Changeset - a0f5016bf36d
[Not reviewed]
plot-manager
0 3 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-08-21 16:58:03
hy@ozderya.net
plotmanager roughly integrated
3 files changed with 37 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/mainwindow.cpp
Show inline comments
 
@@ -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();
 
}
 

	
src/plotmanager.cpp
Show inline comments
 
@@ -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();
 
}
src/plotmanager.h
Show inline comments
 
@@ -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:
0 comments (0 inline, 0 general)