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
 
@@ -161,19 +161,16 @@ MainWindow::MainWindow(QWidget *parent) 
 

	
 
    plotControlPanel.setChannelNamesModel(channelMan.channelNames());
 

	
 
    // 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());
 

	
 
    // Init sps (sample per second) counter
 
    spsLabel.setText("0sps");
 
@@ -198,23 +195,19 @@ MainWindow::MainWindow(QWidget *parent) 
 
        demoIndicator.attach(ui->plot);
 
    }
 
}
 

	
 
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
 
}
 

	
 
void MainWindow::setupAboutDialog()
 
{
 
@@ -310,37 +303,29 @@ void MainWindow::onNumOfSamplesChanged(i
 
    channelMan.setNumOfSamples(value);
 
    ui->plot->replot();
 
}
 

	
 
void MainWindow::onNumOfChannelsChanged(unsigned value)
 
{
 
    unsigned int oldNum = curves.size();
 
    unsigned int oldNum = plotMan->numOfCurves();
 
    unsigned numOfChannels = value;
 

	
 
    if (numOfChannels > oldNum)
 
    {
 
        // 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();
 
}
 

	
 
void MainWindow::onChannelNameChanged(unsigned channel, QString name)
 
{
 
    // This slot is triggered also when a new channel is added, in
src/plotmanager.cpp
Show inline comments
 
@@ -31,18 +31,18 @@ PlotManager::PlotManager(QWidget* plotAr
 
    isMulti = false;
 
    scrollArea = NULL;
 
    setupLayout(isMulti);
 
    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()
 
{
 
    while (curves.size())
 
    {
 
@@ -160,7 +160,28 @@ void PlotManager::addCurve(QString title
 

	
 
    curve->setSamples(new FrameBufferSeries(buffer));
 
    unsigned index = curves.size()-1;
 
    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
 
@@ -45,12 +45,15 @@ public:
 
    /// 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();
 

	
 
signals:
 

	
 
public slots:
 
    /// Enable/Disable multiple plot display
 
    void setMulti(bool enabled);
 

	
0 comments (0 inline, 0 general)