From 0e6411c7adc876218155c2e2b0668bc477c4a259 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Sat, 19 Oct 2013 16:19:49 +0100 Subject: [PATCH] Fix setStyleText() to apply to future curves --- src/ui/linechart/IncrementalPlot.cc | 63 ++++++++++++++++------------- src/ui/linechart/IncrementalPlot.h | 6 ++- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/ui/linechart/IncrementalPlot.cc b/src/ui/linechart/IncrementalPlot.cc index 6a5e13f4d..5826d09d3 100644 --- a/src/ui/linechart/IncrementalPlot.cc +++ b/src/ui/linechart/IncrementalPlot.cc @@ -157,36 +157,43 @@ void IncrementalPlot::showLegend(bool show) */ void IncrementalPlot::setStyleText(const QString &style) { + styleText = style.toLower(); foreach (QwtPlotCurve* curve, curves) { - // Style of datapoints - if (style.toLower().contains("circles")) { - curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse, - Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) ); - } else if (style.toLower().contains("crosses")) { - curve->setSymbol(QwtSymbol(QwtSymbol::XCross, - Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(5, 5)) ); - } else if (style.toLower().contains("rect")) { - curve->setSymbol(QwtSymbol(QwtSymbol::Rect, - Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) ); - } else if (style.toLower().contains("line")) { // Show no symbol - curve->setSymbol(QwtSymbol(QwtSymbol::NoSymbol, - Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) ); - } + updateStyle(curve); + } + replot(); +} - // Style of lines - if (style.toLower().contains("dotted")) { - curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DotLine)); - } else if (style.toLower().contains("dashed")) { - curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DashLine)); - } else if (style.toLower().contains("line") || style.toLower().contains("solid")) { - curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::SolidLine)); - } else { - curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::NoPen)); - } - curve->setStyle(QwtPlotCurve::Lines); +void IncrementalPlot::updateStyle(QwtPlotCurve *curve) +{ + if(styleText.isNull()) + return; + // Style of datapoints + if (styleText.contains("circles")) { + curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse, + Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) ); + } else if (styleText.contains("crosses")) { + curve->setSymbol(QwtSymbol(QwtSymbol::XCross, + Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(5, 5)) ); + } else if (styleText.contains("rect")) { + curve->setSymbol(QwtSymbol(QwtSymbol::Rect, + Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) ); + } else if (styleText.contains("line")) { // Show no symbol + curve->setSymbol(QwtSymbol(QwtSymbol::NoSymbol, + Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) ); + } + // Style of lines + if (styleText.contains("dotted")) { + curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DotLine)); + } else if (styleText.contains("dashed")) { + curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DashLine)); + } else if (styleText.contains("line") || styleText.contains("solid")) { + curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::SolidLine)); + } else { + curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::NoPen)); } - replot(); + curve->setStyle(QwtPlotCurve::Lines); } void IncrementalPlot::resetScaling() @@ -275,7 +282,7 @@ void IncrementalPlot::appendData(const QString &key, double *x, double *y, int s const QColor &c = getNextColor(); curve->setSymbol(QwtSymbol(QwtSymbol::XCross, QBrush(c), QPen(c, symbolWidth), QSize(5, 5)) ); - + updateStyle(curve); //Apply any user-set style curve->attach(this); } else { curve = curves.value(key); @@ -374,7 +381,7 @@ void IncrementalPlot::showGrid(bool show) replot(); } -bool IncrementalPlot::gridEnabled() +bool IncrementalPlot::gridEnabled() const { return grid->isVisible(); } diff --git a/src/ui/linechart/IncrementalPlot.h b/src/ui/linechart/IncrementalPlot.h index 0b7f2d3b4..cb9784ee7 100644 --- a/src/ui/linechart/IncrementalPlot.h +++ b/src/ui/linechart/IncrementalPlot.h @@ -81,7 +81,7 @@ public: virtual ~IncrementalPlot(); /** @brief Get the state of the grid */ - bool gridEnabled(); + bool gridEnabled() const; /** @brief Read out data from a curve */ int data(const QString &key, double* r_x, double* r_y, int maxSize); @@ -125,10 +125,12 @@ protected: double xmax; ///< Maximum x value seen double ymin; ///< Minimum y value seen double ymax; ///< Maximum y value seen - + QString styleText; ///< Curve style set by setStyleText private: QMap d_data; ///< Data points + /** Helper function to apply styleText style to the given curve */ + void updateStyle(QwtPlotCurve *curve); }; #endif /* INCREMENTALPLOT_H */ -- 2.22.0