# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2016-08-26 16:16:49 # Node ID bd649e494eb161bdf77854296cb1e7695e3b327f # Parent baaf95cd20895e36166d80cf3f3052c7ef339ea8 show demo indicator on all plots diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -187,16 +187,8 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->actionDemoMode, &QAction::toggled, this, &MainWindow::enableDemo); - { // init demo indicator - QwtText demoText(" DEMO RUNNING "); // looks better with spaces - demoText.setColor(QColor("white")); - demoText.setBackgroundBrush(Qt::darkRed); - demoText.setBorderRadius(4); - demoText.setRenderFlags(Qt::AlignLeft | Qt::AlignTop); - demoIndicator.setText(demoText); - demoIndicator.hide(); - demoIndicator.attach(ui->plot); - } + QObject::connect(ui->actionDemoMode, &QAction::toggled, + plotMan, &PlotManager::showDemoIndicator); } MainWindow::~MainWindow() @@ -356,9 +348,6 @@ void MainWindow::enableDemo(bool enabled if (!serialPort.isOpen()) { dataFormatPanel.enableDemo(true); - ui->actionDemoMode->setChecked(true); - demoIndicator.show(); - plotMan->replot(); } else { @@ -369,8 +358,6 @@ void MainWindow::enableDemo(bool enabled { dataFormatPanel.enableDemo(false); ui->actionDemoMode->setChecked(false); - demoIndicator.hide(); - plotMan->replot(); } } diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -32,7 +32,6 @@ #include #include #include -#include #include "portcontrol.h" #include "commandpanel.h" @@ -83,7 +82,6 @@ private: SnapshotManager snapshotMan; - QwtPlotTextLabel demoIndicator; bool isDemoRunning(); // test widget diff --git a/src/plot.cpp b/src/plot.cpp --- a/src/plot.cpp +++ b/src/plot.cpp @@ -43,6 +43,16 @@ Plot::Plot(QWidget* parent) : darkBackground(false); snapshotOverlay = NULL; + + // init demo indicator + QwtText demoText(" DEMO RUNNING "); // looks better with spaces + demoText.setColor(QColor("white")); + demoText.setBackgroundBrush(Qt::darkRed); + demoText.setBorderRadius(4); + demoText.setRenderFlags(Qt::AlignLeft | Qt::AlignTop); + demoIndicator.setText(demoText); + demoIndicator.hide(); + demoIndicator.attach(this); } Plot::~Plot() @@ -104,6 +114,12 @@ void Plot::showLegend(bool show) replot(); } +void Plot::showDemoIndicator(bool show) +{ + demoIndicator.setVisible(show); + replot(); +} + void Plot::unzoom() { zoomer.zoom(0); diff --git a/src/plot.h b/src/plot.h --- a/src/plot.h +++ b/src/plot.h @@ -27,6 +27,7 @@ #include #include #include +#include #include "zoomer.h" #include "scalezoomer.h" @@ -50,6 +51,7 @@ private: QwtPlotGrid grid; PlotSnapshotOverlay* snapshotOverlay; QwtPlotLegendItem legend; + QwtPlotTextLabel demoIndicator; void resetAxes(); @@ -57,6 +59,7 @@ public slots: void showGrid(bool show = true); void showMinorGrid(bool show = true); void showLegend(bool show = true); + void showDemoIndicator(bool show = true); void unzoom(); void darkBackground(bool enabled = true); void setAxis(bool autoScaled, double yMin = 0, double yMax = 1); diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -35,6 +35,7 @@ PlotManager::PlotManager(QWidget* plotAr { // initalize layout and single widget isMulti = false; + isDemoShown = false; scrollArea = NULL; setupLayout(isMulti); addPlotWidget(); @@ -174,6 +175,7 @@ Plot* PlotManager::addPlotWidget() plot->showGrid(showGridAction.isChecked()); plot->showMinorGrid(showMinorGridAction.isChecked()); plot->showLegend(showLegendAction.isChecked()); + plot->showDemoIndicator(isDemoShown); return plot; } @@ -286,6 +288,15 @@ void PlotManager::showLegend(bool show) } } +void PlotManager::showDemoIndicator(bool show) +{ + isDemoShown = show; + for (auto plot : plotWidgets) + { + plot->showDemoIndicator(show); + } +} + void PlotManager::unzoom() { for (auto plot : plotWidgets) diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -59,6 +59,8 @@ public slots: void setMulti(bool enabled); /// Update all plot widgets void replot(); + /// Enable display of a "DEMO" label on each plot + void showDemoIndicator(bool show = true); private: bool isMulti; @@ -67,6 +69,7 @@ private: QScrollArea* scrollArea; QList curves; QList plotWidgets; + bool isDemoShown; // menu actions QAction showGridAction;