Commit ff6ecfe6 authored by Bryant's avatar Bryant

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.
parent c96458cf
......@@ -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.
......
......@@ -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;}");
}
}
......
......@@ -42,7 +42,7 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
set[i] = static_cast<double>((*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<double>((*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<uint16_t> &data)
pos[i] = static_cast<double>((*positions)[i]);
set[i] = static_cast<double>((*setpoints)[i]);
}
curve->setData(pos, set);
curve->setSamples(pos, set);
plot->replot();
} else {
qDebug() << __FILE__ << __LINE__ << ": wrong data vector size";
......
......@@ -34,7 +34,6 @@ This file is part of the QGROUNDCONTROL project
#include <QVector>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
//#include <qwt_array.h>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
......
......@@ -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());
}
......
......@@ -41,7 +41,8 @@ ChartPlot::ChartPlot(QWidget *parent):
grid->attach(this);
// Enable zooming
zoomer = new ScrollZoomer(canvas());
QwtPlotCanvas *c = static_cast<QwtPlotCanvas*>(canvas());
zoomer = new ScrollZoomer(c);
colors = QList<QColor>();
......@@ -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.
......
......@@ -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<QwtPlotCanvas*>(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
}
}
......
......@@ -32,7 +32,6 @@ This file is part of the QGROUNDCONTROL project
#define INCREMENTALPLOT_H
#include <QTimer>
#include <qwt_array.h>
#include <qwt_plot.h>
#include <qwt_legend.h>
#include <QMap>
......@@ -59,8 +58,8 @@ public:
private:
int d_count;
QwtArray<double> d_x;
QwtArray<double> d_y;
QVector<double> d_x;
QVector<double> d_y;
};
/**
......
......@@ -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<QString, QwtPlotCurve*>::iterator i;
......
......@@ -45,7 +45,7 @@ This file is part of the PIXHAWK project
#include <qwt_scale_draw.h>
#include <qwt_scale_widget.h>
#include <qwt_scale_engine.h>
#include <qwt_array.h>
#include <qwt_compat.h>
#include <qwt_plot.h>
#include "ChartPlot.h"
#include "MG.h"
......
......@@ -6,6 +6,7 @@
#include <qscrollview.h>
#endif
#include <qwt_plot_zoomer.h>
#include <qwt_plot_canvas.h>
class ScrollData;
class ScrollBar;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment