Changeset - c901d5cbc093
[Not reviewed]
barplot
0 3 0
Hasan Yavuz Ă–ZDERYA - 8 years ago 2017-10-05 08:52:44
hy@ozderya.net
slight code reduction
3 files changed with 6 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/barplot.cpp
Show inline comments
 
@@ -22,22 +22,20 @@
 

	
 
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
 
@@ -18,35 +18,34 @@
 
*/
 

	
 
#include "barscaledraw.h"
 

	
 
#include <QtDebug>
 

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

	
 
    QObject::connect(_channelMan, &ChannelManager::channelNameChanged,
 
            [this]()
 
            {
 
                invalidateCache();
 
            });
 
}
 

	
 
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
 
@@ -23,20 +23,17 @@
 
#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)