/[qspeakers]/plot.cpp
ViewVC logotype

Contents of /plot.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations)
Mon Oct 6 20:36:42 2014 UTC (7 years, 1 month ago) by ben
File size: 1688 byte(s)
add custom plot class
1 #include "plot.h"
2 #include <qwt/qwt_scale_engine.h>
3 #include <qwt/qwt_plot_curve.h>
4 #include <qwt/qwt_plot_grid.h>
5
6 Plot::Plot(QWidget *parent) :
7 QwtPlot(parent)
8 {
9 setAutoReplot(false);
10 initializeScales();
11 initializeCanvas();
12 initializeCurve();
13 setAutoReplot(true);
14 }
15
16 Plot::Plot(QwtText title, QWidget *parent) :
17 QwtPlot(title, parent)
18 {
19 setAutoReplot(false);
20 initializeScales();
21 initializeCanvas();
22 initializeCurve();
23 setAutoReplot(true);
24 }
25
26 Plot::~Plot()
27 {
28 }
29
30 void Plot::initializeCurve() {
31 curve = new QwtPlotCurve("Amplitude");
32 curve->setRenderHint(QwtPlotItem::RenderAntialiased);
33 curve->setPen(QPen(Qt::darkBlue));
34 curve->setLegendAttribute(QwtPlotCurve::LegendShowLine);
35 curve->setYAxis(QwtPlot::yLeft);
36 curve->attach(this);
37 }
38
39 void Plot::initializeCanvas() {
40
41 setCanvasBackground(QColor(Qt::white));
42
43 QwtPlotGrid *grid = new QwtPlotGrid;
44 grid->enableXMin(true);
45 grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
46 grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
47 grid->attach(this);
48 }
49
50 void Plot::initializeScales() {
51 QwtText XAxisLabel;
52 XAxisLabel.setText("Frequency [Hz]");
53 setAxisTitle(QwtPlot::xBottom, XAxisLabel);
54 setAxisMaxMajor(QwtPlot::xBottom, 3);
55 setAxisMaxMinor(QwtPlot::xBottom, 10);
56 setAxisScaleEngine(QwtPlot::xBottom, new QwtLog10ScaleEngine());
57 setAxisScale(QwtPlot::xBottom, 10.0, 1000.0);
58
59 QwtText YAxisLabel;
60 YAxisLabel.setText("Sound pressure [dB]");
61 setAxisTitle(QwtPlot::yLeft, YAxisLabel);
62 setAxisMaxMajor(QwtPlot::yLeft, 5);
63 setAxisMaxMinor(QwtPlot::yLeft, 10);
64 setAxisScale(QwtPlot::yLeft, -40.0, 10.0);
65 }

  ViewVC Help
Powered by ViewVC 1.1.26