diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -187,8 +187,28 @@ Plot* PlotManager::addPlotWidget() void PlotManager::addCurve(QString title, FrameBuffer* buffer) { + auto curve = new QwtPlotCurve(title); + curve->setSamples(new FrameBufferSeries(buffer)); + _addCurve(curve); +} + +void PlotManager::addCurve(QString title, QVector data) +{ + auto curve = new QwtPlotCurve(title); + curve->setSamples(data); + _addCurve(curve); +} + +void PlotManager::_addCurve(QwtPlotCurve* curve) +{ + // store and init the curve + curves.append(curve); + + unsigned index = curves.size()-1; + curve->setPen(Plot::makeColor(index)); + + // create the plot for the curve if we are on multi display Plot* plot; - if (isMulti) { // create a new plot widget @@ -199,14 +219,7 @@ void PlotManager::addCurve(QString title plot = plotWidgets[0]; } - // create the curve - QwtPlotCurve* curve = new QwtPlotCurve(title); - curves.append(curve); - - curve->setSamples(new FrameBufferSeries(buffer)); - unsigned index = curves.size()-1; - curve->setPen(Plot::makeColor(index)); - + // show the curve curve->attach(plot); plot->replot(); } diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -37,20 +37,17 @@ class PlotManager : public QObject public: explicit PlotManager(QWidget* plotArea, QObject *parent = 0); ~PlotManager(); - /// Add a new curve with title and buffer. A color is /// automatically chosen for curve. void addCurve(QString title, FrameBuffer* buffer); - + /// Alternative of `addCurve` for static curve data (snapshots). + void addCurve(QString title, QVector data); /// Set the displayed title for a curve void setTitle(unsigned index, QString title); - /// Removes curves from the end void removeCurves(unsigned number); - /// Returns current number of curves known by plot manager unsigned numOfCurves(); - /// Returns the list of actions to be inserted into the `View` menu QList menuActions(); @@ -86,9 +83,12 @@ private: QAction showLegendAction; void setupLayout(bool multiPlot); - Plot* addPlotWidget(); ///< inserts a new plot widget to the current layout + /// Inserts a new plot widget to the current layout. + Plot* addPlotWidget(); /// Returns the plot widget that given curve is attached to Plot* plotWidget(unsigned curveIndex); + /// Common part of overloaded `addCurve` functions + void _addCurve(QwtPlotCurve* curve); private slots: void showGrid(bool show = true); diff --git a/src/snapshotview.cpp b/src/snapshotview.cpp --- a/src/snapshotview.cpp +++ b/src/snapshotview.cpp @@ -28,18 +28,17 @@ SnapshotView::SnapshotView(QWidget *pare _snapshot = snapshot; ui->setupUi(this); + + plotMan = new PlotManager(ui->plotArea); + ui->menuSnapshot->insertAction(ui->actionClose, snapshot->deleteAction()); this->setWindowTitle(snapshot->name()); + // initialize curves unsigned numOfChannels = snapshot->data.size(); - for (unsigned ci = 0; ci < numOfChannels; ci++) { - QwtPlotCurve* curve = new QwtPlotCurve(snapshot->channelName(ci)); - curves.append(curve); - curve->setSamples(snapshot->data[ci]); - curve->setPen(Plot::makeColor(ci)); - curve->attach(ui->plot); + plotMan->addCurve(snapshot->channelName(ci), snapshot->data[ci]); } renameDialog.setWindowTitle("Rename Snapshot"); @@ -50,11 +49,10 @@ SnapshotView::SnapshotView(QWidget *pare connect(ui->actionExport, &QAction::triggered, this, &SnapshotView::save); - // TODO: fix snapshot menu - // for (auto a : ui->plot->menuActions()) - // { - // ui->menuView->addAction(a); - // } + for (auto a : plotMan->menuActions()) + { + ui->menuView->addAction(a); + } } SnapshotView::~SnapshotView() diff --git a/src/snapshotview.h b/src/snapshotview.h --- a/src/snapshotview.h +++ b/src/snapshotview.h @@ -29,7 +29,7 @@ #include #include -#include "plot.h" +#include "plotmanager.h" #include "snapshot.h" namespace Ui { @@ -52,6 +52,7 @@ private: QList curves; Snapshot* _snapshot; QInputDialog renameDialog; + PlotManager* plotMan; void closeEvent(QCloseEvent *event); diff --git a/src/snapshotview.ui b/src/snapshotview.ui --- a/src/snapshotview.ui +++ b/src/snapshotview.ui @@ -16,7 +16,7 @@ - + @@ -26,7 +26,7 @@ 0 0 544 - 27 + 20 @@ -73,14 +73,6 @@ - - - Plot - QWidget -
plot.h
- 1 -
-