1 | #include "plot.h"
|
2 |
|
3 | Plot::Plot(QWidget *parent):
|
4 | QwtPlot( parent )
|
5 | {
|
6 | xData[0] = 0;
|
7 | yData[0] = 0;
|
8 |
|
9 | // Insert new density curve
|
10 | density = new QwtPlotCurve("y = density");
|
11 | //density->setRenderHint(QwtPlotItem::RenderAntialiased);
|
12 | density->setStyle(QwtPlotCurve::Lines);
|
13 | density->setLegendAttribute(QwtPlotCurve::LegendShowLine, true);
|
14 | density->setPen(QPen(Qt::red));
|
15 | density->attach(this);
|
16 |
|
17 | // Draw grid
|
18 | QwtPlotGrid *grid = new QwtPlotGrid();
|
19 | grid->setPen(QPen(Qt::gray, 0.0, Qt::DotLine));
|
20 | grid->enableX(true);
|
21 | grid->enableXMin(true);
|
22 | grid->enableY(true);
|
23 | grid->enableYMin(false);
|
24 | grid->attach(this);
|
25 |
|
26 | // Insert markers
|
27 | // ...a horizontal line at y = 0...
|
28 | QwtPlotMarker *mY = new QwtPlotMarker();
|
29 | mY->setLabel(QString::fromLatin1("y = 0"));
|
30 | mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
|
31 | mY->setLineStyle(QwtPlotMarker::HLine);
|
32 | mY->setYValue(0.0);
|
33 | mY->attach(this);
|
34 |
|
35 | // ...a vertical line at x = 0...
|
36 | QwtPlotMarker *mX = new QwtPlotMarker();
|
37 | mX->setLabel(QString::fromLatin1("x = 0"));
|
38 | mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
|
39 | mX->setLabelOrientation(Qt::Vertical);
|
40 | mX->setLineStyle(QwtPlotMarker::VLine);
|
41 | mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
|
42 | mX->setXValue(0.0);
|
43 | mX->attach(this);
|
44 |
|
45 | // panning with the left mouse button
|
46 | (void) new QwtPlotPanner( canvas() );
|
47 |
|
48 | // zoom in/out with the wheel
|
49 | (void) new QwtPlotMagnifier( canvas() );
|
50 |
|
51 | setAutoFillBackground( true );
|
52 | setPalette( QPalette( QColor( 165, 193, 228 ) ) );
|
53 | updateGradient();
|
54 |
|
55 | setTitle("A Simple QwtPlot Demonstration");
|
56 | insertLegend(new QwtLegend(), QwtPlot::RightLegend);
|
57 |
|
58 | // axes
|
59 | setAxisTitle(xBottom, "x -->" );
|
60 | setAxisScale(xBottom, 0.0, 10.0);
|
61 |
|
62 | setAxisTitle(yLeft, "y -->");
|
63 | setAxisScale(yLeft, -1.0, 1.0);
|
64 |
|
65 | // canvas
|
66 | canvas()->setLineWidth( 1 );
|
67 | canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );
|
68 | canvas()->setBorderRadius( 15 );
|
69 |
|
70 | QPalette canvasPalette( Qt::white );
|
71 | canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
|
72 | canvas()->setPalette( canvasPalette );
|
73 |
|
74 | //populate(); // beim Aufruf von hier aus, funktionieren die Plots...
|
75 | }
|
76 |
|
77 | Plot::~Plot()
|
78 | {
|
79 |
|
80 | }
|
81 |
|
82 | void Plot::populate()
|
83 | {
|
84 | qWarning()<< "Plot : populate()";
|
85 |
|
86 | double maxD = 0;
|
87 | double minD = 1;
|
88 | double maxS = 0;
|
89 | double minS = 1;
|
90 |
|
91 | double dens = 2.0;
|
92 | unsigned int sample = 0;
|
93 | unsigned int x = 0;
|
94 | unsigned int y = 0;
|
95 |
|
96 | while(sample < 5)
|
97 | {
|
98 | xData[x++]= sample;
|
99 | yData[y++]= dens;
|
100 |
|
101 | maxS = sample;
|
102 | minS = sample++;
|
103 | maxD = dens;
|
104 | minD = dens++;
|
105 |
|
106 | setAxisScale(xBottom, (int)minS-1, (int)maxS+1);
|
107 | setAxisScale(yLeft, (int)minD-1, (int)maxD+1);
|
108 |
|
109 | density->setSamples(xData, yData, sample);
|
110 | }
|
111 | setAutoReplot(true);
|
112 | // Call "replot()" to refresh plot displaying
|
113 | replot();
|
114 | }
|