Changeset - 262f56d3e063
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 7 years ago 2018-12-16 13:30:18
hy@ozderya.net
support multi plot and channel visibility for value tracker
7 files changed with 57 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/plot.cpp
Show inline comments
 
@@ -31,9 +31,9 @@
 
static const int SYMBOL_SHOW_AT_WIDTH = 5;
 
static const int SYMBOL_SIZE_MAX = 7;
 

	
 
Plot::Plot(const Stream* stream, QWidget* parent) :
 
Plot::Plot(QWidget* parent) :
 
    QwtPlot(parent),
 
    zoomer(this->canvas(), stream, false),
 
    zoomer(this->canvas(), false),
 
    sZoomer(this, &zoomer)
 
{
 
    isAutoScaled = true;
 
@@ -91,6 +91,11 @@ Plot::~Plot()
 
    if (snapshotOverlay != NULL) delete snapshotOverlay;
 
}
 

	
 
void Plot::setDispChannels(QVector<const StreamChannel*> channels)
 
{
 
    zoomer.setDispChannels(channels);
 
}
 

	
 
void Plot::setYAxis(bool autoScaled, double yAxisMin, double yAxisMax)
 
{
 
    this->isAutoScaled = autoScaled;
src/plot.h
Show inline comments
 
@@ -47,9 +47,12 @@ public:
 
        ShowSymbolsHide
 
    };
 

	
 
    Plot(const Stream* stream, QWidget* parent = 0);
 
    Plot(QWidget* parent = 0);
 
    ~Plot();
 

	
 
    /// Set displayed channels for value tracking (can be null)
 
    void setDispChannels(QVector<const StreamChannel*> channels);
 

	
 
public slots:
 
    void showGrid(bool show = true);
 
    void showMinorGrid(bool show = true);
src/plotmanager.cpp
Show inline comments
 
@@ -54,7 +54,6 @@ PlotManager::PlotManager(QWidget* plotAr
 
    {
 
        addCurve(stream->channel(i)->name(), stream->channel(i)->xData(), stream->channel(i)->yData());
 
    }
 

	
 
}
 

	
 
PlotManager::PlotManager(QWidget* plotArea, PlotMenu* menu,
 
@@ -94,8 +93,6 @@ void PlotManager::construct(QWidget* plo
 
    // initalize layout and single widget
 
    isMulti = false;
 
    scrollArea = NULL;
 
    setupLayout(isMulti);
 
    addPlotWidget();
 

	
 
    // connect to  menu
 
    connect(menu, &PlotMenu::symbolShowChanged, this, &PlotManager:: setSymbols);
 
@@ -217,8 +214,6 @@ void PlotManager::checkNoVisChannels()
 

	
 
void PlotManager::setMulti(bool enabled)
 
{
 
    if (enabled == isMulti) return;
 

	
 
    isMulti = enabled;
 

	
 
    // detach all curves
 
@@ -239,11 +234,14 @@ void PlotManager::setMulti(bool enabled)
 
    if (isMulti)
 
    {
 
        // add new widgets and attach
 
        int i = 0;
 
        for (auto curve : curves)
 
        {
 
            auto plot = addPlotWidget();
 
            plot->setVisible(curve->isVisible());
 
            plot->setDispChannels(QVector<const StreamChannel*>(1, _stream->channel(i)));
 
            curve->attach(plot);
 
            i++;
 
        }
 
    }
 
    else
 
@@ -251,6 +249,11 @@ void PlotManager::setMulti(bool enabled)
 
        // add a single widget
 
        auto plot = addPlotWidget();
 

	
 
        if (_stream != nullptr)
 
        {
 
            plot->setDispChannels(_stream->allChannels());
 
        }
 

	
 
        // attach all curves
 
        for (auto curve : curves)
 
        {
 
@@ -305,7 +308,7 @@ void PlotManager::setupLayout(bool multi
 

	
 
Plot* PlotManager::addPlotWidget()
 
{
 
    auto plot = new Plot(_stream);
 
    auto plot = new Plot();
 
    plotWidgets.append(plot);
 
    layout->addWidget(plot);
 

	
 
@@ -355,10 +358,12 @@ void PlotManager::_addCurve(QwtPlotCurve
 
    {
 
        // create a new plot widget
 
        plot = addPlotWidget();
 
        plot->setDispChannels(QVector<const StreamChannel*>(1, _stream->channel(index)));
 
    }
 
    else
 
    {
 
        plot = plotWidgets[0];
 
        plot->setDispChannels(_stream->allChannels());
 
    }
 

	
 
    // show the curve
src/stream.cpp
Show inline comments
 
@@ -87,6 +87,16 @@ StreamChannel* Stream::channel(unsigned 
 
    return const_cast<StreamChannel*>(static_cast<const Stream&>(*this).channel(index));
 
}
 

	
 
QVector<const StreamChannel*> Stream::allChannels() const
 
{
 
    QVector<const StreamChannel*> result(numChannels());
 
    for (unsigned ci = 0; ci < numChannels(); ci++)
 
    {
 
        result[ci] = channel(ci);
 
    }
 
    return result;
 
}
 

	
 
const ChannelInfoModel* Stream::infoModel() const
 
{
 
    return &_infoModel;
src/stream.h
Show inline comments
 
@@ -57,6 +57,7 @@ public:
 
    unsigned numSamples() const;
 
    const StreamChannel* channel(unsigned index) const;
 
    StreamChannel* channel(unsigned index);
 
    QVector<const StreamChannel*> allChannels() const;
 
    const ChannelInfoModel* infoModel() const;
 
    ChannelInfoModel* infoModel();
 

	
src/zoomer.cpp
Show inline comments
 
@@ -26,11 +26,10 @@
 
static const int VALUE_POINT_DIAM = 4;
 
static const int VALUE_TEXT_MARGIN = VALUE_POINT_DIAM + 2;
 

	
 
Zoomer::Zoomer(QWidget* widget, const Stream* stream, bool doReplot) :
 
Zoomer::Zoomer(QWidget* widget, bool doReplot) :
 
    ScrollZoomer(widget)
 
{
 
    is_panning = false;
 
    _stream = stream;
 

	
 
    setTrackerMode(AlwaysOn);
 

	
 
@@ -63,6 +62,11 @@ void Zoomer::zoom( const QRectF & rect)
 
    ScrollZoomer::zoom(rect);
 
}
 

	
 
void Zoomer::setDispChannels(QVector<const StreamChannel*> channels)
 
{
 
    dispChannels = channels;
 
}
 

	
 
QwtText Zoomer::trackerTextF(const QPointF& pos) const
 
{
 
    QwtText b = ScrollZoomer::trackerTextF(pos);
 
@@ -112,7 +116,7 @@ void Zoomer::drawTracker(QPainter* paint
 
    {
 
        QwtPlotZoomer::drawTracker(painter);
 
    }
 
    else if (_stream != nullptr && _stream->numChannels())
 
    else if (dispChannels.length())
 
    {
 
        drawValues(painter);
 
    }
 
@@ -136,12 +140,14 @@ void Zoomer::drawValues(QPainter* painte
 
    // draw sample values
 
    for (int ci = 0; ci < values.size(); ci++)
 
    {
 
        if (!dispChannels[ci]->visible()) continue;
 

	
 
        double val = values[ci];
 
        if (!std::isnan(val))
 
        {
 
            auto p = transform(QPointF(x, val));
 

	
 
            painter->setBrush(_stream->channel(ci)->color());
 
            painter->setBrush(dispChannels[ci]->color());
 
            painter->setPen(Qt::NoPen);
 
            painter->drawEllipse(p, VALUE_POINT_DIAM, VALUE_POINT_DIAM);
 

	
 
@@ -158,16 +164,17 @@ void Zoomer::drawValues(QPainter* painte
 

	
 
QVector<double> Zoomer::findValues(double x) const
 
{
 
    // TODO: process only channel(s) of this plot
 
    unsigned nc = _stream->numChannels();
 
    QVector<double> r(nc);
 
    unsigned nc = dispChannels.length();
 
    QVector<double> result(nc);
 
    for (unsigned ci = 0; ci < nc; ci++)
 
    {
 
        auto chan = _stream->channel(ci);
 
        double val = chan->findValue(x);
 
        r[ci] = val;
 
        if (dispChannels[ci]->visible())
 
        {
 
            result[ci] = dispChannels[ci]->findValue(x);
 
        }
 

	
 
    }
 
    return r;
 
    return result;
 
}
 

	
 
QRect Zoomer::trackerRect(const QFont& font) const
src/zoomer.h
Show inline comments
 
@@ -24,16 +24,18 @@
 
#include <QRect>
 

	
 
#include "scrollzoomer.h"
 
#include "stream.h"
 
#include "streamchannel.h"
 

	
 
class Zoomer : public ScrollZoomer
 
{
 
    Q_OBJECT
 

	
 
public:
 
    Zoomer(QWidget*, const Stream* stream, bool doReplot=true);
 
    Zoomer(QWidget*, bool doReplot=true);
 
    void zoom(int up);
 
    void zoom(const QRectF&);
 
    /// Set displayed channels for value tracking (can be null)
 
    void setDispChannels(QVector<const StreamChannel*> channels);
 

	
 
signals:
 
    void unzoomed();
 
@@ -59,7 +61,8 @@ protected:
 
private:
 
    bool is_panning;
 
    QPointF pan_point;
 
    const Stream* _stream;
 
    /// displayed channels for value tracking
 
    QVector<const StreamChannel*> dispChannels;
 

	
 
    /// Draw sample values
 
    void drawValues(QPainter* painter) const;
0 comments (0 inline, 0 general)