@@ -1,731 +1,730 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 "declarativechart.h" |
|
22 | 22 | #include <QPainter> |
|
23 | 23 | #include <QDeclarativeEngine> |
|
24 | 24 | #include "declarativelineseries.h" |
|
25 | 25 | #include "declarativeareaseries.h" |
|
26 | 26 | #include "declarativebarseries.h" |
|
27 | 27 | #include "declarativepieseries.h" |
|
28 | 28 | #include "declarativesplineseries.h" |
|
29 | 29 | #include "declarativescatterseries.h" |
|
30 | 30 | #include "qbarcategoryaxis.h" |
|
31 | 31 | #include "qvalueaxis.h" |
|
32 | 32 | #include "qcategoryaxis.h" |
|
33 | 33 | #include "qabstractseries_p.h" |
|
34 | 34 | #include "declarativemargins.h" |
|
35 | 35 | #include "chartdataset_p.h" |
|
36 | 36 | #include "qchart_p.h" |
|
37 | 37 | |
|
38 | 38 | #ifndef QT_ON_ARM |
|
39 | 39 | #include "qdatetimeaxis.h" |
|
40 | 40 | #endif |
|
41 | 41 | |
|
42 | 42 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
43 | 43 | |
|
44 | 44 | /*! |
|
45 | 45 | \qmlclass ChartView DeclarativeChart |
|
46 | 46 | |
|
47 | 47 | ChartView element is the parent that is responsible for showing different chart series types. |
|
48 | 48 | |
|
49 | 49 | The following QML shows how to create a simple chart with one pie series: |
|
50 | 50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
51 | 51 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
52 | 52 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
53 | 53 | |
|
54 | 54 | \beginfloatleft |
|
55 | 55 | \image examples_qmlpiechart.png |
|
56 | 56 | \endfloat |
|
57 | 57 | \clearfloat |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \qmlproperty Theme ChartView::theme |
|
62 | 62 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
63 | 63 | widths and chart background. |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \qmlproperty Animation ChartView::animationOptions |
|
68 | 68 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
69 | 69 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
70 | 70 | */ |
|
71 | 71 | |
|
72 | 72 | /*! |
|
73 | 73 | \qmlproperty Font ChartView::titleFont |
|
74 | 74 | The title font of the chart |
|
75 | 75 | |
|
76 | 76 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \qmlproperty string ChartView::title |
|
81 | 81 | The title of the chart, shown on top of the chart. |
|
82 | 82 | \sa ChartView::titleColor |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \qmlproperty color ChartView::titleColor |
|
87 | 87 | The color of the title text. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \qmlproperty Legend ChartView::legend |
|
92 | 92 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | \qmlproperty int ChartView::count |
|
97 | 97 | The count of series added to the chart. |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \qmlproperty color ChartView::backgroundColor |
|
102 | 102 | The color of the chart's background. By default background color is defined by chart theme. |
|
103 | 103 | \sa ChartView::theme |
|
104 | 104 | */ |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | \qmlproperty bool ChartView::dropShadowEnabled |
|
108 | 108 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
109 | 109 | */ |
|
110 | 110 | |
|
111 | 111 | /*! |
|
112 | 112 | \qmlproperty real ChartView::topMargin |
|
113 | 113 | Deprecated. Use minimumMargins and plotArea instead. |
|
114 | 114 | */ |
|
115 | 115 | |
|
116 | 116 | /*! |
|
117 | 117 | \qmlproperty real ChartView::bottomMargin |
|
118 | 118 | Deprecated. Use minimumMargins and plotArea instead. |
|
119 | 119 | */ |
|
120 | 120 | |
|
121 | 121 | /*! |
|
122 | 122 | \qmlproperty real ChartView::leftMargin |
|
123 | 123 | Deprecated. Use minimumMargins and plotArea instead. |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | /*! |
|
127 | 127 | \qmlproperty real ChartView::rightMargin |
|
128 | 128 | Deprecated. Use minimumMargins and plotArea instead. |
|
129 | 129 | */ |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | \qmlproperty Margins ChartView::minimumMargins |
|
133 | 133 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
134 | 134 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
135 | 135 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
136 | 136 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
137 | 137 | given time, you can check ChartView::plotArea instead. |
|
138 | 138 | */ |
|
139 | 139 | |
|
140 | 140 | /*! |
|
141 | 141 | \qmlproperty rect ChartView::plotArea |
|
142 | 142 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
143 | 143 | margins. |
|
144 | 144 | \sa ChartView::minimumMargins |
|
145 | 145 | */ |
|
146 | 146 | |
|
147 | 147 | /*! |
|
148 | 148 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
149 | 149 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
150 | 150 | the count property of the chart. |
|
151 | 151 | */ |
|
152 | 152 | |
|
153 | 153 | /*! |
|
154 | 154 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
155 | 155 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | 159 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
160 | 160 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
161 | 161 | optional axis \a axisY. For example: |
|
162 | 162 | \code |
|
163 | 163 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
164 | 164 | var myAxisX = chartView.axisX(lineSeries); |
|
165 | 165 | var myAxisY = chartView.axisY(lineSeries); |
|
166 | 166 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
167 | 167 | \endcode |
|
168 | 168 | */ |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
172 | 172 | Removes the \a series from the chart. The series object is also destroyed. |
|
173 | 173 | */ |
|
174 | 174 | |
|
175 | 175 | /*! |
|
176 | 176 | \qmlmethod ChartView::removeAllSeries() |
|
177 | 177 | Removes all series from the chart. All the series objects are also destroyed. |
|
178 | 178 | */ |
|
179 | 179 | |
|
180 | 180 | /*! |
|
181 | 181 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
182 | 182 | The x-axis of the series. |
|
183 | 183 | */ |
|
184 | 184 | |
|
185 | 185 | /*! |
|
186 | 186 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
187 | 187 | The y-axis of the series. |
|
188 | 188 | */ |
|
189 | 189 | |
|
190 | 190 | /*! |
|
191 | 191 | \qmlmethod ChartView::zoomY(real factor) |
|
192 | 192 | Zooms in by \a factor on the center of the chart. |
|
193 | 193 | */ |
|
194 | 194 | |
|
195 | 195 | /*! |
|
196 | 196 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
197 | 197 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
198 | 198 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
199 | 199 | */ |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | \qmlmethod ChartView::scrollRight(real pixels) |
|
203 | 203 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
204 | 204 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
205 | 205 | */ |
|
206 | 206 | |
|
207 | 207 | /*! |
|
208 | 208 | \qmlmethod ChartView::scrollUp(real pixels) |
|
209 | 209 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
210 | 210 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
211 | 211 | */ |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | \qmlmethod ChartView::scrollDown(real pixels) |
|
215 | 215 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
216 | 216 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
217 | 217 | */ |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
221 | 221 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
222 | 222 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
223 | 223 | title. |
|
224 | 224 | */ |
|
225 | 225 | |
|
226 | 226 | /*! |
|
227 | 227 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
228 | 228 | The \a series has been added to the chart. |
|
229 | 229 | */ |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
233 | 233 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
234 | 234 | object after the signal handler has completed. |
|
235 | 235 | */ |
|
236 | 236 | |
|
237 | 237 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
238 | 238 | : QDeclarativeItem(parent), |
|
239 | 239 | m_chart(new QChart(this)) |
|
240 | 240 | { |
|
241 | 241 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
242 | 242 | m_margins = new DeclarativeMargins(this); |
|
243 | 243 | m_margins->setTop(m_chart->margins().top()); |
|
244 | 244 | m_margins->setLeft(m_chart->margins().left()); |
|
245 | 245 | m_margins->setRight(m_chart->margins().right()); |
|
246 | 246 | m_margins->setBottom(m_chart->margins().bottom()); |
|
247 | 247 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
248 | 248 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
249 | 249 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
250 | 250 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
251 |
connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries* |
|
|
251 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
|
252 | 252 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
253 | 253 | } |
|
254 | 254 | |
|
255 |
void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series |
|
|
255 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) | |
|
256 | 256 | { |
|
257 | Q_UNUSED(domain) | |
|
258 | 257 | emit seriesAdded(series); |
|
259 | 258 | } |
|
260 | 259 | |
|
261 | 260 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
262 | 261 | { |
|
263 | 262 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
264 | 263 | emit minimumMarginsChanged(); |
|
265 | 264 | emit plotAreaChanged(m_chart->plotArea()); |
|
266 | 265 | } |
|
267 | 266 | |
|
268 | 267 | DeclarativeChart::~DeclarativeChart() |
|
269 | 268 | { |
|
270 | 269 | delete m_chart; |
|
271 | 270 | } |
|
272 | 271 | |
|
273 | 272 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
274 | 273 | { |
|
275 | 274 | if (event->type() == QEvent::ChildAdded) { |
|
276 | 275 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
277 | 276 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
278 | 277 | } |
|
279 | 278 | } |
|
280 | 279 | } |
|
281 | 280 | |
|
282 | 281 | void DeclarativeChart::componentComplete() |
|
283 | 282 | { |
|
284 | 283 | foreach (QObject *child, children()) { |
|
285 | 284 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
286 | 285 | // Add series to the chart |
|
287 | 286 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
288 | 287 | m_chart->addSeries(series); |
|
289 | 288 | |
|
290 | 289 | // Set optional user defined axes for the series and connect axis related signals |
|
291 | 290 | if (qobject_cast<DeclarativeLineSeries *>(child)) { |
|
292 | 291 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); |
|
293 | 292 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
294 | 293 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
295 | 294 | setAxisX(s->axisX(), s); |
|
296 | 295 | setAxisY(s->axisY(), s); |
|
297 | 296 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { |
|
298 | 297 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); |
|
299 | 298 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
300 | 299 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
301 | 300 | setAxisX(s->axisX(), s); |
|
302 | 301 | setAxisY(s->axisY(), s); |
|
303 | 302 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { |
|
304 | 303 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); |
|
305 | 304 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
306 | 305 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
307 | 306 | setAxisX(s->axisX(), s); |
|
308 | 307 | setAxisY(s->axisY(), s); |
|
309 | 308 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { |
|
310 | 309 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); |
|
311 | 310 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
312 | 311 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
313 | 312 | setAxisX(s->axisX(), s); |
|
314 | 313 | setAxisY(s->axisY(), s); |
|
315 | 314 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { |
|
316 | 315 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); |
|
317 | 316 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
318 | 317 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
319 | 318 | setAxisX(s->axisX(), s); |
|
320 | 319 | setAxisY(s->axisY(), s); |
|
321 | 320 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { |
|
322 | 321 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); |
|
323 | 322 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
324 | 323 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
325 | 324 | setAxisX(s->axisX(), s); |
|
326 | 325 | setAxisY(s->axisY(), s); |
|
327 | 326 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { |
|
328 | 327 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); |
|
329 | 328 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
330 | 329 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
331 | 330 | setAxisX(s->axisX(), s); |
|
332 | 331 | setAxisY(s->axisY(), s); |
|
333 | 332 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { |
|
334 | 333 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); |
|
335 | 334 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
336 | 335 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
337 | 336 | setAxisX(s->axisX(), s); |
|
338 | 337 | setAxisY(s->axisY(), s); |
|
339 | 338 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { |
|
340 | 339 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); |
|
341 | 340 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
342 | 341 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
343 | 342 | setAxisX(s->axisX(), s); |
|
344 | 343 | setAxisY(s->axisY(), s); |
|
345 | 344 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { |
|
346 | 345 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); |
|
347 | 346 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
348 | 347 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
349 | 348 | setAxisX(s->axisX(), s); |
|
350 | 349 | setAxisY(s->axisY(), s); |
|
351 | 350 | } |
|
352 | 351 | } |
|
353 | 352 | } |
|
354 | 353 | |
|
355 | 354 | // Create the missing axes for the series that cannot be painted without axes |
|
356 | 355 | foreach (QAbstractSeries *chartSeries, m_chart->series()) |
|
357 | 356 | createDefaultAxes(chartSeries); |
|
358 | 357 | |
|
359 | 358 | QDeclarativeItem::componentComplete(); |
|
360 | 359 | } |
|
361 | 360 | |
|
362 | 361 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
363 | 362 | { |
|
364 | 363 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; |
|
365 | 364 | if (axis && qobject_cast<QAbstractSeries *>(sender())) |
|
366 | 365 | m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender())); |
|
367 | 366 | else |
|
368 | 367 | qWarning() << "Trying to set axisX to null."; |
|
369 | 368 | } |
|
370 | 369 | |
|
371 | 370 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
372 | 371 | { |
|
373 | 372 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; |
|
374 | 373 | if (axis && qobject_cast<QAbstractSeries *>(sender())) |
|
375 | 374 | m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender())); |
|
376 | 375 | else |
|
377 | 376 | qWarning() << "Trying to set axisY to null."; |
|
378 | 377 | } |
|
379 | 378 | |
|
380 | 379 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
381 | 380 | { |
|
382 | 381 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
383 | 382 | if (newGeometry.isValid()) { |
|
384 | 383 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
385 | 384 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
386 | 385 | } |
|
387 | 386 | } |
|
388 | 387 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
389 | 388 | |
|
390 | 389 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
391 | 390 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
392 | 391 | // to implement it here for the QML API purposes. |
|
393 | 392 | emit plotAreaChanged(m_chart->plotArea()); |
|
394 | 393 | } |
|
395 | 394 | |
|
396 | 395 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
397 | 396 | { |
|
398 | 397 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
399 | 398 | if (chartTheme != m_chart->theme()) |
|
400 | 399 | m_chart->setTheme(chartTheme); |
|
401 | 400 | } |
|
402 | 401 | |
|
403 | 402 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
404 | 403 | { |
|
405 | 404 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
406 | 405 | } |
|
407 | 406 | |
|
408 | 407 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
409 | 408 | { |
|
410 | 409 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
411 | 410 | if (animationOptions != m_chart->animationOptions()) |
|
412 | 411 | m_chart->setAnimationOptions(animationOptions); |
|
413 | 412 | } |
|
414 | 413 | |
|
415 | 414 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
416 | 415 | { |
|
417 | 416 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
418 | 417 | return DeclarativeChart::AllAnimations; |
|
419 | 418 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
420 | 419 | return DeclarativeChart::GridAxisAnimations; |
|
421 | 420 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
422 | 421 | return DeclarativeChart::SeriesAnimations; |
|
423 | 422 | else |
|
424 | 423 | return DeclarativeChart::NoAnimation; |
|
425 | 424 | } |
|
426 | 425 | |
|
427 | 426 | void DeclarativeChart::setTitle(QString title) |
|
428 | 427 | { |
|
429 | 428 | if (title != m_chart->title()) |
|
430 | 429 | m_chart->setTitle(title); |
|
431 | 430 | } |
|
432 | 431 | QString DeclarativeChart::title() |
|
433 | 432 | { |
|
434 | 433 | return m_chart->title(); |
|
435 | 434 | } |
|
436 | 435 | |
|
437 | 436 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
438 | 437 | { |
|
439 | 438 | return m_chart->axisX(series); |
|
440 | 439 | } |
|
441 | 440 | |
|
442 | 441 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
443 | 442 | { |
|
444 | 443 | return m_chart->axisY(series); |
|
445 | 444 | } |
|
446 | 445 | |
|
447 | 446 | QLegend *DeclarativeChart::legend() |
|
448 | 447 | { |
|
449 | 448 | return m_chart->legend(); |
|
450 | 449 | } |
|
451 | 450 | |
|
452 | 451 | void DeclarativeChart::setTitleColor(QColor color) |
|
453 | 452 | { |
|
454 | 453 | QBrush b = m_chart->titleBrush(); |
|
455 | 454 | if (color != b.color()) { |
|
456 | 455 | b.setColor(color); |
|
457 | 456 | m_chart->setTitleBrush(b); |
|
458 | 457 | emit titleColorChanged(color); |
|
459 | 458 | } |
|
460 | 459 | } |
|
461 | 460 | |
|
462 | 461 | QFont DeclarativeChart::titleFont() const |
|
463 | 462 | { |
|
464 | 463 | return m_chart->titleFont(); |
|
465 | 464 | } |
|
466 | 465 | |
|
467 | 466 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
468 | 467 | { |
|
469 | 468 | m_chart->setTitleFont(font); |
|
470 | 469 | } |
|
471 | 470 | |
|
472 | 471 | QColor DeclarativeChart::titleColor() |
|
473 | 472 | { |
|
474 | 473 | return m_chart->titleBrush().color(); |
|
475 | 474 | } |
|
476 | 475 | |
|
477 | 476 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
478 | 477 | { |
|
479 | 478 | QBrush b = m_chart->backgroundBrush(); |
|
480 | 479 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
481 | 480 | b.setStyle(Qt::SolidPattern); |
|
482 | 481 | b.setColor(color); |
|
483 | 482 | m_chart->setBackgroundBrush(b); |
|
484 | 483 | emit backgroundColorChanged(); |
|
485 | 484 | } |
|
486 | 485 | } |
|
487 | 486 | |
|
488 | 487 | QColor DeclarativeChart::backgroundColor() |
|
489 | 488 | { |
|
490 | 489 | return m_chart->backgroundBrush().color(); |
|
491 | 490 | } |
|
492 | 491 | |
|
493 | 492 | int DeclarativeChart::count() |
|
494 | 493 | { |
|
495 | 494 | return m_chart->series().count(); |
|
496 | 495 | } |
|
497 | 496 | |
|
498 | 497 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
499 | 498 | { |
|
500 | 499 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
501 | 500 | m_chart->setDropShadowEnabled(enabled); |
|
502 | 501 | dropShadowEnabledChanged(enabled); |
|
503 | 502 | } |
|
504 | 503 | } |
|
505 | 504 | |
|
506 | 505 | bool DeclarativeChart::dropShadowEnabled() |
|
507 | 506 | { |
|
508 | 507 | return m_chart->isDropShadowEnabled(); |
|
509 | 508 | } |
|
510 | 509 | |
|
511 | 510 | qreal DeclarativeChart::topMargin() |
|
512 | 511 | { |
|
513 | 512 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
514 | 513 | return m_chart->plotArea().top(); |
|
515 | 514 | } |
|
516 | 515 | |
|
517 | 516 | qreal DeclarativeChart::bottomMargin() |
|
518 | 517 | { |
|
519 | 518 | |
|
520 | 519 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
521 | 520 | return m_chart->plotArea().bottom(); |
|
522 | 521 | } |
|
523 | 522 | |
|
524 | 523 | qreal DeclarativeChart::leftMargin() |
|
525 | 524 | { |
|
526 | 525 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
527 | 526 | return m_chart->plotArea().left(); |
|
528 | 527 | } |
|
529 | 528 | |
|
530 | 529 | qreal DeclarativeChart::rightMargin() |
|
531 | 530 | { |
|
532 | 531 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
533 | 532 | return m_chart->plotArea().right(); |
|
534 | 533 | } |
|
535 | 534 | |
|
536 | 535 | void DeclarativeChart::zoom(qreal factor) |
|
537 | 536 | { |
|
538 | 537 | m_chart->zoom(factor); |
|
539 | 538 | } |
|
540 | 539 | |
|
541 | 540 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
542 | 541 | { |
|
543 | 542 | m_chart->scroll(-pixels, 0); |
|
544 | 543 | } |
|
545 | 544 | |
|
546 | 545 | void DeclarativeChart::scrollRight(qreal pixels) |
|
547 | 546 | { |
|
548 | 547 | m_chart->scroll(pixels, 0); |
|
549 | 548 | } |
|
550 | 549 | |
|
551 | 550 | void DeclarativeChart::scrollUp(qreal pixels) |
|
552 | 551 | { |
|
553 | 552 | m_chart->scroll(0, pixels); |
|
554 | 553 | } |
|
555 | 554 | |
|
556 | 555 | void DeclarativeChart::scrollDown(qreal pixels) |
|
557 | 556 | { |
|
558 | 557 | m_chart->scroll(0, -pixels); |
|
559 | 558 | } |
|
560 | 559 | |
|
561 | 560 | QAbstractSeries *DeclarativeChart::series(int index) |
|
562 | 561 | { |
|
563 | 562 | if (index < m_chart->series().count()) { |
|
564 | 563 | return m_chart->series().at(index); |
|
565 | 564 | } |
|
566 | 565 | return 0; |
|
567 | 566 | } |
|
568 | 567 | |
|
569 | 568 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
570 | 569 | { |
|
571 | 570 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
572 | 571 | if (series->name() == seriesName) |
|
573 | 572 | return series; |
|
574 | 573 | } |
|
575 | 574 | return 0; |
|
576 | 575 | } |
|
577 | 576 | |
|
578 | 577 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
579 | 578 | { |
|
580 | 579 | return createSeries(type, name, 0, 0); |
|
581 | 580 | } |
|
582 | 581 | |
|
583 | 582 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
584 | 583 | { |
|
585 | 584 | QAbstractSeries *series = 0; |
|
586 | 585 | |
|
587 | 586 | switch (type) { |
|
588 | 587 | case DeclarativeChart::SeriesTypeLine: |
|
589 | 588 | series = new DeclarativeLineSeries(); |
|
590 | 589 | break; |
|
591 | 590 | case DeclarativeChart::SeriesTypeArea: { |
|
592 | 591 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
593 | 592 | area->setUpperSeries(new DeclarativeLineSeries()); |
|
594 | 593 | series = area; |
|
595 | 594 | break; |
|
596 | 595 | } |
|
597 | 596 | case DeclarativeChart::SeriesTypeStackedBar: |
|
598 | 597 | series = new DeclarativeStackedBarSeries(); |
|
599 | 598 | break; |
|
600 | 599 | case DeclarativeChart::SeriesTypePercentBar: |
|
601 | 600 | series = new DeclarativePercentBarSeries(); |
|
602 | 601 | break; |
|
603 | 602 | case DeclarativeChart::SeriesTypeBar: |
|
604 | 603 | series = new DeclarativeBarSeries(); |
|
605 | 604 | break; |
|
606 | 605 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
607 | 606 | series = new DeclarativeHorizontalBarSeries(); |
|
608 | 607 | break; |
|
609 | 608 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
610 | 609 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
611 | 610 | break; |
|
612 | 611 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
613 | 612 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
614 | 613 | break; |
|
615 | 614 | case DeclarativeChart::SeriesTypePie: |
|
616 | 615 | series = new DeclarativePieSeries(); |
|
617 | 616 | break; |
|
618 | 617 | case DeclarativeChart::SeriesTypeScatter: |
|
619 | 618 | series = new DeclarativeScatterSeries(); |
|
620 | 619 | break; |
|
621 | 620 | case DeclarativeChart::SeriesTypeSpline: |
|
622 | 621 | series = new DeclarativeSplineSeries(); |
|
623 | 622 | break; |
|
624 | 623 | default: |
|
625 | 624 | qWarning() << "Illegal series type"; |
|
626 | 625 | } |
|
627 | 626 | |
|
628 | 627 | if (series) { |
|
629 | 628 | series->setName(name); |
|
630 | 629 | m_chart->addSeries(series); |
|
631 | 630 | // Set possible user defined axes |
|
632 | 631 | setAxisX(axisX, series); |
|
633 | 632 | setAxisY(axisY, series); |
|
634 | 633 | // Then create the missing axes |
|
635 | 634 | createDefaultAxes(series); |
|
636 | 635 | } |
|
637 | 636 | |
|
638 | 637 | return series; |
|
639 | 638 | } |
|
640 | 639 | |
|
641 | 640 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
642 | 641 | { |
|
643 | 642 | if (series) |
|
644 | 643 | m_chart->removeSeries(series); |
|
645 | 644 | else |
|
646 | 645 | qWarning("removeSeries: cannot remove null"); |
|
647 | 646 | } |
|
648 | 647 | |
|
649 | 648 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
650 | 649 | { |
|
651 | 650 | if (axis) |
|
652 | 651 | m_chart->setAxisX(axis, series); |
|
653 | 652 | } |
|
654 | 653 | |
|
655 | 654 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
656 | 655 | { |
|
657 | 656 | if (axis) |
|
658 | 657 | m_chart->setAxisY(axis, series); |
|
659 | 658 | } |
|
660 | 659 | |
|
661 | 660 | void DeclarativeChart::createDefaultAxes() |
|
662 | 661 | { |
|
663 | 662 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
664 | 663 | } |
|
665 | 664 | |
|
666 | 665 | void DeclarativeChart::createDefaultAxes(QAbstractSeries *series) |
|
667 | 666 | { |
|
668 | 667 | foreach (QAbstractSeries *s, m_chart->series()) { |
|
669 | 668 | // If there is already an x axis of the correct type, re-use it |
|
670 | 669 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) |
|
671 | 670 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) |
|
672 | 671 | m_chart->setAxisX(m_chart->axisX(s), series); |
|
673 | 672 | |
|
674 | 673 | // If there is already a y axis of the correct type, re-use it |
|
675 | 674 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) |
|
676 | 675 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) |
|
677 | 676 | m_chart->setAxisY(m_chart->axisY(s), series); |
|
678 | 677 | } |
|
679 | 678 | |
|
680 | 679 | // If no x axis of correct type was found, create a new x axis based of default axis type |
|
681 | 680 | if (!m_chart->axisX(series)) { |
|
682 | 681 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { |
|
683 | 682 | case QAbstractAxis::AxisTypeValue: |
|
684 | 683 | m_chart->setAxisX(new QValueAxis(this), series); |
|
685 | 684 | break; |
|
686 | 685 | case QAbstractAxis::AxisTypeBarCategory: |
|
687 | 686 | m_chart->setAxisX(new QBarCategoryAxis(this), series); |
|
688 | 687 | break; |
|
689 | 688 | case QAbstractAxis::AxisTypeCategory: |
|
690 | 689 | m_chart->setAxisX(new QCategoryAxis(this), series); |
|
691 | 690 | break; |
|
692 | 691 | #ifndef QT_ON_ARM |
|
693 | 692 | case QAbstractAxis::AxisTypeDateTime: |
|
694 | 693 | m_chart->setAxisX(new QDateTimeAxis(this), series); |
|
695 | 694 | break; |
|
696 | 695 | #endif |
|
697 | 696 | default: |
|
698 | 697 | // Do nothing, assume AxisTypeNoAxis |
|
699 | 698 | break; |
|
700 | 699 | } |
|
701 | 700 | } |
|
702 | 701 | |
|
703 | 702 | // If no y axis of correct type was found, create a new y axis based of default axis type |
|
704 | 703 | if (!m_chart->axisY(series)) { |
|
705 | 704 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { |
|
706 | 705 | case QAbstractAxis::AxisTypeValue: |
|
707 | 706 | m_chart->setAxisY(new QValueAxis(this), series); |
|
708 | 707 | break; |
|
709 | 708 | case QAbstractAxis::AxisTypeBarCategory: |
|
710 | 709 | m_chart->setAxisY(new QBarCategoryAxis(this), series); |
|
711 | 710 | break; |
|
712 | 711 | case QAbstractAxis::AxisTypeCategory: |
|
713 | 712 | m_chart->setAxisY(new QCategoryAxis(this), series); |
|
714 | 713 | break; |
|
715 | 714 | #ifndef QT_ON_ARM |
|
716 | 715 | case QAbstractAxis::AxisTypeDateTime: |
|
717 | 716 | m_chart->setAxisY(new QDateTimeAxis(this), series); |
|
718 | 717 | break; |
|
719 | 718 | #endif |
|
720 | 719 | default: |
|
721 | 720 | // Do nothing, assume AxisTypeNoAxis |
|
722 | 721 | break; |
|
723 | 722 | } |
|
724 | 723 | } |
|
725 | 724 | |
|
726 | 725 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); |
|
727 | 726 | } |
|
728 | 727 | |
|
729 | 728 | #include "moc_declarativechart.cpp" |
|
730 | 729 | |
|
731 | 730 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,172 +1,172 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | #ifndef DECLARATIVECHART_H |
|
22 | 22 | #define DECLARATIVECHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QtCore/QtGlobal> |
|
25 | 25 | #include <QtDeclarative/QDeclarativeItem> |
|
26 | 26 | |
|
27 | 27 | #include "qchart.h" |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class DeclarativeMargins; |
|
32 | 32 | class AbstractDomain; |
|
33 | 33 | |
|
34 | 34 | class DeclarativeChart : public QDeclarativeItem |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
38 | 38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
39 | 39 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
40 | 40 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
41 | 41 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
42 | 42 | Q_PROPERTY(QLegend *legend READ legend) |
|
43 | 43 | Q_PROPERTY(int count READ count) |
|
44 | 44 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
45 | 45 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
46 | 46 | Q_PROPERTY(qreal topMargin READ topMargin) |
|
47 | 47 | Q_PROPERTY(qreal bottomMargin READ bottomMargin) |
|
48 | 48 | Q_PROPERTY(qreal leftMargin READ leftMargin) |
|
49 | 49 | Q_PROPERTY(qreal rightMargin READ rightMargin) |
|
50 | 50 | Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) |
|
51 | 51 | Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) |
|
52 | 52 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) |
|
53 | 53 | Q_ENUMS(Animation) |
|
54 | 54 | Q_ENUMS(Theme) |
|
55 | 55 | Q_ENUMS(SeriesType) |
|
56 | 56 | |
|
57 | 57 | public: |
|
58 | 58 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
59 | 59 | enum Theme { |
|
60 | 60 | ChartThemeLight = 0, |
|
61 | 61 | ChartThemeBlueCerulean, |
|
62 | 62 | ChartThemeDark, |
|
63 | 63 | ChartThemeBrownSand, |
|
64 | 64 | ChartThemeBlueNcs, |
|
65 | 65 | ChartThemeHighContrast, |
|
66 | 66 | ChartThemeBlueIcy |
|
67 | 67 | }; |
|
68 | 68 | |
|
69 | 69 | enum Animation { |
|
70 | 70 | NoAnimation = 0x0, |
|
71 | 71 | GridAxisAnimations = 0x1, |
|
72 | 72 | SeriesAnimations = 0x2, |
|
73 | 73 | AllAnimations = 0x3 |
|
74 | 74 | }; |
|
75 | 75 | |
|
76 | 76 | enum SeriesType { |
|
77 | 77 | SeriesTypeLine, |
|
78 | 78 | SeriesTypeArea, |
|
79 | 79 | SeriesTypeBar, |
|
80 | 80 | SeriesTypeStackedBar, |
|
81 | 81 | SeriesTypePercentBar, |
|
82 | 82 | SeriesTypePie, |
|
83 | 83 | SeriesTypeScatter, |
|
84 | 84 | SeriesTypeSpline, |
|
85 | 85 | SeriesTypeHorizontalBar, |
|
86 | 86 | SeriesTypeHorizontalStackedBar, |
|
87 | 87 | SeriesTypeHorizontalPercentBar |
|
88 | 88 | }; |
|
89 | 89 | |
|
90 | 90 | public: |
|
91 | 91 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
92 | 92 | ~DeclarativeChart(); |
|
93 | 93 | |
|
94 | 94 | public: // From QDeclarativeItem/QGraphicsItem |
|
95 | 95 | void childEvent(QChildEvent *event); |
|
96 | 96 | void componentComplete(); |
|
97 | 97 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
98 | 98 | |
|
99 | 99 | public: |
|
100 | 100 | void setTheme(DeclarativeChart::Theme theme); |
|
101 | 101 | DeclarativeChart::Theme theme(); |
|
102 | 102 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
103 | 103 | DeclarativeChart::Animation animationOptions(); |
|
104 | 104 | void setTitle(QString title); |
|
105 | 105 | QString title(); |
|
106 | 106 | QLegend *legend(); |
|
107 | 107 | QFont titleFont() const; |
|
108 | 108 | void setTitleFont(const QFont &font); |
|
109 | 109 | void setTitleColor(QColor color); |
|
110 | 110 | QColor titleColor(); |
|
111 | 111 | void setBackgroundColor(QColor color); |
|
112 | 112 | QColor backgroundColor(); |
|
113 | 113 | int count(); |
|
114 | 114 | void setDropShadowEnabled(bool enabled); |
|
115 | 115 | bool dropShadowEnabled(); |
|
116 | 116 | qreal topMargin(); |
|
117 | 117 | qreal bottomMargin(); |
|
118 | 118 | qreal leftMargin(); |
|
119 | 119 | qreal rightMargin(); |
|
120 | 120 | void createDefaultAxes(QAbstractSeries *series); |
|
121 | 121 | //TODO this is deprecated: |
|
122 | 122 | DeclarativeMargins *minimumMargins() { return m_margins; } |
|
123 | 123 | |
|
124 | 124 | Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } |
|
125 | 125 | QRectF plotArea() { return m_chart->plotArea(); } |
|
126 | 126 | |
|
127 | 127 | public: |
|
128 | 128 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
129 | 129 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
130 | 130 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
131 | 131 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY); |
|
132 | 132 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); |
|
133 | 133 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } |
|
134 | 134 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
135 | 135 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
136 | 136 | Q_INVOKABLE void createDefaultAxes(); |
|
137 | 137 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
138 | 138 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
139 | 139 | Q_INVOKABLE void zoom(qreal factor); |
|
140 | 140 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
141 | 141 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
142 | 142 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
143 | 143 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
144 | 144 | |
|
145 | 145 | Q_SIGNALS: |
|
146 | 146 | void axisLabelsChanged(); |
|
147 | 147 | void titleColorChanged(QColor color); |
|
148 | 148 | void backgroundColorChanged(); |
|
149 | 149 | void dropShadowEnabledChanged(bool enabled); |
|
150 | 150 | void minimumMarginsChanged(); |
|
151 | 151 | Q_REVISION(2) void marginsChanged(); |
|
152 | 152 | void plotAreaChanged(QRectF plotArea); |
|
153 | 153 | void seriesAdded(QAbstractSeries *series); |
|
154 | 154 | void seriesRemoved(QAbstractSeries *series); |
|
155 | 155 | |
|
156 | 156 | public Q_SLOTS: |
|
157 | 157 | void changeMinimumMargins(int top, int bottom, int left, int right); |
|
158 | 158 | void handleAxisXSet(QAbstractAxis *axis); |
|
159 | 159 | void handleAxisYSet(QAbstractAxis *axis); |
|
160 |
void handleSeriesAdded(QAbstractSeries *series |
|
|
160 | void handleSeriesAdded(QAbstractSeries *series); | |
|
161 | 161 | |
|
162 | 162 | private: |
|
163 | 163 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
164 | 164 | // multi inheritance, so we now have a QChart as a member instead |
|
165 | 165 | QChart *m_chart; |
|
166 | 166 | //QMargins m_chartMargins; |
|
167 | 167 | DeclarativeMargins *m_margins; |
|
168 | 168 | }; |
|
169 | 169 | |
|
170 | 170 | QTCOMMERCIALCHART_END_NAMESPACE |
|
171 | 171 | |
|
172 | 172 | #endif // DECLARATIVECHART_H |
@@ -1,497 +1,497 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 "chartaxis_p.h" |
|
22 | 22 | #include "qabstractaxis.h" |
|
23 | 23 | #include "qabstractaxis_p.h" |
|
24 | 24 | #include "chartpresenter_p.h" |
|
25 | 25 | #include "chartlayout_p.h" |
|
26 | 26 | #include "abstractdomain_p.h" |
|
27 | 27 | #include <qmath.h> |
|
28 | 28 | #include <QDateTime> |
|
29 | 29 | #include <QValueAxis> |
|
30 | 30 | #include <QLogValueAxis> |
|
31 | 31 | #include <QGraphicsLayout> |
|
32 | 32 | #include <QFontMetrics> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) |
|
37 | 37 | : ChartElement(item), |
|
38 | 38 | m_axis(axis), |
|
39 | 39 | m_labelsAngle(0), |
|
40 | 40 | m_grid(new QGraphicsItemGroup(item)), |
|
41 | 41 | m_arrow(new QGraphicsItemGroup(item)), |
|
42 | 42 | m_shades(new QGraphicsItemGroup(item)), |
|
43 | 43 | m_labels(new QGraphicsItemGroup(item)), |
|
44 | 44 | m_title(new QGraphicsSimpleTextItem(item)), |
|
45 | 45 | m_animation(0), |
|
46 | 46 | m_labelPadding(5), |
|
47 | 47 | m_intervalAxis(intervalAxis) |
|
48 | 48 | { |
|
49 | 49 | Q_ASSERT(item); |
|
50 | 50 | //initial initialization |
|
51 | 51 | m_arrow->setHandlesChildEvents(false); |
|
52 | 52 | m_arrow->setZValue(ChartPresenter::AxisZValue); |
|
53 | 53 | m_arrow->setVisible(m_axis->isLineVisible()); |
|
54 | 54 | m_labels->setZValue(ChartPresenter::AxisZValue); |
|
55 | 55 | m_labels->setVisible(m_axis->labelsVisible()); |
|
56 | 56 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
57 | 57 | m_shades->setVisible(m_axis->shadesVisible()); |
|
58 | 58 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
59 | 59 | m_grid->setVisible(m_axis->isGridLineVisible()); |
|
60 | 60 | m_title->setZValue(ChartPresenter::GridZValue); |
|
61 | 61 | connectSlots(); |
|
62 | 62 | |
|
63 | 63 | setFlag(QGraphicsItem::ItemHasNoContents,true); |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | void ChartAxis::connectSlots() |
|
67 | 67 | { |
|
68 | 68 | QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); |
|
69 | 69 | QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); |
|
70 | 70 | QObject::connect(m_axis,SIGNAL(gridLineVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); |
|
71 | 71 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); |
|
72 | 72 | QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); |
|
73 | 73 | QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); |
|
74 | 74 | QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); |
|
75 | 75 | QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); |
|
76 | 76 | QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); |
|
77 | 77 | QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); |
|
78 | 78 | QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); |
|
79 | 79 | QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); |
|
80 | 80 | QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); |
|
81 | 81 | QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); |
|
82 | 82 | QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); |
|
83 | 83 | QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); |
|
84 | 84 | QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); |
|
85 | 85 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | ChartAxis::~ChartAxis() |
|
89 | 89 | { |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | void ChartAxis::setAnimation(AxisAnimation *animation) |
|
93 | 93 | { |
|
94 | 94 | m_animation = animation; |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
98 | 98 | { |
|
99 | 99 | m_layoutVector = layout; |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | void ChartAxis::createItems(int count) |
|
103 | 103 | { |
|
104 |
if (m_arrow->child |
|
|
104 | if (m_arrow->childItems().size() == 0){ | |
|
105 | 105 | QGraphicsLineItem* arrow = new ArrowItem(this, this); |
|
106 | 106 | arrow->setPen(m_axis->linePen()); |
|
107 | 107 | m_arrow->addToGroup(arrow); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 |
if (m_intervalAxis && m_grid->child |
|
|
110 | if (m_intervalAxis && m_grid->childItems().size() == 0) { | |
|
111 | 111 | for (int i = 0 ; i < 2 ; i ++){ |
|
112 |
|
|
|
113 |
|
|
|
112 | QGraphicsLineItem* item = new QGraphicsLineItem(this); | |
|
113 | item->setPen(m_axis->gridLinePen()); | |
|
114 | 114 | m_grid->addToGroup(item); |
|
115 | 115 | } |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | for (int i = 0; i < count; ++i) { |
|
119 | 119 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); |
|
120 | 120 | arrow->setPen(m_axis->linePen()); |
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
121 | QGraphicsLineItem* grid = new QGraphicsLineItem(this); | |
|
122 | grid->setPen(m_axis->gridLinePen()); | |
|
123 | QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this); | |
|
124 | label->setFont(m_axis->labelsFont()); | |
|
125 | label->setPen(m_axis->labelsPen()); | |
|
126 | label->setBrush(m_axis->labelsBrush()); | |
|
127 | m_arrow->addToGroup(arrow); | |
|
128 | 128 | m_grid->addToGroup(grid); |
|
129 | 129 | m_labels->addToGroup(label); |
|
130 | 130 | |
|
131 | 131 | if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ |
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
132 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); | |
|
133 | shades->setPen(m_axis->shadesPen()); | |
|
134 | shades->setBrush(m_axis->shadesBrush()); | |
|
135 | 135 | m_shades->addToGroup(shades); |
|
136 | 136 | } |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | void ChartAxis::deleteItems(int count) |
|
142 | 142 | { |
|
143 | 143 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
144 | 144 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
145 | 145 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
146 | 146 | QList<QGraphicsItem *> axis = m_arrow->childItems(); |
|
147 | 147 | |
|
148 | 148 | for (int i = 0; i < count; ++i) { |
|
149 | 149 | if (lines.size() % 2 && lines.size() > 1) |
|
150 | 150 | delete(shades.takeLast()); |
|
151 | 151 | delete(lines.takeLast()); |
|
152 | 152 | delete(labels.takeLast()); |
|
153 | 153 | delete(axis.takeLast()); |
|
154 | 154 | } |
|
155 | 155 | } |
|
156 | 156 | |
|
157 | 157 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
158 | 158 | { |
|
159 | 159 | int diff = m_layoutVector.size() - layout.size(); |
|
160 | 160 | |
|
161 | 161 | if (diff > 0) |
|
162 | 162 | deleteItems(diff); |
|
163 | 163 | else if (diff < 0) |
|
164 | 164 | createItems(-diff); |
|
165 | 165 | |
|
166 | 166 | if (m_animation) { |
|
167 | 167 | switch (presenter()->state()) { |
|
168 | 168 | case ChartPresenter::ZoomInState: |
|
169 | 169 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
170 | 170 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
171 | 171 | break; |
|
172 | 172 | case ChartPresenter::ZoomOutState: |
|
173 | 173 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
174 | 174 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
175 | 175 | break; |
|
176 | 176 | case ChartPresenter::ScrollUpState: |
|
177 | 177 | case ChartPresenter::ScrollLeftState: |
|
178 | 178 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
179 | 179 | break; |
|
180 | 180 | case ChartPresenter::ScrollDownState: |
|
181 | 181 | case ChartPresenter::ScrollRightState: |
|
182 | 182 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
183 | 183 | break; |
|
184 | 184 | case ChartPresenter::ShowState: |
|
185 | 185 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
186 | 186 | break; |
|
187 | 187 | } |
|
188 | 188 | m_animation->setValues(m_layoutVector, layout); |
|
189 | 189 | presenter()->startAnimation(m_animation); |
|
190 | 190 | } else { |
|
191 | 191 | setLayout(layout); |
|
192 | 192 | updateGeometry(); |
|
193 | 193 | } |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | void ChartAxis::setLabelPadding(int padding) |
|
197 | 197 | { |
|
198 | 198 | m_labelPadding = padding; |
|
199 | 199 | } |
|
200 | 200 | |
|
201 | 201 | bool ChartAxis::isEmpty() |
|
202 | 202 | { |
|
203 | 203 | return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); |
|
204 | 204 | } |
|
205 | 205 | |
|
206 | 206 | void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
|
207 | 207 | { |
|
208 | 208 | m_gridRect = grid; |
|
209 | 209 | m_axisRect = axis; |
|
210 | 210 | |
|
211 | 211 | if (isEmpty()) |
|
212 | 212 | return; |
|
213 | 213 | |
|
214 | 214 | QVector<qreal> layout = calculateLayout(); |
|
215 | 215 | updateLayout(layout); |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | qreal ChartAxis::min() const |
|
219 | 219 | { |
|
220 |
|
|
|
220 | return m_axis->d_ptr->min(); | |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | qreal ChartAxis::max() const |
|
224 | 224 | { |
|
225 |
|
|
|
225 | return m_axis->d_ptr->max(); | |
|
226 | 226 | } |
|
227 | 227 | |
|
228 | 228 | QFont ChartAxis::font() const |
|
229 | 229 | { |
|
230 |
|
|
|
230 | return m_axis->labelsFont(); | |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | QFont ChartAxis::titleFont() const |
|
234 | 234 | { |
|
235 |
|
|
|
235 | return m_axis->titleFont(); | |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | QString ChartAxis::titleText() const |
|
239 | 239 | { |
|
240 |
|
|
|
240 | return m_axis->titleText(); | |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | void ChartAxis::axisSelected() |
|
244 | 244 | { |
|
245 |
|
|
|
245 | emit clicked(); | |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | Qt::Orientation ChartAxis::orientation() const |
|
249 | 249 | { |
|
250 | 250 | return m_axis->orientation(); |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | Qt::Alignment ChartAxis::alignment() const |
|
254 | 254 | { |
|
255 | 255 | return m_axis->alignment(); |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | void ChartAxis::setLabels(const QStringList &labels) |
|
259 | 259 | { |
|
260 | 260 | m_labelsList = labels; |
|
261 | 261 | } |
|
262 | 262 | |
|
263 | 263 | QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
264 | 264 | { |
|
265 | 265 | Q_UNUSED(which); |
|
266 | 266 | Q_UNUSED(constraint); |
|
267 | 267 | return QSizeF(); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | //handlers |
|
271 | 271 | |
|
272 | 272 | void ChartAxis::handleArrowVisibleChanged(bool visible) |
|
273 | 273 | { |
|
274 | 274 | m_arrow->setVisible(visible); |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | 277 | void ChartAxis::handleGridVisibleChanged(bool visible) |
|
278 | 278 | { |
|
279 | 279 | m_grid->setVisible(visible); |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | void ChartAxis::handleLabelsVisibleChanged(bool visible) |
|
283 | 283 | { |
|
284 | 284 | m_labels->setVisible(visible); |
|
285 | 285 | } |
|
286 | 286 | |
|
287 | 287 | void ChartAxis::handleShadesVisibleChanged(bool visible) |
|
288 | 288 | { |
|
289 | 289 | m_shades->setVisible(visible); |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | void ChartAxis::handleLabelsAngleChanged(int angle) |
|
293 | 293 | { |
|
294 | 294 | foreach (QGraphicsItem *item, m_labels->childItems()) |
|
295 | 295 | item->setRotation(angle); |
|
296 | 296 | |
|
297 | 297 | m_labelsAngle = angle; |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) |
|
301 | 301 | { |
|
302 | 302 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
303 | 303 | static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) |
|
307 | 307 | { |
|
308 | 308 | foreach (QGraphicsItem *item , m_labels->childItems()) |
|
309 | 309 | static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | void ChartAxis::handleLabelsFontChanged(const QFont &font) |
|
313 | 313 | { |
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
|
314 | foreach (QGraphicsItem *item , m_labels->childItems()) | |
|
315 | static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | |
|
316 | QGraphicsLayoutItem::updateGeometry(); | |
|
317 | presenter()->layout()->invalidate(); | |
|
318 | 318 | } |
|
319 | 319 | |
|
320 | 320 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) |
|
321 | 321 | { |
|
322 | 322 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
323 | 323 | static_cast<QGraphicsRectItem *>(item)->setBrush(brush); |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | void ChartAxis::handleShadesPenChanged(const QPen &pen) |
|
327 | 327 | { |
|
328 | 328 | foreach (QGraphicsItem *item , m_shades->childItems()) |
|
329 | 329 | static_cast<QGraphicsRectItem *>(item)->setPen(pen); |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | void ChartAxis::handleArrowPenChanged(const QPen &pen) |
|
333 | 333 | { |
|
334 | 334 | foreach (QGraphicsItem *item , m_arrow->childItems()) |
|
335 | 335 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
336 | 336 | } |
|
337 | 337 | |
|
338 | 338 | void ChartAxis::handleGridPenChanged(const QPen &pen) |
|
339 | 339 | { |
|
340 | 340 | foreach (QGraphicsItem *item , m_grid->childItems()) |
|
341 | 341 | static_cast<QGraphicsLineItem *>(item)->setPen(pen); |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | void ChartAxis::handleTitleTextChanged(const QString &title) |
|
345 | 345 | { |
|
346 |
|
|
|
347 |
|
|
|
348 |
|
|
|
346 | Q_UNUSED(title) | |
|
347 | QGraphicsLayoutItem::updateGeometry(); | |
|
348 | presenter()->layout()->invalidate(); | |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | |
|
352 | 352 | void ChartAxis::handleTitlePenChanged(const QPen &pen) |
|
353 | 353 | { |
|
354 | 354 | m_title->setPen(pen); |
|
355 | 355 | } |
|
356 | 356 | |
|
357 | 357 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) |
|
358 | 358 | { |
|
359 | 359 | m_title->setBrush(brush); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | void ChartAxis::handleTitleFontChanged(const QFont &font) |
|
363 | 363 | { |
|
364 | 364 | if(m_title->font() != font){ |
|
365 | 365 | m_title->setFont(font); |
|
366 | 366 | QGraphicsLayoutItem::updateGeometry(); |
|
367 | 367 | presenter()->layout()->invalidate(); |
|
368 | 368 | } |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | void ChartAxis::handleVisibleChanged(bool visible) |
|
372 | 372 | { |
|
373 |
|
|
|
373 | setVisible(visible); | |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | void ChartAxis::handleRangeChanged(qreal min, qreal max) |
|
377 | 377 | { |
|
378 |
|
|
|
379 |
|
|
|
378 | Q_UNUSED(min); | |
|
379 | Q_UNUSED(max); | |
|
380 | 380 | |
|
381 |
|
|
|
381 | if (!isEmpty()) { | |
|
382 | 382 | |
|
383 |
|
|
|
384 |
|
|
|
385 |
|
|
|
386 |
|
|
|
383 | QVector<qreal> layout = calculateLayout(); | |
|
384 | updateLayout(layout); | |
|
385 | QSizeF before = effectiveSizeHint(Qt::PreferredSize); | |
|
386 | QSizeF after = sizeHint(Qt::PreferredSize); | |
|
387 | 387 | |
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
|
|
|
392 |
|
|
|
393 |
|
|
|
394 | } | |
|
395 | } | |
|
388 | if (before != after) { | |
|
389 | QGraphicsLayoutItem::updateGeometry(); | |
|
390 | //we don't want to call invalidate on layout, since it will change minimum size of component, | |
|
391 | //which we would like to avoid since it causes nasty flips when scrolling or zooming, | |
|
392 | //instead recalculate layout and use plotArea for extra space. | |
|
393 | presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | |
|
394 | } | |
|
395 | } | |
|
396 | 396 | |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | //helpers |
|
400 | 400 | |
|
401 | 401 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) |
|
402 | 402 | { |
|
403 | 403 | //TODO: Q_ASSERT(m_max > m_min); |
|
404 | 404 | //TODO: Q_ASSERT(ticks > 1); |
|
405 | 405 | |
|
406 | 406 | QStringList labels; |
|
407 | 407 | |
|
408 | 408 | if(max <= min || ticks < 1){ |
|
409 | 409 | return labels; |
|
410 | 410 | } |
|
411 | 411 | |
|
412 | 412 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
413 | 413 | n++; |
|
414 | 414 | |
|
415 | 415 | if (format.isNull()) { |
|
416 | 416 | for (int i = 0; i < ticks; i++) { |
|
417 | 417 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
418 | 418 | labels << QString::number(value, 'f', n); |
|
419 | 419 | } |
|
420 | 420 | } else { |
|
421 | 421 | QByteArray array = format.toLatin1(); |
|
422 | 422 | for (int i = 0; i < ticks; i++) { |
|
423 | 423 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
424 | 424 | if (format.contains("d") |
|
425 | 425 | || format.contains("i") |
|
426 | 426 | || format.contains("c")) |
|
427 | 427 | labels << QString().sprintf(array, (qint64)value); |
|
428 | 428 | else if (format.contains("u") |
|
429 | 429 | || format.contains("o") |
|
430 | 430 | || format.contains("x", Qt::CaseInsensitive)) |
|
431 | 431 | labels << QString().sprintf(array, (quint64)value); |
|
432 | 432 | else if (format.contains("f", Qt::CaseInsensitive) |
|
433 | 433 | || format.contains("e", Qt::CaseInsensitive) |
|
434 | 434 | || format.contains("g", Qt::CaseInsensitive)) |
|
435 | 435 | labels << QString().sprintf(array, value); |
|
436 | 436 | } |
|
437 | 437 | } |
|
438 | 438 | |
|
439 | 439 | return labels; |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) |
|
443 | 443 | { |
|
444 | 444 | // Q_ASSERT(m_max > m_min); |
|
445 | 445 | // Q_ASSERT(ticks > 1); |
|
446 | 446 | |
|
447 | 447 | QStringList labels; |
|
448 | 448 | |
|
449 | 449 | int n = 0; |
|
450 | 450 | if (ticks > 1) |
|
451 | 451 | n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); |
|
452 | 452 | n++; |
|
453 | 453 | |
|
454 | 454 | int firstTick; |
|
455 | 455 | if (base > 1) |
|
456 | 456 | firstTick = ceil(log10(min) / log10(base)); |
|
457 | 457 | else |
|
458 | 458 | firstTick = ceil(log10(max) / log10(base)); |
|
459 | 459 | |
|
460 | 460 | if (format.isNull()) { |
|
461 | 461 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
462 | 462 | qreal value = qPow(base, i); |
|
463 | 463 | labels << QString::number(value, 'f', n); |
|
464 | 464 | } |
|
465 | 465 | } else { |
|
466 |
QByteArray array = format.to |
|
|
466 | QByteArray array = format.toLatin1(); | |
|
467 | 467 | for (int i = firstTick; i < ticks + firstTick; i++) { |
|
468 | 468 | qreal value = qPow(base, i); |
|
469 | 469 | labels << QString().sprintf(array, value); |
|
470 | 470 | } |
|
471 | 471 | } |
|
472 | 472 | |
|
473 | 473 | return labels; |
|
474 | 474 | } |
|
475 | 475 | |
|
476 | 476 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) |
|
477 | 477 | { |
|
478 | 478 | //TODO: Q_ASSERT(m_max > m_min); |
|
479 | 479 | //TODO: Q_ASSERT(ticks > 1); |
|
480 | 480 | QStringList labels; |
|
481 | 481 | |
|
482 | 482 | if(max <= min || ticks < 1) { |
|
483 | 483 | return labels; |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); |
|
487 | 487 | n++; |
|
488 | 488 | for (int i = 0; i < ticks; i++) { |
|
489 | 489 | qreal value = min + (i * (max - min) / (ticks - 1)); |
|
490 | 490 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); |
|
491 | 491 | } |
|
492 | 492 | return labels; |
|
493 | 493 | } |
|
494 | 494 | |
|
495 | 495 | #include "moc_chartaxis_p.cpp" |
|
496 | 496 | |
|
497 | 497 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,925 +1,925 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | |
|
31 | 31 | #include "qpielegendmarker.h" |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 | 36 | \class QPieSeries |
|
37 | 37 | \brief Pie series API for QtCommercial Charts |
|
38 | 38 | |
|
39 | 39 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
40 | 40 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
41 | 41 | The actual slice size is determined by that relative value. |
|
42 | 42 | |
|
43 | 43 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
44 | 44 | These relate to the actual chart rectangle. |
|
45 | 45 | |
|
46 | 46 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
47 | 47 | This can be done by setting a starting angle and angle span to the series. |
|
48 | 48 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
49 | 49 | |
|
50 | 50 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. |
|
51 | 51 | \table 100% |
|
52 | 52 | \row |
|
53 | 53 | \o \image examples_piechart.png |
|
54 | 54 | \o \image examples_donut.png |
|
55 | 55 | \endtable |
|
56 | 56 | */ |
|
57 | 57 | /*! |
|
58 | 58 | \qmlclass PieSeries QPieSeries |
|
59 | 59 | \inherits AbstractSeries |
|
60 | 60 | |
|
61 | 61 | The following QML shows how to create a simple pie chart. |
|
62 | 62 | |
|
63 | 63 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
64 | 64 | |
|
65 | 65 | \beginfloatleft |
|
66 | 66 | \image demos_qmlchart1.png |
|
67 | 67 | \endfloat |
|
68 | 68 | \clearfloat |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \property QPieSeries::horizontalPosition |
|
73 | 73 | \brief Defines the horizontal position of the pie. |
|
74 | 74 | |
|
75 | 75 | The value is a relative value to the chart rectangle where: |
|
76 | 76 | |
|
77 | 77 | \list |
|
78 | 78 | \o 0.0 is the absolute left. |
|
79 | 79 | \o 1.0 is the absolute right. |
|
80 | 80 | \endlist |
|
81 | 81 | Default value is 0.5 (center). |
|
82 | 82 | \sa verticalPosition |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \qmlproperty real PieSeries::horizontalPosition |
|
87 | 87 | |
|
88 | 88 | Defines the horizontal position of the pie. |
|
89 | 89 | |
|
90 | 90 | The value is a relative value to the chart rectangle where: |
|
91 | 91 | |
|
92 | 92 | \list |
|
93 | 93 | \o 0.0 is the absolute left. |
|
94 | 94 | \o 1.0 is the absolute right. |
|
95 | 95 | \endlist |
|
96 | 96 | Default value is 0.5 (center). |
|
97 | 97 | \sa verticalPosition |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \property QPieSeries::verticalPosition |
|
102 | 102 | \brief Defines the vertical position of the pie. |
|
103 | 103 | |
|
104 | 104 | The value is a relative value to the chart rectangle where: |
|
105 | 105 | |
|
106 | 106 | \list |
|
107 | 107 | \o 0.0 is the absolute top. |
|
108 | 108 | \o 1.0 is the absolute bottom. |
|
109 | 109 | \endlist |
|
110 | 110 | Default value is 0.5 (center). |
|
111 | 111 | \sa horizontalPosition |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | 115 | \qmlproperty real PieSeries::verticalPosition |
|
116 | 116 | |
|
117 | 117 | Defines the vertical position of the pie. |
|
118 | 118 | |
|
119 | 119 | The value is a relative value to the chart rectangle where: |
|
120 | 120 | |
|
121 | 121 | \list |
|
122 | 122 | \o 0.0 is the absolute top. |
|
123 | 123 | \o 1.0 is the absolute bottom. |
|
124 | 124 | \endlist |
|
125 | 125 | Default value is 0.5 (center). |
|
126 | 126 | \sa horizontalPosition |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \property QPieSeries::size |
|
131 | 131 | \brief Defines the pie size. |
|
132 | 132 | |
|
133 | 133 | The value is a relative value to the chart rectangle where: |
|
134 | 134 | |
|
135 | 135 | \list |
|
136 | 136 | \o 0.0 is the minimum size (pie not drawn). |
|
137 | 137 | \o 1.0 is the maximum size that can fit the chart. |
|
138 | 138 | \endlist |
|
139 | 139 | |
|
140 | 140 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. |
|
141 | 141 | |
|
142 | 142 | Default value is 0.7. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \qmlproperty real PieSeries::size |
|
147 | 147 | |
|
148 | 148 | Defines the pie size. |
|
149 | 149 | |
|
150 | 150 | The value is a relative value to the chart rectangle where: |
|
151 | 151 | |
|
152 | 152 | \list |
|
153 | 153 | \o 0.0 is the minimum size (pie not drawn). |
|
154 | 154 | \o 1.0 is the maximum size that can fit the chart. |
|
155 | 155 | \endlist |
|
156 | 156 | |
|
157 | 157 | Default value is 0.7. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | \property QPieSeries::holeSize |
|
162 | 162 | \brief Defines the donut hole size. |
|
163 | 163 | |
|
164 | 164 | The value is a relative value to the chart rectangle where: |
|
165 | 165 | |
|
166 | 166 | \list |
|
167 | 167 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
168 | 168 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
169 | 169 | \endlist |
|
170 | 170 | |
|
171 | 171 | The value is never greater then size property. |
|
172 | 172 | Default value is 0.0. |
|
173 | 173 | */ |
|
174 | 174 | |
|
175 | 175 | /*! |
|
176 | 176 | \qmlproperty real PieSeries::holeSize |
|
177 | 177 | |
|
178 | 178 | Defines the donut hole size. |
|
179 | 179 | |
|
180 | 180 | The value is a relative value to the chart rectangle where: |
|
181 | 181 | |
|
182 | 182 | \list |
|
183 | 183 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
184 | 184 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
185 | 185 | \endlist |
|
186 | 186 | |
|
187 | 187 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. |
|
188 | 188 | |
|
189 | 189 | Default value is 0.0. |
|
190 | 190 | */ |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | \property QPieSeries::startAngle |
|
194 | 194 | \brief Defines the starting angle of the pie. |
|
195 | 195 | |
|
196 | 196 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
197 | 197 | |
|
198 | 198 | Default is value is 0. |
|
199 | 199 | */ |
|
200 | 200 | |
|
201 | 201 | /*! |
|
202 | 202 | \qmlproperty real PieSeries::startAngle |
|
203 | 203 | |
|
204 | 204 | Defines the starting angle of the pie. |
|
205 | 205 | |
|
206 | 206 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
207 | 207 | |
|
208 | 208 | Default is value is 0. |
|
209 | 209 | */ |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | \property QPieSeries::endAngle |
|
213 | 213 | \brief Defines the ending angle of the pie. |
|
214 | 214 | |
|
215 | 215 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
216 | 216 | |
|
217 | 217 | Default is value is 360. |
|
218 | 218 | */ |
|
219 | 219 | |
|
220 | 220 | /*! |
|
221 | 221 | \qmlproperty real PieSeries::endAngle |
|
222 | 222 | |
|
223 | 223 | Defines the ending angle of the pie. |
|
224 | 224 | |
|
225 | 225 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
226 | 226 | |
|
227 | 227 | Default is value is 360. |
|
228 | 228 | */ |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | \property QPieSeries::count |
|
232 | 232 | |
|
233 | 233 | Number of slices in the series. |
|
234 | 234 | */ |
|
235 | 235 | |
|
236 | 236 | /*! |
|
237 | 237 | \qmlproperty int PieSeries::count |
|
238 | 238 | |
|
239 | 239 | Number of slices in the series. |
|
240 | 240 | */ |
|
241 | 241 | |
|
242 | 242 | /*! |
|
243 | 243 | \fn void QPieSeries::countChanged() |
|
244 | 244 | Emitted when the slice count has changed. |
|
245 | 245 | \sa count |
|
246 | 246 | */ |
|
247 | 247 | /*! |
|
248 | 248 | \qmlsignal PieSeries::onCountChanged() |
|
249 | 249 | Emitted when the slice count has changed. |
|
250 | 250 | */ |
|
251 | 251 | |
|
252 | 252 | /*! |
|
253 | 253 | \property QPieSeries::sum |
|
254 | 254 | |
|
255 | 255 | Sum of all slices. |
|
256 | 256 | |
|
257 | 257 | The series keeps track of the sum of all slices it holds. |
|
258 | 258 | */ |
|
259 | 259 | |
|
260 | 260 | /*! |
|
261 | 261 | \qmlproperty real PieSeries::sum |
|
262 | 262 | |
|
263 | 263 | Sum of all slices. |
|
264 | 264 | |
|
265 | 265 | The series keeps track of the sum of all slices it holds. |
|
266 | 266 | */ |
|
267 | 267 | |
|
268 | 268 | /*! |
|
269 | 269 | \fn void QPieSeries::sumChanged() |
|
270 | 270 | Emitted when the sum of all slices has changed. |
|
271 | 271 | \sa sum |
|
272 | 272 | */ |
|
273 | 273 | /*! |
|
274 | 274 | \qmlsignal PieSeries::onSumChanged() |
|
275 | 275 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
276 | 276 | change value of a slice. |
|
277 | 277 | */ |
|
278 | 278 | |
|
279 | 279 | /*! |
|
280 | 280 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
281 | 281 | |
|
282 | 282 | This signal is emitted when \a slices have been added to the series. |
|
283 | 283 | |
|
284 | 284 | \sa append(), insert() |
|
285 | 285 | */ |
|
286 | 286 | /*! |
|
287 | 287 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
288 | 288 | Emitted when \a slice has been added to the series. |
|
289 | 289 | */ |
|
290 | 290 | |
|
291 | 291 | /*! |
|
292 | 292 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
293 | 293 | This signal is emitted when \a slices have been removed from the series. |
|
294 | 294 | \sa remove() |
|
295 | 295 | */ |
|
296 | 296 | /*! |
|
297 | 297 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
298 | 298 | Emitted when \a slice has been removed from the series. |
|
299 | 299 | */ |
|
300 | 300 | |
|
301 | 301 | /*! |
|
302 | 302 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
303 | 303 | This signal is emitted when a \a slice has been clicked. |
|
304 | 304 | \sa QPieSlice::clicked() |
|
305 | 305 | */ |
|
306 | 306 | /*! |
|
307 | 307 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
308 | 308 | This signal is emitted when a \a slice has been clicked. |
|
309 | 309 | */ |
|
310 | 310 | |
|
311 | 311 | /*! |
|
312 | 312 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
313 | 313 | This signal is emitted when user has hovered over or away from the \a slice. |
|
314 | 314 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
315 | 315 | \sa QPieSlice::hovered() |
|
316 | 316 | */ |
|
317 | 317 | /*! |
|
318 | 318 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
319 | 319 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
320 | 320 | over the slice and false when hover has moved away from the slice. |
|
321 | 321 | */ |
|
322 | 322 | |
|
323 | 323 | /*! |
|
324 | 324 | \qmlmethod PieSlice PieSeries::at(int index) |
|
325 | 325 | Returns slice at \a index. Returns null if the index is not valid. |
|
326 | 326 | */ |
|
327 | 327 | |
|
328 | 328 | /*! |
|
329 | 329 | \qmlmethod PieSlice PieSeries::find(string label) |
|
330 | 330 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
331 | 331 | */ |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
335 | 335 | Adds a new slice with \a label and \a value to the pie. |
|
336 | 336 | */ |
|
337 | 337 | |
|
338 | 338 | /*! |
|
339 | 339 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
340 | 340 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. |
|
341 | 341 | */ |
|
342 | 342 | |
|
343 | 343 | /*! |
|
344 | 344 | \qmlmethod PieSeries::clear() |
|
345 | 345 | Removes all slices from the pie. |
|
346 | 346 | */ |
|
347 | 347 | |
|
348 | 348 | /*! |
|
349 | 349 | Constructs a series object which is a child of \a parent. |
|
350 | 350 | */ |
|
351 | 351 | QPieSeries::QPieSeries(QObject *parent) |
|
352 | 352 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) |
|
353 | 353 | { |
|
354 | 354 | Q_D(QPieSeries); |
|
355 | 355 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | /*! |
|
359 | 359 | Destroys the series and its slices. |
|
360 | 360 | */ |
|
361 | 361 | QPieSeries::~QPieSeries() |
|
362 | 362 | { |
|
363 | 363 | // NOTE: d_prt destroyed by QObject |
|
364 | 364 | } |
|
365 | 365 | |
|
366 | 366 | /*! |
|
367 | 367 | Returns QChartSeries::SeriesTypePie. |
|
368 | 368 | */ |
|
369 | 369 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
370 | 370 | { |
|
371 | 371 | return QAbstractSeries::SeriesTypePie; |
|
372 | 372 | } |
|
373 | 373 | |
|
374 | 374 | /*! |
|
375 | 375 | Appends a single \a slice to the series. |
|
376 | 376 | Slice ownership is passed to the series. |
|
377 | 377 | |
|
378 | 378 | Returns true if append was succesfull. |
|
379 | 379 | */ |
|
380 | 380 | bool QPieSeries::append(QPieSlice *slice) |
|
381 | 381 | { |
|
382 | 382 | return append(QList<QPieSlice *>() << slice); |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | /*! |
|
386 | 386 | Appends an array of \a slices to the series. |
|
387 | 387 | Slice ownership is passed to the series. |
|
388 | 388 | |
|
389 | 389 | Returns true if append was successful. |
|
390 | 390 | */ |
|
391 | 391 | bool QPieSeries::append(QList<QPieSlice *> slices) |
|
392 | 392 | { |
|
393 | 393 | Q_D(QPieSeries); |
|
394 | 394 | |
|
395 | 395 | if (slices.count() == 0) |
|
396 | 396 | return false; |
|
397 | 397 | |
|
398 | 398 | foreach (QPieSlice *s, slices) { |
|
399 | 399 | if (!s || d->m_slices.contains(s)) |
|
400 | 400 | return false; |
|
401 | 401 | if (s->series()) // already added to some series |
|
402 | 402 | return false; |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | foreach (QPieSlice *s, slices) { |
|
406 | 406 | s->setParent(this); |
|
407 | 407 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
408 | 408 | d->m_slices << s; |
|
409 | 409 | } |
|
410 | 410 | |
|
411 | 411 | d->updateDerivativeData(); |
|
412 | 412 | |
|
413 | 413 | foreach(QPieSlice * s, slices) { |
|
414 | 414 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
415 | 415 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
416 | 416 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
417 | 417 | } |
|
418 | 418 | |
|
419 | 419 | emit added(slices); |
|
420 | 420 | emit countChanged(); |
|
421 | 421 | |
|
422 | 422 | return true; |
|
423 | 423 | } |
|
424 | 424 | |
|
425 | 425 | /*! |
|
426 | 426 | Appends a single \a slice to the series and returns a reference to the series. |
|
427 | 427 | Slice ownership is passed to the series. |
|
428 | 428 | */ |
|
429 | 429 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) |
|
430 | 430 | { |
|
431 | 431 | append(slice); |
|
432 | 432 | return *this; |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | |
|
436 | 436 | /*! |
|
437 | 437 | Appends a single slice to the series with give \a value and \a label. |
|
438 | 438 | Slice ownership is passed to the series. |
|
439 | 439 | */ |
|
440 | 440 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
441 | 441 | { |
|
442 | 442 | QPieSlice *slice = new QPieSlice(label, value); |
|
443 | 443 | append(slice); |
|
444 | 444 | return slice; |
|
445 | 445 | } |
|
446 | 446 | |
|
447 | 447 | /*! |
|
448 | 448 | Inserts a single \a slice to the series before the slice at \a index position. |
|
449 | 449 | Slice ownership is passed to the series. |
|
450 | 450 | |
|
451 | 451 | Returns true if insert was successful. |
|
452 | 452 | */ |
|
453 | 453 | bool QPieSeries::insert(int index, QPieSlice *slice) |
|
454 | 454 | { |
|
455 | 455 | Q_D(QPieSeries); |
|
456 | 456 | |
|
457 | 457 | if (index < 0 || index > d->m_slices.count()) |
|
458 | 458 | return false; |
|
459 | 459 | |
|
460 | 460 | if (!slice || d->m_slices.contains(slice)) |
|
461 | 461 | return false; |
|
462 | 462 | |
|
463 | 463 | if (slice->series()) // already added to some series |
|
464 | 464 | return false; |
|
465 | 465 | |
|
466 | 466 | slice->setParent(this); |
|
467 | 467 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
468 | 468 | d->m_slices.insert(index, slice); |
|
469 | 469 | |
|
470 | 470 | d->updateDerivativeData(); |
|
471 | 471 | |
|
472 | 472 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
473 | 473 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
474 | 474 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
475 | 475 | |
|
476 | 476 | emit added(QList<QPieSlice *>() << slice); |
|
477 | 477 | emit countChanged(); |
|
478 | 478 | |
|
479 | 479 | return true; |
|
480 | 480 | } |
|
481 | 481 | |
|
482 | 482 | /*! |
|
483 | 483 | Removes a single \a slice from the series and deletes the slice. |
|
484 | 484 | |
|
485 | 485 | Do not reference the pointer after this call. |
|
486 | 486 | |
|
487 | 487 | Returns true if remove was successful. |
|
488 | 488 | */ |
|
489 | 489 | bool QPieSeries::remove(QPieSlice *slice) |
|
490 | 490 | { |
|
491 | 491 | Q_D(QPieSeries); |
|
492 | 492 | |
|
493 | 493 | if (!d->m_slices.removeOne(slice)) |
|
494 | 494 | return false; |
|
495 | 495 | |
|
496 | 496 | d->updateDerivativeData(); |
|
497 | 497 | |
|
498 | 498 | emit removed(QList<QPieSlice *>() << slice); |
|
499 | 499 | emit countChanged(); |
|
500 | 500 | |
|
501 | 501 | delete slice; |
|
502 | 502 | slice = 0; |
|
503 | 503 | |
|
504 | 504 | return true; |
|
505 | 505 | } |
|
506 | 506 | |
|
507 | 507 | /*! |
|
508 | 508 | Takes a single \a slice from the series. Does not destroy the slice object. |
|
509 | 509 | |
|
510 | 510 | NOTE: The series remains as the slice's parent object. You must set the |
|
511 | 511 | parent object to take full ownership. |
|
512 | 512 | |
|
513 | 513 | Returns true if take was successful. |
|
514 | 514 | */ |
|
515 | 515 | bool QPieSeries::take(QPieSlice *slice) |
|
516 | 516 | { |
|
517 | 517 | Q_D(QPieSeries); |
|
518 | 518 | |
|
519 | 519 | if (!d->m_slices.removeOne(slice)) |
|
520 | 520 | return false; |
|
521 | 521 | |
|
522 | 522 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; |
|
523 | 523 | slice->disconnect(d); |
|
524 | 524 | |
|
525 | 525 | d->updateDerivativeData(); |
|
526 | 526 | |
|
527 | 527 | emit removed(QList<QPieSlice *>() << slice); |
|
528 | 528 | emit countChanged(); |
|
529 | 529 | |
|
530 | 530 | return true; |
|
531 | 531 | } |
|
532 | 532 | |
|
533 | 533 | /*! |
|
534 | 534 | Clears all slices from the series. |
|
535 | 535 | */ |
|
536 | 536 | void QPieSeries::clear() |
|
537 | 537 | { |
|
538 | 538 | Q_D(QPieSeries); |
|
539 | 539 | if (d->m_slices.count() == 0) |
|
540 | 540 | return; |
|
541 | 541 | |
|
542 | 542 | QList<QPieSlice *> slices = d->m_slices; |
|
543 | 543 | foreach (QPieSlice *s, d->m_slices) |
|
544 | 544 | d->m_slices.removeOne(s); |
|
545 | 545 | |
|
546 | 546 | d->updateDerivativeData(); |
|
547 | 547 | |
|
548 | 548 | emit removed(slices); |
|
549 | 549 | emit countChanged(); |
|
550 | 550 | |
|
551 | 551 | foreach (QPieSlice *s, slices) |
|
552 | 552 | delete s; |
|
553 | 553 | } |
|
554 | 554 | |
|
555 | 555 | /*! |
|
556 | 556 | Returns a list of slices that belong to this series. |
|
557 | 557 | */ |
|
558 | 558 | QList<QPieSlice *> QPieSeries::slices() const |
|
559 | 559 | { |
|
560 | 560 | Q_D(const QPieSeries); |
|
561 | 561 | return d->m_slices; |
|
562 | 562 | } |
|
563 | 563 | |
|
564 | 564 | /*! |
|
565 | 565 | returns the number of the slices in this series. |
|
566 | 566 | */ |
|
567 | 567 | int QPieSeries::count() const |
|
568 | 568 | { |
|
569 | 569 | Q_D(const QPieSeries); |
|
570 | 570 | return d->m_slices.count(); |
|
571 | 571 | } |
|
572 | 572 | |
|
573 | 573 | /*! |
|
574 | 574 | Returns true is the series is empty. |
|
575 | 575 | */ |
|
576 | 576 | bool QPieSeries::isEmpty() const |
|
577 | 577 | { |
|
578 | 578 | Q_D(const QPieSeries); |
|
579 | 579 | return d->m_slices.isEmpty(); |
|
580 | 580 | } |
|
581 | 581 | |
|
582 | 582 | /*! |
|
583 | 583 | Returns the sum of all slice values in this series. |
|
584 | 584 | |
|
585 | 585 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
586 | 586 | */ |
|
587 | 587 | qreal QPieSeries::sum() const |
|
588 | 588 | { |
|
589 | 589 | Q_D(const QPieSeries); |
|
590 | 590 | return d->m_sum; |
|
591 | 591 | } |
|
592 | 592 | |
|
593 | 593 | void QPieSeries::setHoleSize(qreal holeSize) |
|
594 | 594 | { |
|
595 | 595 | Q_D(QPieSeries); |
|
596 | 596 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); |
|
597 | 597 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); |
|
598 | 598 | } |
|
599 | 599 | |
|
600 | 600 | qreal QPieSeries::holeSize() const |
|
601 | 601 | { |
|
602 | 602 | Q_D(const QPieSeries); |
|
603 | 603 | return d->m_holeRelativeSize; |
|
604 | 604 | } |
|
605 | 605 | |
|
606 | 606 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
607 | 607 | { |
|
608 | 608 | Q_D(QPieSeries); |
|
609 | 609 | |
|
610 | 610 | if (relativePosition < 0.0) |
|
611 | 611 | relativePosition = 0.0; |
|
612 | 612 | if (relativePosition > 1.0) |
|
613 | 613 | relativePosition = 1.0; |
|
614 | 614 | |
|
615 | 615 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { |
|
616 | 616 | d->m_pieRelativeHorPos = relativePosition; |
|
617 | 617 | emit d->horizontalPositionChanged(); |
|
618 | 618 | } |
|
619 | 619 | } |
|
620 | 620 | |
|
621 | 621 | qreal QPieSeries::horizontalPosition() const |
|
622 | 622 | { |
|
623 | 623 | Q_D(const QPieSeries); |
|
624 | 624 | return d->m_pieRelativeHorPos; |
|
625 | 625 | } |
|
626 | 626 | |
|
627 | 627 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
628 | 628 | { |
|
629 | 629 | Q_D(QPieSeries); |
|
630 | 630 | |
|
631 | 631 | if (relativePosition < 0.0) |
|
632 | 632 | relativePosition = 0.0; |
|
633 | 633 | if (relativePosition > 1.0) |
|
634 | 634 | relativePosition = 1.0; |
|
635 | 635 | |
|
636 | 636 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { |
|
637 | 637 | d->m_pieRelativeVerPos = relativePosition; |
|
638 | 638 | emit d->verticalPositionChanged(); |
|
639 | 639 | } |
|
640 | 640 | } |
|
641 | 641 | |
|
642 | 642 | qreal QPieSeries::verticalPosition() const |
|
643 | 643 | { |
|
644 | 644 | Q_D(const QPieSeries); |
|
645 | 645 | return d->m_pieRelativeVerPos; |
|
646 | 646 | } |
|
647 | 647 | |
|
648 | 648 | void QPieSeries::setPieSize(qreal relativeSize) |
|
649 | 649 | { |
|
650 | 650 | Q_D(QPieSeries); |
|
651 | 651 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
652 | 652 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); |
|
653 | 653 | |
|
654 | 654 | } |
|
655 | 655 | |
|
656 | 656 | qreal QPieSeries::pieSize() const |
|
657 | 657 | { |
|
658 | 658 | Q_D(const QPieSeries); |
|
659 | 659 | return d->m_pieRelativeSize; |
|
660 | 660 | } |
|
661 | 661 | |
|
662 | 662 | |
|
663 | 663 | void QPieSeries::setPieStartAngle(qreal angle) |
|
664 | 664 | { |
|
665 | 665 | Q_D(QPieSeries); |
|
666 | 666 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) |
|
667 | 667 | return; |
|
668 | 668 | d->m_pieStartAngle = angle; |
|
669 | 669 | d->updateDerivativeData(); |
|
670 | 670 | emit d->pieStartAngleChanged(); |
|
671 | 671 | } |
|
672 | 672 | |
|
673 | 673 | qreal QPieSeries::pieStartAngle() const |
|
674 | 674 | { |
|
675 | 675 | Q_D(const QPieSeries); |
|
676 | 676 | return d->m_pieStartAngle; |
|
677 | 677 | } |
|
678 | 678 | |
|
679 | 679 | /*! |
|
680 | 680 | Sets the end angle of the pie. |
|
681 | 681 | |
|
682 | 682 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
683 | 683 | |
|
684 | 684 | \a angle must be greater than start angle. |
|
685 | 685 | |
|
686 | 686 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
687 | 687 | */ |
|
688 | 688 | void QPieSeries::setPieEndAngle(qreal angle) |
|
689 | 689 | { |
|
690 | 690 | Q_D(QPieSeries); |
|
691 | 691 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) |
|
692 | 692 | return; |
|
693 | 693 | d->m_pieEndAngle = angle; |
|
694 | 694 | d->updateDerivativeData(); |
|
695 | 695 | emit d->pieEndAngleChanged(); |
|
696 | 696 | } |
|
697 | 697 | |
|
698 | 698 | /*! |
|
699 | 699 | Returns the end angle of the pie. |
|
700 | 700 | |
|
701 | 701 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
702 | 702 | |
|
703 | 703 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
704 | 704 | */ |
|
705 | 705 | qreal QPieSeries::pieEndAngle() const |
|
706 | 706 | { |
|
707 | 707 | Q_D(const QPieSeries); |
|
708 | 708 | return d->m_pieEndAngle; |
|
709 | 709 | } |
|
710 | 710 | |
|
711 | 711 | /*! |
|
712 | 712 | Sets the all the slice labels \a visible or invisible. |
|
713 | 713 | |
|
714 | 714 | Note that this affects only the current slices in the series. |
|
715 | 715 | If user adds a new slice the default label visibility is false. |
|
716 | 716 | |
|
717 | 717 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
718 | 718 | */ |
|
719 | 719 | void QPieSeries::setLabelsVisible(bool visible) |
|
720 | 720 | { |
|
721 | 721 | Q_D(QPieSeries); |
|
722 | 722 | foreach (QPieSlice *s, d->m_slices) |
|
723 | 723 | s->setLabelVisible(visible); |
|
724 | 724 | } |
|
725 | 725 | |
|
726 | 726 | /*! |
|
727 | 727 | Sets the all the slice labels \a position |
|
728 | 728 | |
|
729 | 729 | Note that this affects only the current slices in the series. |
|
730 | 730 | If user adds a new slice the default label position is LabelOutside |
|
731 | 731 | |
|
732 | 732 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
733 | 733 | */ |
|
734 | 734 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
735 | 735 | { |
|
736 | 736 | Q_D(QPieSeries); |
|
737 | 737 | foreach (QPieSlice *s, d->m_slices) |
|
738 | 738 | s->setLabelPosition(position); |
|
739 | 739 | } |
|
740 | 740 | |
|
741 | 741 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
742 | 742 | |
|
743 | 743 | |
|
744 | 744 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
745 | 745 | QAbstractSeriesPrivate(parent), |
|
746 | 746 | m_pieRelativeHorPos(0.5), |
|
747 | 747 | m_pieRelativeVerPos(0.5), |
|
748 | 748 | m_pieRelativeSize(0.7), |
|
749 | 749 | m_pieStartAngle(0), |
|
750 | 750 | m_pieEndAngle(360), |
|
751 | 751 | m_sum(0), |
|
752 | 752 | m_holeRelativeSize(0.0) |
|
753 | 753 | { |
|
754 | 754 | } |
|
755 | 755 | |
|
756 | 756 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
757 | 757 | { |
|
758 | 758 | } |
|
759 | 759 | |
|
760 | 760 | void QPieSeriesPrivate::updateDerivativeData() |
|
761 | 761 | { |
|
762 | 762 | // calculate sum of all slices |
|
763 | 763 | qreal sum = 0; |
|
764 | 764 | foreach (QPieSlice *s, m_slices) |
|
765 | 765 | sum += s->value(); |
|
766 | 766 | |
|
767 | 767 | if (!qFuzzyCompare(m_sum, sum)) { |
|
768 | 768 | m_sum = sum; |
|
769 | 769 | emit q_func()->sumChanged(); |
|
770 | 770 | } |
|
771 | 771 | |
|
772 | 772 | // nothing to show.. |
|
773 | 773 | if (qFuzzyCompare(m_sum, 0)) |
|
774 | 774 | return; |
|
775 | 775 | |
|
776 | 776 | // update slice attributes |
|
777 | 777 | qreal sliceAngle = m_pieStartAngle; |
|
778 | 778 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
779 | 779 | QVector<QPieSlice *> changed; |
|
780 | 780 | foreach (QPieSlice *s, m_slices) { |
|
781 | 781 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
782 | 782 | d->setPercentage(s->value() / m_sum); |
|
783 | 783 | d->setStartAngle(sliceAngle); |
|
784 | 784 | d->setAngleSpan(pieSpan * s->percentage()); |
|
785 | 785 | sliceAngle += s->angleSpan(); |
|
786 | 786 | } |
|
787 | 787 | |
|
788 | 788 | |
|
789 | 789 | emit calculatedDataChanged(); |
|
790 | 790 | } |
|
791 | 791 | |
|
792 | 792 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
793 | 793 | { |
|
794 | 794 | bool changed = false; |
|
795 | 795 | |
|
796 | 796 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { |
|
797 | 797 | m_holeRelativeSize = innerSize; |
|
798 | 798 | changed = true; |
|
799 | 799 | } |
|
800 | 800 | |
|
801 | 801 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { |
|
802 | 802 | m_pieRelativeSize = outerSize; |
|
803 | 803 | changed = true; |
|
804 | 804 | } |
|
805 | 805 | |
|
806 | 806 | if (changed) |
|
807 | 807 | emit pieSizeChanged(); |
|
808 | 808 | } |
|
809 | 809 | |
|
810 | 810 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
811 | 811 | { |
|
812 | 812 | return series->d_func(); |
|
813 | 813 | } |
|
814 | 814 | |
|
815 | 815 | void QPieSeriesPrivate::sliceValueChanged() |
|
816 | 816 | { |
|
817 | 817 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
818 | 818 | updateDerivativeData(); |
|
819 | 819 | } |
|
820 | 820 | |
|
821 | 821 | void QPieSeriesPrivate::sliceClicked() |
|
822 | 822 | { |
|
823 | 823 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
824 | 824 | Q_ASSERT(m_slices.contains(slice)); |
|
825 | 825 | Q_Q(QPieSeries); |
|
826 | 826 | emit q->clicked(slice); |
|
827 | 827 | } |
|
828 | 828 | |
|
829 | 829 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
830 | 830 | { |
|
831 | 831 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
832 | 832 | Q_ASSERT(m_slices.contains(slice)); |
|
833 | 833 | Q_Q(QPieSeries); |
|
834 | 834 | emit q->hovered(slice, state); |
|
835 | 835 | } |
|
836 | 836 | |
|
837 | 837 | void QPieSeriesPrivate::initializeDomain() |
|
838 | 838 | { |
|
839 | 839 | // does not apply to pie |
|
840 | 840 | } |
|
841 | 841 | |
|
842 | 842 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
843 | 843 | { |
|
844 | 844 | Q_Q(QPieSeries); |
|
845 | 845 | PieChartItem *pie = new PieChartItem(q,parent); |
|
846 | 846 | m_item.reset(pie); |
|
847 | 847 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
848 | 848 | } |
|
849 | 849 | |
|
850 | 850 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
851 | 851 | { |
|
852 | 852 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); |
|
853 | 853 | Q_ASSERT(item); |
|
854 | 854 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
855 | 855 | item->setAnimation(new PieAnimation(item)); |
|
856 | 856 | }else{ |
|
857 | 857 | item->setAnimation(0); |
|
858 | 858 | } |
|
859 | 859 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
860 | 860 | } |
|
861 | 861 | |
|
862 | 862 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
863 | 863 | { |
|
864 | 864 | Q_Q(QPieSeries); |
|
865 | 865 | QList<QLegendMarker*> markers; |
|
866 | 866 | foreach(QPieSlice* slice, q->slices()) { |
|
867 | 867 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); |
|
868 | 868 | markers << marker; |
|
869 | 869 | } |
|
870 | 870 | return markers; |
|
871 | 871 | } |
|
872 | 872 | |
|
873 | 873 | void QPieSeriesPrivate::initializeAxes() |
|
874 | 874 | { |
|
875 | 875 | |
|
876 | 876 | } |
|
877 | 877 | |
|
878 | 878 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
879 | 879 | { |
|
880 | 880 | Q_UNUSED(orientation); |
|
881 | 881 | return QAbstractAxis::AxisTypeNoAxis; |
|
882 | 882 | } |
|
883 | 883 | |
|
884 | 884 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
885 | 885 | { |
|
886 | 886 | Q_UNUSED(orientation); |
|
887 | 887 | return 0; |
|
888 | 888 | } |
|
889 | 889 | |
|
890 | 890 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
891 | 891 | { |
|
892 | Q_Q(QPieSeries); | |
|
893 | const QList<QColor>& colors = theme->seriesColors(); | |
|
892 | //Q_Q(QPieSeries); | |
|
893 | //const QList<QColor>& colors = theme->seriesColors(); | |
|
894 | 894 | const QList<QGradient>& gradients = theme->seriesGradients(); |
|
895 | 895 | |
|
896 | 896 | for (int i(0); i < m_slices.count(); i++) { |
|
897 | 897 | |
|
898 | 898 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); |
|
899 | 899 | |
|
900 | 900 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
901 | 901 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); |
|
902 | 902 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); |
|
903 | 903 | |
|
904 | 904 | QPieSlice *s = m_slices.at(i); |
|
905 | 905 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
906 | 906 | |
|
907 | 907 | if (forced || d->m_data.m_slicePen.isThemed()) |
|
908 | 908 | d->setPen(penColor, true); |
|
909 | 909 | |
|
910 | 910 | if (forced || d->m_data.m_sliceBrush.isThemed()) |
|
911 | 911 | d->setBrush(brushColor, true); |
|
912 | 912 | |
|
913 | 913 | if (forced || d->m_data.m_labelBrush.isThemed()) |
|
914 | 914 | d->setLabelBrush(theme->labelBrush().color(), true); |
|
915 | 915 | |
|
916 | 916 | if (forced || d->m_data.m_labelFont.isThemed()) |
|
917 | 917 | d->setLabelFont(theme->labelFont(), true); |
|
918 | 918 | } |
|
919 | 919 | } |
|
920 | 920 | |
|
921 | 921 | |
|
922 | 922 | #include "moc_qpieseries.cpp" |
|
923 | 923 | #include "moc_qpieseries_p.cpp" |
|
924 | 924 | |
|
925 | 925 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,148 +1,148 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | #ifndef QCHART_H |
|
22 | 22 | #define QCHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QAbstractSeries> |
|
25 | 25 | #include <QLegend> |
|
26 | 26 | #include <QGraphicsWidget> |
|
27 | 27 | #include <QMargins> |
|
28 | 28 | |
|
29 | 29 | class QGraphicsSceneResizeEvent; |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | class QAbstractSeries; |
|
34 | 34 | class QAbstractAxis; |
|
35 | 35 | class QLegend; |
|
36 |
|
|
|
36 | class QChartPrivate; | |
|
37 | 37 | |
|
38 | 38 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
42 | 42 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
43 | 43 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible) |
|
44 | 44 | Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled) |
|
45 | 45 | Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions) |
|
46 | 46 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) |
|
47 | 47 | Q_ENUMS(ChartTheme) |
|
48 | 48 | Q_ENUMS(AnimationOption) |
|
49 | 49 | |
|
50 | 50 | public: |
|
51 | 51 | enum ChartTheme { |
|
52 | 52 | ChartThemeLight = 0, |
|
53 | 53 | ChartThemeBlueCerulean, |
|
54 | 54 | ChartThemeDark, |
|
55 | 55 | ChartThemeBrownSand, |
|
56 | 56 | ChartThemeBlueNcs, |
|
57 | 57 | ChartThemeHighContrast, |
|
58 | 58 | ChartThemeBlueIcy |
|
59 | 59 | }; |
|
60 | 60 | |
|
61 | 61 | enum AnimationOption { |
|
62 | 62 | NoAnimation = 0x0, |
|
63 | 63 | GridAxisAnimations = 0x1, |
|
64 | 64 | SeriesAnimations = 0x2, |
|
65 | 65 | AllAnimations = 0x3 |
|
66 | 66 | }; |
|
67 | 67 | |
|
68 | 68 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
69 | 69 | |
|
70 | 70 | public: |
|
71 | 71 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
72 | 72 | ~QChart(); |
|
73 | 73 | |
|
74 | 74 | void addSeries(QAbstractSeries *series); |
|
75 | 75 | void removeSeries(QAbstractSeries *series); |
|
76 | 76 | void removeAllSeries(); |
|
77 | 77 | QList<QAbstractSeries *> series() const; |
|
78 | 78 | |
|
79 | 79 | //depreciated shit//////////////////////////////////////////////////. |
|
80 | 80 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
81 | 81 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
82 | 82 | |
|
83 | 83 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; |
|
84 | 84 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; |
|
85 | 85 | ///////////////////////////////////////////////////////////////////// |
|
86 | 86 | |
|
87 | 87 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); |
|
88 | 88 | void removeAxis(QAbstractAxis *axis); |
|
89 | 89 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; |
|
90 | 90 | |
|
91 | 91 | void createDefaultAxes(); |
|
92 | 92 | |
|
93 | 93 | void setTheme(QChart::ChartTheme theme); |
|
94 | 94 | QChart::ChartTheme theme() const; |
|
95 | 95 | |
|
96 | 96 | void setTitle(const QString &title); |
|
97 | 97 | QString title() const; |
|
98 | 98 | void setTitleFont(const QFont &font); |
|
99 | 99 | QFont titleFont() const; |
|
100 | 100 | void setTitleBrush(const QBrush &brush); |
|
101 | 101 | QBrush titleBrush() const; |
|
102 | 102 | |
|
103 | 103 | void setBackgroundBrush(const QBrush &brush); |
|
104 | 104 | QBrush backgroundBrush() const; |
|
105 | 105 | void setBackgroundPen(const QPen &pen); |
|
106 | 106 | QPen backgroundPen() const; |
|
107 | 107 | void setBackgroundVisible(bool visible = true); |
|
108 | 108 | bool isBackgroundVisible() const; |
|
109 | 109 | |
|
110 | 110 | void setDropShadowEnabled(bool enabled = true); |
|
111 | 111 | bool isDropShadowEnabled() const; |
|
112 | 112 | void setAnimationOptions(AnimationOptions options); |
|
113 | 113 | AnimationOptions animationOptions() const; |
|
114 | 114 | |
|
115 | 115 | void zoomIn(); |
|
116 | 116 | void zoomOut(); |
|
117 | 117 | |
|
118 | 118 | void zoomIn(const QRectF &rect); |
|
119 | 119 | void zoom(qreal factor); |
|
120 | 120 | |
|
121 | 121 | void scroll(qreal dx, qreal dy); |
|
122 | 122 | |
|
123 | 123 | QLegend *legend() const; |
|
124 | 124 | |
|
125 | 125 | void setMinimumMargins(const QMargins& margins); |
|
126 | 126 | QMargins minimumMargins() const; |
|
127 | 127 | |
|
128 | 128 | void setMargins(const QMargins &margins); |
|
129 | 129 | QMargins margins() const; |
|
130 | 130 | |
|
131 | 131 | QRectF plotArea() const; |
|
132 | 132 | |
|
133 | 133 | protected: |
|
134 | 134 | QScopedPointer<QChartPrivate> d_ptr; |
|
135 | 135 | friend class QLegend; |
|
136 | 136 | friend class DeclarativeChart; |
|
137 | 137 | friend class ChartDataSet; |
|
138 | 138 | friend class ChartPresenter; |
|
139 | 139 | friend class ChartThemeManager; |
|
140 | 140 | friend class QAbstractSeries; |
|
141 | 141 | Q_DISABLE_COPY(QChart) |
|
142 | 142 | }; |
|
143 | 143 | |
|
144 | 144 | QTCOMMERCIALCHART_END_NAMESPACE |
|
145 | 145 | |
|
146 | 146 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
147 | 147 | |
|
148 | 148 | #endif // QCHART_H |
@@ -1,177 +1,177 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTTHEMESYSTEM_P_H |
|
31 | 31 | #define CHARTTHEMESYSTEM_P_H |
|
32 | 32 | |
|
33 | 33 | #include "charttheme_p.h" |
|
34 | 34 | #ifdef Q_OS_WIN |
|
35 | 35 | #include <windows.h> |
|
36 | 36 | #include <stdio.h> |
|
37 | 37 | #endif |
|
38 | 38 | |
|
39 | 39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | 40 | |
|
41 | 41 | class ChartThemeSystem: public ChartTheme |
|
42 | 42 | { |
|
43 | 43 | public: |
|
44 | 44 | // System theme not used at the moment (the user is not able to select this theme) |
|
45 | 45 | ChartThemeSystem() : ChartTheme(QChart::ChartThemeLight /*QChart::ChartThemeSystem*/) |
|
46 | 46 | { |
|
47 | 47 | #ifdef Q_OS_WIN |
|
48 | 48 | // We could also use theme specific window frame color as a series base color (it would give more |
|
49 | 49 | // variation to the base colors in addition to the blue and black used now) |
|
50 | 50 | |
|
51 | 51 | // First series base color from COLOR_HIGHLIGHT |
|
52 | 52 | DWORD colorHighlight; |
|
53 | 53 | colorHighlight = GetSysColor(COLOR_HIGHLIGHT); |
|
54 | 54 | m_seriesColors.append(QColor(GetRValue(colorHighlight), |
|
55 | 55 | GetGValue(colorHighlight), |
|
56 | 56 | GetBValue(colorHighlight))); |
|
57 | 57 | |
|
58 | 58 | // Second series base color from COLOR_WINDOWFRAME |
|
59 | 59 | DWORD colorWindowFrame; |
|
60 | 60 | colorWindowFrame = GetSysColor(COLOR_WINDOWFRAME); |
|
61 | 61 | m_seriesColors.append(QColor(GetRValue(colorWindowFrame), |
|
62 | 62 | GetGValue(colorWindowFrame), |
|
63 | 63 | GetBValue(colorWindowFrame))); |
|
64 | 64 | |
|
65 | 65 | // Third series base color from the middle of the COLOR_ACTIVECAPTION / |
|
66 | 66 | // COLOR_GRADIENTACTIVECAPTION gradient |
|
67 | 67 | DWORD colorGradientActiveCaptionLeft; |
|
68 | 68 | colorGradientActiveCaptionLeft = GetSysColor(COLOR_ACTIVECAPTION); |
|
69 | 69 | DWORD colorGradientActiveCaptionRight; |
|
70 | 70 | colorGradientActiveCaptionRight = GetSysColor(COLOR_GRADIENTACTIVECAPTION); |
|
71 | 71 | QLinearGradient g; |
|
72 | 72 | QColor start = QColor(GetRValue(colorGradientActiveCaptionLeft), |
|
73 | 73 | GetGValue(colorGradientActiveCaptionLeft), |
|
74 | 74 | GetBValue(colorGradientActiveCaptionLeft)); |
|
75 | 75 | g.setColorAt(0.0, start); |
|
76 | 76 | QColor end = QColor(GetRValue(colorGradientActiveCaptionRight), |
|
77 | 77 | GetGValue(colorGradientActiveCaptionRight), |
|
78 | 78 | GetBValue(colorGradientActiveCaptionRight)); |
|
79 | 79 | g.setColorAt(1.0, end); |
|
80 | m_seriesColors.append(colorAt(g, 0.5)); | |
|
80 | m_seriesColors.append(ChartThemeManager::colorAt(g, 0.5)); | |
|
81 | 81 | |
|
82 | 82 | // Generate gradients from the base colors |
|
83 | generateSeriesGradients(); | |
|
83 | ChartThemeManager::generateSeriesGradients(m_seriesColors); | |
|
84 | 84 | |
|
85 | 85 | // Background fill color from COLOR_WINDOW |
|
86 | 86 | QLinearGradient backgroundGradient; |
|
87 | 87 | DWORD colorWindow; |
|
88 | 88 | colorWindow = GetSysColor(COLOR_WINDOW); |
|
89 | 89 | backgroundGradient.setColorAt(0.0, QColor(GetRValue(colorWindow), |
|
90 | 90 | GetGValue(colorWindow), |
|
91 | 91 | GetBValue(colorWindow))); |
|
92 | 92 | backgroundGradient.setColorAt(1.0, QColor(GetRValue(colorWindow), |
|
93 | 93 | GetGValue(colorWindow), |
|
94 | 94 | GetBValue(colorWindow))); |
|
95 | 95 | // Axes and other |
|
96 | 96 | m_axisLinePen = QPen(0xd6d6d6); |
|
97 | 97 | m_axisLinePen.setWidth(1); |
|
98 | 98 | m_labelBrush = QBrush(QRgb(0x404044)); |
|
99 | 99 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
100 | 100 | m_gridLinePen.setWidth(1); |
|
101 | 101 | m_backgroundShades = BackgroundShadesNone; |
|
102 | 102 | |
|
103 | 103 | #elif defined(Q_OS_LINUX) |
|
104 | 104 | // Using a hard coded theme for Linux system theme |
|
105 | 105 | m_seriesColors << QRgb(0x60a6e6); |
|
106 | 106 | m_seriesColors << QRgb(0x92ca66); |
|
107 | 107 | m_seriesColors << QRgb(0xeba85f); |
|
108 | 108 | m_seriesColors << QRgb(0xfc5751); |
|
109 | 109 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); |
|
110 | 110 | |
|
111 | 111 | // Background |
|
112 | 112 | QLinearGradient backgroundGradient; |
|
113 | 113 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
114 | 114 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
115 | 115 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
116 | 116 | m_chartBackgroundGradient = backgroundGradient; |
|
117 | 117 | |
|
118 | 118 | // Axes and other |
|
119 | 119 | m_axisLinePen = QPen(0xd6d6d6); |
|
120 | 120 | m_axisLinePen.setWidth(1); |
|
121 | 121 | m_labelBrush = QBrush(QRgb(0x404044)); |
|
122 | 122 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
123 | 123 | m_gridLinePen.setWidth(1); |
|
124 | 124 | m_backgroundShades = BackgroundShadesNone; |
|
125 | 125 | |
|
126 | 126 | #elif defined(Q_OS_MAC) |
|
127 | 127 | // Using a hard coded theme for OSX system theme; the colors match the OSX 10.7 colors |
|
128 | 128 | m_seriesColors << QRgb(0x60a6e6); |
|
129 | 129 | m_seriesColors << QRgb(0x92ca66); |
|
130 | 130 | m_seriesColors << QRgb(0xeba85f); |
|
131 | 131 | m_seriesColors << QRgb(0xfc5751); |
|
132 | 132 | generateSeriesGradients(); |
|
133 | 133 | |
|
134 | 134 | // Background |
|
135 | 135 | QLinearGradient backgroundGradient; |
|
136 | 136 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
137 | 137 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
138 | 138 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
139 | 139 | m_chartBackgroundGradient = backgroundGradient; |
|
140 | 140 | |
|
141 | 141 | // Axes and other |
|
142 | 142 | m_axisLinePen = QPen(0xd6d6d6); |
|
143 | 143 | m_axisLinePen.setWidth(1); |
|
144 | 144 | m_labelBrush = QBrush(QRgb(0x404044)); |
|
145 | 145 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
146 | 146 | m_gridLinePen.setWidth(1); |
|
147 | 147 | m_backgroundShades = BackgroundShadesNone; |
|
148 | 148 | |
|
149 | 149 | #else |
|
150 | 150 | // Hard coded theme |
|
151 | 151 | m_seriesColors << QRgb(0x60a6e6); |
|
152 | 152 | m_seriesColors << QRgb(0x92ca66); |
|
153 | 153 | m_seriesColors << QRgb(0xeba85f); |
|
154 | 154 | m_seriesColors << QRgb(0xfc5751); |
|
155 | 155 | m_seriesGradients = ChartThemeManager::generateSeriesGradients(m_seriesColors); |
|
156 | 156 | |
|
157 | 157 | // Background |
|
158 | 158 | QLinearGradient backgroundGradient; |
|
159 | 159 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); |
|
160 | 160 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); |
|
161 | 161 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
162 | 162 | m_chartBackgroundGradient = backgroundGradient; |
|
163 | 163 | |
|
164 | 164 | // Axes and other |
|
165 | 165 | m_axisLinePen = QPen(0xd6d6d6); |
|
166 | 166 | m_axisLinePen.setWidth(1); |
|
167 | 167 | m_labelBrush = QBrush(QRgb(0x404044)); |
|
168 | 168 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); |
|
169 | 169 | m_gridLinePen.setWidth(1); |
|
170 | 170 | m_backgroundShades = BackgroundShadesNone; |
|
171 | 171 | #endif |
|
172 | 172 | } |
|
173 | 173 | }; |
|
174 | 174 | |
|
175 | 175 | QTCOMMERCIALCHART_END_NAMESPACE |
|
176 | 176 | |
|
177 | 177 | #endif // CHARTTHEMESYSTEM_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now