1 #include "plot.h"
2 #include "curvetracker.h"
3 #include <qwt_picker_machine.h>
4 #include <qwt_plot_layout.h>
5 #include <qwt_plot_canvas.h>
6 #include <qwt_plot_grid.h>
7 #include <qwt_plot_textlabel.h>
8 #include <qwt_plot_zoneitem.h>
9 #include <qwt_plot_curve.h>
10 #include <qwt_plot_layout.h>
11 #include <qwt_scale_widget.h>
12 #include <qwt_symbol.h>
13
Plot(QWidget * parent)14 Plot::Plot( QWidget *parent ):
15 QwtPlot( parent)
16 {
17 setPalette( Qt::black );
18
19 // we want to have the axis scales like a frame around the
20 // canvas
21 plotLayout()->setAlignCanvasToScales( true );
22 for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
23 axisWidget( axis )->setMargin( 0 );
24
25 QwtPlotCanvas *canvas = new QwtPlotCanvas();
26 canvas->setAutoFillBackground( false );
27 canvas->setFrameStyle( QFrame::NoFrame );
28 setCanvas( canvas );
29
30 setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
31
32 // a title
33 QwtText title( "Picker Demo" );
34 title.setColor( Qt::white );
35 title.setRenderFlags( Qt::AlignHCenter | Qt::AlignTop );
36
37 QFont font;
38 font.setBold( true );
39 title.setFont( font );
40
41 QwtPlotTextLabel *titleItem = new QwtPlotTextLabel();
42 titleItem->setText( title );
43 titleItem->attach( this );
44
45 #if 1
46 // section
47
48 //QColor c( "PaleVioletRed" );
49
50 QwtPlotZoneItem* zone = new QwtPlotZoneItem();
51 zone->setPen( Qt::darkGray );
52 zone->setBrush( QColor( "#834358" ) );
53 zone->setOrientation( Qt::Horizontal );
54 zone->setInterval( 3.8, 5.7 );
55 zone->attach( this );
56
57 #else
58 // grid
59
60 QwtPlotGrid *grid = new QwtPlotGrid();
61 grid->setMajorPen( Qt::white, 0, Qt::DotLine );
62 grid->setMinorPen( Qt::gray, 0 , Qt::DotLine );
63 grid->attach( this );
64 #endif
65
66 // curves
67
68 QPolygonF points1;
69 points1 << QPointF( 0.2, 4.4 ) << QPointF( 1.2, 3.0 )
70 << QPointF( 2.7, 4.5 ) << QPointF( 3.5, 6.8 )
71 << QPointF( 4.7, 7.9 ) << QPointF( 5.8, 7.1 );
72
73 insertCurve( "Curve 1", "DarkOrange", points1 );
74
75 QPolygonF points2;
76 points2 << QPointF( 0.4, 8.7 ) << QPointF( 1.4, 7.8 )
77 << QPointF( 2.3, 5.5 ) << QPointF( 3.3, 4.1 )
78 << QPointF( 4.4, 5.2 ) << QPointF( 5.6, 5.7 );
79
80 insertCurve( "Curve 2", "DodgerBlue", points2 );
81
82 CurveTracker* tracker = new CurveTracker( this->canvas() );
83
84 // for the demo we want the tracker to be active without
85 // having to click on the canvas
86 tracker->setStateMachine( new QwtPickerTrackerMachine() );
87 tracker->setRubberBandPen( QPen( "MediumOrchid" ) );
88 }
89
insertCurve(const QString & title,const QColor & color,const QPolygonF & points)90 void Plot::insertCurve( const QString &title,
91 const QColor &color, const QPolygonF &points )
92 {
93 QwtPlotCurve *curve = new QwtPlotCurve();
94 curve->setTitle( title );
95 curve->setPen( color, 2 ),
96 curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
97
98 QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
99 QBrush( Qt::white ), QPen( color, 2 ), QSize( 8, 8 ) );
100 curve->setSymbol( symbol );
101
102 curve->setSamples( points );
103
104 curve->attach( this );
105 }
106
107
108