├── Navaltek.pro
├── Navaltek.pro.user
├── Navaltek.pro.user.3.2-pre1
├── README.md
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── qcustomplot.cpp
└── qcustomplot.h
/Navaltek.pro:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------
2 | #
3 | # Project created by QtCreator 2014-12-22T21:59:39
4 | #
5 | #-------------------------------------------------
6 |
7 | QT += core gui serialport
8 |
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
10 |
11 | TARGET = Navaltek
12 | TEMPLATE = app
13 |
14 |
15 | SOURCES += main.cpp\
16 | mainwindow.cpp \
17 | qcustomplot.cpp
18 |
19 | HEADERS += mainwindow.h \
20 | qcustomplot.h
21 |
22 | FORMS += mainwindow.ui
23 |
--------------------------------------------------------------------------------
/Navaltek.pro.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {fe2746b3-6b59-440c-8d6d-55140fe5bfd0}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | 0
45 | 8
46 | true
47 | 1
48 | true
49 | true
50 | true
51 | false
52 |
53 |
54 |
55 | ProjectExplorer.Project.PluginSettings
56 |
57 |
58 |
59 | ProjectExplorer.Project.Target.0
60 |
61 | Desktop Qt 5.4.0 MinGW 32bit
62 | Desktop Qt 5.4.0 MinGW 32bit
63 | qt.54.win32_mingw491_kit
64 | 0
65 | 0
66 | 0
67 |
68 | H:/QT5/build-Navaltek-Desktop_Qt_5_4_0_MinGW_32bit-Debug
69 |
70 |
71 | true
72 | qmake
73 |
74 | QtProjectManager.QMakeBuildStep
75 | false
76 | true
77 |
78 | false
79 | false
80 |
81 |
82 | true
83 | Make
84 |
85 | Qt4ProjectManager.MakeStep
86 |
87 | false
88 |
89 |
90 |
91 | 2
92 | Build
93 |
94 | ProjectExplorer.BuildSteps.Build
95 |
96 |
97 |
98 | true
99 | Make
100 |
101 | Qt4ProjectManager.MakeStep
102 |
103 | true
104 | clean
105 |
106 |
107 | 1
108 | Clean
109 |
110 | ProjectExplorer.BuildSteps.Clean
111 |
112 | 2
113 | false
114 |
115 | Debug
116 |
117 | Qt4ProjectManager.Qt4BuildConfiguration
118 | 2
119 | true
120 |
121 |
122 | H:/QT5/build-Navaltek-Desktop_Qt_5_4_0_MinGW_32bit-Release
123 |
124 |
125 | true
126 | qmake
127 |
128 | QtProjectManager.QMakeBuildStep
129 | false
130 | true
131 |
132 | false
133 | false
134 |
135 |
136 | true
137 | Make
138 |
139 | Qt4ProjectManager.MakeStep
140 |
141 | false
142 |
143 |
144 |
145 | 2
146 | Build
147 |
148 | ProjectExplorer.BuildSteps.Build
149 |
150 |
151 |
152 | true
153 | Make
154 |
155 | Qt4ProjectManager.MakeStep
156 |
157 | true
158 | clean
159 |
160 |
161 | 1
162 | Clean
163 |
164 | ProjectExplorer.BuildSteps.Clean
165 |
166 | 2
167 | false
168 |
169 | Release
170 |
171 | Qt4ProjectManager.Qt4BuildConfiguration
172 | 0
173 | true
174 |
175 | 2
176 |
177 |
178 | 0
179 | Deploy
180 |
181 | ProjectExplorer.BuildSteps.Deploy
182 |
183 | 1
184 | Deploy locally
185 |
186 | ProjectExplorer.DefaultDeployConfiguration
187 |
188 | 1
189 |
190 |
191 |
192 | false
193 | false
194 | false
195 | false
196 | true
197 | 0.01
198 | 10
199 | true
200 | 1
201 | 25
202 |
203 | 1
204 | true
205 | false
206 | true
207 | valgrind
208 |
209 | 0
210 | 1
211 | 2
212 | 3
213 | 4
214 | 5
215 | 6
216 | 7
217 | 8
218 | 9
219 | 10
220 | 11
221 | 12
222 | 13
223 | 14
224 |
225 | 2
226 |
227 | Navaltek
228 | Navaltek2
229 | Qt4ProjectManager.Qt4RunConfiguration:F:/Misc/QT/QT5/Navaltek/Navaltek.pro
230 |
231 | Navaltek.pro
232 | false
233 | false
234 |
235 | 3768
236 | false
237 | true
238 | false
239 | false
240 | true
241 |
242 | 1
243 |
244 |
245 |
246 | ProjectExplorer.Project.TargetCount
247 | 1
248 |
249 |
250 | ProjectExplorer.Project.Updater.FileVersion
251 | 18
252 |
253 |
254 | Version
255 | 18
256 |
257 |
258 |
--------------------------------------------------------------------------------
/Navaltek.pro.user.3.2-pre1:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ProjectExplorer.Project.ActiveTarget
7 | 0
8 |
9 |
10 | ProjectExplorer.Project.EditorSettings
11 |
12 | true
13 | false
14 | true
15 |
16 | Cpp
17 |
18 | CppGlobal
19 |
20 |
21 |
22 | QmlJS
23 |
24 | QmlJSGlobal
25 |
26 |
27 | 2
28 | UTF-8
29 | false
30 | 4
31 | false
32 | true
33 | 1
34 | true
35 | 0
36 | true
37 | 0
38 | 8
39 | true
40 | 1
41 | true
42 | true
43 | true
44 | false
45 |
46 |
47 |
48 | ProjectExplorer.Project.PluginSettings
49 |
50 |
51 |
52 | ProjectExplorer.Project.Target.0
53 |
54 | Desktop Qt 5.2.0 MinGW 32bit
55 | Desktop Qt 5.2.0 MinGW 32bit
56 | qt.520.win32_mingw48.essentials_kit
57 | 1
58 | 0
59 | 0
60 |
61 | C:/Users/ARYAN/QT5/build-Navaltek-Desktop_Qt_5_2_0_MinGW_32bit-Debug
62 |
63 |
64 | true
65 | qmake
66 |
67 | QtProjectManager.QMakeBuildStep
68 | false
69 | true
70 |
71 | false
72 |
73 |
74 | true
75 | Make
76 |
77 | Qt4ProjectManager.MakeStep
78 |
79 | false
80 |
81 |
82 |
83 | 2
84 | Build
85 |
86 | ProjectExplorer.BuildSteps.Build
87 |
88 |
89 |
90 | true
91 | Make
92 |
93 | Qt4ProjectManager.MakeStep
94 |
95 | true
96 | clean
97 |
98 |
99 | 1
100 | Clean
101 |
102 | ProjectExplorer.BuildSteps.Clean
103 |
104 | 2
105 | false
106 |
107 | Debug
108 |
109 | Qt4ProjectManager.Qt4BuildConfiguration
110 | 2
111 | true
112 |
113 |
114 | C:/Users/ARYAN/QT5/build-Navaltek-Desktop_Qt_5_2_0_MinGW_32bit-Release
115 |
116 |
117 | true
118 | qmake
119 |
120 | QtProjectManager.QMakeBuildStep
121 | false
122 | true
123 |
124 | false
125 |
126 |
127 | true
128 | Make
129 |
130 | Qt4ProjectManager.MakeStep
131 |
132 | false
133 |
134 |
135 |
136 | 2
137 | Build
138 |
139 | ProjectExplorer.BuildSteps.Build
140 |
141 |
142 |
143 | true
144 | Make
145 |
146 | Qt4ProjectManager.MakeStep
147 |
148 | true
149 | clean
150 |
151 |
152 | 1
153 | Clean
154 |
155 | ProjectExplorer.BuildSteps.Clean
156 |
157 | 2
158 | false
159 |
160 | Release
161 |
162 | Qt4ProjectManager.Qt4BuildConfiguration
163 | 0
164 | true
165 |
166 | 2
167 |
168 |
169 | 0
170 | Deploy
171 |
172 | ProjectExplorer.BuildSteps.Deploy
173 |
174 | 1
175 | Deploy locally
176 |
177 | ProjectExplorer.DefaultDeployConfiguration
178 |
179 | 1
180 |
181 |
182 |
183 | false
184 | false
185 | false
186 | false
187 | true
188 | 0.01
189 | 10
190 | true
191 | 1
192 | 25
193 |
194 | 1
195 | true
196 | false
197 | true
198 | valgrind
199 |
200 | 0
201 | 1
202 | 2
203 | 3
204 | 4
205 | 5
206 | 6
207 | 7
208 | 8
209 | 9
210 | 10
211 | 11
212 | 12
213 | 13
214 | 14
215 |
216 | 2
217 |
218 | Navaltek
219 |
220 | Qt4ProjectManager.Qt4RunConfiguration:C:/Users/ARYAN/QT5/Navaltek/Navaltek.pro
221 |
222 | Navaltek.pro
223 | false
224 | false
225 |
226 | 3768
227 | true
228 | false
229 | false
230 | false
231 | true
232 |
233 | 1
234 |
235 |
236 |
237 | ProjectExplorer.Project.TargetCount
238 | 1
239 |
240 |
241 | ProjectExplorer.Project.Updater.EnvironmentId
242 | {573b584d-c689-4936-a96b-393d7925201f}
243 |
244 |
245 | ProjectExplorer.Project.Updater.FileVersion
246 | 15
247 |
248 |
249 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RealTimeDataPlotter
2 | Plots realtime IMU filtered data connected to an Arduino board in communication over comport with PC
3 | I used qcustomplot library available through www.qcustomplot.com and interfaced the library with mpu9150 IMU sensor through an arduino uno board. This provides a direct access to a GUI standalone app communicating with Arduino in RealTime and turning the servo motor attached.
4 | Pls watch the demo video here https://youtu.be/Yp6yDAjSesY
5 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include
3 |
4 | int main(int argc, char *argv[])
5 | {
6 | QApplication a(argc, argv);
7 | MainWindow w;
8 | w.show();
9 |
10 | return a.exec();
11 | }
12 |
--------------------------------------------------------------------------------
/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ui_mainwindow.h"
3 | #include
4 |
5 | QSerialPort *serial;
6 | QString comport="";
7 | char buffer[2];
8 |
9 |
10 | MainWindow::MainWindow(QWidget *parent) :
11 | QMainWindow(parent),
12 | ui(new Ui::MainWindow)
13 | {
14 | ui->setupUi(this);
15 |
16 | ui->pushButton->setDisabled(true);
17 |
18 | //ui->customPlot = new QCustomPlot(ui->centralWidget);
19 | //QCustomPlot *customPlot;
20 | ui->customPlot->addGraph(); // blue line
21 | ui->customPlot->graph(0)->setPen(QPen(Qt::blue));
22 | ui->customPlot->graph(0)->setBrush(QBrush(QColor(240, 255, 200)));
23 | ui->customPlot->graph(0)->setAntialiasedFill(false);
24 | ui->customPlot->addGraph(); // red line
25 | ui->customPlot->graph(1)->setPen(QPen(Qt::red));
26 | ui->customPlot->graph(0)->setChannelFillGraph(ui->customPlot->graph(1));
27 |
28 | ui->customPlot->addGraph(); // blue dot
29 | ui->customPlot->graph(2)->setPen(QPen(Qt::blue));
30 | ui->customPlot->graph(2)->setLineStyle(QCPGraph::lsNone);
31 | ui->customPlot->graph(2)->setScatterStyle(QCPScatterStyle::ssDisc);
32 | ui->customPlot->addGraph(); // red dot
33 | ui->customPlot->graph(3)->setPen(QPen(Qt::red));
34 | ui->customPlot->graph(3)->setLineStyle(QCPGraph::lsNone);
35 | ui->customPlot->graph(3)->setScatterStyle(QCPScatterStyle::ssDisc);
36 |
37 | ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
38 | ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
39 | ui->customPlot->xAxis->setAutoTickStep(false);
40 | ui->customPlot->xAxis->setTickStep(2);
41 | ui->customPlot->axisRect()->setupFullAxesBox();
42 |
43 | // make left and bottom axes transfer their ranges to right and top axes:
44 | connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
45 | connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));
46 |
47 | // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
48 | connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
49 | dataTimer.start(0); // Interval 0 means to refresh as fast as possible
50 |
51 | }
52 |
53 | MainWindow::~MainWindow()
54 | {
55 | serial->close();
56 | delete ui;
57 | }
58 |
59 | void MainWindow::on_pushButton_clicked()
60 | {
61 | QString angle = ui->textEdit_2->toPlainText();
62 |
63 | serial->write(angle.toLatin1());
64 | //serial->write("9");
65 | char a;
66 | serial->read(&a,1);
67 | QString b= NULL;
68 | b=a;
69 | //ui->label->setText(angle);
70 | ui->label->clear();
71 | ui->textEdit_2->clear();
72 |
73 |
74 | }
75 |
76 | void MainWindow::Receivedata(){
77 |
78 | QByteArray ba;
79 | ba=serial->readAll();
80 | ui->label->setText(ba);
81 |
82 | }
83 |
84 | void MainWindow::realtimeDataSlot()
85 | {
86 | // calculate two new data points:
87 | #if QT_VERSION < QT_VERSION_CHECK(4, 7, 0)
88 | double key = 0;
89 | #else
90 | double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
91 | #endif
92 | static double lastPointKey = 0;
93 | if (key-lastPointKey > 0.01) // at most add point every 10 ms
94 | {
95 | double value0 = tan(key); //qSin(key); //sin(key*1.6+cos(key*1.7)*2)*10 + sin(key*1.2+0.56)*20 + 26;
96 | double value1 = -tan(key); //qCos(key); //sin(key*1.3+cos(key*1.2)*1.2)*7 + sin(key*0.9+0.26)*24 + 26;
97 | // add data to lines:
98 | ui->customPlot->graph(0)->addData(key, value0);
99 | ui->customPlot->graph(1)->addData(key, value1);
100 | // set data of dots:
101 | ui->customPlot->graph(2)->clearData();
102 | ui->customPlot->graph(2)->addData(key, value0);
103 | ui->customPlot->graph(3)->clearData();
104 | ui->customPlot->graph(3)->addData(key, value1);
105 | // remove data of lines that's outside visible range:
106 | ui->customPlot->graph(0)->removeDataBefore(key-8);
107 | ui->customPlot->graph(1)->removeDataBefore(key-8);
108 | // rescale value (vertical) axis to fit the current data:
109 | ui->customPlot->graph(0)->rescaleValueAxis();
110 | ui->customPlot->graph(1)->rescaleValueAxis(true);
111 | lastPointKey = key;
112 | }
113 | // make key axis range scroll with the data (at a constant range size of 8):
114 | ui->customPlot->xAxis->setRange(key+0.25, 8, Qt::AlignRight);
115 | ui->customPlot->replot();
116 |
117 | // calculate frames per second:
118 | static double lastFpsKey;
119 | static int frameCount;
120 | ++frameCount;
121 | if (key-lastFpsKey > 2) // average fps over 2 seconds
122 | {
123 | ui->statusBar->showMessage(
124 | QString("%1 FPS, Total Data points: %2")
125 | .arg(frameCount/(key-lastFpsKey), 0, 'f', 0)
126 | .arg(ui->customPlot->graph(0)->data()->count()+ui->customPlot->graph(1)->data()->count())
127 | , 0);
128 | lastFpsKey = key;
129 | frameCount = 0;
130 | }
131 | }
132 |
133 | void MainWindow::setupPlayground(QCustomPlot *customPlot)
134 | {
135 | Q_UNUSED(customPlot)
136 | }
137 |
138 | void MainWindow::on_pushButton_2_clicked()
139 | {
140 | serial = new QSerialPort(this);
141 | comport = ui->textEdit->toPlainText();
142 | serial->setPortName(comport);
143 | serial->open(QIODevice::ReadWrite);
144 | serial->setBaudRate(QSerialPort::Baud115200);
145 | serial->setDataBits(QSerialPort::Data8);
146 | serial->setParity(QSerialPort::NoParity);
147 | serial->setStopBits(QSerialPort::OneStop);
148 | serial->setFlowControl(QSerialPort::NoFlowControl);
149 | connect(serial,SIGNAL(readyRead()),this,SLOT(Receivedata()));
150 | ui->pushButton_2->setDisabled(true);
151 | ui->pushButton->setDisabled(false);
152 | }
153 |
154 |
--------------------------------------------------------------------------------
/mainwindow.h:
--------------------------------------------------------------------------------
1 | #ifndef MAINWINDOW_H
2 | #define MAINWINDOW_H
3 |
4 | #include
5 | #include
6 | #include "qcustomplot.h"
7 |
8 | namespace Ui {
9 | class MainWindow;
10 | }
11 |
12 | class MainWindow : public QMainWindow
13 | {
14 | Q_OBJECT
15 |
16 | public:
17 | explicit MainWindow(QWidget *parent = 0);
18 | ~MainWindow();
19 |
20 | private slots:
21 | void on_pushButton_clicked();
22 | void Receivedata();
23 | void realtimeDataSlot();
24 | void setupPlayground(QCustomPlot *customPlot);
25 |
26 | void on_pushButton_2_clicked();
27 |
28 |
29 |
30 | private:
31 | Ui::MainWindow *ui;
32 | QTimer dataTimer;
33 | };
34 |
35 | #endif // MAINWINDOW_H
36 |
--------------------------------------------------------------------------------
/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 740
10 | 611
11 |
12 |
13 |
14 | MainWindow
15 |
16 |
17 |
18 |
19 |
20 | 130
21 | 140
22 | 75
23 | 23
24 |
25 |
26 |
27 | Başlat
28 |
29 |
30 |
31 |
32 |
33 | 220
34 | 450
35 | 511
36 | 121
37 |
38 |
39 |
40 |
41 | 22
42 |
43 |
44 |
45 | Sonuçlar:
46 |
47 |
48 |
49 |
50 |
51 | 220
52 | 20
53 | 511
54 | 421
55 |
56 |
57 |
58 |
59 |
60 |
61 | 10
62 | 60
63 | 111
64 | 31
65 |
66 |
67 |
68 |
69 | 10
70 |
71 |
72 |
73 | <html><head/><body><p>COM3</p></body></html>
74 |
75 |
76 |
77 |
78 |
79 | 130
80 | 70
81 | 75
82 | 23
83 |
84 |
85 |
86 | Bağlan
87 |
88 |
89 |
90 |
91 |
92 | 10
93 | 130
94 | 111
95 | 31
96 |
97 |
98 |
99 |
100 | 10
101 |
102 |
103 |
104 |
105 |
106 |
107 | 10
108 | 40
109 | 81
110 | 21
111 |
112 |
113 |
114 |
115 | 12
116 |
117 |
118 |
119 | COMPORT:
120 |
121 |
122 |
123 |
124 |
125 | 10
126 | 112
127 | 81
128 | 16
129 |
130 |
131 |
132 |
133 | 12
134 |
135 |
136 |
137 | Servo Açısı:
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | QCustomPlot
147 | QWidget
148 |
149 | 1
150 |
151 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/qcustomplot.h:
--------------------------------------------------------------------------------
1 | /***************************************************************************
2 | ** **
3 | ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 | ** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer **
5 | ** **
6 | ** This program is free software: you can redistribute it and/or modify **
7 | ** it under the terms of the GNU General Public License as published by **
8 | ** the Free Software Foundation, either version 3 of the License, or **
9 | ** (at your option) any later version. **
10 | ** **
11 | ** This program is distributed in the hope that it will be useful, **
12 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 | ** GNU General Public License for more details. **
15 | ** **
16 | ** You should have received a copy of the GNU General Public License **
17 | ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 | ** **
19 | ****************************************************************************
20 | ** Author: Emanuel Eichhammer **
21 | ** Website/Contact: http://www.qcustomplot.com/ **
22 | ** Date: 07.04.14 **
23 | ** Version: 1.2.1 **
24 | ****************************************************************************/
25 |
26 | #ifndef QCUSTOMPLOT_H
27 | #define QCUSTOMPLOT_H
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 | #include
45 | #include
46 | #include
47 | #include
48 | #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
49 | # include
50 | # include
51 | # include
52 | #else
53 | # include
54 | # include
55 | #endif
56 |
57 | class QCPPainter;
58 | class QCustomPlot;
59 | class QCPLayerable;
60 | class QCPLayoutElement;
61 | class QCPLayout;
62 | class QCPAxis;
63 | class QCPAxisRect;
64 | class QCPAxisPainterPrivate;
65 | class QCPAbstractPlottable;
66 | class QCPGraph;
67 | class QCPAbstractItem;
68 | class QCPItemPosition;
69 | class QCPLayer;
70 | class QCPPlotTitle;
71 | class QCPLegend;
72 | class QCPAbstractLegendItem;
73 | class QCPColorMap;
74 | class QCPColorScale;
75 |
76 |
77 | /*! \file */
78 |
79 |
80 | // decl definitions for shared library compilation/usage:
81 | #if defined(QCUSTOMPLOT_COMPILE_LIBRARY)
82 | # define QCP_LIB_DECL Q_DECL_EXPORT
83 | #elif defined(QCUSTOMPLOT_USE_LIBRARY)
84 | # define QCP_LIB_DECL Q_DECL_IMPORT
85 | #else
86 | # define QCP_LIB_DECL
87 | #endif
88 |
89 | /*!
90 | The QCP Namespace contains general enums and QFlags used throughout the QCustomPlot library
91 | */
92 | namespace QCP
93 | {
94 | /*!
95 | Defines the sides of a rectangular entity to which margins can be applied.
96 |
97 | \see QCPLayoutElement::setAutoMargins, QCPAxisRect::setAutoMargins
98 | */
99 | enum MarginSide { msLeft = 0x01 ///< 0x01 left margin
100 | ,msRight = 0x02 ///< 0x02 right margin
101 | ,msTop = 0x04 ///< 0x04 top margin
102 | ,msBottom = 0x08 ///< 0x08 bottom margin
103 | ,msAll = 0xFF ///< 0xFF all margins
104 | ,msNone = 0x00 ///< 0x00 no margin
105 | };
106 | Q_DECLARE_FLAGS(MarginSides, MarginSide)
107 |
108 | /*!
109 | Defines what objects of a plot can be forcibly drawn antialiased/not antialiased. If an object is
110 | neither forcibly drawn antialiased nor forcibly drawn not antialiased, it is up to the respective
111 | element how it is drawn. Typically it provides a \a setAntialiased function for this.
112 |
113 | \c AntialiasedElements is a flag of or-combined elements of this enum type.
114 |
115 | \see QCustomPlot::setAntialiasedElements, QCustomPlot::setNotAntialiasedElements
116 | */
117 | enum AntialiasedElement { aeAxes = 0x0001 ///< 0x0001 Axis base line and tick marks
118 | ,aeGrid = 0x0002 ///< 0x0002 Grid lines
119 | ,aeSubGrid = 0x0004 ///< 0x0004 Sub grid lines
120 | ,aeLegend = 0x0008 ///< 0x0008 Legend box
121 | ,aeLegendItems = 0x0010 ///< 0x0010 Legend items
122 | ,aePlottables = 0x0020 ///< 0x0020 Main lines of plottables (excluding error bars, see element \ref aeErrorBars)
123 | ,aeItems = 0x0040 ///< 0x0040 Main lines of items
124 | ,aeScatters = 0x0080 ///< 0x0080 Scatter symbols of plottables (excluding scatter symbols of type ssPixmap)
125 | ,aeErrorBars = 0x0100 ///< 0x0100 Error bars
126 | ,aeFills = 0x0200 ///< 0x0200 Borders of fills (e.g. under or between graphs)
127 | ,aeZeroLine = 0x0400 ///< 0x0400 Zero-lines, see \ref QCPGrid::setZeroLinePen
128 | ,aeAll = 0xFFFF ///< 0xFFFF All elements
129 | ,aeNone = 0x0000 ///< 0x0000 No elements
130 | };
131 | Q_DECLARE_FLAGS(AntialiasedElements, AntialiasedElement)
132 |
133 | /*!
134 | Defines plotting hints that control various aspects of the quality and speed of plotting.
135 |
136 | \see QCustomPlot::setPlottingHints
137 | */
138 | enum PlottingHint { phNone = 0x000 ///< 0x000 No hints are set
139 | ,phFastPolylines = 0x001 ///< 0x001 Graph/Curve lines are drawn with a faster method. This reduces the quality
140 | ///< especially of the line segment joins. (Only relevant for solid line pens.)
141 | ,phForceRepaint = 0x002 ///< 0x002 causes an immediate repaint() instead of a soft update() when QCustomPlot::replot() is called with parameter \ref QCustomPlot::rpHint.
142 | ///< This is set by default to prevent the plot from freezing on fast consecutive replots (e.g. user drags ranges with mouse).
143 | ,phCacheLabels = 0x004 ///< 0x004 axis (tick) labels will be cached as pixmaps, increasing replot performance.
144 | };
145 | Q_DECLARE_FLAGS(PlottingHints, PlottingHint)
146 |
147 | /*!
148 | Defines the mouse interactions possible with QCustomPlot.
149 |
150 | \c Interactions is a flag of or-combined elements of this enum type.
151 |
152 | \see QCustomPlot::setInteractions
153 | */
154 | enum Interaction { iRangeDrag = 0x001 ///< 0x001 Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes)
155 | ,iRangeZoom = 0x002 ///< 0x002 Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes)
156 | ,iMultiSelect = 0x004 ///< 0x004 The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking
157 | ,iSelectPlottables = 0x008 ///< 0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable)
158 | ,iSelectAxes = 0x010 ///< 0x010 Axes are selectable (or parts of them, see QCPAxis::setSelectableParts)
159 | ,iSelectLegend = 0x020 ///< 0x020 Legends are selectable (or their child items, see QCPLegend::setSelectableParts)
160 | ,iSelectItems = 0x040 ///< 0x040 Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem)
161 | ,iSelectOther = 0x080 ///< 0x080 All other objects are selectable (e.g. your own derived layerables, the plot title,...)
162 | };
163 | Q_DECLARE_FLAGS(Interactions, Interaction)
164 |
165 | /*! \internal
166 |
167 | Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
168 | is \e nan or \e +/-inf). This function is used to check data validity upon replots, when the
169 | compiler flag \c QCUSTOMPLOT_CHECK_DATA is set.
170 | */
171 | inline bool isInvalidData(double value)
172 | {
173 | return qIsNaN(value) || qIsInf(value);
174 | }
175 |
176 | /*! \internal
177 | \overload
178 |
179 | Checks two arguments instead of one.
180 | */
181 | inline bool isInvalidData(double value1, double value2)
182 | {
183 | return isInvalidData(value1) || isInvalidData(value2);
184 | }
185 |
186 | /*! \internal
187 |
188 | Sets the specified \a side of \a margins to \a value
189 |
190 | \see getMarginValue
191 | */
192 | inline void setMarginValue(QMargins &margins, QCP::MarginSide side, int value)
193 | {
194 | switch (side)
195 | {
196 | case QCP::msLeft: margins.setLeft(value); break;
197 | case QCP::msRight: margins.setRight(value); break;
198 | case QCP::msTop: margins.setTop(value); break;
199 | case QCP::msBottom: margins.setBottom(value); break;
200 | case QCP::msAll: margins = QMargins(value, value, value, value); break;
201 | default: break;
202 | }
203 | }
204 |
205 | /*! \internal
206 |
207 | Returns the value of the specified \a side of \a margins. If \a side is \ref QCP::msNone or
208 | \ref QCP::msAll, returns 0.
209 |
210 | \see setMarginValue
211 | */
212 | inline int getMarginValue(const QMargins &margins, QCP::MarginSide side)
213 | {
214 | switch (side)
215 | {
216 | case QCP::msLeft: return margins.left();
217 | case QCP::msRight: return margins.right();
218 | case QCP::msTop: return margins.top();
219 | case QCP::msBottom: return margins.bottom();
220 | default: break;
221 | }
222 | return 0;
223 | }
224 |
225 | } // end of namespace QCP
226 |
227 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::AntialiasedElements)
228 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::PlottingHints)
229 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::MarginSides)
230 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCP::Interactions)
231 |
232 |
233 | class QCP_LIB_DECL QCPScatterStyle
234 | {
235 | Q_GADGET
236 | public:
237 | /*!
238 | Defines the shape used for scatter points.
239 |
240 | On plottables/items that draw scatters, the sizes of these visualizations (with exception of
241 | \ref ssDot and \ref ssPixmap) can be controlled with the \ref setSize function. Scatters are
242 | drawn with the pen and brush specified with \ref setPen and \ref setBrush.
243 | */
244 | Q_ENUMS(ScatterShape)
245 | enum ScatterShape { ssNone ///< no scatter symbols are drawn (e.g. in QCPGraph, data only represented with lines)
246 | ,ssDot ///< \enumimage{ssDot.png} a single pixel (use \ref ssDisc or \ref ssCircle if you want a round shape with a certain radius)
247 | ,ssCross ///< \enumimage{ssCross.png} a cross
248 | ,ssPlus ///< \enumimage{ssPlus.png} a plus
249 | ,ssCircle ///< \enumimage{ssCircle.png} a circle
250 | ,ssDisc ///< \enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
251 | ,ssSquare ///< \enumimage{ssSquare.png} a square
252 | ,ssDiamond ///< \enumimage{ssDiamond.png} a diamond
253 | ,ssStar ///< \enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
254 | ,ssTriangle ///< \enumimage{ssTriangle.png} an equilateral triangle, standing on baseline
255 | ,ssTriangleInverted ///< \enumimage{ssTriangleInverted.png} an equilateral triangle, standing on corner
256 | ,ssCrossSquare ///< \enumimage{ssCrossSquare.png} a square with a cross inside
257 | ,ssPlusSquare ///< \enumimage{ssPlusSquare.png} a square with a plus inside
258 | ,ssCrossCircle ///< \enumimage{ssCrossCircle.png} a circle with a cross inside
259 | ,ssPlusCircle ///< \enumimage{ssPlusCircle.png} a circle with a plus inside
260 | ,ssPeace ///< \enumimage{ssPeace.png} a circle, with one vertical and two downward diagonal lines
261 | ,ssPixmap ///< a custom pixmap specified by \ref setPixmap, centered on the data point coordinates
262 | ,ssCustom ///< custom painter operations are performed per scatter (As QPainterPath, see \ref setCustomPath)
263 | };
264 |
265 | QCPScatterStyle();
266 | QCPScatterStyle(ScatterShape shape, double size=6);
267 | QCPScatterStyle(ScatterShape shape, const QColor &color, double size);
268 | QCPScatterStyle(ScatterShape shape, const QColor &color, const QColor &fill, double size);
269 | QCPScatterStyle(ScatterShape shape, const QPen &pen, const QBrush &brush, double size);
270 | QCPScatterStyle(const QPixmap &pixmap);
271 | QCPScatterStyle(const QPainterPath &customPath, const QPen &pen, const QBrush &brush=Qt::NoBrush, double size=6);
272 |
273 | // getters:
274 | double size() const { return mSize; }
275 | ScatterShape shape() const { return mShape; }
276 | QPen pen() const { return mPen; }
277 | QBrush brush() const { return mBrush; }
278 | QPixmap pixmap() const { return mPixmap; }
279 | QPainterPath customPath() const { return mCustomPath; }
280 |
281 | // setters:
282 | void setSize(double size);
283 | void setShape(ScatterShape shape);
284 | void setPen(const QPen &pen);
285 | void setBrush(const QBrush &brush);
286 | void setPixmap(const QPixmap &pixmap);
287 | void setCustomPath(const QPainterPath &customPath);
288 |
289 | // non-property methods:
290 | bool isNone() const { return mShape == ssNone; }
291 | bool isPenDefined() const { return mPenDefined; }
292 | void applyTo(QCPPainter *painter, const QPen &defaultPen) const;
293 | void drawShape(QCPPainter *painter, QPointF pos) const;
294 | void drawShape(QCPPainter *painter, double x, double y) const;
295 |
296 | protected:
297 | // property members:
298 | double mSize;
299 | ScatterShape mShape;
300 | QPen mPen;
301 | QBrush mBrush;
302 | QPixmap mPixmap;
303 | QPainterPath mCustomPath;
304 |
305 | // non-property members:
306 | bool mPenDefined;
307 | };
308 | Q_DECLARE_TYPEINFO(QCPScatterStyle, Q_MOVABLE_TYPE);
309 |
310 |
311 | class QCP_LIB_DECL QCPPainter : public QPainter
312 | {
313 | Q_GADGET
314 | public:
315 | /*!
316 | Defines special modes the painter can operate in. They disable or enable certain subsets of features/fixes/workarounds,
317 | depending on whether they are wanted on the respective output device.
318 | */
319 | enum PainterMode { pmDefault = 0x00 ///< 0x00 Default mode for painting on screen devices
320 | ,pmVectorized = 0x01 ///< 0x01 Mode for vectorized painting (e.g. PDF export). For example, this prevents some antialiasing fixes.
321 | ,pmNoCaching = 0x02 ///< 0x02 Mode for all sorts of exports (e.g. PNG, PDF,...). For example, this prevents using cached pixmap labels
322 | ,pmNonCosmetic = 0x04 ///< 0x04 Turns pen widths 0 to 1, i.e. disables cosmetic pens. (A cosmetic pen is always drawn with width 1 pixel in the vector image/pdf viewer, independent of zoom.)
323 | };
324 | Q_FLAGS(PainterMode PainterModes)
325 | Q_DECLARE_FLAGS(PainterModes, PainterMode)
326 |
327 | QCPPainter();
328 | QCPPainter(QPaintDevice *device);
329 | ~QCPPainter();
330 |
331 | // getters:
332 | bool antialiasing() const { return testRenderHint(QPainter::Antialiasing); }
333 | PainterModes modes() const { return mModes; }
334 |
335 | // setters:
336 | void setAntialiasing(bool enabled);
337 | void setMode(PainterMode mode, bool enabled=true);
338 | void setModes(PainterModes modes);
339 |
340 | // methods hiding non-virtual base class functions (QPainter bug workarounds):
341 | bool begin(QPaintDevice *device);
342 | void setPen(const QPen &pen);
343 | void setPen(const QColor &color);
344 | void setPen(Qt::PenStyle penStyle);
345 | void drawLine(const QLineF &line);
346 | void drawLine(const QPointF &p1, const QPointF &p2) {drawLine(QLineF(p1, p2));}
347 | void save();
348 | void restore();
349 |
350 | // non-virtual methods:
351 | void makeNonCosmetic();
352 |
353 | protected:
354 | // property members:
355 | PainterModes mModes;
356 | bool mIsAntialiasing;
357 |
358 | // non-property members:
359 | QStack mAntialiasingStack;
360 | };
361 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCPPainter::PainterModes)
362 |
363 |
364 | class QCP_LIB_DECL QCPLayer : public QObject
365 | {
366 | Q_OBJECT
367 | /// \cond INCLUDE_QPROPERTIES
368 | Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
369 | Q_PROPERTY(QString name READ name)
370 | Q_PROPERTY(int index READ index)
371 | Q_PROPERTY(QList children READ children)
372 | Q_PROPERTY(bool visible READ visible WRITE setVisible)
373 | /// \endcond
374 | public:
375 | QCPLayer(QCustomPlot* parentPlot, const QString &layerName);
376 | ~QCPLayer();
377 |
378 | // getters:
379 | QCustomPlot *parentPlot() const { return mParentPlot; }
380 | QString name() const { return mName; }
381 | int index() const { return mIndex; }
382 | QList children() const { return mChildren; }
383 | bool visible() const { return mVisible; }
384 |
385 | // setters:
386 | void setVisible(bool visible);
387 |
388 | protected:
389 | // property members:
390 | QCustomPlot *mParentPlot;
391 | QString mName;
392 | int mIndex;
393 | QList mChildren;
394 | bool mVisible;
395 |
396 | // non-virtual methods:
397 | void addChild(QCPLayerable *layerable, bool prepend);
398 | void removeChild(QCPLayerable *layerable);
399 |
400 | private:
401 | Q_DISABLE_COPY(QCPLayer)
402 |
403 | friend class QCustomPlot;
404 | friend class QCPLayerable;
405 | };
406 |
407 | class QCP_LIB_DECL QCPLayerable : public QObject
408 | {
409 | Q_OBJECT
410 | /// \cond INCLUDE_QPROPERTIES
411 | Q_PROPERTY(bool visible READ visible WRITE setVisible)
412 | Q_PROPERTY(QCustomPlot* parentPlot READ parentPlot)
413 | Q_PROPERTY(QCPLayerable* parentLayerable READ parentLayerable)
414 | Q_PROPERTY(QCPLayer* layer READ layer WRITE setLayer NOTIFY layerChanged)
415 | Q_PROPERTY(bool antialiased READ antialiased WRITE setAntialiased)
416 | /// \endcond
417 | public:
418 | QCPLayerable(QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0);
419 | ~QCPLayerable();
420 |
421 | // getters:
422 | bool visible() const { return mVisible; }
423 | QCustomPlot *parentPlot() const { return mParentPlot; }
424 | QCPLayerable *parentLayerable() const { return mParentLayerable.data(); }
425 | QCPLayer *layer() const { return mLayer; }
426 | bool antialiased() const { return mAntialiased; }
427 |
428 | // setters:
429 | void setVisible(bool on);
430 | Q_SLOT bool setLayer(QCPLayer *layer);
431 | bool setLayer(const QString &layerName);
432 | void setAntialiased(bool enabled);
433 |
434 | // introduced virtual methods:
435 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
436 |
437 | // non-property methods:
438 | bool realVisibility() const;
439 |
440 | signals:
441 | void layerChanged(QCPLayer *newLayer);
442 |
443 | protected:
444 | // property members:
445 | bool mVisible;
446 | QCustomPlot *mParentPlot;
447 | QPointer mParentLayerable;
448 | QCPLayer *mLayer;
449 | bool mAntialiased;
450 |
451 | // introduced virtual methods:
452 | virtual void parentPlotInitialized(QCustomPlot *parentPlot);
453 | virtual QCP::Interaction selectionCategory() const;
454 | virtual QRect clipRect() const;
455 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const = 0;
456 | virtual void draw(QCPPainter *painter) = 0;
457 | // events:
458 | virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
459 | virtual void deselectEvent(bool *selectionStateChanged);
460 |
461 | // non-property methods:
462 | void initializeParentPlot(QCustomPlot *parentPlot);
463 | void setParentLayerable(QCPLayerable* parentLayerable);
464 | bool moveToLayer(QCPLayer *layer, bool prepend);
465 | void applyAntialiasingHint(QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const;
466 |
467 | private:
468 | Q_DISABLE_COPY(QCPLayerable)
469 |
470 | friend class QCustomPlot;
471 | friend class QCPAxisRect;
472 | };
473 |
474 |
475 | class QCP_LIB_DECL QCPRange
476 | {
477 | public:
478 | double lower, upper;
479 |
480 | QCPRange();
481 | QCPRange(double lower, double upper);
482 |
483 | bool operator==(const QCPRange& other) { return lower == other.lower && upper == other.upper; }
484 | bool operator!=(const QCPRange& other) { return !(*this == other); }
485 |
486 | QCPRange &operator+=(const double& value) { lower+=value; upper+=value; return *this; }
487 | QCPRange &operator-=(const double& value) { lower-=value; upper-=value; return *this; }
488 | QCPRange &operator*=(const double& value) { lower*=value; upper*=value; return *this; }
489 | QCPRange &operator/=(const double& value) { lower/=value; upper/=value; return *this; }
490 | friend inline const QCPRange operator+(const QCPRange&, double);
491 | friend inline const QCPRange operator+(double, const QCPRange&);
492 | friend inline const QCPRange operator-(const QCPRange& range, double value);
493 | friend inline const QCPRange operator*(const QCPRange& range, double value);
494 | friend inline const QCPRange operator*(double value, const QCPRange& range);
495 | friend inline const QCPRange operator/(const QCPRange& range, double value);
496 |
497 | double size() const;
498 | double center() const;
499 | void normalize();
500 | void expand(const QCPRange &otherRange);
501 | QCPRange expanded(const QCPRange &otherRange) const;
502 | QCPRange sanitizedForLogScale() const;
503 | QCPRange sanitizedForLinScale() const;
504 | bool contains(double value) const;
505 |
506 | static bool validRange(double lower, double upper);
507 | static bool validRange(const QCPRange &range);
508 | static const double minRange; //1e-280;
509 | static const double maxRange; //1e280;
510 |
511 | };
512 | Q_DECLARE_TYPEINFO(QCPRange, Q_MOVABLE_TYPE);
513 |
514 | /* documentation of inline functions */
515 |
516 | /*! \fn QCPRange &QCPRange::operator+=(const double& value)
517 |
518 | Adds \a value to both boundaries of the range.
519 | */
520 |
521 | /*! \fn QCPRange &QCPRange::operator-=(const double& value)
522 |
523 | Subtracts \a value from both boundaries of the range.
524 | */
525 |
526 | /*! \fn QCPRange &QCPRange::operator*=(const double& value)
527 |
528 | Multiplies both boundaries of the range by \a value.
529 | */
530 |
531 | /*! \fn QCPRange &QCPRange::operator/=(const double& value)
532 |
533 | Divides both boundaries of the range by \a value.
534 | */
535 |
536 | /* end documentation of inline functions */
537 |
538 | /*!
539 | Adds \a value to both boundaries of the range.
540 | */
541 | inline const QCPRange operator+(const QCPRange& range, double value)
542 | {
543 | QCPRange result(range);
544 | result += value;
545 | return result;
546 | }
547 |
548 | /*!
549 | Adds \a value to both boundaries of the range.
550 | */
551 | inline const QCPRange operator+(double value, const QCPRange& range)
552 | {
553 | QCPRange result(range);
554 | result += value;
555 | return result;
556 | }
557 |
558 | /*!
559 | Subtracts \a value from both boundaries of the range.
560 | */
561 | inline const QCPRange operator-(const QCPRange& range, double value)
562 | {
563 | QCPRange result(range);
564 | result -= value;
565 | return result;
566 | }
567 |
568 | /*!
569 | Multiplies both boundaries of the range by \a value.
570 | */
571 | inline const QCPRange operator*(const QCPRange& range, double value)
572 | {
573 | QCPRange result(range);
574 | result *= value;
575 | return result;
576 | }
577 |
578 | /*!
579 | Multiplies both boundaries of the range by \a value.
580 | */
581 | inline const QCPRange operator*(double value, const QCPRange& range)
582 | {
583 | QCPRange result(range);
584 | result *= value;
585 | return result;
586 | }
587 |
588 | /*!
589 | Divides both boundaries of the range by \a value.
590 | */
591 | inline const QCPRange operator/(const QCPRange& range, double value)
592 | {
593 | QCPRange result(range);
594 | result /= value;
595 | return result;
596 | }
597 |
598 |
599 | class QCP_LIB_DECL QCPMarginGroup : public QObject
600 | {
601 | Q_OBJECT
602 | public:
603 | QCPMarginGroup(QCustomPlot *parentPlot);
604 | ~QCPMarginGroup();
605 |
606 | // non-virtual methods:
607 | QList elements(QCP::MarginSide side) const { return mChildren.value(side); }
608 | bool isEmpty() const;
609 | void clear();
610 |
611 | protected:
612 | // non-property members:
613 | QCustomPlot *mParentPlot;
614 | QHash > mChildren;
615 |
616 | // non-virtual methods:
617 | int commonMargin(QCP::MarginSide side) const;
618 | void addChild(QCP::MarginSide side, QCPLayoutElement *element);
619 | void removeChild(QCP::MarginSide side, QCPLayoutElement *element);
620 |
621 | private:
622 | Q_DISABLE_COPY(QCPMarginGroup)
623 |
624 | friend class QCPLayoutElement;
625 | };
626 |
627 |
628 | class QCP_LIB_DECL QCPLayoutElement : public QCPLayerable
629 | {
630 | Q_OBJECT
631 | /// \cond INCLUDE_QPROPERTIES
632 | Q_PROPERTY(QCPLayout* layout READ layout)
633 | Q_PROPERTY(QRect rect READ rect)
634 | Q_PROPERTY(QRect outerRect READ outerRect WRITE setOuterRect)
635 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
636 | Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
637 | Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
638 | Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
639 | /// \endcond
640 | public:
641 | /*!
642 | Defines the phases of the update process, that happens just before a replot. At each phase,
643 | \ref update is called with the according UpdatePhase value.
644 | */
645 | enum UpdatePhase { upPreparation ///< Phase used for any type of preparation that needs to be done before margin calculation and layout
646 | ,upMargins ///< Phase in which the margins are calculated and set
647 | ,upLayout ///< Final phase in which the layout system places the rects of the elements
648 | };
649 | Q_ENUMS(UpdatePhase)
650 |
651 | explicit QCPLayoutElement(QCustomPlot *parentPlot=0);
652 | virtual ~QCPLayoutElement();
653 |
654 | // getters:
655 | QCPLayout *layout() const { return mParentLayout; }
656 | QRect rect() const { return mRect; }
657 | QRect outerRect() const { return mOuterRect; }
658 | QMargins margins() const { return mMargins; }
659 | QMargins minimumMargins() const { return mMinimumMargins; }
660 | QCP::MarginSides autoMargins() const { return mAutoMargins; }
661 | QSize minimumSize() const { return mMinimumSize; }
662 | QSize maximumSize() const { return mMaximumSize; }
663 | QCPMarginGroup *marginGroup(QCP::MarginSide side) const { return mMarginGroups.value(side, (QCPMarginGroup*)0); }
664 | QHash marginGroups() const { return mMarginGroups; }
665 |
666 | // setters:
667 | void setOuterRect(const QRect &rect);
668 | void setMargins(const QMargins &margins);
669 | void setMinimumMargins(const QMargins &margins);
670 | void setAutoMargins(QCP::MarginSides sides);
671 | void setMinimumSize(const QSize &size);
672 | void setMinimumSize(int width, int height);
673 | void setMaximumSize(const QSize &size);
674 | void setMaximumSize(int width, int height);
675 | void setMarginGroup(QCP::MarginSides sides, QCPMarginGroup *group);
676 |
677 | // introduced virtual methods:
678 | virtual void update(UpdatePhase phase);
679 | virtual QSize minimumSizeHint() const;
680 | virtual QSize maximumSizeHint() const;
681 | virtual QList elements(bool recursive) const;
682 |
683 | // reimplemented virtual methods:
684 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
685 |
686 | protected:
687 | // property members:
688 | QCPLayout *mParentLayout;
689 | QSize mMinimumSize, mMaximumSize;
690 | QRect mRect, mOuterRect;
691 | QMargins mMargins, mMinimumMargins;
692 | QCP::MarginSides mAutoMargins;
693 | QHash mMarginGroups;
694 |
695 | // introduced virtual methods:
696 | virtual int calculateAutoMargin(QCP::MarginSide side);
697 | // events:
698 | virtual void mousePressEvent(QMouseEvent *event) {Q_UNUSED(event)}
699 | virtual void mouseMoveEvent(QMouseEvent *event) {Q_UNUSED(event)}
700 | virtual void mouseReleaseEvent(QMouseEvent *event) {Q_UNUSED(event)}
701 | virtual void mouseDoubleClickEvent(QMouseEvent *event) {Q_UNUSED(event)}
702 | virtual void wheelEvent(QWheelEvent *event) {Q_UNUSED(event)}
703 |
704 | // reimplemented virtual methods:
705 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const { Q_UNUSED(painter) }
706 | virtual void draw(QCPPainter *painter) { Q_UNUSED(painter) }
707 | virtual void parentPlotInitialized(QCustomPlot *parentPlot);
708 |
709 | private:
710 | Q_DISABLE_COPY(QCPLayoutElement)
711 |
712 | friend class QCustomPlot;
713 | friend class QCPLayout;
714 | friend class QCPMarginGroup;
715 | };
716 |
717 |
718 | class QCP_LIB_DECL QCPLayout : public QCPLayoutElement
719 | {
720 | Q_OBJECT
721 | public:
722 | explicit QCPLayout();
723 |
724 | // reimplemented virtual methods:
725 | virtual void update(UpdatePhase phase);
726 | virtual QList elements(bool recursive) const;
727 |
728 | // introduced virtual methods:
729 | virtual int elementCount() const = 0;
730 | virtual QCPLayoutElement* elementAt(int index) const = 0;
731 | virtual QCPLayoutElement* takeAt(int index) = 0;
732 | virtual bool take(QCPLayoutElement* element) = 0;
733 | virtual void simplify();
734 |
735 | // non-virtual methods:
736 | bool removeAt(int index);
737 | bool remove(QCPLayoutElement* element);
738 | void clear();
739 |
740 | protected:
741 | // introduced virtual methods:
742 | virtual void updateLayout();
743 |
744 | // non-virtual methods:
745 | void sizeConstraintsChanged() const;
746 | void adoptElement(QCPLayoutElement *el);
747 | void releaseElement(QCPLayoutElement *el);
748 | QVector getSectionSizes(QVector maxSizes, QVector minSizes, QVector stretchFactors, int totalSize) const;
749 |
750 | private:
751 | Q_DISABLE_COPY(QCPLayout)
752 | friend class QCPLayoutElement;
753 | };
754 |
755 |
756 | class QCP_LIB_DECL QCPLayoutGrid : public QCPLayout
757 | {
758 | Q_OBJECT
759 | /// \cond INCLUDE_QPROPERTIES
760 | Q_PROPERTY(int rowCount READ rowCount)
761 | Q_PROPERTY(int columnCount READ columnCount)
762 | Q_PROPERTY(QList columnStretchFactors READ columnStretchFactors WRITE setColumnStretchFactors)
763 | Q_PROPERTY(QList rowStretchFactors READ rowStretchFactors WRITE setRowStretchFactors)
764 | Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
765 | Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
766 | /// \endcond
767 | public:
768 | explicit QCPLayoutGrid();
769 | virtual ~QCPLayoutGrid();
770 |
771 | // getters:
772 | int rowCount() const;
773 | int columnCount() const;
774 | QList columnStretchFactors() const { return mColumnStretchFactors; }
775 | QList rowStretchFactors() const { return mRowStretchFactors; }
776 | int columnSpacing() const { return mColumnSpacing; }
777 | int rowSpacing() const { return mRowSpacing; }
778 |
779 | // setters:
780 | void setColumnStretchFactor(int column, double factor);
781 | void setColumnStretchFactors(const QList &factors);
782 | void setRowStretchFactor(int row, double factor);
783 | void setRowStretchFactors(const QList &factors);
784 | void setColumnSpacing(int pixels);
785 | void setRowSpacing(int pixels);
786 |
787 | // reimplemented virtual methods:
788 | virtual void updateLayout();
789 | virtual int elementCount() const;
790 | virtual QCPLayoutElement* elementAt(int index) const;
791 | virtual QCPLayoutElement* takeAt(int index);
792 | virtual bool take(QCPLayoutElement* element);
793 | virtual QList elements(bool recursive) const;
794 | virtual void simplify();
795 | virtual QSize minimumSizeHint() const;
796 | virtual QSize maximumSizeHint() const;
797 |
798 | // non-virtual methods:
799 | QCPLayoutElement *element(int row, int column) const;
800 | bool addElement(int row, int column, QCPLayoutElement *element);
801 | bool hasElement(int row, int column);
802 | void expandTo(int newRowCount, int newColumnCount);
803 | void insertRow(int newIndex);
804 | void insertColumn(int newIndex);
805 |
806 | protected:
807 | // property members:
808 | QList > mElements;
809 | QList mColumnStretchFactors;
810 | QList mRowStretchFactors;
811 | int mColumnSpacing, mRowSpacing;
812 |
813 | // non-virtual methods:
814 | void getMinimumRowColSizes(QVector *minColWidths, QVector *minRowHeights) const;
815 | void getMaximumRowColSizes(QVector *maxColWidths, QVector *maxRowHeights) const;
816 |
817 | private:
818 | Q_DISABLE_COPY(QCPLayoutGrid)
819 | };
820 |
821 |
822 | class QCP_LIB_DECL QCPLayoutInset : public QCPLayout
823 | {
824 | Q_OBJECT
825 | public:
826 | /*!
827 | Defines how the placement and sizing is handled for a certain element in a QCPLayoutInset.
828 | */
829 | enum InsetPlacement { ipFree ///< The element may be positioned/sized arbitrarily, see \ref setInsetRect
830 | ,ipBorderAligned ///< The element is aligned to one of the layout sides, see \ref setInsetAlignment
831 | };
832 |
833 | explicit QCPLayoutInset();
834 | virtual ~QCPLayoutInset();
835 |
836 | // getters:
837 | InsetPlacement insetPlacement(int index) const;
838 | Qt::Alignment insetAlignment(int index) const;
839 | QRectF insetRect(int index) const;
840 |
841 | // setters:
842 | void setInsetPlacement(int index, InsetPlacement placement);
843 | void setInsetAlignment(int index, Qt::Alignment alignment);
844 | void setInsetRect(int index, const QRectF &rect);
845 |
846 | // reimplemented virtual methods:
847 | virtual void updateLayout();
848 | virtual int elementCount() const;
849 | virtual QCPLayoutElement* elementAt(int index) const;
850 | virtual QCPLayoutElement* takeAt(int index);
851 | virtual bool take(QCPLayoutElement* element);
852 | virtual void simplify() {}
853 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
854 |
855 | // non-virtual methods:
856 | void addElement(QCPLayoutElement *element, Qt::Alignment alignment);
857 | void addElement(QCPLayoutElement *element, const QRectF &rect);
858 |
859 | protected:
860 | // property members:
861 | QList mElements;
862 | QList mInsetPlacement;
863 | QList mInsetAlignment;
864 | QList mInsetRect;
865 |
866 | private:
867 | Q_DISABLE_COPY(QCPLayoutInset)
868 | };
869 |
870 |
871 | class QCP_LIB_DECL QCPLineEnding
872 | {
873 | Q_GADGET
874 | public:
875 | /*!
876 | Defines the type of ending decoration for line-like items, e.g. an arrow.
877 |
878 | \image html QCPLineEnding.png
879 |
880 | The width and length of these decorations can be controlled with the functions \ref setWidth
881 | and \ref setLength. Some decorations like \ref esDisc, \ref esSquare, \ref esDiamond and \ref esBar only
882 | support a width, the length property is ignored.
883 |
884 | \see QCPItemLine::setHead, QCPItemLine::setTail, QCPItemCurve::setHead, QCPItemCurve::setTail, QCPAxis::setLowerEnding, QCPAxis::setUpperEnding
885 | */
886 | Q_ENUMS(EndingStyle)
887 | enum EndingStyle { esNone ///< No ending decoration
888 | ,esFlatArrow ///< A filled arrow head with a straight/flat back (a triangle)
889 | ,esSpikeArrow ///< A filled arrow head with an indented back
890 | ,esLineArrow ///< A non-filled arrow head with open back
891 | ,esDisc ///< A filled circle
892 | ,esSquare ///< A filled square
893 | ,esDiamond ///< A filled diamond (45° rotated square)
894 | ,esBar ///< A bar perpendicular to the line
895 | ,esHalfBar ///< A bar perpendicular to the line, pointing out to only one side (to which side can be changed with \ref setInverted)
896 | ,esSkewedBar ///< A bar that is skewed (skew controllable via \ref setLength)
897 | };
898 |
899 | QCPLineEnding();
900 | QCPLineEnding(EndingStyle style, double width=8, double length=10, bool inverted=false);
901 |
902 | // getters:
903 | EndingStyle style() const { return mStyle; }
904 | double width() const { return mWidth; }
905 | double length() const { return mLength; }
906 | bool inverted() const { return mInverted; }
907 |
908 | // setters:
909 | void setStyle(EndingStyle style);
910 | void setWidth(double width);
911 | void setLength(double length);
912 | void setInverted(bool inverted);
913 |
914 | // non-property methods:
915 | double boundingDistance() const;
916 | double realLength() const;
917 | void draw(QCPPainter *painter, const QVector2D &pos, const QVector2D &dir) const;
918 | void draw(QCPPainter *painter, const QVector2D &pos, double angle) const;
919 |
920 | protected:
921 | // property members:
922 | EndingStyle mStyle;
923 | double mWidth, mLength;
924 | bool mInverted;
925 | };
926 | Q_DECLARE_TYPEINFO(QCPLineEnding, Q_MOVABLE_TYPE);
927 |
928 |
929 | class QCP_LIB_DECL QCPGrid :public QCPLayerable
930 | {
931 | Q_OBJECT
932 | /// \cond INCLUDE_QPROPERTIES
933 | Q_PROPERTY(bool subGridVisible READ subGridVisible WRITE setSubGridVisible)
934 | Q_PROPERTY(bool antialiasedSubGrid READ antialiasedSubGrid WRITE setAntialiasedSubGrid)
935 | Q_PROPERTY(bool antialiasedZeroLine READ antialiasedZeroLine WRITE setAntialiasedZeroLine)
936 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
937 | Q_PROPERTY(QPen subGridPen READ subGridPen WRITE setSubGridPen)
938 | Q_PROPERTY(QPen zeroLinePen READ zeroLinePen WRITE setZeroLinePen)
939 | /// \endcond
940 | public:
941 | QCPGrid(QCPAxis *parentAxis);
942 |
943 | // getters:
944 | bool subGridVisible() const { return mSubGridVisible; }
945 | bool antialiasedSubGrid() const { return mAntialiasedSubGrid; }
946 | bool antialiasedZeroLine() const { return mAntialiasedZeroLine; }
947 | QPen pen() const { return mPen; }
948 | QPen subGridPen() const { return mSubGridPen; }
949 | QPen zeroLinePen() const { return mZeroLinePen; }
950 |
951 | // setters:
952 | void setSubGridVisible(bool visible);
953 | void setAntialiasedSubGrid(bool enabled);
954 | void setAntialiasedZeroLine(bool enabled);
955 | void setPen(const QPen &pen);
956 | void setSubGridPen(const QPen &pen);
957 | void setZeroLinePen(const QPen &pen);
958 |
959 | protected:
960 | // property members:
961 | bool mSubGridVisible;
962 | bool mAntialiasedSubGrid, mAntialiasedZeroLine;
963 | QPen mPen, mSubGridPen, mZeroLinePen;
964 | // non-property members:
965 | QCPAxis *mParentAxis;
966 |
967 | // reimplemented virtual methods:
968 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
969 | virtual void draw(QCPPainter *painter);
970 |
971 | // non-virtual methods:
972 | void drawGridLines(QCPPainter *painter) const;
973 | void drawSubGridLines(QCPPainter *painter) const;
974 |
975 | friend class QCPAxis;
976 | };
977 |
978 |
979 | class QCP_LIB_DECL QCPAxis : public QCPLayerable
980 | {
981 | Q_OBJECT
982 | /// \cond INCLUDE_QPROPERTIES
983 | Q_PROPERTY(AxisType axisType READ axisType)
984 | Q_PROPERTY(QCPAxisRect* axisRect READ axisRect)
985 | Q_PROPERTY(ScaleType scaleType READ scaleType WRITE setScaleType NOTIFY scaleTypeChanged)
986 | Q_PROPERTY(double scaleLogBase READ scaleLogBase WRITE setScaleLogBase)
987 | Q_PROPERTY(QCPRange range READ range WRITE setRange NOTIFY rangeChanged)
988 | Q_PROPERTY(bool rangeReversed READ rangeReversed WRITE setRangeReversed)
989 | Q_PROPERTY(bool autoTicks READ autoTicks WRITE setAutoTicks)
990 | Q_PROPERTY(int autoTickCount READ autoTickCount WRITE setAutoTickCount)
991 | Q_PROPERTY(bool autoTickLabels READ autoTickLabels WRITE setAutoTickLabels)
992 | Q_PROPERTY(bool autoTickStep READ autoTickStep WRITE setAutoTickStep)
993 | Q_PROPERTY(bool autoSubTicks READ autoSubTicks WRITE setAutoSubTicks)
994 | Q_PROPERTY(bool ticks READ ticks WRITE setTicks)
995 | Q_PROPERTY(bool tickLabels READ tickLabels WRITE setTickLabels)
996 | Q_PROPERTY(int tickLabelPadding READ tickLabelPadding WRITE setTickLabelPadding)
997 | Q_PROPERTY(LabelType tickLabelType READ tickLabelType WRITE setTickLabelType)
998 | Q_PROPERTY(QFont tickLabelFont READ tickLabelFont WRITE setTickLabelFont)
999 | Q_PROPERTY(QColor tickLabelColor READ tickLabelColor WRITE setTickLabelColor)
1000 | Q_PROPERTY(double tickLabelRotation READ tickLabelRotation WRITE setTickLabelRotation)
1001 | Q_PROPERTY(QString dateTimeFormat READ dateTimeFormat WRITE setDateTimeFormat)
1002 | Q_PROPERTY(Qt::TimeSpec dateTimeSpec READ dateTimeSpec WRITE setDateTimeSpec)
1003 | Q_PROPERTY(QString numberFormat READ numberFormat WRITE setNumberFormat)
1004 | Q_PROPERTY(int numberPrecision READ numberPrecision WRITE setNumberPrecision)
1005 | Q_PROPERTY(double tickStep READ tickStep WRITE setTickStep)
1006 | Q_PROPERTY(QVector tickVector READ tickVector WRITE setTickVector)
1007 | Q_PROPERTY(QVector tickVectorLabels READ tickVectorLabels WRITE setTickVectorLabels)
1008 | Q_PROPERTY(int tickLengthIn READ tickLengthIn WRITE setTickLengthIn)
1009 | Q_PROPERTY(int tickLengthOut READ tickLengthOut WRITE setTickLengthOut)
1010 | Q_PROPERTY(int subTickCount READ subTickCount WRITE setSubTickCount)
1011 | Q_PROPERTY(int subTickLengthIn READ subTickLengthIn WRITE setSubTickLengthIn)
1012 | Q_PROPERTY(int subTickLengthOut READ subTickLengthOut WRITE setSubTickLengthOut)
1013 | Q_PROPERTY(QPen basePen READ basePen WRITE setBasePen)
1014 | Q_PROPERTY(QPen tickPen READ tickPen WRITE setTickPen)
1015 | Q_PROPERTY(QPen subTickPen READ subTickPen WRITE setSubTickPen)
1016 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont)
1017 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor)
1018 | Q_PROPERTY(QString label READ label WRITE setLabel)
1019 | Q_PROPERTY(int labelPadding READ labelPadding WRITE setLabelPadding)
1020 | Q_PROPERTY(int padding READ padding WRITE setPadding)
1021 | Q_PROPERTY(int offset READ offset WRITE setOffset)
1022 | Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectionChanged)
1023 | Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectableChanged)
1024 | Q_PROPERTY(QFont selectedTickLabelFont READ selectedTickLabelFont WRITE setSelectedTickLabelFont)
1025 | Q_PROPERTY(QFont selectedLabelFont READ selectedLabelFont WRITE setSelectedLabelFont)
1026 | Q_PROPERTY(QColor selectedTickLabelColor READ selectedTickLabelColor WRITE setSelectedTickLabelColor)
1027 | Q_PROPERTY(QColor selectedLabelColor READ selectedLabelColor WRITE setSelectedLabelColor)
1028 | Q_PROPERTY(QPen selectedBasePen READ selectedBasePen WRITE setSelectedBasePen)
1029 | Q_PROPERTY(QPen selectedTickPen READ selectedTickPen WRITE setSelectedTickPen)
1030 | Q_PROPERTY(QPen selectedSubTickPen READ selectedSubTickPen WRITE setSelectedSubTickPen)
1031 | Q_PROPERTY(QCPLineEnding lowerEnding READ lowerEnding WRITE setLowerEnding)
1032 | Q_PROPERTY(QCPLineEnding upperEnding READ upperEnding WRITE setUpperEnding)
1033 | Q_PROPERTY(QCPGrid* grid READ grid)
1034 | /// \endcond
1035 | public:
1036 | /*!
1037 | Defines at which side of the axis rect the axis will appear. This also affects how the tick
1038 | marks are drawn, on which side the labels are placed etc.
1039 | */
1040 | enum AxisType { atLeft = 0x01 ///< 0x01 Axis is vertical and on the left side of the axis rect
1041 | ,atRight = 0x02 ///< 0x02 Axis is vertical and on the right side of the axis rect
1042 | ,atTop = 0x04 ///< 0x04 Axis is horizontal and on the top side of the axis rect
1043 | ,atBottom = 0x08 ///< 0x08 Axis is horizontal and on the bottom side of the axis rect
1044 | };
1045 | Q_FLAGS(AxisType AxisTypes)
1046 | Q_DECLARE_FLAGS(AxisTypes, AxisType)
1047 | /*!
1048 | When automatic tick label generation is enabled (\ref setAutoTickLabels), defines how the
1049 | coordinate of the tick is interpreted, i.e. translated into a string.
1050 |
1051 | \see setTickLabelType
1052 | */
1053 | enum LabelType { ltNumber ///< Tick coordinate is regarded as normal number and will be displayed as such. (see \ref setNumberFormat)
1054 | ,ltDateTime ///< Tick coordinate is regarded as a date/time (seconds since 1970-01-01T00:00:00 UTC) and will be displayed and formatted as such. (for details, see \ref setDateTimeFormat)
1055 | };
1056 | Q_ENUMS(LabelType)
1057 | /*!
1058 | Defines the scale of an axis.
1059 | \see setScaleType
1060 | */
1061 | enum ScaleType { stLinear ///< Linear scaling
1062 | ,stLogarithmic ///< Logarithmic scaling with correspondingly transformed plots and (major) tick marks at every base power (see \ref setScaleLogBase).
1063 | };
1064 | Q_ENUMS(ScaleType)
1065 | /*!
1066 | Defines the selectable parts of an axis.
1067 | \see setSelectableParts, setSelectedParts
1068 | */
1069 | enum SelectablePart { spNone = 0 ///< None of the selectable parts
1070 | ,spAxis = 0x001 ///< The axis backbone and tick marks
1071 | ,spTickLabels = 0x002 ///< Tick labels (numbers) of this axis (as a whole, not individually)
1072 | ,spAxisLabel = 0x004 ///< The axis label
1073 | };
1074 | Q_FLAGS(SelectablePart SelectableParts)
1075 | Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
1076 |
1077 | explicit QCPAxis(QCPAxisRect *parent, AxisType type);
1078 | virtual ~QCPAxis();
1079 |
1080 | // getters:
1081 | AxisType axisType() const { return mAxisType; }
1082 | QCPAxisRect *axisRect() const { return mAxisRect; }
1083 | ScaleType scaleType() const { return mScaleType; }
1084 | double scaleLogBase() const { return mScaleLogBase; }
1085 | const QCPRange range() const { return mRange; }
1086 | bool rangeReversed() const { return mRangeReversed; }
1087 | bool autoTicks() const { return mAutoTicks; }
1088 | int autoTickCount() const { return mAutoTickCount; }
1089 | bool autoTickLabels() const { return mAutoTickLabels; }
1090 | bool autoTickStep() const { return mAutoTickStep; }
1091 | bool autoSubTicks() const { return mAutoSubTicks; }
1092 | bool ticks() const { return mTicks; }
1093 | bool tickLabels() const { return mTickLabels; }
1094 | int tickLabelPadding() const;
1095 | LabelType tickLabelType() const { return mTickLabelType; }
1096 | QFont tickLabelFont() const { return mTickLabelFont; }
1097 | QColor tickLabelColor() const { return mTickLabelColor; }
1098 | double tickLabelRotation() const;
1099 | QString dateTimeFormat() const { return mDateTimeFormat; }
1100 | Qt::TimeSpec dateTimeSpec() const { return mDateTimeSpec; }
1101 | QString numberFormat() const;
1102 | int numberPrecision() const { return mNumberPrecision; }
1103 | double tickStep() const { return mTickStep; }
1104 | QVector tickVector() const { return mTickVector; }
1105 | QVector tickVectorLabels() const { return mTickVectorLabels; }
1106 | int tickLengthIn() const;
1107 | int tickLengthOut() const;
1108 | int subTickCount() const { return mSubTickCount; }
1109 | int subTickLengthIn() const;
1110 | int subTickLengthOut() const;
1111 | QPen basePen() const { return mBasePen; }
1112 | QPen tickPen() const { return mTickPen; }
1113 | QPen subTickPen() const { return mSubTickPen; }
1114 | QFont labelFont() const { return mLabelFont; }
1115 | QColor labelColor() const { return mLabelColor; }
1116 | QString label() const { return mLabel; }
1117 | int labelPadding() const;
1118 | int padding() const { return mPadding; }
1119 | int offset() const;
1120 | SelectableParts selectedParts() const { return mSelectedParts; }
1121 | SelectableParts selectableParts() const { return mSelectableParts; }
1122 | QFont selectedTickLabelFont() const { return mSelectedTickLabelFont; }
1123 | QFont selectedLabelFont() const { return mSelectedLabelFont; }
1124 | QColor selectedTickLabelColor() const { return mSelectedTickLabelColor; }
1125 | QColor selectedLabelColor() const { return mSelectedLabelColor; }
1126 | QPen selectedBasePen() const { return mSelectedBasePen; }
1127 | QPen selectedTickPen() const { return mSelectedTickPen; }
1128 | QPen selectedSubTickPen() const { return mSelectedSubTickPen; }
1129 | QCPLineEnding lowerEnding() const;
1130 | QCPLineEnding upperEnding() const;
1131 | QCPGrid *grid() const { return mGrid; }
1132 |
1133 | // setters:
1134 | Q_SLOT void setScaleType(QCPAxis::ScaleType type);
1135 | void setScaleLogBase(double base);
1136 | Q_SLOT void setRange(const QCPRange &range);
1137 | void setRange(double lower, double upper);
1138 | void setRange(double position, double size, Qt::AlignmentFlag alignment);
1139 | void setRangeLower(double lower);
1140 | void setRangeUpper(double upper);
1141 | void setRangeReversed(bool reversed);
1142 | void setAutoTicks(bool on);
1143 | void setAutoTickCount(int approximateCount);
1144 | void setAutoTickLabels(bool on);
1145 | void setAutoTickStep(bool on);
1146 | void setAutoSubTicks(bool on);
1147 | void setTicks(bool show);
1148 | void setTickLabels(bool show);
1149 | void setTickLabelPadding(int padding);
1150 | void setTickLabelType(LabelType type);
1151 | void setTickLabelFont(const QFont &font);
1152 | void setTickLabelColor(const QColor &color);
1153 | void setTickLabelRotation(double degrees);
1154 | void setDateTimeFormat(const QString &format);
1155 | void setDateTimeSpec(const Qt::TimeSpec &timeSpec);
1156 | void setNumberFormat(const QString &formatCode);
1157 | void setNumberPrecision(int precision);
1158 | void setTickStep(double step);
1159 | void setTickVector(const QVector &vec);
1160 | void setTickVectorLabels(const QVector &vec);
1161 | void setTickLength(int inside, int outside=0);
1162 | void setTickLengthIn(int inside);
1163 | void setTickLengthOut(int outside);
1164 | void setSubTickCount(int count);
1165 | void setSubTickLength(int inside, int outside=0);
1166 | void setSubTickLengthIn(int inside);
1167 | void setSubTickLengthOut(int outside);
1168 | void setBasePen(const QPen &pen);
1169 | void setTickPen(const QPen &pen);
1170 | void setSubTickPen(const QPen &pen);
1171 | void setLabelFont(const QFont &font);
1172 | void setLabelColor(const QColor &color);
1173 | void setLabel(const QString &str);
1174 | void setLabelPadding(int padding);
1175 | void setPadding(int padding);
1176 | void setOffset(int offset);
1177 | void setSelectedTickLabelFont(const QFont &font);
1178 | void setSelectedLabelFont(const QFont &font);
1179 | void setSelectedTickLabelColor(const QColor &color);
1180 | void setSelectedLabelColor(const QColor &color);
1181 | void setSelectedBasePen(const QPen &pen);
1182 | void setSelectedTickPen(const QPen &pen);
1183 | void setSelectedSubTickPen(const QPen &pen);
1184 | Q_SLOT void setSelectableParts(const QCPAxis::SelectableParts &selectableParts);
1185 | Q_SLOT void setSelectedParts(const QCPAxis::SelectableParts &selectedParts);
1186 | void setLowerEnding(const QCPLineEnding &ending);
1187 | void setUpperEnding(const QCPLineEnding &ending);
1188 |
1189 | // reimplemented virtual methods:
1190 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
1191 |
1192 | // non-property methods:
1193 | Qt::Orientation orientation() const { return mOrientation; }
1194 | void moveRange(double diff);
1195 | void scaleRange(double factor, double center);
1196 | void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0);
1197 | void rescale(bool onlyVisiblePlottables=false);
1198 | double pixelToCoord(double value) const;
1199 | double coordToPixel(double value) const;
1200 | SelectablePart getPartAt(const QPointF &pos) const;
1201 | QList plottables() const;
1202 | QList graphs() const;
1203 | QList items() const;
1204 |
1205 | static AxisType marginSideToAxisType(QCP::MarginSide side);
1206 | static Qt::Orientation orientation(AxisType type) { return type==atBottom||type==atTop ? Qt::Horizontal : Qt::Vertical; }
1207 | static AxisType opposite(AxisType type);
1208 |
1209 | signals:
1210 | void ticksRequest();
1211 | void rangeChanged(const QCPRange &newRange);
1212 | void rangeChanged(const QCPRange &newRange, const QCPRange &oldRange);
1213 | void scaleTypeChanged(QCPAxis::ScaleType scaleType);
1214 | void selectionChanged(const QCPAxis::SelectableParts &parts);
1215 | void selectableChanged(const QCPAxis::SelectableParts &parts);
1216 |
1217 | protected:
1218 | // property members:
1219 | // axis base:
1220 | AxisType mAxisType;
1221 | QCPAxisRect *mAxisRect;
1222 | //int mOffset; // in QCPAxisPainter
1223 | int mPadding;
1224 | Qt::Orientation mOrientation;
1225 | SelectableParts mSelectableParts, mSelectedParts;
1226 | QPen mBasePen, mSelectedBasePen;
1227 | //QCPLineEnding mLowerEnding, mUpperEnding; // in QCPAxisPainter
1228 | // axis label:
1229 | //int mLabelPadding; // in QCPAxisPainter
1230 | QString mLabel;
1231 | QFont mLabelFont, mSelectedLabelFont;
1232 | QColor mLabelColor, mSelectedLabelColor;
1233 | // tick labels:
1234 | //int mTickLabelPadding; // in QCPAxisPainter
1235 | bool mTickLabels, mAutoTickLabels;
1236 | //double mTickLabelRotation; // in QCPAxisPainter
1237 | LabelType mTickLabelType;
1238 | QFont mTickLabelFont, mSelectedTickLabelFont;
1239 | QColor mTickLabelColor, mSelectedTickLabelColor;
1240 | QString mDateTimeFormat;
1241 | Qt::TimeSpec mDateTimeSpec;
1242 | int mNumberPrecision;
1243 | char mNumberFormatChar;
1244 | bool mNumberBeautifulPowers;
1245 | //bool mNumberMultiplyCross; // QCPAxisPainter
1246 | // ticks and subticks:
1247 | bool mTicks;
1248 | double mTickStep;
1249 | int mSubTickCount, mAutoTickCount;
1250 | bool mAutoTicks, mAutoTickStep, mAutoSubTicks;
1251 | //int mTickLengthIn, mTickLengthOut, mSubTickLengthIn, mSubTickLengthOut; // QCPAxisPainter
1252 | QPen mTickPen, mSelectedTickPen;
1253 | QPen mSubTickPen, mSelectedSubTickPen;
1254 | // scale and range:
1255 | QCPRange mRange;
1256 | bool mRangeReversed;
1257 | ScaleType mScaleType;
1258 | double mScaleLogBase, mScaleLogBaseLogInv;
1259 |
1260 | // non-property members:
1261 | QCPGrid *mGrid;
1262 | QCPAxisPainterPrivate *mAxisPainter;
1263 | int mLowestVisibleTick, mHighestVisibleTick;
1264 | QVector mTickVector;
1265 | QVector mTickVectorLabels;
1266 | QVector mSubTickVector;
1267 | bool mCachedMarginValid;
1268 | int mCachedMargin;
1269 |
1270 | // introduced virtual methods:
1271 | virtual void setupTickVectors();
1272 | virtual void generateAutoTicks();
1273 | virtual int calculateAutoSubTickCount(double tickStep) const;
1274 | virtual int calculateMargin();
1275 |
1276 | // reimplemented virtual methods:
1277 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1278 | virtual void draw(QCPPainter *painter);
1279 | virtual QCP::Interaction selectionCategory() const;
1280 | // events:
1281 | virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1282 | virtual void deselectEvent(bool *selectionStateChanged);
1283 |
1284 | // non-virtual methods:
1285 | void visibleTickBounds(int &lowIndex, int &highIndex) const;
1286 | double baseLog(double value) const;
1287 | double basePow(double value) const;
1288 | QPen getBasePen() const;
1289 | QPen getTickPen() const;
1290 | QPen getSubTickPen() const;
1291 | QFont getTickLabelFont() const;
1292 | QFont getLabelFont() const;
1293 | QColor getTickLabelColor() const;
1294 | QColor getLabelColor() const;
1295 |
1296 | private:
1297 | Q_DISABLE_COPY(QCPAxis)
1298 |
1299 | friend class QCustomPlot;
1300 | friend class QCPGrid;
1301 | friend class QCPAxisRect;
1302 | };
1303 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::SelectableParts)
1304 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCPAxis::AxisTypes)
1305 | Q_DECLARE_METATYPE(QCPAxis::SelectablePart)
1306 |
1307 |
1308 | class QCPAxisPainterPrivate
1309 | {
1310 | public:
1311 | explicit QCPAxisPainterPrivate(QCustomPlot *parentPlot);
1312 | virtual ~QCPAxisPainterPrivate();
1313 |
1314 | virtual void draw(QCPPainter *painter);
1315 | virtual int size() const;
1316 | void clearCache();
1317 |
1318 | QRect axisSelectionBox() const { return mAxisSelectionBox; }
1319 | QRect tickLabelsSelectionBox() const { return mTickLabelsSelectionBox; }
1320 | QRect labelSelectionBox() const { return mLabelSelectionBox; }
1321 |
1322 | // public property members:
1323 | QCPAxis::AxisType type;
1324 | QPen basePen;
1325 | QCPLineEnding lowerEnding, upperEnding; // directly accessed by QCPAxis setters/getters
1326 | int labelPadding; // directly accessed by QCPAxis setters/getters
1327 | QFont labelFont;
1328 | QColor labelColor;
1329 | QString label;
1330 | int tickLabelPadding; // directly accessed by QCPAxis setters/getters
1331 | double tickLabelRotation; // directly accessed by QCPAxis setters/getters
1332 | bool substituteExponent;
1333 | bool numberMultiplyCross; // directly accessed by QCPAxis setters/getters
1334 | int tickLengthIn, tickLengthOut, subTickLengthIn, subTickLengthOut; // directly accessed by QCPAxis setters/getters
1335 | QPen tickPen, subTickPen;
1336 | QFont tickLabelFont;
1337 | QColor tickLabelColor;
1338 | QRect alignmentRect, viewportRect;
1339 | double offset; // directly accessed by QCPAxis setters/getters
1340 | bool abbreviateDecimalPowers;
1341 | bool reversedEndings;
1342 |
1343 | QVector subTickPositions;
1344 | QVector tickPositions;
1345 | QVector tickLabels;
1346 |
1347 | protected:
1348 | struct CachedLabel
1349 | {
1350 | QPointF offset;
1351 | QPixmap pixmap;
1352 | };
1353 | struct TickLabelData
1354 | {
1355 | QString basePart, expPart;
1356 | QRect baseBounds, expBounds, totalBounds, rotatedTotalBounds;
1357 | QFont baseFont, expFont;
1358 | };
1359 | QCustomPlot *mParentPlot;
1360 | QByteArray mLabelParameterHash; // to determine whether mLabelCache needs to be cleared due to changed parameters
1361 | QCache mLabelCache;
1362 | QRect mAxisSelectionBox, mTickLabelsSelectionBox, mLabelSelectionBox;
1363 |
1364 | virtual QByteArray generateLabelParameterHash() const;
1365 |
1366 | virtual void placeTickLabel(QCPPainter *painter, double position, int distanceToAxis, const QString &text, QSize *tickLabelsSize);
1367 | virtual void drawTickLabel(QCPPainter *painter, double x, double y, const TickLabelData &labelData) const;
1368 | virtual TickLabelData getTickLabelData(const QFont &font, const QString &text) const;
1369 | virtual QPointF getTickLabelDrawOffset(const TickLabelData &labelData) const;
1370 | virtual void getMaxTickLabelSize(const QFont &font, const QString &text, QSize *tickLabelsSize) const;
1371 | };
1372 |
1373 |
1374 | class QCP_LIB_DECL QCPAbstractPlottable : public QCPLayerable
1375 | {
1376 | Q_OBJECT
1377 | /// \cond INCLUDE_QPROPERTIES
1378 | Q_PROPERTY(QString name READ name WRITE setName)
1379 | Q_PROPERTY(bool antialiasedFill READ antialiasedFill WRITE setAntialiasedFill)
1380 | Q_PROPERTY(bool antialiasedScatters READ antialiasedScatters WRITE setAntialiasedScatters)
1381 | Q_PROPERTY(bool antialiasedErrorBars READ antialiasedErrorBars WRITE setAntialiasedErrorBars)
1382 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
1383 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
1384 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
1385 | Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
1386 | Q_PROPERTY(QCPAxis* keyAxis READ keyAxis WRITE setKeyAxis)
1387 | Q_PROPERTY(QCPAxis* valueAxis READ valueAxis WRITE setValueAxis)
1388 | Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
1389 | Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
1390 | /// \endcond
1391 | public:
1392 | QCPAbstractPlottable(QCPAxis *keyAxis, QCPAxis *valueAxis);
1393 |
1394 | // getters:
1395 | QString name() const { return mName; }
1396 | bool antialiasedFill() const { return mAntialiasedFill; }
1397 | bool antialiasedScatters() const { return mAntialiasedScatters; }
1398 | bool antialiasedErrorBars() const { return mAntialiasedErrorBars; }
1399 | QPen pen() const { return mPen; }
1400 | QPen selectedPen() const { return mSelectedPen; }
1401 | QBrush brush() const { return mBrush; }
1402 | QBrush selectedBrush() const { return mSelectedBrush; }
1403 | QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1404 | QCPAxis *valueAxis() const { return mValueAxis.data(); }
1405 | bool selectable() const { return mSelectable; }
1406 | bool selected() const { return mSelected; }
1407 |
1408 | // setters:
1409 | void setName(const QString &name);
1410 | void setAntialiasedFill(bool enabled);
1411 | void setAntialiasedScatters(bool enabled);
1412 | void setAntialiasedErrorBars(bool enabled);
1413 | void setPen(const QPen &pen);
1414 | void setSelectedPen(const QPen &pen);
1415 | void setBrush(const QBrush &brush);
1416 | void setSelectedBrush(const QBrush &brush);
1417 | void setKeyAxis(QCPAxis *axis);
1418 | void setValueAxis(QCPAxis *axis);
1419 | Q_SLOT void setSelectable(bool selectable);
1420 | Q_SLOT void setSelected(bool selected);
1421 |
1422 | // introduced virtual methods:
1423 | virtual void clearData() = 0;
1424 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1425 | virtual bool addToLegend();
1426 | virtual bool removeFromLegend() const;
1427 |
1428 | // non-property methods:
1429 | void rescaleAxes(bool onlyEnlarge=false) const;
1430 | void rescaleKeyAxis(bool onlyEnlarge=false) const;
1431 | void rescaleValueAxis(bool onlyEnlarge=false) const;
1432 |
1433 | signals:
1434 | void selectionChanged(bool selected);
1435 | void selectableChanged(bool selectable);
1436 |
1437 | protected:
1438 | /*!
1439 | Represents negative and positive sign domain for passing to \ref getKeyRange and \ref getValueRange.
1440 | */
1441 | enum SignDomain { sdNegative ///< The negative sign domain, i.e. numbers smaller than zero
1442 | ,sdBoth ///< Both sign domains, including zero, i.e. all (rational) numbers
1443 | ,sdPositive ///< The positive sign domain, i.e. numbers greater than zero
1444 | };
1445 |
1446 | // property members:
1447 | QString mName;
1448 | bool mAntialiasedFill, mAntialiasedScatters, mAntialiasedErrorBars;
1449 | QPen mPen, mSelectedPen;
1450 | QBrush mBrush, mSelectedBrush;
1451 | QPointer mKeyAxis, mValueAxis;
1452 | bool mSelectable, mSelected;
1453 |
1454 | // reimplemented virtual methods:
1455 | virtual QRect clipRect() const;
1456 | virtual void draw(QCPPainter *painter) = 0;
1457 | virtual QCP::Interaction selectionCategory() const;
1458 | void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1459 | // events:
1460 | virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1461 | virtual void deselectEvent(bool *selectionStateChanged);
1462 |
1463 | // introduced virtual methods:
1464 | virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const = 0;
1465 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0;
1466 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const = 0;
1467 |
1468 | // non-virtual methods:
1469 | void coordsToPixels(double key, double value, double &x, double &y) const;
1470 | const QPointF coordsToPixels(double key, double value) const;
1471 | void pixelsToCoords(double x, double y, double &key, double &value) const;
1472 | void pixelsToCoords(const QPointF &pixelPos, double &key, double &value) const;
1473 | QPen mainPen() const;
1474 | QBrush mainBrush() const;
1475 | void applyFillAntialiasingHint(QCPPainter *painter) const;
1476 | void applyScattersAntialiasingHint(QCPPainter *painter) const;
1477 | void applyErrorBarsAntialiasingHint(QCPPainter *painter) const;
1478 | double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1479 |
1480 | private:
1481 | Q_DISABLE_COPY(QCPAbstractPlottable)
1482 |
1483 | friend class QCustomPlot;
1484 | friend class QCPAxis;
1485 | friend class QCPPlottableLegendItem;
1486 | };
1487 |
1488 |
1489 | class QCP_LIB_DECL QCPItemAnchor
1490 | {
1491 | public:
1492 | QCPItemAnchor(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name, int anchorId=-1);
1493 | virtual ~QCPItemAnchor();
1494 |
1495 | // getters:
1496 | QString name() const { return mName; }
1497 | virtual QPointF pixelPoint() const;
1498 |
1499 | protected:
1500 | // property members:
1501 | QString mName;
1502 |
1503 | // non-property members:
1504 | QCustomPlot *mParentPlot;
1505 | QCPAbstractItem *mParentItem;
1506 | int mAnchorId;
1507 | QSet mChildren;
1508 |
1509 | // introduced virtual methods:
1510 | virtual QCPItemPosition *toQCPItemPosition() { return 0; }
1511 |
1512 | // non-virtual methods:
1513 | void addChild(QCPItemPosition* pos); // called from pos when this anchor is set as parent
1514 | void removeChild(QCPItemPosition *pos); // called from pos when its parent anchor is reset or pos deleted
1515 |
1516 | private:
1517 | Q_DISABLE_COPY(QCPItemAnchor)
1518 |
1519 | friend class QCPItemPosition;
1520 | };
1521 |
1522 |
1523 |
1524 | class QCP_LIB_DECL QCPItemPosition : public QCPItemAnchor
1525 | {
1526 | public:
1527 | /*!
1528 | Defines the ways an item position can be specified. Thus it defines what the numbers passed to
1529 | \ref setCoords actually mean.
1530 |
1531 | \see setType
1532 | */
1533 | enum PositionType { ptAbsolute ///< Static positioning in pixels, starting from the top left corner of the viewport/widget.
1534 | ,ptViewportRatio ///< Static positioning given by a fraction of the viewport size. For example, if you call setCoords(0, 0), the position will be at the top
1535 | ///< left corner of the viewport/widget. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and
1536 | ///< vertically at the top of the viewport/widget, etc.
1537 | ,ptAxisRectRatio ///< Static positioning given by a fraction of the axis rect size (see \ref setAxisRect). For example, if you call setCoords(0, 0), the position will be at the top
1538 | ///< left corner of the axis rect. setCoords(1, 1) will be at the bottom right corner, setCoords(0.5, 0) will be horizontally centered and
1539 | ///< vertically at the top of the axis rect, etc. You can also go beyond the axis rect by providing negative coordinates or coordinates larger than 1.
1540 | ,ptPlotCoords ///< Dynamic positioning at a plot coordinate defined by two axes (see \ref setAxes).
1541 | };
1542 |
1543 | QCPItemPosition(QCustomPlot *parentPlot, QCPAbstractItem *parentItem, const QString name);
1544 | virtual ~QCPItemPosition();
1545 |
1546 | // getters:
1547 | PositionType type() const { return mPositionType; }
1548 | QCPItemAnchor *parentAnchor() const { return mParentAnchor; }
1549 | double key() const { return mKey; }
1550 | double value() const { return mValue; }
1551 | QPointF coords() const { return QPointF(mKey, mValue); }
1552 | QCPAxis *keyAxis() const { return mKeyAxis.data(); }
1553 | QCPAxis *valueAxis() const { return mValueAxis.data(); }
1554 | QCPAxisRect *axisRect() const;
1555 | virtual QPointF pixelPoint() const;
1556 |
1557 | // setters:
1558 | void setType(PositionType type);
1559 | bool setParentAnchor(QCPItemAnchor *parentAnchor, bool keepPixelPosition=false);
1560 | void setCoords(double key, double value);
1561 | void setCoords(const QPointF &coords);
1562 | void setAxes(QCPAxis* keyAxis, QCPAxis* valueAxis);
1563 | void setAxisRect(QCPAxisRect *axisRect);
1564 | void setPixelPoint(const QPointF &pixelPoint);
1565 |
1566 | protected:
1567 | // property members:
1568 | PositionType mPositionType;
1569 | QPointer mKeyAxis, mValueAxis;
1570 | QPointer mAxisRect;
1571 | double mKey, mValue;
1572 | QCPItemAnchor *mParentAnchor;
1573 |
1574 | // reimplemented virtual methods:
1575 | virtual QCPItemPosition *toQCPItemPosition() { return this; }
1576 |
1577 | private:
1578 | Q_DISABLE_COPY(QCPItemPosition)
1579 |
1580 | };
1581 |
1582 |
1583 | class QCP_LIB_DECL QCPAbstractItem : public QCPLayerable
1584 | {
1585 | Q_OBJECT
1586 | /// \cond INCLUDE_QPROPERTIES
1587 | Q_PROPERTY(bool clipToAxisRect READ clipToAxisRect WRITE setClipToAxisRect)
1588 | Q_PROPERTY(QCPAxisRect* clipAxisRect READ clipAxisRect WRITE setClipAxisRect)
1589 | Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
1590 | Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
1591 | /// \endcond
1592 | public:
1593 | QCPAbstractItem(QCustomPlot *parentPlot);
1594 | virtual ~QCPAbstractItem();
1595 |
1596 | // getters:
1597 | bool clipToAxisRect() const { return mClipToAxisRect; }
1598 | QCPAxisRect *clipAxisRect() const;
1599 | bool selectable() const { return mSelectable; }
1600 | bool selected() const { return mSelected; }
1601 |
1602 | // setters:
1603 | void setClipToAxisRect(bool clip);
1604 | void setClipAxisRect(QCPAxisRect *rect);
1605 | Q_SLOT void setSelectable(bool selectable);
1606 | Q_SLOT void setSelected(bool selected);
1607 |
1608 | // reimplemented virtual methods:
1609 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const = 0;
1610 |
1611 | // non-virtual methods:
1612 | QList positions() const { return mPositions; }
1613 | QList anchors() const { return mAnchors; }
1614 | QCPItemPosition *position(const QString &name) const;
1615 | QCPItemAnchor *anchor(const QString &name) const;
1616 | bool hasAnchor(const QString &name) const;
1617 |
1618 | signals:
1619 | void selectionChanged(bool selected);
1620 | void selectableChanged(bool selectable);
1621 |
1622 | protected:
1623 | // property members:
1624 | bool mClipToAxisRect;
1625 | QPointer mClipAxisRect;
1626 | QList mPositions;
1627 | QList mAnchors;
1628 | bool mSelectable, mSelected;
1629 |
1630 | // reimplemented virtual methods:
1631 | virtual QCP::Interaction selectionCategory() const;
1632 | virtual QRect clipRect() const;
1633 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
1634 | virtual void draw(QCPPainter *painter) = 0;
1635 | // events:
1636 | virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
1637 | virtual void deselectEvent(bool *selectionStateChanged);
1638 |
1639 | // introduced virtual methods:
1640 | virtual QPointF anchorPixelPoint(int anchorId) const;
1641 |
1642 | // non-virtual methods:
1643 | double distSqrToLine(const QPointF &start, const QPointF &end, const QPointF &point) const;
1644 | double rectSelectTest(const QRectF &rect, const QPointF &pos, bool filledRect) const;
1645 | QCPItemPosition *createPosition(const QString &name);
1646 | QCPItemAnchor *createAnchor(const QString &name, int anchorId);
1647 |
1648 | private:
1649 | Q_DISABLE_COPY(QCPAbstractItem)
1650 |
1651 | friend class QCustomPlot;
1652 | friend class QCPItemAnchor;
1653 | };
1654 |
1655 |
1656 | class QCP_LIB_DECL QCustomPlot : public QWidget
1657 | {
1658 | Q_OBJECT
1659 | /// \cond INCLUDE_QPROPERTIES
1660 | Q_PROPERTY(QRect viewport READ viewport WRITE setViewport)
1661 | Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1662 | Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1663 | Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1664 | Q_PROPERTY(QCPLayoutGrid* plotLayout READ plotLayout)
1665 | Q_PROPERTY(bool autoAddPlottableToLegend READ autoAddPlottableToLegend WRITE setAutoAddPlottableToLegend)
1666 | Q_PROPERTY(int selectionTolerance READ selectionTolerance WRITE setSelectionTolerance)
1667 | Q_PROPERTY(bool noAntialiasingOnDrag READ noAntialiasingOnDrag WRITE setNoAntialiasingOnDrag)
1668 | Q_PROPERTY(Qt::KeyboardModifier multiSelectModifier READ multiSelectModifier WRITE setMultiSelectModifier)
1669 | /// \endcond
1670 | public:
1671 | /*!
1672 | Defines how a layer should be inserted relative to an other layer.
1673 |
1674 | \see addLayer, moveLayer
1675 | */
1676 | enum LayerInsertMode { limBelow ///< Layer is inserted below other layer
1677 | ,limAbove ///< Layer is inserted above other layer
1678 | };
1679 | Q_ENUMS(LayerInsertMode)
1680 |
1681 | /*!
1682 | Defines with what timing the QCustomPlot surface is refreshed after a replot.
1683 |
1684 | \see replot
1685 | */
1686 | enum RefreshPriority { rpImmediate ///< The QCustomPlot surface is immediately refreshed, by calling QWidget::repaint() after the replot
1687 | ,rpQueued ///< Queues the refresh such that it is performed at a slightly delayed point in time after the replot, by calling QWidget::update() after the replot
1688 | ,rpHint ///< Whether to use immediate repaint or queued update depends on whether the plotting hint \ref QCP::phForceRepaint is set, see \ref setPlottingHints.
1689 | };
1690 |
1691 | explicit QCustomPlot(QWidget *parent = 0);
1692 | virtual ~QCustomPlot();
1693 |
1694 | // getters:
1695 | QRect viewport() const { return mViewport; }
1696 | QPixmap background() const { return mBackgroundPixmap; }
1697 | bool backgroundScaled() const { return mBackgroundScaled; }
1698 | Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1699 | QCPLayoutGrid *plotLayout() const { return mPlotLayout; }
1700 | QCP::AntialiasedElements antialiasedElements() const { return mAntialiasedElements; }
1701 | QCP::AntialiasedElements notAntialiasedElements() const { return mNotAntialiasedElements; }
1702 | bool autoAddPlottableToLegend() const { return mAutoAddPlottableToLegend; }
1703 | const QCP::Interactions interactions() const { return mInteractions; }
1704 | int selectionTolerance() const { return mSelectionTolerance; }
1705 | bool noAntialiasingOnDrag() const { return mNoAntialiasingOnDrag; }
1706 | QCP::PlottingHints plottingHints() const { return mPlottingHints; }
1707 | Qt::KeyboardModifier multiSelectModifier() const { return mMultiSelectModifier; }
1708 |
1709 | // setters:
1710 | void setViewport(const QRect &rect);
1711 | void setBackground(const QPixmap &pm);
1712 | void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
1713 | void setBackground(const QBrush &brush);
1714 | void setBackgroundScaled(bool scaled);
1715 | void setBackgroundScaledMode(Qt::AspectRatioMode mode);
1716 | void setAntialiasedElements(const QCP::AntialiasedElements &antialiasedElements);
1717 | void setAntialiasedElement(QCP::AntialiasedElement antialiasedElement, bool enabled=true);
1718 | void setNotAntialiasedElements(const QCP::AntialiasedElements ¬AntialiasedElements);
1719 | void setNotAntialiasedElement(QCP::AntialiasedElement notAntialiasedElement, bool enabled=true);
1720 | void setAutoAddPlottableToLegend(bool on);
1721 | void setInteractions(const QCP::Interactions &interactions);
1722 | void setInteraction(const QCP::Interaction &interaction, bool enabled=true);
1723 | void setSelectionTolerance(int pixels);
1724 | void setNoAntialiasingOnDrag(bool enabled);
1725 | void setPlottingHints(const QCP::PlottingHints &hints);
1726 | void setPlottingHint(QCP::PlottingHint hint, bool enabled=true);
1727 | void setMultiSelectModifier(Qt::KeyboardModifier modifier);
1728 |
1729 | // non-property methods:
1730 | // plottable interface:
1731 | QCPAbstractPlottable *plottable(int index);
1732 | QCPAbstractPlottable *plottable();
1733 | bool addPlottable(QCPAbstractPlottable *plottable);
1734 | bool removePlottable(QCPAbstractPlottable *plottable);
1735 | bool removePlottable(int index);
1736 | int clearPlottables();
1737 | int plottableCount() const;
1738 | QList selectedPlottables() const;
1739 | QCPAbstractPlottable *plottableAt(const QPointF &pos, bool onlySelectable=false) const;
1740 | bool hasPlottable(QCPAbstractPlottable *plottable) const;
1741 |
1742 | // specialized interface for QCPGraph:
1743 | QCPGraph *graph(int index) const;
1744 | QCPGraph *graph() const;
1745 | QCPGraph *addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0);
1746 | bool removeGraph(QCPGraph *graph);
1747 | bool removeGraph(int index);
1748 | int clearGraphs();
1749 | int graphCount() const;
1750 | QList selectedGraphs() const;
1751 |
1752 | // item interface:
1753 | QCPAbstractItem *item(int index) const;
1754 | QCPAbstractItem *item() const;
1755 | bool addItem(QCPAbstractItem* item);
1756 | bool removeItem(QCPAbstractItem *item);
1757 | bool removeItem(int index);
1758 | int clearItems();
1759 | int itemCount() const;
1760 | QList selectedItems() const;
1761 | QCPAbstractItem *itemAt(const QPointF &pos, bool onlySelectable=false) const;
1762 | bool hasItem(QCPAbstractItem *item) const;
1763 |
1764 | // layer interface:
1765 | QCPLayer *layer(const QString &name) const;
1766 | QCPLayer *layer(int index) const;
1767 | QCPLayer *currentLayer() const;
1768 | bool setCurrentLayer(const QString &name);
1769 | bool setCurrentLayer(QCPLayer *layer);
1770 | int layerCount() const;
1771 | bool addLayer(const QString &name, QCPLayer *otherLayer=0, LayerInsertMode insertMode=limAbove);
1772 | bool removeLayer(QCPLayer *layer);
1773 | bool moveLayer(QCPLayer *layer, QCPLayer *otherLayer, LayerInsertMode insertMode=limAbove);
1774 |
1775 | // axis rect/layout interface:
1776 | int axisRectCount() const;
1777 | QCPAxisRect* axisRect(int index=0) const;
1778 | QList axisRects() const;
1779 | QCPLayoutElement* layoutElementAt(const QPointF &pos) const;
1780 | Q_SLOT void rescaleAxes(bool onlyVisiblePlottables=false);
1781 |
1782 | QList selectedAxes() const;
1783 | QList selectedLegends() const;
1784 | Q_SLOT void deselectAll();
1785 |
1786 | bool savePdf(const QString &fileName, bool noCosmeticPen=false, int width=0, int height=0, const QString &pdfCreator="", const QString &pdfTitle="");
1787 | bool savePng(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1788 | bool saveJpg(const QString &fileName, int width=0, int height=0, double scale=1.0, int quality=-1);
1789 | bool saveBmp(const QString &fileName, int width=0, int height=0, double scale=1.0);
1790 | bool saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality=-1);
1791 | QPixmap toPixmap(int width=0, int height=0, double scale=1.0);
1792 | void toPainter(QCPPainter *painter, int width=0, int height=0);
1793 | Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpHint);
1794 |
1795 | QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;
1796 | QCPLegend *legend;
1797 |
1798 | signals:
1799 | void mouseDoubleClick(QMouseEvent *event);
1800 | void mousePress(QMouseEvent *event);
1801 | void mouseMove(QMouseEvent *event);
1802 | void mouseRelease(QMouseEvent *event);
1803 | void mouseWheel(QWheelEvent *event);
1804 |
1805 | void plottableClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1806 | void plottableDoubleClick(QCPAbstractPlottable *plottable, QMouseEvent *event);
1807 | void itemClick(QCPAbstractItem *item, QMouseEvent *event);
1808 | void itemDoubleClick(QCPAbstractItem *item, QMouseEvent *event);
1809 | void axisClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1810 | void axisDoubleClick(QCPAxis *axis, QCPAxis::SelectablePart part, QMouseEvent *event);
1811 | void legendClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1812 | void legendDoubleClick(QCPLegend *legend, QCPAbstractLegendItem *item, QMouseEvent *event);
1813 | void titleClick(QMouseEvent *event, QCPPlotTitle *title);
1814 | void titleDoubleClick(QMouseEvent *event, QCPPlotTitle *title);
1815 |
1816 | void selectionChangedByUser();
1817 | void beforeReplot();
1818 | void afterReplot();
1819 |
1820 | protected:
1821 | // property members:
1822 | QRect mViewport;
1823 | QCPLayoutGrid *mPlotLayout;
1824 | bool mAutoAddPlottableToLegend;
1825 | QList mPlottables;
1826 | QList mGraphs; // extra list of plottables also in mPlottables that are of type QCPGraph
1827 | QList mItems;
1828 | QList mLayers;
1829 | QCP::AntialiasedElements mAntialiasedElements, mNotAntialiasedElements;
1830 | QCP::Interactions mInteractions;
1831 | int mSelectionTolerance;
1832 | bool mNoAntialiasingOnDrag;
1833 | QBrush mBackgroundBrush;
1834 | QPixmap mBackgroundPixmap;
1835 | QPixmap mScaledBackgroundPixmap;
1836 | bool mBackgroundScaled;
1837 | Qt::AspectRatioMode mBackgroundScaledMode;
1838 | QCPLayer *mCurrentLayer;
1839 | QCP::PlottingHints mPlottingHints;
1840 | Qt::KeyboardModifier mMultiSelectModifier;
1841 |
1842 | // non-property members:
1843 | QPixmap mPaintBuffer;
1844 | QPoint mMousePressPos;
1845 | QPointer mMouseEventElement;
1846 | bool mReplotting;
1847 |
1848 | // reimplemented virtual methods:
1849 | virtual QSize minimumSizeHint() const;
1850 | virtual QSize sizeHint() const;
1851 | virtual void paintEvent(QPaintEvent *event);
1852 | virtual void resizeEvent(QResizeEvent *event);
1853 | virtual void mouseDoubleClickEvent(QMouseEvent *event);
1854 | virtual void mousePressEvent(QMouseEvent *event);
1855 | virtual void mouseMoveEvent(QMouseEvent *event);
1856 | virtual void mouseReleaseEvent(QMouseEvent *event);
1857 | virtual void wheelEvent(QWheelEvent *event);
1858 |
1859 | // introduced virtual methods:
1860 | virtual void draw(QCPPainter *painter);
1861 | virtual void axisRemoved(QCPAxis *axis);
1862 | virtual void legendRemoved(QCPLegend *legend);
1863 |
1864 | // non-virtual methods:
1865 | void updateLayerIndices() const;
1866 | QCPLayerable *layerableAt(const QPointF &pos, bool onlySelectable, QVariant *selectionDetails=0) const;
1867 | void drawBackground(QCPPainter *painter);
1868 |
1869 | friend class QCPLegend;
1870 | friend class QCPAxis;
1871 | friend class QCPLayer;
1872 | friend class QCPAxisRect;
1873 | };
1874 |
1875 |
1876 | class QCP_LIB_DECL QCPColorGradient
1877 | {
1878 | Q_GADGET
1879 | public:
1880 | /*!
1881 | Defines the color spaces in which color interpolation between gradient stops can be performed.
1882 |
1883 | \see setColorInterpolation
1884 | */
1885 | enum ColorInterpolation { ciRGB ///< Color channels red, green and blue are linearly interpolated
1886 | ,ciHSV ///< Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)
1887 | };
1888 | Q_ENUMS(ColorInterpolation)
1889 |
1890 | /*!
1891 | Defines the available presets that can be loaded with \ref loadPreset. See the documentation
1892 | there for an image of the presets.
1893 | */
1894 | enum GradientPreset { gpGrayscale ///< Continuous lightness from black to white (suited for non-biased data representation)
1895 | ,gpHot ///< Continuous lightness from black over firey colors to white (suited for non-biased data representation)
1896 | ,gpCold ///< Continuous lightness from black over icey colors to white (suited for non-biased data representation)
1897 | ,gpNight ///< Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)
1898 | ,gpCandy ///< Blue over pink to white
1899 | ,gpGeography ///< Colors suitable to represent different elevations on geographical maps
1900 | ,gpIon ///< Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)
1901 | ,gpThermal ///< Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white
1902 | ,gpPolar ///< Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values
1903 | ,gpSpectrum ///< An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)
1904 | ,gpJet ///< Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)
1905 | ,gpHues ///< Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see \ref setPeriodic)
1906 | };
1907 | Q_ENUMS(GradientPreset)
1908 |
1909 | QCPColorGradient(GradientPreset preset=gpCold);
1910 | bool operator==(const QCPColorGradient &other) const;
1911 | bool operator!=(const QCPColorGradient &other) const { return !(*this == other); }
1912 |
1913 | // getters:
1914 | int levelCount() const { return mLevelCount; }
1915 | QMap colorStops() const { return mColorStops; }
1916 | ColorInterpolation colorInterpolation() const { return mColorInterpolation; }
1917 | bool periodic() const { return mPeriodic; }
1918 |
1919 | // setters:
1920 | void setLevelCount(int n);
1921 | void setColorStops(const QMap &colorStops);
1922 | void setColorStopAt(double position, const QColor &color);
1923 | void setColorInterpolation(ColorInterpolation interpolation);
1924 | void setPeriodic(bool enabled);
1925 |
1926 | // non-property methods:
1927 | void colorize(const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false);
1928 | QRgb color(double position, const QCPRange &range, bool logarithmic=false);
1929 | void loadPreset(GradientPreset preset);
1930 | void clearColorStops();
1931 | QCPColorGradient inverted() const;
1932 |
1933 | protected:
1934 | void updateColorBuffer();
1935 |
1936 | // property members:
1937 | int mLevelCount;
1938 | QMap mColorStops;
1939 | ColorInterpolation mColorInterpolation;
1940 | bool mPeriodic;
1941 |
1942 | // non-property members:
1943 | QVector mColorBuffer;
1944 | bool mColorBufferInvalidated;
1945 | };
1946 |
1947 |
1948 | class QCP_LIB_DECL QCPAxisRect : public QCPLayoutElement
1949 | {
1950 | Q_OBJECT
1951 | /// \cond INCLUDE_QPROPERTIES
1952 | Q_PROPERTY(QPixmap background READ background WRITE setBackground)
1953 | Q_PROPERTY(bool backgroundScaled READ backgroundScaled WRITE setBackgroundScaled)
1954 | Q_PROPERTY(Qt::AspectRatioMode backgroundScaledMode READ backgroundScaledMode WRITE setBackgroundScaledMode)
1955 | Q_PROPERTY(Qt::Orientations rangeDrag READ rangeDrag WRITE setRangeDrag)
1956 | Q_PROPERTY(Qt::Orientations rangeZoom READ rangeZoom WRITE setRangeZoom)
1957 | /// \endcond
1958 | public:
1959 | explicit QCPAxisRect(QCustomPlot *parentPlot, bool setupDefaultAxes=true);
1960 | virtual ~QCPAxisRect();
1961 |
1962 | // getters:
1963 | QPixmap background() const { return mBackgroundPixmap; }
1964 | bool backgroundScaled() const { return mBackgroundScaled; }
1965 | Qt::AspectRatioMode backgroundScaledMode() const { return mBackgroundScaledMode; }
1966 | Qt::Orientations rangeDrag() const { return mRangeDrag; }
1967 | Qt::Orientations rangeZoom() const { return mRangeZoom; }
1968 | QCPAxis *rangeDragAxis(Qt::Orientation orientation);
1969 | QCPAxis *rangeZoomAxis(Qt::Orientation orientation);
1970 | double rangeZoomFactor(Qt::Orientation orientation);
1971 |
1972 | // setters:
1973 | void setBackground(const QPixmap &pm);
1974 | void setBackground(const QPixmap &pm, bool scaled, Qt::AspectRatioMode mode=Qt::KeepAspectRatioByExpanding);
1975 | void setBackground(const QBrush &brush);
1976 | void setBackgroundScaled(bool scaled);
1977 | void setBackgroundScaledMode(Qt::AspectRatioMode mode);
1978 | void setRangeDrag(Qt::Orientations orientations);
1979 | void setRangeZoom(Qt::Orientations orientations);
1980 | void setRangeDragAxes(QCPAxis *horizontal, QCPAxis *vertical);
1981 | void setRangeZoomAxes(QCPAxis *horizontal, QCPAxis *vertical);
1982 | void setRangeZoomFactor(double horizontalFactor, double verticalFactor);
1983 | void setRangeZoomFactor(double factor);
1984 |
1985 | // non-property methods:
1986 | int axisCount(QCPAxis::AxisType type) const;
1987 | QCPAxis *axis(QCPAxis::AxisType type, int index=0) const;
1988 | QList axes(QCPAxis::AxisTypes types) const;
1989 | QList axes() const;
1990 | QCPAxis *addAxis(QCPAxis::AxisType type);
1991 | QList addAxes(QCPAxis::AxisTypes types);
1992 | bool removeAxis(QCPAxis *axis);
1993 | QCPLayoutInset *insetLayout() const { return mInsetLayout; }
1994 |
1995 | void setupFullAxesBox(bool connectRanges=false);
1996 | QList plottables() const;
1997 | QList graphs() const;
1998 | QList items() const;
1999 |
2000 | // read-only interface imitating a QRect:
2001 | int left() const { return mRect.left(); }
2002 | int right() const { return mRect.right(); }
2003 | int top() const { return mRect.top(); }
2004 | int bottom() const { return mRect.bottom(); }
2005 | int width() const { return mRect.width(); }
2006 | int height() const { return mRect.height(); }
2007 | QSize size() const { return mRect.size(); }
2008 | QPoint topLeft() const { return mRect.topLeft(); }
2009 | QPoint topRight() const { return mRect.topRight(); }
2010 | QPoint bottomLeft() const { return mRect.bottomLeft(); }
2011 | QPoint bottomRight() const { return mRect.bottomRight(); }
2012 | QPoint center() const { return mRect.center(); }
2013 |
2014 | // reimplemented virtual methods:
2015 | virtual void update(UpdatePhase phase);
2016 | virtual QList elements(bool recursive) const;
2017 |
2018 | protected:
2019 | // property members:
2020 | QBrush mBackgroundBrush;
2021 | QPixmap mBackgroundPixmap;
2022 | QPixmap mScaledBackgroundPixmap;
2023 | bool mBackgroundScaled;
2024 | Qt::AspectRatioMode mBackgroundScaledMode;
2025 | QCPLayoutInset *mInsetLayout;
2026 | Qt::Orientations mRangeDrag, mRangeZoom;
2027 | QPointer mRangeDragHorzAxis, mRangeDragVertAxis, mRangeZoomHorzAxis, mRangeZoomVertAxis;
2028 | double mRangeZoomFactorHorz, mRangeZoomFactorVert;
2029 | // non-property members:
2030 | QCPRange mDragStartHorzRange, mDragStartVertRange;
2031 | QCP::AntialiasedElements mAADragBackup, mNotAADragBackup;
2032 | QPoint mDragStart;
2033 | bool mDragging;
2034 | QHash > mAxes;
2035 |
2036 | // reimplemented virtual methods:
2037 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2038 | virtual void draw(QCPPainter *painter);
2039 | virtual int calculateAutoMargin(QCP::MarginSide side);
2040 | // events:
2041 | virtual void mousePressEvent(QMouseEvent *event);
2042 | virtual void mouseMoveEvent(QMouseEvent *event);
2043 | virtual void mouseReleaseEvent(QMouseEvent *event);
2044 | virtual void wheelEvent(QWheelEvent *event);
2045 |
2046 | // non-property methods:
2047 | void drawBackground(QCPPainter *painter);
2048 | void updateAxesOffset(QCPAxis::AxisType type);
2049 |
2050 | private:
2051 | Q_DISABLE_COPY(QCPAxisRect)
2052 |
2053 | friend class QCustomPlot;
2054 | };
2055 |
2056 |
2057 | class QCP_LIB_DECL QCPAbstractLegendItem : public QCPLayoutElement
2058 | {
2059 | Q_OBJECT
2060 | /// \cond INCLUDE_QPROPERTIES
2061 | Q_PROPERTY(QCPLegend* parentLegend READ parentLegend)
2062 | Q_PROPERTY(QFont font READ font WRITE setFont)
2063 | Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2064 | Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2065 | Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2066 | Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectionChanged)
2067 | Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectableChanged)
2068 | /// \endcond
2069 | public:
2070 | explicit QCPAbstractLegendItem(QCPLegend *parent);
2071 |
2072 | // getters:
2073 | QCPLegend *parentLegend() const { return mParentLegend; }
2074 | QFont font() const { return mFont; }
2075 | QColor textColor() const { return mTextColor; }
2076 | QFont selectedFont() const { return mSelectedFont; }
2077 | QColor selectedTextColor() const { return mSelectedTextColor; }
2078 | bool selectable() const { return mSelectable; }
2079 | bool selected() const { return mSelected; }
2080 |
2081 | // setters:
2082 | void setFont(const QFont &font);
2083 | void setTextColor(const QColor &color);
2084 | void setSelectedFont(const QFont &font);
2085 | void setSelectedTextColor(const QColor &color);
2086 | Q_SLOT void setSelectable(bool selectable);
2087 | Q_SLOT void setSelected(bool selected);
2088 |
2089 | // reimplemented virtual methods:
2090 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2091 |
2092 | signals:
2093 | void selectionChanged(bool selected);
2094 | void selectableChanged(bool selectable);
2095 |
2096 | protected:
2097 | // property members:
2098 | QCPLegend *mParentLegend;
2099 | QFont mFont;
2100 | QColor mTextColor;
2101 | QFont mSelectedFont;
2102 | QColor mSelectedTextColor;
2103 | bool mSelectable, mSelected;
2104 |
2105 | // reimplemented virtual methods:
2106 | virtual QCP::Interaction selectionCategory() const;
2107 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2108 | virtual QRect clipRect() const;
2109 | virtual void draw(QCPPainter *painter) = 0;
2110 | // events:
2111 | virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2112 | virtual void deselectEvent(bool *selectionStateChanged);
2113 |
2114 | private:
2115 | Q_DISABLE_COPY(QCPAbstractLegendItem)
2116 |
2117 | friend class QCPLegend;
2118 | };
2119 |
2120 |
2121 | class QCP_LIB_DECL QCPPlottableLegendItem : public QCPAbstractLegendItem
2122 | {
2123 | Q_OBJECT
2124 | public:
2125 | QCPPlottableLegendItem(QCPLegend *parent, QCPAbstractPlottable *plottable);
2126 |
2127 | // getters:
2128 | QCPAbstractPlottable *plottable() { return mPlottable; }
2129 |
2130 | protected:
2131 | // property members:
2132 | QCPAbstractPlottable *mPlottable;
2133 |
2134 | // reimplemented virtual methods:
2135 | virtual void draw(QCPPainter *painter);
2136 | virtual QSize minimumSizeHint() const;
2137 |
2138 | // non-virtual methods:
2139 | QPen getIconBorderPen() const;
2140 | QColor getTextColor() const;
2141 | QFont getFont() const;
2142 | };
2143 |
2144 |
2145 | class QCP_LIB_DECL QCPLegend : public QCPLayoutGrid
2146 | {
2147 | Q_OBJECT
2148 | /// \cond INCLUDE_QPROPERTIES
2149 | Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen)
2150 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
2151 | Q_PROPERTY(QFont font READ font WRITE setFont)
2152 | Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2153 | Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
2154 | Q_PROPERTY(int iconTextPadding READ iconTextPadding WRITE setIconTextPadding)
2155 | Q_PROPERTY(QPen iconBorderPen READ iconBorderPen WRITE setIconBorderPen)
2156 | Q_PROPERTY(SelectableParts selectableParts READ selectableParts WRITE setSelectableParts NOTIFY selectionChanged)
2157 | Q_PROPERTY(SelectableParts selectedParts READ selectedParts WRITE setSelectedParts NOTIFY selectableChanged)
2158 | Q_PROPERTY(QPen selectedBorderPen READ selectedBorderPen WRITE setSelectedBorderPen)
2159 | Q_PROPERTY(QPen selectedIconBorderPen READ selectedIconBorderPen WRITE setSelectedIconBorderPen)
2160 | Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
2161 | Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2162 | Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2163 | /// \endcond
2164 | public:
2165 | /*!
2166 | Defines the selectable parts of a legend
2167 |
2168 | \see setSelectedParts, setSelectableParts
2169 | */
2170 | enum SelectablePart { spNone = 0x000 ///< 0x000 None
2171 | ,spLegendBox = 0x001 ///< 0x001 The legend box (frame)
2172 | ,spItems = 0x002 ///< 0x002 Legend items individually (see \ref selectedItems)
2173 | };
2174 | Q_FLAGS(SelectablePart SelectableParts)
2175 | Q_DECLARE_FLAGS(SelectableParts, SelectablePart)
2176 |
2177 | explicit QCPLegend();
2178 | virtual ~QCPLegend();
2179 |
2180 | // getters:
2181 | QPen borderPen() const { return mBorderPen; }
2182 | QBrush brush() const { return mBrush; }
2183 | QFont font() const { return mFont; }
2184 | QColor textColor() const { return mTextColor; }
2185 | QSize iconSize() const { return mIconSize; }
2186 | int iconTextPadding() const { return mIconTextPadding; }
2187 | QPen iconBorderPen() const { return mIconBorderPen; }
2188 | SelectableParts selectableParts() const { return mSelectableParts; }
2189 | SelectableParts selectedParts() const;
2190 | QPen selectedBorderPen() const { return mSelectedBorderPen; }
2191 | QPen selectedIconBorderPen() const { return mSelectedIconBorderPen; }
2192 | QBrush selectedBrush() const { return mSelectedBrush; }
2193 | QFont selectedFont() const { return mSelectedFont; }
2194 | QColor selectedTextColor() const { return mSelectedTextColor; }
2195 |
2196 | // setters:
2197 | void setBorderPen(const QPen &pen);
2198 | void setBrush(const QBrush &brush);
2199 | void setFont(const QFont &font);
2200 | void setTextColor(const QColor &color);
2201 | void setIconSize(const QSize &size);
2202 | void setIconSize(int width, int height);
2203 | void setIconTextPadding(int padding);
2204 | void setIconBorderPen(const QPen &pen);
2205 | Q_SLOT void setSelectableParts(const SelectableParts &selectableParts);
2206 | Q_SLOT void setSelectedParts(const SelectableParts &selectedParts);
2207 | void setSelectedBorderPen(const QPen &pen);
2208 | void setSelectedIconBorderPen(const QPen &pen);
2209 | void setSelectedBrush(const QBrush &brush);
2210 | void setSelectedFont(const QFont &font);
2211 | void setSelectedTextColor(const QColor &color);
2212 |
2213 | // reimplemented virtual methods:
2214 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2215 |
2216 | // non-virtual methods:
2217 | QCPAbstractLegendItem *item(int index) const;
2218 | QCPPlottableLegendItem *itemWithPlottable(const QCPAbstractPlottable *plottable) const;
2219 | int itemCount() const;
2220 | bool hasItem(QCPAbstractLegendItem *item) const;
2221 | bool hasItemWithPlottable(const QCPAbstractPlottable *plottable) const;
2222 | bool addItem(QCPAbstractLegendItem *item);
2223 | bool removeItem(int index);
2224 | bool removeItem(QCPAbstractLegendItem *item);
2225 | void clearItems();
2226 | QList selectedItems() const;
2227 |
2228 | signals:
2229 | void selectionChanged(QCPLegend::SelectableParts parts);
2230 | void selectableChanged(QCPLegend::SelectableParts parts);
2231 |
2232 | protected:
2233 | // property members:
2234 | QPen mBorderPen, mIconBorderPen;
2235 | QBrush mBrush;
2236 | QFont mFont;
2237 | QColor mTextColor;
2238 | QSize mIconSize;
2239 | int mIconTextPadding;
2240 | SelectableParts mSelectedParts, mSelectableParts;
2241 | QPen mSelectedBorderPen, mSelectedIconBorderPen;
2242 | QBrush mSelectedBrush;
2243 | QFont mSelectedFont;
2244 | QColor mSelectedTextColor;
2245 |
2246 | // reimplemented virtual methods:
2247 | virtual void parentPlotInitialized(QCustomPlot *parentPlot);
2248 | virtual QCP::Interaction selectionCategory() const;
2249 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2250 | virtual void draw(QCPPainter *painter);
2251 | // events:
2252 | virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2253 | virtual void deselectEvent(bool *selectionStateChanged);
2254 |
2255 | // non-virtual methods:
2256 | QPen getBorderPen() const;
2257 | QBrush getBrush() const;
2258 |
2259 | private:
2260 | Q_DISABLE_COPY(QCPLegend)
2261 |
2262 | friend class QCustomPlot;
2263 | friend class QCPAbstractLegendItem;
2264 | };
2265 | Q_DECLARE_OPERATORS_FOR_FLAGS(QCPLegend::SelectableParts)
2266 | Q_DECLARE_METATYPE(QCPLegend::SelectablePart)
2267 |
2268 |
2269 | class QCP_LIB_DECL QCPPlotTitle : public QCPLayoutElement
2270 | {
2271 | Q_OBJECT
2272 | /// \cond INCLUDE_QPROPERTIES
2273 | Q_PROPERTY(QString text READ text WRITE setText)
2274 | Q_PROPERTY(QFont font READ font WRITE setFont)
2275 | Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
2276 | Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
2277 | Q_PROPERTY(QColor selectedTextColor READ selectedTextColor WRITE setSelectedTextColor)
2278 | Q_PROPERTY(bool selectable READ selectable WRITE setSelectable NOTIFY selectableChanged)
2279 | Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectionChanged)
2280 | /// \endcond
2281 | public:
2282 | explicit QCPPlotTitle(QCustomPlot *parentPlot);
2283 | explicit QCPPlotTitle(QCustomPlot *parentPlot, const QString &text);
2284 |
2285 | // getters:
2286 | QString text() const { return mText; }
2287 | QFont font() const { return mFont; }
2288 | QColor textColor() const { return mTextColor; }
2289 | QFont selectedFont() const { return mSelectedFont; }
2290 | QColor selectedTextColor() const { return mSelectedTextColor; }
2291 | bool selectable() const { return mSelectable; }
2292 | bool selected() const { return mSelected; }
2293 |
2294 | // setters:
2295 | void setText(const QString &text);
2296 | void setFont(const QFont &font);
2297 | void setTextColor(const QColor &color);
2298 | void setSelectedFont(const QFont &font);
2299 | void setSelectedTextColor(const QColor &color);
2300 | Q_SLOT void setSelectable(bool selectable);
2301 | Q_SLOT void setSelected(bool selected);
2302 |
2303 | // reimplemented virtual methods:
2304 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2305 |
2306 | signals:
2307 | void selectionChanged(bool selected);
2308 | void selectableChanged(bool selectable);
2309 |
2310 | protected:
2311 | // property members:
2312 | QString mText;
2313 | QFont mFont;
2314 | QColor mTextColor;
2315 | QFont mSelectedFont;
2316 | QColor mSelectedTextColor;
2317 | QRect mTextBoundingRect;
2318 | bool mSelectable, mSelected;
2319 |
2320 | // reimplemented virtual methods:
2321 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2322 | virtual void draw(QCPPainter *painter);
2323 | virtual QSize minimumSizeHint() const;
2324 | virtual QSize maximumSizeHint() const;
2325 | // events:
2326 | virtual void selectEvent(QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged);
2327 | virtual void deselectEvent(bool *selectionStateChanged);
2328 |
2329 | // non-virtual methods:
2330 | QFont mainFont() const;
2331 | QColor mainTextColor() const;
2332 |
2333 | private:
2334 | Q_DISABLE_COPY(QCPPlotTitle)
2335 | };
2336 |
2337 |
2338 | class QCPColorScaleAxisRectPrivate : public QCPAxisRect
2339 | {
2340 | Q_OBJECT
2341 | public:
2342 | explicit QCPColorScaleAxisRectPrivate(QCPColorScale *parentColorScale);
2343 | protected:
2344 | QCPColorScale *mParentColorScale;
2345 | QImage mGradientImage;
2346 | bool mGradientImageInvalidated;
2347 | // re-using some methods of QCPAxisRect to make them available to friend class QCPColorScale
2348 | using QCPAxisRect::calculateAutoMargin;
2349 | using QCPAxisRect::mousePressEvent;
2350 | using QCPAxisRect::mouseMoveEvent;
2351 | using QCPAxisRect::mouseReleaseEvent;
2352 | using QCPAxisRect::wheelEvent;
2353 | using QCPAxisRect::update;
2354 | virtual void draw(QCPPainter *painter);
2355 | void updateGradientImage();
2356 | Q_SLOT void axisSelectionChanged(QCPAxis::SelectableParts selectedParts);
2357 | Q_SLOT void axisSelectableChanged(QCPAxis::SelectableParts selectableParts);
2358 | friend class QCPColorScale;
2359 | };
2360 |
2361 |
2362 | class QCP_LIB_DECL QCPColorScale : public QCPLayoutElement
2363 | {
2364 | Q_OBJECT
2365 | /// \cond INCLUDE_QPROPERTIES
2366 | Q_PROPERTY(QCPAxis::AxisType type READ type WRITE setType)
2367 | Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
2368 | Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
2369 | Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
2370 | Q_PROPERTY(QString label READ label WRITE setLabel)
2371 | Q_PROPERTY(int barWidth READ barWidth WRITE setBarWidth)
2372 | Q_PROPERTY(bool rangeDrag READ rangeDrag WRITE setRangeDrag)
2373 | Q_PROPERTY(bool rangeZoom READ rangeZoom WRITE setRangeZoom)
2374 | /// \endcond
2375 | public:
2376 | explicit QCPColorScale(QCustomPlot *parentPlot);
2377 | virtual ~QCPColorScale();
2378 |
2379 | // getters:
2380 | QCPAxis *axis() const { return mColorAxis.data(); }
2381 | QCPAxis::AxisType type() const { return mType; }
2382 | QCPRange dataRange() const { return mDataRange; }
2383 | QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
2384 | QCPColorGradient gradient() const { return mGradient; }
2385 | QString label() const;
2386 | int barWidth () const { return mBarWidth; }
2387 | bool rangeDrag() const;
2388 | bool rangeZoom() const;
2389 |
2390 | // setters:
2391 | void setType(QCPAxis::AxisType type);
2392 | Q_SLOT void setDataRange(const QCPRange &dataRange);
2393 | Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
2394 | Q_SLOT void setGradient(const QCPColorGradient &gradient);
2395 | void setLabel(const QString &str);
2396 | void setBarWidth(int width);
2397 | void setRangeDrag(bool enabled);
2398 | void setRangeZoom(bool enabled);
2399 |
2400 | // non-property methods:
2401 | QList colorMaps() const;
2402 | void rescaleDataRange(bool onlyVisibleMaps);
2403 |
2404 | // reimplemented virtual methods:
2405 | virtual void update(UpdatePhase phase);
2406 |
2407 | signals:
2408 | void dataRangeChanged(QCPRange newRange);
2409 | void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
2410 | void gradientChanged(QCPColorGradient newGradient);
2411 |
2412 | protected:
2413 | // property members:
2414 | QCPAxis::AxisType mType;
2415 | QCPRange mDataRange;
2416 | QCPAxis::ScaleType mDataScaleType;
2417 | QCPColorGradient mGradient;
2418 | int mBarWidth;
2419 |
2420 | // non-property members:
2421 | QPointer mAxisRect;
2422 | QPointer mColorAxis;
2423 |
2424 | // reimplemented virtual methods:
2425 | virtual void applyDefaultAntialiasingHint(QCPPainter *painter) const;
2426 | // events:
2427 | virtual void mousePressEvent(QMouseEvent *event);
2428 | virtual void mouseMoveEvent(QMouseEvent *event);
2429 | virtual void mouseReleaseEvent(QMouseEvent *event);
2430 | virtual void wheelEvent(QWheelEvent *event);
2431 |
2432 | private:
2433 | Q_DISABLE_COPY(QCPColorScale)
2434 |
2435 | friend class QCPColorScaleAxisRectPrivate;
2436 | };
2437 |
2438 |
2439 | /*! \file */
2440 |
2441 |
2442 |
2443 | class QCP_LIB_DECL QCPData
2444 | {
2445 | public:
2446 | QCPData();
2447 | QCPData(double key, double value);
2448 | double key, value;
2449 | double keyErrorPlus, keyErrorMinus;
2450 | double valueErrorPlus, valueErrorMinus;
2451 | };
2452 | Q_DECLARE_TYPEINFO(QCPData, Q_MOVABLE_TYPE);
2453 |
2454 | /*! \typedef QCPDataMap
2455 | Container for storing QCPData items in a sorted fashion. The key of the map
2456 | is the key member of the QCPData instance.
2457 |
2458 | This is the container in which QCPGraph holds its data.
2459 | \see QCPData, QCPGraph::setData
2460 | */
2461 | typedef QMap QCPDataMap;
2462 | typedef QMapIterator QCPDataMapIterator;
2463 | typedef QMutableMapIterator QCPDataMutableMapIterator;
2464 |
2465 |
2466 | class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable
2467 | {
2468 | Q_OBJECT
2469 | /// \cond INCLUDE_QPROPERTIES
2470 | Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
2471 | Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
2472 | Q_PROPERTY(ErrorType errorType READ errorType WRITE setErrorType)
2473 | Q_PROPERTY(QPen errorPen READ errorPen WRITE setErrorPen)
2474 | Q_PROPERTY(double errorBarSize READ errorBarSize WRITE setErrorBarSize)
2475 | Q_PROPERTY(bool errorBarSkipSymbol READ errorBarSkipSymbol WRITE setErrorBarSkipSymbol)
2476 | Q_PROPERTY(QCPGraph* channelFillGraph READ channelFillGraph WRITE setChannelFillGraph)
2477 | Q_PROPERTY(bool adaptiveSampling READ adaptiveSampling WRITE setAdaptiveSampling)
2478 | /// \endcond
2479 | public:
2480 | /*!
2481 | Defines how the graph's line is represented visually in the plot. The line is drawn with the
2482 | current pen of the graph (\ref setPen).
2483 | \see setLineStyle
2484 | */
2485 | enum LineStyle { lsNone ///< data points are not connected with any lines (e.g. data only represented
2486 | ///< with symbols according to the scatter style, see \ref setScatterStyle)
2487 | ,lsLine ///< data points are connected by a straight line
2488 | ,lsStepLeft ///< line is drawn as steps where the step height is the value of the left data point
2489 | ,lsStepRight ///< line is drawn as steps where the step height is the value of the right data point
2490 | ,lsStepCenter ///< line is drawn as steps where the step is in between two data points
2491 | ,lsImpulse ///< each data point is represented by a line parallel to the value axis, which reaches from the data point to the zero-value-line
2492 | };
2493 | Q_ENUMS(LineStyle)
2494 | /*!
2495 | Defines what kind of error bars are drawn for each data point
2496 | */
2497 | enum ErrorType { etNone ///< No error bars are shown
2498 | ,etKey ///< Error bars for the key dimension of the data point are shown
2499 | ,etValue ///< Error bars for the value dimension of the data point are shown
2500 | ,etBoth ///< Error bars for both key and value dimensions of the data point are shown
2501 | };
2502 | Q_ENUMS(ErrorType)
2503 |
2504 | explicit QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis);
2505 | virtual ~QCPGraph();
2506 |
2507 | // getters:
2508 | QCPDataMap *data() const { return mData; }
2509 | LineStyle lineStyle() const { return mLineStyle; }
2510 | QCPScatterStyle scatterStyle() const { return mScatterStyle; }
2511 | ErrorType errorType() const { return mErrorType; }
2512 | QPen errorPen() const { return mErrorPen; }
2513 | double errorBarSize() const { return mErrorBarSize; }
2514 | bool errorBarSkipSymbol() const { return mErrorBarSkipSymbol; }
2515 | QCPGraph *channelFillGraph() const { return mChannelFillGraph.data(); }
2516 | bool adaptiveSampling() const { return mAdaptiveSampling; }
2517 |
2518 | // setters:
2519 | void setData(QCPDataMap *data, bool copy=false);
2520 | void setData(const QVector &key, const QVector &value);
2521 | void setDataKeyError(const QVector &key, const QVector &value, const QVector &keyError);
2522 | void setDataKeyError(const QVector &key, const QVector &value, const QVector &keyErrorMinus, const QVector &keyErrorPlus);
2523 | void setDataValueError(const QVector &key, const QVector &value, const QVector &valueError);
2524 | void setDataValueError(const QVector &key, const QVector &value, const QVector &valueErrorMinus, const QVector &valueErrorPlus);
2525 | void setDataBothError(const QVector &key, const QVector &value, const QVector &keyError, const QVector &valueError);
2526 | void setDataBothError(const QVector &key, const QVector &value, const QVector &keyErrorMinus, const QVector &keyErrorPlus, const QVector &valueErrorMinus, const QVector &valueErrorPlus);
2527 | void setLineStyle(LineStyle ls);
2528 | void setScatterStyle(const QCPScatterStyle &style);
2529 | void setErrorType(ErrorType errorType);
2530 | void setErrorPen(const QPen &pen);
2531 | void setErrorBarSize(double size);
2532 | void setErrorBarSkipSymbol(bool enabled);
2533 | void setChannelFillGraph(QCPGraph *targetGraph);
2534 | void setAdaptiveSampling(bool enabled);
2535 |
2536 | // non-property methods:
2537 | void addData(const QCPDataMap &dataMap);
2538 | void addData(const QCPData &data);
2539 | void addData(double key, double value);
2540 | void addData(const QVector &keys, const QVector &values);
2541 | void removeDataBefore(double key);
2542 | void removeDataAfter(double key);
2543 | void removeData(double fromKey, double toKey);
2544 | void removeData(double key);
2545 |
2546 | // reimplemented virtual methods:
2547 | virtual void clearData();
2548 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2549 | using QCPAbstractPlottable::rescaleAxes;
2550 | using QCPAbstractPlottable::rescaleKeyAxis;
2551 | using QCPAbstractPlottable::rescaleValueAxis;
2552 | void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2553 | void rescaleKeyAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2554 | void rescaleValueAxis(bool onlyEnlarge, bool includeErrorBars) const; // overloads base class interface
2555 |
2556 | protected:
2557 | // property members:
2558 | QCPDataMap *mData;
2559 | QPen mErrorPen;
2560 | LineStyle mLineStyle;
2561 | QCPScatterStyle mScatterStyle;
2562 | ErrorType mErrorType;
2563 | double mErrorBarSize;
2564 | bool mErrorBarSkipSymbol;
2565 | QPointer mChannelFillGraph;
2566 | bool mAdaptiveSampling;
2567 |
2568 | // reimplemented virtual methods:
2569 | virtual void draw(QCPPainter *painter);
2570 | virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2571 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2572 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2573 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
2574 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain, bool includeErrors) const; // overloads base class interface
2575 |
2576 | // introduced virtual methods:
2577 | virtual void drawFill(QCPPainter *painter, QVector *lineData) const;
2578 | virtual void drawScatterPlot(QCPPainter *painter, QVector *scatterData) const;
2579 | virtual void drawLinePlot(QCPPainter *painter, QVector *lineData) const;
2580 | virtual void drawImpulsePlot(QCPPainter *painter, QVector *lineData) const;
2581 |
2582 | // non-virtual methods:
2583 | void getPreparedData(QVector *lineData, QVector *scatterData) const;
2584 | void getPlotData(QVector *lineData, QVector *scatterData) const;
2585 | void getScatterPlotData(QVector *scatterData) const;
2586 | void getLinePlotData(QVector *linePixelData, QVector *scatterData) const;
2587 | void getStepLeftPlotData(QVector *linePixelData, QVector *scatterData) const;
2588 | void getStepRightPlotData(QVector *linePixelData, QVector *scatterData) const;
2589 | void getStepCenterPlotData(QVector *linePixelData, QVector *scatterData) const;
2590 | void getImpulsePlotData(QVector *linePixelData, QVector *scatterData) const;
2591 | void drawError(QCPPainter *painter, double x, double y, const QCPData &data) const;
2592 | void getVisibleDataBounds(QCPDataMap::const_iterator &lower, QCPDataMap::const_iterator &upper) const;
2593 | int countDataInBounds(const QCPDataMap::const_iterator &lower, const QCPDataMap::const_iterator &upper, int maxCount) const;
2594 | void addFillBasePoints(QVector *lineData) const;
2595 | void removeFillBasePoints(QVector *lineData) const;
2596 | QPointF lowerFillBasePoint(double lowerKey) const;
2597 | QPointF upperFillBasePoint(double upperKey) const;
2598 | const QPolygonF getChannelFillPolygon(const QVector *lineData) const;
2599 | int findIndexBelowX(const QVector *data, double x) const;
2600 | int findIndexAboveX(const QVector *data, double x) const;
2601 | int findIndexBelowY(const QVector *data, double y) const;
2602 | int findIndexAboveY(const QVector *data, double y) const;
2603 | double pointDistance(const QPointF &pixelPoint) const;
2604 |
2605 | friend class QCustomPlot;
2606 | friend class QCPLegend;
2607 | };
2608 |
2609 |
2610 | /*! \file */
2611 |
2612 |
2613 |
2614 | class QCP_LIB_DECL QCPCurveData
2615 | {
2616 | public:
2617 | QCPCurveData();
2618 | QCPCurveData(double t, double key, double value);
2619 | double t, key, value;
2620 | };
2621 | Q_DECLARE_TYPEINFO(QCPCurveData, Q_MOVABLE_TYPE);
2622 |
2623 | /*! \typedef QCPCurveDataMap
2624 | Container for storing QCPCurveData items in a sorted fashion. The key of the map
2625 | is the t member of the QCPCurveData instance.
2626 |
2627 | This is the container in which QCPCurve holds its data.
2628 | \see QCPCurveData, QCPCurve::setData
2629 | */
2630 |
2631 | typedef QMap QCPCurveDataMap;
2632 | typedef QMapIterator QCPCurveDataMapIterator;
2633 | typedef QMutableMapIterator QCPCurveDataMutableMapIterator;
2634 |
2635 |
2636 | class QCP_LIB_DECL QCPCurve : public QCPAbstractPlottable
2637 | {
2638 | Q_OBJECT
2639 | /// \cond INCLUDE_QPROPERTIES
2640 | Q_PROPERTY(QCPScatterStyle scatterStyle READ scatterStyle WRITE setScatterStyle)
2641 | Q_PROPERTY(LineStyle lineStyle READ lineStyle WRITE setLineStyle)
2642 | /// \endcond
2643 | public:
2644 | /*!
2645 | Defines how the curve's line is represented visually in the plot. The line is drawn with the
2646 | current pen of the curve (\ref setPen).
2647 | \see setLineStyle
2648 | */
2649 | enum LineStyle { lsNone ///< No line is drawn between data points (e.g. only scatters)
2650 | ,lsLine ///< Data points are connected with a straight line
2651 | };
2652 | explicit QCPCurve(QCPAxis *keyAxis, QCPAxis *valueAxis);
2653 | virtual ~QCPCurve();
2654 |
2655 | // getters:
2656 | QCPCurveDataMap *data() const { return mData; }
2657 | QCPScatterStyle scatterStyle() const { return mScatterStyle; }
2658 | LineStyle lineStyle() const { return mLineStyle; }
2659 |
2660 | // setters:
2661 | void setData(QCPCurveDataMap *data, bool copy=false);
2662 | void setData(const QVector &t, const QVector &key, const QVector &value);
2663 | void setData(const QVector &key, const QVector &value);
2664 | void setScatterStyle(const QCPScatterStyle &style);
2665 | void setLineStyle(LineStyle style);
2666 |
2667 | // non-property methods:
2668 | void addData(const QCPCurveDataMap &dataMap);
2669 | void addData(const QCPCurveData &data);
2670 | void addData(double t, double key, double value);
2671 | void addData(double key, double value);
2672 | void addData(const QVector &ts, const QVector &keys, const QVector &values);
2673 | void removeDataBefore(double t);
2674 | void removeDataAfter(double t);
2675 | void removeData(double fromt, double tot);
2676 | void removeData(double t);
2677 |
2678 | // reimplemented virtual methods:
2679 | virtual void clearData();
2680 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2681 |
2682 | protected:
2683 | // property members:
2684 | QCPCurveDataMap *mData;
2685 | QCPScatterStyle mScatterStyle;
2686 | LineStyle mLineStyle;
2687 |
2688 | // reimplemented virtual methods:
2689 | virtual void draw(QCPPainter *painter);
2690 | virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2691 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2692 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2693 |
2694 | // introduced virtual methods:
2695 | virtual void drawScatterPlot(QCPPainter *painter, const QVector *pointData) const;
2696 |
2697 | // non-virtual methods:
2698 | void getCurveData(QVector *lineData) const;
2699 | double pointDistance(const QPointF &pixelPoint) const;
2700 | QPointF outsideCoordsToPixels(double key, double value, int region, QRect axisRect) const;
2701 |
2702 | friend class QCustomPlot;
2703 | friend class QCPLegend;
2704 | };
2705 |
2706 |
2707 | /*! \file */
2708 |
2709 |
2710 |
2711 | class QCP_LIB_DECL QCPBarData
2712 | {
2713 | public:
2714 | QCPBarData();
2715 | QCPBarData(double key, double value);
2716 | double key, value;
2717 | };
2718 | Q_DECLARE_TYPEINFO(QCPBarData, Q_MOVABLE_TYPE);
2719 |
2720 | /*! \typedef QCPBarDataMap
2721 | Container for storing QCPBarData items in a sorted fashion. The key of the map
2722 | is the key member of the QCPBarData instance.
2723 |
2724 | This is the container in which QCPBars holds its data.
2725 | \see QCPBarData, QCPBars::setData
2726 | */
2727 | typedef QMap QCPBarDataMap;
2728 | typedef QMapIterator QCPBarDataMapIterator;
2729 | typedef QMutableMapIterator QCPBarDataMutableMapIterator;
2730 |
2731 |
2732 | class QCP_LIB_DECL QCPBars : public QCPAbstractPlottable
2733 | {
2734 | Q_OBJECT
2735 | /// \cond INCLUDE_QPROPERTIES
2736 | Q_PROPERTY(double width READ width WRITE setWidth)
2737 | Q_PROPERTY(QCPBars* barBelow READ barBelow)
2738 | Q_PROPERTY(QCPBars* barAbove READ barAbove)
2739 | /// \endcond
2740 | public:
2741 | explicit QCPBars(QCPAxis *keyAxis, QCPAxis *valueAxis);
2742 | virtual ~QCPBars();
2743 |
2744 | // getters:
2745 | double width() const { return mWidth; }
2746 | QCPBars *barBelow() const { return mBarBelow.data(); }
2747 | QCPBars *barAbove() const { return mBarAbove.data(); }
2748 | QCPBarDataMap *data() const { return mData; }
2749 |
2750 | // setters:
2751 | void setWidth(double width);
2752 | void setData(QCPBarDataMap *data, bool copy=false);
2753 | void setData(const QVector &key, const QVector &value);
2754 |
2755 | // non-property methods:
2756 | void moveBelow(QCPBars *bars);
2757 | void moveAbove(QCPBars *bars);
2758 | void addData(const QCPBarDataMap &dataMap);
2759 | void addData(const QCPBarData &data);
2760 | void addData(double key, double value);
2761 | void addData(const QVector &keys, const QVector &values);
2762 | void removeDataBefore(double key);
2763 | void removeDataAfter(double key);
2764 | void removeData(double fromKey, double toKey);
2765 | void removeData(double key);
2766 |
2767 | // reimplemented virtual methods:
2768 | virtual void clearData();
2769 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2770 |
2771 | protected:
2772 | // property members:
2773 | QCPBarDataMap *mData;
2774 | double mWidth;
2775 | QPointer mBarBelow, mBarAbove;
2776 |
2777 | // reimplemented virtual methods:
2778 | virtual void draw(QCPPainter *painter);
2779 | virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2780 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2781 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2782 |
2783 | // non-virtual methods:
2784 | QPolygonF getBarPolygon(double key, double value) const;
2785 | double getBaseValue(double key, bool positive) const;
2786 | static void connectBars(QCPBars* lower, QCPBars* upper);
2787 |
2788 | friend class QCustomPlot;
2789 | friend class QCPLegend;
2790 | };
2791 |
2792 |
2793 | /*! \file */
2794 |
2795 |
2796 |
2797 | class QCP_LIB_DECL QCPStatisticalBox : public QCPAbstractPlottable
2798 | {
2799 | Q_OBJECT
2800 | /// \cond INCLUDE_QPROPERTIES
2801 | Q_PROPERTY(double key READ key WRITE setKey)
2802 | Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
2803 | Q_PROPERTY(double lowerQuartile READ lowerQuartile WRITE setLowerQuartile)
2804 | Q_PROPERTY(double median READ median WRITE setMedian)
2805 | Q_PROPERTY(double upperQuartile READ upperQuartile WRITE setUpperQuartile)
2806 | Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
2807 | Q_PROPERTY(QVector outliers READ outliers WRITE setOutliers)
2808 | Q_PROPERTY(double width READ width WRITE setWidth)
2809 | Q_PROPERTY(double whiskerWidth READ whiskerWidth WRITE setWhiskerWidth)
2810 | Q_PROPERTY(QPen whiskerPen READ whiskerPen WRITE setWhiskerPen)
2811 | Q_PROPERTY(QPen whiskerBarPen READ whiskerBarPen WRITE setWhiskerBarPen)
2812 | Q_PROPERTY(QPen medianPen READ medianPen WRITE setMedianPen)
2813 | Q_PROPERTY(QCPScatterStyle outlierStyle READ outlierStyle WRITE setOutlierStyle)
2814 | /// \endcond
2815 | public:
2816 | explicit QCPStatisticalBox(QCPAxis *keyAxis, QCPAxis *valueAxis);
2817 |
2818 | // getters:
2819 | double key() const { return mKey; }
2820 | double minimum() const { return mMinimum; }
2821 | double lowerQuartile() const { return mLowerQuartile; }
2822 | double median() const { return mMedian; }
2823 | double upperQuartile() const { return mUpperQuartile; }
2824 | double maximum() const { return mMaximum; }
2825 | QVector outliers() const { return mOutliers; }
2826 | double width() const { return mWidth; }
2827 | double whiskerWidth() const { return mWhiskerWidth; }
2828 | QPen whiskerPen() const { return mWhiskerPen; }
2829 | QPen whiskerBarPen() const { return mWhiskerBarPen; }
2830 | QPen medianPen() const { return mMedianPen; }
2831 | QCPScatterStyle outlierStyle() const { return mOutlierStyle; }
2832 |
2833 | // setters:
2834 | void setKey(double key);
2835 | void setMinimum(double value);
2836 | void setLowerQuartile(double value);
2837 | void setMedian(double value);
2838 | void setUpperQuartile(double value);
2839 | void setMaximum(double value);
2840 | void setOutliers(const QVector &values);
2841 | void setData(double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum);
2842 | void setWidth(double width);
2843 | void setWhiskerWidth(double width);
2844 | void setWhiskerPen(const QPen &pen);
2845 | void setWhiskerBarPen(const QPen &pen);
2846 | void setMedianPen(const QPen &pen);
2847 | void setOutlierStyle(const QCPScatterStyle &style);
2848 |
2849 | // non-property methods:
2850 | virtual void clearData();
2851 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2852 |
2853 | protected:
2854 | // property members:
2855 | QVector mOutliers;
2856 | double mKey, mMinimum, mLowerQuartile, mMedian, mUpperQuartile, mMaximum;
2857 | double mWidth;
2858 | double mWhiskerWidth;
2859 | QPen mWhiskerPen, mWhiskerBarPen, mMedianPen;
2860 | QCPScatterStyle mOutlierStyle;
2861 |
2862 | // reimplemented virtual methods:
2863 | virtual void draw(QCPPainter *painter);
2864 | virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2865 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2866 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2867 |
2868 | // introduced virtual methods:
2869 | virtual void drawQuartileBox(QCPPainter *painter, QRectF *quartileBox=0) const;
2870 | virtual void drawMedian(QCPPainter *painter) const;
2871 | virtual void drawWhiskers(QCPPainter *painter) const;
2872 | virtual void drawOutliers(QCPPainter *painter) const;
2873 |
2874 | friend class QCustomPlot;
2875 | friend class QCPLegend;
2876 | };
2877 |
2878 |
2879 | class QCP_LIB_DECL QCPColorMapData
2880 | {
2881 | public:
2882 | QCPColorMapData(int keySize, int valueSize, const QCPRange &keyRange, const QCPRange &valueRange);
2883 | ~QCPColorMapData();
2884 | QCPColorMapData(const QCPColorMapData &other);
2885 | QCPColorMapData &operator=(const QCPColorMapData &other);
2886 |
2887 | // getters:
2888 | int keySize() const { return mKeySize; }
2889 | int valueSize() const { return mValueSize; }
2890 | QCPRange keyRange() const { return mKeyRange; }
2891 | QCPRange valueRange() const { return mValueRange; }
2892 | QCPRange dataBounds() const { return mDataBounds; }
2893 | double data(double key, double value);
2894 | double cell(int keyIndex, int valueIndex);
2895 |
2896 | // setters:
2897 | void setSize(int keySize, int valueSize);
2898 | void setKeySize(int keySize);
2899 | void setValueSize(int valueSize);
2900 | void setRange(const QCPRange &keyRange, const QCPRange &valueRange);
2901 | void setKeyRange(const QCPRange &keyRange);
2902 | void setValueRange(const QCPRange &valueRange);
2903 | void setData(double key, double value, double z);
2904 | void setCell(int keyIndex, int valueIndex, double z);
2905 |
2906 | // non-property methods:
2907 | void recalculateDataBounds();
2908 | void clear();
2909 | void fill(double z);
2910 | bool isEmpty() const { return mIsEmpty; }
2911 | void coordToCell(double key, double value, int *keyIndex, int *valueIndex) const;
2912 | void cellToCoord(int keyIndex, int valueIndex, double *key, double *value) const;
2913 |
2914 | protected:
2915 | // property members:
2916 | int mKeySize, mValueSize;
2917 | QCPRange mKeyRange, mValueRange;
2918 | bool mIsEmpty;
2919 | // non-property members:
2920 | double *mData;
2921 | QCPRange mDataBounds;
2922 | bool mDataModified;
2923 |
2924 | friend class QCPColorMap;
2925 | };
2926 |
2927 |
2928 | class QCP_LIB_DECL QCPColorMap : public QCPAbstractPlottable
2929 | {
2930 | Q_OBJECT
2931 | /// \cond INCLUDE_QPROPERTIES
2932 | Q_PROPERTY(QCPRange dataRange READ dataRange WRITE setDataRange NOTIFY dataRangeChanged)
2933 | Q_PROPERTY(QCPAxis::ScaleType dataScaleType READ dataScaleType WRITE setDataScaleType NOTIFY dataScaleTypeChanged)
2934 | Q_PROPERTY(QCPColorGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
2935 | Q_PROPERTY(bool interpolate READ interpolate WRITE setInterpolate)
2936 | Q_PROPERTY(bool tightBoundary READ tightBoundary WRITE setTightBoundary)
2937 | Q_PROPERTY(QCPColorScale* colorScale READ colorScale WRITE setColorScale)
2938 | /// \endcond
2939 | public:
2940 | explicit QCPColorMap(QCPAxis *keyAxis, QCPAxis *valueAxis);
2941 | virtual ~QCPColorMap();
2942 |
2943 | // getters:
2944 | QCPColorMapData *data() const { return mMapData; }
2945 | QCPRange dataRange() const { return mDataRange; }
2946 | QCPAxis::ScaleType dataScaleType() const { return mDataScaleType; }
2947 | bool interpolate() const { return mInterpolate; }
2948 | bool tightBoundary() const { return mTightBoundary; }
2949 | QCPColorGradient gradient() const { return mGradient; }
2950 | QCPColorScale *colorScale() const { return mColorScale.data(); }
2951 |
2952 | // setters:
2953 | void setData(QCPColorMapData *data, bool copy=false);
2954 | Q_SLOT void setDataRange(const QCPRange &dataRange);
2955 | Q_SLOT void setDataScaleType(QCPAxis::ScaleType scaleType);
2956 | Q_SLOT void setGradient(const QCPColorGradient &gradient);
2957 | void setInterpolate(bool enabled);
2958 | void setTightBoundary(bool enabled);
2959 | void setColorScale(QCPColorScale *colorScale);
2960 |
2961 | // non-property methods:
2962 | void rescaleDataRange(bool recalculateDataBounds=false);
2963 | Q_SLOT void updateLegendIcon(Qt::TransformationMode transformMode=Qt::SmoothTransformation, const QSize &thumbSize=QSize(32, 18));
2964 |
2965 | // reimplemented virtual methods:
2966 | virtual void clearData();
2967 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
2968 |
2969 | signals:
2970 | void dataRangeChanged(QCPRange newRange);
2971 | void dataScaleTypeChanged(QCPAxis::ScaleType scaleType);
2972 | void gradientChanged(QCPColorGradient newGradient);
2973 |
2974 | protected:
2975 | // property members:
2976 | QCPRange mDataRange;
2977 | QCPAxis::ScaleType mDataScaleType;
2978 | QCPColorMapData *mMapData;
2979 | QCPColorGradient mGradient;
2980 | bool mInterpolate;
2981 | bool mTightBoundary;
2982 | QPointer mColorScale;
2983 | // non-property members:
2984 | QImage mMapImage;
2985 | QPixmap mLegendIcon;
2986 | bool mMapImageInvalidated;
2987 |
2988 | // introduced virtual methods:
2989 | virtual void updateMapImage();
2990 |
2991 | // reimplemented virtual methods:
2992 | virtual void draw(QCPPainter *painter);
2993 | virtual void drawLegendIcon(QCPPainter *painter, const QRectF &rect) const;
2994 | virtual QCPRange getKeyRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2995 | virtual QCPRange getValueRange(bool &foundRange, SignDomain inSignDomain=sdBoth) const;
2996 |
2997 | friend class QCustomPlot;
2998 | friend class QCPLegend;
2999 | };
3000 |
3001 |
3002 | class QCP_LIB_DECL QCPItemStraightLine : public QCPAbstractItem
3003 | {
3004 | Q_OBJECT
3005 | /// \cond INCLUDE_QPROPERTIES
3006 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3007 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3008 | /// \endcond
3009 | public:
3010 | QCPItemStraightLine(QCustomPlot *parentPlot);
3011 | virtual ~QCPItemStraightLine();
3012 |
3013 | // getters:
3014 | QPen pen() const { return mPen; }
3015 | QPen selectedPen() const { return mSelectedPen; }
3016 |
3017 | // setters;
3018 | void setPen(const QPen &pen);
3019 | void setSelectedPen(const QPen &pen);
3020 |
3021 | // reimplemented virtual methods:
3022 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3023 |
3024 | QCPItemPosition * const point1;
3025 | QCPItemPosition * const point2;
3026 |
3027 | protected:
3028 | // property members:
3029 | QPen mPen, mSelectedPen;
3030 |
3031 | // reimplemented virtual methods:
3032 | virtual void draw(QCPPainter *painter);
3033 |
3034 | // non-virtual methods:
3035 | double distToStraightLine(const QVector2D &point1, const QVector2D &vec, const QVector2D &point) const;
3036 | QLineF getRectClippedStraightLine(const QVector2D &point1, const QVector2D &vec, const QRect &rect) const;
3037 | QPen mainPen() const;
3038 | };
3039 |
3040 |
3041 | class QCP_LIB_DECL QCPItemLine : public QCPAbstractItem
3042 | {
3043 | Q_OBJECT
3044 | /// \cond INCLUDE_QPROPERTIES
3045 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3046 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3047 | Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
3048 | Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
3049 | /// \endcond
3050 | public:
3051 | QCPItemLine(QCustomPlot *parentPlot);
3052 | virtual ~QCPItemLine();
3053 |
3054 | // getters:
3055 | QPen pen() const { return mPen; }
3056 | QPen selectedPen() const { return mSelectedPen; }
3057 | QCPLineEnding head() const { return mHead; }
3058 | QCPLineEnding tail() const { return mTail; }
3059 |
3060 | // setters;
3061 | void setPen(const QPen &pen);
3062 | void setSelectedPen(const QPen &pen);
3063 | void setHead(const QCPLineEnding &head);
3064 | void setTail(const QCPLineEnding &tail);
3065 |
3066 | // reimplemented virtual methods:
3067 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3068 |
3069 | QCPItemPosition * const start;
3070 | QCPItemPosition * const end;
3071 |
3072 | protected:
3073 | // property members:
3074 | QPen mPen, mSelectedPen;
3075 | QCPLineEnding mHead, mTail;
3076 |
3077 | // reimplemented virtual methods:
3078 | virtual void draw(QCPPainter *painter);
3079 |
3080 | // non-virtual methods:
3081 | QLineF getRectClippedLine(const QVector2D &start, const QVector2D &end, const QRect &rect) const;
3082 | QPen mainPen() const;
3083 | };
3084 |
3085 |
3086 | class QCP_LIB_DECL QCPItemCurve : public QCPAbstractItem
3087 | {
3088 | Q_OBJECT
3089 | /// \cond INCLUDE_QPROPERTIES
3090 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3091 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3092 | Q_PROPERTY(QCPLineEnding head READ head WRITE setHead)
3093 | Q_PROPERTY(QCPLineEnding tail READ tail WRITE setTail)
3094 | /// \endcond
3095 | public:
3096 | QCPItemCurve(QCustomPlot *parentPlot);
3097 | virtual ~QCPItemCurve();
3098 |
3099 | // getters:
3100 | QPen pen() const { return mPen; }
3101 | QPen selectedPen() const { return mSelectedPen; }
3102 | QCPLineEnding head() const { return mHead; }
3103 | QCPLineEnding tail() const { return mTail; }
3104 |
3105 | // setters;
3106 | void setPen(const QPen &pen);
3107 | void setSelectedPen(const QPen &pen);
3108 | void setHead(const QCPLineEnding &head);
3109 | void setTail(const QCPLineEnding &tail);
3110 |
3111 | // reimplemented virtual methods:
3112 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3113 |
3114 | QCPItemPosition * const start;
3115 | QCPItemPosition * const startDir;
3116 | QCPItemPosition * const endDir;
3117 | QCPItemPosition * const end;
3118 |
3119 | protected:
3120 | // property members:
3121 | QPen mPen, mSelectedPen;
3122 | QCPLineEnding mHead, mTail;
3123 |
3124 | // reimplemented virtual methods:
3125 | virtual void draw(QCPPainter *painter);
3126 |
3127 | // non-virtual methods:
3128 | QPen mainPen() const;
3129 | };
3130 |
3131 |
3132 | class QCP_LIB_DECL QCPItemRect : public QCPAbstractItem
3133 | {
3134 | Q_OBJECT
3135 | /// \cond INCLUDE_QPROPERTIES
3136 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3137 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3138 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3139 | Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3140 | /// \endcond
3141 | public:
3142 | QCPItemRect(QCustomPlot *parentPlot);
3143 | virtual ~QCPItemRect();
3144 |
3145 | // getters:
3146 | QPen pen() const { return mPen; }
3147 | QPen selectedPen() const { return mSelectedPen; }
3148 | QBrush brush() const { return mBrush; }
3149 | QBrush selectedBrush() const { return mSelectedBrush; }
3150 |
3151 | // setters;
3152 | void setPen(const QPen &pen);
3153 | void setSelectedPen(const QPen &pen);
3154 | void setBrush(const QBrush &brush);
3155 | void setSelectedBrush(const QBrush &brush);
3156 |
3157 | // reimplemented virtual methods:
3158 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3159 |
3160 | QCPItemPosition * const topLeft;
3161 | QCPItemPosition * const bottomRight;
3162 | QCPItemAnchor * const top;
3163 | QCPItemAnchor * const topRight;
3164 | QCPItemAnchor * const right;
3165 | QCPItemAnchor * const bottom;
3166 | QCPItemAnchor * const bottomLeft;
3167 | QCPItemAnchor * const left;
3168 |
3169 | protected:
3170 | enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
3171 |
3172 | // property members:
3173 | QPen mPen, mSelectedPen;
3174 | QBrush mBrush, mSelectedBrush;
3175 |
3176 | // reimplemented virtual methods:
3177 | virtual void draw(QCPPainter *painter);
3178 | virtual QPointF anchorPixelPoint(int anchorId) const;
3179 |
3180 | // non-virtual methods:
3181 | QPen mainPen() const;
3182 | QBrush mainBrush() const;
3183 | };
3184 |
3185 |
3186 | class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
3187 | {
3188 | Q_OBJECT
3189 | /// \cond INCLUDE_QPROPERTIES
3190 | Q_PROPERTY(QColor color READ color WRITE setColor)
3191 | Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
3192 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3193 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3194 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3195 | Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3196 | Q_PROPERTY(QFont font READ font WRITE setFont)
3197 | Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
3198 | Q_PROPERTY(QString text READ text WRITE setText)
3199 | Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
3200 | Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
3201 | Q_PROPERTY(double rotation READ rotation WRITE setRotation)
3202 | Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
3203 | /// \endcond
3204 | public:
3205 | QCPItemText(QCustomPlot *parentPlot);
3206 | virtual ~QCPItemText();
3207 |
3208 | // getters:
3209 | QColor color() const { return mColor; }
3210 | QColor selectedColor() const { return mSelectedColor; }
3211 | QPen pen() const { return mPen; }
3212 | QPen selectedPen() const { return mSelectedPen; }
3213 | QBrush brush() const { return mBrush; }
3214 | QBrush selectedBrush() const { return mSelectedBrush; }
3215 | QFont font() const { return mFont; }
3216 | QFont selectedFont() const { return mSelectedFont; }
3217 | QString text() const { return mText; }
3218 | Qt::Alignment positionAlignment() const { return mPositionAlignment; }
3219 | Qt::Alignment textAlignment() const { return mTextAlignment; }
3220 | double rotation() const { return mRotation; }
3221 | QMargins padding() const { return mPadding; }
3222 |
3223 | // setters;
3224 | void setColor(const QColor &color);
3225 | void setSelectedColor(const QColor &color);
3226 | void setPen(const QPen &pen);
3227 | void setSelectedPen(const QPen &pen);
3228 | void setBrush(const QBrush &brush);
3229 | void setSelectedBrush(const QBrush &brush);
3230 | void setFont(const QFont &font);
3231 | void setSelectedFont(const QFont &font);
3232 | void setText(const QString &text);
3233 | void setPositionAlignment(Qt::Alignment alignment);
3234 | void setTextAlignment(Qt::Alignment alignment);
3235 | void setRotation(double degrees);
3236 | void setPadding(const QMargins &padding);
3237 |
3238 | // reimplemented virtual methods:
3239 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3240 |
3241 | QCPItemPosition * const position;
3242 | QCPItemAnchor * const topLeft;
3243 | QCPItemAnchor * const top;
3244 | QCPItemAnchor * const topRight;
3245 | QCPItemAnchor * const right;
3246 | QCPItemAnchor * const bottomRight;
3247 | QCPItemAnchor * const bottom;
3248 | QCPItemAnchor * const bottomLeft;
3249 | QCPItemAnchor * const left;
3250 |
3251 | protected:
3252 | enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
3253 |
3254 | // property members:
3255 | QColor mColor, mSelectedColor;
3256 | QPen mPen, mSelectedPen;
3257 | QBrush mBrush, mSelectedBrush;
3258 | QFont mFont, mSelectedFont;
3259 | QString mText;
3260 | Qt::Alignment mPositionAlignment;
3261 | Qt::Alignment mTextAlignment;
3262 | double mRotation;
3263 | QMargins mPadding;
3264 |
3265 | // reimplemented virtual methods:
3266 | virtual void draw(QCPPainter *painter);
3267 | virtual QPointF anchorPixelPoint(int anchorId) const;
3268 |
3269 | // non-virtual methods:
3270 | QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
3271 | QFont mainFont() const;
3272 | QColor mainColor() const;
3273 | QPen mainPen() const;
3274 | QBrush mainBrush() const;
3275 | };
3276 |
3277 |
3278 | class QCP_LIB_DECL QCPItemEllipse : public QCPAbstractItem
3279 | {
3280 | Q_OBJECT
3281 | /// \cond INCLUDE_QPROPERTIES
3282 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3283 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3284 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3285 | Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3286 | /// \endcond
3287 | public:
3288 | QCPItemEllipse(QCustomPlot *parentPlot);
3289 | virtual ~QCPItemEllipse();
3290 |
3291 | // getters:
3292 | QPen pen() const { return mPen; }
3293 | QPen selectedPen() const { return mSelectedPen; }
3294 | QBrush brush() const { return mBrush; }
3295 | QBrush selectedBrush() const { return mSelectedBrush; }
3296 |
3297 | // setters;
3298 | void setPen(const QPen &pen);
3299 | void setSelectedPen(const QPen &pen);
3300 | void setBrush(const QBrush &brush);
3301 | void setSelectedBrush(const QBrush &brush);
3302 |
3303 | // reimplemented virtual methods:
3304 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3305 |
3306 | QCPItemPosition * const topLeft;
3307 | QCPItemPosition * const bottomRight;
3308 | QCPItemAnchor * const topLeftRim;
3309 | QCPItemAnchor * const top;
3310 | QCPItemAnchor * const topRightRim;
3311 | QCPItemAnchor * const right;
3312 | QCPItemAnchor * const bottomRightRim;
3313 | QCPItemAnchor * const bottom;
3314 | QCPItemAnchor * const bottomLeftRim;
3315 | QCPItemAnchor * const left;
3316 | QCPItemAnchor * const center;
3317 |
3318 | protected:
3319 | enum AnchorIndex {aiTopLeftRim, aiTop, aiTopRightRim, aiRight, aiBottomRightRim, aiBottom, aiBottomLeftRim, aiLeft, aiCenter};
3320 |
3321 | // property members:
3322 | QPen mPen, mSelectedPen;
3323 | QBrush mBrush, mSelectedBrush;
3324 |
3325 | // reimplemented virtual methods:
3326 | virtual void draw(QCPPainter *painter);
3327 | virtual QPointF anchorPixelPoint(int anchorId) const;
3328 |
3329 | // non-virtual methods:
3330 | QPen mainPen() const;
3331 | QBrush mainBrush() const;
3332 | };
3333 |
3334 |
3335 | class QCP_LIB_DECL QCPItemPixmap : public QCPAbstractItem
3336 | {
3337 | Q_OBJECT
3338 | /// \cond INCLUDE_QPROPERTIES
3339 | Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
3340 | Q_PROPERTY(bool scaled READ scaled WRITE setScaled)
3341 | Q_PROPERTY(Qt::AspectRatioMode aspectRatioMode READ aspectRatioMode)
3342 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3343 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3344 | /// \endcond
3345 | public:
3346 | QCPItemPixmap(QCustomPlot *parentPlot);
3347 | virtual ~QCPItemPixmap();
3348 |
3349 | // getters:
3350 | QPixmap pixmap() const { return mPixmap; }
3351 | bool scaled() const { return mScaled; }
3352 | Qt::AspectRatioMode aspectRatioMode() const { return mAspectRatioMode; }
3353 | QPen pen() const { return mPen; }
3354 | QPen selectedPen() const { return mSelectedPen; }
3355 |
3356 | // setters;
3357 | void setPixmap(const QPixmap &pixmap);
3358 | void setScaled(bool scaled, Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio);
3359 | void setPen(const QPen &pen);
3360 | void setSelectedPen(const QPen &pen);
3361 |
3362 | // reimplemented virtual methods:
3363 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3364 |
3365 | QCPItemPosition * const topLeft;
3366 | QCPItemPosition * const bottomRight;
3367 | QCPItemAnchor * const top;
3368 | QCPItemAnchor * const topRight;
3369 | QCPItemAnchor * const right;
3370 | QCPItemAnchor * const bottom;
3371 | QCPItemAnchor * const bottomLeft;
3372 | QCPItemAnchor * const left;
3373 |
3374 | protected:
3375 | enum AnchorIndex {aiTop, aiTopRight, aiRight, aiBottom, aiBottomLeft, aiLeft};
3376 |
3377 | // property members:
3378 | QPixmap mPixmap;
3379 | QPixmap mScaledPixmap;
3380 | bool mScaled;
3381 | Qt::AspectRatioMode mAspectRatioMode;
3382 | QPen mPen, mSelectedPen;
3383 |
3384 | // reimplemented virtual methods:
3385 | virtual void draw(QCPPainter *painter);
3386 | virtual QPointF anchorPixelPoint(int anchorId) const;
3387 |
3388 | // non-virtual methods:
3389 | void updateScaledPixmap(QRect finalRect=QRect(), bool flipHorz=false, bool flipVert=false);
3390 | QRect getFinalRect(bool *flippedHorz=0, bool *flippedVert=0) const;
3391 | QPen mainPen() const;
3392 | };
3393 |
3394 |
3395 | class QCP_LIB_DECL QCPItemTracer : public QCPAbstractItem
3396 | {
3397 | Q_OBJECT
3398 | /// \cond INCLUDE_QPROPERTIES
3399 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3400 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3401 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
3402 | Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
3403 | Q_PROPERTY(double size READ size WRITE setSize)
3404 | Q_PROPERTY(TracerStyle style READ style WRITE setStyle)
3405 | Q_PROPERTY(QCPGraph* graph READ graph WRITE setGraph)
3406 | Q_PROPERTY(double graphKey READ graphKey WRITE setGraphKey)
3407 | Q_PROPERTY(bool interpolating READ interpolating WRITE setInterpolating)
3408 | /// \endcond
3409 | public:
3410 | /*!
3411 | The different visual appearances a tracer item can have. Some styles size may be controlled with \ref setSize.
3412 |
3413 | \see setStyle
3414 | */
3415 | enum TracerStyle { tsNone ///< The tracer is not visible
3416 | ,tsPlus ///< A plus shaped crosshair with limited size
3417 | ,tsCrosshair ///< A plus shaped crosshair which spans the complete axis rect
3418 | ,tsCircle ///< A circle
3419 | ,tsSquare ///< A square
3420 | };
3421 | Q_ENUMS(TracerStyle)
3422 |
3423 | QCPItemTracer(QCustomPlot *parentPlot);
3424 | virtual ~QCPItemTracer();
3425 |
3426 | // getters:
3427 | QPen pen() const { return mPen; }
3428 | QPen selectedPen() const { return mSelectedPen; }
3429 | QBrush brush() const { return mBrush; }
3430 | QBrush selectedBrush() const { return mSelectedBrush; }
3431 | double size() const { return mSize; }
3432 | TracerStyle style() const { return mStyle; }
3433 | QCPGraph *graph() const { return mGraph; }
3434 | double graphKey() const { return mGraphKey; }
3435 | bool interpolating() const { return mInterpolating; }
3436 |
3437 | // setters;
3438 | void setPen(const QPen &pen);
3439 | void setSelectedPen(const QPen &pen);
3440 | void setBrush(const QBrush &brush);
3441 | void setSelectedBrush(const QBrush &brush);
3442 | void setSize(double size);
3443 | void setStyle(TracerStyle style);
3444 | void setGraph(QCPGraph *graph);
3445 | void setGraphKey(double key);
3446 | void setInterpolating(bool enabled);
3447 |
3448 | // reimplemented virtual methods:
3449 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3450 |
3451 | // non-virtual methods:
3452 | void updatePosition();
3453 |
3454 | QCPItemPosition * const position;
3455 |
3456 | protected:
3457 | // property members:
3458 | QPen mPen, mSelectedPen;
3459 | QBrush mBrush, mSelectedBrush;
3460 | double mSize;
3461 | TracerStyle mStyle;
3462 | QCPGraph *mGraph;
3463 | double mGraphKey;
3464 | bool mInterpolating;
3465 |
3466 | // reimplemented virtual methods:
3467 | virtual void draw(QCPPainter *painter);
3468 |
3469 | // non-virtual methods:
3470 | QPen mainPen() const;
3471 | QBrush mainBrush() const;
3472 | };
3473 |
3474 |
3475 | class QCP_LIB_DECL QCPItemBracket : public QCPAbstractItem
3476 | {
3477 | Q_OBJECT
3478 | /// \cond INCLUDE_QPROPERTIES
3479 | Q_PROPERTY(QPen pen READ pen WRITE setPen)
3480 | Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
3481 | Q_PROPERTY(double length READ length WRITE setLength)
3482 | Q_PROPERTY(BracketStyle style READ style WRITE setStyle)
3483 | /// \endcond
3484 | public:
3485 | enum BracketStyle { bsSquare ///< A brace with angled edges
3486 | ,bsRound ///< A brace with round edges
3487 | ,bsCurly ///< A curly brace
3488 | ,bsCalligraphic ///< A curly brace with varying stroke width giving a calligraphic impression
3489 | };
3490 |
3491 | QCPItemBracket(QCustomPlot *parentPlot);
3492 | virtual ~QCPItemBracket();
3493 |
3494 | // getters:
3495 | QPen pen() const { return mPen; }
3496 | QPen selectedPen() const { return mSelectedPen; }
3497 | double length() const { return mLength; }
3498 | BracketStyle style() const { return mStyle; }
3499 |
3500 | // setters;
3501 | void setPen(const QPen &pen);
3502 | void setSelectedPen(const QPen &pen);
3503 | void setLength(double length);
3504 | void setStyle(BracketStyle style);
3505 |
3506 | // reimplemented virtual methods:
3507 | virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
3508 |
3509 | QCPItemPosition * const left;
3510 | QCPItemPosition * const right;
3511 | QCPItemAnchor * const center;
3512 |
3513 | protected:
3514 | // property members:
3515 | enum AnchorIndex {aiCenter};
3516 | QPen mPen, mSelectedPen;
3517 | double mLength;
3518 | BracketStyle mStyle;
3519 |
3520 | // reimplemented virtual methods:
3521 | virtual void draw(QCPPainter *painter);
3522 | virtual QPointF anchorPixelPoint(int anchorId) const;
3523 |
3524 | // non-virtual methods:
3525 | QPen mainPen() const;
3526 | };
3527 |
3528 | #endif // QCUSTOMPLOT_H
3529 |
3530 |
--------------------------------------------------------------------------------