Changeset - 2de781e96b6e
[Not reviewed]
barplot
0 2 2
Hasan Yavuz ÖZDERYA - 8 years ago 2017-10-03 08:29:24
hy@ozderya.net
show channel names in x axis
4 files changed with 102 insertions and 0 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -136,6 +136,7 @@ add_executable(${PROGRAM_NAME} WIN32
 
  src/plotmanager.cpp
 
  src/barplot.cpp
 
  src/barchart.cpp
 
  src/barscaledraw.cpp
 
  src/numberformat.cpp
 
  src/updatechecker.cpp
 
  src/versionnumber.cpp
src/barplot.cpp
Show inline comments
 
@@ -18,19 +18,26 @@
 
*/
 

	
 
#include "barplot.h"
 
#include "barscaledraw.h"
 

	
 
BarPlot::BarPlot(ChannelManager* channelMan, QWidget* parent) :
 
    QwtPlot(parent), barChart(channelMan)
 
{
 
    _channelMan = channelMan;
 
    barChart.attach(this);
 
    setAxisMaxMinor(QwtPlot::xBottom, 0);
 
    setAxisScaleDraw(QwtPlot::xBottom, new BarScaleDraw(channelMan));
 

	
 
    update();
 
    connect(_channelMan, &ChannelManager::dataAdded, this, &BarPlot::update);
 
    connect(_channelMan, &ChannelManager::numOfChannelsChanged, this, &BarPlot::update);
 
    connect(_channelMan, &ChannelManager::channelNameChanged, this, &BarPlot::update);
 
}
 

	
 
void BarPlot::update()
 
{
 
    setAxisScale(QwtPlot::xBottom, 0, _channelMan->numOfChannels(), 1);
 
    static_cast<BarScaleDraw*>(axisScaleDraw(QwtPlot::xBottom))->updateLabels();
 
    barChart.resample();
 
    replot();
 
}
src/barscaledraw.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 "barscaledraw.h"
 

	
 
#include <QtDebug>
 

	
 
BarScaleDraw::BarScaleDraw(ChannelManager* channelMan)
 
{
 
    _channelMan = channelMan;
 
    enableComponent(Backbone, false);
 
    setLabelRotation(-90);
 
    setLabelAlignment(Qt::AlignLeft | Qt::AlignVCenter);
 
}
 

	
 
QwtText BarScaleDraw::label(double value) const
 
{
 
    int index = value;
 
    unsigned numChannels = _channelMan->numOfChannels();
 

	
 
    qDebug() << index;
 

	
 
    if (index >=0 && index < (int) numChannels)
 
    {
 
        return _channelMan->channelName(index);
 
    }
 
    else
 
    {
 
        return QString("");
 
    }
 
}
 

	
 
void BarScaleDraw::updateLabels()
 
{
 
    invalidateCache();
 
}
src/barscaledraw.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 BARSCALEDRAW_H
 
#define BARSCALEDRAW_H
 

	
 
#include <QStringList>
 
#include <qwt_scale_draw.h>
 
#include <qwt_text.h>
 

	
 
#include "channelmanager.h"
 

	
 
class BarScaleDraw : public QwtScaleDraw
 
{
 
public:
 
    explicit BarScaleDraw(ChannelManager* channelMan);
 
    QwtText label(double value) const;
 

	
 
public slots:
 
    void updateLabels();
 

	
 
private:
 
    ChannelManager* _channelMan;
 
};
 

	
 
#endif // BARSCALEDRAW_H
0 comments (0 inline, 0 general)