@@ -1,76 +1,76 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.3 |
|
23 | 23 | |
|
24 | 24 | Rectangle { |
|
25 | 25 | anchors.fill: parent |
|
26 | 26 | |
|
27 | 27 | //![1] |
|
28 | 28 | PolarChartView { |
|
29 | 29 | title: "Numerical Data for Dummies" |
|
30 | 30 | anchors.fill: parent |
|
31 | 31 | legend.visible: false |
|
32 | 32 | |
|
33 | 33 | LineSeries { |
|
34 | 34 | axisRadial: CategoryAxis { |
|
35 | 35 | min: 0 |
|
36 | 36 | max: 30 |
|
37 | 37 | CategoryRange { |
|
38 | 38 | label: "critical" |
|
39 | 39 | endValue: 2 |
|
40 | 40 | } |
|
41 | 41 | CategoryRange { |
|
42 | 42 | label: "low" |
|
43 |
endValue: |
|
|
43 | endValue: 7 | |
|
44 | 44 | } |
|
45 | 45 | CategoryRange { |
|
46 | 46 | label: "normal" |
|
47 |
endValue: |
|
|
47 | endValue: 12 | |
|
48 | 48 | } |
|
49 | 49 | CategoryRange { |
|
50 | 50 | label: "high" |
|
51 |
endValue: 1 |
|
|
51 | endValue: 18 | |
|
52 | 52 | } |
|
53 | 53 | CategoryRange { |
|
54 | 54 | label: "extremely high" |
|
55 | 55 | endValue: 30 |
|
56 | 56 | } |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | axisAngular: ValueAxis { |
|
60 | 60 | tickCount: 13 |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | XYPoint { x: 0; y: 4.3 } |
|
64 | 64 | XYPoint { x: 1; y: 4.1 } |
|
65 | 65 | XYPoint { x: 2; y: 4.7 } |
|
66 | 66 | XYPoint { x: 3; y: 3.9 } |
|
67 | 67 | XYPoint { x: 4; y: 5.2 } |
|
68 | 68 | XYPoint { x: 5; y: 5.3 } |
|
69 | 69 | XYPoint { x: 6; y: 6.1 } |
|
70 | 70 | XYPoint { x: 7; y: 7.7 } |
|
71 | 71 | XYPoint { x: 8; y: 12.9 } |
|
72 | 72 | XYPoint { x: 9; y: 19.2 } |
|
73 | 73 | } |
|
74 | 74 | } |
|
75 | 75 | //![1] |
|
76 | 76 | } |
@@ -1,37 +1,37 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 | import QtQuick 1.0 |
|
22 | 22 | |
|
23 | 23 | Item { |
|
24 | 24 | id: container |
|
25 |
width: |
|
|
26 |
height: |
|
|
25 | width: 800 | |
|
26 | height: 600 | |
|
27 | 27 | Component.onCompleted: { |
|
28 | 28 | var co = Qt.createComponent("main.qml") |
|
29 | 29 | if (co.status == Component.Ready) { |
|
30 | 30 | var o = co.createObject(container) |
|
31 | 31 | } else { |
|
32 | 32 | console.log(co.errorString()) |
|
33 | 33 | console.log("QtCommercial.Chart 1.3 not available") |
|
34 | 34 | console.log("Please use correct QML_IMPORT_PATH export") |
|
35 | 35 | } |
|
36 | 36 | } |
|
37 | 37 | } |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,596 +1,596 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 "qlegend.h" |
|
22 | 22 | #include "qlegend_p.h" |
|
23 | 23 | #include "qabstractseries.h" |
|
24 | 24 | #include "qabstractseries_p.h" |
|
25 | 25 | #include "qchart_p.h" |
|
26 | 26 | #include "legendlayout_p.h" |
|
27 | 27 | #include "chartpresenter_p.h" |
|
28 | 28 | #include "abstractchartlayout_p.h" |
|
29 | 29 | #include "qlegendmarker.h" |
|
30 | 30 | #include "qlegendmarker_p.h" |
|
31 | 31 | #include "legendmarkeritem_p.h" |
|
32 | 32 | #include "chartdataset_p.h" |
|
33 | 33 | #include <QPainter> |
|
34 | 34 | #include <QPen> |
|
35 | 35 | #include <QGraphicsItemGroup> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | /*! |
|
40 | 40 | \class QLegend |
|
41 | 41 | \brief Legend object. |
|
42 | 42 | \mainclass |
|
43 | 43 | |
|
44 | 44 | QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when |
|
45 | 45 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
46 | 46 | handle the drawing manually. |
|
47 | 47 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
48 | 48 | |
|
49 | 49 | \image examples_percentbarchart_legend.png |
|
50 | 50 | |
|
51 | 51 | \sa QChart |
|
52 | 52 | */ |
|
53 | 53 | /*! |
|
54 | 54 | \qmlclass Legend QLegend |
|
55 |
\brief Legend is part of Qt |
|
|
55 | \brief Legend is part of Qt Chart QML API. | |
|
56 | 56 | |
|
57 | 57 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
58 | 58 | series have been changed. Legend is used via ChartView class. For example: |
|
59 | 59 | \code |
|
60 | 60 | ChartView { |
|
61 | 61 | legend.visible: true |
|
62 | 62 | legend.alignment: Qt.AlignBottom |
|
63 | 63 | // Add a few series... |
|
64 | 64 | } |
|
65 | 65 | \endcode |
|
66 | 66 | |
|
67 | 67 | \image examples_percentbarchart_legend.png |
|
68 | 68 | |
|
69 | 69 | Please note that there is no QML API available for modifying legend markers, unlike in the Qt API of Charts. |
|
70 | 70 | The use case of modifying markers can be implemented for example by creating your own custom legend. For an example |
|
71 | 71 | on how to do this, see \l {demos/qmlcustomlegend}{Qml Custom Demo} application. |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \property QLegend::alignment |
|
76 | 76 | \brief The alignment of the legend. |
|
77 | 77 | |
|
78 | 78 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
79 | 79 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty Qt.Alignment Legend::alignment |
|
83 | 83 | \brief The alignment of the legend. |
|
84 | 84 | |
|
85 | 85 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
86 | 86 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \property QLegend::backgroundVisible |
|
91 | 91 | Whether the legend background is visible or not. |
|
92 | 92 | */ |
|
93 | 93 | /*! |
|
94 | 94 | \qmlproperty bool Legend::backgroundVisible |
|
95 | 95 | Whether the legend background is visible or not. |
|
96 | 96 | */ |
|
97 | 97 | |
|
98 | 98 | /*! |
|
99 | 99 | \property QLegend::color |
|
100 | 100 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
101 | 101 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
102 | 102 | */ |
|
103 | 103 | /*! |
|
104 | 104 | \qmlproperty color Legend::color |
|
105 | 105 | The color of the legend, i.e. the background (brush) color. |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \property QLegend::borderColor |
|
110 | 110 | The border color of the legend, i.e. the line color. |
|
111 | 111 | */ |
|
112 | 112 | /*! |
|
113 | 113 | \qmlproperty color Legend::borderColor |
|
114 | 114 | The border color of the legend, i.e. the line color. |
|
115 | 115 | */ |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | 118 | \property QLegend::font |
|
119 | 119 | The font of markers used by legend |
|
120 | 120 | */ |
|
121 | 121 | /*! |
|
122 | 122 | \qmlproperty Font Legend::font |
|
123 | 123 | The font of markers used by legend |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | /*! |
|
127 | 127 | \property QLegend::labelColor |
|
128 | 128 | The color of brush used to draw labels. |
|
129 | 129 | */ |
|
130 | 130 | /*! |
|
131 | 131 | \qmlproperty color QLegend::labelColor |
|
132 | 132 | The color of brush used to draw labels. |
|
133 | 133 | */ |
|
134 | 134 | |
|
135 | 135 | /*! |
|
136 | 136 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
137 | 137 | The visibility of the legend background changed to \a visible. |
|
138 | 138 | */ |
|
139 | 139 | |
|
140 | 140 | /*! |
|
141 | 141 | \fn void QLegend::colorChanged(QColor) |
|
142 | 142 | The color of the legend background changed to \a color. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \fn void QLegend::borderColorChanged(QColor) |
|
147 | 147 | The border color of the legend background changed to \a color. |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \fn void QLegend::fontChanged(QFont) |
|
152 | 152 | The font of markers of the legend changed to \a font. |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QLegend::labelColorChanged(QColor color) |
|
157 | 157 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
161 | 161 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
162 | 162 | { |
|
163 | 163 | setZValue(ChartPresenter::LegendZValue); |
|
164 | 164 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
165 | 165 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
166 | 166 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
167 | 167 | setLayout(d_ptr->m_layout); |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
172 | 172 | */ |
|
173 | 173 | QLegend::~QLegend() |
|
174 | 174 | { |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | \internal |
|
179 | 179 | */ |
|
180 | 180 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
181 | 181 | { |
|
182 | 182 | Q_UNUSED(option) |
|
183 | 183 | Q_UNUSED(widget) |
|
184 | 184 | |
|
185 | 185 | if (!d_ptr->m_backgroundVisible) |
|
186 | 186 | return; |
|
187 | 187 | |
|
188 | 188 | painter->setOpacity(opacity()); |
|
189 | 189 | painter->setPen(d_ptr->m_pen); |
|
190 | 190 | painter->setBrush(d_ptr->m_brush); |
|
191 | 191 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | Sets the \a brush of legend. Brush affects the background of legend. |
|
197 | 197 | */ |
|
198 | 198 | void QLegend::setBrush(const QBrush &brush) |
|
199 | 199 | { |
|
200 | 200 | if (d_ptr->m_brush != brush) { |
|
201 | 201 | d_ptr->m_brush = brush; |
|
202 | 202 | update(); |
|
203 | 203 | emit colorChanged(brush.color()); |
|
204 | 204 | } |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | Returns the brush used by legend. |
|
209 | 209 | */ |
|
210 | 210 | QBrush QLegend::brush() const |
|
211 | 211 | { |
|
212 | 212 | return d_ptr->m_brush; |
|
213 | 213 | } |
|
214 | 214 | |
|
215 | 215 | void QLegend::setColor(QColor color) |
|
216 | 216 | { |
|
217 | 217 | QBrush b = d_ptr->m_brush; |
|
218 | 218 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
219 | 219 | b.setStyle(Qt::SolidPattern); |
|
220 | 220 | b.setColor(color); |
|
221 | 221 | setBrush(b); |
|
222 | 222 | } |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | QColor QLegend::color() |
|
226 | 226 | { |
|
227 | 227 | return d_ptr->m_brush.color(); |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | Sets the \a pen of legend. Pen affects the legend borders. |
|
232 | 232 | */ |
|
233 | 233 | void QLegend::setPen(const QPen &pen) |
|
234 | 234 | { |
|
235 | 235 | if (d_ptr->m_pen != pen) { |
|
236 | 236 | d_ptr->m_pen = pen; |
|
237 | 237 | update(); |
|
238 | 238 | emit borderColorChanged(pen.color()); |
|
239 | 239 | } |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | 242 | /*! |
|
243 | 243 | Returns the pen used by legend |
|
244 | 244 | */ |
|
245 | 245 | |
|
246 | 246 | QPen QLegend::pen() const |
|
247 | 247 | { |
|
248 | 248 | return d_ptr->m_pen; |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void QLegend::setFont(const QFont &font) |
|
252 | 252 | { |
|
253 | 253 | if (d_ptr->m_font != font) { |
|
254 | 254 | d_ptr->m_font = font; |
|
255 | 255 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
256 | 256 | marker->setFont(d_ptr->m_font); |
|
257 | 257 | } |
|
258 | 258 | layout()->invalidate(); |
|
259 | 259 | emit fontChanged(font); |
|
260 | 260 | } |
|
261 | 261 | } |
|
262 | 262 | |
|
263 | 263 | QFont QLegend::font() const |
|
264 | 264 | { |
|
265 | 265 | return d_ptr->m_font; |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | void QLegend::setBorderColor(QColor color) |
|
269 | 269 | { |
|
270 | 270 | QPen p = d_ptr->m_pen; |
|
271 | 271 | if (p.color() != color) { |
|
272 | 272 | p.setColor(color); |
|
273 | 273 | setPen(p); |
|
274 | 274 | } |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | 277 | QColor QLegend::borderColor() |
|
278 | 278 | { |
|
279 | 279 | return d_ptr->m_pen.color(); |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | /*! |
|
283 | 283 | Set brush used to draw labels to \a brush. |
|
284 | 284 | */ |
|
285 | 285 | void QLegend::setLabelBrush(const QBrush &brush) |
|
286 | 286 | { |
|
287 | 287 | if (d_ptr->m_labelBrush != brush) { |
|
288 | 288 | d_ptr->m_labelBrush = brush; |
|
289 | 289 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
290 | 290 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
291 | 291 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
292 | 292 | // instead of mapping it from label brush color |
|
293 | 293 | marker->setPen(brush.color()); |
|
294 | 294 | } |
|
295 | 295 | emit labelColorChanged(brush.color()); |
|
296 | 296 | } |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | /*! |
|
300 | 300 | Brush used to draw labels. |
|
301 | 301 | */ |
|
302 | 302 | QBrush QLegend::labelBrush() const |
|
303 | 303 | { |
|
304 | 304 | return d_ptr->m_labelBrush; |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | void QLegend::setLabelColor(QColor color) |
|
308 | 308 | { |
|
309 | 309 | QBrush b = d_ptr->m_labelBrush; |
|
310 | 310 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
311 | 311 | b.setStyle(Qt::SolidPattern); |
|
312 | 312 | b.setColor(color); |
|
313 | 313 | setLabelBrush(b); |
|
314 | 314 | } |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | QColor QLegend::labelColor() const |
|
318 | 318 | { |
|
319 | 319 | return d_ptr->m_labelBrush.color(); |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | |
|
323 | 323 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
324 | 324 | { |
|
325 | 325 | if (d_ptr->m_alignment != alignment) { |
|
326 | 326 | d_ptr->m_alignment = alignment; |
|
327 | 327 | layout()->invalidate(); |
|
328 | 328 | } |
|
329 | 329 | } |
|
330 | 330 | |
|
331 | 331 | Qt::Alignment QLegend::alignment() const |
|
332 | 332 | { |
|
333 | 333 | return d_ptr->m_alignment; |
|
334 | 334 | } |
|
335 | 335 | |
|
336 | 336 | /*! |
|
337 | 337 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
338 | 338 | */ |
|
339 | 339 | void QLegend::detachFromChart() |
|
340 | 340 | { |
|
341 | 341 | d_ptr->m_attachedToChart = false; |
|
342 | 342 | // layout()->invalidate(); |
|
343 | 343 | d_ptr->m_chart->layout()->invalidate(); |
|
344 | 344 | setParent(0); |
|
345 | 345 | |
|
346 | 346 | } |
|
347 | 347 | |
|
348 | 348 | /*! |
|
349 | 349 | Attaches the legend to chart. Chart may change layout of the legend. |
|
350 | 350 | */ |
|
351 | 351 | void QLegend::attachToChart() |
|
352 | 352 | { |
|
353 | 353 | d_ptr->m_attachedToChart = true; |
|
354 | 354 | // layout()->invalidate(); |
|
355 | 355 | d_ptr->m_chart->layout()->invalidate(); |
|
356 | 356 | setParent(d_ptr->m_chart); |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | /*! |
|
360 | 360 | Returns true, if legend is attached to chart. |
|
361 | 361 | */ |
|
362 | 362 | bool QLegend::isAttachedToChart() |
|
363 | 363 | { |
|
364 | 364 | return d_ptr->m_attachedToChart; |
|
365 | 365 | } |
|
366 | 366 | |
|
367 | 367 | /*! |
|
368 | 368 | Sets the visibility of legend background to \a visible |
|
369 | 369 | */ |
|
370 | 370 | void QLegend::setBackgroundVisible(bool visible) |
|
371 | 371 | { |
|
372 | 372 | if (d_ptr->m_backgroundVisible != visible) { |
|
373 | 373 | d_ptr->m_backgroundVisible = visible; |
|
374 | 374 | update(); |
|
375 | 375 | emit backgroundVisibleChanged(visible); |
|
376 | 376 | } |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | /*! |
|
380 | 380 | Returns the visibility of legend background |
|
381 | 381 | */ |
|
382 | 382 | bool QLegend::isBackgroundVisible() const |
|
383 | 383 | { |
|
384 | 384 | return d_ptr->m_backgroundVisible; |
|
385 | 385 | } |
|
386 | 386 | |
|
387 | 387 | /*! |
|
388 | 388 | Returns the list of markers in legend. The list can be filtered with \a series parameter. |
|
389 | 389 | If \a series is given, only markers related to that series are returned. |
|
390 | 390 | */ |
|
391 | 391 | QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const |
|
392 | 392 | { |
|
393 | 393 | return d_ptr->markers(series); |
|
394 | 394 | } |
|
395 | 395 | |
|
396 | 396 | /*! |
|
397 | 397 | \internal \a event see QGraphicsWidget for details |
|
398 | 398 | */ |
|
399 | 399 | void QLegend::hideEvent(QHideEvent *event) |
|
400 | 400 | { |
|
401 | 401 | if (isAttachedToChart()) |
|
402 | 402 | d_ptr->m_presenter->layout()->invalidate(); |
|
403 | 403 | QGraphicsWidget::hideEvent(event); |
|
404 | 404 | } |
|
405 | 405 | /*! |
|
406 | 406 | \internal \a event see QGraphicsWidget for details |
|
407 | 407 | */ |
|
408 | 408 | void QLegend::showEvent(QShowEvent *event) |
|
409 | 409 | { |
|
410 | 410 | if (isAttachedToChart()) { |
|
411 | 411 | d_ptr->items()->setVisible(false); |
|
412 | 412 | layout()->invalidate(); |
|
413 | 413 | } |
|
414 | 414 | QGraphicsWidget::showEvent(event); |
|
415 | 415 | //layout activation will show the items |
|
416 | 416 | } |
|
417 | 417 | |
|
418 | 418 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
419 | 419 | |
|
420 | 420 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
421 | 421 | : q_ptr(q), |
|
422 | 422 | m_presenter(presenter), |
|
423 | 423 | m_layout(new LegendLayout(q)), |
|
424 | 424 | m_chart(chart), |
|
425 | 425 | m_items(new QGraphicsItemGroup(q)), |
|
426 | 426 | m_alignment(Qt::AlignTop), |
|
427 | 427 | m_brush(QBrush()), |
|
428 | 428 | m_pen(QPen()), |
|
429 | 429 | m_labelBrush(QBrush()), |
|
430 | 430 | m_diameter(5), |
|
431 | 431 | m_attachedToChart(true), |
|
432 | 432 | m_backgroundVisible(false) |
|
433 | 433 | { |
|
434 | 434 | m_items->setHandlesChildEvents(false); |
|
435 | 435 | } |
|
436 | 436 | |
|
437 | 437 | QLegendPrivate::~QLegendPrivate() |
|
438 | 438 | { |
|
439 | 439 | |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | void QLegendPrivate::setOffset(const QPointF &offset) |
|
443 | 443 | { |
|
444 | 444 | m_layout->setOffset(offset.x(), offset.y()); |
|
445 | 445 | } |
|
446 | 446 | |
|
447 | 447 | QPointF QLegendPrivate::offset() const |
|
448 | 448 | { |
|
449 | 449 | return m_layout->offset(); |
|
450 | 450 | } |
|
451 | 451 | |
|
452 | 452 | int QLegendPrivate::roundness(qreal size) |
|
453 | 453 | { |
|
454 | 454 | return 100 * m_diameter / int(size); |
|
455 | 455 | } |
|
456 | 456 | |
|
457 | 457 | QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series) |
|
458 | 458 | { |
|
459 | 459 | // Return all markers |
|
460 | 460 | if (!series) { |
|
461 | 461 | return m_markers; |
|
462 | 462 | } |
|
463 | 463 | |
|
464 | 464 | // Create filtered list |
|
465 | 465 | QList<QLegendMarker *> markers; |
|
466 | 466 | foreach (QLegendMarker *marker, m_markers) { |
|
467 | 467 | if (marker->series() == series) { |
|
468 | 468 | markers.append(marker); |
|
469 | 469 | } |
|
470 | 470 | } |
|
471 | 471 | return markers; |
|
472 | 472 | } |
|
473 | 473 | |
|
474 | 474 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) |
|
475 | 475 | { |
|
476 | 476 | if (m_series.contains(series)) { |
|
477 | 477 | return; |
|
478 | 478 | } |
|
479 | 479 | |
|
480 | 480 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
481 | 481 | decorateMarkers(newMarkers); |
|
482 | 482 | addMarkers(newMarkers); |
|
483 | 483 | |
|
484 | 484 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
485 | 485 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
486 | 486 | |
|
487 | 487 | m_series.append(series); |
|
488 | 488 | m_items->setVisible(false); |
|
489 | 489 | m_layout->invalidate(); |
|
490 | 490 | } |
|
491 | 491 | |
|
492 | 492 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
493 | 493 | { |
|
494 | 494 | if (m_series.contains(series)) { |
|
495 | 495 | m_series.removeOne(series); |
|
496 | 496 | } |
|
497 | 497 | |
|
498 | 498 | // Find out, which markers to remove |
|
499 | 499 | QList<QLegendMarker *> removed; |
|
500 | 500 | foreach (QLegendMarker *m, m_markers) { |
|
501 | 501 | if (m->series() == series) { |
|
502 | 502 | removed << m; |
|
503 | 503 | } |
|
504 | 504 | } |
|
505 | 505 | removeMarkers(removed); |
|
506 | 506 | |
|
507 | 507 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
508 | 508 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
509 | 509 | |
|
510 | 510 | m_layout->invalidate(); |
|
511 | 511 | } |
|
512 | 512 | |
|
513 | 513 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
514 | 514 | { |
|
515 | 515 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
516 | 516 | Q_ASSERT(series); |
|
517 | 517 | |
|
518 | 518 | foreach (QLegendMarker *marker, m_markers) { |
|
519 | 519 | if (marker->series() == series) { |
|
520 | 520 | marker->setVisible(series->isVisible()); |
|
521 | 521 | } |
|
522 | 522 | } |
|
523 | 523 | m_layout->invalidate(); |
|
524 | 524 | } |
|
525 | 525 | |
|
526 | 526 | void QLegendPrivate::handleCountChanged() |
|
527 | 527 | { |
|
528 | 528 | // Here we handle the changes in marker count. |
|
529 | 529 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. |
|
530 | 530 | |
|
531 | 531 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); |
|
532 | 532 | QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr); |
|
533 | 533 | |
|
534 | 534 | // Find out removed markers and created markers |
|
535 | 535 | QList<QLegendMarker *> removedMarkers; |
|
536 | 536 | foreach (QLegendMarker *oldMarker, m_markers) { |
|
537 | 537 | // we have marker, which is related to sender. |
|
538 | 538 | if (oldMarker->series() == series->q_ptr) { |
|
539 | 539 | bool found = false; |
|
540 | 540 | foreach(QLegendMarker *newMarker, createdMarkers) { |
|
541 | 541 | // New marker considered existing if: |
|
542 | 542 | // - d_ptr->relatedObject() is same for both markers. |
|
543 | 543 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { |
|
544 | 544 | // Delete the new marker, since we already have existing marker, that might be connected on user side. |
|
545 | 545 | found = true; |
|
546 | 546 | createdMarkers.removeOne(newMarker); |
|
547 | 547 | delete newMarker; |
|
548 | 548 | } |
|
549 | 549 | } |
|
550 | 550 | if (!found) { |
|
551 | 551 | // No related object found for marker, add to removedMarkers list |
|
552 | 552 | removedMarkers << oldMarker; |
|
553 | 553 | } |
|
554 | 554 | } |
|
555 | 555 | } |
|
556 | 556 | |
|
557 | 557 | removeMarkers(removedMarkers); |
|
558 | 558 | decorateMarkers(createdMarkers); |
|
559 | 559 | addMarkers(createdMarkers); |
|
560 | 560 | |
|
561 | 561 | q_ptr->layout()->invalidate(); |
|
562 | 562 | } |
|
563 | 563 | |
|
564 | 564 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) |
|
565 | 565 | { |
|
566 | 566 | foreach (QLegendMarker *marker, markers) { |
|
567 | 567 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
568 | 568 | m_markers << marker; |
|
569 | 569 | m_markerHash.insert(marker->d_ptr->item(), marker); |
|
570 | 570 | } |
|
571 | 571 | } |
|
572 | 572 | |
|
573 | 573 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) |
|
574 | 574 | { |
|
575 | 575 | foreach (QLegendMarker *marker, markers) { |
|
576 | 576 | marker->d_ptr->item()->setVisible(false); |
|
577 | 577 | m_items->removeFromGroup(marker->d_ptr->item()); |
|
578 | 578 | m_markers.removeOne(marker); |
|
579 | 579 | m_markerHash.remove(marker->d_ptr->item()); |
|
580 | 580 | delete marker; |
|
581 | 581 | } |
|
582 | 582 | } |
|
583 | 583 | |
|
584 | 584 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) |
|
585 | 585 | { |
|
586 | 586 | foreach (QLegendMarker *marker, markers) { |
|
587 | 587 | marker->setFont(m_font); |
|
588 | 588 | marker->setLabelBrush(m_labelBrush); |
|
589 | 589 | } |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | |
|
593 | 593 | #include "moc_qlegend.cpp" |
|
594 | 594 | #include "moc_qlegend_p.cpp" |
|
595 | 595 | |
|
596 | 596 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,939 +1,939 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 "qpieseries.h" |
|
22 | 22 | #include "qpieseries_p.h" |
|
23 | 23 | #include "qpieslice.h" |
|
24 | 24 | #include "qpieslice_p.h" |
|
25 | 25 | #include "pieslicedata_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "qabstractaxis.h" |
|
29 | 29 | #include "pieanimation_p.h" |
|
30 | 30 | #include "charthelpers_p.h" |
|
31 | 31 | |
|
32 | 32 | #include "qpielegendmarker.h" |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \class QPieSeries |
|
38 |
\brief Pie series API for Qt |
|
|
38 | \brief Pie series API for Qt Charts. | |
|
39 | 39 | |
|
40 | 40 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
41 | 41 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
42 | 42 | The actual slice size is determined by that relative value. |
|
43 | 43 | |
|
44 | 44 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0. |
|
45 | 45 | These relate to the actual chart rectangle. |
|
46 | 46 | |
|
47 | 47 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
48 | 48 | This can be done by setting a starting angle and angle span to the series. |
|
49 | 49 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
50 | 50 | |
|
51 | 51 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. |
|
52 | 52 | \table 100% |
|
53 | 53 | \row |
|
54 | 54 | \o \image examples_piechart.png |
|
55 | 55 | \o \image examples_donutchart.png |
|
56 | 56 | \endtable |
|
57 | 57 | */ |
|
58 | 58 | /*! |
|
59 | 59 | \qmlclass PieSeries QPieSeries |
|
60 | 60 | \inherits AbstractSeries |
|
61 | 61 | |
|
62 | 62 | The following QML shows how to create a simple pie chart. |
|
63 | 63 | |
|
64 | 64 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
65 | 65 | |
|
66 | 66 | \beginfloatleft |
|
67 | 67 | \image demos_qmlchart1.png |
|
68 | 68 | \endfloat |
|
69 | 69 | \clearfloat |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \property QPieSeries::horizontalPosition |
|
74 | 74 | \brief Defines the horizontal position of the pie. |
|
75 | 75 | |
|
76 | 76 | The value is a relative value to the chart rectangle where: |
|
77 | 77 | |
|
78 | 78 | \list |
|
79 | 79 | \o 0.0 is the absolute left. |
|
80 | 80 | \o 1.0 is the absolute right. |
|
81 | 81 | \endlist |
|
82 | 82 | Default value is 0.5 (center). |
|
83 | 83 | \sa verticalPosition |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | 87 | \qmlproperty real PieSeries::horizontalPosition |
|
88 | 88 | |
|
89 | 89 | Defines the horizontal position of the pie. |
|
90 | 90 | |
|
91 | 91 | The value is a relative value to the chart rectangle where: |
|
92 | 92 | |
|
93 | 93 | \list |
|
94 | 94 | \o 0.0 is the absolute left. |
|
95 | 95 | \o 1.0 is the absolute right. |
|
96 | 96 | \endlist |
|
97 | 97 | Default value is 0.5 (center). |
|
98 | 98 | \sa verticalPosition |
|
99 | 99 | */ |
|
100 | 100 | |
|
101 | 101 | /*! |
|
102 | 102 | \property QPieSeries::verticalPosition |
|
103 | 103 | \brief Defines the vertical position of the pie. |
|
104 | 104 | |
|
105 | 105 | The value is a relative value to the chart rectangle where: |
|
106 | 106 | |
|
107 | 107 | \list |
|
108 | 108 | \o 0.0 is the absolute top. |
|
109 | 109 | \o 1.0 is the absolute bottom. |
|
110 | 110 | \endlist |
|
111 | 111 | Default value is 0.5 (center). |
|
112 | 112 | \sa horizontalPosition |
|
113 | 113 | */ |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | \qmlproperty real PieSeries::verticalPosition |
|
117 | 117 | |
|
118 | 118 | Defines the vertical position of the pie. |
|
119 | 119 | |
|
120 | 120 | The value is a relative value to the chart rectangle where: |
|
121 | 121 | |
|
122 | 122 | \list |
|
123 | 123 | \o 0.0 is the absolute top. |
|
124 | 124 | \o 1.0 is the absolute bottom. |
|
125 | 125 | \endlist |
|
126 | 126 | Default value is 0.5 (center). |
|
127 | 127 | \sa horizontalPosition |
|
128 | 128 | */ |
|
129 | 129 | |
|
130 | 130 | /*! |
|
131 | 131 | \property QPieSeries::size |
|
132 | 132 | \brief Defines the pie size. |
|
133 | 133 | |
|
134 | 134 | The value is a relative value to the chart rectangle where: |
|
135 | 135 | |
|
136 | 136 | \list |
|
137 | 137 | \o 0.0 is the minimum size (pie not drawn). |
|
138 | 138 | \o 1.0 is the maximum size that can fit the chart. |
|
139 | 139 | \endlist |
|
140 | 140 | |
|
141 | 141 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. |
|
142 | 142 | |
|
143 | 143 | Default value is 0.7. |
|
144 | 144 | */ |
|
145 | 145 | |
|
146 | 146 | /*! |
|
147 | 147 | \qmlproperty real PieSeries::size |
|
148 | 148 | |
|
149 | 149 | Defines the pie size. |
|
150 | 150 | |
|
151 | 151 | The value is a relative value to the chart rectangle where: |
|
152 | 152 | |
|
153 | 153 | \list |
|
154 | 154 | \o 0.0 is the minimum size (pie not drawn). |
|
155 | 155 | \o 1.0 is the maximum size that can fit the chart. |
|
156 | 156 | \endlist |
|
157 | 157 | |
|
158 | 158 | Default value is 0.7. |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \property QPieSeries::holeSize |
|
163 | 163 | \brief Defines the donut hole size. |
|
164 | 164 | |
|
165 | 165 | The value is a relative value to the chart rectangle where: |
|
166 | 166 | |
|
167 | 167 | \list |
|
168 | 168 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
169 | 169 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
170 | 170 | \endlist |
|
171 | 171 | |
|
172 | 172 | The value is never greater then size property. |
|
173 | 173 | Default value is 0.0. |
|
174 | 174 | */ |
|
175 | 175 | |
|
176 | 176 | /*! |
|
177 | 177 | \qmlproperty real PieSeries::holeSize |
|
178 | 178 | |
|
179 | 179 | Defines the donut hole size. |
|
180 | 180 | |
|
181 | 181 | The value is a relative value to the chart rectangle where: |
|
182 | 182 | |
|
183 | 183 | \list |
|
184 | 184 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
185 | 185 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
186 | 186 | \endlist |
|
187 | 187 | |
|
188 | 188 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. |
|
189 | 189 | |
|
190 | 190 | Default value is 0.0. |
|
191 | 191 | */ |
|
192 | 192 | |
|
193 | 193 | /*! |
|
194 | 194 | \property QPieSeries::startAngle |
|
195 | 195 | \brief Defines the starting angle of the pie. |
|
196 | 196 | |
|
197 | 197 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
198 | 198 | |
|
199 | 199 | Default is value is 0. |
|
200 | 200 | */ |
|
201 | 201 | |
|
202 | 202 | /*! |
|
203 | 203 | \qmlproperty real PieSeries::startAngle |
|
204 | 204 | |
|
205 | 205 | Defines the starting angle of the pie. |
|
206 | 206 | |
|
207 | 207 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
208 | 208 | |
|
209 | 209 | Default is value is 0. |
|
210 | 210 | */ |
|
211 | 211 | |
|
212 | 212 | /*! |
|
213 | 213 | \property QPieSeries::endAngle |
|
214 | 214 | \brief Defines the ending angle of the pie. |
|
215 | 215 | |
|
216 | 216 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
217 | 217 | |
|
218 | 218 | Default is value is 360. |
|
219 | 219 | */ |
|
220 | 220 | |
|
221 | 221 | /*! |
|
222 | 222 | \qmlproperty real PieSeries::endAngle |
|
223 | 223 | |
|
224 | 224 | Defines the ending angle of the pie. |
|
225 | 225 | |
|
226 | 226 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
227 | 227 | |
|
228 | 228 | Default is value is 360. |
|
229 | 229 | */ |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | \property QPieSeries::count |
|
233 | 233 | |
|
234 | 234 | Number of slices in the series. |
|
235 | 235 | */ |
|
236 | 236 | |
|
237 | 237 | /*! |
|
238 | 238 | \qmlproperty int PieSeries::count |
|
239 | 239 | |
|
240 | 240 | Number of slices in the series. |
|
241 | 241 | */ |
|
242 | 242 | |
|
243 | 243 | /*! |
|
244 | 244 | \fn void QPieSeries::countChanged() |
|
245 | 245 | Emitted when the slice count has changed. |
|
246 | 246 | \sa count |
|
247 | 247 | */ |
|
248 | 248 | /*! |
|
249 | 249 | \qmlsignal PieSeries::onCountChanged() |
|
250 | 250 | Emitted when the slice count has changed. |
|
251 | 251 | */ |
|
252 | 252 | |
|
253 | 253 | /*! |
|
254 | 254 | \property QPieSeries::sum |
|
255 | 255 | |
|
256 | 256 | Sum of all slices. |
|
257 | 257 | |
|
258 | 258 | The series keeps track of the sum of all slices it holds. |
|
259 | 259 | */ |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | \qmlproperty real PieSeries::sum |
|
263 | 263 | |
|
264 | 264 | Sum of all slices. |
|
265 | 265 | |
|
266 | 266 | The series keeps track of the sum of all slices it holds. |
|
267 | 267 | */ |
|
268 | 268 | |
|
269 | 269 | /*! |
|
270 | 270 | \fn void QPieSeries::sumChanged() |
|
271 | 271 | Emitted when the sum of all slices has changed. |
|
272 | 272 | \sa sum |
|
273 | 273 | */ |
|
274 | 274 | /*! |
|
275 | 275 | \qmlsignal PieSeries::onSumChanged() |
|
276 | 276 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
277 | 277 | change value of a slice. |
|
278 | 278 | */ |
|
279 | 279 | |
|
280 | 280 | /*! |
|
281 | 281 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
282 | 282 | |
|
283 | 283 | This signal is emitted when \a slices have been added to the series. |
|
284 | 284 | |
|
285 | 285 | \sa append(), insert() |
|
286 | 286 | */ |
|
287 | 287 | /*! |
|
288 | 288 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
289 | 289 | Emitted when \a slice has been added to the series. |
|
290 | 290 | */ |
|
291 | 291 | |
|
292 | 292 | /*! |
|
293 | 293 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
294 | 294 | This signal is emitted when \a slices have been removed from the series. |
|
295 | 295 | \sa remove() |
|
296 | 296 | */ |
|
297 | 297 | /*! |
|
298 | 298 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
299 | 299 | Emitted when \a slice has been removed from the series. |
|
300 | 300 | */ |
|
301 | 301 | |
|
302 | 302 | /*! |
|
303 | 303 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
304 | 304 | This signal is emitted when a \a slice has been clicked. |
|
305 | 305 | \sa QPieSlice::clicked() |
|
306 | 306 | */ |
|
307 | 307 | /*! |
|
308 | 308 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
309 | 309 | This signal is emitted when a \a slice has been clicked. |
|
310 | 310 | */ |
|
311 | 311 | |
|
312 | 312 | /*! |
|
313 | 313 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
314 | 314 | This signal is emitted when user has hovered over or away from the \a slice. |
|
315 | 315 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
316 | 316 | \sa QPieSlice::hovered() |
|
317 | 317 | */ |
|
318 | 318 | /*! |
|
319 | 319 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
320 | 320 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
321 | 321 | over the slice and false when hover has moved away from the slice. |
|
322 | 322 | */ |
|
323 | 323 | |
|
324 | 324 | /*! |
|
325 | 325 | \qmlmethod PieSlice PieSeries::at(int index) |
|
326 | 326 | Returns slice at \a index. Returns null if the index is not valid. |
|
327 | 327 | */ |
|
328 | 328 | |
|
329 | 329 | /*! |
|
330 | 330 | \qmlmethod PieSlice PieSeries::find(string label) |
|
331 | 331 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
332 | 332 | */ |
|
333 | 333 | |
|
334 | 334 | /*! |
|
335 | 335 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
336 | 336 | Adds a new slice with \a label and \a value to the pie. |
|
337 | 337 | */ |
|
338 | 338 | |
|
339 | 339 | /*! |
|
340 | 340 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
341 | 341 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. |
|
342 | 342 | */ |
|
343 | 343 | |
|
344 | 344 | /*! |
|
345 | 345 | \qmlmethod PieSeries::clear() |
|
346 | 346 | Removes all slices from the pie. |
|
347 | 347 | */ |
|
348 | 348 | |
|
349 | 349 | /*! |
|
350 | 350 | Constructs a series object which is a child of \a parent. |
|
351 | 351 | */ |
|
352 | 352 | QPieSeries::QPieSeries(QObject *parent) |
|
353 | 353 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) |
|
354 | 354 | { |
|
355 | 355 | Q_D(QPieSeries); |
|
356 | 356 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | /*! |
|
360 | 360 | Destroys the series and its slices. |
|
361 | 361 | */ |
|
362 | 362 | QPieSeries::~QPieSeries() |
|
363 | 363 | { |
|
364 | 364 | // NOTE: d_prt destroyed by QObject |
|
365 | 365 | clear(); |
|
366 | 366 | } |
|
367 | 367 | |
|
368 | 368 | /*! |
|
369 | 369 | Returns QAbstractSeries::SeriesTypePie. |
|
370 | 370 | */ |
|
371 | 371 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
372 | 372 | { |
|
373 | 373 | return QAbstractSeries::SeriesTypePie; |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | /*! |
|
377 | 377 | Appends a single \a slice to the series. |
|
378 | 378 | Slice ownership is passed to the series. |
|
379 | 379 | |
|
380 | 380 | Returns true if append was succesfull. |
|
381 | 381 | */ |
|
382 | 382 | bool QPieSeries::append(QPieSlice *slice) |
|
383 | 383 | { |
|
384 | 384 | return append(QList<QPieSlice *>() << slice); |
|
385 | 385 | } |
|
386 | 386 | |
|
387 | 387 | /*! |
|
388 | 388 | Appends an array of \a slices to the series. |
|
389 | 389 | Slice ownership is passed to the series. |
|
390 | 390 | |
|
391 | 391 | Returns true if append was successful. |
|
392 | 392 | */ |
|
393 | 393 | bool QPieSeries::append(QList<QPieSlice *> slices) |
|
394 | 394 | { |
|
395 | 395 | Q_D(QPieSeries); |
|
396 | 396 | |
|
397 | 397 | if (slices.count() == 0) |
|
398 | 398 | return false; |
|
399 | 399 | |
|
400 | 400 | foreach (QPieSlice *s, slices) { |
|
401 | 401 | if (!s || d->m_slices.contains(s)) |
|
402 | 402 | return false; |
|
403 | 403 | if (s->series()) // already added to some series |
|
404 | 404 | return false; |
|
405 | 405 | if (!isValidValue(s->value())) |
|
406 | 406 | return false; |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | foreach (QPieSlice *s, slices) { |
|
410 | 410 | s->setParent(this); |
|
411 | 411 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
412 | 412 | d->m_slices << s; |
|
413 | 413 | } |
|
414 | 414 | |
|
415 | 415 | d->updateDerivativeData(); |
|
416 | 416 | |
|
417 | 417 | foreach(QPieSlice * s, slices) { |
|
418 | 418 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
419 | 419 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
420 | 420 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | emit added(slices); |
|
424 | 424 | emit countChanged(); |
|
425 | 425 | |
|
426 | 426 | return true; |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | /*! |
|
430 | 430 | Appends a single \a slice to the series and returns a reference to the series. |
|
431 | 431 | Slice ownership is passed to the series. |
|
432 | 432 | */ |
|
433 | 433 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) |
|
434 | 434 | { |
|
435 | 435 | append(slice); |
|
436 | 436 | return *this; |
|
437 | 437 | } |
|
438 | 438 | |
|
439 | 439 | |
|
440 | 440 | /*! |
|
441 | 441 | Appends a single slice to the series with give \a value and \a label. |
|
442 | 442 | Slice ownership is passed to the series. |
|
443 | 443 | Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series. |
|
444 | 444 | */ |
|
445 | 445 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
446 | 446 | { |
|
447 | 447 | if (isValidValue(value)) { |
|
448 | 448 | QPieSlice *slice = new QPieSlice(label, value); |
|
449 | 449 | append(slice); |
|
450 | 450 | return slice; |
|
451 | 451 | } else { |
|
452 | 452 | return 0; |
|
453 | 453 | } |
|
454 | 454 | } |
|
455 | 455 | |
|
456 | 456 | /*! |
|
457 | 457 | Inserts a single \a slice to the series before the slice at \a index position. |
|
458 | 458 | Slice ownership is passed to the series. |
|
459 | 459 | |
|
460 | 460 | Returns true if insert was successful. |
|
461 | 461 | */ |
|
462 | 462 | bool QPieSeries::insert(int index, QPieSlice *slice) |
|
463 | 463 | { |
|
464 | 464 | Q_D(QPieSeries); |
|
465 | 465 | |
|
466 | 466 | if (index < 0 || index > d->m_slices.count()) |
|
467 | 467 | return false; |
|
468 | 468 | |
|
469 | 469 | if (!slice || d->m_slices.contains(slice)) |
|
470 | 470 | return false; |
|
471 | 471 | |
|
472 | 472 | if (slice->series()) // already added to some series |
|
473 | 473 | return false; |
|
474 | 474 | |
|
475 | 475 | if (!isValidValue(slice->value())) |
|
476 | 476 | return false; |
|
477 | 477 | |
|
478 | 478 | slice->setParent(this); |
|
479 | 479 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
480 | 480 | d->m_slices.insert(index, slice); |
|
481 | 481 | |
|
482 | 482 | d->updateDerivativeData(); |
|
483 | 483 | |
|
484 | 484 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
485 | 485 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
486 | 486 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
487 | 487 | |
|
488 | 488 | emit added(QList<QPieSlice *>() << slice); |
|
489 | 489 | emit countChanged(); |
|
490 | 490 | |
|
491 | 491 | return true; |
|
492 | 492 | } |
|
493 | 493 | |
|
494 | 494 | /*! |
|
495 | 495 | Removes a single \a slice from the series and deletes the slice. |
|
496 | 496 | |
|
497 | 497 | Do not reference the pointer after this call. |
|
498 | 498 | |
|
499 | 499 | Returns true if remove was successful. |
|
500 | 500 | */ |
|
501 | 501 | bool QPieSeries::remove(QPieSlice *slice) |
|
502 | 502 | { |
|
503 | 503 | Q_D(QPieSeries); |
|
504 | 504 | |
|
505 | 505 | if (!d->m_slices.removeOne(slice)) |
|
506 | 506 | return false; |
|
507 | 507 | |
|
508 | 508 | d->updateDerivativeData(); |
|
509 | 509 | |
|
510 | 510 | emit removed(QList<QPieSlice *>() << slice); |
|
511 | 511 | emit countChanged(); |
|
512 | 512 | |
|
513 | 513 | delete slice; |
|
514 | 514 | slice = 0; |
|
515 | 515 | |
|
516 | 516 | return true; |
|
517 | 517 | } |
|
518 | 518 | |
|
519 | 519 | /*! |
|
520 | 520 | Takes a single \a slice from the series. Does not destroy the slice object. |
|
521 | 521 | |
|
522 | 522 | \note The series remains as the slice's parent object. You must set the |
|
523 | 523 | parent object to take full ownership. |
|
524 | 524 | |
|
525 | 525 | Returns true if take was successful. |
|
526 | 526 | */ |
|
527 | 527 | bool QPieSeries::take(QPieSlice *slice) |
|
528 | 528 | { |
|
529 | 529 | Q_D(QPieSeries); |
|
530 | 530 | |
|
531 | 531 | if (!d->m_slices.removeOne(slice)) |
|
532 | 532 | return false; |
|
533 | 533 | |
|
534 | 534 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; |
|
535 | 535 | slice->disconnect(d); |
|
536 | 536 | |
|
537 | 537 | d->updateDerivativeData(); |
|
538 | 538 | |
|
539 | 539 | emit removed(QList<QPieSlice *>() << slice); |
|
540 | 540 | emit countChanged(); |
|
541 | 541 | |
|
542 | 542 | return true; |
|
543 | 543 | } |
|
544 | 544 | |
|
545 | 545 | /*! |
|
546 | 546 | Clears all slices from the series. |
|
547 | 547 | */ |
|
548 | 548 | void QPieSeries::clear() |
|
549 | 549 | { |
|
550 | 550 | Q_D(QPieSeries); |
|
551 | 551 | if (d->m_slices.count() == 0) |
|
552 | 552 | return; |
|
553 | 553 | |
|
554 | 554 | QList<QPieSlice *> slices = d->m_slices; |
|
555 | 555 | foreach (QPieSlice *s, d->m_slices) |
|
556 | 556 | d->m_slices.removeOne(s); |
|
557 | 557 | |
|
558 | 558 | d->updateDerivativeData(); |
|
559 | 559 | |
|
560 | 560 | emit removed(slices); |
|
561 | 561 | emit countChanged(); |
|
562 | 562 | |
|
563 | 563 | foreach (QPieSlice *s, slices) |
|
564 | 564 | delete s; |
|
565 | 565 | } |
|
566 | 566 | |
|
567 | 567 | /*! |
|
568 | 568 | Returns a list of slices that belong to this series. |
|
569 | 569 | */ |
|
570 | 570 | QList<QPieSlice *> QPieSeries::slices() const |
|
571 | 571 | { |
|
572 | 572 | Q_D(const QPieSeries); |
|
573 | 573 | return d->m_slices; |
|
574 | 574 | } |
|
575 | 575 | |
|
576 | 576 | /*! |
|
577 | 577 | returns the number of the slices in this series. |
|
578 | 578 | */ |
|
579 | 579 | int QPieSeries::count() const |
|
580 | 580 | { |
|
581 | 581 | Q_D(const QPieSeries); |
|
582 | 582 | return d->m_slices.count(); |
|
583 | 583 | } |
|
584 | 584 | |
|
585 | 585 | /*! |
|
586 | 586 | Returns true is the series is empty. |
|
587 | 587 | */ |
|
588 | 588 | bool QPieSeries::isEmpty() const |
|
589 | 589 | { |
|
590 | 590 | Q_D(const QPieSeries); |
|
591 | 591 | return d->m_slices.isEmpty(); |
|
592 | 592 | } |
|
593 | 593 | |
|
594 | 594 | /*! |
|
595 | 595 | Returns the sum of all slice values in this series. |
|
596 | 596 | |
|
597 | 597 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
598 | 598 | */ |
|
599 | 599 | qreal QPieSeries::sum() const |
|
600 | 600 | { |
|
601 | 601 | Q_D(const QPieSeries); |
|
602 | 602 | return d->m_sum; |
|
603 | 603 | } |
|
604 | 604 | |
|
605 | 605 | void QPieSeries::setHoleSize(qreal holeSize) |
|
606 | 606 | { |
|
607 | 607 | Q_D(QPieSeries); |
|
608 | 608 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); |
|
609 | 609 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); |
|
610 | 610 | } |
|
611 | 611 | |
|
612 | 612 | qreal QPieSeries::holeSize() const |
|
613 | 613 | { |
|
614 | 614 | Q_D(const QPieSeries); |
|
615 | 615 | return d->m_holeRelativeSize; |
|
616 | 616 | } |
|
617 | 617 | |
|
618 | 618 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
619 | 619 | { |
|
620 | 620 | Q_D(QPieSeries); |
|
621 | 621 | |
|
622 | 622 | if (relativePosition < 0.0) |
|
623 | 623 | relativePosition = 0.0; |
|
624 | 624 | if (relativePosition > 1.0) |
|
625 | 625 | relativePosition = 1.0; |
|
626 | 626 | |
|
627 | 627 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { |
|
628 | 628 | d->m_pieRelativeHorPos = relativePosition; |
|
629 | 629 | emit d->horizontalPositionChanged(); |
|
630 | 630 | } |
|
631 | 631 | } |
|
632 | 632 | |
|
633 | 633 | qreal QPieSeries::horizontalPosition() const |
|
634 | 634 | { |
|
635 | 635 | Q_D(const QPieSeries); |
|
636 | 636 | return d->m_pieRelativeHorPos; |
|
637 | 637 | } |
|
638 | 638 | |
|
639 | 639 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
640 | 640 | { |
|
641 | 641 | Q_D(QPieSeries); |
|
642 | 642 | |
|
643 | 643 | if (relativePosition < 0.0) |
|
644 | 644 | relativePosition = 0.0; |
|
645 | 645 | if (relativePosition > 1.0) |
|
646 | 646 | relativePosition = 1.0; |
|
647 | 647 | |
|
648 | 648 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { |
|
649 | 649 | d->m_pieRelativeVerPos = relativePosition; |
|
650 | 650 | emit d->verticalPositionChanged(); |
|
651 | 651 | } |
|
652 | 652 | } |
|
653 | 653 | |
|
654 | 654 | qreal QPieSeries::verticalPosition() const |
|
655 | 655 | { |
|
656 | 656 | Q_D(const QPieSeries); |
|
657 | 657 | return d->m_pieRelativeVerPos; |
|
658 | 658 | } |
|
659 | 659 | |
|
660 | 660 | void QPieSeries::setPieSize(qreal relativeSize) |
|
661 | 661 | { |
|
662 | 662 | Q_D(QPieSeries); |
|
663 | 663 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
664 | 664 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); |
|
665 | 665 | |
|
666 | 666 | } |
|
667 | 667 | |
|
668 | 668 | qreal QPieSeries::pieSize() const |
|
669 | 669 | { |
|
670 | 670 | Q_D(const QPieSeries); |
|
671 | 671 | return d->m_pieRelativeSize; |
|
672 | 672 | } |
|
673 | 673 | |
|
674 | 674 | |
|
675 | 675 | void QPieSeries::setPieStartAngle(qreal angle) |
|
676 | 676 | { |
|
677 | 677 | Q_D(QPieSeries); |
|
678 | 678 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) |
|
679 | 679 | return; |
|
680 | 680 | d->m_pieStartAngle = angle; |
|
681 | 681 | d->updateDerivativeData(); |
|
682 | 682 | emit d->pieStartAngleChanged(); |
|
683 | 683 | } |
|
684 | 684 | |
|
685 | 685 | qreal QPieSeries::pieStartAngle() const |
|
686 | 686 | { |
|
687 | 687 | Q_D(const QPieSeries); |
|
688 | 688 | return d->m_pieStartAngle; |
|
689 | 689 | } |
|
690 | 690 | |
|
691 | 691 | /*! |
|
692 | 692 | Sets the end angle of the pie. |
|
693 | 693 | |
|
694 | 694 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
695 | 695 | |
|
696 | 696 | \a angle must be greater than start angle. |
|
697 | 697 | |
|
698 | 698 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
699 | 699 | */ |
|
700 | 700 | void QPieSeries::setPieEndAngle(qreal angle) |
|
701 | 701 | { |
|
702 | 702 | Q_D(QPieSeries); |
|
703 | 703 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) |
|
704 | 704 | return; |
|
705 | 705 | d->m_pieEndAngle = angle; |
|
706 | 706 | d->updateDerivativeData(); |
|
707 | 707 | emit d->pieEndAngleChanged(); |
|
708 | 708 | } |
|
709 | 709 | |
|
710 | 710 | /*! |
|
711 | 711 | Returns the end angle of the pie. |
|
712 | 712 | |
|
713 | 713 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
714 | 714 | |
|
715 | 715 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
716 | 716 | */ |
|
717 | 717 | qreal QPieSeries::pieEndAngle() const |
|
718 | 718 | { |
|
719 | 719 | Q_D(const QPieSeries); |
|
720 | 720 | return d->m_pieEndAngle; |
|
721 | 721 | } |
|
722 | 722 | |
|
723 | 723 | /*! |
|
724 | 724 | Sets the all the slice labels \a visible or invisible. |
|
725 | 725 | |
|
726 | 726 | Note that this affects only the current slices in the series. |
|
727 | 727 | If user adds a new slice the default label visibility is false. |
|
728 | 728 | |
|
729 | 729 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
730 | 730 | */ |
|
731 | 731 | void QPieSeries::setLabelsVisible(bool visible) |
|
732 | 732 | { |
|
733 | 733 | Q_D(QPieSeries); |
|
734 | 734 | foreach (QPieSlice *s, d->m_slices) |
|
735 | 735 | s->setLabelVisible(visible); |
|
736 | 736 | } |
|
737 | 737 | |
|
738 | 738 | /*! |
|
739 | 739 | Sets the all the slice labels \a position |
|
740 | 740 | |
|
741 | 741 | Note that this affects only the current slices in the series. |
|
742 | 742 | If user adds a new slice the default label position is LabelOutside |
|
743 | 743 | |
|
744 | 744 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
745 | 745 | */ |
|
746 | 746 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
747 | 747 | { |
|
748 | 748 | Q_D(QPieSeries); |
|
749 | 749 | foreach (QPieSlice *s, d->m_slices) |
|
750 | 750 | s->setLabelPosition(position); |
|
751 | 751 | } |
|
752 | 752 | |
|
753 | 753 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
754 | 754 | |
|
755 | 755 | |
|
756 | 756 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
757 | 757 | QAbstractSeriesPrivate(parent), |
|
758 | 758 | m_pieRelativeHorPos(0.5), |
|
759 | 759 | m_pieRelativeVerPos(0.5), |
|
760 | 760 | m_pieRelativeSize(0.7), |
|
761 | 761 | m_pieStartAngle(0), |
|
762 | 762 | m_pieEndAngle(360), |
|
763 | 763 | m_sum(0), |
|
764 | 764 | m_holeRelativeSize(0.0) |
|
765 | 765 | { |
|
766 | 766 | } |
|
767 | 767 | |
|
768 | 768 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
769 | 769 | { |
|
770 | 770 | } |
|
771 | 771 | |
|
772 | 772 | void QPieSeriesPrivate::updateDerivativeData() |
|
773 | 773 | { |
|
774 | 774 | // calculate sum of all slices |
|
775 | 775 | qreal sum = 0; |
|
776 | 776 | foreach (QPieSlice *s, m_slices) |
|
777 | 777 | sum += s->value(); |
|
778 | 778 | |
|
779 | 779 | if (!qFuzzyCompare(m_sum, sum)) { |
|
780 | 780 | m_sum = sum; |
|
781 | 781 | emit q_func()->sumChanged(); |
|
782 | 782 | } |
|
783 | 783 | |
|
784 | 784 | // nothing to show.. |
|
785 | 785 | if (qFuzzyCompare(m_sum, 0)) |
|
786 | 786 | return; |
|
787 | 787 | |
|
788 | 788 | // update slice attributes |
|
789 | 789 | qreal sliceAngle = m_pieStartAngle; |
|
790 | 790 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
791 | 791 | QVector<QPieSlice *> changed; |
|
792 | 792 | foreach (QPieSlice *s, m_slices) { |
|
793 | 793 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
794 | 794 | d->setPercentage(s->value() / m_sum); |
|
795 | 795 | d->setStartAngle(sliceAngle); |
|
796 | 796 | d->setAngleSpan(pieSpan * s->percentage()); |
|
797 | 797 | sliceAngle += s->angleSpan(); |
|
798 | 798 | } |
|
799 | 799 | |
|
800 | 800 | |
|
801 | 801 | emit calculatedDataChanged(); |
|
802 | 802 | } |
|
803 | 803 | |
|
804 | 804 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
805 | 805 | { |
|
806 | 806 | bool changed = false; |
|
807 | 807 | |
|
808 | 808 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { |
|
809 | 809 | m_holeRelativeSize = innerSize; |
|
810 | 810 | changed = true; |
|
811 | 811 | } |
|
812 | 812 | |
|
813 | 813 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { |
|
814 | 814 | m_pieRelativeSize = outerSize; |
|
815 | 815 | changed = true; |
|
816 | 816 | } |
|
817 | 817 | |
|
818 | 818 | if (changed) |
|
819 | 819 | emit pieSizeChanged(); |
|
820 | 820 | } |
|
821 | 821 | |
|
822 | 822 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
823 | 823 | { |
|
824 | 824 | return series->d_func(); |
|
825 | 825 | } |
|
826 | 826 | |
|
827 | 827 | void QPieSeriesPrivate::sliceValueChanged() |
|
828 | 828 | { |
|
829 | 829 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
830 | 830 | updateDerivativeData(); |
|
831 | 831 | } |
|
832 | 832 | |
|
833 | 833 | void QPieSeriesPrivate::sliceClicked() |
|
834 | 834 | { |
|
835 | 835 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
836 | 836 | Q_ASSERT(m_slices.contains(slice)); |
|
837 | 837 | Q_Q(QPieSeries); |
|
838 | 838 | emit q->clicked(slice); |
|
839 | 839 | } |
|
840 | 840 | |
|
841 | 841 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
842 | 842 | { |
|
843 | 843 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
844 | 844 | Q_ASSERT(m_slices.contains(slice)); |
|
845 | 845 | Q_Q(QPieSeries); |
|
846 | 846 | emit q->hovered(slice, state); |
|
847 | 847 | } |
|
848 | 848 | |
|
849 | 849 | void QPieSeriesPrivate::initializeDomain() |
|
850 | 850 | { |
|
851 | 851 | // does not apply to pie |
|
852 | 852 | } |
|
853 | 853 | |
|
854 | 854 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
855 | 855 | { |
|
856 | 856 | Q_Q(QPieSeries); |
|
857 | 857 | PieChartItem *pie = new PieChartItem(q,parent); |
|
858 | 858 | m_item.reset(pie); |
|
859 | 859 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
860 | 860 | } |
|
861 | 861 | |
|
862 | 862 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
863 | 863 | { |
|
864 | 864 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); |
|
865 | 865 | Q_ASSERT(item); |
|
866 | 866 | if (item->animation()) |
|
867 | 867 | item->animation()->stopAndDestroyLater(); |
|
868 | 868 | |
|
869 | 869 | if (options.testFlag(QChart::SeriesAnimations)) |
|
870 | 870 | item->setAnimation(new PieAnimation(item)); |
|
871 | 871 | else |
|
872 | 872 | item->setAnimation(0); |
|
873 | 873 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
874 | 874 | } |
|
875 | 875 | |
|
876 | 876 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
877 | 877 | { |
|
878 | 878 | Q_Q(QPieSeries); |
|
879 | 879 | QList<QLegendMarker*> markers; |
|
880 | 880 | foreach(QPieSlice* slice, q->slices()) { |
|
881 | 881 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); |
|
882 | 882 | markers << marker; |
|
883 | 883 | } |
|
884 | 884 | return markers; |
|
885 | 885 | } |
|
886 | 886 | |
|
887 | 887 | void QPieSeriesPrivate::initializeAxes() |
|
888 | 888 | { |
|
889 | 889 | |
|
890 | 890 | } |
|
891 | 891 | |
|
892 | 892 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
893 | 893 | { |
|
894 | 894 | Q_UNUSED(orientation); |
|
895 | 895 | return QAbstractAxis::AxisTypeNoAxis; |
|
896 | 896 | } |
|
897 | 897 | |
|
898 | 898 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
899 | 899 | { |
|
900 | 900 | Q_UNUSED(orientation); |
|
901 | 901 | return 0; |
|
902 | 902 | } |
|
903 | 903 | |
|
904 | 904 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
905 | 905 | { |
|
906 | 906 | //Q_Q(QPieSeries); |
|
907 | 907 | //const QList<QColor>& colors = theme->seriesColors(); |
|
908 | 908 | const QList<QGradient>& gradients = theme->seriesGradients(); |
|
909 | 909 | |
|
910 | 910 | for (int i(0); i < m_slices.count(); i++) { |
|
911 | 911 | |
|
912 | 912 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); |
|
913 | 913 | |
|
914 | 914 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
915 | 915 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); |
|
916 | 916 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); |
|
917 | 917 | |
|
918 | 918 | QPieSlice *s = m_slices.at(i); |
|
919 | 919 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
920 | 920 | |
|
921 | 921 | if (forced || d->m_data.m_slicePen.isThemed()) |
|
922 | 922 | d->setPen(penColor, true); |
|
923 | 923 | |
|
924 | 924 | if (forced || d->m_data.m_sliceBrush.isThemed()) |
|
925 | 925 | d->setBrush(brushColor, true); |
|
926 | 926 | |
|
927 | 927 | if (forced || d->m_data.m_labelBrush.isThemed()) |
|
928 | 928 | d->setLabelBrush(theme->labelBrush().color(), true); |
|
929 | 929 | |
|
930 | 930 | if (forced || d->m_data.m_labelFont.isThemed()) |
|
931 | 931 | d->setLabelFont(theme->labelFont(), true); |
|
932 | 932 | } |
|
933 | 933 | } |
|
934 | 934 | |
|
935 | 935 | |
|
936 | 936 | #include "moc_qpieseries.cpp" |
|
937 | 937 | #include "moc_qpieseries_p.cpp" |
|
938 | 938 | |
|
939 | 939 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,312 +1,312 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 "qabstractseries.h" |
|
22 | 22 | #include "qabstractseries_p.h" |
|
23 | 23 | #include "chartdataset_p.h" |
|
24 | 24 | #include "qchart.h" |
|
25 | 25 | #include "qchart_p.h" |
|
26 | 26 | #include "chartitem_p.h" |
|
27 | 27 | #include "xydomain_p.h" |
|
28 | 28 | #include "xlogydomain_p.h" |
|
29 | 29 | #include "logxydomain_p.h" |
|
30 | 30 | #include "logxlogydomain_p.h" |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | /*! |
|
35 | 35 | \class QAbstractSeries |
|
36 |
\brief Base class for all Qt |
|
|
36 | \brief Base class for all Qt Chart series. | |
|
37 | 37 | \mainclass |
|
38 | 38 | |
|
39 | 39 | Usually you use the series type specific inherited classes instead of the base class. |
|
40 | 40 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
41 | 41 | QPercentBarSeries, QPieSeries |
|
42 | 42 | */ |
|
43 | 43 | /*! |
|
44 | 44 | \qmlclass AbstractSeries |
|
45 | 45 | AbstractSeries is the base class for all series. |
|
46 | 46 | The class cannot be instantiated by the user. |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \enum QAbstractSeries::SeriesType |
|
51 | 51 | |
|
52 | 52 | The type of the series object. |
|
53 | 53 | |
|
54 | 54 | \value SeriesTypeLine |
|
55 | 55 | \value SeriesTypeArea |
|
56 | 56 | \value SeriesTypeBar |
|
57 | 57 | \value SeriesTypeStackedBar |
|
58 | 58 | \value SeriesTypePercentBar |
|
59 | 59 | \value SeriesTypePie |
|
60 | 60 | \value SeriesTypeScatter |
|
61 | 61 | \value SeriesTypeSpline |
|
62 | 62 | \value SeriesTypeHorizontalBar |
|
63 | 63 | \value SeriesTypeHorizontalStackedBar |
|
64 | 64 | \value SeriesTypeHorizontalPercentBar |
|
65 | 65 | \value SeriesTypeBoxPlot |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QAbstractSeries::type |
|
70 | 70 | The type of the series. |
|
71 | 71 | */ |
|
72 | 72 | /*! |
|
73 | 73 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
74 | 74 | The type of the series. |
|
75 | 75 | */ |
|
76 | 76 | |
|
77 | 77 | /*! |
|
78 | 78 | \property QAbstractSeries::name |
|
79 | 79 | \brief name of the series property. The name is shown in legend for series and supports html formatting. |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty string AbstractSeries::name |
|
83 | 83 | Name of the series. The name is shown in legend for series and supports html formatting. |
|
84 | 84 | */ |
|
85 | 85 | |
|
86 | 86 | /*! |
|
87 | 87 | \fn void QAbstractSeries::nameChanged() |
|
88 | 88 | This signal is emitted when the series name changes. |
|
89 | 89 | */ |
|
90 | 90 | /*! |
|
91 | 91 | \qmlsignal AbstractSeries::onNameChanged() |
|
92 | 92 | This signal is emitted when the series name changes. |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | \property QAbstractSeries::visible |
|
97 | 97 | \brief whether the series is visible or not; true by default. |
|
98 | 98 | */ |
|
99 | 99 | /*! |
|
100 | 100 | \qmlproperty bool AbstractSeries::visible |
|
101 | 101 | Visibility of the series. True by default. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \fn void QAbstractSeries::visibleChanged() |
|
106 | 106 | Emitted when the series visibility changes. |
|
107 | 107 | */ |
|
108 | 108 | /*! |
|
109 | 109 | \qmlsignal AbstractSeries::onVisibleChanged() |
|
110 | 110 | Emitted when the series visibility changes. |
|
111 | 111 | */ |
|
112 | 112 | |
|
113 | 113 | /*! |
|
114 | 114 | \property QAbstractSeries::opacity |
|
115 | 115 | \brief The opacity of the series. |
|
116 | 116 | |
|
117 | 117 | By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
118 | 118 | */ |
|
119 | 119 | /*! |
|
120 | 120 | \qmlproperty real AbstractSeries::opacity |
|
121 | 121 | The opacity of the series. By default the opacity is 1.0. |
|
122 | 122 | The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \fn void QAbstractSeries::opacityChanged() |
|
127 | 127 | Emitted when the opacity of the series changes. |
|
128 | 128 | */ |
|
129 | 129 | /*! |
|
130 | 130 | \qmlsignal AbstractSeries::onOpacityChanged() |
|
131 | 131 | Emitted when the opacity of the series changes. |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \internal |
|
136 | 136 | \brief Constructs QAbstractSeries object with \a parent. |
|
137 | 137 | */ |
|
138 | 138 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
139 | 139 | QObject(parent), |
|
140 | 140 | d_ptr(&d) |
|
141 | 141 | { |
|
142 | 142 | } |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \brief Virtual destructor for the chart series. |
|
146 | 146 | */ |
|
147 | 147 | QAbstractSeries::~QAbstractSeries() |
|
148 | 148 | { |
|
149 | 149 | if (d_ptr->m_chart) |
|
150 | 150 | qFatal("Series still bound to a chart when destroyed!"); |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | void QAbstractSeries::setName(const QString &name) |
|
154 | 154 | { |
|
155 | 155 | if (name != d_ptr->m_name) { |
|
156 | 156 | d_ptr->m_name = name; |
|
157 | 157 | emit nameChanged(); |
|
158 | 158 | } |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | QString QAbstractSeries::name() const |
|
162 | 162 | { |
|
163 | 163 | return d_ptr->m_name; |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | void QAbstractSeries::setVisible(bool visible) |
|
167 | 167 | { |
|
168 | 168 | if (visible != d_ptr->m_visible) { |
|
169 | 169 | d_ptr->m_visible = visible; |
|
170 | 170 | emit visibleChanged(); |
|
171 | 171 | } |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | bool QAbstractSeries::isVisible() const |
|
175 | 175 | { |
|
176 | 176 | return d_ptr->m_visible; |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | qreal QAbstractSeries::opacity() const |
|
180 | 180 | { |
|
181 | 181 | return d_ptr->m_opacity; |
|
182 | 182 | } |
|
183 | 183 | |
|
184 | 184 | void QAbstractSeries::setOpacity(qreal opacity) |
|
185 | 185 | { |
|
186 | 186 | if (opacity != d_ptr->m_opacity) { |
|
187 | 187 | d_ptr->m_opacity = opacity; |
|
188 | 188 | emit opacityChanged(); |
|
189 | 189 | } |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | \brief Returns the chart where series belongs to. |
|
194 | 194 | |
|
195 | 195 | Set automatically when the series is added to the chart |
|
196 | 196 | and unset when the series is removed from the chart. |
|
197 | 197 | */ |
|
198 | 198 | QChart *QAbstractSeries::chart() const |
|
199 | 199 | { |
|
200 | 200 | return d_ptr->m_chart; |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | \brief Sets the visibility of the series to true. |
|
205 | 205 | |
|
206 | 206 | \sa setVisible(), isVisible() |
|
207 | 207 | */ |
|
208 | 208 | void QAbstractSeries::show() |
|
209 | 209 | { |
|
210 | 210 | setVisible(true); |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | \brief Sets the visibility of the series to false. |
|
215 | 215 | |
|
216 | 216 | \sa setVisible(), isVisible() |
|
217 | 217 | */ |
|
218 | 218 | void QAbstractSeries::hide() |
|
219 | 219 | { |
|
220 | 220 | setVisible(false); |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | /*! |
|
224 | 224 | Attach \a axis to the series. |
|
225 | 225 | \return true if the axis was attached successfully, false otherwise. |
|
226 | 226 | \note If multiple axes of same orientation are attached to same series, |
|
227 | 227 | they will have same min/max ranges. |
|
228 | 228 | \sa QChart::addAxis(), QChart::createDefaultAxes() |
|
229 | 229 | */ |
|
230 | 230 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) |
|
231 | 231 | { |
|
232 | 232 | if(d_ptr->m_chart) { |
|
233 | 233 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis); |
|
234 | 234 | } else { |
|
235 | 235 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
236 | 236 | return false; |
|
237 | 237 | } |
|
238 | 238 | } |
|
239 | 239 | |
|
240 | 240 | /*! |
|
241 | 241 | Detach \a axis from the series. |
|
242 | 242 | \return true if the axis was detached successfully, false otherwise. |
|
243 | 243 | \sa QChart::removeAxis() |
|
244 | 244 | */ |
|
245 | 245 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) |
|
246 | 246 | { |
|
247 | 247 | if(d_ptr->m_chart) { |
|
248 | 248 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis); |
|
249 | 249 | } |
|
250 | 250 | else { |
|
251 | 251 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
252 | 252 | return false; |
|
253 | 253 | } |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | /*! |
|
257 | 257 | Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except |
|
258 | 258 | in case of a QPieSeries, which does not have any axes attached. |
|
259 | 259 | \sa attachAxis(), detachAxis() |
|
260 | 260 | */ |
|
261 | 261 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() |
|
262 | 262 | { |
|
263 | 263 | return d_ptr->m_axes; |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | 266 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
267 | 267 | |
|
268 | 268 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) |
|
269 | 269 | : q_ptr(q), |
|
270 | 270 | m_chart(0), |
|
271 | 271 | m_item(0), |
|
272 | 272 | m_domain(new XYDomain()), |
|
273 | 273 | m_visible(true), |
|
274 | 274 | m_opacity(1.0) |
|
275 | 275 | { |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
279 | 279 | { |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) |
|
283 | 283 | { |
|
284 | 284 | Q_ASSERT(domain); |
|
285 | 285 | if(m_domain.data()!=domain) { |
|
286 | 286 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); |
|
287 | 287 | m_domain.reset(domain); |
|
288 | 288 | if(!m_item.isNull()) { |
|
289 | 289 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
290 | 290 | m_item->handleDomainUpdated(); |
|
291 | 291 | } |
|
292 | 292 | } |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
296 | 296 | { |
|
297 | 297 | Q_ASSERT(!m_item.isNull()); |
|
298 | 298 | Q_UNUSED(parent); |
|
299 | 299 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
300 | 300 | } |
|
301 | 301 | |
|
302 | 302 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
303 | 303 | { |
|
304 | 304 | Q_UNUSED(options); |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | #include "moc_qabstractseries.cpp" |
|
308 | 308 | #include "moc_qabstractseries_p.cpp" |
|
309 | 309 | |
|
310 | 310 | QTCOMMERCIALCHART_END_NAMESPACE |
|
311 | 311 | |
|
312 | 312 |
@@ -1,826 +1,826 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include "legendscroller_p.h" |
|
24 | 24 | #include "qlegend_p.h" |
|
25 | 25 | #include "chartbackground_p.h" |
|
26 | 26 | #include "qabstractaxis.h" |
|
27 | 27 | #include "abstractchartlayout_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartpresenter_p.h" |
|
30 | 30 | #include "chartdataset_p.h" |
|
31 | 31 | #include <QGraphicsScene> |
|
32 | 32 | #include <QGraphicsSceneResizeEvent> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \enum QChart::ChartTheme |
|
38 | 38 | |
|
39 | 39 | This enum describes the theme used by the chart. |
|
40 | 40 | |
|
41 | 41 | \value ChartThemeLight The default theme |
|
42 | 42 | \value ChartThemeBlueCerulean |
|
43 | 43 | \value ChartThemeDark |
|
44 | 44 | \value ChartThemeBrownSand |
|
45 | 45 | \value ChartThemeBlueNcs |
|
46 | 46 | \value ChartThemeHighContrast |
|
47 | 47 | \value ChartThemeBlueIcy |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | /*! |
|
51 | 51 | \enum QChart::AnimationOption |
|
52 | 52 | |
|
53 | 53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
54 | 54 | |
|
55 | 55 | \value NoAnimation |
|
56 | 56 | \value GridAxisAnimations |
|
57 | 57 | \value SeriesAnimations |
|
58 | 58 | \value AllAnimations |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \enum QChart::ChartType |
|
63 | 63 | |
|
64 | 64 | This enum describes the chart type. |
|
65 | 65 | |
|
66 | 66 | \value ChartTypeUndefined |
|
67 | 67 | \value ChartTypeCartesian |
|
68 | 68 | \value ChartTypePolar |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \class QChart |
|
73 | \brief Qt Enterprise Chart API. | |
|
73 | \brief Main chart API for Qt Charts. | |
|
74 | 74 | |
|
75 | 75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
76 | 76 | representation of different types of series and other chart related objects like legend and |
|
77 | 77 | axes. If you simply want to show a chart in a layout, you can use the |
|
78 | 78 | convenience class QChartView instead of QChart. |
|
79 | 79 | \sa QChartView, QPolarChart |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \property QChart::animationOptions |
|
84 | 84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QChart::backgroundVisible |
|
89 | 89 | Specifies whether the chart background is visible or not. |
|
90 | 90 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \property QChart::dropShadowEnabled |
|
95 | 95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
96 | 96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QChart::backgroundRoundness |
|
101 | 101 | The diameter of the rounding cirle at the corners of the chart background. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \property QChart::minimumMargins |
|
106 | 106 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
107 | 107 | This property is deprecated; use margins property instead. |
|
108 | 108 | |
|
109 | 109 | \sa margins |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \property QChart::margins |
|
114 | 114 | Margins between the plot area (axes) and the edge of the chart widget. |
|
115 | 115 | */ |
|
116 | 116 | |
|
117 | 117 | /*! |
|
118 | 118 | \property QChart::theme |
|
119 | 119 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
120 | 120 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few |
|
121 | 121 | different themes. |
|
122 | 122 | \note Changing the theme will overwrite all customizations previously applied to the series. |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \property QChart::title |
|
127 | 127 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting. |
|
128 | 128 | */ |
|
129 | 129 | |
|
130 | 130 | /*! |
|
131 | 131 | \property QChart::chartType |
|
132 | 132 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
133 | 133 | This property is set internally and it is read only. |
|
134 | 134 | \sa QPolarChart |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \property QChart::plotAreaBackgroundVisible |
|
139 | 139 | Specifies whether the chart plot area background is visible or not. |
|
140 | 140 | \note By default the plot area background is not visible and the plot area uses |
|
141 | 141 | the general chart background. |
|
142 | 142 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \internal |
|
147 | 147 | Constructs a chart object of \a type which is a child of a \a parent. |
|
148 | 148 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
149 | 149 | This constructor is called only by subclasses. |
|
150 | 150 | */ |
|
151 | 151 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
152 | 152 | : QGraphicsWidget(parent, wFlags), |
|
153 | 153 | d_ptr(new QChartPrivate(this, type)) |
|
154 | 154 | { |
|
155 | 155 | d_ptr->init(); |
|
156 | 156 | } |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | 159 | Constructs a chart object which is a child of a \a parent. |
|
160 | 160 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
161 | 161 | */ |
|
162 | 162 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
163 | 163 | : QGraphicsWidget(parent, wFlags), |
|
164 | 164 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
165 | 165 | { |
|
166 | 166 | d_ptr->init(); |
|
167 | 167 | } |
|
168 | 168 | |
|
169 | 169 | /*! |
|
170 | 170 | Destroys the chart object and its children, like series and axis objects added to it. |
|
171 | 171 | */ |
|
172 | 172 | QChart::~QChart() |
|
173 | 173 | { |
|
174 | 174 | //start by deleting dataset, it will remove all series and axes |
|
175 | 175 | delete d_ptr->m_dataset; |
|
176 | 176 | d_ptr->m_dataset = 0; |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | Adds the \a series onto the chart and takes the ownership of it. |
|
181 | 181 | |
|
182 | 182 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart |
|
183 | 183 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to |
|
184 | 184 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges |
|
185 | 185 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other |
|
186 | 186 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after |
|
187 | 187 | a series has been added or explicitly attach axes for the series. |
|
188 | 188 | |
|
189 | 189 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
190 | 190 | */ |
|
191 | 191 | void QChart::addSeries(QAbstractSeries *series) |
|
192 | 192 | { |
|
193 | 193 | Q_ASSERT(series); |
|
194 | 194 | d_ptr->m_dataset->addSeries(series); |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | /*! |
|
198 | 198 | Removes the \a series from the chart. |
|
199 | 199 | The chart releases its ownership of the specified \a series object. |
|
200 | 200 | |
|
201 | 201 | \sa addSeries(), removeAllSeries() |
|
202 | 202 | */ |
|
203 | 203 | void QChart::removeSeries(QAbstractSeries *series) |
|
204 | 204 | { |
|
205 | 205 | Q_ASSERT(series); |
|
206 | 206 | d_ptr->m_dataset->removeSeries(series); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | /*! |
|
210 | 210 | Removes and deletes all series objects that have been added to the chart. |
|
211 | 211 | |
|
212 | 212 | \sa addSeries(), removeSeries() |
|
213 | 213 | */ |
|
214 | 214 | void QChart::removeAllSeries() |
|
215 | 215 | { |
|
216 | 216 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
217 | 217 | removeSeries(s); |
|
218 | 218 | delete s; |
|
219 | 219 | } |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | /*! |
|
223 | 223 | Sets the \a brush that is used for painting the background of the chart area. |
|
224 | 224 | */ |
|
225 | 225 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
226 | 226 | { |
|
227 | 227 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | Gets the brush that is used for painting the background of the chart area. |
|
232 | 232 | */ |
|
233 | 233 | QBrush QChart::backgroundBrush() const |
|
234 | 234 | { |
|
235 | 235 | return d_ptr->m_presenter->backgroundBrush(); |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | /*! |
|
239 | 239 | Sets the \a pen that is used for painting the background of the chart area. |
|
240 | 240 | */ |
|
241 | 241 | void QChart::setBackgroundPen(const QPen &pen) |
|
242 | 242 | { |
|
243 | 243 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
244 | 244 | } |
|
245 | 245 | |
|
246 | 246 | /*! |
|
247 | 247 | Gets the pen that is used for painting the background of the chart area. |
|
248 | 248 | */ |
|
249 | 249 | QPen QChart::backgroundPen() const |
|
250 | 250 | { |
|
251 | 251 | return d_ptr->m_presenter->backgroundPen(); |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | void QChart::setTitle(const QString &title) |
|
255 | 255 | { |
|
256 | 256 | d_ptr->m_presenter->setTitle(title); |
|
257 | 257 | } |
|
258 | 258 | |
|
259 | 259 | QString QChart::title() const |
|
260 | 260 | { |
|
261 | 261 | return d_ptr->m_presenter->title(); |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | /*! |
|
265 | 265 | Sets the \a font that is used for drawing the chart title. |
|
266 | 266 | */ |
|
267 | 267 | void QChart::setTitleFont(const QFont &font) |
|
268 | 268 | { |
|
269 | 269 | d_ptr->m_presenter->setTitleFont(font); |
|
270 | 270 | } |
|
271 | 271 | |
|
272 | 272 | /*! |
|
273 | 273 | Gets the font that is used for drawing the chart title. |
|
274 | 274 | */ |
|
275 | 275 | QFont QChart::titleFont() const |
|
276 | 276 | { |
|
277 | 277 | return d_ptr->m_presenter->titleFont(); |
|
278 | 278 | } |
|
279 | 279 | |
|
280 | 280 | /*! |
|
281 | 281 | Sets the \a brush used for drawing the title text. |
|
282 | 282 | */ |
|
283 | 283 | void QChart::setTitleBrush(const QBrush &brush) |
|
284 | 284 | { |
|
285 | 285 | d_ptr->m_presenter->setTitleBrush(brush); |
|
286 | 286 | } |
|
287 | 287 | |
|
288 | 288 | /*! |
|
289 | 289 | Returns the brush used for drawing the title text. |
|
290 | 290 | */ |
|
291 | 291 | QBrush QChart::titleBrush() const |
|
292 | 292 | { |
|
293 | 293 | return d_ptr->m_presenter->titleBrush(); |
|
294 | 294 | } |
|
295 | 295 | |
|
296 | 296 | void QChart::setTheme(QChart::ChartTheme theme) |
|
297 | 297 | { |
|
298 | 298 | d_ptr->m_themeManager->setTheme(theme); |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | QChart::ChartTheme QChart::theme() const |
|
302 | 302 | { |
|
303 | 303 | return d_ptr->m_themeManager->theme()->id(); |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | /*! |
|
307 | 307 | Zooms in the view by a factor of two. |
|
308 | 308 | */ |
|
309 | 309 | void QChart::zoomIn() |
|
310 | 310 | { |
|
311 | 311 | d_ptr->zoomIn(2.0); |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | /*! |
|
315 | 315 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
316 | 316 | \note This is not supported for polar charts. |
|
317 | 317 | */ |
|
318 | 318 | void QChart::zoomIn(const QRectF &rect) |
|
319 | 319 | { |
|
320 | 320 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
321 | 321 | return; |
|
322 | 322 | d_ptr->zoomIn(rect); |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | /*! |
|
326 | 326 | Zooms out the view by a factor of two. |
|
327 | 327 | */ |
|
328 | 328 | void QChart::zoomOut() |
|
329 | 329 | { |
|
330 | 330 | d_ptr->zoomOut(2.0); |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Zooms in the view by a custom \a factor. |
|
335 | 335 | |
|
336 | 336 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
337 | 337 | */ |
|
338 | 338 | void QChart::zoom(qreal factor) |
|
339 | 339 | { |
|
340 | 340 | if (qFuzzyCompare(factor, 0)) |
|
341 | 341 | return; |
|
342 | 342 | |
|
343 | 343 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
344 | 344 | return; |
|
345 | 345 | |
|
346 | 346 | if (factor < 0) |
|
347 | 347 | return; |
|
348 | 348 | |
|
349 | 349 | if (factor > 1.0) |
|
350 | 350 | d_ptr->zoomIn(factor); |
|
351 | 351 | else |
|
352 | 352 | d_ptr->zoomOut(1.0 / factor); |
|
353 | 353 | } |
|
354 | 354 | |
|
355 | 355 | |
|
356 | 356 | /*! |
|
357 | 357 | Resets the series domains to what they were before any zoom method was called. |
|
358 | 358 | Note that this will also reset any scrolls and explicit axis range settings done between |
|
359 | 359 | the first zoom operation and calling this method. If no zoom operation has been |
|
360 | 360 | done, this method does nothing. |
|
361 | 361 | */ |
|
362 | 362 | void QChart::zoomReset() |
|
363 | 363 | { |
|
364 | 364 | d_ptr->zoomReset(); |
|
365 | 365 | } |
|
366 | 366 | |
|
367 | 367 | /*! |
|
368 | 368 | Returns true if any series has a zoomed domain. |
|
369 | 369 | */ |
|
370 | 370 | bool QChart::isZoomed() |
|
371 | 371 | { |
|
372 | 372 | return d_ptr->isZoomed(); |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | /*! |
|
376 | 376 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
377 | 377 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
|
378 | 378 | |
|
379 | 379 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
380 | 380 | */ |
|
381 | 381 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
382 | 382 | { |
|
383 | 383 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
384 | 384 | if (axisList.count()) |
|
385 | 385 | return axisList[0]; |
|
386 | 386 | return 0; |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | /*! |
|
390 | 390 | Returns a pointer to the vertical axis attached to the specified \a series. |
|
391 | 391 | If no \a series is specified, the first vertical axis added to the chart is returned. |
|
392 | 392 | |
|
393 | 393 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
394 | 394 | */ |
|
395 | 395 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
396 | 396 | { |
|
397 | 397 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
398 | 398 | if (axisList.count()) |
|
399 | 399 | return axisList[0]; |
|
400 | 400 | return 0; |
|
401 | 401 | } |
|
402 | 402 | |
|
403 | 403 | /*! |
|
404 | 404 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, |
|
405 | 405 | then all axes added to the chart with the specified orientation are returned. |
|
406 | 406 | \sa addAxis(), createDefaultAxes() |
|
407 | 407 | */ |
|
408 | 408 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
409 | 409 | { |
|
410 | 410 | QList<QAbstractAxis *> result ; |
|
411 | 411 | |
|
412 | 412 | if (series) { |
|
413 | 413 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
414 | 414 | if (orientation.testFlag(axis->orientation())) |
|
415 | 415 | result << axis; |
|
416 | 416 | } |
|
417 | 417 | } else { |
|
418 | 418 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
419 | 419 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
420 | 420 | result << axis; |
|
421 | 421 | } |
|
422 | 422 | } |
|
423 | 423 | |
|
424 | 424 | return result; |
|
425 | 425 | } |
|
426 | 426 | |
|
427 | 427 | /*! |
|
428 | 428 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to |
|
429 | 429 | the chart will be deleted. |
|
430 | 430 | |
|
431 | 431 | \note This function has to be called after all series have been added to the chart. The axes created by this function |
|
432 | 432 | will NOT get automatically attached to any series added to the chart after this function has been called. |
|
433 | 433 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing |
|
434 | 434 | if there are other series with properly attached axes also present. |
|
435 | 435 | |
|
436 | 436 | \table |
|
437 | 437 | \header |
|
438 | 438 | \o Series type |
|
439 | 439 | \o X-axis |
|
440 | 440 | \o Y-axis |
|
441 | 441 | \row |
|
442 | 442 | \o QXYSeries |
|
443 | 443 | \o QValueAxis |
|
444 | 444 | \o QValueAxis |
|
445 | 445 | \row |
|
446 | 446 | \o QBarSeries |
|
447 | 447 | \o QBarCategoryAxis |
|
448 | 448 | \o QValueAxis |
|
449 | 449 | \row |
|
450 | 450 | \o QPieSeries |
|
451 | 451 | \o None |
|
452 | 452 | \o None |
|
453 | 453 | \endtable |
|
454 | 454 | |
|
455 | 455 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. |
|
456 | 456 | If there are several series of different types added to the chart, then each series gets its own axes pair. |
|
457 | 457 | |
|
458 | 458 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. |
|
459 | 459 | QPieSeries does not create any axes. |
|
460 | 460 | |
|
461 | 461 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() |
|
462 | 462 | */ |
|
463 | 463 | void QChart::createDefaultAxes() |
|
464 | 464 | { |
|
465 | 465 | d_ptr->m_dataset->createDefaultAxes(); |
|
466 | 466 | } |
|
467 | 467 | |
|
468 | 468 | /*! |
|
469 | 469 | Returns the legend object of the chart. Ownership stays with the chart. |
|
470 | 470 | */ |
|
471 | 471 | QLegend *QChart::legend() const |
|
472 | 472 | { |
|
473 | 473 | return d_ptr->m_legend; |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | void QChart::setMinimumMargins(const QMargins &margins) |
|
477 | 477 | { |
|
478 | 478 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
479 | 479 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
480 | 480 | } |
|
481 | 481 | |
|
482 | 482 | QMargins QChart::minimumMargins() const |
|
483 | 483 | { |
|
484 | 484 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
485 | 485 | return d_ptr->m_presenter->layout()->margins(); |
|
486 | 486 | } |
|
487 | 487 | |
|
488 | 488 | void QChart::setMargins(const QMargins &margins) |
|
489 | 489 | { |
|
490 | 490 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
491 | 491 | } |
|
492 | 492 | |
|
493 | 493 | QMargins QChart::margins() const |
|
494 | 494 | { |
|
495 | 495 | return d_ptr->m_presenter->layout()->margins(); |
|
496 | 496 | } |
|
497 | 497 | |
|
498 | 498 | QChart::ChartType QChart::chartType() const |
|
499 | 499 | { |
|
500 | 500 | return d_ptr->m_type; |
|
501 | 501 | } |
|
502 | 502 | |
|
503 | 503 | /*! |
|
504 | 504 | Returns the the rectangle within which the drawing of the chart is done. |
|
505 | 505 | It does not include the area defined by margins. |
|
506 | 506 | */ |
|
507 | 507 | QRectF QChart::plotArea() const |
|
508 | 508 | { |
|
509 | 509 | return d_ptr->m_presenter->geometry(); |
|
510 | 510 | } |
|
511 | 511 | |
|
512 | 512 | /*! |
|
513 | 513 | Sets the \a brush for the background of the plot area of the chart. |
|
514 | 514 | |
|
515 | 515 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() |
|
516 | 516 | */ |
|
517 | 517 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) |
|
518 | 518 | { |
|
519 | 519 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); |
|
520 | 520 | } |
|
521 | 521 | |
|
522 | 522 | /*! |
|
523 | 523 | Returns the brush for the background of the plot area of the chart. |
|
524 | 524 | |
|
525 | 525 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() |
|
526 | 526 | */ |
|
527 | 527 | QBrush QChart::plotAreaBackgroundBrush() const |
|
528 | 528 | { |
|
529 | 529 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); |
|
530 | 530 | } |
|
531 | 531 | |
|
532 | 532 | /*! |
|
533 | 533 | Sets the \a pen for the background of the plot area of the chart. |
|
534 | 534 | |
|
535 | 535 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() |
|
536 | 536 | */ |
|
537 | 537 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) |
|
538 | 538 | { |
|
539 | 539 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); |
|
540 | 540 | } |
|
541 | 541 | |
|
542 | 542 | /*! |
|
543 | 543 | Returns the pen for the background of the plot area of the chart. |
|
544 | 544 | |
|
545 | 545 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() |
|
546 | 546 | */ |
|
547 | 547 | QPen QChart::plotAreaBackgroundPen() const |
|
548 | 548 | { |
|
549 | 549 | return d_ptr->m_presenter->plotAreaBackgroundPen(); |
|
550 | 550 | } |
|
551 | 551 | |
|
552 | 552 | void QChart::setPlotAreaBackgroundVisible(bool visible) |
|
553 | 553 | { |
|
554 | 554 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); |
|
555 | 555 | } |
|
556 | 556 | |
|
557 | 557 | bool QChart::isPlotAreaBackgroundVisible() const |
|
558 | 558 | { |
|
559 | 559 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); |
|
560 | 560 | } |
|
561 | 561 | |
|
562 | 562 | void QChart::setAnimationOptions(AnimationOptions options) |
|
563 | 563 | { |
|
564 | 564 | d_ptr->m_presenter->setAnimationOptions(options); |
|
565 | 565 | } |
|
566 | 566 | |
|
567 | 567 | QChart::AnimationOptions QChart::animationOptions() const |
|
568 | 568 | { |
|
569 | 569 | return d_ptr->m_presenter->animationOptions(); |
|
570 | 570 | } |
|
571 | 571 | |
|
572 | 572 | /*! |
|
573 | 573 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
574 | 574 | |
|
575 | 575 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
576 | 576 | */ |
|
577 | 577 | void QChart::scroll(qreal dx, qreal dy) |
|
578 | 578 | { |
|
579 | 579 | d_ptr->scroll(dx,dy); |
|
580 | 580 | } |
|
581 | 581 | |
|
582 | 582 | void QChart::setBackgroundVisible(bool visible) |
|
583 | 583 | { |
|
584 | 584 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
585 | 585 | } |
|
586 | 586 | |
|
587 | 587 | bool QChart::isBackgroundVisible() const |
|
588 | 588 | { |
|
589 | 589 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | void QChart::setDropShadowEnabled(bool enabled) |
|
593 | 593 | { |
|
594 | 594 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
595 | 595 | } |
|
596 | 596 | |
|
597 | 597 | bool QChart::isDropShadowEnabled() const |
|
598 | 598 | { |
|
599 | 599 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | void QChart::setBackgroundRoundness(qreal diameter) |
|
603 | 603 | { |
|
604 | 604 | d_ptr->m_presenter->setBackgroundRoundness(diameter); |
|
605 | 605 | } |
|
606 | 606 | |
|
607 | 607 | qreal QChart::backgroundRoundness() const |
|
608 | 608 | { |
|
609 | 609 | return d_ptr->m_presenter->backgroundRoundness(); |
|
610 | 610 | } |
|
611 | 611 | |
|
612 | 612 | /*! |
|
613 | 613 | Returns all series that are added to the chart. |
|
614 | 614 | |
|
615 | 615 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
616 | 616 | */ |
|
617 | 617 | QList<QAbstractSeries *> QChart::series() const |
|
618 | 618 | { |
|
619 | 619 | return d_ptr->m_dataset->series(); |
|
620 | 620 | } |
|
621 | 621 | |
|
622 | 622 | /*! |
|
623 | 623 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. |
|
624 | 624 | The chart takes ownership of both the \a axis and the \a series. |
|
625 | 625 | Any horizontal axes previously attached to the \a series are deleted. |
|
626 | 626 | |
|
627 | 627 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
628 | 628 | */ |
|
629 | 629 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) |
|
630 | 630 | { |
|
631 | 631 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); |
|
632 | 632 | |
|
633 | 633 | foreach (QAbstractAxis* a, list) { |
|
634 | 634 | d_ptr->m_dataset->removeAxis(a); |
|
635 | 635 | delete a; |
|
636 | 636 | } |
|
637 | 637 | |
|
638 | 638 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
639 | 639 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); |
|
640 | 640 | d_ptr->m_dataset->attachAxis(series, axis); |
|
641 | 641 | } |
|
642 | 642 | |
|
643 | 643 | /*! |
|
644 | 644 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. |
|
645 | 645 | The chart takes ownership of both the \a axis and the \a series. |
|
646 | 646 | Any vertical axes previously attached to the \a series are deleted. |
|
647 | 647 | |
|
648 | 648 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
649 | 649 | */ |
|
650 | 650 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) |
|
651 | 651 | { |
|
652 | 652 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); |
|
653 | 653 | |
|
654 | 654 | foreach (QAbstractAxis* a, list) { |
|
655 | 655 | d_ptr->m_dataset->removeAxis(a); |
|
656 | 656 | delete a; |
|
657 | 657 | } |
|
658 | 658 | |
|
659 | 659 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
660 | 660 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); |
|
661 | 661 | d_ptr->m_dataset->attachAxis(series, axis); |
|
662 | 662 | } |
|
663 | 663 | |
|
664 | 664 | /*! |
|
665 | 665 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
666 | 666 | |
|
667 | 667 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
668 | 668 | */ |
|
669 | 669 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
670 | 670 | { |
|
671 | 671 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
672 | 672 | } |
|
673 | 673 | |
|
674 | 674 | /*! |
|
675 | 675 | Removes the \a axis from the chart. |
|
676 | 676 | The chart releases its ownership of the specified \a axis object. |
|
677 | 677 | |
|
678 | 678 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
679 | 679 | */ |
|
680 | 680 | void QChart::removeAxis(QAbstractAxis *axis) |
|
681 | 681 | { |
|
682 | 682 | d_ptr->m_dataset->removeAxis(axis); |
|
683 | 683 | } |
|
684 | 684 | |
|
685 | 685 | /*! |
|
686 | 686 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. |
|
687 | 687 | */ |
|
688 | 688 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
689 | 689 | { |
|
690 | 690 | return d_ptr->m_dataset->mapToValue(position, series); |
|
691 | 691 | } |
|
692 | 692 | |
|
693 | 693 | /*! |
|
694 | 694 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. |
|
695 | 695 | */ |
|
696 | 696 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
697 | 697 | { |
|
698 | 698 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
699 | 699 | } |
|
700 | 700 | |
|
701 | 701 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
702 | 702 | |
|
703 | 703 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
704 | 704 | q_ptr(q), |
|
705 | 705 | m_legend(0), |
|
706 | 706 | m_dataset(new ChartDataSet(q)), |
|
707 | 707 | m_presenter(new ChartPresenter(q, type)), |
|
708 | 708 | m_themeManager(new ChartThemeManager(q)), |
|
709 | 709 | m_type(type) |
|
710 | 710 | { |
|
711 | 711 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
712 | 712 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
713 | 713 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
714 | 714 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
715 | 715 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
716 | 716 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
717 | 717 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
718 | 718 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
719 | 719 | } |
|
720 | 720 | |
|
721 | 721 | QChartPrivate::~QChartPrivate() |
|
722 | 722 | { |
|
723 | 723 | } |
|
724 | 724 | |
|
725 | 725 | // Hackish solution to the problem of explicitly assigning the default pen/brush/font |
|
726 | 726 | // to a series or axis and having theme override it: |
|
727 | 727 | // Initialize pens, brushes, and fonts to something nobody is likely to ever use, |
|
728 | 728 | // so that default theme initialization will always set these properly. |
|
729 | 729 | QPen &QChartPrivate::defaultPen() |
|
730 | 730 | { |
|
731 | 731 | static QPen defaultPen(QColor(1, 2, 0), 0.93247536); |
|
732 | 732 | return defaultPen; |
|
733 | 733 | } |
|
734 | 734 | |
|
735 | 735 | QBrush &QChartPrivate::defaultBrush() |
|
736 | 736 | { |
|
737 | 737 | static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern); |
|
738 | 738 | return defaultBrush; |
|
739 | 739 | } |
|
740 | 740 | |
|
741 | 741 | QFont &QChartPrivate::defaultFont() |
|
742 | 742 | { |
|
743 | 743 | static bool defaultFontInitialized(false); |
|
744 | 744 | static QFont defaultFont; |
|
745 | 745 | if (!defaultFontInitialized) { |
|
746 | 746 | defaultFont.setPointSizeF(8.34563465); |
|
747 | 747 | defaultFontInitialized = true; |
|
748 | 748 | } |
|
749 | 749 | return defaultFont; |
|
750 | 750 | } |
|
751 | 751 | |
|
752 | 752 | void QChartPrivate::init() |
|
753 | 753 | { |
|
754 | 754 | m_legend = new LegendScroller(q_ptr); |
|
755 | 755 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
756 | 756 | q_ptr->setLayout(m_presenter->layout()); |
|
757 | 757 | } |
|
758 | 758 | |
|
759 | 759 | void QChartPrivate::zoomIn(qreal factor) |
|
760 | 760 | { |
|
761 | 761 | QRectF rect = m_presenter->geometry(); |
|
762 | 762 | rect.setWidth(rect.width() / factor); |
|
763 | 763 | rect.setHeight(rect.height() / factor); |
|
764 | 764 | rect.moveCenter(m_presenter->geometry().center()); |
|
765 | 765 | zoomIn(rect); |
|
766 | 766 | } |
|
767 | 767 | |
|
768 | 768 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
769 | 769 | { |
|
770 | 770 | if (!rect.isValid()) |
|
771 | 771 | return; |
|
772 | 772 | |
|
773 | 773 | QRectF r = rect.normalized(); |
|
774 | 774 | const QRectF geometry = m_presenter->geometry(); |
|
775 | 775 | r.translate(-geometry.topLeft()); |
|
776 | 776 | |
|
777 | 777 | if (!r.isValid()) |
|
778 | 778 | return; |
|
779 | 779 | |
|
780 | 780 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
781 | 781 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
782 | 782 | m_dataset->zoomInDomain(r); |
|
783 | 783 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
784 | 784 | |
|
785 | 785 | } |
|
786 | 786 | |
|
787 | 787 | void QChartPrivate::zoomReset() |
|
788 | 788 | { |
|
789 | 789 | m_dataset->zoomResetDomain(); |
|
790 | 790 | } |
|
791 | 791 | |
|
792 | 792 | bool QChartPrivate::isZoomed() |
|
793 | 793 | { |
|
794 | 794 | return m_dataset->isZoomedDomain(); |
|
795 | 795 | } |
|
796 | 796 | |
|
797 | 797 | void QChartPrivate::zoomOut(qreal factor) |
|
798 | 798 | { |
|
799 | 799 | const QRectF geometry = m_presenter->geometry(); |
|
800 | 800 | |
|
801 | 801 | QRectF r; |
|
802 | 802 | r.setSize(geometry.size() / factor); |
|
803 | 803 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
804 | 804 | if (!r.isValid()) |
|
805 | 805 | return; |
|
806 | 806 | |
|
807 | 807 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
808 | 808 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
809 | 809 | m_dataset->zoomOutDomain(r); |
|
810 | 810 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
811 | 811 | } |
|
812 | 812 | |
|
813 | 813 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
814 | 814 | { |
|
815 | 815 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
816 | 816 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
817 | 817 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
818 | 818 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
819 | 819 | |
|
820 | 820 | m_dataset->scrollDomain(dx, dy); |
|
821 | 821 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
822 | 822 | } |
|
823 | 823 | |
|
824 | 824 | #include "moc_qchart.cpp" |
|
825 | 825 | |
|
826 | 826 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,132 +1,132 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 "qpolarchart.h" |
|
22 | 22 | #include "qabstractaxis.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \enum QPolarChart::PolarOrientation |
|
28 | 28 | |
|
29 | 29 | This type is used to specify the polar orientation of an axis. |
|
30 | 30 | |
|
31 | 31 | \value PolarOrientationRadial |
|
32 | 32 | \value PolarOrientationAngular |
|
33 | 33 | */ |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 | 36 | \class QPolarChart |
|
37 | \brief Qt Enterprise Chart API. | |
|
37 | \brief Polar chart API for Qt Charts. | |
|
38 | 38 | |
|
39 | 39 | QPolarChart is a specialization of QChart to show a polar chart. |
|
40 | 40 | |
|
41 | 41 | Polar charts support line, spline, area, and scatter series, and all axis types |
|
42 | 42 | supported by those series. |
|
43 | 43 | |
|
44 | 44 | \note When setting ticks to an angular QValueAxis, keep in mind that the first and last tick |
|
45 | 45 | are co-located at 0/360 degree angle. |
|
46 | 46 | |
|
47 | 47 | \note If the angular distance between two consecutive points in a series is more than 180 degrees, |
|
48 | 48 | any line connecting the two points becomes meaningless, so choose the axis ranges accordingly |
|
49 | 49 | when displaying line, spline, or area series. In such case series don't draw a direct line between |
|
50 | 50 | the two points, but instead draw a line to and from the center of the chart. |
|
51 | 51 | |
|
52 | 52 | \note Polar charts draw all axes of same orientation in the same position, so using multiple |
|
53 | 53 | axes of same orientation can be confusing, unless the extra axes are only used to customize the |
|
54 | 54 | grid (e.g. you can display a highlighted range with a secondary shaded QCategoryAxis or provide |
|
55 | 55 | unlabeled subticks with a secondary QValueAxis that has its labels hidden). |
|
56 | 56 | |
|
57 | 57 | \sa QChart |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | Constructs a polar chart as a child of the \a parent. |
|
62 | 62 | Parameter \a wFlags is passed to the QChart constructor. |
|
63 | 63 | */ |
|
64 | 64 | QPolarChart::QPolarChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
65 | 65 | : QChart(QChart::ChartTypePolar, parent, wFlags) |
|
66 | 66 | { |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | /*! |
|
70 | 70 | Destroys the polar chart object and its children, like series and axis objects added to it. |
|
71 | 71 | */ |
|
72 | 72 | QPolarChart::~QPolarChart() |
|
73 | 73 | { |
|
74 | 74 | } |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | Returns the axes added for the \a series with \a polarOrientation. If no series is provided, then any axis with the |
|
78 | 78 | specified polar orientation is returned. |
|
79 | 79 | |
|
80 | 80 | \sa addAxis() |
|
81 | 81 | */ |
|
82 | 82 | QList<QAbstractAxis *> QPolarChart::axes(PolarOrientations polarOrientation, QAbstractSeries *series) const |
|
83 | 83 | { |
|
84 | 84 | Qt::Orientations orientation(0); |
|
85 | 85 | if (polarOrientation.testFlag(PolarOrientationAngular)) |
|
86 | 86 | orientation |= Qt::Horizontal; |
|
87 | 87 | if (polarOrientation.testFlag(PolarOrientationRadial)) |
|
88 | 88 | orientation |= Qt::Vertical; |
|
89 | 89 | |
|
90 | 90 | return QChart::axes(orientation, series); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | This convenience method adds \a axis to the polar chart with \a polarOrientation. |
|
95 | 95 | The chart takes the ownership of the axis. |
|
96 | 96 | |
|
97 | 97 | \note Axes can be added to a polar chart also with QChart::addAxis() instead of this method. |
|
98 | 98 | The specified alignment determines the polar orientation: horizontal alignments indicate angular |
|
99 | 99 | axis and vertical alignments indicate radial axis. |
|
100 | 100 | |
|
101 | 101 | \sa QChart::removeAxis(), QChart::createDefaultAxes(), QAbstractSeries::attachAxis(), QChart::addAxis() |
|
102 | 102 | */ |
|
103 | 103 | void QPolarChart::addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation) |
|
104 | 104 | { |
|
105 | 105 | if (!axis || axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
106 | 106 | qWarning("QAbstractAxis::AxisTypeBarCategory is not a supported axis type for polar charts."); |
|
107 | 107 | } else { |
|
108 | 108 | Qt::Alignment alignment = Qt::AlignLeft; |
|
109 | 109 | if (polarOrientation == PolarOrientationAngular) |
|
110 | 110 | alignment = Qt::AlignBottom; |
|
111 | 111 | QChart::addAxis(axis, alignment); |
|
112 | 112 | } |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | Angular axes of a polar chart report horizontal orientation and radial axes report |
|
117 | 117 | vertical orientation. |
|
118 | 118 | This function is a convenience function for converting the orientation of an \a axis to |
|
119 | 119 | corresponding polar orientation. If the \a axis is NULL or not added to a polar chart, |
|
120 | 120 | the return value is meaningless. |
|
121 | 121 | */ |
|
122 | 122 | QPolarChart::PolarOrientation QPolarChart::axisPolarOrientation(QAbstractAxis *axis) |
|
123 | 123 | { |
|
124 | 124 | if (axis && axis->orientation() == Qt::Horizontal) |
|
125 | 125 | return PolarOrientationAngular; |
|
126 | 126 | else |
|
127 | 127 | return PolarOrientationRadial; |
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | #include "moc_qpolarchart.cpp" |
|
131 | 131 | |
|
132 | 132 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now