mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 08:38:45 +00:00
Qwt 6.0.1 Support
Upgrade to QWT 6.0.1, but still uses a locally patched copy since support for 8 axes has not been included, despite it being a relatively simple patch. Fixes #634. Fixes #567.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include <qprinter.h>
|
||||
#if QT_VERSION >= 0x040000
|
||||
#include <qprintdialog.h>
|
||||
#endif
|
||||
#include <qwt_color_map.h>
|
||||
#include <qwt_plot_spectrogram.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
@@ -9,6 +7,7 @@
|
||||
#include <qwt_plot_zoomer.h>
|
||||
#include <qwt_plot_panner.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qwt_plot_renderer.h>
|
||||
#include "plot.h"
|
||||
|
||||
class MyZoomer: public QwtPlotZoomer
|
||||
@@ -20,14 +19,12 @@ public:
|
||||
setTrackerMode(AlwaysOn);
|
||||
}
|
||||
|
||||
virtual QwtText trackerText(const QwtDoublePoint &pos) const
|
||||
virtual QwtText trackerTextF(const QPointF &pos) const
|
||||
{
|
||||
QColor bg(Qt::white);
|
||||
#if QT_VERSION >= 0x040300
|
||||
bg.setAlpha(200);
|
||||
#endif
|
||||
|
||||
QwtText text = QwtPlotZoomer::trackerText(pos);
|
||||
QwtText text = QwtPlotZoomer::trackerTextF(pos);
|
||||
text.setBackgroundBrush( QBrush( bg ));
|
||||
return text;
|
||||
}
|
||||
@@ -36,19 +33,11 @@ public:
|
||||
class SpectrogramData: public QwtRasterData
|
||||
{
|
||||
public:
|
||||
SpectrogramData():
|
||||
QwtRasterData(QwtDoubleRect(-1.5, -1.5, 3.0, 3.0))
|
||||
SpectrogramData()
|
||||
{
|
||||
}
|
||||
|
||||
virtual QwtRasterData *copy() const
|
||||
{
|
||||
return new SpectrogramData();
|
||||
}
|
||||
|
||||
virtual QwtDoubleInterval range() const
|
||||
{
|
||||
return QwtDoubleInterval(0.0, 10.0);
|
||||
setInterval( Qt::XAxis, QwtInterval( -1.5, 1.5 ) );
|
||||
setInterval( Qt::YAxis, QwtInterval( -1.5, 1.5 ) );
|
||||
setInterval( Qt::ZAxis, QwtInterval( 0.0, 10.0 ) );
|
||||
}
|
||||
|
||||
virtual double value(double x, double y) const
|
||||
@@ -62,36 +51,42 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class ColorMap: public QwtLinearColorMap
|
||||
{
|
||||
public:
|
||||
ColorMap():
|
||||
QwtLinearColorMap(Qt::darkCyan, Qt::red)
|
||||
{
|
||||
addColorStop(0.1, Qt::cyan);
|
||||
addColorStop(0.6, Qt::green);
|
||||
addColorStop(0.95, Qt::yellow);
|
||||
}
|
||||
};
|
||||
|
||||
Plot::Plot(QWidget *parent):
|
||||
QwtPlot(parent)
|
||||
{
|
||||
d_spectrogram = new QwtPlotSpectrogram();
|
||||
d_spectrogram->setRenderThreadCount(0); // use system specific thread count
|
||||
|
||||
QwtLinearColorMap colorMap(Qt::darkCyan, Qt::red);
|
||||
colorMap.addColorStop(0.1, Qt::cyan);
|
||||
colorMap.addColorStop(0.6, Qt::green);
|
||||
colorMap.addColorStop(0.95, Qt::yellow);
|
||||
d_spectrogram->setColorMap(new ColorMap());
|
||||
|
||||
d_spectrogram->setColorMap(colorMap);
|
||||
|
||||
d_spectrogram->setData(SpectrogramData());
|
||||
d_spectrogram->setData(new SpectrogramData());
|
||||
d_spectrogram->attach(this);
|
||||
|
||||
QwtValueList contourLevels;
|
||||
QList<double> contourLevels;
|
||||
for ( double level = 0.5; level < 10.0; level += 1.0 )
|
||||
contourLevels += level;
|
||||
d_spectrogram->setContourLevels(contourLevels);
|
||||
|
||||
const QwtInterval zInterval = d_spectrogram->data()->interval( Qt::ZAxis );
|
||||
// A color bar on the right axis
|
||||
QwtScaleWidget *rightAxis = axisWidget(QwtPlot::yRight);
|
||||
rightAxis->setTitle("Intensity");
|
||||
rightAxis->setColorBarEnabled(true);
|
||||
rightAxis->setColorMap(d_spectrogram->data().range(),
|
||||
d_spectrogram->colorMap());
|
||||
rightAxis->setColorMap( zInterval, new ColorMap());
|
||||
|
||||
setAxisScale(QwtPlot::yRight,
|
||||
d_spectrogram->data().range().minValue(),
|
||||
d_spectrogram->data().range().maxValue() );
|
||||
setAxisScale(QwtPlot::yRight, zInterval.minValue(), zInterval.maxValue() );
|
||||
enableAxis(QwtPlot::yRight);
|
||||
|
||||
plotLayout()->setAlignCanvasToScales(true);
|
||||
@@ -103,13 +98,8 @@ Plot::Plot(QWidget *parent):
|
||||
// Ctrl+RighButton: zoom out to full size
|
||||
|
||||
QwtPlotZoomer* zoomer = new MyZoomer(canvas());
|
||||
#if QT_VERSION < 0x040000
|
||||
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
|
||||
Qt::RightButton, Qt::ControlButton);
|
||||
#else
|
||||
zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
|
||||
Qt::RightButton, Qt::ControlModifier);
|
||||
#endif
|
||||
zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
|
||||
Qt::RightButton);
|
||||
|
||||
@@ -142,25 +132,27 @@ void Plot::showSpectrogram(bool on)
|
||||
replot();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_PRINTER
|
||||
|
||||
void Plot::printPlot()
|
||||
{
|
||||
#if 1
|
||||
QPrinter printer;
|
||||
printer.setOrientation(QPrinter::Landscape);
|
||||
#if QT_VERSION < 0x040000
|
||||
printer.setColorMode(QPrinter::Color);
|
||||
#if 0
|
||||
printer.setOutputFileName("/tmp/spectrogram.ps");
|
||||
#endif
|
||||
if (printer.setup())
|
||||
#else
|
||||
#if 0
|
||||
printer.setOutputFileName("/tmp/spectrogram.pdf");
|
||||
QPrinter printer(QPrinter::HighResolution);
|
||||
#endif
|
||||
printer.setOrientation(QPrinter::Landscape);
|
||||
printer.setOutputFileName("spectrogram.pdf");
|
||||
QPrintDialog dialog(&printer);
|
||||
if ( dialog.exec() )
|
||||
#endif
|
||||
{
|
||||
print(printer);
|
||||
QwtPlotRenderer renderer;
|
||||
|
||||
renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
|
||||
renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
|
||||
|
||||
renderer.renderTo(this, printer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user