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
 
@@ -28,16 +28,14 @@ BarPlot::BarPlot(ChannelManager* channel
 
    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
 
@@ -24,29 +24,28 @@
 
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
 
@@ -29,14 +29,11 @@
 
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)