# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2018-12-16 13:30:18 # Node ID 262f56d3e063189e904be729a8767fd9a99259d2 # Parent f7670384fcb072dbe52ede5b5d9bc688470dd530 support multi plot and channel visibility for value tracker diff --git a/src/plot.cpp b/src/plot.cpp --- a/src/plot.cpp +++ b/src/plot.cpp @@ -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 channels) +{ + zoomer.setDispChannels(channels); +} + void Plot::setYAxis(bool autoScaled, double yAxisMin, double yAxisMax) { this->isAutoScaled = autoScaled; diff --git a/src/plot.h b/src/plot.h --- a/src/plot.h +++ b/src/plot.h @@ -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 channels); + public slots: void showGrid(bool show = true); void showMinorGrid(bool show = true); diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -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(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(1, _stream->channel(index))); } else { plot = plotWidgets[0]; + plot->setDispChannels(_stream->allChannels()); } // show the curve diff --git a/src/stream.cpp b/src/stream.cpp --- a/src/stream.cpp +++ b/src/stream.cpp @@ -87,6 +87,16 @@ StreamChannel* Stream::channel(unsigned return const_cast(static_cast(*this).channel(index)); } +QVector Stream::allChannels() const +{ + QVector result(numChannels()); + for (unsigned ci = 0; ci < numChannels(); ci++) + { + result[ci] = channel(ci); + } + return result; +} + const ChannelInfoModel* Stream::infoModel() const { return &_infoModel; diff --git a/src/stream.h b/src/stream.h --- a/src/stream.h +++ b/src/stream.h @@ -57,6 +57,7 @@ public: unsigned numSamples() const; const StreamChannel* channel(unsigned index) const; StreamChannel* channel(unsigned index); + QVector allChannels() const; const ChannelInfoModel* infoModel() const; ChannelInfoModel* infoModel(); diff --git a/src/zoomer.cpp b/src/zoomer.cpp --- a/src/zoomer.cpp +++ b/src/zoomer.cpp @@ -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 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 Zoomer::findValues(double x) const { - // TODO: process only channel(s) of this plot - unsigned nc = _stream->numChannels(); - QVector r(nc); + unsigned nc = dispChannels.length(); + QVector 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 diff --git a/src/zoomer.h b/src/zoomer.h --- a/src/zoomer.h +++ b/src/zoomer.h @@ -24,16 +24,18 @@ #include #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 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 dispChannels; /// Draw sample values void drawValues(QPainter* painter) const;