diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -88,7 +88,7 @@ MainWindow::MainWindow(QWidget *parent) setupAboutDialog(); // init view menu - for (auto a : ui->plot->menuActions()) + for (auto a : plotMan->menuActions()) { ui->menuView->addAction(a); } diff --git a/src/plot.cpp b/src/plot.cpp --- a/src/plot.cpp +++ b/src/plot.cpp @@ -29,12 +29,7 @@ Plot::Plot(QWidget* parent) : QwtPlot(parent), zoomer(this->canvas(), false), - sZoomer(this, &zoomer), - showGridAction("Grid", this), - showMinorGridAction("Minor Grid", this), - unzoomAction("Unzoom", this), - darkBackgroundAction("Dark Background", this), - showLegendAction("Legend", this) + sZoomer(this, &zoomer) { isAutoScaled = true; @@ -47,39 +42,6 @@ Plot::Plot(QWidget* parent) : showGrid(false); darkBackground(false); - showGridAction.setToolTip("Show Grid"); - showMinorGridAction.setToolTip("Show Minor Grid"); - unzoomAction.setToolTip("Unzoom the Plot"); - darkBackgroundAction.setToolTip("Enable Dark Plot Background"); - showLegendAction.setToolTip("Display the Legend on Plot"); - - showGridAction.setShortcut(QKeySequence("G")); - showMinorGridAction.setShortcut(QKeySequence("M")); - - showGridAction.setCheckable(true); - showMinorGridAction.setCheckable(true); - darkBackgroundAction.setCheckable(true); - showLegendAction.setCheckable(true); - - showGridAction.setChecked(false); - showMinorGridAction.setChecked(false); - darkBackgroundAction.setChecked(false); - showLegendAction.setChecked(true); - - showMinorGridAction.setEnabled(false); - - connect(&showGridAction, SELECT::OVERLOAD_OF(&QAction::triggered), - this, &Plot::showGrid); - connect(&showGridAction, SELECT::OVERLOAD_OF(&QAction::triggered), - &showMinorGridAction, &QAction::setEnabled); - connect(&showMinorGridAction, SELECT::OVERLOAD_OF(&QAction::triggered), - this, &Plot::showMinorGrid); - connect(&unzoomAction, &QAction::triggered, this, &Plot::unzoom); - connect(&darkBackgroundAction, SELECT::OVERLOAD_OF(&QAction::triggered), - this, &Plot::darkBackground); - connect(&showLegendAction, SELECT::OVERLOAD_OF(&QAction::triggered), - [this](bool enabled){legend.setVisible(enabled); replot();}); - snapshotOverlay = NULL; } @@ -102,17 +64,6 @@ void Plot::setAxis(bool autoScaled, doub resetAxes(); } -QList Plot::menuActions() -{ - QList actions; - actions << &showGridAction; - actions << &showMinorGridAction; - actions << &unzoomAction; - actions << &darkBackgroundAction; - actions << &showLegendAction; - return actions; -} - void Plot::resetAxes() { if (isAutoScaled) @@ -213,7 +164,9 @@ void Plot::flashSnapshotOverlay() if (snapshotOverlay != NULL) delete snapshotOverlay; QColor color; - if (darkBackgroundAction.isChecked()) + // TODO: fix snapshot overlay + // if (darkBackgroundAction.isChecked()) + if(1) { color = QColor(Qt::white); } diff --git a/src/plot.h b/src/plot.h --- a/src/plot.h +++ b/src/plot.h @@ -40,8 +40,6 @@ public: Plot(QWidget* parent = 0); ~Plot(); - QList menuActions(); - static QColor makeColor(unsigned int channelIndex); private: @@ -53,12 +51,6 @@ private: PlotSnapshotOverlay* snapshotOverlay; QwtPlotLegendItem legend; - QAction showGridAction; - QAction showMinorGridAction; - QAction unzoomAction; - QAction darkBackgroundAction; - QAction showLegendAction; - void resetAxes(); public slots: diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -17,15 +17,21 @@ along with serialplot. If not, see . */ +#include + #include "plot.h" - #include "plotmanager.h" +#include "utils.h" -#include PlotManager::PlotManager(QWidget* plotArea, QObject *parent) : QObject(parent), - _plotArea(plotArea) + _plotArea(plotArea), + showGridAction("Grid", this), + showMinorGridAction("Minor Grid", this), + unzoomAction("Unzoom", this), + darkBackgroundAction("Dark Background", this), + showLegendAction("Legend", this) { // initalize layout and single widget isMulti = false; @@ -33,13 +39,40 @@ PlotManager::PlotManager(QWidget* plotAr setupLayout(isMulti); addPlotWidget(); - // test code - // addCurve("test", new FrameBuffer(100)); - // addCurve("test", new FrameBuffer(100)); - // addCurve("test", new FrameBuffer(100)); + // initialize menu actions + showGridAction.setToolTip("Show Grid"); + showMinorGridAction.setToolTip("Show Minor Grid"); + unzoomAction.setToolTip("Unzoom the Plot"); + darkBackgroundAction.setToolTip("Enable Dark Plot Background"); + showLegendAction.setToolTip("Display the Legend on Plot"); + + showGridAction.setShortcut(QKeySequence("G")); + showMinorGridAction.setShortcut(QKeySequence("M")); + + showGridAction.setCheckable(true); + showMinorGridAction.setCheckable(true); + darkBackgroundAction.setCheckable(true); + showLegendAction.setCheckable(true); - // setMulti(true); - // setMulti(false); + showGridAction.setChecked(false); + showMinorGridAction.setChecked(false); + darkBackgroundAction.setChecked(false); + showLegendAction.setChecked(true); + + showMinorGridAction.setEnabled(false); + + connect(&showGridAction, SELECT::OVERLOAD_OF(&QAction::triggered), + this, &PlotManager::showGrid); + connect(&showGridAction, SELECT::OVERLOAD_OF(&QAction::triggered), + &showMinorGridAction, &QAction::setEnabled); + connect(&showMinorGridAction, SELECT::OVERLOAD_OF(&QAction::triggered), + this, &PlotManager::showMinorGrid); + connect(&unzoomAction, &QAction::triggered, this, &PlotManager::unzoom); + connect(&darkBackgroundAction, SELECT::OVERLOAD_OF(&QAction::triggered), + this, &PlotManager::darkBackground); + // TODO: enable legend + // connect(&showLegendAction, SELECT::OVERLOAD_OF(&QAction::triggered), + // [this](bool enabled){legend.setVisible(enabled); replot();}); } PlotManager::~PlotManager() @@ -212,3 +245,43 @@ void PlotManager::replot() plot->replot(); } } + +QList PlotManager::menuActions() +{ + QList actions; + actions << &showGridAction; + actions << &showMinorGridAction; + actions << &unzoomAction; + actions << &darkBackgroundAction; + actions << &showLegendAction; + return actions; +} + +void PlotManager::showGrid(bool show) +{ + for (auto plot : plotWidgets) + { + plot->showGrid(show); + } +} +void PlotManager::showMinorGrid(bool show) +{ + for (auto plot : plotWidgets) + { + plot->showMinorGrid(show); + } +} +void PlotManager::unzoom() +{ + for (auto plot : plotWidgets) + { + plot->unzoom(); + } +} +void PlotManager::darkBackground(bool enabled) +{ + for (auto plot : plotWidgets) + { + plot->darkBackground(enabled); + } +} diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -51,7 +51,8 @@ public: /// Returns current number of curves known by plot manager unsigned numOfCurves(); -signals: + /// Returns the list of actions to be inserted into the `View` menu + QList menuActions(); public slots: /// Enable/Disable multiple plot display @@ -67,10 +68,23 @@ private: QList curves; QList plotWidgets; + // menu actions + QAction showGridAction; + QAction showMinorGridAction; + QAction unzoomAction; + QAction darkBackgroundAction; + QAction showLegendAction; + void setupLayout(bool multiPlot); Plot* addPlotWidget(); ///< inserts a new plot widget to the current layout /// Returns the plot widget that given curve is attached to Plot* plotWidget(unsigned curveIndex); + +private slots: + void showGrid(bool show = true); + void showMinorGrid(bool show = true); + void unzoom(); + void darkBackground(bool enabled = true); }; #endif // PLOTMANAGER_H diff --git a/src/snapshotview.cpp b/src/snapshotview.cpp --- a/src/snapshotview.cpp +++ b/src/snapshotview.cpp @@ -50,10 +50,11 @@ SnapshotView::SnapshotView(QWidget *pare connect(ui->actionExport, &QAction::triggered, this, &SnapshotView::save); - for (auto a : ui->plot->menuActions()) - { - ui->menuView->addAction(a); - } + // TODO: fix snapshot menu + // for (auto a : ui->plot->menuActions()) + // { + // ui->menuView->addAction(a); + // } } SnapshotView::~SnapshotView()