# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2016-08-21 16:58:03 # Node ID a0f5016bf36d5ffe252c0aae6b67803d29aece8d # Parent 5a4e6dd9042e9bcb6b28c1322f9c5bebd7dbc3dd plotmanager roughly integrated diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -164,13 +164,10 @@ MainWindow::MainWindow(QWidget *parent) // init curve list for (unsigned int i = 0; i < numOfChannels; i++) { - curves.append(new QwtPlotCurve(channelMan.channelName(i))); - curves[i]->setSamples( - new FrameBufferSeries(channelMan.channelBuffer(i))); - curves[i]->setPen(Plot::makeColor(i)); - curves[i]->attach(ui->plot); + plotMan->addCurve(channelMan.channelName(i), channelMan.channelBuffer(i)); } + // TODO: plotman // init auto scale ui->plot->setAxis(plotControlPanel.autoScale(), plotControlPanel.yMin(), plotControlPanel.yMax()); @@ -201,17 +198,13 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { - for (auto curve : curves) - { - // also deletes respective FrameBuffer - delete curve; - } - if (serialPort.isOpen()) { serialPort.close(); } + delete plotMan; + delete ui; ui = NULL; // we check if ui is deleted in messageHandler } @@ -313,7 +306,7 @@ void MainWindow::onNumOfSamplesChanged(i void MainWindow::onNumOfChannelsChanged(unsigned value) { - unsigned int oldNum = curves.size(); + unsigned int oldNum = plotMan->numOfCurves(); unsigned numOfChannels = value; if (numOfChannels > oldNum) @@ -321,23 +314,15 @@ void MainWindow::onNumOfChannelsChanged( // add new channels for (unsigned int i = oldNum; i < numOfChannels; i++) { - QwtPlotCurve* curve = new QwtPlotCurve(channelMan.channelName(i)); - curve->setSamples( - new FrameBufferSeries(channelMan.channelBuffer(i))); - curve->setPen(Plot::makeColor(i)); - curve->attach(ui->plot); - curves.append(curve); + plotMan->addCurve(channelMan.channelName(i), channelMan.channelBuffer(i)); } } else if(numOfChannels < oldNum) { - // remove channels - for (unsigned int i = 0; i < oldNum - numOfChannels; i++) - { - delete curves.takeLast(); - } + plotMan->removeCurves(oldNum - numOfChannels); } + // TODO: plotman.replot ui->plot->replot(); } diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -34,12 +34,12 @@ PlotManager::PlotManager(QWidget* plotAr addPlotWidget(); // test code - addCurve("test", new FrameBuffer(100)); - addCurve("test", new FrameBuffer(100)); - addCurve("test", new FrameBuffer(100)); + // addCurve("test", new FrameBuffer(100)); + // addCurve("test", new FrameBuffer(100)); + // addCurve("test", new FrameBuffer(100)); - setMulti(true); - setMulti(false); + // setMulti(true); + // setMulti(false); } PlotManager::~PlotManager() @@ -163,4 +163,25 @@ void PlotManager::addCurve(QString title curve->setPen(Plot::makeColor(index)); curve->attach(plot); + plot->replot(); } + +void PlotManager::removeCurves(unsigned number) +{ + for (unsigned i = 0; i < number; i++) + { + if (!curves.isEmpty()) + { + delete curves.takeLast(); + if (isMulti) // delete corresponding widget as well + { + delete plotWidgets.takeLast(); + } + } + } +} + +unsigned PlotManager::numOfCurves() +{ + return curves.size(); +} diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -48,6 +48,9 @@ public: /// Removes curves from the end void removeCurves(unsigned number); + /// Returns current number of curves known by plot manager + unsigned numOfCurves(); + signals: public slots: