Changeset - b42c4952c5cc
[Not reviewed]
barplot
0 3 2
Hasan Yavuz ÖZDERYA - 8 years ago 2017-10-03 05:28:24
hy@ozderya.net
bar plot experimental implementation
5 files changed with 93 insertions and 0 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -134,6 +134,7 @@ add_executable(${PROGRAM_NAME} WIN32
 
  src/framedreader.cpp
 
  src/framedreadersettings.cpp
 
  src/plotmanager.cpp
 
  src/barplot.cpp
 
  src/numberformat.cpp
 
  src/updatechecker.cpp
 
  src/versionnumber.cpp
src/barplot.cpp
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "barplot.h"
 

	
 
BarPlot::BarPlot(ChannelManager* channelMan, QWidget* parent) :
 
    QwtPlot(parent)
 
{
 
    _channelMan = channelMan;
 
    barChart.attach(this);
 

	
 
    connect(_channelMan, &ChannelManager::dataAdded, [this]()
 
            {
 
                barChart.setSamples(chartData());
 
                replot();
 
            });
 
}
 

	
 
QVector<double> BarPlot::chartData() const
 
{
 
    unsigned numChannels = _channelMan->numOfChannels();
 
    unsigned numOfSamples = _channelMan->numOfSamples();
 
    QVector<double> data(numChannels);
 
    for (int i = 0; i < numChannels; i++)
 
    {
 
        data[i] = _channelMan->channelBuffer(i)->sample(numOfSamples-1);
 
    }
 
    return data;
 
}
src/barplot.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2017 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU General Public License for more details.
 

	
 
  You should have received a copy of the GNU General Public License
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef BARPLOT_H
 
#define BARPLOT_H
 

	
 
#include <qwt_plot.h>
 
#include <qwt_plot_barchart.h>
 

	
 
#include "channelmanager.h"
 

	
 
class BarPlot : public QwtPlot
 
{
 
    Q_OBJECT
 

	
 
public:
 
    explicit BarPlot(ChannelManager* channelMan, QWidget* parent = 0);
 

	
 
private:
 
    QwtPlotBarChart barChart;
 
    ChannelManager* _channelMan;
 

	
 
    QVector<double> chartData() const;
 
};
 

	
 
#endif // BARPLOT_H
src/mainwindow.cpp
Show inline comments
 
@@ -63,6 +63,7 @@ MainWindow::MainWindow(QWidget *parent) 
 
    snapshotMan(this, &channelMan),
 
    commandPanel(&serialPort),
 
    dataFormatPanel(&serialPort, &channelMan, &recorder),
 
    barPlot(&channelMan),
 
    recordPanel(&recorder, &channelMan),
 
    updateCheckDialog(this)
 
{
 
@@ -264,6 +265,8 @@ MainWindow::MainWindow(QWidget *parent) 
 
                this->ui->tabWidget->setCurrentWidget(&commandPanel);
 
                this->ui->tabWidget->showTabs();
 
            });
 

	
 
    barPlot.show();
 
}
 

	
 
MainWindow::~MainWindow()
src/mainwindow.h
Show inline comments
 
@@ -44,6 +44,7 @@
 
#include "channelmanager.h"
 
#include "snapshotmanager.h"
 
#include "plotmanager.h"
 
#include "barplot.h"
 
#include "datarecorder.h"
 
#include "updatecheckdialog.h"
 

	
 
@@ -78,6 +79,7 @@ private:
 
    QList<QwtPlotCurve*> curves;
 
    ChannelManager channelMan;
 
    PlotManager* plotMan;
 
    BarPlot barPlot;
 
    SnapshotManager snapshotMan;
 
    DataRecorder recorder;       // operated by `recordPanel`
 

	
0 comments (0 inline, 0 general)