| 1 |
/***************************************************************************** |
| 2 |
* Qwt Examples - Copyright (C) 2002 Uwe Rathmann |
| 3 |
* This file may be used under the terms of the 3-clause BSD License |
| 4 |
*****************************************************************************/ |
| 5 |
|
| 6 |
#include "Plot.h" |
| 7 |
#include "Settings.h" |
| 8 |
|
| 9 |
#include <QwtDate> |
| 10 |
#include <QwtDateScaleDraw> |
| 11 |
#include <QwtDateScaleEngine> |
| 12 |
#include <QwtPlotPanner> |
| 13 |
#include <QwtPlotMagnifier> |
| 14 |
#include <QwtPlotGrid> |
| 15 |
#include <QwtPlotLayout> |
| 16 |
|
| 17 |
Plot::Plot( QWidget* parent ) |
| 18 |
: QwtPlot( parent ) |
| 19 |
{ |
| 20 |
setAutoFillBackground( true ); |
| 21 |
setPalette( Qt::darkGray ); |
| 22 |
setCanvasBackground( Qt::white ); |
| 23 |
|
| 24 |
plotLayout()->setAlignCanvasToScales( true ); |
| 25 |
|
| 26 |
initAxis( QwtAxis::YLeft, "Local Time", Qt::LocalTime ); |
| 27 |
initAxis( QwtAxis::YRight, |
| 28 |
"Coordinated Universal Time ( UTC )", Qt::UTC ); |
| 29 |
|
| 30 |
QwtPlotPanner* panner = new QwtPlotPanner( canvas() ); |
| 31 |
QwtPlotMagnifier* magnifier = new QwtPlotMagnifier( canvas() ); |
| 32 |
|
| 33 |
for ( int axis = 0; axis < QwtAxis::AxisPositions; axis++ ) |
| 34 |
{ |
| 35 |
const bool on = QwtAxis::isYAxis( axis ); |
| 36 |
|
| 37 |
setAxisVisible( axis, on ); |
| 38 |
panner->setAxisEnabled( axis, on ); |
| 39 |
magnifier->setAxisEnabled( axis, on ); |
| 40 |
} |
| 41 |
|
| 42 |
QwtPlotGrid* grid = new QwtPlotGrid(); |
| 43 |
grid->setMajorPen( Qt::black, 0, Qt::SolidLine ); |
| 44 |
grid->setMinorPen( Qt::gray, 0, Qt::SolidLine ); |
| 45 |
grid->enableX( false ); |
| 46 |
grid->enableXMin( false ); |
| 47 |
grid->enableY( true ); |
| 48 |
grid->enableYMin( true ); |
| 49 |
|
| 50 |
grid->attach( this ); |
| 51 |
} |
| 52 |
|
| 53 |
void Plot::initAxis( int axis, |
| 54 |
const QString& title, Qt::TimeSpec timeSpec ) |
| 55 |
{ |
| 56 |
setAxisTitle( axis, title ); |
| 57 |
|
| 58 |
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw( timeSpec ); |
| 59 |
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine( timeSpec ); |
| 60 |
|
| 61 |
#if 0 |
| 62 |
if ( timeSpec == Qt::LocalTime ) |
| 63 |
{ |
| 64 |
scaleDraw->setTimeSpec( Qt::OffsetFromUTC ); |
| 65 |
scaleDraw->setUtcOffset( 10 ); |
| 66 |
|
| 67 |
scaleEngine->setTimeSpec( Qt::OffsetFromUTC ); |
| 68 |
scaleEngine->setUtcOffset( 10 ); |
| 69 |
} |
| 70 |
#endif |
| 71 |
setAxisScaleDraw( axis, scaleDraw ); |
| 72 |
setAxisScaleEngine( axis, scaleEngine ); |
| 73 |
} |
| 74 |
|
| 75 |
void Plot::applySettings( const Settings& settings ) |
| 76 |
{ |
| 77 |
applyAxisSettings( QwtAxis::YLeft, settings ); |
| 78 |
applyAxisSettings( QwtAxis::YRight, settings ); |
| 79 |
|
| 80 |
replot(); |
| 81 |
} |
| 82 |
|
| 83 |
void Plot::applyAxisSettings( int axis, const Settings& settings ) |
| 84 |
{ |
| 85 |
QwtDateScaleEngine* scaleEngine = |
| 86 |
static_cast< QwtDateScaleEngine* >( axisScaleEngine( axis ) ); |
| 87 |
|
| 88 |
scaleEngine->setMaxWeeks( settings.maxWeeks ); |
| 89 |
setAxisMaxMinor( axis, settings.maxMinorSteps ); |
| 90 |
setAxisMaxMajor( axis, settings.maxMajorSteps ); |
| 91 |
|
| 92 |
|
| 93 |
setAxisScale( axis, QwtDate::toDouble( settings.startDateTime ), |
| 94 |
QwtDate::toDouble( settings.endDateTime ) ); |
| 95 |
} |
| 96 |
|
| 97 |
#include "moc_Plot.cpp" |