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