From ff6ecfe63f0a6f85fcb60e7a2a8f9062a896e245 Mon Sep 17 00:00:00 2001 From: Bryant Date: Wed, 25 Jun 2014 18:57:04 -0700 Subject: [PATCH] Now update QGC to use the new Qwt 6.1 code. I was unsure how to update the QwtPlotPrintFilter code, so I just commented it out with a FIXME. --- QGCExternalLibs.pri | 4 +- src/ui/QGCDataPlot2D.cc | 45 +++++++------- src/ui/RadioCalibration/CurveCalibrator.cc | 6 +- src/ui/RadioCalibration/CurveCalibrator.h | 1 - src/ui/designer/QGCXYPlot.cc | 7 +-- src/ui/linechart/ChartPlot.cc | 11 ++-- src/ui/linechart/IncrementalPlot.cc | 70 +++++++++++----------- src/ui/linechart/IncrementalPlot.h | 5 +- src/ui/linechart/LinechartPlot.cc | 42 +++++-------- src/ui/linechart/LinechartPlot.h | 2 +- src/ui/linechart/ScrollZoomer.h | 1 + 11 files changed, 91 insertions(+), 103 deletions(-) diff --git a/QGCExternalLibs.pri b/QGCExternalLibs.pri index ce80c1a78..cbd86a9c5 100644 --- a/QGCExternalLibs.pri +++ b/QGCExternalLibs.pri @@ -320,7 +320,9 @@ INCLUDEPATH += \ # # [REQUIRED] QWT plotting library dependency. Provides plotting capabilities. # -include(libs/qwt/qwt.pri) +include(libs/qwt.pri) +DEPENDPATH += libs/qwt +INCLUDEPATH += libs/qwt # # [REQUIRED] QSerialPort library. Provides serial port wrapper library. diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc index 4a24151a1..b8c15d175 100644 --- a/src/ui/QGCDataPlot2D.cc +++ b/src/ui/QGCDataPlot2D.cc @@ -172,19 +172,20 @@ void QGCDataPlot2D::print() if ( dialog.exec() ) { plot->setStyleSheet("QWidget { background-color: #FFFFFF; color: #000000; background-clip: border; font-size: 10pt;}"); plot->setCanvasBackground(Qt::white); - QwtPlotPrintFilter filter; - filter.color(Qt::white, QwtPlotPrintFilter::CanvasBackground); - filter.color(Qt::black, QwtPlotPrintFilter::AxisScale); - filter.color(Qt::black, QwtPlotPrintFilter::AxisTitle); - filter.color(Qt::black, QwtPlotPrintFilter::MajorGrid); - filter.color(Qt::black, QwtPlotPrintFilter::MinorGrid); - if ( printer.colorMode() == QPrinter::GrayScale ) { - int options = QwtPlotPrintFilter::PrintAll; - options &= ~QwtPlotPrintFilter::PrintBackground; - options |= QwtPlotPrintFilter::PrintFrameWithScales; - filter.setOptions(options); - } - plot->print(printer, filter); + // FIXME: QwtPlotPrintFilter no longer exists in Qwt 6.1 + //QwtPlotPrintFilter filter; + //filter.color(Qt::white, QwtPlotPrintFilter::CanvasBackground); + //filter.color(Qt::black, QwtPlotPrintFilter::AxisScale); + //filter.color(Qt::black, QwtPlotPrintFilter::AxisTitle); + //filter.color(Qt::black, QwtPlotPrintFilter::MajorGrid); + //filter.color(Qt::black, QwtPlotPrintFilter::MinorGrid); + //if ( printer.colorMode() == QPrinter::GrayScale ) { + // int options = QwtPlotPrintFilter::PrintAll; + // options &= ~QwtPlotPrintFilter::PrintBackground; + // options |= QwtPlotPrintFilter::PrintFrameWithScales; + // filter.setOptions(options); + //} + //plot->print(printer); plot->setStyleSheet("QWidget { background-color: #050508; color: #DDDDDF; background-clip: border; font-size: 11pt;}"); //plot->setCanvasBackground(QColor(5, 5, 8)); } @@ -210,6 +211,7 @@ void QGCDataPlot2D::exportPDF(QString fileName) plot->setStyleSheet("QWidget { background-color: #FFFFFF; color: #000000; background-clip: border; font-size: 10pt;}"); // plot->setCanvasBackground(Qt::white); + // FIXME: QwtPlotPrintFilter no longer exists in Qwt 6.1 // QwtPlotPrintFilter filter; // filter.color(Qt::white, QwtPlotPrintFilter::CanvasBackground); // filter.color(Qt::black, QwtPlotPrintFilter::AxisScale); @@ -223,7 +225,7 @@ void QGCDataPlot2D::exportPDF(QString fileName) // options |= QwtPlotPrintFilter::PrintFrameWithScales; // filter.setOptions(options); // } - plot->print(printer);//, filter); + //plot->print(printer); plot->setStyleSheet("QWidget { background-color: #050508; color: #DDDDDF; background-clip: border; font-size: 11pt;}"); //plot->setCanvasBackground(QColor(5, 5, 8)); } @@ -237,14 +239,15 @@ void QGCDataPlot2D::exportSVG(QString fileName) generator.setFileName(fileName); generator.setSize(QSize(800, 600)); - QwtPlotPrintFilter filter; - filter.color(Qt::white, QwtPlotPrintFilter::CanvasBackground); - filter.color(Qt::black, QwtPlotPrintFilter::AxisScale); - filter.color(Qt::black, QwtPlotPrintFilter::AxisTitle); - filter.color(Qt::black, QwtPlotPrintFilter::MajorGrid); - filter.color(Qt::black, QwtPlotPrintFilter::MinorGrid); + // FIXME: QwtPlotPrintFilter no longer exists in Qwt 6.1 + //QwtPlotPrintFilter filter; + //filter.color(Qt::white, QwtPlotPrintFilter::CanvasBackground); + //filter.color(Qt::black, QwtPlotPrintFilter::AxisScale); + //filter.color(Qt::black, QwtPlotPrintFilter::AxisTitle); + //filter.color(Qt::black, QwtPlotPrintFilter::MajorGrid); + //filter.color(Qt::black, QwtPlotPrintFilter::MinorGrid); - plot->print(generator, filter); + //plot->print(generator); plot->setStyleSheet("QWidget { background-color: #050508; color: #DDDDDF; background-clip: border; font-size: 11pt;}"); } } diff --git a/src/ui/RadioCalibration/CurveCalibrator.cc b/src/ui/RadioCalibration/CurveCalibrator.cc index 9ef8ec58b..5fb3d2456 100644 --- a/src/ui/RadioCalibration/CurveCalibrator.cc +++ b/src/ui/RadioCalibration/CurveCalibrator.cc @@ -42,7 +42,7 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) : set[i] = static_cast((*setpoints)[i]); } - curve->setData(pos, set); + curve->setSamples(pos, set); curve->attach(plot); plot->replot(); @@ -99,7 +99,7 @@ void CurveCalibrator::setSetpoint(int setpoint) set[i] = static_cast((*setpoints)[i]); } - curve->setData(pos, set); + curve->setSamples(pos, set); plot->replot(); emit setpointChanged(setpoint, setpoints->value(setpoint)); @@ -118,7 +118,7 @@ void CurveCalibrator::set(const QVector &data) pos[i] = static_cast((*positions)[i]); set[i] = static_cast((*setpoints)[i]); } - curve->setData(pos, set); + curve->setSamples(pos, set); plot->replot(); } else { qDebug() << __FILE__ << __LINE__ << ": wrong data vector size"; diff --git a/src/ui/RadioCalibration/CurveCalibrator.h b/src/ui/RadioCalibration/CurveCalibrator.h index 1f4c0b1e9..9a4dec922 100644 --- a/src/ui/RadioCalibration/CurveCalibrator.h +++ b/src/ui/RadioCalibration/CurveCalibrator.h @@ -34,7 +34,6 @@ This file is part of the QGROUNDCONTROL project #include #include #include -//#include #include #include #include diff --git a/src/ui/designer/QGCXYPlot.cc b/src/ui/designer/QGCXYPlot.cc index a258feedf..5df799a35 100644 --- a/src/ui/designer/QGCXYPlot.cc +++ b/src/ui/designer/QGCXYPlot.cc @@ -116,9 +116,8 @@ public: return QwtDoubleRect(xmin,ymin,xmax-xmin,ymax-ymin); } -protected: /* From QwtPlotItem. Draw the complete series */ - virtual void draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const + virtual void draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const { Q_UNUSED(canvasRect); QPointF lastPoint; @@ -151,7 +150,7 @@ protected: ++smoothCount; point = smoothTotal/smoothCount; } - QPointF paintCoord = QPointF(xMap.xTransform(point.x()), yMap.xTransform(point.y())); + QPointF paintCoord = QPointF(xMap.transform(point.x()), yMap.transform(point.y())); m_color.setAlpha((m_maxShowPoints - count + i)*255/m_maxShowPoints); p->setPen(m_color); if(i != 0) @@ -246,7 +245,7 @@ QGCXYPlot::~QGCXYPlot() void QGCXYPlot::clearPlot() { xycurve->clear(); - plot->clear(); + plot->detachItems(); ui->timeScrollBar->setMaximum(xycurve->dataSize()); ui->timeScrollBar->setValue(ui->timeScrollBar->maximum()); } diff --git a/src/ui/linechart/ChartPlot.cc b/src/ui/linechart/ChartPlot.cc index a1741f85c..e6d5b6db0 100644 --- a/src/ui/linechart/ChartPlot.cc +++ b/src/ui/linechart/ChartPlot.cc @@ -41,7 +41,8 @@ ChartPlot::ChartPlot(QWidget *parent): grid->attach(this); // Enable zooming - zoomer = new ScrollZoomer(canvas()); + QwtPlotCanvas *c = static_cast(canvas()); + zoomer = new ScrollZoomer(c); colors = QList(); @@ -113,8 +114,8 @@ void ChartPlot::styleChanged(MainWindow::QGC_MAINWINDOW_STYLE style) setCanvasBackground(QColor(0xFF, 0xFF, 0xFF)); // Configure the plot grid. - grid->setMinPen(QPen(QColor(0x55, 0x55, 0x55), gridWidth, Qt::DotLine)); - grid->setMajPen(QPen(QColor(0x22, 0x22, 0x22), gridWidth, Qt::DotLine)); + grid->setMinorPen(QPen(QColor(0x55, 0x55, 0x55), gridWidth, Qt::DotLine)); + grid->setMajorPen(QPen(QColor(0x22, 0x22, 0x22), gridWidth, Qt::DotLine)); } else { @@ -126,8 +127,8 @@ void ChartPlot::styleChanged(MainWindow::QGC_MAINWINDOW_STYLE style) setCanvasBackground(QColor(0, 0, 0)); // Configure the plot grid. - grid->setMinPen(QPen(QColor(0xAA, 0xAA, 0xAA), gridWidth, Qt::DotLine)); - grid->setMajPen(QPen(QColor(0xDD, 0xDD, 0xDD), gridWidth, Qt::DotLine)); + grid->setMinorPen(QPen(QColor(0xAA, 0xAA, 0xAA), gridWidth, Qt::DotLine)); + grid->setMajorPen(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/IncrementalPlot.cc b/src/ui/linechart/IncrementalPlot.cc index 5826d09d3..a06077dab 100644 --- a/src/ui/linechart/IncrementalPlot.cc +++ b/src/ui/linechart/IncrementalPlot.cc @@ -132,7 +132,7 @@ void IncrementalPlot::showLegend(bool show) if (legend == NULL) { legend = new QwtLegend; legend->setFrameStyle(QFrame::Box); - legend->setItemMode(QwtLegend::CheckableItem); + legend->setDefaultItemMode(QwtLegendData::Checkable); } insertLegend(legend, QwtPlot::RightLegend); } else { @@ -168,30 +168,32 @@ void IncrementalPlot::updateStyle(QwtPlotCurve *curve) { if(styleText.isNull()) return; - // Style of datapoints + + // Since the symbols always use the same color as the curve line, we just use that color. + // This saves us from having to deal with cases where the symbol is NULL. + QColor oldColor = curve->pen().color(); + + // Update the symbol style + QwtSymbol *newSymbol = NULL; if (styleText.contains("circles")) { - curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse, - Qt::NoBrush, QPen(QBrush(curve->symbol().pen().color()), symbolWidth), QSize(6, 6)) ); + newSymbol = new QwtSymbol(QwtSymbol::Ellipse, Qt::NoBrush, QPen(oldColor, 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)) ); + newSymbol = new QwtSymbol(QwtSymbol::XCross, Qt::NoBrush, QPen(oldColor, 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)) ); + newSymbol = new QwtSymbol(QwtSymbol::Rect, Qt::NoBrush, QPen(oldColor, symbolWidth), QSize(6, 6)); } + // Else-case already handled by NULL value, which indicates no symbol + curve->setSymbol(newSymbol); - // Style of lines + // Update the line style if (styleText.contains("dotted")) { - curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DotLine)); + curve->setPen(QPen(oldColor, curveWidth, Qt::DotLine)); } else if (styleText.contains("dashed")) { - curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::DashLine)); + curve->setPen(QPen(oldColor, curveWidth, Qt::DashLine)); } else if (styleText.contains("line") || styleText.contains("solid")) { - curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::SolidLine)); + curve->setPen(QPen(oldColor, curveWidth, Qt::SolidLine)); } else { - curve->setPen(QPen(QBrush(curve->symbol().pen().color()), curveWidth, Qt::NoPen)); + curve->setPen(QPen(oldColor, curveWidth, Qt::NoPen)); } curve->setStyle(QwtPlotCurve::Lines); } @@ -273,23 +275,27 @@ void IncrementalPlot::appendData(const QString &key, double *x, double *y, int s data = d_data.value(key); } + // If this is a new curve, create it. if (!curves.contains(key)) { curve = new QwtPlotCurve(key); curves.insert(key, curve); curve->setStyle(QwtPlotCurve::NoCurve); - curve->setPaintAttribute(QwtPlotCurve::PaintFiltered); + curve->setPaintAttribute(QwtPlotCurve::FilterPoints); + // Set the color. Only the pen needs to be set 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->setPen(c, symbolWidth); + + qDebug() << "Creating curve" << key << "with color" << c; + + updateStyle(curve); curve->attach(this); } else { curve = curves.value(key); } data->append(x, y, size); - curve->setRawData(data->x(), data->y(), data->count()); + curve->setRawSamples(data->x(), data->y(), data->count()); bool scaleChanged = false; @@ -326,17 +332,10 @@ void IncrementalPlot::appendData(const QString &key, double *x, double *y, int s updateScale(); } else { - const bool cacheMode = - canvas()->testPaintAttribute(QwtPlotCanvas::PaintCached); - -#if QT_VERSION >= 0x040000 && defined(Q_WS_X11) - // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent - // works on X11. This has an tremendous effect on the performance.. - - canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); -#endif + QwtPlotCanvas *c = static_cast(canvas()); + const bool cacheMode = c->testPaintAttribute(QwtPlotCanvas::BackingStore); - canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); + c->setPaintAttribute(QwtPlotCanvas::BackingStore, false); // FIXME Check if here all curves should be drawn // QwtPlotCurve* plotCurve; // foreach(plotCurve, curves) @@ -344,12 +343,11 @@ void IncrementalPlot::appendData(const QString &key, double *x, double *y, int s // plotCurve->draw(0, curve->dataSize()-1); // } - curve->draw(curve->dataSize() - size, curve->dataSize() - 1); - canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode); + // FIXME: Unsure what this call should be now. + //curve->draw(curve->dataSize() - size, curve->dataSize() - 1); + replot(); + c->setPaintAttribute(QwtPlotCanvas::BackingStore, cacheMode); -#if QT_VERSION >= 0x040000 && defined(Q_WS_X11) - canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false); -#endif } } diff --git a/src/ui/linechart/IncrementalPlot.h b/src/ui/linechart/IncrementalPlot.h index 66f2b0734..3988556c5 100644 --- a/src/ui/linechart/IncrementalPlot.h +++ b/src/ui/linechart/IncrementalPlot.h @@ -32,7 +32,6 @@ This file is part of the QGROUNDCONTROL project #define INCREMENTALPLOT_H #include -#include #include #include #include @@ -59,8 +58,8 @@ public: private: int d_count; - QwtArray d_x; - QwtArray d_y; + QVector d_x; + QVector d_y; }; /** diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index f65134499..3916338a6 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -277,7 +277,7 @@ void LinechartPlot::appendData(QString dataname, quint64 ms, double value) // Assign dataset to curve QwtPlotCurve* curve = curves.value(dataname); - curve->setRawData(dataset->getPlotX(), dataset->getPlotY(), dataset->getPlotCount()); + curve->setRawSamples(dataset->getPlotX(), dataset->getPlotY(), dataset->getPlotCount()); // qDebug() << "mintime" << minTime << "maxtime" << maxTime << "last max time" << "window position" << getWindowPosition(); @@ -324,7 +324,7 @@ void LinechartPlot::addCurve(QString id) curves.insert(id, curve); curve->setStyle(QwtPlotCurve::Lines); - curve->setPaintAttribute(QwtPlotCurve::PaintFiltered); + curve->setPaintAttribute(QwtPlotCurve::FilterPoints, true); setCurveColor(id, currentColor); //curve->setBrush(currentColor); Leads to a filled curve // curve->setRenderHint(QwtPlotItem::RenderAntialiased); @@ -468,10 +468,18 @@ void LinechartPlot::showCurve(QString id) void LinechartPlot::setCurveColor(QString id, QColor color) { QwtPlotCurve* curve = curves.value(id); + // Change the color of the curve. curve->setPen(QPen(QBrush(color), curveWidth)); - QwtSymbol x = curve->symbol(); - x.setPen(QPen(QBrush(color), symbolWidth)); - curve->setSymbol(x); + + qDebug() << "Setting curve" << id << "to" << color; + + // And change the color of the symbol, making sure to preserve the symbol style + const QwtSymbol *oldSymbol = curve->symbol(); + QwtSymbol *newSymbol = NULL; + if (oldSymbol) { + newSymbol = new QwtSymbol(oldSymbol->style(), QBrush(color), QPen(color, symbolWidth), QSize(symbolWidth, symbolWidth)); + } + curve->setSymbol(newSymbol); } /** @@ -609,7 +617,7 @@ quint64 LinechartPlot::getDataInterval() **/ void LinechartPlot::setLogarithmicScaling() { - yScaleEngine = new QwtLog10ScaleEngine(); + yScaleEngine = new QwtLogScaleEngine(); setAxisScaleEngine(QwtPlot::yLeft, yScaleEngine); } @@ -671,24 +679,6 @@ void LinechartPlot::paintRealtime() windowLock.unlock(); - // Defined both on windows 32- and 64 bit -#if !(defined Q_OS_WIN) - - // const bool cacheMode = - // canvas()->testPaintAttribute(QwtPlotCanvas::PaintCached); - const bool oldDirectPaint = - canvas()->testAttribute(Qt::WA_PaintOutsidePaintEvent); - - const QPaintEngine *pe = canvas()->paintEngine(); - bool directPaint = pe->hasFeature(QPaintEngine::PaintOutsidePaintEvent); - //if ( pe->type() == QPaintEngine::X11 ) { - // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent - // works on X11. This has an tremendous effect on the performance.. - directPaint = true; - //} - canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, directPaint); -#endif - // Only set current view as zoombase if zoomer is not active // else we could not zoom out any more @@ -698,10 +688,6 @@ void LinechartPlot::paintRealtime() replot(); } -#if !(defined Q_OS_WIN) - canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, oldDirectPaint); -#endif - /* QMap::iterator i; diff --git a/src/ui/linechart/LinechartPlot.h b/src/ui/linechart/LinechartPlot.h index 5d19f5c53..be5c29bf9 100644 --- a/src/ui/linechart/LinechartPlot.h +++ b/src/ui/linechart/LinechartPlot.h @@ -45,7 +45,7 @@ This file is part of the PIXHAWK project #include #include #include -#include +#include #include #include "ChartPlot.h" #include "MG.h" diff --git a/src/ui/linechart/ScrollZoomer.h b/src/ui/linechart/ScrollZoomer.h index b4e12b52d..fbbbe18f2 100644 --- a/src/ui/linechart/ScrollZoomer.h +++ b/src/ui/linechart/ScrollZoomer.h @@ -6,6 +6,7 @@ #include #endif #include +#include class ScrollData; class ScrollBar; -- 2.22.0