@@ -1,99 +1,98 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartview.h" |
|
21 | #include "chartview.h" | |
22 | #include <QScatterSeries> |
|
22 | #include <QScatterSeries> | |
23 | #include <QLegendMarker> |
|
23 | #include <QLegendMarker> | |
24 | #include <QImage> |
|
24 | #include <QImage> | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <qmath.h> |
|
26 | #include <qmath.h> | |
27 |
|
27 | |||
28 | const float Pi = 3.14159f; |
|
28 | const float Pi = 3.14159f; | |
29 |
|
29 | |||
30 | ChartView::ChartView(QWidget *parent) : |
|
30 | ChartView::ChartView(QWidget *parent) : | |
31 | QChartView(new QChart(), parent) |
|
31 | QChartView(new QChart(), parent) | |
32 | { |
|
32 | { | |
33 | //![1] |
|
33 | //![1] | |
34 | QScatterSeries *series0 = new QScatterSeries(); |
|
34 | QScatterSeries *series0 = new QScatterSeries(); | |
35 | series0->setName("scatter1"); |
|
35 | series0->setName("scatter1"); | |
36 | series0->setMarkerShape(QScatterSeries::MarkerShapeCircle); |
|
36 | series0->setMarkerShape(QScatterSeries::MarkerShapeCircle); | |
37 | series0->setMarkerSize(15.0); |
|
37 | series0->setMarkerSize(15.0); | |
38 |
|
38 | |||
39 | QScatterSeries *series1 = new QScatterSeries(); |
|
39 | QScatterSeries *series1 = new QScatterSeries(); | |
40 | series1->setName("scatter2"); |
|
40 | series1->setName("scatter2"); | |
41 | series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle); |
|
41 | series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle); | |
42 | series1->setMarkerSize(20.0); |
|
42 | series1->setMarkerSize(20.0); | |
43 |
|
43 | |||
44 | QScatterSeries *series2 = new QScatterSeries(); |
|
44 | QScatterSeries *series2 = new QScatterSeries(); | |
45 | series2->setName("scatter3"); |
|
45 | series2->setName("scatter3"); | |
46 | series2->setMarkerShape(QScatterSeries::MarkerShapeRectangle); |
|
46 | series2->setMarkerShape(QScatterSeries::MarkerShapeRectangle); | |
47 | series2->setMarkerSize(30.0); |
|
47 | series2->setMarkerSize(30.0); | |
48 | //![1] |
|
48 | //![1] | |
49 |
|
49 | |||
50 | //![2] |
|
50 | //![2] | |
51 | series0->append(0, 6); |
|
51 | series0->append(0, 6); | |
52 | series0->append(2, 4); |
|
52 | series0->append(2, 4); | |
53 | series0->append(3, 8); |
|
53 | series0->append(3, 8); | |
54 | series0->append(7, 4); |
|
54 | series0->append(7, 4); | |
55 | series0->append(10, 5); |
|
55 | series0->append(10, 5); | |
56 |
|
56 | |||
57 | *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2); |
|
57 | *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2); | |
58 | *series2 << QPointF(1, 5) << QPointF(4, 6) << QPointF(6, 3) << QPointF(9, 5); |
|
58 | *series2 << QPointF(1, 5) << QPointF(4, 6) << QPointF(6, 3) << QPointF(9, 5); | |
59 | //![2] |
|
59 | //![2] | |
60 |
|
60 | |||
61 | //![3] |
|
61 | //![3] | |
62 | QPainterPath starPath; |
|
62 | QPainterPath starPath; | |
63 | starPath.moveTo(30, 15); |
|
63 | starPath.moveTo(30, 15); | |
64 | for (int i = 1; i < 5; ++i) { |
|
64 | for (int i = 1; i < 5; ++i) { | |
65 | starPath.lineTo(15 + 15 * qCos(0.8 * i * Pi), |
|
65 | starPath.lineTo(15 + 15 * qCos(0.8 * i * Pi), | |
66 | 15 + 15 * qSin(0.8 * i * Pi)); |
|
66 | 15 + 15 * qSin(0.8 * i * Pi)); | |
67 | } |
|
67 | } | |
68 | starPath.closeSubpath(); |
|
68 | starPath.closeSubpath(); | |
69 |
|
69 | |||
70 | QImage star(30, 30, QImage::Format_ARGB32); |
|
70 | QImage star(30, 30, QImage::Format_ARGB32); | |
71 | star.fill(Qt::transparent); |
|
71 | star.fill(Qt::transparent); | |
72 |
|
72 | |||
73 | QPainter painter(&star); |
|
73 | QPainter painter(&star); | |
74 | painter.setRenderHint(QPainter::Antialiasing); |
|
74 | painter.setRenderHint(QPainter::Antialiasing); | |
75 | painter.setPen(QRgb(0xf6a625)); |
|
75 | painter.setPen(QRgb(0xf6a625)); | |
76 | painter.setBrush(painter.pen().color()); |
|
76 | painter.setBrush(painter.pen().color()); | |
77 | painter.drawPath(starPath); |
|
77 | painter.drawPath(starPath); | |
78 |
|
78 | |||
79 | series2->setBrush(star); |
|
79 | series2->setBrush(star); | |
80 | series2->setPen(Qt::NoPen); |
|
|||
81 | //![3] |
|
80 | //![3] | |
82 |
|
81 | |||
83 | //![4] |
|
82 | //![4] | |
84 | setRenderHint(QPainter::Antialiasing); |
|
83 | setRenderHint(QPainter::Antialiasing); | |
85 | chart()->addSeries(series0); |
|
84 | chart()->addSeries(series0); | |
86 | chart()->addSeries(series1); |
|
85 | chart()->addSeries(series1); | |
87 | chart()->addSeries(series2); |
|
86 | chart()->addSeries(series2); | |
88 |
|
87 | |||
89 | chart()->setTitle("Simple scatterchart example"); |
|
88 | chart()->setTitle("Simple scatterchart example"); | |
90 | chart()->createDefaultAxes(); |
|
89 | chart()->createDefaultAxes(); | |
91 | chart()->setDropShadowEnabled(false); |
|
90 | chart()->setDropShadowEnabled(false); | |
92 | //![4] |
|
91 | //![4] | |
93 |
|
92 | |||
94 | //![5] |
|
93 | //![5] | |
95 | QList<QLegendMarker *> markers = chart()->legend()->markers(series2); |
|
94 | QList<QLegendMarker *> markers = chart()->legend()->markers(series2); | |
96 | for (int i = 0; i < markers.count(); i++) |
|
95 | for (int i = 0; i < markers.count(); i++) | |
97 | markers.at(i)->setBrush(painter.pen().color()); |
|
96 | markers.at(i)->setBrush(painter.pen().color()); | |
98 | //![5] |
|
97 | //![5] | |
99 | } |
|
98 | } |
General Comments 0
You need to be logged in to leave comments.
Login now