# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2017-10-25 16:36:34 # Node ID a035648d9d3b177996aea376593cffcedd9f614e # Parent da1c905338e1ec75235a89aacb4ea98ebb5dc6f9 added secondary plot menu diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "framebufferseries.h" #include "utils.h" @@ -60,7 +61,7 @@ MainWindow::MainWindow(QWidget *parent) aboutDialog(this), portControl(&serialPort), channelMan(1, 1, this), - barPlot(&channelMan), + secondaryPlot(NULL), snapshotMan(this, &channelMan), commandPanel(&serialPort), dataFormatPanel(&serialPort, &channelMan, &recorder), @@ -110,6 +111,10 @@ MainWindow::MainWindow(QWidget *parent) // init UI signals + // Secondary plot menu signals + connect(ui->actionBarPlot, &QAction::triggered, + this, &MainWindow::showBarPlot); + // Help menu signals QObject::connect(ui->actionHelpAbout, &QAction::triggered, &aboutDialog, &QWidget::show); @@ -155,10 +160,7 @@ MainWindow::MainWindow(QWidget *parent) connect(&plotControlPanel, &PlotControlPanel::plotWidthChanged, plotMan, &PlotManager::setPlotWidth); - // secondary (bar) plot signals - connect(&plotControlPanel, &PlotControlPanel::yScaleChanged, - &barPlot, &BarPlot::setYAxis); - + // plot toolbar signals QObject::connect(ui->actionClear, SIGNAL(triggered(bool)), this, SLOT(clearPlot())); @@ -269,8 +271,6 @@ MainWindow::MainWindow(QWidget *parent) this->ui->tabWidget->setCurrentWidget(&commandPanel); this->ui->tabWidget->showTabs(); }); - - ui->splitter->addWidget(&barPlot); } MainWindow::~MainWindow() @@ -485,6 +485,46 @@ void MainWindow::enableDemo(bool enabled } } +void MainWindow::showSecondary(QWidget* wid) +{ + if (secondaryPlot != NULL) + { + secondaryPlot->deleteLater(); + } + + secondaryPlot = wid; + ui->splitter->addWidget(wid); +} + +void MainWindow::hideSecondary() +{ + if (secondaryPlot == NULL) + { + qFatal("Secondary plot doesn't exist!"); + } + + secondaryPlot->deleteLater(); + secondaryPlot = NULL; +} + +void MainWindow::showBarPlot(bool show) +{ + if (show) + { + auto plot = new BarPlot(&channelMan); + plot->setYAxis(plotControlPanel.autoScale(), + plotControlPanel.yMin(), + plotControlPanel.yMax()); + connect(&plotControlPanel, &PlotControlPanel::yScaleChanged, + plot, &BarPlot::setYAxis); + showSecondary(plot); + } + else + { + hideSecondary(); + } +} + void MainWindow::onExportCsv() { bool wasPaused = ui->actionPause->isChecked(); 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,7 @@ private: QList curves; ChannelManager channelMan; PlotManager* plotMan; - BarPlot barPlot; + QWidget* secondaryPlot; SnapshotManager snapshotMan; DataRecorder recorder; // operated by `recordPanel` @@ -90,7 +89,13 @@ private: PlotControlPanel plotControlPanel; UpdateCheckDialog updateCheckDialog; + /// Returns true if demo is running bool isDemoRunning(); + /// Display a secondary plot in the splitter, removing and + /// deleting previous one if it exists + void showSecondary(QWidget* wid); + /// Hide secondary plot + void hideSecondary(); /// Stores settings for all modules void saveAllSettings(QSettings* settings); /// Load settings for all modules @@ -113,6 +118,8 @@ private slots: void clearPlot(); void onSpsChanged(unsigned sps); void enableDemo(bool enabled); + void showBarPlot(bool show); + void onExportCsv(); void onSaveSettings(); void onLoadSettings(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -101,7 +101,7 @@ 0 0 653 - 24 + 23 @@ -128,8 +128,18 @@ &View + + + Secondary + + + + + + + @@ -154,7 +164,8 @@ false - + + .. Pause @@ -168,7 +179,8 @@ - + + .. Clear @@ -238,6 +250,30 @@ &Check Update + + + true + + + Bar Plot + + + + + true + + + Vertical + + + + + true + + + Horizontal + +