Changeset - 2b91fa46c0df
[Not reviewed]
barplot
0 4 2
Hasan Yavuz ÖZDERYA - 8 years ago 2017-10-03 06:04:32
hy@ozderya.net
show channel colors
6 files changed with 111 insertions and 17 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -132,12 +132,13 @@ add_executable(${PROGRAM_NAME} WIN32
 
  src/asciireadersettings.cpp
 
  src/demoreader.cpp
 
  src/framedreader.cpp
 
  src/framedreadersettings.cpp
 
  src/plotmanager.cpp
 
  src/barplot.cpp
 
  src/barchart.cpp
 
  src/numberformat.cpp
 
  src/updatechecker.cpp
 
  src/versionnumber.cpp
 
  src/updatecheckdialog.cpp
 
  misc/windows_icon.rc
 
  ${UI_FILES}
src/barchart.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 <QPalette>
 

	
 
#include "barchart.h"
 

	
 
BarChart::BarChart(ChannelManager* channelMan)
 
{
 
    _channelMan = channelMan;
 
}
 

	
 
void BarChart::resample()
 
{
 
    setSamples(chartData());
 
}
 

	
 
QVector<double> BarChart::chartData() const
 
{
 
    unsigned numChannels = _channelMan->numOfChannels();
 
    unsigned numOfSamples = _channelMan->numOfSamples();
 
    QVector<double> data(numChannels);
 
    for (unsigned i = 0; i < numChannels; i++)
 
    {
 
        data[i] = _channelMan->channelBuffer(i)->sample(numOfSamples-1);
 
    }
 
    return data;
 
}
 

	
 
QwtColumnSymbol* BarChart::specialSymbol(int sampleIndex, const QPointF& sample) const
 
{
 
    unsigned numChannels = _channelMan->numOfChannels();
 
    if (sampleIndex < 0 || sampleIndex > (int) numChannels)
 
    {
 
        return NULL;
 
    }
 

	
 
    auto info = _channelMan->infoModel();
 
    auto color = info->color(sampleIndex);
 

	
 
    QwtColumnSymbol* symbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
 
    symbol->setLineWidth(1);
 
    symbol->setFrameStyle(QwtColumnSymbol::Plain);
 
    symbol->setPalette(QPalette(color));
 

	
 
    return symbol;
 
}
src/barchart.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 BARCHART_H
 
#define BARCHART_H
 

	
 
#include <qwt_plot_barchart.h>
 
#include <qwt_column_symbol.h>
 
#include "channelmanager.h"
 

	
 
class BarChart : public QwtPlotBarChart
 
{
 
public:
 
    explicit BarChart(ChannelManager* channelMan);
 

	
 
    void resample();
 
    QwtColumnSymbol* specialSymbol(int sampleIndex, const QPointF&) const;
 

	
 
private:
 
    ChannelManager* _channelMan;
 

	
 
    QVector<double> chartData() const;
 
};
 

	
 

	
 
#endif // BARCHART_H
src/barplot.cpp
Show inline comments
 
@@ -17,29 +17,17 @@
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "barplot.h"
 

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

	
 
    connect(_channelMan, &ChannelManager::dataAdded, [this]()
 
            {
 
                barChart.setSamples(chartData());
 
                barChart.resample();
 
                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
 
@@ -18,25 +18,25 @@
 
*/
 

	
 
#ifndef BARPLOT_H
 
#define BARPLOT_H
 

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

	
 
#include "channelmanager.h"
 
#include "barchart.h"
 

	
 
class BarPlot : public QwtPlot
 
{
 
    Q_OBJECT
 

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

	
 
private:
 
    QwtPlotBarChart barChart;
 
    ChannelManager* _channelMan;
 
    BarChart barChart;
 

	
 
    QVector<double> chartData() const;
 
};
 

	
 
#endif // BARPLOT_H
src/mainwindow.cpp
Show inline comments
 
@@ -57,16 +57,16 @@ const QMap<int, QString> panelSettingMap
 
MainWindow::MainWindow(QWidget *parent) :
 
    QMainWindow(parent),
 
    ui(new Ui::MainWindow),
 
    aboutDialog(this),
 
    portControl(&serialPort),
 
    channelMan(1, 1, this),
 
    barPlot(&channelMan),
 
    snapshotMan(this, &channelMan),
 
    commandPanel(&serialPort),
 
    dataFormatPanel(&serialPort, &channelMan, &recorder),
 
    barPlot(&channelMan),
 
    recordPanel(&recorder, &channelMan),
 
    updateCheckDialog(this)
 
{
 
    ui->setupUi(this);
 

	
 
    plotMan = new PlotManager(ui->plotArea, channelMan.infoModel());
0 comments (0 inline, 0 general)