Skip to content
Snippets Groups Projects
Commit 6e373dbb authored by tobiglaser's avatar tobiglaser
Browse files

changed generate into preview and lock buttons

parent fbb69029
No related branches found
No related tags found
No related merge requests found
...@@ -45,9 +45,13 @@ ConfigPanel::ConfigPanel(QWidget* parent) : QDockWidget{parent} ...@@ -45,9 +45,13 @@ ConfigPanel::ConfigPanel(QWidget* parent) : QDockWidget{parent}
fileLine = new QLineEdit(); fileLine = new QLineEdit();
fileLine->setPlaceholderText("/path/to/yourFile.csv"); fileLine->setPlaceholderText("/path/to/yourFile.csv");
fileWidget->layout()->addWidget(fileLine); fileWidget->layout()->addWidget(fileLine);
fileGenerateButton = new QPushButton("Preview"); auto fileGenerateButton = new QPushButton("Preview");
fileLayout->addWidget(fileGenerateButton); fileLayout->addWidget(fileGenerateButton);
auto fileLockButton = new QPushButton("Lock");
fileLayout->addWidget(fileLockButton);
lockButtons.push_back(fileLockButton);
fileLayout->addStretch(); fileLayout->addStretch();
connect(fileGenerateButton, &QPushButton::clicked, this, &ConfigPanel::previewButtonClicked);
connect(openButton, &QPushButton::clicked, this, &ConfigPanel::onOpenButton); connect(openButton, &QPushButton::clicked, this, &ConfigPanel::onOpenButton);
randomWidget = new QWidget(); randomWidget = new QWidget();
...@@ -58,9 +62,13 @@ ConfigPanel::ConfigPanel(QWidget* parent) : QDockWidget{parent} ...@@ -58,9 +62,13 @@ ConfigPanel::ConfigPanel(QWidget* parent) : QDockWidget{parent}
randomLayout->setContentsMargins(0, 0, 0, 0); randomLayout->setContentsMargins(0, 0, 0, 0);
problemSizeBox = new QSpinBox(); problemSizeBox = new QSpinBox();
randomLayout->addWidget(problemSizeBox); randomLayout->addWidget(problemSizeBox);
randomGenerateButton = new QPushButton("Preview"); auto randomGenerateButton = new QPushButton("Preview");
randomLayout->addWidget(randomGenerateButton); randomLayout->addWidget(randomGenerateButton);
auto randomLockButton = new QPushButton("Lock");
randomLayout->addWidget(randomLockButton);
lockButtons.push_back(randomLockButton);
randomLayout->addStretch(); randomLayout->addStretch();
connect(randomGenerateButton, &QPushButton::clicked, this, &ConfigPanel::previewButtonClicked);
problemSizeBox->setMinimum(1); problemSizeBox->setMinimum(1);
problemSizeBox->setMaximum(INT_MAX); problemSizeBox->setMaximum(INT_MAX);
...@@ -77,11 +85,20 @@ ConfigPanel::ConfigPanel(QWidget* parent) : QDockWidget{parent} ...@@ -77,11 +85,20 @@ ConfigPanel::ConfigPanel(QWidget* parent) : QDockWidget{parent}
pasteBox->setMinimumHeight(25); pasteBox->setMinimumHeight(25);
pasteBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); pasteBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
pasteGenerateButton = new QPushButton("Preview"); auto pasteGenerateButton = new QPushButton("Preview");
pasteLayout->addWidget(pasteGenerateButton); pasteLayout->addWidget(pasteGenerateButton);
auto pasteLockButton = new QPushButton("Lock");
pasteLayout->addWidget(pasteLockButton);
lockButtons.push_back(pasteLockButton);
pasteLayout->addStretch(); pasteLayout->addStretch();
connect(pasteGenerateButton, &QPushButton::clicked, this, &ConfigPanel::previewButtonClicked);
stackedWidget->setCurrentWidget(pasteWidget); stackedWidget->setCurrentWidget(pasteWidget);
for (auto &&button : lockButtons)
{
connect(button, &QPushButton::clicked, this, lockButtonClicked);
}
} }
void ConfigPanel::setRunning(bool running) void ConfigPanel::setRunning(bool running)
...@@ -100,18 +117,26 @@ void ConfigPanel::setRunning(bool running) ...@@ -100,18 +117,26 @@ void ConfigPanel::setRunning(bool running)
void ConfigPanel::setGenLocked() void ConfigPanel::setGenLocked()
{ {
randomGenerateButton->setEnabled(false); for (auto &&button : lockButtons)
randomGenerateButton->setText("Generated"); {
fileGenerateButton->setEnabled(false); button->setText("Unlock");
fileGenerateButton->setText("Generated"); }
problemSizeBox->setDisabled(true);
fileLine->setDisabled(true);
openButton->setDisabled(true);
pasteBox->setDisabled(true);
} }
void ConfigPanel::setGenUnlocked() void ConfigPanel::setGenUnlocked()
{ {
randomGenerateButton->setEnabled(true); for (auto &&button : lockButtons)
randomGenerateButton->setText("Generate"); {
fileGenerateButton->setEnabled(true); button->setText("Lock");
fileGenerateButton->setText("Generate"); }
problemSizeBox->setDisabled(false);
fileLine->setDisabled(false);
openButton->setDisabled(false);
pasteBox->setDisabled(false);
} }
void ConfigPanel::onOpenButton() void ConfigPanel::onOpenButton()
......
...@@ -14,12 +14,12 @@ class ConfigPanel : public QDockWidget ...@@ -14,12 +14,12 @@ class ConfigPanel : public QDockWidget
{ {
Q_OBJECT Q_OBJECT
private:
std::vector<QPushButton*> lockButtons;
public: public:
QPushButton* runButton; QPushButton* runButton;
QPushButton* openButton; QPushButton* openButton;
QPushButton* randomGenerateButton;
QPushButton* fileGenerateButton;
QPushButton* pasteGenerateButton;
QLineEdit* fileLine; QLineEdit* fileLine;
QPlainTextEdit* pasteBox; QPlainTextEdit* pasteBox;
QComboBox* algoBox; QComboBox* algoBox;
...@@ -40,6 +40,10 @@ public slots: ...@@ -40,6 +40,10 @@ public slots:
void setRunning(bool running); void setRunning(bool running);
void setGenLocked(); void setGenLocked();
void setGenUnlocked(); void setGenUnlocked();
signals:
void previewButtonClicked();
void lockButtonClicked();
}; };
#endif // CONFIGPANEL_H #endif // CONFIGPANEL_H
...@@ -45,11 +45,8 @@ void Control::makeConnections() ...@@ -45,11 +45,8 @@ void Control::makeConnections()
connect(cc, &CuteControl::s_undo, this, &Control::undo); connect(cc, &CuteControl::s_undo, this, &Control::undo);
connect(this, &Control::endThread, cc, &CuteControl::end); connect(this, &Control::endThread, cc, &CuteControl::end);
connect(w->configPanel->runButton, &QPushButton::clicked, this, &Control::onRunButton); connect(w->configPanel->runButton, &QPushButton::clicked, this, &Control::onRunButton);
connect(w->configPanel->fileGenerateButton, &QPushButton::clicked, this, &Control::onGenerateButton); connect(w->configPanel, &ConfigPanel::previewButtonClicked, this, &Control::onPreviewButton);
connect(w->configPanel->randomGenerateButton, &QPushButton::clicked, this, &Control::onGenerateButton); connect(w->configPanel, &ConfigPanel::lockButtonClicked, this, &Control::onLockButton);
connect(w->configPanel->pasteGenerateButton, &QPushButton::clicked, this, &Control::onGenerateButton);
connect(w->configPanel->fileLine, &QLineEdit::textChanged, this, &Control::onProblemSettingChanged);
connect(w->configPanel->problemSizeBox, &QSpinBox::textChanged, this, &Control::onProblemSettingChanged);
connect(w, &MainWindow::saveProblem, this, &Control::saveProblem); connect(w, &MainWindow::saveProblem, this, &Control::saveProblem);
connect(w->cm, &ChartMenu::s_setPlotScale, this, &Control::setPlotScale); connect(w->cm, &ChartMenu::s_setPlotScale, this, &Control::setPlotScale);
connect(cc, &CuteControl::s_verbosityChanged, w, &MainWindow::changeVerbosity); connect(cc, &CuteControl::s_verbosityChanged, w, &MainWindow::changeVerbosity);
...@@ -306,17 +303,29 @@ void Control::generateProblem() ...@@ -306,17 +303,29 @@ void Control::generateProblem()
} }
} }
void Control::onGenerateButton() void Control::onPreviewButton()
{ {
generateProblem(); if (!threadRunning)
problemRetained = true; {
w->configPanel->setGenLocked(); resetPlot(0);
CuteControl::get().plotPoints(getProblem(), 0, {});
}
} }
void Control::onProblemSettingChanged([[maybe_unused]] const QString& text) void Control::onLockButton()
{ {
problemRetained = false; if (problemRetained)
w->configPanel->setGenUnlocked(); {
problemRetained = false;
w->configPanel->setGenUnlocked();
}
else
{
if (problem.empty())
generateProblem();
problemRetained = true;
w->configPanel->setGenLocked();
}
} }
void Control::plotXYSeries(QtCharts::QXYSeries* s, int plot, bool onTop, bool legend, QString tooltip) void Control::plotXYSeries(QtCharts::QXYSeries* s, int plot, bool onTop, bool legend, QString tooltip)
...@@ -578,6 +587,8 @@ void Control::redrawOnTopSeries(int plot) ...@@ -578,6 +587,8 @@ void Control::redrawOnTopSeries(int plot)
{ {
for (auto s : onTopSeries[plot]) for (auto s : onTopSeries[plot])
{ {
QtCharts::QLegendMarker* legendMarker = w->charts[plot]->legend()->markers(s)[0];
bool legendVisible = legendMarker->isVisible();
w->charts[plot]->removeSeries(s); w->charts[plot]->removeSeries(s);
w->charts[plot]->addSeries(s); w->charts[plot]->addSeries(s);
auto axes = w->charts[plot]->axes(); auto axes = w->charts[plot]->axes();
...@@ -585,6 +596,8 @@ void Control::redrawOnTopSeries(int plot) ...@@ -585,6 +596,8 @@ void Control::redrawOnTopSeries(int plot)
{ {
s->attachAxis(axis); s->attachAxis(axis);
} }
legendMarker = w->charts[plot]->legend()->markers(s)[0];
legendMarker->setVisible(legendVisible);
}; };
} }
......
...@@ -56,10 +56,10 @@ public slots: ...@@ -56,10 +56,10 @@ public slots:
void setAxisTitles(int plot, QString x, QString y); void setAxisTitles(int plot, QString x, QString y);
void setAxisVisible(int plot, bool x, bool y); void setAxisVisible(int plot, bool x, bool y);
void onRunButton(); void onRunButton();
void onGenerateButton(); void onPreviewButton();
void setProblemSize(int n); void setProblemSize(int n);
void setProblemFile(QString path); void setProblemFile(QString path);
void onProblemSettingChanged(const QString& text); void onLockButton();
void plotXYSeries(QtCharts::QXYSeries* s, int plot, bool onTop, bool legend, QString tooltip = ""); void plotXYSeries(QtCharts::QXYSeries* s, int plot, bool onTop, bool legend, QString tooltip = "");
void plotBarSeries(QtCharts::QBarSeries* series, int plot, bool onTop, bool legend); void plotBarSeries(QtCharts::QBarSeries* series, int plot, bool onTop, bool legend);
void highlightValue(float value, int plot, QColor c); void highlightValue(float value, int plot, QColor c);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment