1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "mainwindow.h"
31#include "chartview.h"
32#include <QtCharts/QScatterSeries>
33#include <QtCharts/QLineSeries>
34#include <QtCharts/QSplineSeries>
35#include <QtCharts/QAreaSeries>
36#include <QtCharts/QBarSeries>
37#include <QtCharts/QBarSet>
38#include <QtCharts/QValueAxis>
39#include <QtCharts/QLogValueAxis>
40#include <QtCharts/QDateTimeAxis>
41#include <QtCharts/QCategoryAxis>
42#include <QtCharts/QPolarChart>
43#include <QtCore/QDebug>
44#include <QtCore/QtMath>
45#include <QtCore/QDateTime>
46
47QT_CHARTS_USE_NAMESPACE
48#include "ui_mainwindow.h"
49
50MainWindow::MainWindow(QWidget *parent) :
51 QMainWindow(parent),
52 ui(new Ui::MainWindow),
53 m_angularTickCount(9),
54 m_radialTickCount(11),
55 m_labelsAngle(0),
56 m_angularMin(0.0),
57 m_angularMax(40000.0),
58 m_radialMin(0.0),
59 m_radialMax(30000.0),
60 m_angularShadesVisible(false),
61 m_radialShadesVisible(false),
62 m_labelsVisible(true),
63 m_titleVisible(true),
64 m_gridVisible(true),
65 m_arrowVisible(true),
66 m_minorGridVisible(true),
67 m_minorArrowVisible(true),
68 m_angularShadesBrush(new QBrush(Qt::NoBrush)),
69 m_radialShadesBrush(new QBrush(Qt::NoBrush)),
70 m_labelBrush(new QBrush(Qt::black)),
71 m_titleBrush(new QBrush(Qt::black)),
72 m_backgroundBrush(new QBrush(Qt::white)),
73 m_plotAreaBackgroundBrush(new QBrush(Qt::NoBrush)),
74 m_angularShadesPen(new QPen(Qt::NoPen)),
75 m_radialShadesPen(new QPen(Qt::NoPen)),
76 m_gridPen(new QPen(QRgb(0x010101))), // Note: Pure black is default color, so it gets overridden by
77 m_arrowPen(new QPen(QRgb(0x010101))), // default theme if set to that initially. This is an example of workaround.
78 m_minorGridPen(new QPen(QBrush(QRgb(0x010101)), 1, Qt::DashLine)),
79 m_backgroundPen(new QPen(Qt::NoPen)),
80 m_plotAreaBackgroundPen(new QPen(Qt::NoPen)),
81 m_labelFormat(QString("%.2f")),
82 m_animationOptions(QChart::NoAnimation),
83 m_angularTitle(QString("Angular Title")),
84 m_radialTitle(QString("Radial Title")),
85 m_base(2.0),
86 m_dateFormat(QString("mm-ss-zzz")),
87 m_chart(0),
88 m_angularAxis(0),
89 m_radialAxis(0),
90 m_angularAxisMode(AxisModeNone),
91 m_radialAxisMode(AxisModeNone),
92 m_moreCategories(false),
93 m_series1(0),
94 m_series2(0),
95 m_series3(0),
96 m_series4(0),
97 m_series5(0),
98 m_series6(0),
99 m_series7(0)
100{
101 ui->setupUi(this);
102
103 ui->angularTicksSpin->setValue(m_angularTickCount);
104 ui->radialTicksSpin->setValue(m_radialTickCount);
105 ui->anglesSpin->setValue(m_labelsAngle);
106 ui->radialMinSpin->setValue(m_radialMin);
107 ui->radialMaxSpin->setValue(m_radialMax);
108 ui->angularMinSpin->setValue(m_angularMin);
109 ui->angularMaxSpin->setValue(m_angularMax);
110 ui->angularShadesComboBox->setCurrentIndex(0);
111 ui->radialShadesComboBox->setCurrentIndex(0);
112 ui->labelFormatEdit->setText(m_labelFormat);
113 ui->dateFormatEdit->setText(m_dateFormat);
114 ui->moreCategoriesCheckBox->setChecked(m_moreCategories);
115
116 ui->series1checkBox->setChecked(true);
117 ui->series2checkBox->setChecked(true);
118 ui->series3checkBox->setChecked(true);
119 ui->series4checkBox->setChecked(true);
120 ui->series5checkBox->setChecked(true);
121 ui->series6checkBox->setChecked(true);
122 ui->series7checkBox->setChecked(true);
123
124 m_currentLabelFont.setFamily(ui->labelFontComboBox->currentFont().family());
125 m_currentLabelFont.setPixelSize(15);
126 m_currentTitleFont.setFamily(ui->titleFontComboBox->currentFont().family());
127 m_currentTitleFont.setPixelSize(30);
128
129 ui->labelFontSizeSpin->setValue(m_currentLabelFont.pixelSize());
130 ui->titleFontSizeSpin->setValue(m_currentTitleFont.pixelSize());
131
132 ui->logBaseSpin->setValue(m_base);
133
134 initXYValueChart();
135 setAngularAxis(AxisModeValue);
136 setRadialAxis(AxisModeValue);
137
138 ui->angularAxisComboBox->setCurrentIndex(int(m_angularAxisMode));
139 ui->radialAxisComboBox->setCurrentIndex(int(m_radialAxisMode));
140
141 connect(sender: ui->angularTicksSpin, SIGNAL(valueChanged(int)),
142 receiver: this, SLOT(angularTicksChanged(int)));
143 connect(sender: ui->radialTicksSpin, SIGNAL(valueChanged(int)),
144 receiver: this, SLOT(radialTicksChanged(int)));
145 connect(sender: ui->angularMinorTicksSpin, SIGNAL(valueChanged(int)),
146 receiver: this, SLOT(angularMinorTicksChanged(int)));
147 connect(sender: ui->radialMinorTicksSpin, SIGNAL(valueChanged(int)),
148 receiver: this, SLOT(radialMinorTicksChanged(int)));
149 connect(sender: ui->anglesSpin, SIGNAL(valueChanged(int)),
150 receiver: this, SLOT(anglesChanged(int)));
151 connect(sender: ui->radialMinSpin, SIGNAL(valueChanged(double)),
152 receiver: this, SLOT(radialMinChanged(double)));
153 connect(sender: ui->radialMaxSpin, SIGNAL(valueChanged(double)),
154 receiver: this, SLOT(radialMaxChanged(double)));
155 connect(sender: ui->angularMinSpin, SIGNAL(valueChanged(double)),
156 receiver: this, SLOT(angularMinChanged(double)));
157 connect(sender: ui->angularMaxSpin, SIGNAL(valueChanged(double)),
158 receiver: this, SLOT(angularMaxChanged(double)));
159 connect(sender: ui->angularShadesComboBox, SIGNAL(currentIndexChanged(int)),
160 receiver: this, SLOT(angularShadesIndexChanged(int)));
161 connect(sender: ui->radialShadesComboBox, SIGNAL(currentIndexChanged(int)),
162 receiver: this, SLOT(radialShadesIndexChanged(int)));
163 connect(sender: ui->animationsComboBox, SIGNAL(currentIndexChanged(int)),
164 receiver: this, SLOT(animationIndexChanged(int)));
165 connect(sender: ui->labelFormatEdit, SIGNAL(textEdited(QString)),
166 receiver: this, SLOT(labelFormatEdited(QString)));
167 connect(sender: ui->labelFontComboBox, SIGNAL(currentFontChanged(QFont)),
168 receiver: this, SLOT(labelFontChanged(QFont)));
169 connect(sender: ui->labelFontSizeSpin, SIGNAL(valueChanged(int)),
170 receiver: this, SLOT(labelFontSizeChanged(int)));
171 connect(sender: ui->labelComboBox, SIGNAL(currentIndexChanged(int)),
172 receiver: this, SLOT(labelsIndexChanged(int)));
173 connect(sender: ui->titleFontComboBox, SIGNAL(currentFontChanged(QFont)),
174 receiver: this, SLOT(titleFontChanged(QFont)));
175 connect(sender: ui->titleFontSizeSpin, SIGNAL(valueChanged(int)),
176 receiver: this, SLOT(titleFontSizeChanged(int)));
177 connect(sender: ui->titleComboBox, SIGNAL(currentIndexChanged(int)),
178 receiver: this, SLOT(titleIndexChanged(int)));
179 connect(sender: ui->gridComboBox, SIGNAL(currentIndexChanged(int)),
180 receiver: this, SLOT(gridIndexChanged(int)));
181 connect(sender: ui->minorGridComboBox, SIGNAL(currentIndexChanged(int)),
182 receiver: this, SLOT(minorGridIndexChanged(int)));
183 connect(sender: ui->gridLineColorComboBox, SIGNAL(currentIndexChanged(int)),
184 receiver: this, SLOT(gridLineColorIndexChanged(int)));
185 connect(sender: ui->arrowComboBox, SIGNAL(currentIndexChanged(int)),
186 receiver: this, SLOT(arrowIndexChanged(int)));
187 connect(sender: ui->logBaseSpin, SIGNAL(valueChanged(double)),
188 receiver: this, SLOT(logBaseChanged(double)));
189 connect(sender: ui->angularAxisComboBox, SIGNAL(currentIndexChanged(int)),
190 receiver: this, SLOT(angularAxisIndexChanged(int)));
191 connect(sender: ui->radialAxisComboBox, SIGNAL(currentIndexChanged(int)),
192 receiver: this, SLOT(radialAxisIndexChanged(int)));
193 connect(sender: ui->niceNumbersCheckBox, SIGNAL(clicked()),
194 receiver: this, SLOT(niceNumbersChecked()));
195 connect(sender: ui->dateFormatEdit, SIGNAL(textEdited(QString)),
196 receiver: this, SLOT(dateFormatEdited(QString)));
197 connect(sender: ui->moreCategoriesCheckBox, SIGNAL(clicked()),
198 receiver: this, SLOT(moreCategoriesChecked()));
199 connect(sender: ui->categoryLabelLocationCheckBox, SIGNAL(clicked()),
200 receiver: this, SLOT(categoryLabelLocationChecked()));
201 connect(sender: ui->series1checkBox, SIGNAL(clicked()),
202 receiver: this, SLOT(series1CheckBoxChecked()));
203 connect(sender: ui->series2checkBox, SIGNAL(clicked()),
204 receiver: this, SLOT(series2CheckBoxChecked()));
205 connect(sender: ui->series3checkBox, SIGNAL(clicked()),
206 receiver: this, SLOT(series3CheckBoxChecked()));
207 connect(sender: ui->series4checkBox, SIGNAL(clicked()),
208 receiver: this, SLOT(series4CheckBoxChecked()));
209 connect(sender: ui->series5checkBox, SIGNAL(clicked()),
210 receiver: this, SLOT(series5CheckBoxChecked()));
211 connect(sender: ui->series6checkBox, SIGNAL(clicked()),
212 receiver: this, SLOT(series6CheckBoxChecked()));
213 connect(sender: ui->series7checkBox, SIGNAL(clicked()),
214 receiver: this, SLOT(series7CheckBoxChecked()));
215 connect(sender: ui->themeComboBox, SIGNAL(currentIndexChanged(int)),
216 receiver: this, SLOT(themeIndexChanged(int)));
217 connect(sender: ui->backgroundComboBox, SIGNAL(currentIndexChanged(int)),
218 receiver: this, SLOT(backgroundIndexChanged(int)));
219 connect(sender: ui->plotAreaComboBox, SIGNAL(currentIndexChanged(int)),
220 receiver: this, SLOT(plotAreaIndexChanged(int)));
221
222 ui->chartView->setChart(m_chart);
223 ui->chartView->setRenderHint(hint: QPainter::Antialiasing);
224}
225
226MainWindow::~MainWindow()
227{
228 delete ui;
229 delete m_angularShadesBrush;
230 delete m_radialShadesBrush;
231 delete m_angularShadesPen;
232 delete m_radialShadesPen;
233}
234
235void MainWindow::initXYValueChart()
236{
237 qreal seriesAngularMin = 1;
238 qreal seriesAngularMax = 46000;
239 qreal seriesRadialMin = 1;
240 qreal seriesRadialMax = 23500;
241 qreal radialDimension = seriesRadialMax - seriesRadialMin;
242 qreal angularDimension = seriesAngularMax - seriesAngularMin;
243
244 // Scatter series, points outside min-max ranges should not be drawn
245 m_series1 = new QScatterSeries();
246 m_series1->setName("scatter");
247 qreal scatterCount = 10;
248 qreal scatterAngularStep = angularDimension / scatterCount;
249 qreal scatterRadialStep = radialDimension / scatterCount;
250 for (qreal i = 0.0; i < scatterCount; i++) {
251 m_series1->append(x: (i * scatterAngularStep) + seriesAngularMin, y: (i * scatterRadialStep) + seriesRadialMin);
252 //qDebug() << m_series1->points().last();
253 }
254 m_series1->setMarkerSize(10);
255 *m_series1 << QPointF(50, 50) << QPointF(150, 150) << QPointF(250, 250) << QPointF(350, 350) << QPointF(450, 450);
256 *m_series1 << QPointF(1050, 0.50) << QPointF(1150, 0.25) << QPointF(1250, 0.12) << QPointF(1350, 0.075) << QPointF(1450, 0.036);
257 *m_series1 << QPointF(0.50, 2000) << QPointF(0.25, 3500) << QPointF(0.12, 5000) << QPointF(0.075, 6500) << QPointF(0.036, 8000);
258
259 // Line series, points outside min-max ranges should not be drawn,
260 // but lines should be properly interpolated at chart edges
261 m_series2 = new QLineSeries();
262 m_series2->setName("line 1");
263 qreal lineCount = 100;
264 qreal lineAngularStep = angularDimension / lineCount;
265 qreal lineRadialStep = radialDimension / lineCount;
266 for (qreal i = 0.0; i < lineCount; i++) {
267 m_series2->append(x: (i * lineAngularStep) + seriesAngularMin, y: (i * lineRadialStep) + seriesRadialMin);
268 //qDebug() << m_series2->points().last();
269 }
270 QPen series2Pen = QPen(Qt::blue, 10);
271 //series2Pen.setStyle(Qt::DashDotDotLine);
272 m_series2->setPen(series2Pen);
273
274 m_series3 = new QLineSeries();
275 m_series3->setName("Area upper");
276 lineCount = 87;
277 lineAngularStep = angularDimension / lineCount;
278 lineRadialStep = radialDimension / lineCount;
279 for (qreal i = 1.0; i <= lineCount; i++) {
280 m_series3->append(x: (i * lineAngularStep) + seriesAngularMin, y: (i * lineRadialStep) + seriesRadialMin + 200.0);
281 //qDebug() << m_series3->points().last();
282 }
283
284 m_series4 = new QLineSeries();
285 m_series4->setName("Area lower");
286 lineCount = 89;
287 lineAngularStep = angularDimension / lineCount;
288 lineRadialStep = radialDimension / lineCount;
289 for (qreal i = 1.0; i <= lineCount; i++) {
290 m_series4->append(x: (i * lineAngularStep) + seriesAngularMin + 100.0, y: (i * lineRadialStep) + seriesRadialMin + i * 300.0);
291 //qDebug() << m_series4->points().last();
292 }
293
294 m_series5 = new QAreaSeries();
295 m_series5->setName("area");
296 m_series5->setUpperSeries(m_series3);
297 m_series5->setLowerSeries(m_series4);
298 m_series5->setOpacity(0.5);
299
300 m_series6 = new QSplineSeries();
301 m_series6->setName("spline");
302 qreal ad = angularDimension / 20;
303 qreal rd = radialDimension / 10;
304 m_series6->append(x: seriesAngularMin, y: seriesRadialMin + rd * 2);
305 m_series6->append(x: seriesAngularMin + ad, y: seriesRadialMin + rd * 5);
306 m_series6->append(x: seriesAngularMin + ad * 2, y: seriesRadialMin + rd * 4);
307 m_series6->append(x: seriesAngularMin + ad * 3, y: seriesRadialMin + rd * 9);
308 m_series6->append(x: seriesAngularMin + ad * 4, y: seriesRadialMin + rd * 11);
309 m_series6->append(x: seriesAngularMin + ad * 5, y: seriesRadialMin + rd * 12);
310 m_series6->append(x: seriesAngularMin + ad * 6, y: seriesRadialMin + rd * 9);
311 m_series6->append(x: seriesAngularMin + ad * 7, y: seriesRadialMin + rd * 11);
312 m_series6->append(x: seriesAngularMin + ad * 8, y: seriesRadialMin + rd * 12);
313 m_series6->append(x: seriesAngularMin + ad * 9, y: seriesRadialMin + rd * 6);
314 m_series6->append(x: seriesAngularMin + ad * 10, y: seriesRadialMin + rd * 4);
315 m_series6->append(x: seriesAngularMin + ad * 10, y: seriesRadialMin + rd * 8);
316 m_series6->append(x: seriesAngularMin + ad * 11, y: seriesRadialMin + rd * 9);
317 m_series6->append(x: seriesAngularMin + ad * 12, y: seriesRadialMin + rd * 11);
318 m_series6->append(x: seriesAngularMin + ad * 13, y: seriesRadialMin + rd * 12);
319 m_series6->append(x: seriesAngularMin + ad * 14, y: seriesRadialMin + rd * 6);
320 m_series6->append(x: seriesAngularMin + ad * 15, y: seriesRadialMin + rd * 3);
321 m_series6->append(x: seriesAngularMin + ad * 16, y: seriesRadialMin + rd * 2);
322 m_series6->append(x: seriesAngularMin + ad * 17, y: seriesRadialMin + rd * 6);
323 m_series6->append(x: seriesAngularMin + ad * 18, y: seriesRadialMin + rd * 6);
324 m_series6->append(x: seriesAngularMin + ad * 19, y: seriesRadialMin + rd * 6);
325 m_series6->append(x: seriesAngularMin + ad * 20, y: seriesRadialMin + rd * 6);
326 m_series6->append(x: seriesAngularMin + ad * 19, y: seriesRadialMin + rd * 2);
327 m_series6->append(x: seriesAngularMin + ad * 18, y: seriesRadialMin + rd * 9);
328 m_series6->append(x: seriesAngularMin + ad * 17, y: seriesRadialMin + rd * 7);
329 m_series6->append(x: seriesAngularMin + ad * 16, y: seriesRadialMin + rd * 3);
330 m_series6->append(x: seriesAngularMin + ad * 15, y: seriesRadialMin + rd * 1);
331 m_series6->append(x: seriesAngularMin + ad * 14, y: seriesRadialMin + rd * 7);
332 m_series6->append(x: seriesAngularMin + ad * 13, y: seriesRadialMin + rd * 5);
333 m_series6->append(x: seriesAngularMin + ad * 12, y: seriesRadialMin + rd * 9);
334 m_series6->append(x: seriesAngularMin + ad * 11, y: seriesRadialMin + rd * 1);
335 m_series6->append(x: seriesAngularMin + ad * 10, y: seriesRadialMin + rd * 4);
336 m_series6->append(x: seriesAngularMin + ad * 9, y: seriesRadialMin + rd * 1);
337 m_series6->append(x: seriesAngularMin + ad * 8, y: seriesRadialMin + rd * 2);
338 m_series6->append(x: seriesAngularMin + ad * 7, y: seriesRadialMin + rd * 4);
339 m_series6->append(x: seriesAngularMin + ad * 6, y: seriesRadialMin + rd * 8);
340 m_series6->append(x: seriesAngularMin + ad * 5, y: seriesRadialMin + rd * 12);
341 m_series6->append(x: seriesAngularMin + ad * 4, y: seriesRadialMin + rd * 9);
342 m_series6->append(x: seriesAngularMin + ad * 3, y: seriesRadialMin + rd * 8);
343 m_series6->append(x: seriesAngularMin + ad * 2, y: seriesRadialMin + rd * 7);
344 m_series6->append(x: seriesAngularMin + ad, y: seriesRadialMin + rd * 4);
345 m_series6->append(x: seriesAngularMin, y: seriesRadialMin + rd * 10);
346
347 m_series6->setPointsVisible(true);
348 QPen series6Pen = QPen(Qt::red, 10);
349 //series6Pen.setStyle(Qt::DashDotDotLine);
350 m_series6->setPen(series6Pen);
351
352 // m_series7 shows points at category intersections
353 m_series7 = new QScatterSeries();
354 m_series7->setName("Category check");
355 m_series7->setMarkerSize(7);
356 m_series7->setBrush(QColor(Qt::red));
357 m_series7->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
358 *m_series7 << QPointF(1000, 1000)
359 << QPointF(1000, 2000)
360 << QPointF(1000, 4000)
361 << QPointF(1000, 9000)
362 << QPointF(1000, 14000)
363 << QPointF(1000, 16500)
364 << QPointF(1000, 19000)
365
366 << QPointF(4000, 1000)
367 << QPointF(4000, 2000)
368 << QPointF(4000, 4000)
369 << QPointF(4000, 9000)
370 << QPointF(4000, 14000)
371 << QPointF(4000, 16500)
372 << QPointF(4000, 19000)
373
374 << QPointF(7000, 1000)
375 << QPointF(7000, 2000)
376 << QPointF(7000, 4000)
377 << QPointF(7000, 9000)
378 << QPointF(7000, 14000)
379 << QPointF(7000, 16500)
380 << QPointF(7000, 19000)
381
382 << QPointF(12000, 1000)
383 << QPointF(12000, 2000)
384 << QPointF(12000, 4000)
385 << QPointF(12000, 9000)
386 << QPointF(12000, 14000)
387 << QPointF(12000, 16500)
388 << QPointF(12000, 19000)
389
390 << QPointF(17000, 1000)
391 << QPointF(17000, 2000)
392 << QPointF(17000, 4000)
393 << QPointF(17000, 9000)
394 << QPointF(17000, 14000)
395 << QPointF(17000, 16500)
396 << QPointF(17000, 19000)
397
398 << QPointF(22000, 1000)
399 << QPointF(22000, 2000)
400 << QPointF(22000, 4000)
401 << QPointF(22000, 9000)
402 << QPointF(22000, 14000)
403 << QPointF(22000, 16500)
404 << QPointF(22000, 19000)
405
406 << QPointF(28000, 1000)
407 << QPointF(28000, 2000)
408 << QPointF(28000, 4000)
409 << QPointF(28000, 9000)
410 << QPointF(28000, 14000)
411 << QPointF(28000, 16500)
412 << QPointF(28000, 19000);
413
414 m_chart = new QPolarChart();
415
416 m_chart->addSeries(series: m_series1);
417 m_chart->addSeries(series: m_series2);
418 m_chart->addSeries(series: m_series3);
419 m_chart->addSeries(series: m_series4);
420 m_chart->addSeries(series: m_series5);
421 m_chart->addSeries(series: m_series6);
422 m_chart->addSeries(series: m_series7);
423
424 connect(sender: m_series1, SIGNAL(clicked(QPointF)), receiver: this, SLOT(seriesClicked(QPointF)));
425 connect(sender: m_series2, SIGNAL(clicked(QPointF)), receiver: this, SLOT(seriesClicked(QPointF)));
426 connect(sender: m_series3, SIGNAL(clicked(QPointF)), receiver: this, SLOT(seriesClicked(QPointF)));
427 connect(sender: m_series4, SIGNAL(clicked(QPointF)), receiver: this, SLOT(seriesClicked(QPointF)));
428 connect(sender: m_series5, SIGNAL(clicked(QPointF)), receiver: this, SLOT(seriesClicked(QPointF)));
429 connect(sender: m_series6, SIGNAL(clicked(QPointF)), receiver: this, SLOT(seriesClicked(QPointF)));
430 connect(sender: m_series7, SIGNAL(clicked(QPointF)), receiver: this, SLOT(seriesClicked(QPointF)));
431 connect(sender: m_series1, SIGNAL(hovered(QPointF, bool)), receiver: this, SLOT(seriesHovered(QPointF, bool)));
432 connect(sender: m_series2, SIGNAL(hovered(QPointF, bool)), receiver: this, SLOT(seriesHovered(QPointF, bool)));
433 connect(sender: m_series3, SIGNAL(hovered(QPointF, bool)), receiver: this, SLOT(seriesHovered(QPointF, bool)));
434 connect(sender: m_series4, SIGNAL(hovered(QPointF, bool)), receiver: this, SLOT(seriesHovered(QPointF, bool)));
435 connect(sender: m_series5, SIGNAL(hovered(QPointF, bool)), receiver: this, SLOT(seriesHovered(QPointF, bool)));
436 connect(sender: m_series6, SIGNAL(hovered(QPointF, bool)), receiver: this, SLOT(seriesHovered(QPointF, bool)));
437 connect(sender: m_series7, SIGNAL(hovered(QPointF, bool)), receiver: this, SLOT(seriesHovered(QPointF, bool)));
438
439 m_chart->setTitle("Use arrow keys to scroll and +/- to zoom");
440 m_chart->setAnimationOptions(m_animationOptions);
441 //m_chart->legend()->setVisible(false);
442 m_chart->setAcceptHoverEvents(true);
443 m_chart->setBackgroundBrush(*m_backgroundBrush);
444 m_chart->setBackgroundPen(*m_backgroundPen);
445 m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush);
446 m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen);
447}
448
449void MainWindow::setAngularAxis(MainWindow::AxisMode mode)
450{
451 if (m_angularAxis) {
452 m_chart->removeAxis(axis: m_angularAxis);
453 delete m_angularAxis;
454 m_angularAxis = 0;
455 }
456
457 m_angularAxisMode = mode;
458
459 switch (m_angularAxisMode) {
460 case AxisModeNone:
461 return;
462 case AxisModeValue:
463 m_angularAxis = new QValueAxis();
464 static_cast<QValueAxis *>(m_angularAxis)->setTickCount(m_angularTickCount);
465 static_cast<QValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat);
466 break;
467 case AxisModeLogValue:
468 m_angularAxis = new QLogValueAxis();
469 static_cast<QLogValueAxis *>(m_angularAxis)->setBase(m_base);
470 static_cast<QLogValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat);
471 break;
472 case AxisModeDateTime:
473 m_angularAxis = new QDateTimeAxis();
474 static_cast<QDateTimeAxis *>(m_angularAxis)->setTickCount(m_angularTickCount);
475 static_cast<QDateTimeAxis *>(m_angularAxis)->setFormat(m_dateFormat);
476 break;
477 case AxisModeCategory:
478 m_angularAxis = new QCategoryAxis();
479 applyCategories();
480 break;
481 default:
482 qWarning() << "Unsupported AxisMode";
483 break;
484 }
485
486 m_angularAxis->setLabelsAngle(m_labelsAngle);
487 m_angularAxis->setLabelsFont(m_currentLabelFont);
488 m_angularAxis->setLabelsBrush(*m_labelBrush);
489 m_angularAxis->setLabelsVisible(m_labelsVisible);
490 m_angularAxis->setShadesBrush(*m_angularShadesBrush);
491 m_angularAxis->setShadesPen(*m_angularShadesPen);
492 m_angularAxis->setShadesVisible(m_angularShadesVisible);
493 m_angularAxis->setTitleFont(m_currentTitleFont);
494 m_angularAxis->setTitleBrush(*m_titleBrush);
495 m_angularAxis->setTitleVisible(m_titleVisible);
496 m_angularAxis->setTitleText(m_angularTitle);
497 m_angularAxis->setGridLinePen(*m_gridPen);
498 m_angularAxis->setGridLineVisible(m_gridVisible);
499 m_angularAxis->setLinePen(*m_arrowPen);
500 m_angularAxis->setLineVisible(m_arrowVisible);
501 m_angularAxis->setMinorGridLinePen(*m_minorGridPen);
502 m_angularAxis->setMinorGridLineVisible(m_minorGridVisible);
503
504 m_chart->addAxis(axis: m_angularAxis, polarOrientation: QPolarChart::PolarOrientationAngular);
505
506 m_series1->attachAxis(axis: m_angularAxis);
507 m_series2->attachAxis(axis: m_angularAxis);
508 m_series3->attachAxis(axis: m_angularAxis);
509 m_series4->attachAxis(axis: m_angularAxis);
510 m_series5->attachAxis(axis: m_angularAxis);
511 m_series6->attachAxis(axis: m_angularAxis);
512 m_series7->attachAxis(axis: m_angularAxis);
513
514 applyRanges();
515
516 //connect(m_angularAxis, SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(angularRangeChanged(qreal, qreal)));
517}
518
519void MainWindow::setRadialAxis(MainWindow::AxisMode mode)
520{
521 if (m_radialAxis) {
522 m_chart->removeAxis(axis: m_radialAxis);
523 delete m_radialAxis;
524 m_radialAxis = 0;
525 }
526
527 m_radialAxisMode = mode;
528
529 switch (m_radialAxisMode) {
530 case AxisModeNone:
531 return;
532 case AxisModeValue:
533 m_radialAxis = new QValueAxis();
534 static_cast<QValueAxis *>(m_radialAxis)->setTickCount(m_radialTickCount);
535 static_cast<QValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat);
536 break;
537 case AxisModeLogValue:
538 m_radialAxis = new QLogValueAxis();
539 static_cast<QLogValueAxis *>(m_radialAxis)->setBase(m_base);
540 static_cast<QLogValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat);
541 break;
542 case AxisModeDateTime:
543 m_radialAxis = new QDateTimeAxis();
544 static_cast<QDateTimeAxis *>(m_radialAxis)->setTickCount(m_radialTickCount);
545 static_cast<QDateTimeAxis *>(m_radialAxis)->setFormat(m_dateFormat);
546 break;
547 case AxisModeCategory:
548 m_radialAxis = new QCategoryAxis();
549 applyCategories();
550 break;
551 default:
552 qWarning() << "Unsupported AxisMode";
553 break;
554 }
555
556 m_radialAxis->setLabelsAngle(m_labelsAngle);
557 m_radialAxis->setLabelsFont(m_currentLabelFont);
558 m_radialAxis->setLabelsBrush(*m_labelBrush);
559 m_radialAxis->setLabelsVisible(m_labelsVisible);
560 m_radialAxis->setShadesBrush(*m_radialShadesBrush);
561 m_radialAxis->setShadesPen(*m_radialShadesPen);
562 m_radialAxis->setShadesVisible(m_radialShadesVisible);
563 m_radialAxis->setTitleFont(m_currentTitleFont);
564 m_radialAxis->setTitleBrush(*m_titleBrush);
565 m_radialAxis->setTitleVisible(m_titleVisible);
566 m_radialAxis->setTitleText(m_radialTitle);
567 m_radialAxis->setGridLinePen(*m_gridPen);
568 m_radialAxis->setGridLineVisible(m_gridVisible);
569 m_radialAxis->setLinePen(*m_arrowPen);
570 m_radialAxis->setLineVisible(m_arrowVisible);
571 m_radialAxis->setMinorGridLinePen(*m_minorGridPen);
572 m_radialAxis->setMinorGridLineVisible(m_minorGridVisible);
573
574 m_chart->addAxis(axis: m_radialAxis, polarOrientation: QPolarChart::PolarOrientationRadial);
575
576 m_series1->attachAxis(axis: m_radialAxis);
577 m_series2->attachAxis(axis: m_radialAxis);
578 m_series3->attachAxis(axis: m_radialAxis);
579 m_series4->attachAxis(axis: m_radialAxis);
580 m_series5->attachAxis(axis: m_radialAxis);
581 m_series6->attachAxis(axis: m_radialAxis);
582 m_series7->attachAxis(axis: m_radialAxis);
583
584 applyRanges();
585
586 series1CheckBoxChecked();
587 series2CheckBoxChecked();
588 series3CheckBoxChecked();
589 series4CheckBoxChecked();
590 series5CheckBoxChecked();
591 series6CheckBoxChecked();
592 series7CheckBoxChecked();
593
594 //connect(m_radialAxis, SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(radialRangeChanged(qreal, qreal)));
595}
596
597void MainWindow::applyRanges()
598{
599 if (ui->niceNumbersCheckBox->isChecked()) {
600 if (m_angularAxisMode == AxisModeValue) {
601 static_cast<QValueAxis *>(m_angularAxis)->applyNiceNumbers();
602 m_angularMin = static_cast<QValueAxis *>(m_angularAxis)->min();
603 m_angularMax = static_cast<QValueAxis *>(m_angularAxis)->max();
604 m_angularTickCount = static_cast<QValueAxis *>(m_angularAxis)->tickCount();
605 }
606 if (m_radialAxisMode == AxisModeValue) {
607 static_cast<QValueAxis *>(m_radialAxis)->applyNiceNumbers();
608 m_radialMin = static_cast<QValueAxis *>(m_radialAxis)->min();
609 m_radialMax = static_cast<QValueAxis *>(m_radialAxis)->max();
610 m_radialTickCount = static_cast<QValueAxis *>(m_radialAxis)->tickCount();
611 }
612 }
613
614 if (m_angularAxis)
615 m_angularAxis->setRange(min: m_angularMin, max: m_angularMax);
616 if (m_radialAxis)
617 m_radialAxis->setRange(min: m_radialMin, max: m_radialMax);
618}
619
620void MainWindow::angularTicksChanged(int value)
621{
622 m_angularTickCount = value;
623 if (m_angularAxisMode == AxisModeValue)
624 static_cast<QValueAxis *>(m_angularAxis)->setTickCount(m_angularTickCount);
625 else if (m_angularAxisMode == AxisModeDateTime)
626 static_cast<QDateTimeAxis *>(m_angularAxis)->setTickCount(m_angularTickCount);
627}
628
629void MainWindow::radialTicksChanged(int value)
630{
631 m_radialTickCount = value;
632 if (m_radialAxisMode == AxisModeValue)
633 static_cast<QValueAxis *>(m_radialAxis)->setTickCount(m_radialTickCount);
634 else if (m_radialAxisMode == AxisModeDateTime)
635 static_cast<QDateTimeAxis *>(m_radialAxis)->setTickCount(m_radialTickCount);
636}
637
638void MainWindow::angularMinorTicksChanged(int value)
639{
640 // Minor tick valid only for QValueAxis
641 m_angularMinorTickCount = value;
642 if (m_angularAxisMode == AxisModeValue)
643 static_cast<QValueAxis *>(m_angularAxis)->setMinorTickCount(m_angularMinorTickCount);
644}
645
646void MainWindow::radialMinorTicksChanged(int value)
647{
648 // Minor tick valid only for QValueAxis
649 m_radialMinorTickCount = value;
650 if (m_radialAxisMode == AxisModeValue)
651 static_cast<QValueAxis *>(m_radialAxis)->setMinorTickCount(m_radialMinorTickCount);
652}
653
654void MainWindow::anglesChanged(int value)
655{
656 m_labelsAngle = value;
657 m_radialAxis->setLabelsAngle(m_labelsAngle);
658 m_angularAxis->setLabelsAngle(m_labelsAngle);
659}
660
661void MainWindow::angularMinChanged(double value)
662{
663 m_angularMin = value;
664 if (m_angularAxisMode != AxisModeDateTime) {
665 m_angularAxis->setMin(m_angularMin);
666 } else {
667 QDateTime dateTime;
668 dateTime.setMSecsSinceEpoch(qint64(m_angularMin));
669 m_angularAxis->setMin(dateTime);
670 }
671}
672
673void MainWindow::angularMaxChanged(double value)
674{
675 m_angularMax = value;
676 if (m_angularAxisMode != AxisModeDateTime) {
677 m_angularAxis->setMax(m_angularMax);
678 } else {
679 QDateTime dateTime;
680 dateTime.setMSecsSinceEpoch(qint64(m_angularMax));
681 m_angularAxis->setMax(dateTime);
682 }
683}
684
685void MainWindow::radialMinChanged(double value)
686{
687 m_radialMin = value;
688 if (m_radialAxisMode != AxisModeDateTime) {
689 m_radialAxis->setMin(m_radialMin);
690 } else {
691 QDateTime dateTime;
692 dateTime.setMSecsSinceEpoch(qint64(m_radialMin));
693 m_radialAxis->setMin(dateTime);
694 }
695}
696
697void MainWindow::radialMaxChanged(double value)
698{
699 m_radialMax = value;
700 if (m_radialAxisMode != AxisModeDateTime) {
701 m_radialAxis->setMax(m_radialMax);
702 } else {
703 QDateTime dateTime;
704 dateTime.setMSecsSinceEpoch(qint64(m_radialMax));
705 m_radialAxis->setMax(dateTime);
706 }
707}
708
709void MainWindow::angularShadesIndexChanged(int index)
710{
711 delete m_angularShadesBrush;
712 delete m_angularShadesPen;
713
714 switch (index) {
715 case 0:
716 m_angularShadesBrush = new QBrush(Qt::NoBrush);
717 m_angularShadesPen = new QPen(Qt::NoPen);
718 m_angularShadesVisible = false;
719 break;
720 case 1:
721 m_angularShadesBrush = new QBrush(Qt::lightGray);
722 m_angularShadesPen = new QPen(Qt::NoPen);
723 m_angularShadesVisible = true;
724 break;
725 case 2:
726 m_angularShadesBrush = new QBrush(Qt::yellow);
727 m_angularShadesPen = new QPen(Qt::DotLine);
728 m_angularShadesPen->setWidth(2);
729 m_angularShadesVisible = true;
730 break;
731 default:
732 break;
733 }
734
735 m_angularAxis->setShadesBrush(*m_angularShadesBrush);
736 m_angularAxis->setShadesPen(*m_angularShadesPen);
737 m_angularAxis->setShadesVisible(m_angularShadesVisible);
738}
739
740void MainWindow::radialShadesIndexChanged(int index)
741{
742 delete m_radialShadesBrush;
743 delete m_radialShadesPen;
744
745 switch (index) {
746 case 0:
747 m_radialShadesBrush = new QBrush(Qt::NoBrush);
748 m_radialShadesPen = new QPen(Qt::NoPen);
749 m_radialShadesVisible = false;
750 break;
751 case 1:
752 m_radialShadesBrush = new QBrush(Qt::green);
753 m_radialShadesPen = new QPen(Qt::NoPen);
754 m_radialShadesVisible = true;
755 break;
756 case 2:
757 m_radialShadesBrush = new QBrush(Qt::blue);
758 m_radialShadesPen = new QPen(Qt::DotLine);
759 m_radialShadesPen->setWidth(2);
760 m_radialShadesVisible = true;
761 break;
762 default:
763 break;
764 }
765
766 m_radialAxis->setShadesBrush(*m_radialShadesBrush);
767 m_radialAxis->setShadesPen(*m_radialShadesPen);
768 m_radialAxis->setShadesVisible(m_radialShadesVisible);
769}
770
771void MainWindow::labelFormatEdited(const QString &text)
772{
773 m_labelFormat = text;
774 if (m_angularAxisMode == AxisModeValue)
775 static_cast<QValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat);
776 else if (m_angularAxisMode == AxisModeLogValue)
777 static_cast<QLogValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat);
778
779 if (m_radialAxisMode == AxisModeValue)
780 static_cast<QValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat);
781 else if (m_radialAxisMode == AxisModeLogValue)
782 static_cast<QLogValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat);
783}
784
785void MainWindow::labelFontChanged(const QFont &font)
786{
787 m_currentLabelFont = font;
788 m_currentLabelFont.setPixelSize(ui->labelFontSizeSpin->value());
789 m_angularAxis->setLabelsFont(m_currentLabelFont);
790 m_radialAxis->setLabelsFont(m_currentLabelFont);
791}
792
793void MainWindow::labelFontSizeChanged(int value)
794{
795 m_currentLabelFont = ui->labelFontComboBox->currentFont();
796 m_currentLabelFont.setPixelSize(value);
797 m_angularAxis->setLabelsFont(m_currentLabelFont);
798 m_radialAxis->setLabelsFont(m_currentLabelFont);
799}
800
801void MainWindow::animationIndexChanged(int index)
802{
803 switch (index) {
804 case 0:
805 m_animationOptions = QChart::NoAnimation;
806 break;
807 case 1:
808 m_animationOptions = QChart::SeriesAnimations;
809 break;
810 case 2:
811 m_animationOptions = QChart::GridAxisAnimations;
812 break;
813 case 3:
814 m_animationOptions = QChart::AllAnimations;
815 break;
816 default:
817 break;
818 }
819
820 m_chart->setAnimationOptions(m_animationOptions);
821}
822
823void MainWindow::labelsIndexChanged(int index)
824{
825 delete m_labelBrush;
826
827 switch (index) {
828 case 0:
829 m_labelBrush = new QBrush(Qt::NoBrush);
830 m_labelsVisible = false;
831 break;
832 case 1:
833 m_labelBrush = new QBrush(Qt::black);
834 m_labelsVisible = true;
835 break;
836 case 2:
837 m_labelBrush = new QBrush(Qt::white);
838 m_labelsVisible = true;
839 break;
840 default:
841 break;
842 }
843
844 m_radialAxis->setLabelsBrush(*m_labelBrush);
845 m_radialAxis->setLabelsVisible(m_labelsVisible);
846 m_angularAxis->setLabelsBrush(*m_labelBrush);
847 m_angularAxis->setLabelsVisible(m_labelsVisible);
848}
849
850void MainWindow::titleIndexChanged(int index)
851{
852 delete m_titleBrush;
853
854 switch (index) {
855 case 0:
856 m_titleBrush = new QBrush(Qt::NoBrush);
857 m_titleVisible = false;
858 m_angularTitle = QString();
859 m_radialTitle = QString();
860 break;
861 case 1:
862 m_titleBrush = new QBrush(Qt::NoBrush);
863 m_titleVisible = true;
864 m_angularTitle = QString();
865 m_radialTitle = QString();
866 break;
867 case 2:
868 m_titleBrush = new QBrush(Qt::NoBrush);
869 m_titleVisible = false;
870 m_angularTitle = QString("Invisible Ang. Title!");
871 m_radialTitle = QString("Invisible Rad. Title!");
872 break;
873 case 3:
874 m_titleBrush = new QBrush(Qt::black);
875 m_titleVisible = true;
876 m_angularTitle = QString("Angular Title");
877 m_radialTitle = QString("Radial Title");
878 break;
879 case 4:
880 m_titleBrush = new QBrush(Qt::white);
881 m_titleVisible = true;
882 m_angularTitle = QString("Angular Blue Title");
883 m_radialTitle = QString("Radial Blue Title");
884 break;
885 default:
886 break;
887 }
888
889 m_radialAxis->setTitleBrush(*m_titleBrush);
890 m_radialAxis->setTitleVisible(m_titleVisible);
891 m_radialAxis->setTitleText(m_radialTitle);
892 m_angularAxis->setTitleBrush(*m_titleBrush);
893 m_angularAxis->setTitleVisible(m_titleVisible);
894 m_angularAxis->setTitleText(m_angularTitle);
895}
896
897void MainWindow::titleFontChanged(const QFont &font)
898{
899 m_currentTitleFont = font;
900 m_currentTitleFont.setPixelSize(ui->titleFontSizeSpin->value());
901 m_angularAxis->setTitleFont(m_currentTitleFont);
902 m_radialAxis->setTitleFont(m_currentTitleFont);
903}
904
905void MainWindow::titleFontSizeChanged(int value)
906{
907 m_currentTitleFont = ui->titleFontComboBox->currentFont();
908 m_currentTitleFont.setPixelSize(value);
909 m_angularAxis->setTitleFont(m_currentTitleFont);
910 m_radialAxis->setTitleFont(m_currentTitleFont);
911}
912
913void MainWindow::gridIndexChanged(int index)
914{
915 delete m_gridPen;
916
917 switch (index) {
918 case 0:
919 m_gridPen = new QPen(Qt::NoPen);
920 m_gridVisible = false;
921 break;
922 case 1:
923 m_gridPen = new QPen(Qt::black);
924 m_gridVisible = true;
925 break;
926 case 2:
927 m_gridPen = new QPen(Qt::red);
928 m_gridPen->setStyle(Qt::DashDotLine);
929 m_gridPen->setWidth(3);
930 m_gridVisible = true;
931 break;
932 default:
933 break;
934 }
935
936 m_angularAxis->setGridLinePen(*m_gridPen);
937 m_angularAxis->setGridLineVisible(m_gridVisible);
938 m_radialAxis->setGridLinePen(*m_gridPen);
939 m_radialAxis->setGridLineVisible(m_gridVisible);
940}
941
942void MainWindow::minorGridIndexChanged(int index)
943{
944 delete m_minorGridPen;
945
946 switch (index) {
947 case 0:
948 m_minorGridPen = new QPen(Qt::NoPen);
949 m_minorGridVisible = false;
950 break;
951 case 1:
952 m_minorGridPen = new QPen(Qt::black);
953 m_minorGridPen->setStyle(Qt::DashLine);
954 m_minorGridVisible = true;
955 break;
956 case 2:
957 m_minorGridPen = new QPen(Qt::green);
958 m_minorGridPen->setStyle(Qt::DotLine);
959 m_minorGridPen->setWidth(1);
960 m_minorGridVisible = true;
961 break;
962 default:
963 break;
964 }
965
966 m_angularAxis->setMinorGridLinePen(*m_minorGridPen);
967 m_angularAxis->setMinorGridLineVisible(m_minorGridVisible);
968 m_radialAxis->setMinorGridLinePen(*m_minorGridPen);
969 m_radialAxis->setMinorGridLineVisible(m_minorGridVisible);
970}
971
972void MainWindow::gridLineColorIndexChanged(int index)
973{
974 QColor color;
975 switch (index) {
976 case 0:
977 color = Qt::black;
978 break;
979 case 1:
980 color = Qt::green;
981 break;
982 case 2:
983 color = Qt::red;
984 break;
985 default:
986 break;
987 }
988
989 m_angularAxis->setGridLineColor(color);
990 m_radialAxis->setGridLineColor(color);
991 m_angularAxis->setMinorGridLineColor(color);
992 m_radialAxis->setMinorGridLineColor(color);
993}
994
995void MainWindow::arrowIndexChanged(int index)
996{
997 delete m_arrowPen;
998
999 switch (index) {
1000 case 0:
1001 m_arrowPen = new QPen(Qt::NoPen);
1002 m_arrowVisible = false;
1003 break;
1004 case 1:
1005 m_arrowPen = new QPen(Qt::black);
1006 m_arrowVisible = true;
1007 break;
1008 case 2:
1009 m_arrowPen = new QPen(Qt::red);
1010 m_arrowPen->setStyle(Qt::DashDotLine);
1011 m_arrowPen->setWidth(3);
1012 m_arrowVisible = true;
1013 break;
1014 default:
1015 break;
1016 }
1017
1018 m_angularAxis->setLinePen(*m_arrowPen);
1019 m_angularAxis->setLineVisible(m_arrowVisible);
1020 m_radialAxis->setLinePen(*m_arrowPen);
1021 m_radialAxis->setLineVisible(m_arrowVisible);
1022}
1023
1024void MainWindow::angularRangeChanged(qreal min, qreal max)
1025{
1026 if (!qFuzzyCompare(p1: qreal(ui->angularMinSpin->value()), p2: min))
1027 ui->angularMinSpin->setValue(min);
1028 if (!qFuzzyCompare(p1: qreal(ui->angularMaxSpin->value()), p2: max))
1029 ui->angularMaxSpin->setValue(max);
1030}
1031
1032void MainWindow::radialRangeChanged(qreal min, qreal max)
1033{
1034 if (!qFuzzyCompare(p1: qreal(ui->radialMinSpin->value()), p2: min))
1035 ui->radialMinSpin->setValue(min);
1036 if (!qFuzzyCompare(p1: qreal(ui->radialMaxSpin->value()), p2: max))
1037 ui->radialMaxSpin->setValue(max);
1038}
1039
1040void MainWindow::angularAxisIndexChanged(int index)
1041{
1042 switch (index) {
1043 case 0:
1044 setAngularAxis(AxisModeNone);
1045 break;
1046 case 1:
1047 setAngularAxis(AxisModeValue);
1048 angularMinorTicksChanged(value: ui->angularMinorTicksSpin->value());
1049 break;
1050 case 2:
1051 setAngularAxis(AxisModeLogValue);
1052 break;
1053 case 3:
1054 setAngularAxis(AxisModeDateTime);
1055 break;
1056 case 4:
1057 setAngularAxis(AxisModeCategory);
1058 break;
1059 default:
1060 qWarning(msg: "Invalid Index!");
1061 }
1062}
1063
1064void MainWindow::radialAxisIndexChanged(int index)
1065{
1066 switch (index) {
1067 case 0:
1068 setRadialAxis(AxisModeNone);
1069 break;
1070 case 1:
1071 setRadialAxis(AxisModeValue);
1072 radialMinorTicksChanged(value: ui->radialMinorTicksSpin->value());
1073 break;
1074 case 2:
1075 setRadialAxis(AxisModeLogValue);
1076 break;
1077 case 3:
1078 setRadialAxis(AxisModeDateTime);
1079 break;
1080 case 4:
1081 setRadialAxis(AxisModeCategory);
1082 break;
1083 default:
1084 qWarning(msg: "Invalid Index!");
1085 }
1086}
1087
1088void MainWindow::logBaseChanged(double value)
1089{
1090 m_base = value;
1091 if (m_angularAxisMode == AxisModeLogValue)
1092 static_cast<QLogValueAxis *>(m_angularAxis)->setBase(m_base);
1093 if (m_radialAxisMode == AxisModeLogValue)
1094 static_cast<QLogValueAxis *>(m_radialAxis)->setBase(m_base);
1095}
1096
1097void MainWindow::niceNumbersChecked()
1098{
1099 if (ui->niceNumbersCheckBox->isChecked())
1100 applyRanges();
1101}
1102
1103void MainWindow::dateFormatEdited(const QString &text)
1104{
1105 m_dateFormat = text;
1106 if (m_angularAxisMode == AxisModeDateTime)
1107 static_cast<QDateTimeAxis *>(m_angularAxis)->setFormat(m_dateFormat);
1108 if (m_radialAxisMode == AxisModeDateTime)
1109 static_cast<QDateTimeAxis *>(m_radialAxis)->setFormat(m_dateFormat);
1110}
1111
1112void MainWindow::moreCategoriesChecked()
1113{
1114 applyCategories();
1115 m_moreCategories = ui->moreCategoriesCheckBox->isChecked();
1116}
1117
1118void MainWindow::categoryLabelLocationChecked()
1119{
1120 applyCategories();
1121}
1122
1123void MainWindow::series1CheckBoxChecked()
1124{
1125 if (ui->series1checkBox->isChecked())
1126 m_series1->setVisible(true);
1127 else
1128 m_series1->setVisible(false);
1129}
1130
1131void MainWindow::series2CheckBoxChecked()
1132{
1133 if (ui->series2checkBox->isChecked())
1134 m_series2->setVisible(true);
1135 else
1136 m_series2->setVisible(false);
1137}
1138
1139void MainWindow::series3CheckBoxChecked()
1140{
1141 if (ui->series3checkBox->isChecked())
1142 m_series3->setVisible(true);
1143 else
1144 m_series3->setVisible(false);
1145}
1146
1147void MainWindow::series4CheckBoxChecked()
1148{
1149 if (ui->series4checkBox->isChecked())
1150 m_series4->setVisible(true);
1151 else
1152 m_series4->setVisible(false);
1153}
1154
1155void MainWindow::series5CheckBoxChecked()
1156{
1157 if (ui->series5checkBox->isChecked())
1158 m_series5->setVisible(true);
1159 else
1160 m_series5->setVisible(false);
1161}
1162
1163void MainWindow::series6CheckBoxChecked()
1164{
1165 if (ui->series6checkBox->isChecked())
1166 m_series6->setVisible(true);
1167 else
1168 m_series6->setVisible(false);
1169}
1170
1171void MainWindow::series7CheckBoxChecked()
1172{
1173 if (ui->series7checkBox->isChecked())
1174 m_series7->setVisible(true);
1175 else
1176 m_series7->setVisible(false);
1177}
1178
1179void MainWindow::themeIndexChanged(int index)
1180{
1181 m_chart->setTheme(QChart::ChartTheme(index));
1182}
1183
1184void MainWindow::seriesHovered(QPointF point, bool state)
1185{
1186 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(object: sender());
1187 if (series) {
1188 if (state) {
1189 QString str("'%3' - %1 x %2");
1190 ui->hoverLabel->setText(str.arg(a: point.x()).arg(a: point.y()).arg(a: series->name()));
1191 } else {
1192 ui->hoverLabel->setText("No hover");
1193 }
1194 } else {
1195 qDebug() << "seriesHovered - invalid sender!";
1196 }
1197}
1198
1199void MainWindow::seriesClicked(const QPointF &point)
1200{
1201 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(object: sender());
1202 if (series) {
1203 QString str("'%3' clicked at: %1 x %2");
1204 m_angularTitle = str.arg(a: point.x()).arg(a: point.y()).arg(a: series->name());
1205 m_angularAxis->setTitleText(m_angularTitle);
1206 } else {
1207 qDebug() << "seriesClicked - invalid sender!";
1208 }
1209}
1210
1211void MainWindow::backgroundIndexChanged(int index)
1212{
1213 delete m_backgroundBrush;
1214 delete m_backgroundPen;
1215
1216 switch (index) {
1217 case 0:
1218 m_backgroundBrush = new QBrush(Qt::white);
1219 m_backgroundPen = new QPen(Qt::NoPen);
1220 break;
1221 case 1:
1222 m_backgroundBrush = new QBrush(Qt::blue);
1223 m_backgroundPen = new QPen(Qt::NoPen);
1224 break;
1225 case 2:
1226 m_backgroundBrush = new QBrush(Qt::yellow);
1227 m_backgroundPen = new QPen(Qt::black, 2);
1228 break;
1229 default:
1230 break;
1231 }
1232 m_chart->setBackgroundBrush(*m_backgroundBrush);
1233 m_chart->setBackgroundPen(*m_backgroundPen);
1234}
1235
1236void MainWindow::plotAreaIndexChanged(int index)
1237{
1238 delete m_plotAreaBackgroundBrush;
1239 delete m_plotAreaBackgroundPen;
1240
1241 switch (index) {
1242 case 0:
1243 m_plotAreaBackgroundBrush = new QBrush(Qt::green);
1244 m_plotAreaBackgroundPen = new QPen(Qt::green);
1245 m_chart->setPlotAreaBackgroundVisible(false);
1246 break;
1247 case 1:
1248 m_plotAreaBackgroundBrush = new QBrush(Qt::magenta);
1249 m_plotAreaBackgroundPen = new QPen(Qt::NoPen);
1250 m_chart->setPlotAreaBackgroundVisible(true);
1251 break;
1252 case 2:
1253 m_plotAreaBackgroundBrush = new QBrush(Qt::lightGray);
1254 m_plotAreaBackgroundPen = new QPen(Qt::red, 6);
1255 m_chart->setPlotAreaBackgroundVisible(true);
1256 break;
1257 default:
1258 break;
1259 }
1260 m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush);
1261 m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen);
1262}
1263
1264void MainWindow::applyCategories()
1265{
1266 // Basic layout is three categories, extended has five
1267 if (m_angularAxisMode == AxisModeCategory) {
1268 QCategoryAxis *angCatAxis = static_cast<QCategoryAxis *>(m_angularAxis);
1269 if (angCatAxis->count() == 0) {
1270 angCatAxis->setStartValue(4000);
1271 angCatAxis->append(label: "Category A", categoryEndValue: 7000);
1272 angCatAxis->append(label: "Category B", categoryEndValue: 12000);
1273 angCatAxis->append(label: "Category C", categoryEndValue: 17000);
1274 }
1275 if (angCatAxis->count() == 3 && ui->moreCategoriesCheckBox->isChecked()) {
1276 angCatAxis->setStartValue(1000);
1277 angCatAxis->replaceLabel(oldLabel: "Category A", newLabel: "Cat A");
1278 angCatAxis->replaceLabel(oldLabel: "Category B", newLabel: "Cat B");
1279 angCatAxis->replaceLabel(oldLabel: "Category C", newLabel: "Cat C");
1280 angCatAxis->append(label: "Cat D", categoryEndValue: 22000);
1281 angCatAxis->append(label: "Cat E", categoryEndValue: 28000);
1282 } else if (angCatAxis->count() == 5 && !ui->moreCategoriesCheckBox->isChecked()) {
1283 angCatAxis->setStartValue(4000);
1284 angCatAxis->replaceLabel(oldLabel: "Cat A", newLabel: "Category A");
1285 angCatAxis->replaceLabel(oldLabel: "Cat B", newLabel: "Category B");
1286 angCatAxis->replaceLabel(oldLabel: "Cat C", newLabel: "Category C");
1287 angCatAxis->remove(label: "Cat D");
1288 angCatAxis->remove(label: "Cat E");
1289 }
1290 if (ui->categoryLabelLocationCheckBox->isChecked())
1291 angCatAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
1292 else
1293 angCatAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionCenter);
1294 }
1295
1296 if (m_radialAxisMode == AxisModeCategory) {
1297 QCategoryAxis *radCatAxis = static_cast<QCategoryAxis *>(m_radialAxis);
1298 if (radCatAxis->count() == 0) {
1299 radCatAxis->setStartValue(2000);
1300 radCatAxis->append(label: "Category 1", categoryEndValue: 4000);
1301 radCatAxis->append(label: "Category 2", categoryEndValue: 9000);
1302 radCatAxis->append(label: "Category 3", categoryEndValue: 14000);
1303 }
1304 if (radCatAxis->count() == 3 && ui->moreCategoriesCheckBox->isChecked()) {
1305 radCatAxis->setStartValue(1000);
1306 radCatAxis->replaceLabel(oldLabel: "Category 1", newLabel: "Cat 1");
1307 radCatAxis->replaceLabel(oldLabel: "Category 2", newLabel: "Cat 2");
1308 radCatAxis->replaceLabel(oldLabel: "Category 3", newLabel: "Cat 3");
1309 radCatAxis->append(label: "Cat 4", categoryEndValue: 16500);
1310 radCatAxis->append(label: "Cat 5", categoryEndValue: 19000);
1311 } else if (radCatAxis->count() == 5 && !ui->moreCategoriesCheckBox->isChecked()) {
1312 radCatAxis->setStartValue(2000);
1313 radCatAxis->replaceLabel(oldLabel: "Cat 1", newLabel: "Category 1");
1314 radCatAxis->replaceLabel(oldLabel: "Cat 2", newLabel: "Category 2");
1315 radCatAxis->replaceLabel(oldLabel: "Cat 3", newLabel: "Category 3");
1316 radCatAxis->remove(label: "Cat 4");
1317 radCatAxis->remove(label: "Cat 5");
1318 }
1319 if (ui->categoryLabelLocationCheckBox->isChecked())
1320 radCatAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
1321 else
1322 radCatAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionCenter);
1323 }
1324}
1325

source code of qtcharts/tests/manual/polarcharttest/mainwindow.cpp