From f89cbf71516948eab583eef7d2a994478af89a9c Mon Sep 17 00:00:00 2001 From: Bryant Date: Tue, 4 Jun 2013 11:20:22 -0700 Subject: [PATCH] Further consolidation of Plot code into ChartPlot. Also removed some unused variables from LinechartWidget.cc. Also only active curves are recolored in the IncrementalPlot class. --- src/ui/linechart/ChartPlot.cc | 36 +++++++++++++--------- src/ui/linechart/ChartPlot.h | 5 +++ src/ui/linechart/IncrementalPlot.cc | 10 +----- src/ui/linechart/IncrementalPlot.h | 5 --- src/ui/linechart/LinechartPlot.cc | 48 +++++++++-------------------- src/ui/linechart/LinechartPlot.h | 16 +++++----- src/ui/linechart/LinechartWidget.cc | 3 -- src/ui/linechart/LinechartWidget.h | 3 +- 8 files changed, 49 insertions(+), 77 deletions(-) diff --git a/src/ui/linechart/ChartPlot.cc b/src/ui/linechart/ChartPlot.cc index d78258a7a..71bee45c3 100644 --- a/src/ui/linechart/ChartPlot.cc +++ b/src/ui/linechart/ChartPlot.cc @@ -26,12 +26,15 @@ const QColor ChartPlot::baseColors[numColors] = { ChartPlot::ChartPlot(QWidget *parent): QwtPlot(parent), - nextColorIndex(0)/*, + nextColorIndex(0), symbolWidth(1.2f), - curveWidth(1.0f), + curveWidth(2.0f), gridWidth(0.8f), - scaleWidth(1.0f)*/ + zoomerWidth(3.0f) { + // Initialize the list of curves. + curves = QMap(); + // Set the grid. The colorscheme was already set in generateColorScheme(). grid = new QwtPlotGrid; grid->enableXMin(true); @@ -80,52 +83,55 @@ void ChartPlot::shuffleColors() { foreach (QwtPlotCurve* curve, curves) { - QPen pen(curve->pen()); - pen.setColor(getNextColor()); - curve->setPen(pen); + if (curve->isVisible()) { + QPen pen(curve->pen()); + pen.setColor(getNextColor()); + curve->setPen(pen); + } } } void ChartPlot::applyColorScheme(MainWindow::QGC_MAINWINDOW_STYLE style) { - // Generate the color list for curves + // Generate a new color list for curves and recolor them. for (int i = 0; i < numColors; ++i) { if (style == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT) { -// colors[i] = baseColors[i].lighter(150); + colors[i] = baseColors[i].lighter(150); } else { -// colors[i] = baseColors[i].darker(150); + colors[i] = baseColors[i].darker(150); } } + shuffleColors(); // Configure the rest of the UI colors based on the current theme. if (style == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT) { // Set the coloring of the area selector for zooming. - zoomer->setRubberBandPen(QPen(Qt::darkRed, 3.0f, Qt::DotLine)); + zoomer->setRubberBandPen(QPen(Qt::darkRed, zoomerWidth, Qt::DotLine)); zoomer->setTrackerPen(QPen(Qt::darkRed)); // Set canvas background setCanvasBackground(QColor(0xFF, 0xFF, 0xFF)); // Configure the plot grid. - grid->setMinPen(QPen(QColor(0x55, 0x55, 0x55), 0.8f, Qt::DotLine)); - grid->setMajPen(QPen(QColor(0x22, 0x22, 0x22), 0.8f, Qt::DotLine)); + grid->setMinPen(QPen(QColor(0x55, 0x55, 0x55), gridWidth, Qt::DotLine)); + grid->setMajPen(QPen(QColor(0x22, 0x22, 0x22), gridWidth, Qt::DotLine)); } else { // Set the coloring of the area selector for zooming. - zoomer->setRubberBandPen(QPen(Qt::red, 3.0f, Qt::DotLine)); + zoomer->setRubberBandPen(QPen(Qt::red, zoomerWidth, Qt::DotLine)); zoomer->setTrackerPen(QPen(Qt::red)); // Set canvas background setCanvasBackground(QColor(0, 0, 0)); // Configure the plot grid. - grid->setMinPen(QPen(QColor(0xAA, 0xAA, 0xAA), 0.8f, Qt::DotLine)); - grid->setMajPen(QPen(QColor(0xDD, 0xDD, 0xDD), 0.8f, Qt::DotLine)); + grid->setMinPen(QPen(QColor(0xAA, 0xAA, 0xAA), gridWidth, Qt::DotLine)); + grid->setMajPen(QPen(QColor(0xDD, 0xDD, 0xDD), gridWidth, Qt::DotLine)); } // And finally refresh the widget to make sure all color changes are redrawn. diff --git a/src/ui/linechart/ChartPlot.h b/src/ui/linechart/ChartPlot.h index 56d5b0071..cef45096e 100644 --- a/src/ui/linechart/ChartPlot.h +++ b/src/ui/linechart/ChartPlot.h @@ -31,6 +31,11 @@ protected: ScrollZoomer* zoomer; ///< Zoomer class for widget QwtPlotGrid* grid; ///< Plot grid + float symbolWidth; ///< Width of curve symbols in pixels + float curveWidth; ///< Width of curve lines in pixels + float gridWidth; ///< Width of gridlines in pixels + float zoomerWidth; ///< Width of zoomer selection box + protected slots: /** @brief Generate coloring for this plot canvas based on current window theme */ diff --git a/src/ui/linechart/IncrementalPlot.cc b/src/ui/linechart/IncrementalPlot.cc index 5da648a73..6ef4c4375 100644 --- a/src/ui/linechart/IncrementalPlot.cc +++ b/src/ui/linechart/IncrementalPlot.cc @@ -85,10 +85,6 @@ const double* CurveData::y() const IncrementalPlot::IncrementalPlot(QWidget *parent): ChartPlot(parent), - symbolWidth(1.2f), - curveWidth(1.0f), - gridWidth(0.8f), - scaleWidth(1.0f), symmetric(false) { setAutoReplot(false); @@ -96,10 +92,6 @@ IncrementalPlot::IncrementalPlot(QWidget *parent): plotLayout()->setAlignCanvasToScales(true); - grid = new QwtPlotGrid; - grid->setMajPen(QPen(Qt::gray, 0.8f, Qt::DotLine)); - grid->attach(this); - QwtLinearScaleEngine* yScaleEngine = new QwtLinearScaleEngine(); setAxisScaleEngine(QwtPlot::yLeft, yScaleEngine); @@ -280,7 +272,7 @@ void IncrementalPlot::appendData(QString key, double *x, double *y, int size) const QColor &c = getNextColor(); curve->setSymbol(QwtSymbol(QwtSymbol::XCross, - QBrush(c), QPen(c, 1.2f), QSize(5, 5)) ); + QBrush(c), QPen(c, symbolWidth), QSize(5, 5)) ); curve->attach(this); } else { diff --git a/src/ui/linechart/IncrementalPlot.h b/src/ui/linechart/IncrementalPlot.h index bce6925bd..06dee02ff 100644 --- a/src/ui/linechart/IncrementalPlot.h +++ b/src/ui/linechart/IncrementalPlot.h @@ -86,11 +86,6 @@ public: /** @brief Read out data from a curve */ int data(QString key, double* r_x, double* r_y, int maxSize); - float symbolWidth; - float curveWidth; - float gridWidth; - float scaleWidth; - public slots: /** @brief Append one data point */ void appendData(QString key, double x, double y); diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 5e677818f..098f451fe 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -54,7 +54,6 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval): //lastMaxTimeAdded = QTime(); - curves = QMap(); data = QMap(); scaleMaps = QMap(); @@ -63,14 +62,6 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval): setAutoReplot(false); - // Set grid - QwtPlotGrid *grid = new QwtPlotGrid; - grid->setMinPen(QPen(Qt::darkGray, 0, Qt::DotLine)); - grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine)); - grid->enableXMin(true); - // TODO xmin? - grid->attach(this); - // Set left scale //setAxisOptions(QwtPlot::yLeft, QwtAutoScale::Logarithmic); @@ -87,15 +78,6 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval): plotLayout()->setAlignCanvasToScales(true); - // Set canvas background - setCanvasBackground(QColor(40, 40, 40)); - - // Enable zooming - //zoomer = new Zoomer(canvas()); - zoomer = new ScrollZoomer(canvas()); - zoomer->setRubberBandPen(QPen(Qt::blue, 1.2, Qt::DotLine)); - zoomer->setTrackerPen(QPen(Qt::blue)); - // Start QTimer for plot update updateTimer = new QTimer(this); connect(updateTimer, SIGNAL(timeout()), this, SLOT(paintRealtime())); @@ -400,22 +382,6 @@ quint64 LinechartPlot::getWindowPosition() return plotPosition; } -/** - * @brief Set the color of a curve - * - * This method emits the colorSet(id, color) signal. - * - * @param id The id-string of the curve - * @param color The newly assigned color - **/ -void LinechartPlot::setCurveColor(QString id, QColor color) -{ - QwtPlotCurve* curve = curves.value(id); - curve->setPen(color); - - emit colorSet(id, color); -} - /** * @brief Set the scaling of the (vertical) y axis * The mapping of the variable values on the drawing pane can be @@ -495,6 +461,20 @@ void LinechartPlot::showCurve(QString id) // curves.value(id)->show(); //} +/** + * @brief Set the color of a curve + * + * This method emits the colorSet(id, color) signal. + * + * @param id The id-string of the curve + * @param color The newly assigned color + **/ +void LinechartPlot::setCurveColor(QString id, QColor color) +{ + QwtPlotCurve* curve = curves.value(id); + curve->setPen(color); +} + /** * @brief Check the visibility of a curve * diff --git a/src/ui/linechart/LinechartPlot.h b/src/ui/linechart/LinechartPlot.h index 6c6e16a1c..66af4d2ce 100644 --- a/src/ui/linechart/LinechartPlot.h +++ b/src/ui/linechart/LinechartPlot.h @@ -175,7 +175,6 @@ public: quint64 getPlotInterval(); quint64 getDataInterval(); quint64 getWindowPosition(); - QList getColorMap(); /** @brief Get the short-term mean of a curve */ double getMean(QString id); @@ -215,7 +214,13 @@ public slots: // Functions referring to the currently active plot void setVisible(QString id, bool visible); - //void showCurve(QString id, int position); + + /** + * @brief Set the color of a curve + * + * @param id The id-string of the curve + * @param color The newly assigned color + **/ void setCurveColor(QString id, QColor color); /** @brief Enforce the use of the receive timestamp */ @@ -291,13 +296,6 @@ signals: * @param color The curve color in the diagram **/ void curveAdded(QString idstring); - /** - * @brief This signal is emitted when a curve gets assigned a color - * - * @param idstring The id-string of the curve - * @param color The curve color in the diagram - **/ - void colorSet(QString idstring, QColor color); /** * @brief This signal is emitted when a curve is removed * diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index eb6600eaf..ccd64f98b 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -61,7 +61,6 @@ LinechartWidget::LinechartWidget(int systemid, QWidget *parent) : QWidget(parent plotWindowLock(), curveListIndex(0), curveListCounter(0), - listedCurves(new QList()), curveLabels(new QMap()), curveMeans(new QMap()), curveMedians(new QMap()), @@ -154,8 +153,6 @@ LinechartWidget::~LinechartWidget() stopLogging(); if (activePlot) delete activePlot; activePlot = NULL; - delete listedCurves; - listedCurves = NULL; } void LinechartWidget::selectActiveSystem(int mav) diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index 3e57975c7..a775c303f 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -95,7 +95,7 @@ public slots: void appendData(int uasId, const QString& curve, const QString& unit, quint64 value, quint64 usec); /** @brief Append double data to the given curve. */ void appendData(int uasId, const QString& curve, const QString& unit, double value, quint64 usec); - + void takeButtonClick(bool checked); void setPlotWindowPosition(int scrollBarValue); void setPlotWindowPosition(quint64 position); @@ -138,7 +138,6 @@ protected: int curveListIndex; int curveListCounter; ///< Counter of curves in curve list - QList* listedCurves; ///< Curves listed QMap* curveLabels; ///< References to the curve labels QMap curveNameLabels; ///< References to the curve labels QMap curveNames; ///< Full curve names -- 2.22.0