diff --git a/src/barplot.cpp b/src/barplot.cpp --- a/src/barplot.cpp +++ b/src/barplot.cpp @@ -40,3 +40,16 @@ void BarPlot::update() barChart.resample(); replot(); } + +void BarPlot::darkBackground(bool enabled) +{ + if (enabled) + { + setCanvasBackground(QBrush(Qt::black)); + } + else + { + setCanvasBackground(QBrush(Qt::white)); + } + replot(); +} diff --git a/src/barplot.h b/src/barplot.h --- a/src/barplot.h +++ b/src/barplot.h @@ -38,8 +38,12 @@ private: QVector chartData() const; +public slots: + void darkBackground(bool enabled); + private slots: void update(); + }; #endif // BARPLOT_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -60,7 +60,6 @@ MainWindow::MainWindow(QWidget *parent) aboutDialog(this), portControl(&serialPort), channelMan(1, 1, this), - barPlot(&channelMan), snapshotMan(this, &channelMan), commandPanel(&serialPort), dataFormatPanel(&serialPort, &channelMan, &recorder), @@ -69,7 +68,7 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); - plotMan = new PlotManager(ui->plotArea, channelMan.infoModel()); + plotMan = new PlotManager(ui->plotArea, ui->splitter, &channelMan, channelMan.infoModel()); ui->tabWidget->insertTab(0, &portControl, "Port"); ui->tabWidget->insertTab(1, &dataFormatPanel, "Data Format"); @@ -265,8 +264,6 @@ MainWindow::MainWindow(QWidget *parent) this->ui->tabWidget->setCurrentWidget(&commandPanel); this->ui->tabWidget->showTabs(); }); - - ui->splitter->addWidget(&barPlot); } MainWindow::~MainWindow() diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -44,7 +44,6 @@ #include "channelmanager.h" #include "snapshotmanager.h" #include "plotmanager.h" -#include "barplot.h" #include "datarecorder.h" #include "updatecheckdialog.h" @@ -79,7 +78,6 @@ private: QList curves; ChannelManager channelMan; PlotManager* plotMan; - BarPlot barPlot; SnapshotManager snapshotMan; DataRecorder recorder; // operated by `recordPanel` diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -28,15 +28,19 @@ #include "utils.h" #include "setting_defines.h" -PlotManager::PlotManager(QWidget* plotArea, ChannelInfoModel* infoModel, QObject *parent) : +PlotManager::PlotManager( + QWidget* plotArea, QSplitter* splitter, ChannelManager* channelMan, + ChannelInfoModel* infoModel, QObject *parent) : QObject(parent), _plotArea(plotArea), + _splitter(splitter), showGridAction("&Grid", this), showMinorGridAction("&Minor Grid", this), unzoomAction("&Unzoom", this), darkBackgroundAction("&Dark Background", this), showLegendAction("&Legend", this), showMultiAction("Multi &Plot", this), + showBarPlotAction("&Bar Plot", this), setSymbolsAction("Symbols", this) { _autoScaled = true; @@ -44,11 +48,13 @@ PlotManager::PlotManager(QWidget* plotAr _yMax = 1; _xAxisAsIndex = true; isDemoShown = false; + _channelMan = channelMan; _infoModel = infoModel; _numOfSamples = 1; _plotWidth = 1; showSymbols = Plot::ShowSymbolsAuto; emptyPlot = NULL; + barPlot = NULL; // initalize layout and single widget isMulti = false; @@ -63,6 +69,7 @@ PlotManager::PlotManager(QWidget* plotAr darkBackgroundAction.setToolTip("Enable Dark Plot Background"); showLegendAction.setToolTip("Display the Legend on Plot"); showMultiAction.setToolTip("Display All Channels Separately"); + showBarPlotAction.setToolTip("Show bar plot"); setSymbolsAction.setToolTip("Show/Hide symbols"); showGridAction.setShortcut(QKeySequence("G")); @@ -73,12 +80,14 @@ PlotManager::PlotManager(QWidget* plotAr darkBackgroundAction.setCheckable(true); showLegendAction.setCheckable(true); showMultiAction.setCheckable(true); + showBarPlotAction.setCheckable(true); showGridAction.setChecked(false); showMinorGridAction.setChecked(false); darkBackgroundAction.setChecked(false); showLegendAction.setChecked(true); showMultiAction.setChecked(false); + showBarPlotAction.setChecked(false); showMinorGridAction.setEnabled(false); @@ -128,6 +137,8 @@ PlotManager::PlotManager(QWidget* plotAr this, &PlotManager::showLegend); connect(&showMultiAction, SELECT::OVERLOAD_OF(&QAction::triggered), this, &PlotManager::setMulti); + connect(&showBarPlotAction, SELECT::OVERLOAD_OF(&QAction::triggered), + this, &PlotManager::showBarPlot); // connect to channel info model if (_infoModel != NULL) // TODO: remove when snapshots have infomodel @@ -264,6 +275,26 @@ void PlotManager::setMulti(bool enabled) checkNoVisChannels(); } +void PlotManager::showBarPlot(bool show) +{ + // A secondary plot can only be shown if splitter is provided. + Q_ASSERT(_splitter != NULL); + + if (show) + { + Q_ASSERT(barPlot == NULL); + + barPlot = new BarPlot(_channelMan, _splitter); + } + else + { + Q_ASSERT(barPlot != NULL); + + delete barPlot; + barPlot = NULL; + } +} + void PlotManager::setupLayout(bool multiPlot) { // delete previous layout if it exists @@ -428,6 +459,7 @@ QList PlotManager::menuActions actions << &darkBackgroundAction; actions << &showLegendAction; actions << &showMultiAction; + actions << &showBarPlotAction; actions << &setSymbolsAction; return actions; } @@ -479,6 +511,7 @@ void PlotManager::darkBackground(bool en { plot->darkBackground(enabled); } + if (barPlot != NULL) barPlot->darkBackground(enabled); } void PlotManager::setSymbols(Plot::ShowSymbols shown) diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -28,10 +28,13 @@ #include #include #include +#include #include #include "plot.h" +#include "barplot.h" #include "framebufferseries.h" +#include "channelmanager.h" #include "channelinfomodel.h" struct PlotViewSettings @@ -49,7 +52,10 @@ class PlotManager : public QObject Q_OBJECT public: - explicit PlotManager(QWidget* plotArea, ChannelInfoModel* infoModel = NULL, QObject *parent = 0); + explicit PlotManager( + QWidget* plotArea, QSplitter* splitter = NULL, + ChannelManager* channelMan = NULL, ChannelInfoModel* infoModel = NULL, + QObject *parent = 0); ~PlotManager(); /// Add a new curve with title and buffer. A color is /// automatically chosen for curve. @@ -74,8 +80,6 @@ public: void loadSettings(QSettings* settings); public slots: - /// Enable/Disable multiple plot display - void setMulti(bool enabled); /// Update all plot widgets void replot(); /// Enable display of a "DEMO" label on each plot @@ -94,11 +98,14 @@ public slots: private: bool isMulti; QWidget* _plotArea; + BarPlot* barPlot; + QSplitter* _splitter; QVBoxLayout* layout; ///< layout of the `plotArea` QScrollArea* scrollArea; QList curves; QList plotWidgets; Plot* emptyPlot; ///< for displaying when all channels are hidden + ChannelManager* _channelMan; ChannelInfoModel* _infoModel; bool isDemoShown; bool _autoScaled; @@ -118,6 +125,7 @@ private: QAction darkBackgroundAction; QAction showLegendAction; QAction showMultiAction; + QAction showBarPlotAction; QAction setSymbolsAction; QMenu setSymbolsMenu; QAction* setSymbolsAutoAct; @@ -141,6 +149,10 @@ private slots: void showLegend(bool show = true); void unzoom(); void darkBackground(bool enabled = true); + /// Enable/Disable multiple plot display + void setMulti(bool enabled); + /// Display/Hide bar plot + void showBarPlot(bool show = true); void onChannelInfoChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, diff --git a/src/snapshotview.cpp b/src/snapshotview.cpp --- a/src/snapshotview.cpp +++ b/src/snapshotview.cpp @@ -29,7 +29,7 @@ SnapshotView::SnapshotView(MainWindow* p ui->setupUi(this); - plotMan = new PlotManager(ui->plotArea, snapshot->infoModel(), this); + plotMan = new PlotManager(ui->plotArea, NULL, NULL, snapshot->infoModel(), this); plotMan->setViewSettings(parent->viewSettings()); ui->menuSnapshot->insertAction(ui->actionClose, snapshot->deleteAction());