@@ -1,900 +1,924 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 "declarativelineseries.h" |
|
24 | 24 | #include "declarativeareaseries.h" |
|
25 | 25 | #include "declarativebarseries.h" |
|
26 | 26 | #include "declarativepieseries.h" |
|
27 | 27 | #include "declarativesplineseries.h" |
|
28 | 28 | #include "declarativescatterseries.h" |
|
29 | 29 | #include "qbarcategoryaxis.h" |
|
30 | 30 | #include "qvalueaxis.h" |
|
31 | 31 | #include "qlogvalueaxis.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 "declarativeaxes.h" |
|
37 | 37 | #include "qchart_p.h" |
|
38 | 38 | #include "qpolarchart.h" |
|
39 | 39 | |
|
40 | 40 | #ifndef QT_ON_ARM |
|
41 | 41 | #include "qdatetimeaxis.h" |
|
42 | 42 | #endif |
|
43 | 43 | |
|
44 | 44 | #ifdef CHARTS_FOR_QUICK2 |
|
45 | 45 | #include <QGraphicsSceneMouseEvent> |
|
46 | 46 | #include <QGraphicsSceneHoverEvent> |
|
47 | 47 | #include <QApplication> |
|
48 | 48 | #endif |
|
49 | 49 | |
|
50 | 50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
51 | 51 | |
|
52 | 52 | /*! |
|
53 | 53 | \qmlclass ChartView DeclarativeChart |
|
54 | 54 | |
|
55 | 55 | ChartView element is the parent that is responsible for showing different chart series types. |
|
56 | 56 | |
|
57 | 57 | The following QML shows how to create a simple chart with one pie series: |
|
58 | 58 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
59 | 59 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
60 | 60 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
61 | 61 | |
|
62 | 62 | \beginfloatleft |
|
63 | 63 | \image examples_qmlpiechart.png |
|
64 | 64 | \endfloat |
|
65 | 65 | \clearfloat |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty Theme ChartView::theme |
|
70 | 70 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
71 | 71 | widths and chart background. |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \qmlproperty Animation ChartView::animationOptions |
|
76 | 76 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
77 | 77 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty Font ChartView::titleFont |
|
82 | 82 | The title font of the chart |
|
83 | 83 | |
|
84 | 84 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \qmlproperty string ChartView::title |
|
89 | 89 | The title of the chart, shown on top of the chart. |
|
90 | 90 | \sa ChartView::titleColor |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \qmlproperty color ChartView::titleColor |
|
95 | 95 | The color of the title text. |
|
96 | 96 | */ |
|
97 | 97 | |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty Legend ChartView::legend |
|
100 | 100 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \qmlproperty int ChartView::count |
|
105 | 105 | The count of series added to the chart. |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \qmlproperty color ChartView::backgroundColor |
|
110 | 110 | The color of the chart's background. By default background color is defined by chart theme. |
|
111 | 111 | \sa ChartView::theme |
|
112 | 112 | */ |
|
113 | 113 | |
|
114 | 114 | /*! |
|
115 | \qmlproperty color ChartView::plotAreaColor | |
|
116 | The color of the background of the chart's plot area. By default plot area background uses chart's | |
|
117 | background color. | |
|
118 | \sa ChartView::backgroundColor | |
|
119 | */ | |
|
120 | ||
|
121 | /*! | |
|
115 | 122 | \qmlproperty bool ChartView::dropShadowEnabled |
|
116 | 123 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
117 | 124 | */ |
|
118 | 125 | |
|
119 | 126 | /*! |
|
120 | 127 | \qmlproperty real ChartView::topMargin |
|
121 | 128 | */ |
|
122 | 129 | |
|
123 | 130 | /*! |
|
124 | 131 | \qmlproperty real ChartView::bottomMargin |
|
125 | 132 | */ |
|
126 | 133 | |
|
127 | 134 | /*! |
|
128 | 135 | \qmlproperty real ChartView::leftMargin |
|
129 | 136 | */ |
|
130 | 137 | |
|
131 | 138 | /*! |
|
132 | 139 | \qmlproperty real ChartView::rightMargin |
|
133 | 140 | */ |
|
134 | 141 | |
|
135 | 142 | /*! |
|
136 | 143 | \qmlproperty Margins ChartView::minimumMargins |
|
137 | 144 | Deprecated; use margins instead. |
|
138 | 145 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
139 | 146 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
140 | 147 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
141 | 148 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
142 | 149 | given time, you can check ChartView::plotArea instead. |
|
143 | 150 | */ |
|
144 | 151 | |
|
145 | 152 | /*! |
|
146 | 153 | \qmlproperty rect ChartView::plotArea |
|
147 | 154 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
148 | 155 | margins. |
|
149 | 156 | \sa ChartView::minimumMargins |
|
150 | 157 | */ |
|
151 | 158 | |
|
152 | 159 | /*! |
|
153 | 160 | \qmlproperty Margins ChartView::margins |
|
154 | 161 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
155 | 162 | area of ChartView is used for drawing title, axes and legend. |
|
156 | 163 | */ |
|
157 | 164 | |
|
158 | 165 | /*! |
|
159 | 166 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
160 | 167 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
161 | 168 | the count property of the chart. |
|
162 | 169 | */ |
|
163 | 170 | |
|
164 | 171 | /*! |
|
165 | 172 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
166 | 173 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
167 | 174 | */ |
|
168 | 175 | |
|
169 | 176 | /*! |
|
170 | 177 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
171 | 178 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
172 | 179 | optional axis \a axisY. For example: |
|
173 | 180 | \code |
|
174 | 181 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
175 | 182 | var myAxisX = chartView.axisX(lineSeries); |
|
176 | 183 | var myAxisY = chartView.axisY(lineSeries); |
|
177 | 184 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
178 | 185 | \endcode |
|
179 | 186 | */ |
|
180 | 187 | |
|
181 | 188 | /*! |
|
182 | 189 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
183 | 190 | Removes the \a series from the chart. The series object is also destroyed. |
|
184 | 191 | */ |
|
185 | 192 | |
|
186 | 193 | /*! |
|
187 | 194 | \qmlmethod ChartView::removeAllSeries() |
|
188 | 195 | Removes all series from the chart. All the series objects are also destroyed. |
|
189 | 196 | */ |
|
190 | 197 | |
|
191 | 198 | /*! |
|
192 | 199 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
193 | 200 | The x-axis of the series. |
|
194 | 201 | */ |
|
195 | 202 | |
|
196 | 203 | /*! |
|
197 | 204 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
198 | 205 | The y-axis of the series. |
|
199 | 206 | */ |
|
200 | 207 | |
|
201 | 208 | /*! |
|
202 | 209 | \qmlmethod ChartView::zoomY(real factor) |
|
203 | 210 | Zooms in by \a factor on the center of the chart. |
|
204 | 211 | */ |
|
205 | 212 | |
|
206 | 213 | /*! |
|
207 | 214 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
208 | 215 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
209 | 216 | */ |
|
210 | 217 | |
|
211 | 218 | /*! |
|
212 | 219 | \qmlmethod ChartView::scrollRight(real pixels) |
|
213 | 220 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
214 | 221 | */ |
|
215 | 222 | |
|
216 | 223 | /*! |
|
217 | 224 | \qmlmethod ChartView::scrollUp(real pixels) |
|
218 | 225 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
219 | 226 | */ |
|
220 | 227 | |
|
221 | 228 | /*! |
|
222 | 229 | \qmlmethod ChartView::scrollDown(real pixels) |
|
223 | 230 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
224 | 231 | */ |
|
225 | 232 | |
|
226 | 233 | /*! |
|
227 | 234 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
228 | 235 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
229 | 236 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
230 | 237 | title. |
|
231 | 238 | */ |
|
232 | 239 | |
|
233 | 240 | /*! |
|
234 | 241 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
235 | 242 | The \a series has been added to the chart. |
|
236 | 243 | */ |
|
237 | 244 | |
|
238 | 245 | /*! |
|
239 | 246 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
240 | 247 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
241 | 248 | object after the signal handler has completed. |
|
242 | 249 | */ |
|
243 | 250 | |
|
244 | 251 | DeclarativeChart::DeclarativeChart(QDECLARATIVE_ITEM *parent) |
|
245 | 252 | : QDECLARATIVE_PAINTED_ITEM(parent) |
|
246 | 253 | { |
|
247 | 254 | initChart(QChart::ChartTypeCartesian); |
|
248 | 255 | } |
|
249 | 256 | |
|
250 | 257 | DeclarativeChart::DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent) |
|
251 | 258 | : QDECLARATIVE_PAINTED_ITEM(parent) |
|
252 | 259 | { |
|
253 | 260 | initChart(type); |
|
254 | 261 | } |
|
255 | 262 | |
|
256 | 263 | void DeclarativeChart::initChart(QChart::ChartType type) |
|
257 | 264 | { |
|
258 | 265 | #ifdef CHARTS_FOR_QUICK2 |
|
259 | 266 | if (type == QChart::ChartTypePolar) |
|
260 | 267 | m_chart = new QPolarChart(); |
|
261 | 268 | else |
|
262 | 269 | m_chart = new QChart(); |
|
263 | 270 | |
|
264 | 271 | m_scene = new QGraphicsScene(this); |
|
265 | 272 | m_scene->addItem(m_chart); |
|
266 | 273 | |
|
267 | 274 | setAntialiasing(QQuickItem::antialiasing()); |
|
268 | 275 | connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(update())); |
|
269 | 276 | connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool))); |
|
270 | 277 | |
|
271 | 278 | setAcceptedMouseButtons(Qt::AllButtons); |
|
272 | 279 | setAcceptHoverEvents(true); |
|
273 | 280 | #else |
|
274 | 281 | if (type == QChart::ChartTypePolar) |
|
275 | 282 | m_chart = new QPolarChart(this); |
|
276 | 283 | else |
|
277 | 284 | m_chart = new QChart(this); |
|
278 | 285 | |
|
279 | 286 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
280 | 287 | #endif |
|
281 | 288 | |
|
282 | 289 | m_margins = new DeclarativeMargins(this); |
|
283 | 290 | m_margins->setTop(m_chart->margins().top()); |
|
284 | 291 | m_margins->setLeft(m_chart->margins().left()); |
|
285 | 292 | m_margins->setRight(m_chart->margins().right()); |
|
286 | 293 | m_margins->setBottom(m_chart->margins().bottom()); |
|
287 | 294 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
288 | 295 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
289 | 296 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
290 | 297 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
291 | 298 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
292 | 299 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
293 | 300 | } |
|
294 | 301 | |
|
295 | 302 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series) |
|
296 | 303 | { |
|
297 | 304 | emit seriesAdded(series); |
|
298 | 305 | } |
|
299 | 306 | |
|
300 | 307 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
301 | 308 | { |
|
302 | 309 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
303 | 310 | emit minimumMarginsChanged(); |
|
304 | 311 | emit plotAreaChanged(m_chart->plotArea()); |
|
305 | 312 | } |
|
306 | 313 | |
|
307 | 314 | DeclarativeChart::~DeclarativeChart() |
|
308 | 315 | { |
|
309 | 316 | delete m_chart; |
|
310 | 317 | } |
|
311 | 318 | |
|
312 | 319 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
313 | 320 | { |
|
314 | 321 | if (event->type() == QEvent::ChildAdded) { |
|
315 | 322 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
316 | 323 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
317 | 324 | } |
|
318 | 325 | } |
|
319 | 326 | } |
|
320 | 327 | |
|
321 | 328 | void DeclarativeChart::componentComplete() |
|
322 | 329 | { |
|
323 | 330 | foreach (QObject *child, children()) { |
|
324 | 331 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
325 | 332 | // Add series to the chart |
|
326 | 333 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
327 | 334 | m_chart->addSeries(series); |
|
328 | 335 | |
|
329 | 336 | // Connect to axis changed signals (unless this is a pie series) |
|
330 | 337 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
331 | 338 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
332 | 339 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
333 | 340 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
334 | 341 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
335 | 342 | } |
|
336 | 343 | |
|
337 | 344 | initializeAxes(series); |
|
338 | 345 | } |
|
339 | 346 | } |
|
340 | 347 | |
|
341 | 348 | QDECLARATIVE_ITEM::componentComplete(); |
|
342 | 349 | } |
|
343 | 350 | |
|
344 | 351 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
345 | 352 | { |
|
346 | 353 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
347 | 354 | if (axis && s) { |
|
348 | 355 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) |
|
349 | 356 | m_chart->addAxis(axis, Qt::AlignBottom); |
|
350 | 357 | if (!s->attachedAxes().contains(axis)) |
|
351 | 358 | s->attachAxis(axis); |
|
352 | 359 | } else { |
|
353 | 360 | qWarning() << "Trying to set axisX to null."; |
|
354 | 361 | } |
|
355 | 362 | } |
|
356 | 363 | |
|
357 | 364 | void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis) |
|
358 | 365 | { |
|
359 | 366 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
360 | 367 | if (axis && s) { |
|
361 | 368 | if (!m_chart->axes(Qt::Horizontal).contains(axis)) |
|
362 | 369 | m_chart->addAxis(axis, Qt::AlignTop); |
|
363 | 370 | if (!s->attachedAxes().contains(axis)) |
|
364 | 371 | s->attachAxis(axis); |
|
365 | 372 | } else { |
|
366 | 373 | qWarning() << "Trying to set axisXTop to null."; |
|
367 | 374 | } |
|
368 | 375 | } |
|
369 | 376 | |
|
370 | 377 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
371 | 378 | { |
|
372 | 379 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
373 | 380 | if (axis && s) { |
|
374 | 381 | if (!m_chart->axes(Qt::Vertical).contains(axis)) |
|
375 | 382 | m_chart->addAxis(axis, Qt::AlignLeft); |
|
376 | 383 | if (!s->attachedAxes().contains(axis)) |
|
377 | 384 | s->attachAxis(axis); |
|
378 | 385 | } else { |
|
379 | 386 | qWarning() << "Trying to set axisY to null."; |
|
380 | 387 | } |
|
381 | 388 | } |
|
382 | 389 | |
|
383 | 390 | void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis) |
|
384 | 391 | { |
|
385 | 392 | QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender()); |
|
386 | 393 | if (axis && s) { |
|
387 | 394 | if (!m_chart->axes(Qt::Vertical).contains(axis)) |
|
388 | 395 | m_chart->addAxis(axis, Qt::AlignRight); |
|
389 | 396 | if (!s->attachedAxes().contains(axis)) |
|
390 | 397 | s->attachAxis(axis); |
|
391 | 398 | } else { |
|
392 | 399 | qWarning() << "Trying to set axisYRight to null."; |
|
393 | 400 | } |
|
394 | 401 | } |
|
395 | 402 | |
|
396 | 403 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
397 | 404 | { |
|
398 | 405 | if (newGeometry.isValid()) { |
|
399 | 406 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
400 | 407 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
401 | 408 | } |
|
402 | 409 | } |
|
403 | 410 | QDECLARATIVE_ITEM::geometryChanged(newGeometry, oldGeometry); |
|
404 | 411 | |
|
405 | 412 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
406 | 413 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
407 | 414 | // to implement it here for the QML API purposes. |
|
408 | 415 | emit plotAreaChanged(m_chart->plotArea()); |
|
409 | 416 | } |
|
410 | 417 | |
|
411 | 418 | #ifdef CHARTS_FOR_QUICK2 |
|
412 | 419 | void DeclarativeChart::paint(QPainter *painter) |
|
413 | 420 | { |
|
414 | 421 | QRectF renderRect(QPointF(0, 0), m_chart->size()); |
|
415 | 422 | m_scene->render(painter, renderRect, renderRect); |
|
416 | 423 | } |
|
417 | 424 | |
|
418 | 425 | void DeclarativeChart::mousePressEvent(QMouseEvent *event) |
|
419 | 426 | { |
|
420 | 427 | m_mousePressScenePoint = event->pos(); |
|
421 | 428 | m_mousePressScreenPoint = event->globalPos(); |
|
422 | 429 | m_lastMouseMoveScenePoint = m_mousePressScenePoint; |
|
423 | 430 | m_lastMouseMoveScreenPoint = m_mousePressScreenPoint; |
|
424 | 431 | m_mousePressButton = event->button(); |
|
425 | 432 | m_mousePressButtons = event->buttons(); |
|
426 | 433 | |
|
427 | 434 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress); |
|
428 | 435 | mouseEvent.setWidget(0); |
|
429 | 436 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
430 | 437 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
431 | 438 | mouseEvent.setScenePos(m_mousePressScenePoint); |
|
432 | 439 | mouseEvent.setScreenPos(m_mousePressScreenPoint); |
|
433 | 440 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
434 | 441 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
435 | 442 | mouseEvent.setButtons(m_mousePressButtons); |
|
436 | 443 | mouseEvent.setButton(m_mousePressButton); |
|
437 | 444 | mouseEvent.setModifiers(event->modifiers()); |
|
438 | 445 | mouseEvent.setAccepted(false); |
|
439 | 446 | |
|
440 | 447 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
441 | 448 | } |
|
442 | 449 | |
|
443 | 450 | void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event) |
|
444 | 451 | { |
|
445 | 452 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease); |
|
446 | 453 | mouseEvent.setWidget(0); |
|
447 | 454 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
448 | 455 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
449 | 456 | mouseEvent.setScenePos(event->pos()); |
|
450 | 457 | mouseEvent.setScreenPos(event->globalPos()); |
|
451 | 458 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
452 | 459 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
453 | 460 | mouseEvent.setButtons(event->buttons()); |
|
454 | 461 | mouseEvent.setButton(event->button()); |
|
455 | 462 | mouseEvent.setModifiers(event->modifiers()); |
|
456 | 463 | mouseEvent.setAccepted(false); |
|
457 | 464 | |
|
458 | 465 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
459 | 466 | |
|
460 | 467 | m_mousePressButtons = event->buttons(); |
|
461 | 468 | m_mousePressButton = Qt::NoButton; |
|
462 | 469 | } |
|
463 | 470 | |
|
464 | 471 | void DeclarativeChart::hoverMoveEvent(QHoverEvent *event) |
|
465 | 472 | { |
|
466 | 473 | // Convert hover move to mouse move, since we don't seem to get actual mouse move events. |
|
467 | 474 | // QGraphicsScene generates hover events from mouse move events, so we don't need |
|
468 | 475 | // to pass hover events there. |
|
469 | 476 | QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); |
|
470 | 477 | mouseEvent.setWidget(0); |
|
471 | 478 | mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint); |
|
472 | 479 | mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint); |
|
473 | 480 | mouseEvent.setScenePos(event->pos()); |
|
474 | 481 | // Hover events do not have global pos in them, and the screen position doesn't seem to |
|
475 | 482 | // matter anyway in this use case, so just pass event pos instead of trying to |
|
476 | 483 | // calculate the real screen position. |
|
477 | 484 | mouseEvent.setScreenPos(event->pos()); |
|
478 | 485 | mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint); |
|
479 | 486 | mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint); |
|
480 | 487 | mouseEvent.setButtons(m_mousePressButtons); |
|
481 | 488 | mouseEvent.setButton(m_mousePressButton); |
|
482 | 489 | mouseEvent.setModifiers(event->modifiers()); |
|
483 | 490 | m_lastMouseMoveScenePoint = mouseEvent.scenePos(); |
|
484 | 491 | m_lastMouseMoveScreenPoint = mouseEvent.screenPos(); |
|
485 | 492 | mouseEvent.setAccepted(false); |
|
486 | 493 | |
|
487 | 494 | QApplication::sendEvent(m_scene, &mouseEvent); |
|
488 | 495 | } |
|
489 | 496 | |
|
490 | 497 | void DeclarativeChart::handleAntialiasingChanged(bool enable) |
|
491 | 498 | { |
|
492 | 499 | setAntialiasing(enable); |
|
493 | 500 | } |
|
494 | 501 | #endif |
|
495 | 502 | |
|
496 | 503 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
497 | 504 | { |
|
498 | 505 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
499 | 506 | if (chartTheme != m_chart->theme()) |
|
500 | 507 | m_chart->setTheme(chartTheme); |
|
501 | 508 | } |
|
502 | 509 | |
|
503 | 510 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
504 | 511 | { |
|
505 | 512 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
506 | 513 | } |
|
507 | 514 | |
|
508 | 515 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
509 | 516 | { |
|
510 | 517 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
511 | 518 | if (animationOptions != m_chart->animationOptions()) |
|
512 | 519 | m_chart->setAnimationOptions(animationOptions); |
|
513 | 520 | } |
|
514 | 521 | |
|
515 | 522 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
516 | 523 | { |
|
517 | 524 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
518 | 525 | return DeclarativeChart::AllAnimations; |
|
519 | 526 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
520 | 527 | return DeclarativeChart::GridAxisAnimations; |
|
521 | 528 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
522 | 529 | return DeclarativeChart::SeriesAnimations; |
|
523 | 530 | else |
|
524 | 531 | return DeclarativeChart::NoAnimation; |
|
525 | 532 | } |
|
526 | 533 | |
|
527 | 534 | void DeclarativeChart::setTitle(QString title) |
|
528 | 535 | { |
|
529 | 536 | if (title != m_chart->title()) |
|
530 | 537 | m_chart->setTitle(title); |
|
531 | 538 | } |
|
532 | 539 | QString DeclarativeChart::title() |
|
533 | 540 | { |
|
534 | 541 | return m_chart->title(); |
|
535 | 542 | } |
|
536 | 543 | |
|
537 | 544 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
538 | 545 | { |
|
539 | 546 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series); |
|
540 | 547 | if (axes.count()) |
|
541 | 548 | return axes[0]; |
|
542 | 549 | return 0; |
|
543 | 550 | } |
|
544 | 551 | |
|
545 | 552 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
546 | 553 | { |
|
547 | 554 | QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series); |
|
548 | 555 | if (axes.count()) |
|
549 | 556 | return axes[0]; |
|
550 | 557 | return 0; |
|
551 | 558 | } |
|
552 | 559 | |
|
553 | 560 | QLegend *DeclarativeChart::legend() |
|
554 | 561 | { |
|
555 | 562 | return m_chart->legend(); |
|
556 | 563 | } |
|
557 | 564 | |
|
558 | 565 | void DeclarativeChart::setTitleColor(QColor color) |
|
559 | 566 | { |
|
560 | 567 | QBrush b = m_chart->titleBrush(); |
|
561 | 568 | if (color != b.color()) { |
|
562 | 569 | b.setColor(color); |
|
563 | 570 | m_chart->setTitleBrush(b); |
|
564 | 571 | emit titleColorChanged(color); |
|
565 | 572 | } |
|
566 | 573 | } |
|
567 | 574 | |
|
568 | 575 | QFont DeclarativeChart::titleFont() const |
|
569 | 576 | { |
|
570 | 577 | return m_chart->titleFont(); |
|
571 | 578 | } |
|
572 | 579 | |
|
573 | 580 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
574 | 581 | { |
|
575 | 582 | m_chart->setTitleFont(font); |
|
576 | 583 | } |
|
577 | 584 | |
|
578 | 585 | QColor DeclarativeChart::titleColor() |
|
579 | 586 | { |
|
580 | 587 | return m_chart->titleBrush().color(); |
|
581 | 588 | } |
|
582 | 589 | |
|
583 | 590 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
584 | 591 | { |
|
585 | 592 | QBrush b = m_chart->backgroundBrush(); |
|
586 | 593 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
587 | 594 | b.setStyle(Qt::SolidPattern); |
|
588 | 595 | b.setColor(color); |
|
589 | 596 | m_chart->setBackgroundBrush(b); |
|
590 | 597 | emit backgroundColorChanged(); |
|
591 | 598 | } |
|
592 | 599 | } |
|
593 | 600 | |
|
594 | 601 | QColor DeclarativeChart::backgroundColor() |
|
595 | 602 | { |
|
596 | 603 | return m_chart->backgroundBrush().color(); |
|
597 | 604 | } |
|
598 | 605 | |
|
606 | void QtCommercialChart::DeclarativeChart::setPlotAreaColor(QColor color) | |
|
607 | { | |
|
608 | QBrush b = m_chart->plotAreaBackgroundBrush(); | |
|
609 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
|
610 | b.setStyle(Qt::SolidPattern); | |
|
611 | b.setColor(color); | |
|
612 | m_chart->setPlotAreaBackgroundBrush(b); | |
|
613 | m_chart->setPlotAreaBackgroundVisible(true); | |
|
614 | emit plotAreaColorChanged(); | |
|
615 | } | |
|
616 | } | |
|
617 | ||
|
618 | QColor QtCommercialChart::DeclarativeChart::plotAreaColor() | |
|
619 | { | |
|
620 | return m_chart->plotAreaBackgroundBrush().color(); | |
|
621 | } | |
|
622 | ||
|
599 | 623 | int DeclarativeChart::count() |
|
600 | 624 | { |
|
601 | 625 | return m_chart->series().count(); |
|
602 | 626 | } |
|
603 | 627 | |
|
604 | 628 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
605 | 629 | { |
|
606 | 630 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
607 | 631 | m_chart->setDropShadowEnabled(enabled); |
|
608 | 632 | dropShadowEnabledChanged(enabled); |
|
609 | 633 | } |
|
610 | 634 | } |
|
611 | 635 | |
|
612 | 636 | bool DeclarativeChart::dropShadowEnabled() |
|
613 | 637 | { |
|
614 | 638 | return m_chart->isDropShadowEnabled(); |
|
615 | 639 | } |
|
616 | 640 | |
|
617 | 641 | qreal DeclarativeChart::topMargin() |
|
618 | 642 | { |
|
619 | 643 | qWarning() << "ChartView.topMargin is deprecated. Use margins instead."; |
|
620 | 644 | return m_chart->margins().top(); |
|
621 | 645 | } |
|
622 | 646 | |
|
623 | 647 | qreal DeclarativeChart::bottomMargin() |
|
624 | 648 | { |
|
625 | 649 | qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead."; |
|
626 | 650 | return m_chart->margins().bottom(); |
|
627 | 651 | } |
|
628 | 652 | |
|
629 | 653 | qreal DeclarativeChart::leftMargin() |
|
630 | 654 | { |
|
631 | 655 | qWarning() << "ChartView.leftMargin is deprecated. Use margins instead."; |
|
632 | 656 | return m_chart->margins().left(); |
|
633 | 657 | } |
|
634 | 658 | |
|
635 | 659 | qreal DeclarativeChart::rightMargin() |
|
636 | 660 | { |
|
637 | 661 | qWarning() << "ChartView.rightMargin is deprecated. Use margins instead."; |
|
638 | 662 | return m_chart->margins().right(); |
|
639 | 663 | } |
|
640 | 664 | |
|
641 | 665 | void DeclarativeChart::zoom(qreal factor) |
|
642 | 666 | { |
|
643 | 667 | m_chart->zoom(factor); |
|
644 | 668 | } |
|
645 | 669 | |
|
646 | 670 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
647 | 671 | { |
|
648 | 672 | m_chart->scroll(-pixels, 0); |
|
649 | 673 | } |
|
650 | 674 | |
|
651 | 675 | void DeclarativeChart::scrollRight(qreal pixels) |
|
652 | 676 | { |
|
653 | 677 | m_chart->scroll(pixels, 0); |
|
654 | 678 | } |
|
655 | 679 | |
|
656 | 680 | void DeclarativeChart::scrollUp(qreal pixels) |
|
657 | 681 | { |
|
658 | 682 | m_chart->scroll(0, pixels); |
|
659 | 683 | } |
|
660 | 684 | |
|
661 | 685 | void DeclarativeChart::scrollDown(qreal pixels) |
|
662 | 686 | { |
|
663 | 687 | m_chart->scroll(0, -pixels); |
|
664 | 688 | } |
|
665 | 689 | |
|
666 | 690 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> DeclarativeChart::axes() |
|
667 | 691 | { |
|
668 | 692 | return QDECLARATIVE_LIST_PROPERTY<QAbstractAxis>(this, 0, |
|
669 | 693 | &DeclarativeChart::axesAppendFunc, |
|
670 | 694 | &DeclarativeChart::axesCountFunc, |
|
671 | 695 | #ifdef CHARTS_FOR_QUICK2 |
|
672 | 696 | &DeclarativeChart::axesAtFunc, |
|
673 | 697 | &DeclarativeChart::axesClearFunc); |
|
674 | 698 | #else |
|
675 | 699 | &DeclarativeChart::axesAtFunc); |
|
676 | 700 | #endif |
|
677 | 701 | } |
|
678 | 702 | |
|
679 | 703 | void DeclarativeChart::axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element) |
|
680 | 704 | { |
|
681 | 705 | // Empty implementation |
|
682 | 706 | Q_UNUSED(list); |
|
683 | 707 | Q_UNUSED(element); |
|
684 | 708 | } |
|
685 | 709 | |
|
686 | 710 | int DeclarativeChart::axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) |
|
687 | 711 | { |
|
688 | 712 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
689 | 713 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
690 | 714 | return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count(); |
|
691 | 715 | } |
|
692 | 716 | return 0; |
|
693 | 717 | } |
|
694 | 718 | |
|
695 | 719 | QAbstractAxis *DeclarativeChart::axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index) |
|
696 | 720 | { |
|
697 | 721 | if (qobject_cast<DeclarativeChart *>(list->object)) { |
|
698 | 722 | DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object); |
|
699 | 723 | QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]); |
|
700 | 724 | return axes.at(index); |
|
701 | 725 | } |
|
702 | 726 | return 0; |
|
703 | 727 | } |
|
704 | 728 | |
|
705 | 729 | void DeclarativeChart::axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list) |
|
706 | 730 | { |
|
707 | 731 | // Empty implementation |
|
708 | 732 | Q_UNUSED(list); |
|
709 | 733 | } |
|
710 | 734 | |
|
711 | 735 | |
|
712 | 736 | QAbstractSeries *DeclarativeChart::series(int index) |
|
713 | 737 | { |
|
714 | 738 | if (index < m_chart->series().count()) { |
|
715 | 739 | return m_chart->series().at(index); |
|
716 | 740 | } |
|
717 | 741 | return 0; |
|
718 | 742 | } |
|
719 | 743 | |
|
720 | 744 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
721 | 745 | { |
|
722 | 746 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
723 | 747 | if (series->name() == seriesName) |
|
724 | 748 | return series; |
|
725 | 749 | } |
|
726 | 750 | return 0; |
|
727 | 751 | } |
|
728 | 752 | |
|
729 | 753 | QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
730 | 754 | { |
|
731 | 755 | QAbstractSeries *series = 0; |
|
732 | 756 | |
|
733 | 757 | switch (type) { |
|
734 | 758 | case DeclarativeChart::SeriesTypeLine: |
|
735 | 759 | series = new DeclarativeLineSeries(); |
|
736 | 760 | break; |
|
737 | 761 | case DeclarativeChart::SeriesTypeArea: { |
|
738 | 762 | DeclarativeAreaSeries *area = new DeclarativeAreaSeries(); |
|
739 | 763 | area->setUpperSeries(new DeclarativeLineSeries()); |
|
740 | 764 | series = area; |
|
741 | 765 | break; |
|
742 | 766 | } |
|
743 | 767 | case DeclarativeChart::SeriesTypeStackedBar: |
|
744 | 768 | series = new DeclarativeStackedBarSeries(); |
|
745 | 769 | break; |
|
746 | 770 | case DeclarativeChart::SeriesTypePercentBar: |
|
747 | 771 | series = new DeclarativePercentBarSeries(); |
|
748 | 772 | break; |
|
749 | 773 | case DeclarativeChart::SeriesTypeBar: |
|
750 | 774 | series = new DeclarativeBarSeries(); |
|
751 | 775 | break; |
|
752 | 776 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
753 | 777 | series = new DeclarativeHorizontalBarSeries(); |
|
754 | 778 | break; |
|
755 | 779 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
756 | 780 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
757 | 781 | break; |
|
758 | 782 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
759 | 783 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
760 | 784 | break; |
|
761 | 785 | case DeclarativeChart::SeriesTypePie: |
|
762 | 786 | series = new DeclarativePieSeries(); |
|
763 | 787 | break; |
|
764 | 788 | case DeclarativeChart::SeriesTypeScatter: |
|
765 | 789 | series = new DeclarativeScatterSeries(); |
|
766 | 790 | break; |
|
767 | 791 | case DeclarativeChart::SeriesTypeSpline: |
|
768 | 792 | series = new DeclarativeSplineSeries(); |
|
769 | 793 | break; |
|
770 | 794 | default: |
|
771 | 795 | qWarning() << "Illegal series type"; |
|
772 | 796 | } |
|
773 | 797 | |
|
774 | 798 | if (series) { |
|
775 | 799 | // Connect to axis changed signals (unless this is a pie series) |
|
776 | 800 | if (!qobject_cast<DeclarativePieSeries *>(series)) { |
|
777 | 801 | connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
778 | 802 | connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
779 | 803 | connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
780 | 804 | connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*))); |
|
781 | 805 | } |
|
782 | 806 | |
|
783 | 807 | series->setName(name); |
|
784 | 808 | m_chart->addSeries(series); |
|
785 | 809 | |
|
786 | 810 | if (axisX) |
|
787 | 811 | setAxisX(axisX, series); |
|
788 | 812 | if (axisY) |
|
789 | 813 | setAxisY(axisY, series); |
|
790 | 814 | |
|
791 | 815 | if (series->attachedAxes().count() < 2) |
|
792 | 816 | initializeAxes(series); |
|
793 | 817 | } |
|
794 | 818 | |
|
795 | 819 | return series; |
|
796 | 820 | } |
|
797 | 821 | |
|
798 | 822 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
799 | 823 | { |
|
800 | 824 | if (series) |
|
801 | 825 | m_chart->removeSeries(series); |
|
802 | 826 | else |
|
803 | 827 | qWarning("removeSeries: cannot remove null"); |
|
804 | 828 | } |
|
805 | 829 | |
|
806 | 830 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
807 | 831 | { |
|
808 | 832 | if (axis) |
|
809 | 833 | m_chart->setAxisX(axis, series); |
|
810 | 834 | } |
|
811 | 835 | |
|
812 | 836 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
813 | 837 | { |
|
814 | 838 | if (axis) |
|
815 | 839 | m_chart->setAxisY(axis, series); |
|
816 | 840 | } |
|
817 | 841 | |
|
818 | 842 | void DeclarativeChart::createDefaultAxes() |
|
819 | 843 | { |
|
820 | 844 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
821 | 845 | } |
|
822 | 846 | |
|
823 | 847 | QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series) |
|
824 | 848 | { |
|
825 | 849 | if (!series) { |
|
826 | 850 | qWarning() << "No axis type defined for null series"; |
|
827 | 851 | return 0; |
|
828 | 852 | } |
|
829 | 853 | |
|
830 | 854 | foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) { |
|
831 | 855 | if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation)) |
|
832 | 856 | return existingAxis; |
|
833 | 857 | } |
|
834 | 858 | |
|
835 | 859 | switch (series->d_ptr->defaultAxisType(orientation)) { |
|
836 | 860 | case QAbstractAxis::AxisTypeValue: |
|
837 | 861 | return new QValueAxis(this); |
|
838 | 862 | case QAbstractAxis::AxisTypeBarCategory: |
|
839 | 863 | return new QBarCategoryAxis(this); |
|
840 | 864 | case QAbstractAxis::AxisTypeCategory: |
|
841 | 865 | return new QCategoryAxis(this); |
|
842 | 866 | #ifndef QT_ON_ARM |
|
843 | 867 | case QAbstractAxis::AxisTypeDateTime: |
|
844 | 868 | return new QDateTimeAxis(this); |
|
845 | 869 | #endif |
|
846 | 870 | case QAbstractAxis::AxisTypeLogValue: |
|
847 | 871 | return new QLogValueAxis(this); |
|
848 | 872 | default: |
|
849 | 873 | // assume AxisTypeNoAxis |
|
850 | 874 | return 0; |
|
851 | 875 | } |
|
852 | 876 | } |
|
853 | 877 | |
|
854 | 878 | void DeclarativeChart::initializeAxes(QAbstractSeries *series) |
|
855 | 879 | { |
|
856 | 880 | if (qobject_cast<DeclarativeLineSeries *>(series)) |
|
857 | 881 | doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes); |
|
858 | 882 | else if (qobject_cast<DeclarativeScatterSeries *>(series)) |
|
859 | 883 | doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes); |
|
860 | 884 | else if (qobject_cast<DeclarativeSplineSeries *>(series)) |
|
861 | 885 | doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes); |
|
862 | 886 | else if (qobject_cast<DeclarativeAreaSeries *>(series)) |
|
863 | 887 | doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes); |
|
864 | 888 | else if (qobject_cast<DeclarativeBarSeries *>(series)) |
|
865 | 889 | doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes); |
|
866 | 890 | else if (qobject_cast<DeclarativeStackedBarSeries *>(series)) |
|
867 | 891 | doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes); |
|
868 | 892 | else if (qobject_cast<DeclarativePercentBarSeries *>(series)) |
|
869 | 893 | doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes); |
|
870 | 894 | else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series)) |
|
871 | 895 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes); |
|
872 | 896 | else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)) |
|
873 | 897 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes); |
|
874 | 898 | else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)) |
|
875 | 899 | doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes); |
|
876 | 900 | // else: do nothing |
|
877 | 901 | } |
|
878 | 902 | |
|
879 | 903 | void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes) |
|
880 | 904 | { |
|
881 | 905 | // Initialize axis X |
|
882 | 906 | if (axes->axisX()) |
|
883 | 907 | axes->emitAxisXChanged(); |
|
884 | 908 | else if (axes->axisXTop()) |
|
885 | 909 | axes->emitAxisXTopChanged(); |
|
886 | 910 | else |
|
887 | 911 | axes->setAxisX(defaultAxis(Qt::Horizontal, series)); |
|
888 | 912 | |
|
889 | 913 | // Initialize axis Y |
|
890 | 914 | if (axes->axisY()) |
|
891 | 915 | axes->emitAxisYChanged(); |
|
892 | 916 | else if (axes->axisYRight()) |
|
893 | 917 | axes->emitAxisYRightChanged(); |
|
894 | 918 | else |
|
895 | 919 | axes->setAxisY(defaultAxis(Qt::Vertical, series)); |
|
896 | 920 | } |
|
897 | 921 | |
|
898 | 922 | #include "moc_declarativechart.cpp" |
|
899 | 923 | |
|
900 | 924 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,217 +1,221 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 "shared_defines.h" |
|
26 | 26 | |
|
27 | 27 | #ifdef CHARTS_FOR_QUICK2 |
|
28 | 28 | #include <QtQuick/QQuickItem> |
|
29 | 29 | #include <QtQuick/QQuickPaintedItem> |
|
30 | 30 | #include <QtWidgets/QGraphicsScene> |
|
31 | 31 | #else |
|
32 | 32 | #include <QtDeclarative/QDeclarativeItem> |
|
33 | 33 | #endif |
|
34 | 34 | |
|
35 | 35 | #include "qchart.h" |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class DeclarativeMargins; |
|
40 | 40 | class Domain; |
|
41 | 41 | class DeclarativeAxes; |
|
42 | 42 | |
|
43 | 43 | class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
47 | 47 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
48 | 48 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
49 | 49 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
50 | 50 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
51 | 51 | Q_PROPERTY(QLegend *legend READ legend) |
|
52 | 52 | Q_PROPERTY(int count READ count) |
|
53 | 53 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
54 | 54 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
55 | 55 | Q_PROPERTY(qreal topMargin READ topMargin) |
|
56 | 56 | Q_PROPERTY(qreal bottomMargin READ bottomMargin) |
|
57 | 57 | Q_PROPERTY(qreal leftMargin READ leftMargin) |
|
58 | 58 | Q_PROPERTY(qreal rightMargin READ rightMargin) |
|
59 | 59 | Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1) |
|
60 | 60 | Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2) |
|
61 | 61 | Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1) |
|
62 | Q_PROPERTY(QColor plotAreaColor READ plotAreaColor WRITE setPlotAreaColor NOTIFY plotAreaColorChanged REVISION 3) | |
|
62 | 63 | #ifdef CHARTS_FOR_QUICK2 |
|
63 | 64 | Q_PROPERTY(QQmlListProperty<QAbstractAxis> axes READ axes REVISION 2) |
|
64 | 65 | #else |
|
65 | 66 | Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2) |
|
66 | 67 | #endif |
|
67 | 68 | Q_ENUMS(Animation) |
|
68 | 69 | Q_ENUMS(Theme) |
|
69 | 70 | Q_ENUMS(SeriesType) |
|
70 | 71 | |
|
71 | 72 | public: |
|
72 | 73 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
73 | 74 | enum Theme { |
|
74 | 75 | ChartThemeLight = 0, |
|
75 | 76 | ChartThemeBlueCerulean, |
|
76 | 77 | ChartThemeDark, |
|
77 | 78 | ChartThemeBrownSand, |
|
78 | 79 | ChartThemeBlueNcs, |
|
79 | 80 | ChartThemeHighContrast, |
|
80 | 81 | ChartThemeBlueIcy |
|
81 | 82 | }; |
|
82 | 83 | |
|
83 | 84 | enum Animation { |
|
84 | 85 | NoAnimation = 0x0, |
|
85 | 86 | GridAxisAnimations = 0x1, |
|
86 | 87 | SeriesAnimations = 0x2, |
|
87 | 88 | AllAnimations = 0x3 |
|
88 | 89 | }; |
|
89 | 90 | |
|
90 | 91 | enum SeriesType { |
|
91 | 92 | SeriesTypeLine, |
|
92 | 93 | SeriesTypeArea, |
|
93 | 94 | SeriesTypeBar, |
|
94 | 95 | SeriesTypeStackedBar, |
|
95 | 96 | SeriesTypePercentBar, |
|
96 | 97 | SeriesTypePie, |
|
97 | 98 | SeriesTypeScatter, |
|
98 | 99 | SeriesTypeSpline, |
|
99 | 100 | SeriesTypeHorizontalBar, |
|
100 | 101 | SeriesTypeHorizontalStackedBar, |
|
101 | 102 | SeriesTypeHorizontalPercentBar |
|
102 | 103 | }; |
|
103 | 104 | |
|
104 | 105 | public: |
|
105 | 106 | DeclarativeChart(QDECLARATIVE_ITEM *parent = 0); |
|
106 | 107 | ~DeclarativeChart(); |
|
107 | 108 | |
|
108 | 109 | public: // From parent classes |
|
109 | 110 | void childEvent(QChildEvent *event); |
|
110 | 111 | void componentComplete(); |
|
111 | 112 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
112 | 113 | #ifdef CHARTS_FOR_QUICK2 |
|
113 | 114 | void paint(QPainter *painter); |
|
114 | 115 | protected: |
|
115 | 116 | void mousePressEvent(QMouseEvent *event); |
|
116 | 117 | void mouseReleaseEvent(QMouseEvent *event); |
|
117 | 118 | void hoverMoveEvent(QHoverEvent *event); |
|
118 | 119 | private Q_SLOTS: |
|
119 | 120 | void handleAntialiasingChanged(bool enable); |
|
120 | 121 | #endif |
|
121 | 122 | |
|
122 | 123 | public: |
|
123 | 124 | void setTheme(DeclarativeChart::Theme theme); |
|
124 | 125 | DeclarativeChart::Theme theme(); |
|
125 | 126 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
126 | 127 | DeclarativeChart::Animation animationOptions(); |
|
127 | 128 | void setTitle(QString title); |
|
128 | 129 | QString title(); |
|
129 | 130 | QLegend *legend(); |
|
130 | 131 | QFont titleFont() const; |
|
131 | 132 | void setTitleFont(const QFont &font); |
|
132 | 133 | void setTitleColor(QColor color); |
|
133 | 134 | QColor titleColor(); |
|
134 | 135 | void setBackgroundColor(QColor color); |
|
135 | 136 | QColor backgroundColor(); |
|
137 | Q_REVISION(3) void setPlotAreaColor(QColor color); | |
|
138 | Q_REVISION(3) QColor plotAreaColor(); | |
|
136 | 139 | int count(); |
|
137 | 140 | void setDropShadowEnabled(bool enabled); |
|
138 | 141 | bool dropShadowEnabled(); |
|
139 | 142 | |
|
140 | 143 | // Margins & plotArea |
|
141 | 144 | qreal topMargin(); |
|
142 | 145 | qreal bottomMargin(); |
|
143 | 146 | qreal leftMargin(); |
|
144 | 147 | qreal rightMargin(); |
|
145 | 148 | DeclarativeMargins *minimumMargins() { return m_margins; } |
|
146 | 149 | Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; } |
|
147 | 150 | QRectF plotArea() { return m_chart->plotArea(); } |
|
148 | 151 | |
|
149 | 152 | // Axis handling |
|
150 | 153 | QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series); |
|
151 | 154 | void initializeAxes(QAbstractSeries *series); |
|
152 | 155 | void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes); |
|
153 | 156 | QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> axes(); |
|
154 | 157 | static void axesAppendFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, QAbstractAxis *element); |
|
155 | 158 | static int axesCountFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list); |
|
156 | 159 | static QAbstractAxis *axesAtFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list, int index); |
|
157 | 160 | static void axesClearFunc(QDECLARATIVE_LIST_PROPERTY<QAbstractAxis> *list); |
|
158 | 161 | |
|
159 | 162 | public: |
|
160 | 163 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
161 | 164 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
162 | 165 | Q_INVOKABLE QAbstractSeries *createSeries(int type, QString name = "", QAbstractAxis *axisX = 0, QAbstractAxis *axisY = 0); |
|
163 | 166 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); |
|
164 | 167 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } |
|
165 | 168 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
166 | 169 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
167 | 170 | Q_INVOKABLE void createDefaultAxes(); |
|
168 | 171 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
169 | 172 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
170 | 173 | Q_INVOKABLE void zoom(qreal factor); |
|
171 | 174 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
172 | 175 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
173 | 176 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
174 | 177 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
175 | 178 | |
|
176 | 179 | Q_SIGNALS: |
|
177 | 180 | void axisLabelsChanged(); |
|
178 | 181 | void titleColorChanged(QColor color); |
|
179 | 182 | void backgroundColorChanged(); |
|
180 | 183 | void dropShadowEnabledChanged(bool enabled); |
|
181 | 184 | void minimumMarginsChanged(); |
|
182 | 185 | Q_REVISION(2) void marginsChanged(); |
|
183 | 186 | void plotAreaChanged(QRectF plotArea); |
|
184 | 187 | void seriesAdded(QAbstractSeries *series); |
|
185 | 188 | void seriesRemoved(QAbstractSeries *series); |
|
189 | Q_REVISION(3) void plotAreaColorChanged(); | |
|
186 | 190 | |
|
187 | 191 | private Q_SLOTS: |
|
188 | 192 | void changeMinimumMargins(int top, int bottom, int left, int right); |
|
189 | 193 | void handleAxisXSet(QAbstractAxis *axis); |
|
190 | 194 | void handleAxisYSet(QAbstractAxis *axis); |
|
191 | 195 | void handleAxisXTopSet(QAbstractAxis *axis); |
|
192 | 196 | void handleAxisYRightSet(QAbstractAxis *axis); |
|
193 | 197 | void handleSeriesAdded(QAbstractSeries *series); |
|
194 | 198 | |
|
195 | 199 | protected: |
|
196 | 200 | explicit DeclarativeChart(QChart::ChartType type, QDECLARATIVE_ITEM *parent); |
|
197 | 201 | |
|
198 | 202 | private: |
|
199 | 203 | void initChart(QChart::ChartType type); |
|
200 | 204 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
201 | 205 | // multi inheritance, so we now have a QChart as a member instead |
|
202 | 206 | QChart *m_chart; |
|
203 | 207 | #ifdef CHARTS_FOR_QUICK2 |
|
204 | 208 | QGraphicsScene *m_scene; |
|
205 | 209 | QPointF m_mousePressScenePoint; |
|
206 | 210 | QPoint m_mousePressScreenPoint; |
|
207 | 211 | QPointF m_lastMouseMoveScenePoint; |
|
208 | 212 | QPoint m_lastMouseMoveScreenPoint; |
|
209 | 213 | Qt::MouseButton m_mousePressButton; |
|
210 | 214 | Qt::MouseButtons m_mousePressButtons; |
|
211 | 215 | #endif |
|
212 | 216 | DeclarativeMargins *m_margins; |
|
213 | 217 | }; |
|
214 | 218 | |
|
215 | 219 | QTCOMMERCIALCHART_END_NAMESPACE |
|
216 | 220 | |
|
217 | 221 | #endif // DECLARATIVECHART_H |
@@ -1,249 +1,250 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 "qchart.h" |
|
22 | 22 | #include "qabstractaxis.h" |
|
23 | 23 | #include "qvalueaxis.h" |
|
24 | 24 | #include "qlogvalueaxis.h" |
|
25 | 25 | #include "declarativecategoryaxis.h" |
|
26 | 26 | #include "qbarcategoryaxis.h" |
|
27 | 27 | #include "declarativechart.h" |
|
28 | 28 | #include "declarativepolarchart.h" |
|
29 | 29 | #include "declarativexypoint.h" |
|
30 | 30 | #include "declarativelineseries.h" |
|
31 | 31 | #include "declarativesplineseries.h" |
|
32 | 32 | #include "declarativeareaseries.h" |
|
33 | 33 | #include "declarativescatterseries.h" |
|
34 | 34 | #include "declarativebarseries.h" |
|
35 | 35 | #include "declarativepieseries.h" |
|
36 | 36 | #include "declarativeaxes.h" |
|
37 | 37 | #include "qvxymodelmapper.h" |
|
38 | 38 | #include "qhxymodelmapper.h" |
|
39 | 39 | #include "qhpiemodelmapper.h" |
|
40 | 40 | #include "qvpiemodelmapper.h" |
|
41 | 41 | #include "qhbarmodelmapper.h" |
|
42 | 42 | #include "qvbarmodelmapper.h" |
|
43 | 43 | #include "declarativemargins.h" |
|
44 | 44 | #include "qarealegendmarker.h" |
|
45 | 45 | #include "qbarlegendmarker.h" |
|
46 | 46 | #include "qpielegendmarker.h" |
|
47 | 47 | #include "qxylegendmarker.h" |
|
48 | 48 | #ifndef QT_ON_ARM |
|
49 | 49 | #include "qdatetimeaxis.h" |
|
50 | 50 | #endif |
|
51 | 51 | #include "shared_defines.h" |
|
52 | 52 | #include <QAbstractItemModel> |
|
53 | 53 | #ifdef CHARTS_FOR_QUICK2 |
|
54 | 54 | #include <QtQml/QQmlExtensionPlugin> |
|
55 | 55 | #else |
|
56 | 56 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
57 | 57 | #include <QtDeclarative/qdeclarative.h> |
|
58 | 58 | #endif |
|
59 | 59 | |
|
60 | 60 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
61 | 61 | |
|
62 | 62 | Q_DECLARE_METATYPE(QList<QPieSlice *>) |
|
63 | 63 | Q_DECLARE_METATYPE(QList<QBarSet *>) |
|
64 | 64 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
65 | 65 | |
|
66 | 66 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
67 | 67 | |
|
68 | 68 | // NOTE: Hackish fixes for Qt5 (beta2). |
|
69 | 69 | // These should not be needed or at least they are not needed in Qt4. |
|
70 | 70 | |
|
71 | 71 | Q_DECLARE_METATYPE(DeclarativeChart *) |
|
72 | 72 | Q_DECLARE_METATYPE(DeclarativePolarChart *) |
|
73 | 73 | Q_DECLARE_METATYPE(DeclarativeMargins *) |
|
74 | 74 | Q_DECLARE_METATYPE(DeclarativeAreaSeries *) |
|
75 | 75 | Q_DECLARE_METATYPE(DeclarativeBarSeries *) |
|
76 | 76 | Q_DECLARE_METATYPE(DeclarativeBarSet *) |
|
77 | 77 | Q_DECLARE_METATYPE(DeclarativeLineSeries *) |
|
78 | 78 | Q_DECLARE_METATYPE(DeclarativePieSeries *) |
|
79 | 79 | Q_DECLARE_METATYPE(DeclarativeScatterSeries *) |
|
80 | 80 | Q_DECLARE_METATYPE(DeclarativeSplineSeries *) |
|
81 | 81 | |
|
82 | 82 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
83 | 83 | Q_DECLARE_METATYPE(QValueAxis *) |
|
84 | 84 | Q_DECLARE_METATYPE(QBarCategoryAxis *) |
|
85 | 85 | Q_DECLARE_METATYPE(QCategoryAxis *) |
|
86 | 86 | Q_DECLARE_METATYPE(QDateTimeAxis *) |
|
87 | 87 | Q_DECLARE_METATYPE(QLogValueAxis *) |
|
88 | 88 | |
|
89 | 89 | Q_DECLARE_METATYPE(QLegend *) |
|
90 | 90 | Q_DECLARE_METATYPE(QLegendMarker *) |
|
91 | 91 | Q_DECLARE_METATYPE(QAreaLegendMarker *) |
|
92 | 92 | Q_DECLARE_METATYPE(QBarLegendMarker *) |
|
93 | 93 | Q_DECLARE_METATYPE(QPieLegendMarker *) |
|
94 | 94 | |
|
95 | 95 | Q_DECLARE_METATYPE(QHPieModelMapper *) |
|
96 | 96 | Q_DECLARE_METATYPE(QHXYModelMapper *) |
|
97 | 97 | Q_DECLARE_METATYPE(QPieModelMapper *) |
|
98 | 98 | Q_DECLARE_METATYPE(QHBarModelMapper *) |
|
99 | 99 | Q_DECLARE_METATYPE(QBarModelMapper *) |
|
100 | 100 | Q_DECLARE_METATYPE(QVBarModelMapper *) |
|
101 | 101 | Q_DECLARE_METATYPE(QVPieModelMapper *) |
|
102 | 102 | Q_DECLARE_METATYPE(QVXYModelMapper *) |
|
103 | 103 | Q_DECLARE_METATYPE(QXYLegendMarker *) |
|
104 | 104 | Q_DECLARE_METATYPE(QXYModelMapper *) |
|
105 | 105 | |
|
106 | 106 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
107 | 107 | Q_DECLARE_METATYPE(QXYSeries *) |
|
108 | 108 | Q_DECLARE_METATYPE(QAbstractBarSeries *) |
|
109 | 109 | Q_DECLARE_METATYPE(QBarSeries *) |
|
110 | 110 | Q_DECLARE_METATYPE(QBarSet *) |
|
111 | 111 | Q_DECLARE_METATYPE(QAreaSeries *) |
|
112 | 112 | Q_DECLARE_METATYPE(QHorizontalBarSeries *) |
|
113 | 113 | Q_DECLARE_METATYPE(QHorizontalPercentBarSeries *) |
|
114 | 114 | Q_DECLARE_METATYPE(QHorizontalStackedBarSeries *) |
|
115 | 115 | Q_DECLARE_METATYPE(QLineSeries *) |
|
116 | 116 | Q_DECLARE_METATYPE(QPercentBarSeries *) |
|
117 | 117 | Q_DECLARE_METATYPE(QPieSeries *) |
|
118 | 118 | Q_DECLARE_METATYPE(QPieSlice *) |
|
119 | 119 | Q_DECLARE_METATYPE(QScatterSeries *) |
|
120 | 120 | Q_DECLARE_METATYPE(QSplineSeries *) |
|
121 | 121 | Q_DECLARE_METATYPE(QStackedBarSeries *) |
|
122 | 122 | |
|
123 | 123 | #endif |
|
124 | 124 | |
|
125 | 125 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
126 | 126 | |
|
127 | 127 | class ChartQmlPlugin : public QDECLARATIVE_EXTENSION_PLUGIN |
|
128 | 128 | { |
|
129 | 129 | Q_OBJECT |
|
130 | 130 | |
|
131 | 131 | #ifdef CHARTS_FOR_QUICK2 |
|
132 | 132 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") |
|
133 | 133 | #else |
|
134 | 134 | # if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
135 | 135 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDeclarativeExtensionInterface") |
|
136 | 136 | # endif |
|
137 | 137 | #endif |
|
138 | 138 | |
|
139 | 139 | public: |
|
140 | 140 | virtual void registerTypes(const char *uri) |
|
141 | 141 | { |
|
142 | 142 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
143 | 143 | |
|
144 | 144 | qRegisterMetaType<QList<QPieSlice *> >(); |
|
145 | 145 | qRegisterMetaType<QList<QBarSet *> >(); |
|
146 | 146 | qRegisterMetaType<QList<QAbstractAxis *> >(); |
|
147 | 147 | |
|
148 | 148 | // QtCommercial.Chart 1.0 |
|
149 | 149 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
150 | 150 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); |
|
151 | 151 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
152 | 152 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
153 | 153 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
154 | 154 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
155 | 155 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
156 | 156 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
157 | 157 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
158 | 158 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
159 | 159 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
160 | 160 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
161 | 161 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
162 | 162 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
163 | 163 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
164 | 164 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
165 | 165 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
166 | 166 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
167 | 167 | qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis"); |
|
168 | 168 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis"); |
|
169 | 169 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", |
|
170 | 170 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
171 | 171 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", |
|
172 | 172 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
173 | 173 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
174 | 174 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
175 | 175 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
176 | 176 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
177 | 177 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
178 | 178 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
179 | 179 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
180 | 180 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
181 | 181 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
182 | 182 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
183 | 183 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries", |
|
184 | 184 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); |
|
185 | 185 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", |
|
186 | 186 | QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); |
|
187 | 187 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase", |
|
188 | 188 | QLatin1String("Trying to create uncreatable: BarsetBase.")); |
|
189 | 189 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
190 | 190 | QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); |
|
191 | 191 | qmlRegisterUncreatableType<DeclarativeAxes>(uri, 1, 0, "DeclarativeAxes", |
|
192 | 192 | QLatin1String("Trying to create uncreatable: DeclarativeAxes.")); |
|
193 | 193 | |
|
194 | 194 | // QtCommercial.Chart 1.1 |
|
195 | 195 | qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView"); |
|
196 | 196 | qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries"); |
|
197 | 197 | qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries"); |
|
198 | 198 | qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries"); |
|
199 | 199 | qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries"); |
|
200 | 200 | qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries"); |
|
201 | 201 | qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries"); |
|
202 | 202 | qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries"); |
|
203 | 203 | qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries"); |
|
204 | 204 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries"); |
|
205 | 205 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries"); |
|
206 | 206 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries"); |
|
207 | 207 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet"); |
|
208 | 208 | qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis"); |
|
209 | 209 | #ifndef QT_ON_ARM |
|
210 | 210 | qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis"); |
|
211 | 211 | #endif |
|
212 | 212 | qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis"); |
|
213 | 213 | qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange"); |
|
214 | 214 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis"); |
|
215 | 215 | qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins", |
|
216 | 216 | QLatin1String("Trying to create uncreatable: Margins.")); |
|
217 | 217 | |
|
218 | 218 | // QtCommercial.Chart 1.2 |
|
219 | 219 | qmlRegisterType<DeclarativeChart, 2>(uri, 1, 2, "ChartView"); |
|
220 | 220 | qmlRegisterType<DeclarativeScatterSeries, 2>(uri, 1, 2, "ScatterSeries"); |
|
221 | 221 | qmlRegisterType<DeclarativeLineSeries, 2>(uri, 1, 2, "LineSeries"); |
|
222 | 222 | qmlRegisterType<DeclarativeSplineSeries, 2>(uri, 1, 2, "SplineSeries"); |
|
223 | 223 | qmlRegisterType<DeclarativeAreaSeries, 2>(uri, 1, 2, "AreaSeries"); |
|
224 | 224 | qmlRegisterType<DeclarativeBarSeries, 2>(uri, 1, 2, "BarSeries"); |
|
225 | 225 | qmlRegisterType<DeclarativeStackedBarSeries, 2>(uri, 1, 2, "StackedBarSeries"); |
|
226 | 226 | qmlRegisterType<DeclarativePercentBarSeries, 2>(uri, 1, 2, "PercentBarSeries"); |
|
227 | 227 | qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries"); |
|
228 | 228 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries"); |
|
229 | 229 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries"); |
|
230 | 230 | |
|
231 | 231 | // QtCommercial.Chart 1.3 |
|
232 | qmlRegisterType<DeclarativeChart, 3>(uri, 1, 3, "ChartView"); | |
|
232 | 233 | qmlRegisterType<DeclarativePolarChart, 1>(uri, 1, 3, "PolarChartView"); |
|
233 | 234 | qmlRegisterType<DeclarativeSplineSeries, 3>(uri, 1, 3, "SplineSeries"); |
|
234 | 235 | qmlRegisterType<DeclarativeScatterSeries, 3>(uri, 1, 3, "ScatterSeries"); |
|
235 | 236 | qmlRegisterType<DeclarativeLineSeries, 3>(uri, 1, 3, "LineSeries"); |
|
236 | 237 | qmlRegisterType<DeclarativeAreaSeries, 3>(uri, 1, 3, "AreaSeries"); |
|
237 | 238 | qmlRegisterType<QLogValueAxis>(uri, 1, 3, "LogValueAxis"); |
|
238 | 239 | } |
|
239 | 240 | }; |
|
240 | 241 | |
|
241 | 242 | #include "plugin.moc" |
|
242 | 243 | |
|
243 | 244 | QTCOMMERCIALCHART_END_NAMESPACE |
|
244 | 245 | |
|
245 | 246 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
246 | 247 | |
|
247 | 248 | #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) |
|
248 | 249 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
249 | 250 | #endif |
@@ -1,319 +1,382 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 | #include "chartpresenter_p.h" |
|
21 | 21 | #include "qchart.h" |
|
22 | 22 | #include "chartitem_p.h" |
|
23 | 23 | #include "qchart_p.h" |
|
24 | 24 | #include "qabstractaxis.h" |
|
25 | 25 | #include "qabstractaxis_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "chartanimation_p.h" |
|
28 | 28 | #include "qabstractseries_p.h" |
|
29 | 29 | #include "qareaseries.h" |
|
30 | 30 | #include "chartaxiselement_p.h" |
|
31 | 31 | #include "chartbackground_p.h" |
|
32 | 32 | #include "cartesianchartlayout_p.h" |
|
33 | 33 | #include "polarchartlayout_p.h" |
|
34 | 34 | #include "charttitle_p.h" |
|
35 | 35 | #include <QTimer> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type) |
|
40 | 40 | : QObject(chart), |
|
41 | 41 | m_chart(chart), |
|
42 | 42 | m_options(QChart::NoAnimation), |
|
43 | 43 | m_state(ShowState), |
|
44 | 44 | m_background(0), |
|
45 | m_plotAreaBackground(0), | |
|
45 | 46 | m_title(0) |
|
46 | 47 | { |
|
47 | 48 | if (type == QChart::ChartTypeCartesian) |
|
48 | 49 | m_layout = new CartesianChartLayout(this); |
|
49 | 50 | else if (type == QChart::ChartTypePolar) |
|
50 | 51 | m_layout = new PolarChartLayout(this); |
|
51 | 52 | Q_ASSERT(m_layout); |
|
52 | 53 | } |
|
53 | 54 | |
|
54 | 55 | ChartPresenter::~ChartPresenter() |
|
55 | 56 | { |
|
56 | 57 | |
|
57 | 58 | } |
|
58 | 59 | |
|
59 | 60 | void ChartPresenter::setGeometry(const QRectF rect) |
|
60 | 61 | { |
|
61 | 62 | if (m_rect != rect) { |
|
62 | 63 | m_rect = rect; |
|
63 | 64 | foreach (ChartItem *chart, m_chartItems) { |
|
64 | 65 | chart->domain()->setSize(rect.size()); |
|
65 | 66 | chart->setPos(rect.topLeft()); |
|
66 | 67 | } |
|
67 | 68 | } |
|
68 | 69 | } |
|
69 | 70 | |
|
70 | 71 | QRectF ChartPresenter::geometry() const |
|
71 | 72 | { |
|
72 | 73 | return m_rect; |
|
73 | 74 | } |
|
74 | 75 | |
|
75 | 76 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) |
|
76 | 77 | { |
|
77 | 78 | axis->d_ptr->initializeGraphics(rootItem()); |
|
78 | 79 | axis->d_ptr->initializeAnimations(m_options); |
|
79 | 80 | ChartAxisElement *item = axis->d_ptr->axisItem(); |
|
80 | 81 | item->setPresenter(this); |
|
81 | 82 | item->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
82 | 83 | m_axisItems<<item; |
|
83 | 84 | m_axes<<axis; |
|
84 | 85 | m_layout->invalidate(); |
|
85 | 86 | } |
|
86 | 87 | |
|
87 | 88 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) |
|
88 | 89 | { |
|
89 | 90 | ChartAxisElement *item = axis->d_ptr->m_item.take(); |
|
90 | 91 | item->hide(); |
|
91 | 92 | item->disconnect(); |
|
92 | 93 | item->deleteLater(); |
|
93 | 94 | m_axisItems.removeAll(item); |
|
94 | 95 | m_axes.removeAll(axis); |
|
95 | 96 | m_layout->invalidate(); |
|
96 | 97 | } |
|
97 | 98 | |
|
98 | 99 | |
|
99 | 100 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) |
|
100 | 101 | { |
|
101 | 102 | series->d_ptr->initializeGraphics(rootItem()); |
|
102 | 103 | series->d_ptr->initializeAnimations(m_options); |
|
103 | 104 | ChartItem *chart = series->d_ptr->chartItem(); |
|
104 | 105 | chart->setPresenter(this); |
|
105 | 106 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
106 | 107 | chart->domain()->setSize(m_rect.size()); |
|
107 | 108 | chart->setPos(m_rect.topLeft()); |
|
108 | 109 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored |
|
109 | 110 | m_chartItems<<chart; |
|
110 | 111 | m_series<<series; |
|
111 | 112 | m_layout->invalidate(); |
|
112 | 113 | } |
|
113 | 114 | |
|
114 | 115 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) |
|
115 | 116 | { |
|
116 | 117 | ChartItem *chart = series->d_ptr->m_item.take(); |
|
117 | 118 | chart->hide(); |
|
118 | 119 | chart->disconnect(); |
|
119 | 120 | chart->deleteLater(); |
|
120 | 121 | m_chartItems.removeAll(chart); |
|
121 | 122 | m_series.removeAll(series); |
|
122 | 123 | m_layout->invalidate(); |
|
123 | 124 | } |
|
124 | 125 | |
|
125 | 126 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
126 | 127 | { |
|
127 | 128 | if (m_options != options) { |
|
128 | 129 | m_options = options; |
|
129 | 130 | |
|
130 | 131 | foreach(QAbstractSeries* series, m_series){ |
|
131 | 132 | series->d_ptr->initializeAnimations(m_options); |
|
132 | 133 | } |
|
133 | 134 | foreach(QAbstractAxis* axis, m_axes){ |
|
134 | 135 | axis->d_ptr->initializeAnimations(m_options); |
|
135 | 136 | } |
|
136 | 137 | } |
|
137 | 138 | } |
|
138 | 139 | |
|
139 | 140 | void ChartPresenter::setState(State state,QPointF point) |
|
140 | 141 | { |
|
141 | 142 | m_state=state; |
|
142 | 143 | m_statePoint=point; |
|
143 | 144 | } |
|
144 | 145 | |
|
145 | 146 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
146 | 147 | { |
|
147 | 148 | return m_options; |
|
148 | 149 | } |
|
149 | 150 | |
|
150 | 151 | void ChartPresenter::createBackgroundItem() |
|
151 | 152 | { |
|
152 | 153 | if (!m_background) { |
|
153 | 154 | m_background = new ChartBackground(rootItem()); |
|
154 | 155 | m_background->setPen(Qt::NoPen); |
|
155 | 156 | m_background->setZValue(ChartPresenter::BackgroundZValue); |
|
156 | 157 | } |
|
157 | 158 | } |
|
158 | 159 | |
|
160 | void ChartPresenter::createPlotAreaBackgroundItem() | |
|
161 | { | |
|
162 | if (!m_plotAreaBackground) { | |
|
163 | if (m_chart->chartType() == QChart::ChartTypeCartesian) | |
|
164 | m_plotAreaBackground = new QGraphicsRectItem(rootItem()); | |
|
165 | else | |
|
166 | m_plotAreaBackground = new QGraphicsEllipseItem(rootItem()); | |
|
167 | // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes | |
|
168 | // antialising artifacts with axis lines for some reason. | |
|
169 | m_plotAreaBackground->setPen(QPen(Qt::transparent)); | |
|
170 | m_plotAreaBackground->setBrush(Qt::NoBrush); | |
|
171 | m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue); | |
|
172 | m_plotAreaBackground->setVisible(false); | |
|
173 | } | |
|
174 | } | |
|
175 | ||
|
159 | 176 | void ChartPresenter::createTitleItem() |
|
160 | 177 | { |
|
161 | 178 | if (!m_title) { |
|
162 | 179 | m_title = new ChartTitle(rootItem()); |
|
163 | 180 | m_title->setZValue(ChartPresenter::BackgroundZValue); |
|
164 | 181 | } |
|
165 | 182 | } |
|
166 | 183 | |
|
167 | 184 | |
|
168 | 185 | void ChartPresenter::handleAnimationFinished() |
|
169 | 186 | { |
|
170 | 187 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); |
|
171 | 188 | if (m_animations.empty()) |
|
172 | 189 | emit animationsFinished(); |
|
173 | 190 | } |
|
174 | 191 | |
|
175 | 192 | void ChartPresenter::startAnimation(ChartAnimation *animation) |
|
176 | 193 | { |
|
177 | 194 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
178 | 195 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); |
|
179 | 196 | if (!m_animations.isEmpty()) |
|
180 | 197 | m_animations.append(animation); |
|
181 | 198 | QTimer::singleShot(0, animation, SLOT(start())); |
|
182 | 199 | } |
|
183 | 200 | |
|
184 | 201 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
|
185 | 202 | { |
|
186 | 203 | createBackgroundItem(); |
|
187 | 204 | m_background->setBrush(brush); |
|
188 | 205 | m_layout->invalidate(); |
|
189 | 206 | } |
|
190 | 207 | |
|
191 | 208 | QBrush ChartPresenter::backgroundBrush() const |
|
192 | 209 | { |
|
193 | 210 | if (!m_background) |
|
194 | 211 | return QBrush(); |
|
195 | 212 | return m_background->brush(); |
|
196 | 213 | } |
|
197 | 214 | |
|
198 | 215 | void ChartPresenter::setBackgroundPen(const QPen &pen) |
|
199 | 216 | { |
|
200 | 217 | createBackgroundItem(); |
|
201 | 218 | m_background->setPen(pen); |
|
202 | 219 | m_layout->invalidate(); |
|
203 | 220 | } |
|
204 | 221 | |
|
205 | 222 | QPen ChartPresenter::backgroundPen() const |
|
206 | 223 | { |
|
207 | 224 | if (!m_background) |
|
208 | 225 | return QPen(); |
|
209 | 226 | return m_background->pen(); |
|
210 | 227 | } |
|
211 | 228 | |
|
229 | void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush) | |
|
230 | { | |
|
231 | createPlotAreaBackgroundItem(); | |
|
232 | m_plotAreaBackground->setBrush(brush); | |
|
233 | m_layout->invalidate(); | |
|
234 | } | |
|
235 | ||
|
236 | QBrush ChartPresenter::plotAreaBackgroundBrush() const | |
|
237 | { | |
|
238 | if (!m_plotAreaBackground) | |
|
239 | return QBrush(); | |
|
240 | return m_plotAreaBackground->brush(); | |
|
241 | } | |
|
242 | ||
|
243 | void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen) | |
|
244 | { | |
|
245 | createPlotAreaBackgroundItem(); | |
|
246 | m_plotAreaBackground->setPen(pen); | |
|
247 | m_layout->invalidate(); | |
|
248 | } | |
|
249 | ||
|
250 | QPen ChartPresenter::plotAreaBackgroundPen() const | |
|
251 | { | |
|
252 | if (!m_plotAreaBackground) | |
|
253 | return QPen(); | |
|
254 | return m_plotAreaBackground->pen(); | |
|
255 | } | |
|
256 | ||
|
212 | 257 | void ChartPresenter::setTitle(const QString &title) |
|
213 | 258 | { |
|
214 | 259 | createTitleItem(); |
|
215 | 260 | m_title->setText(title); |
|
216 | 261 | m_layout->invalidate(); |
|
217 | 262 | } |
|
218 | 263 | |
|
219 | 264 | QString ChartPresenter::title() const |
|
220 | 265 | { |
|
221 | 266 | if (!m_title) |
|
222 | 267 | return QString(); |
|
223 | 268 | return m_title->text(); |
|
224 | 269 | } |
|
225 | 270 | |
|
226 | 271 | void ChartPresenter::setTitleFont(const QFont &font) |
|
227 | 272 | { |
|
228 | 273 | createTitleItem(); |
|
229 | 274 | m_title->setFont(font); |
|
230 | 275 | m_layout->invalidate(); |
|
231 | 276 | } |
|
232 | 277 | |
|
233 | 278 | QFont ChartPresenter::titleFont() const |
|
234 | 279 | { |
|
235 | 280 | if (!m_title) |
|
236 | 281 | return QFont(); |
|
237 | 282 | return m_title->font(); |
|
238 | 283 | } |
|
239 | 284 | |
|
240 | 285 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
241 | 286 | { |
|
242 | 287 | createTitleItem(); |
|
243 | 288 | m_title->setBrush(brush); |
|
244 | 289 | m_layout->invalidate(); |
|
245 | 290 | } |
|
246 | 291 | |
|
247 | 292 | QBrush ChartPresenter::titleBrush() const |
|
248 | 293 | { |
|
249 | 294 | if (!m_title) |
|
250 | 295 | return QBrush(); |
|
251 | 296 | return m_title->brush(); |
|
252 | 297 | } |
|
253 | 298 | |
|
254 | 299 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
255 | 300 | { |
|
256 | 301 | createBackgroundItem(); |
|
257 | 302 | m_background->setVisible(visible); |
|
258 | 303 | } |
|
259 | 304 | |
|
260 | 305 | |
|
261 | 306 | bool ChartPresenter::isBackgroundVisible() const |
|
262 | 307 | { |
|
263 | 308 | if (!m_background) |
|
264 | 309 | return false; |
|
265 | 310 | return m_background->isVisible(); |
|
266 | 311 | } |
|
267 | 312 | |
|
313 | void ChartPresenter::setPlotAreaBackgroundVisible(bool visible) | |
|
314 | { | |
|
315 | createPlotAreaBackgroundItem(); | |
|
316 | m_plotAreaBackground->setVisible(visible); | |
|
317 | } | |
|
318 | ||
|
319 | bool ChartPresenter::isPlotAreaBackgroundVisible() const | |
|
320 | { | |
|
321 | if (!m_plotAreaBackground) | |
|
322 | return false; | |
|
323 | return m_plotAreaBackground->isVisible(); | |
|
324 | } | |
|
325 | ||
|
268 | 326 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
269 | 327 | { |
|
270 | 328 | createBackgroundItem(); |
|
271 | 329 | m_background->setDropShadowEnabled(enabled); |
|
272 | 330 | } |
|
273 | 331 | |
|
274 | 332 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
275 | 333 | { |
|
276 | 334 | if (!m_background) |
|
277 | 335 | return false; |
|
278 | 336 | return m_background->isDropShadowEnabled(); |
|
279 | 337 | } |
|
280 | 338 | |
|
281 | 339 | |
|
282 | 340 | AbstractChartLayout *ChartPresenter::layout() |
|
283 | 341 | { |
|
284 | 342 | return m_layout; |
|
285 | 343 | } |
|
286 | 344 | |
|
287 | 345 | QLegend *ChartPresenter::legend() |
|
288 | 346 | { |
|
289 | 347 | return m_chart->legend(); |
|
290 | 348 | } |
|
291 | 349 | |
|
292 | 350 | void ChartPresenter::setVisible(bool visible) |
|
293 | 351 | { |
|
294 | 352 | m_chart->setVisible(visible); |
|
295 | 353 | } |
|
296 | 354 | |
|
297 | 355 | ChartBackground *ChartPresenter::backgroundElement() |
|
298 | 356 | { |
|
299 | 357 | return m_background; |
|
300 | 358 | } |
|
301 | 359 | |
|
360 | QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement() | |
|
361 | { | |
|
362 | return m_plotAreaBackground; | |
|
363 | } | |
|
364 | ||
|
302 | 365 | QList<ChartAxisElement *> ChartPresenter::axisItems() const |
|
303 | 366 | { |
|
304 | 367 | return m_axisItems; |
|
305 | 368 | } |
|
306 | 369 | |
|
307 | 370 | QList<ChartItem *> ChartPresenter::chartItems() const |
|
308 | 371 | { |
|
309 | 372 | return m_chartItems; |
|
310 | 373 | } |
|
311 | 374 | |
|
312 | 375 | ChartTitle *ChartPresenter::titleElement() |
|
313 | 376 | { |
|
314 | 377 | return m_title; |
|
315 | 378 | } |
|
316 | 379 | |
|
317 | 380 | #include "moc_chartpresenter_p.cpp" |
|
318 | 381 | |
|
319 | 382 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,166 +1,180 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 CHARTPRESENTER_H |
|
31 | 31 | #define CHARTPRESENTER_H |
|
32 | 32 | |
|
33 | 33 | #include "qchartglobal.h" |
|
34 | 34 | #include "qchart.h" //because of QChart::ChartThemeId |
|
35 | 35 | #include <QRectF> |
|
36 | 36 | #include <QMargins> |
|
37 | 37 | |
|
38 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class ChartItem; |
|
41 | 41 | class AxisItem; |
|
42 | 42 | class QAbstractSeries; |
|
43 | 43 | class ChartDataSet; |
|
44 | 44 | class AbstractDomain; |
|
45 | 45 | class ChartAxisElement; |
|
46 | 46 | class ChartAnimator; |
|
47 | 47 | class ChartBackground; |
|
48 | 48 | class ChartTitle; |
|
49 | 49 | class ChartAnimation; |
|
50 | 50 | class AbstractChartLayout; |
|
51 | 51 | |
|
52 | 52 | class ChartPresenter: public QObject |
|
53 | 53 | { |
|
54 | 54 | Q_OBJECT |
|
55 | 55 | public: |
|
56 | 56 | enum ZValues { |
|
57 | 57 | BackgroundZValue = -1, |
|
58 | PlotAreaZValue, | |
|
58 | 59 |
ShadesZValue |
|
59 | 60 | GridZValue, |
|
60 | 61 | AxisZValue, |
|
61 | 62 | SeriesZValue, |
|
62 | 63 | LineChartZValue = SeriesZValue, |
|
63 | 64 | SplineChartZValue = SeriesZValue, |
|
64 | 65 | BarSeriesZValue = SeriesZValue, |
|
65 | 66 | ScatterSeriesZValue = SeriesZValue, |
|
66 | 67 | PieSeriesZValue = SeriesZValue, |
|
67 | 68 | LegendZValue, |
|
68 | 69 | TopMostZValue |
|
69 | 70 | }; |
|
70 | 71 | |
|
71 | 72 | enum State { |
|
72 | 73 | ShowState, |
|
73 | 74 | ScrollUpState, |
|
74 | 75 | ScrollDownState, |
|
75 | 76 | ScrollLeftState, |
|
76 | 77 | ScrollRightState, |
|
77 | 78 | ZoomInState, |
|
78 | 79 | ZoomOutState |
|
79 | 80 | }; |
|
80 | 81 | |
|
81 | 82 | ChartPresenter(QChart *chart, QChart::ChartType type); |
|
82 | 83 | virtual ~ChartPresenter(); |
|
83 | 84 | |
|
84 | 85 | |
|
85 | 86 | void setGeometry(QRectF rect); |
|
86 | 87 | QRectF geometry() const; |
|
87 | 88 | |
|
88 | 89 | QGraphicsItem *rootItem(){ return m_chart; } |
|
89 | 90 | ChartBackground *backgroundElement(); |
|
91 | QAbstractGraphicsShapeItem *plotAreaElement(); | |
|
90 | 92 | ChartTitle *titleElement(); |
|
91 | 93 | QList<ChartAxisElement *> axisItems() const; |
|
92 | 94 | QList<ChartItem *> chartItems() const; |
|
93 | 95 | |
|
94 | 96 | QLegend *legend(); |
|
95 | 97 | |
|
96 | 98 | void setBackgroundBrush(const QBrush &brush); |
|
97 | 99 | QBrush backgroundBrush() const; |
|
98 | 100 | |
|
99 | 101 | void setBackgroundPen(const QPen &pen); |
|
100 | 102 | QPen backgroundPen() const; |
|
101 | 103 | |
|
104 | void setPlotAreaBackgroundBrush(const QBrush &brush); | |
|
105 | QBrush plotAreaBackgroundBrush() const; | |
|
106 | ||
|
107 | void setPlotAreaBackgroundPen(const QPen &pen); | |
|
108 | QPen plotAreaBackgroundPen() const; | |
|
109 | ||
|
102 | 110 | void setTitle(const QString &title); |
|
103 | 111 | QString title() const; |
|
104 | 112 | |
|
105 | 113 | void setTitleFont(const QFont &font); |
|
106 | 114 | QFont titleFont() const; |
|
107 | 115 | |
|
108 | 116 | void setTitleBrush(const QBrush &brush); |
|
109 | 117 | QBrush titleBrush() const; |
|
110 | 118 | |
|
111 | 119 | void setBackgroundVisible(bool visible); |
|
112 | 120 | bool isBackgroundVisible() const; |
|
113 | 121 | |
|
122 | void setPlotAreaBackgroundVisible(bool visible); | |
|
123 | bool isPlotAreaBackgroundVisible() const; | |
|
124 | ||
|
114 | 125 | void setBackgroundDropShadowEnabled(bool enabled); |
|
115 | 126 | bool isBackgroundDropShadowEnabled() const; |
|
116 | 127 | |
|
117 | 128 | void setVisible(bool visible); |
|
118 | 129 | |
|
119 | 130 | void setAnimationOptions(QChart::AnimationOptions options); |
|
120 | 131 | QChart::AnimationOptions animationOptions() const; |
|
121 | 132 | |
|
122 | 133 | void startAnimation(ChartAnimation *animation); |
|
123 | 134 | |
|
124 | 135 | //TODO refactor |
|
125 | 136 | void setState(State state,QPointF point); |
|
126 | 137 | State state() const { return m_state; } |
|
127 | 138 | QPointF statePoint() const { return m_statePoint; } |
|
128 | 139 | AbstractChartLayout *layout(); |
|
129 | 140 | |
|
130 | 141 | QChart::ChartType chartType() const { return m_chart->chartType(); } |
|
142 | QChart *chart() { return m_chart; } | |
|
131 | 143 | |
|
132 | 144 | private: |
|
133 | 145 | void createBackgroundItem(); |
|
146 | void createPlotAreaBackgroundItem(); | |
|
134 | 147 | void createTitleItem(); |
|
135 | 148 | |
|
136 | 149 | public Q_SLOTS: |
|
137 | 150 | void handleSeriesAdded(QAbstractSeries *series); |
|
138 | 151 | void handleSeriesRemoved(QAbstractSeries *series); |
|
139 | 152 | void handleAxisAdded(QAbstractAxis *axis); |
|
140 | 153 | void handleAxisRemoved(QAbstractAxis *axis); |
|
141 | 154 | |
|
142 | 155 | private Q_SLOTS: |
|
143 | 156 | void handleAnimationFinished(); |
|
144 | 157 | |
|
145 | 158 | Q_SIGNALS: |
|
146 | 159 | void animationsFinished(); |
|
147 | 160 | |
|
148 | 161 | private: |
|
149 | 162 | QChart *m_chart; |
|
150 | 163 | QList<ChartItem *> m_chartItems; |
|
151 | 164 | QList<ChartAxisElement *> m_axisItems; |
|
152 | 165 | QList<QAbstractSeries *> m_series; |
|
153 | 166 | QList<QAbstractAxis *> m_axes; |
|
154 | 167 | QChart::AnimationOptions m_options; |
|
155 | 168 | State m_state; |
|
156 | 169 | QPointF m_statePoint; |
|
157 | 170 | QList<ChartAnimation *> m_animations; |
|
158 | 171 | AbstractChartLayout *m_layout; |
|
159 | 172 | ChartBackground *m_background; |
|
173 | QAbstractGraphicsShapeItem *m_plotAreaBackground; | |
|
160 | 174 | ChartTitle *m_title; |
|
161 | 175 | QRectF m_rect; |
|
162 | 176 | }; |
|
163 | 177 | |
|
164 | 178 | QTCOMMERCIALCHART_END_NAMESPACE |
|
165 | 179 | |
|
166 | 180 | #endif /* CHARTPRESENTER_H */ |
@@ -1,259 +1,267 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 | #include "qabstractseries_p.h" |
|
21 | 21 | #include "qabstractaxis_p.h" |
|
22 | 22 | #include <QTime> |
|
23 | 23 | //themes |
|
24 | 24 | #include "chartthemesystem_p.h" |
|
25 | 25 | #include "chartthemelight_p.h" |
|
26 | 26 | #include "chartthemebluecerulean_p.h" |
|
27 | 27 | #include "chartthemedark_p.h" |
|
28 | 28 | #include "chartthemebrownsand_p.h" |
|
29 | 29 | #include "chartthemebluencs_p.h" |
|
30 | 30 | #include "chartthemehighcontrast_p.h" |
|
31 | 31 | #include "chartthemeblueicy_p.h" |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | ChartThemeManager::ChartThemeManager(QChart* chart) : |
|
36 | 36 | m_chart(chart) |
|
37 | 37 | { |
|
38 | 38 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | void ChartThemeManager::setTheme(QChart::ChartTheme theme) |
|
43 | 43 | { |
|
44 | 44 | if(m_theme.isNull() || theme != m_theme->id()) |
|
45 | 45 | { |
|
46 | 46 | switch (theme) { |
|
47 | 47 | case QChart::ChartThemeLight: |
|
48 | 48 | m_theme.reset(new ChartThemeLight()); |
|
49 | 49 | break; |
|
50 | 50 | case QChart::ChartThemeBlueCerulean: |
|
51 | 51 | m_theme.reset(new ChartThemeBlueCerulean()); |
|
52 | 52 | break; |
|
53 | 53 | case QChart::ChartThemeDark: |
|
54 | 54 | m_theme.reset(new ChartThemeDark()); |
|
55 | 55 | break; |
|
56 | 56 | case QChart::ChartThemeBrownSand: |
|
57 | 57 | m_theme.reset(new ChartThemeBrownSand()); |
|
58 | 58 | break; |
|
59 | 59 | case QChart::ChartThemeBlueNcs: |
|
60 | 60 | m_theme.reset(new ChartThemeBlueNcs()); |
|
61 | 61 | break; |
|
62 | 62 | case QChart::ChartThemeHighContrast: |
|
63 | 63 | m_theme.reset(new ChartThemeHighContrast()); |
|
64 | 64 | break; |
|
65 | 65 | case QChart::ChartThemeBlueIcy: |
|
66 | 66 | m_theme.reset(new ChartThemeBlueIcy()); |
|
67 | 67 | break; |
|
68 | 68 | default: |
|
69 | 69 | m_theme.reset(new ChartThemeSystem()); |
|
70 | 70 | break; |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | if(!m_theme.isNull()) |
|
74 | 74 | { |
|
75 | 75 | decorateChart(m_chart,m_theme.data(),true); |
|
76 | 76 | decorateLegend(m_chart->legend(),m_theme.data(),true); |
|
77 | 77 | foreach(QAbstractAxis* axis, m_axisList) { |
|
78 | 78 | axis->d_ptr->initializeTheme(m_theme.data(),true); |
|
79 | 79 | } |
|
80 | 80 | foreach(QAbstractSeries* series, m_seriesMap.keys()) { |
|
81 | 81 | series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),true); |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | } |
|
85 | 85 | } |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | void ChartThemeManager::decorateChart(QChart *chart,ChartTheme* theme,bool force) const |
|
89 | 89 | { |
|
90 | 90 | QBrush brush; |
|
91 | 91 | |
|
92 | 92 | if (force || brush == chart->backgroundBrush()) |
|
93 | 93 | chart->setBackgroundBrush(theme->chartBackgroundGradient()); |
|
94 | 94 | |
|
95 | if (force) { | |
|
96 | // Always clear plotArea brush when forced update, do not touch otherwise | |
|
97 | QPen pen(Qt::transparent); | |
|
98 | chart->setPlotAreaBackgroundBrush(brush); | |
|
99 | chart->setPlotAreaBackgroundPen(pen); | |
|
100 | chart->setPlotAreaBackgroundVisible(false); | |
|
101 | } | |
|
102 | ||
|
95 | 103 | chart->setTitleFont(theme->masterFont()); |
|
96 | 104 | chart->setTitleBrush(theme->labelBrush()); |
|
97 | 105 | chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled()); |
|
98 | 106 | } |
|
99 | 107 | |
|
100 | 108 | void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme* theme, bool force) const |
|
101 | 109 | { |
|
102 | 110 | QPen pen; |
|
103 | 111 | QBrush brush; |
|
104 | 112 | QFont font; |
|
105 | 113 | |
|
106 | 114 | if (force || pen == legend->pen()) |
|
107 | 115 | legend->setPen(theme->axisLinePen()); |
|
108 | 116 | |
|
109 | 117 | if (force || brush == legend->brush()) |
|
110 | 118 | legend->setBrush(theme->chartBackgroundGradient()); |
|
111 | 119 | |
|
112 | 120 | if (force || font == legend->font()) |
|
113 | 121 | legend->setFont(theme->labelFont()); |
|
114 | 122 | |
|
115 | 123 | if (force || brush == legend->labelBrush()) |
|
116 | 124 | legend->setLabelBrush(theme->labelBrush()); |
|
117 | 125 | } |
|
118 | 126 | |
|
119 | 127 | int ChartThemeManager::createIndexKey(QList<int> keys) const |
|
120 | 128 | { |
|
121 | 129 | qSort(keys); |
|
122 | 130 | |
|
123 | 131 | int key = 0; |
|
124 | 132 | QList<int>::iterator i; |
|
125 | 133 | i = keys.begin(); |
|
126 | 134 | |
|
127 | 135 | while (i != keys.end()) { |
|
128 | 136 | if (*i != key) |
|
129 | 137 | break; |
|
130 | 138 | key++; |
|
131 | 139 | i++; |
|
132 | 140 | } |
|
133 | 141 | |
|
134 | 142 | return key; |
|
135 | 143 | } |
|
136 | 144 | |
|
137 | 145 | int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const |
|
138 | 146 | { |
|
139 | 147 | int count = 0; |
|
140 | 148 | QList<QAbstractSeries *> series = m_seriesMap.keys(); |
|
141 | 149 | foreach(QAbstractSeries *s, series) { |
|
142 | 150 | if (s->type() == type) |
|
143 | 151 | count++; |
|
144 | 152 | } |
|
145 | 153 | return count; |
|
146 | 154 | } |
|
147 | 155 | |
|
148 | 156 | void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series) |
|
149 | 157 | { |
|
150 | 158 | int key = createIndexKey(m_seriesMap.values()); |
|
151 | 159 | m_seriesMap.insert(series,key); |
|
152 | 160 | series->d_ptr->initializeTheme(key,m_theme.data(),false); |
|
153 | 161 | } |
|
154 | 162 | |
|
155 | 163 | void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series) |
|
156 | 164 | { |
|
157 | 165 | m_seriesMap.remove(series); |
|
158 | 166 | } |
|
159 | 167 | |
|
160 | 168 | void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis) |
|
161 | 169 | { |
|
162 | 170 | m_axisList.append(axis); |
|
163 | 171 | axis->d_ptr->initializeTheme(m_theme.data(),false); |
|
164 | 172 | } |
|
165 | 173 | |
|
166 | 174 | void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis) |
|
167 | 175 | { |
|
168 | 176 | m_axisList.removeAll(axis); |
|
169 | 177 | } |
|
170 | 178 | |
|
171 | 179 | void ChartThemeManager::updateSeries(QAbstractSeries *series) |
|
172 | 180 | { |
|
173 | 181 | if(m_seriesMap.contains(series)){ |
|
174 | 182 | series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false); |
|
175 | 183 | } |
|
176 | 184 | } |
|
177 | 185 | QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors) |
|
178 | 186 | { |
|
179 | 187 | QList<QGradient> result; |
|
180 | 188 | // Generate gradients in HSV color space |
|
181 | 189 | foreach (const QColor &color, colors) { |
|
182 | 190 | QLinearGradient g; |
|
183 | 191 | qreal h = color.hsvHueF(); |
|
184 | 192 | qreal s = color.hsvSaturationF(); |
|
185 | 193 | |
|
186 | 194 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
187 | 195 | // most themes. The rest of the gradients we can define manually in theme specific |
|
188 | 196 | // implementation. |
|
189 | 197 | QColor start = color; |
|
190 | 198 | start.setHsvF(h, 0.0, 1.0); |
|
191 | 199 | g.setColorAt(0.0, start); |
|
192 | 200 | |
|
193 | 201 | g.setColorAt(0.5, color); |
|
194 | 202 | |
|
195 | 203 | QColor end = color; |
|
196 | 204 | end.setHsvF(h, s, 0.25); |
|
197 | 205 | g.setColorAt(1.0, end); |
|
198 | 206 | |
|
199 | 207 | result << g; |
|
200 | 208 | } |
|
201 | 209 | |
|
202 | 210 | return result; |
|
203 | 211 | } |
|
204 | 212 | |
|
205 | 213 | |
|
206 | 214 | QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
207 | 215 | { |
|
208 | 216 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
209 | 217 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
210 | 218 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
211 | 219 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
212 | 220 | QColor c; |
|
213 | 221 | c.setRgbF(r, g, b); |
|
214 | 222 | return c; |
|
215 | 223 | } |
|
216 | 224 | |
|
217 | 225 | QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos) |
|
218 | 226 | { |
|
219 | 227 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
220 | 228 | |
|
221 | 229 | QGradientStops stops = gradient.stops(); |
|
222 | 230 | int count = stops.count(); |
|
223 | 231 | |
|
224 | 232 | // find previous stop relative to position |
|
225 | 233 | QGradientStop prev = stops.first(); |
|
226 | 234 | for (int i = 0; i < count; i++) { |
|
227 | 235 | QGradientStop stop = stops.at(i); |
|
228 | 236 | if (pos > stop.first) |
|
229 | 237 | prev = stop; |
|
230 | 238 | |
|
231 | 239 | // given position is actually a stop position? |
|
232 | 240 | if (pos == stop.first) { |
|
233 | 241 | //qDebug() << "stop color" << pos; |
|
234 | 242 | return stop.second; |
|
235 | 243 | } |
|
236 | 244 | } |
|
237 | 245 | |
|
238 | 246 | // find next stop relative to position |
|
239 | 247 | QGradientStop next = stops.last(); |
|
240 | 248 | for (int i = count - 1; i >= 0; i--) { |
|
241 | 249 | QGradientStop stop = stops.at(i); |
|
242 | 250 | if (pos < stop.first) |
|
243 | 251 | next = stop; |
|
244 | 252 | } |
|
245 | 253 | |
|
246 | 254 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
247 | 255 | |
|
248 | 256 | qreal range = next.first - prev.first; |
|
249 | 257 | qreal posDelta = pos - prev.first; |
|
250 | 258 | qreal relativePos = posDelta / range; |
|
251 | 259 | |
|
252 | 260 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
253 | 261 | |
|
254 | 262 | return colorAt(prev.second, next.second, relativePos); |
|
255 | 263 | } |
|
256 | 264 | |
|
257 | 265 | #include "moc_chartthememanager_p.cpp" |
|
258 | 266 | |
|
259 | 267 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,197 +1,201 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 "abstractchartlayout_p.h" |
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | 23 | #include "qlegend_p.h" |
|
24 | 24 | #include "chartaxiselement_p.h" |
|
25 | 25 | #include "charttitle_p.h" |
|
26 | 26 | #include "chartbackground_p.h" |
|
27 | 27 | #include <QDebug> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | static const qreal golden_ratio = 0.4; |
|
32 | 32 | |
|
33 | 33 | AbstractChartLayout::AbstractChartLayout(ChartPresenter *presenter) |
|
34 | 34 | : m_presenter(presenter), |
|
35 | 35 | m_margins(20, 20, 20, 20), |
|
36 | 36 | m_minChartRect(0, 0, 200, 200) |
|
37 | 37 | { |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | AbstractChartLayout::~AbstractChartLayout() |
|
41 | 41 | { |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | void AbstractChartLayout::setGeometry(const QRectF &rect) |
|
45 | 45 | { |
|
46 | 46 | if (!rect.isValid()) |
|
47 | 47 | return; |
|
48 | 48 | |
|
49 | 49 | QList<ChartAxisElement *> axes = m_presenter->axisItems(); |
|
50 | 50 | ChartTitle *title = m_presenter->titleElement(); |
|
51 | 51 | QLegend *legend = m_presenter->legend(); |
|
52 | 52 | ChartBackground *background = m_presenter->backgroundElement(); |
|
53 | 53 | |
|
54 | 54 | QRectF contentGeometry = calculateBackgroundGeometry(rect, background); |
|
55 | 55 | |
|
56 | 56 | contentGeometry = calculateContentGeometry(contentGeometry); |
|
57 | 57 | |
|
58 | 58 | if (title && title->isVisible()) |
|
59 | 59 | contentGeometry = calculateTitleGeometry(contentGeometry, title); |
|
60 | 60 | |
|
61 | 61 | if (legend->isAttachedToChart() && legend->isVisible()) |
|
62 | 62 | contentGeometry = calculateLegendGeometry(contentGeometry, legend); |
|
63 | 63 | |
|
64 | 64 | contentGeometry = calculateAxisGeometry(contentGeometry, axes); |
|
65 | 65 | |
|
66 | 66 | m_presenter->setGeometry(contentGeometry); |
|
67 | if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian) | |
|
68 | static_cast<QGraphicsRectItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry); | |
|
69 | else | |
|
70 | static_cast<QGraphicsEllipseItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry); | |
|
67 | 71 | |
|
68 | 72 | QGraphicsLayout::setGeometry(rect); |
|
69 | 73 | } |
|
70 | 74 | |
|
71 | 75 | QRectF AbstractChartLayout::calculateContentGeometry(const QRectF &geometry) const |
|
72 | 76 | { |
|
73 | 77 | return geometry.adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom()); |
|
74 | 78 | } |
|
75 | 79 | |
|
76 | 80 | QRectF AbstractChartLayout::calculateContentMinimum(const QRectF &minimum) const |
|
77 | 81 | { |
|
78 | 82 | return minimum.adjusted(0, 0, m_margins.left() + m_margins.right(), m_margins.top() + m_margins.bottom()); |
|
79 | 83 | } |
|
80 | 84 | |
|
81 | 85 | |
|
82 | 86 | QRectF AbstractChartLayout::calculateBackgroundGeometry(const QRectF &geometry, ChartBackground *background) const |
|
83 | 87 | { |
|
84 | 88 | qreal left; |
|
85 | 89 | qreal top; |
|
86 | 90 | qreal right; |
|
87 | 91 | qreal bottom; |
|
88 | 92 | getContentsMargins(&left, &top, &right, &bottom); |
|
89 | 93 | QRectF backgroundGeometry = geometry.adjusted(left, top, -right, -bottom); |
|
90 | 94 | if (background) |
|
91 | 95 | background->setRect(backgroundGeometry); |
|
92 | 96 | return backgroundGeometry; |
|
93 | 97 | } |
|
94 | 98 | |
|
95 | 99 | QRectF AbstractChartLayout::calculateBackgroundMinimum(const QRectF &minimum) const |
|
96 | 100 | { |
|
97 | 101 | qreal left; |
|
98 | 102 | qreal top; |
|
99 | 103 | qreal right; |
|
100 | 104 | qreal bottom; |
|
101 | 105 | getContentsMargins(&left, &top, &right, &bottom); |
|
102 | 106 | return minimum.adjusted(0, 0, left + right, top + bottom); |
|
103 | 107 | } |
|
104 | 108 | |
|
105 | 109 | QRectF AbstractChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *legend) const |
|
106 | 110 | { |
|
107 | 111 | QSizeF size = legend->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)); |
|
108 | 112 | QRectF legendRect; |
|
109 | 113 | QRectF result; |
|
110 | 114 | |
|
111 | 115 | switch (legend->alignment()) { |
|
112 | 116 | case Qt::AlignTop: { |
|
113 | 117 | legendRect = QRectF(geometry.topLeft(), QSizeF(geometry.width(), size.height())); |
|
114 | 118 | result = geometry.adjusted(0, legendRect.height(), 0, 0); |
|
115 | 119 | break; |
|
116 | 120 | } |
|
117 | 121 | case Qt::AlignBottom: { |
|
118 | 122 | legendRect = QRectF(QPointF(geometry.left(), geometry.bottom() - size.height()), QSizeF(geometry.width(), size.height())); |
|
119 | 123 | result = geometry.adjusted(0, 0, 0, -legendRect.height()); |
|
120 | 124 | break; |
|
121 | 125 | } |
|
122 | 126 | case Qt::AlignLeft: { |
|
123 | 127 | qreal width = qMin(size.width(), geometry.width() * golden_ratio); |
|
124 | 128 | legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height())); |
|
125 | 129 | result = geometry.adjusted(width, 0, 0, 0); |
|
126 | 130 | break; |
|
127 | 131 | } |
|
128 | 132 | case Qt::AlignRight: { |
|
129 | 133 | qreal width = qMin(size.width(), geometry.width() * golden_ratio); |
|
130 | 134 | legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height())); |
|
131 | 135 | result = geometry.adjusted(0, 0, -width, 0); |
|
132 | 136 | break; |
|
133 | 137 | } |
|
134 | 138 | default: { |
|
135 | 139 | legendRect = QRectF(0, 0, 0, 0); |
|
136 | 140 | result = geometry; |
|
137 | 141 | break; |
|
138 | 142 | } |
|
139 | 143 | } |
|
140 | 144 | |
|
141 | 145 | legend->setGeometry(legendRect); |
|
142 | 146 | |
|
143 | 147 | return result; |
|
144 | 148 | } |
|
145 | 149 | |
|
146 | 150 | QRectF AbstractChartLayout::calculateLegendMinimum(const QRectF &geometry, QLegend *legend) const |
|
147 | 151 | { |
|
148 | 152 | QSizeF minSize = legend->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)); |
|
149 | 153 | return geometry.adjusted(0, 0, minSize.width(), minSize.height()); |
|
150 | 154 | } |
|
151 | 155 | |
|
152 | 156 | QRectF AbstractChartLayout::calculateTitleGeometry(const QRectF &geometry, ChartTitle *title) const |
|
153 | 157 | { |
|
154 | 158 | title->setGeometry(geometry); |
|
155 | 159 | QPointF center = geometry.center() - title->boundingRect().center(); |
|
156 | 160 | title->setPos(center.x(), title->pos().y()); |
|
157 | 161 | return geometry.adjusted(0, title->boundingRect().height()+1, 0, 0); |
|
158 | 162 | } |
|
159 | 163 | |
|
160 | 164 | QRectF AbstractChartLayout::calculateTitleMinimum(const QRectF &minimum, ChartTitle *title) const |
|
161 | 165 | { |
|
162 | 166 | QSizeF min = title->sizeHint(Qt::MinimumSize); |
|
163 | 167 | return minimum.adjusted(0, 0, min.width(), min.height()); |
|
164 | 168 | } |
|
165 | 169 | |
|
166 | 170 | QSizeF AbstractChartLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
167 | 171 | { |
|
168 | 172 | Q_UNUSED(constraint); |
|
169 | 173 | if (which == Qt::MinimumSize) { |
|
170 | 174 | QList<ChartAxisElement *> axes = m_presenter->axisItems(); |
|
171 | 175 | ChartTitle *title = m_presenter->titleElement(); |
|
172 | 176 | QLegend *legend = m_presenter->legend(); |
|
173 | 177 | QRectF minimumRect(0, 0, 0, 0); |
|
174 | 178 | minimumRect = calculateBackgroundMinimum(minimumRect); |
|
175 | 179 | minimumRect = calculateContentMinimum(minimumRect); |
|
176 | 180 | minimumRect = calculateTitleMinimum(minimumRect, title); |
|
177 | 181 | minimumRect = calculateLegendMinimum(minimumRect, legend); |
|
178 | 182 | minimumRect = calculateAxisMinimum(minimumRect, axes); |
|
179 | 183 | return minimumRect.united(m_minChartRect).size().toSize(); |
|
180 | 184 | } |
|
181 | 185 | return QSize(-1, -1); |
|
182 | 186 | } |
|
183 | 187 | |
|
184 | 188 | void AbstractChartLayout::setMargins(const QMargins &margins) |
|
185 | 189 | { |
|
186 | 190 | if (m_margins != margins) { |
|
187 | 191 | m_margins = margins; |
|
188 | 192 | updateGeometry(); |
|
189 | 193 | } |
|
190 | 194 | } |
|
191 | 195 | |
|
192 | 196 | QMargins AbstractChartLayout::margins() const |
|
193 | 197 | { |
|
194 | 198 | return m_margins; |
|
195 | 199 | } |
|
196 | 200 | |
|
197 | 201 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,696 +1,754 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include "legendscroller_p.h" |
|
24 | 24 | #include "qlegend_p.h" |
|
25 | 25 | #include "chartbackground_p.h" |
|
26 | 26 | #include "qabstractaxis.h" |
|
27 | 27 | #include "abstractchartlayout_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartpresenter_p.h" |
|
30 | 30 | #include "chartdataset_p.h" |
|
31 | 31 | #include <QGraphicsScene> |
|
32 | 32 | #include <QGraphicsSceneResizeEvent> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \enum QChart::ChartTheme |
|
38 | 38 | |
|
39 | 39 | This enum describes the theme used by the chart. |
|
40 | 40 | |
|
41 | 41 | \value ChartThemeLight The default theme |
|
42 | 42 | \value ChartThemeBlueCerulean |
|
43 | 43 | \value ChartThemeDark |
|
44 | 44 | \value ChartThemeBrownSand |
|
45 | 45 | \value ChartThemeBlueNcs |
|
46 | 46 | \value ChartThemeHighContrast |
|
47 | 47 | \value ChartThemeBlueIcy |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | /*! |
|
51 | 51 | \enum QChart::AnimationOption |
|
52 | 52 | |
|
53 | 53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
54 | 54 | |
|
55 | 55 | \value NoAnimation |
|
56 | 56 | \value GridAxisAnimations |
|
57 | 57 | \value SeriesAnimations |
|
58 | 58 | \value AllAnimations |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \enum QChart::ChartType |
|
63 | 63 | |
|
64 | 64 | This enum describes the chart type. |
|
65 | 65 | |
|
66 | 66 | \value ChartTypeUndefined |
|
67 | 67 | \value ChartTypeCartesian |
|
68 | 68 | \value ChartTypePolar |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \class QChart |
|
73 | 73 | \brief QtCommercial chart API. |
|
74 | 74 | |
|
75 | 75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
76 | 76 | representation of different types of series and other chart related objects like legend and |
|
77 | 77 | axes. If you simply want to show a chart in a layout, you can use the |
|
78 | 78 | convenience class QChartView instead of QChart. |
|
79 | 79 | \sa QChartView, QPolarChart |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \property QChart::animationOptions |
|
84 | 84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QChart::backgroundVisible |
|
89 | 89 | Specifies whether the chart background is visible or not. |
|
90 | \sa setBackgroundBrush(), setBackgroundPen() | |
|
90 | \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible | |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \property QChart::dropShadowEnabled |
|
95 | 95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
96 | 96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QChart::minimumMargins |
|
101 | 101 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
102 | 102 | This property is deprecated; use margins property instead. |
|
103 | 103 | |
|
104 | 104 | \sa margins |
|
105 | 105 | */ |
|
106 | 106 | |
|
107 | 107 | /*! |
|
108 | 108 | \property QChart::margins |
|
109 | 109 | Margins between the plot area (axes) and the edge of the chart widget. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \property QChart::theme |
|
114 | 114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
115 | 115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few |
|
116 | 116 | different themes. |
|
117 | 117 | \note Changing the theme will overwrite all customizations previously applied to the series. |
|
118 | 118 | */ |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | \property QChart::title |
|
122 | 122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | \property QChart::chartType |
|
127 | 127 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
128 | 128 | This property is set internally and it is read only. |
|
129 | 129 | \sa QPolarChart |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | \property QChart::plotAreaBackgroundVisible | |
|
134 | Specifies whether the chart plot area background is visible or not. | |
|
135 | \note By default the plot area background is not visible and the plot area uses | |
|
136 | the general chart background. | |
|
137 | \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible | |
|
138 | */ | |
|
139 | ||
|
140 | /*! | |
|
133 | 141 | \internal |
|
134 | 142 | Constructs a chart object of \a type which is a child of a \a parent. |
|
135 | 143 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
136 | 144 | This constructor is called only by subclasses. |
|
137 | 145 | */ |
|
138 | 146 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
139 | 147 | : QGraphicsWidget(parent, wFlags), |
|
140 | 148 | d_ptr(new QChartPrivate(this, type)) |
|
141 | 149 | { |
|
142 | 150 | d_ptr->init(); |
|
143 | 151 | } |
|
144 | 152 | |
|
145 | 153 | /*! |
|
146 | 154 | Constructs a chart object which is a child of a \a parent. |
|
147 | 155 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
148 | 156 | */ |
|
149 | 157 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
150 | 158 | : QGraphicsWidget(parent, wFlags), |
|
151 | 159 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
152 | 160 | { |
|
153 | 161 | d_ptr->init(); |
|
154 | 162 | } |
|
155 | 163 | |
|
156 | 164 | /*! |
|
157 | 165 | Destroys the chart object and its children, like series and axis objects added to it. |
|
158 | 166 | */ |
|
159 | 167 | QChart::~QChart() |
|
160 | 168 | { |
|
161 | 169 | //start by deleting dataset, it will remove all series and axes |
|
162 | 170 | delete d_ptr->m_dataset; |
|
163 | 171 | d_ptr->m_dataset = 0; |
|
164 | 172 | } |
|
165 | 173 | |
|
166 | 174 | /*! |
|
167 | 175 | Adds the \a series onto the chart and takes the ownership of it. |
|
168 | 176 | |
|
169 | 177 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart |
|
170 | 178 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to |
|
171 | 179 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges |
|
172 | 180 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other |
|
173 | 181 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after |
|
174 | 182 | a series has been added or explicitly attach axes for the series. |
|
175 | 183 | |
|
176 | 184 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
177 | 185 | */ |
|
178 | 186 | void QChart::addSeries(QAbstractSeries *series) |
|
179 | 187 | { |
|
180 | 188 | Q_ASSERT(series); |
|
181 | 189 | d_ptr->m_dataset->addSeries(series); |
|
182 | 190 | } |
|
183 | 191 | |
|
184 | 192 | /*! |
|
185 | 193 | Removes the \a series from the chart. |
|
186 | 194 | The chart releases its ownership of the specified \a series object. |
|
187 | 195 | |
|
188 | 196 | \sa addSeries(), removeAllSeries() |
|
189 | 197 | */ |
|
190 | 198 | void QChart::removeSeries(QAbstractSeries *series) |
|
191 | 199 | { |
|
192 | 200 | Q_ASSERT(series); |
|
193 | 201 | d_ptr->m_dataset->removeSeries(series); |
|
194 | 202 | } |
|
195 | 203 | |
|
196 | 204 | /*! |
|
197 | 205 | Removes and deletes all series objects that have been added to the chart. |
|
198 | 206 | |
|
199 | 207 | \sa addSeries(), removeSeries() |
|
200 | 208 | */ |
|
201 | 209 | void QChart::removeAllSeries() |
|
202 | 210 | { |
|
203 | 211 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
204 | 212 | removeSeries(s); |
|
205 | 213 | delete s; |
|
206 | 214 | } |
|
207 | 215 | } |
|
208 | 216 | |
|
209 | 217 | /*! |
|
210 | 218 | Sets the \a brush that is used for painting the background of the chart area. |
|
211 | 219 | */ |
|
212 | 220 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
213 | 221 | { |
|
214 | 222 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
215 | 223 | } |
|
216 | 224 | |
|
217 | 225 | /*! |
|
218 | 226 | Gets the brush that is used for painting the background of the chart area. |
|
219 | 227 | */ |
|
220 | 228 | QBrush QChart::backgroundBrush() const |
|
221 | 229 | { |
|
222 | 230 | return d_ptr->m_presenter->backgroundBrush(); |
|
223 | 231 | } |
|
224 | 232 | |
|
225 | 233 | /*! |
|
226 | 234 | Sets the \a pen that is used for painting the background of the chart area. |
|
227 | 235 | */ |
|
228 | 236 | void QChart::setBackgroundPen(const QPen &pen) |
|
229 | 237 | { |
|
230 | 238 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
231 | 239 | } |
|
232 | 240 | |
|
233 | 241 | /*! |
|
234 | 242 | Gets the pen that is used for painting the background of the chart area. |
|
235 | 243 | */ |
|
236 | 244 | QPen QChart::backgroundPen() const |
|
237 | 245 | { |
|
238 | 246 | return d_ptr->m_presenter->backgroundPen(); |
|
239 | 247 | } |
|
240 | 248 | |
|
241 | 249 | void QChart::setTitle(const QString &title) |
|
242 | 250 | { |
|
243 | 251 | d_ptr->m_presenter->setTitle(title); |
|
244 | 252 | } |
|
245 | 253 | |
|
246 | 254 | QString QChart::title() const |
|
247 | 255 | { |
|
248 | 256 | return d_ptr->m_presenter->title(); |
|
249 | 257 | } |
|
250 | 258 | |
|
251 | 259 | /*! |
|
252 | 260 | Sets the \a font that is used for drawing the chart title. |
|
253 | 261 | */ |
|
254 | 262 | void QChart::setTitleFont(const QFont &font) |
|
255 | 263 | { |
|
256 | 264 | d_ptr->m_presenter->setTitleFont(font); |
|
257 | 265 | } |
|
258 | 266 | |
|
259 | 267 | /*! |
|
260 | 268 | Gets the font that is used for drawing the chart title. |
|
261 | 269 | */ |
|
262 | 270 | QFont QChart::titleFont() const |
|
263 | 271 | { |
|
264 | 272 | return d_ptr->m_presenter->titleFont(); |
|
265 | 273 | } |
|
266 | 274 | |
|
267 | 275 | /*! |
|
268 | 276 | Sets the \a brush used for drawing the title text. |
|
269 | 277 | */ |
|
270 | 278 | void QChart::setTitleBrush(const QBrush &brush) |
|
271 | 279 | { |
|
272 | 280 | d_ptr->m_presenter->setTitleBrush(brush); |
|
273 | 281 | } |
|
274 | 282 | |
|
275 | 283 | /*! |
|
276 | 284 | Returns the brush used for drawing the title text. |
|
277 | 285 | */ |
|
278 | 286 | QBrush QChart::titleBrush() const |
|
279 | 287 | { |
|
280 | 288 | return d_ptr->m_presenter->titleBrush(); |
|
281 | 289 | } |
|
282 | 290 | |
|
283 | 291 | void QChart::setTheme(QChart::ChartTheme theme) |
|
284 | 292 | { |
|
285 | 293 | d_ptr->m_themeManager->setTheme(theme); |
|
286 | 294 | } |
|
287 | 295 | |
|
288 | 296 | QChart::ChartTheme QChart::theme() const |
|
289 | 297 | { |
|
290 | 298 | return d_ptr->m_themeManager->theme()->id(); |
|
291 | 299 | } |
|
292 | 300 | |
|
293 | 301 | /*! |
|
294 | 302 | Zooms in the view by a factor of two. |
|
295 | 303 | */ |
|
296 | 304 | void QChart::zoomIn() |
|
297 | 305 | { |
|
298 | 306 | d_ptr->zoomIn(2.0); |
|
299 | 307 | } |
|
300 | 308 | |
|
301 | 309 | /*! |
|
302 | 310 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
303 | 311 | \note This is not supported for polar charts. |
|
304 | 312 | */ |
|
305 | 313 | void QChart::zoomIn(const QRectF &rect) |
|
306 | 314 | { |
|
307 | 315 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
308 | 316 | return; |
|
309 | 317 | d_ptr->zoomIn(rect); |
|
310 | 318 | } |
|
311 | 319 | |
|
312 | 320 | /*! |
|
313 | 321 | Zooms out the view by a factor of two. |
|
314 | 322 | */ |
|
315 | 323 | void QChart::zoomOut() |
|
316 | 324 | { |
|
317 | 325 | d_ptr->zoomOut(2.0); |
|
318 | 326 | } |
|
319 | 327 | |
|
320 | 328 | /*! |
|
321 | 329 | Zooms in the view by a custom \a factor. |
|
322 | 330 | |
|
323 | 331 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
324 | 332 | */ |
|
325 | 333 | void QChart::zoom(qreal factor) |
|
326 | 334 | { |
|
327 | 335 | if (qFuzzyCompare(factor, 0)) |
|
328 | 336 | return; |
|
329 | 337 | |
|
330 | 338 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
331 | 339 | return; |
|
332 | 340 | |
|
333 | 341 | if (factor < 0) |
|
334 | 342 | return; |
|
335 | 343 | |
|
336 | 344 | if (factor > 1.0) |
|
337 | 345 | d_ptr->zoomIn(factor); |
|
338 | 346 | else |
|
339 | 347 | d_ptr->zoomOut(1.0 / factor); |
|
340 | 348 | } |
|
341 | 349 | |
|
342 | 350 | /*! |
|
343 | 351 | Returns a pointer to the horizontal axis attached to the specified \a series. |
|
344 | 352 | If no \a series is specified, the first horizontal axis added to the chart is returned. |
|
345 | 353 | |
|
346 | 354 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
347 | 355 | */ |
|
348 | 356 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
349 | 357 | { |
|
350 | 358 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
351 | 359 | if (axisList.count()) |
|
352 | 360 | return axisList[0]; |
|
353 | 361 | return 0; |
|
354 | 362 | } |
|
355 | 363 | |
|
356 | 364 | /*! |
|
357 | 365 | Returns a pointer to the vertical axis attached to the specified \a series. |
|
358 | 366 | If no \a series is specified, the first vertical axis added to the chart is returned. |
|
359 | 367 | |
|
360 | 368 | \sa addAxis(), QAbstractSeries::attachAxis() |
|
361 | 369 | */ |
|
362 | 370 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
363 | 371 | { |
|
364 | 372 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
365 | 373 | if (axisList.count()) |
|
366 | 374 | return axisList[0]; |
|
367 | 375 | return 0; |
|
368 | 376 | } |
|
369 | 377 | |
|
370 | 378 | /*! |
|
371 | 379 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, |
|
372 | 380 | then all axes added to the chart with the specified orientation are returned. |
|
373 | 381 | \sa addAxis(), createDefaultAxes() |
|
374 | 382 | */ |
|
375 | 383 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
376 | 384 | { |
|
377 | 385 | QList<QAbstractAxis *> result ; |
|
378 | 386 | |
|
379 | 387 | if (series) { |
|
380 | 388 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
381 | 389 | if (orientation.testFlag(axis->orientation())) |
|
382 | 390 | result << axis; |
|
383 | 391 | } |
|
384 | 392 | } else { |
|
385 | 393 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
386 | 394 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
387 | 395 | result << axis; |
|
388 | 396 | } |
|
389 | 397 | } |
|
390 | 398 | |
|
391 | 399 | return result; |
|
392 | 400 | } |
|
393 | 401 | |
|
394 | 402 | /*! |
|
395 | 403 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to |
|
396 | 404 | the chart will be deleted. |
|
397 | 405 | |
|
398 | 406 | \note This function has to be called after all series have been added to the chart. The axes created by this function |
|
399 | 407 | will NOT get automatically attached to any series added to the chart after this function has been called. |
|
400 | 408 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing |
|
401 | 409 | if there are other series with properly attached axes also present. |
|
402 | 410 | |
|
403 | 411 | \table |
|
404 | 412 | \header |
|
405 | 413 | \o Series type |
|
406 | 414 | \o X-axis |
|
407 | 415 | \o Y-axis |
|
408 | 416 | \row |
|
409 | 417 | \o QXYSeries |
|
410 | 418 | \o QValueAxis |
|
411 | 419 | \o QValueAxis |
|
412 | 420 | \row |
|
413 | 421 | \o QBarSeries |
|
414 | 422 | \o QBarCategoryAxis |
|
415 | 423 | \o QValueAxis |
|
416 | 424 | \row |
|
417 | 425 | \o QPieSeries |
|
418 | 426 | \o None |
|
419 | 427 | \o None |
|
420 | 428 | \endtable |
|
421 | 429 | |
|
422 | 430 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. |
|
423 | 431 | If there are several series of different types added to the chart, then each series gets its own axes pair. |
|
424 | 432 | |
|
425 | 433 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. |
|
426 | 434 | QPieSeries does not create any axes. |
|
427 | 435 | |
|
428 | 436 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() |
|
429 | 437 | */ |
|
430 | 438 | void QChart::createDefaultAxes() |
|
431 | 439 | { |
|
432 | 440 | d_ptr->m_dataset->createDefaultAxes(); |
|
433 | 441 | } |
|
434 | 442 | |
|
435 | 443 | /*! |
|
436 | 444 | Returns the legend object of the chart. Ownership stays with the chart. |
|
437 | 445 | */ |
|
438 | 446 | QLegend *QChart::legend() const |
|
439 | 447 | { |
|
440 | 448 | return d_ptr->m_legend; |
|
441 | 449 | } |
|
442 | 450 | |
|
443 | 451 | void QChart::setMinimumMargins(const QMargins &margins) |
|
444 | 452 | { |
|
445 | 453 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
446 | 454 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
447 | 455 | } |
|
448 | 456 | |
|
449 | 457 | QMargins QChart::minimumMargins() const |
|
450 | 458 | { |
|
451 | 459 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
452 | 460 | return d_ptr->m_presenter->layout()->margins(); |
|
453 | 461 | } |
|
454 | 462 | |
|
455 | 463 | void QChart::setMargins(const QMargins &margins) |
|
456 | 464 | { |
|
457 | 465 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
458 | 466 | } |
|
459 | 467 | |
|
460 | 468 | QMargins QChart::margins() const |
|
461 | 469 | { |
|
462 | 470 | return d_ptr->m_presenter->layout()->margins(); |
|
463 | 471 | } |
|
464 | 472 | |
|
465 | 473 | QChart::ChartType QChart::chartType() const |
|
466 | 474 | { |
|
467 | 475 | return d_ptr->m_type; |
|
468 | 476 | } |
|
469 | 477 | |
|
470 | 478 | /*! |
|
471 | 479 | Returns the the rectangle within which the drawing of the chart is done. |
|
472 | 480 | It does not include the area defined by margins. |
|
473 | 481 | */ |
|
474 | 482 | QRectF QChart::plotArea() const |
|
475 | 483 | { |
|
476 | 484 | return d_ptr->m_presenter->geometry(); |
|
477 | 485 | } |
|
478 | 486 | |
|
487 | /*! | |
|
488 | Sets the \a brush for the background of the plot area of the chart. | |
|
489 | ||
|
490 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush() | |
|
491 | */ | |
|
492 | void QChart::setPlotAreaBackgroundBrush(const QBrush &brush) | |
|
493 | { | |
|
494 | d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush); | |
|
495 | } | |
|
496 | ||
|
497 | /*! | |
|
498 | Returns the brush for the background of the plot area of the chart. | |
|
499 | ||
|
500 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush() | |
|
501 | */ | |
|
502 | QBrush QChart::plotAreaBackgroundBrush() const | |
|
503 | { | |
|
504 | return d_ptr->m_presenter->plotAreaBackgroundBrush(); | |
|
505 | } | |
|
506 | ||
|
507 | /*! | |
|
508 | Sets the \a pen for the background of the plot area of the chart. | |
|
509 | ||
|
510 | \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen() | |
|
511 | */ | |
|
512 | void QChart::setPlotAreaBackgroundPen(const QPen &pen) | |
|
513 | { | |
|
514 | d_ptr->m_presenter->setPlotAreaBackgroundPen(pen); | |
|
515 | } | |
|
516 | ||
|
517 | /*! | |
|
518 | Returns the \a pen for the background of the plot area of the chart. | |
|
519 | ||
|
520 | \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen() | |
|
521 | */ | |
|
522 | QPen QChart::plotAreaBackgroundPen() const | |
|
523 | { | |
|
524 | return d_ptr->m_presenter->plotAreaBackgroundPen(); | |
|
525 | } | |
|
526 | ||
|
527 | void QChart::setPlotAreaBackgroundVisible(bool visible) | |
|
528 | { | |
|
529 | d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible); | |
|
530 | } | |
|
531 | ||
|
532 | bool QChart::isPlotAreaBackgroundVisible() const | |
|
533 | { | |
|
534 | return d_ptr->m_presenter->isPlotAreaBackgroundVisible(); | |
|
535 | } | |
|
536 | ||
|
479 | 537 | void QChart::setAnimationOptions(AnimationOptions options) |
|
480 | 538 | { |
|
481 | 539 | d_ptr->m_presenter->setAnimationOptions(options); |
|
482 | 540 | } |
|
483 | 541 | |
|
484 | 542 | QChart::AnimationOptions QChart::animationOptions() const |
|
485 | 543 | { |
|
486 | 544 | return d_ptr->m_presenter->animationOptions(); |
|
487 | 545 | } |
|
488 | 546 | |
|
489 | 547 | /*! |
|
490 | 548 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
491 | 549 | |
|
492 | 550 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
493 | 551 | */ |
|
494 | 552 | void QChart::scroll(qreal dx, qreal dy) |
|
495 | 553 | { |
|
496 | 554 | d_ptr->scroll(dx,dy); |
|
497 | 555 | } |
|
498 | 556 | |
|
499 | 557 | void QChart::setBackgroundVisible(bool visible) |
|
500 | 558 | { |
|
501 | 559 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
502 | 560 | } |
|
503 | 561 | |
|
504 | 562 | bool QChart::isBackgroundVisible() const |
|
505 | 563 | { |
|
506 | 564 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
507 | 565 | } |
|
508 | 566 | |
|
509 | 567 | void QChart::setDropShadowEnabled(bool enabled) |
|
510 | 568 | { |
|
511 | 569 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
512 | 570 | } |
|
513 | 571 | |
|
514 | 572 | bool QChart::isDropShadowEnabled() const |
|
515 | 573 | { |
|
516 | 574 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
517 | 575 | } |
|
518 | 576 | |
|
519 | 577 | /*! |
|
520 | 578 | Returns all series that are added to the chart. |
|
521 | 579 | |
|
522 | 580 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
523 | 581 | */ |
|
524 | 582 | QList<QAbstractSeries *> QChart::series() const |
|
525 | 583 | { |
|
526 | 584 | return d_ptr->m_dataset->series(); |
|
527 | 585 | } |
|
528 | 586 | |
|
529 | 587 | /*! |
|
530 | 588 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. |
|
531 | 589 | The chart takes ownership of both the \a axis and the \a series. |
|
532 | 590 | Any horizontal axes previously attached to the \a series are deleted. |
|
533 | 591 | |
|
534 | 592 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
535 | 593 | */ |
|
536 | 594 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) |
|
537 | 595 | { |
|
538 | 596 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); |
|
539 | 597 | |
|
540 | 598 | foreach (QAbstractAxis* a, list) { |
|
541 | 599 | d_ptr->m_dataset->removeAxis(a); |
|
542 | 600 | delete a; |
|
543 | 601 | } |
|
544 | 602 | |
|
545 | 603 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
546 | 604 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); |
|
547 | 605 | d_ptr->m_dataset->attachAxis(series, axis); |
|
548 | 606 | } |
|
549 | 607 | |
|
550 | 608 | /*! |
|
551 | 609 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. |
|
552 | 610 | The chart takes ownership of both the \a axis and the \a series. |
|
553 | 611 | Any vertical axes previously attached to the \a series are deleted. |
|
554 | 612 | |
|
555 | 613 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
556 | 614 | */ |
|
557 | 615 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) |
|
558 | 616 | { |
|
559 | 617 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); |
|
560 | 618 | |
|
561 | 619 | foreach (QAbstractAxis* a, list) { |
|
562 | 620 | d_ptr->m_dataset->removeAxis(a); |
|
563 | 621 | delete a; |
|
564 | 622 | } |
|
565 | 623 | |
|
566 | 624 | if (!d_ptr->m_dataset->axes().contains(axis)) |
|
567 | 625 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); |
|
568 | 626 | d_ptr->m_dataset->attachAxis(series, axis); |
|
569 | 627 | } |
|
570 | 628 | |
|
571 | 629 | /*! |
|
572 | 630 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
573 | 631 | |
|
574 | 632 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
575 | 633 | */ |
|
576 | 634 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
577 | 635 | { |
|
578 | 636 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
579 | 637 | } |
|
580 | 638 | |
|
581 | 639 | /*! |
|
582 | 640 | Removes the \a axis from the chart. |
|
583 | 641 | The chart releases its ownership of the specified \a axis object. |
|
584 | 642 | |
|
585 | 643 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
586 | 644 | */ |
|
587 | 645 | void QChart::removeAxis(QAbstractAxis *axis) |
|
588 | 646 | { |
|
589 | 647 | d_ptr->m_dataset->removeAxis(axis); |
|
590 | 648 | } |
|
591 | 649 | |
|
592 | 650 | /*! |
|
593 | 651 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. |
|
594 | 652 | */ |
|
595 | 653 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
596 | 654 | { |
|
597 | 655 | return d_ptr->m_dataset->mapToValue(position, series); |
|
598 | 656 | } |
|
599 | 657 | |
|
600 | 658 | /*! |
|
601 | 659 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. |
|
602 | 660 | */ |
|
603 | 661 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
604 | 662 | { |
|
605 | 663 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
606 | 664 | } |
|
607 | 665 | |
|
608 | 666 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
609 | 667 | |
|
610 | 668 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
611 | 669 | q_ptr(q), |
|
612 | 670 | m_type(type), |
|
613 | 671 | m_legend(0), |
|
614 | 672 | m_dataset(new ChartDataSet(q)), |
|
615 | 673 | m_presenter(new ChartPresenter(q, type)), |
|
616 | 674 | m_themeManager(new ChartThemeManager(q)) |
|
617 | 675 | { |
|
618 | 676 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
619 | 677 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
620 | 678 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
621 | 679 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
622 | 680 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
623 | 681 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
624 | 682 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
625 | 683 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
626 | 684 | } |
|
627 | 685 | |
|
628 | 686 | QChartPrivate::~QChartPrivate() |
|
629 | 687 | { |
|
630 | 688 | } |
|
631 | 689 | |
|
632 | 690 | void QChartPrivate::init() |
|
633 | 691 | { |
|
634 | 692 | m_legend = new LegendScroller(q_ptr); |
|
635 | 693 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
636 | 694 | q_ptr->setLayout(m_presenter->layout()); |
|
637 | 695 | } |
|
638 | 696 | |
|
639 | 697 | void QChartPrivate::zoomIn(qreal factor) |
|
640 | 698 | { |
|
641 | 699 | QRectF rect = m_presenter->geometry(); |
|
642 | 700 | rect.setWidth(rect.width() / factor); |
|
643 | 701 | rect.setHeight(rect.height() / factor); |
|
644 | 702 | rect.moveCenter(m_presenter->geometry().center()); |
|
645 | 703 | zoomIn(rect); |
|
646 | 704 | } |
|
647 | 705 | |
|
648 | 706 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
649 | 707 | { |
|
650 | 708 | if (!rect.isValid()) |
|
651 | 709 | return; |
|
652 | 710 | |
|
653 | 711 | QRectF r = rect.normalized(); |
|
654 | 712 | const QRectF geometry = m_presenter->geometry(); |
|
655 | 713 | r.translate(-geometry.topLeft()); |
|
656 | 714 | |
|
657 | 715 | if (!r.isValid()) |
|
658 | 716 | return; |
|
659 | 717 | |
|
660 | 718 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
661 | 719 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
662 | 720 | m_dataset->zoomInDomain(r); |
|
663 | 721 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
664 | 722 | |
|
665 | 723 | } |
|
666 | 724 | |
|
667 | 725 | void QChartPrivate::zoomOut(qreal factor) |
|
668 | 726 | { |
|
669 | 727 | const QRectF geometry = m_presenter->geometry(); |
|
670 | 728 | |
|
671 | 729 | QRectF r; |
|
672 | 730 | r.setSize(geometry.size() / factor); |
|
673 | 731 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
674 | 732 | if (!r.isValid()) |
|
675 | 733 | return; |
|
676 | 734 | |
|
677 | 735 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
678 | 736 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
679 | 737 | m_dataset->zoomOutDomain(r); |
|
680 | 738 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
681 | 739 | } |
|
682 | 740 | |
|
683 | 741 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
684 | 742 | { |
|
685 | 743 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
686 | 744 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
687 | 745 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
688 | 746 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
689 | 747 | |
|
690 | 748 | m_dataset->scrollDomain(dx, dy); |
|
691 | 749 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
692 | 750 | } |
|
693 | 751 | |
|
694 | 752 | #include "moc_qchart.cpp" |
|
695 | 753 | |
|
696 | 754 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,162 +1,169 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 minimumMargins READ minimumMargins WRITE setMinimumMargins) |
|
47 | 47 | Q_PROPERTY(QMargins margins READ margins WRITE setMargins) |
|
48 | 48 | Q_PROPERTY(QChart::ChartType chartType READ chartType) |
|
49 | Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible) | |
|
49 | 50 | Q_ENUMS(ChartTheme) |
|
50 | 51 | Q_ENUMS(AnimationOption) |
|
51 | 52 | Q_ENUMS(ChartType) |
|
52 | 53 | |
|
53 | 54 | public: |
|
54 | 55 | enum ChartType { |
|
55 | 56 | ChartTypeUndefined = 0, |
|
56 | 57 | ChartTypeCartesian, |
|
57 | 58 | ChartTypePolar |
|
58 | 59 | }; |
|
59 | 60 | |
|
60 | 61 | enum ChartTheme { |
|
61 | 62 | ChartThemeLight = 0, |
|
62 | 63 | ChartThemeBlueCerulean, |
|
63 | 64 | ChartThemeDark, |
|
64 | 65 | ChartThemeBrownSand, |
|
65 | 66 | ChartThemeBlueNcs, |
|
66 | 67 | ChartThemeHighContrast, |
|
67 | 68 | ChartThemeBlueIcy |
|
68 | 69 | }; |
|
69 | 70 | |
|
70 | 71 | enum AnimationOption { |
|
71 | 72 | NoAnimation = 0x0, |
|
72 | 73 | GridAxisAnimations = 0x1, |
|
73 | 74 | SeriesAnimations = 0x2, |
|
74 | 75 | AllAnimations = 0x3 |
|
75 | 76 | }; |
|
76 | 77 | |
|
77 | 78 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
78 | 79 | |
|
79 | 80 | public: |
|
80 | 81 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
81 | 82 | ~QChart(); |
|
82 | 83 | |
|
83 | 84 | void addSeries(QAbstractSeries *series); |
|
84 | 85 | void removeSeries(QAbstractSeries *series); |
|
85 | 86 | void removeAllSeries(); |
|
86 | 87 | QList<QAbstractSeries *> series() const; |
|
87 | 88 | |
|
88 | 89 | // *** deprecated *** |
|
89 | 90 | void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
90 | 91 | void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
91 | 92 | QAbstractAxis *axisX(QAbstractSeries *series = 0) const; |
|
92 | 93 | QAbstractAxis *axisY(QAbstractSeries *series = 0) const; |
|
93 | 94 | // ****************** |
|
94 | 95 | |
|
95 | 96 | void addAxis(QAbstractAxis *axis, Qt::Alignment alignment); |
|
96 | 97 | void removeAxis(QAbstractAxis *axis); |
|
97 | 98 | QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const; |
|
98 | 99 | |
|
99 | 100 | void createDefaultAxes(); |
|
100 | 101 | |
|
101 | 102 | void setTheme(QChart::ChartTheme theme); |
|
102 | 103 | QChart::ChartTheme theme() const; |
|
103 | 104 | |
|
104 | 105 | void setTitle(const QString &title); |
|
105 | 106 | QString title() const; |
|
106 | 107 | void setTitleFont(const QFont &font); |
|
107 | 108 | QFont titleFont() const; |
|
108 | 109 | void setTitleBrush(const QBrush &brush); |
|
109 | 110 | QBrush titleBrush() const; |
|
110 | 111 | |
|
111 | 112 | void setBackgroundBrush(const QBrush &brush); |
|
112 | 113 | QBrush backgroundBrush() const; |
|
113 | 114 | void setBackgroundPen(const QPen &pen); |
|
114 | 115 | QPen backgroundPen() const; |
|
115 | 116 | void setBackgroundVisible(bool visible = true); |
|
116 | 117 | bool isBackgroundVisible() const; |
|
117 | 118 | |
|
118 | 119 | void setDropShadowEnabled(bool enabled = true); |
|
119 | 120 | bool isDropShadowEnabled() const; |
|
120 | 121 | void setAnimationOptions(AnimationOptions options); |
|
121 | 122 | AnimationOptions animationOptions() const; |
|
122 | 123 | |
|
123 | 124 | void zoomIn(); |
|
124 | 125 | void zoomOut(); |
|
125 | 126 | |
|
126 | 127 | void zoomIn(const QRectF &rect); |
|
127 | 128 | void zoom(qreal factor); |
|
128 | 129 | |
|
129 | 130 | void scroll(qreal dx, qreal dy); |
|
130 | 131 | |
|
131 | 132 | QLegend *legend() const; |
|
132 | 133 | |
|
133 | 134 | void setMinimumMargins(const QMargins& margins); |
|
134 | 135 | QMargins minimumMargins() const; |
|
135 | 136 | |
|
136 | 137 | void setMargins(const QMargins &margins); |
|
137 | 138 | QMargins margins() const; |
|
138 | 139 | |
|
139 | 140 | QRectF plotArea() const; |
|
141 | void setPlotAreaBackgroundBrush(const QBrush &brush); | |
|
142 | QBrush plotAreaBackgroundBrush() const; | |
|
143 | void setPlotAreaBackgroundPen(const QPen &pen); | |
|
144 | QPen plotAreaBackgroundPen() const; | |
|
145 | void setPlotAreaBackgroundVisible(bool visible = true); | |
|
146 | bool isPlotAreaBackgroundVisible() const; | |
|
140 | 147 | |
|
141 | 148 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); |
|
142 | 149 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); |
|
143 | 150 | |
|
144 | 151 | ChartType chartType() const; |
|
145 | 152 | |
|
146 | 153 | protected: |
|
147 | 154 | explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags); |
|
148 | 155 | QScopedPointer<QChartPrivate> d_ptr; |
|
149 | 156 | friend class QLegend; |
|
150 | 157 | friend class DeclarativeChart; |
|
151 | 158 | friend class ChartDataSet; |
|
152 | 159 | friend class ChartPresenter; |
|
153 | 160 | friend class ChartThemeManager; |
|
154 | 161 | friend class QAbstractSeries; |
|
155 | 162 | Q_DISABLE_COPY(QChart) |
|
156 | 163 | }; |
|
157 | 164 | |
|
158 | 165 | QTCOMMERCIALCHART_END_NAMESPACE |
|
159 | 166 | |
|
160 | 167 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
161 | 168 | |
|
162 | 169 | #endif // QCHART_H |
@@ -1,909 +1,961 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 <QtTest/QtTest> |
|
22 | 22 | #include <qchartview.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <qareaseries.h> |
|
25 | 25 | #include <qscatterseries.h> |
|
26 | 26 | #include <qsplineseries.h> |
|
27 | 27 | #include <qpieseries.h> |
|
28 | 28 | #include <qabstractbarseries.h> |
|
29 | 29 | #include <qbarseries.h> |
|
30 | 30 | #include <qpercentbarseries.h> |
|
31 | 31 | #include <qstackedbarseries.h> |
|
32 | 32 | #include <qvalueaxis.h> |
|
33 | 33 | #include <qbarcategoryaxis.h> |
|
34 | 34 | #include "tst_definitions.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
39 | 39 | Q_DECLARE_METATYPE(QValueAxis *) |
|
40 | 40 | Q_DECLARE_METATYPE(QBarCategoryAxis *) |
|
41 | 41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
42 | 42 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
43 | 43 | Q_DECLARE_METATYPE(QBrush) |
|
44 | 44 | Q_DECLARE_METATYPE(QPen) |
|
45 | 45 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
46 | 46 | |
|
47 | 47 | class tst_QChart : public QObject |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | |
|
51 | 51 | public slots: |
|
52 | 52 | void initTestCase(); |
|
53 | 53 | void cleanupTestCase(); |
|
54 | 54 | void init(); |
|
55 | 55 | void cleanup(); |
|
56 | 56 | |
|
57 | 57 | private slots: |
|
58 | 58 | void qchart_data(); |
|
59 | 59 | void qchart(); |
|
60 | 60 | void addSeries_data(); |
|
61 | 61 | void addSeries(); |
|
62 | 62 | void animationOptions_data(); |
|
63 | 63 | void animationOptions(); |
|
64 | 64 | void axisX_data(); |
|
65 | 65 | void axisX(); |
|
66 | 66 | void axisY_data(); |
|
67 | 67 | void axisY(); |
|
68 | 68 | void backgroundBrush_data(); |
|
69 | 69 | void backgroundBrush(); |
|
70 | 70 | void backgroundPen_data(); |
|
71 | 71 | void backgroundPen(); |
|
72 | 72 | void isBackgroundVisible_data(); |
|
73 | 73 | void isBackgroundVisible(); |
|
74 | void plotAreaBackgroundBrush_data(); | |
|
75 | void plotAreaBackgroundBrush(); | |
|
76 | void plotAreaBackgroundPen_data(); | |
|
77 | void plotAreaBackgroundPen(); | |
|
78 | void isPlotAreaBackgroundVisible_data(); | |
|
79 | void isPlotAreaBackgroundVisible(); | |
|
74 | 80 | void legend_data(); |
|
75 | 81 | void legend(); |
|
76 | 82 | void plotArea_data(); |
|
77 | 83 | void plotArea(); |
|
78 | 84 | void removeAllSeries_data(); |
|
79 | 85 | void removeAllSeries(); |
|
80 | 86 | void removeSeries_data(); |
|
81 | 87 | void removeSeries(); |
|
82 | 88 | void scroll_right_data(); |
|
83 | 89 | void scroll_right(); |
|
84 | 90 | void scroll_left_data(); |
|
85 | 91 | void scroll_left(); |
|
86 | 92 | void scroll_up_data(); |
|
87 | 93 | void scroll_up(); |
|
88 | 94 | void scroll_down_data(); |
|
89 | 95 | void scroll_down(); |
|
90 | 96 | void theme_data(); |
|
91 | 97 | void theme(); |
|
92 | 98 | void title_data(); |
|
93 | 99 | void title(); |
|
94 | 100 | void titleBrush_data(); |
|
95 | 101 | void titleBrush(); |
|
96 | 102 | void titleFont_data(); |
|
97 | 103 | void titleFont(); |
|
98 | 104 | void zoomIn_data(); |
|
99 | 105 | void zoomIn(); |
|
100 | 106 | void zoomOut_data(); |
|
101 | 107 | void zoomOut(); |
|
102 | 108 | void createDefaultAxesForLineSeries_data(); |
|
103 | 109 | void createDefaultAxesForLineSeries(); |
|
104 | 110 | void axisPolarOrientation(); |
|
105 | 111 | private: |
|
106 | 112 | void createTestData(); |
|
107 | 113 | |
|
108 | 114 | private: |
|
109 | 115 | QChartView* m_view; |
|
110 | 116 | QChart* m_chart; |
|
111 | 117 | }; |
|
112 | 118 | |
|
113 | 119 | void tst_QChart::initTestCase() |
|
114 | 120 | { |
|
115 | 121 | |
|
116 | 122 | } |
|
117 | 123 | |
|
118 | 124 | void tst_QChart::cleanupTestCase() |
|
119 | 125 | { |
|
120 | 126 | |
|
121 | 127 | } |
|
122 | 128 | |
|
123 | 129 | void tst_QChart::init() |
|
124 | 130 | { |
|
125 | 131 | m_view = new QChartView(newQChartOrQPolarChart()); |
|
126 | 132 | m_chart = m_view->chart(); |
|
127 | 133 | } |
|
128 | 134 | |
|
129 | 135 | void tst_QChart::cleanup() |
|
130 | 136 | { |
|
131 | 137 | delete m_view; |
|
132 | 138 | m_view = 0; |
|
133 | 139 | m_chart = 0; |
|
134 | 140 | } |
|
135 | 141 | |
|
136 | 142 | |
|
137 | 143 | void tst_QChart::createTestData() |
|
138 | 144 | { |
|
139 | 145 | QLineSeries* series0 = new QLineSeries(this); |
|
140 | 146 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
141 | 147 | m_chart->addSeries(series0); |
|
142 | 148 | m_view->show(); |
|
143 | 149 | QTest::qWaitForWindowShown(m_view); |
|
144 | 150 | } |
|
145 | 151 | |
|
146 | 152 | void tst_QChart::qchart_data() |
|
147 | 153 | { |
|
148 | 154 | } |
|
149 | 155 | |
|
150 | 156 | void tst_QChart::qchart() |
|
151 | 157 | { |
|
152 | 158 | QVERIFY(m_chart); |
|
153 | 159 | QVERIFY(m_chart->legend()); |
|
154 | 160 | QVERIFY(m_chart->legend()->isVisible()); |
|
155 | 161 | |
|
156 | 162 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
157 | 163 | QVERIFY(!m_chart->axisX()); |
|
158 | 164 | QVERIFY(!m_chart->axisY()); |
|
159 | 165 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
160 | 166 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
161 | 167 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
162 | 168 | QVERIFY(m_chart->plotArea().top()==0); |
|
163 | 169 | QVERIFY(m_chart->plotArea().left()==0); |
|
164 | 170 | QVERIFY(m_chart->plotArea().right()==0); |
|
165 | 171 | QVERIFY(m_chart->plotArea().bottom()==0); |
|
166 | 172 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
167 | 173 | QCOMPARE(m_chart->title(), QString()); |
|
168 | 174 | |
|
169 | 175 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
170 | 176 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
171 | 177 | |
|
172 | 178 | m_chart->removeAllSeries(); |
|
173 | 179 | m_chart->scroll(0,0); |
|
174 | 180 | |
|
175 | 181 | m_chart->zoomIn(); |
|
176 | 182 | m_chart->zoomIn(QRectF()); |
|
177 | 183 | m_chart->zoomOut(); |
|
178 | 184 | |
|
179 | 185 | m_view->show(); |
|
180 | 186 | |
|
181 | 187 | QVERIFY(m_chart->plotArea().top()>0); |
|
182 | 188 | QVERIFY(m_chart->plotArea().left()>0); |
|
183 | 189 | QVERIFY(m_chart->plotArea().right()>0); |
|
184 | 190 | QVERIFY(m_chart->plotArea().bottom()>0); |
|
185 | 191 | } |
|
186 | 192 | |
|
187 | 193 | void tst_QChart::addSeries_data() |
|
188 | 194 | { |
|
189 | 195 | QTest::addColumn<QAbstractSeries *>("series"); |
|
190 | 196 | |
|
191 | 197 | QAbstractSeries* line = new QLineSeries(this); |
|
192 | 198 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
193 | 199 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
194 | 200 | QAbstractSeries* spline = new QSplineSeries(this); |
|
195 | 201 | |
|
196 | 202 | QTest::newRow("lineSeries") << line; |
|
197 | 203 | QTest::newRow("areaSeries") << area; |
|
198 | 204 | QTest::newRow("scatterSeries") << scatter; |
|
199 | 205 | QTest::newRow("splineSeries") << spline; |
|
200 | 206 | |
|
201 | 207 | if (!isPolarTest()) { |
|
202 | 208 | QAbstractSeries* pie = new QPieSeries(this); |
|
203 | 209 | QAbstractSeries* bar = new QBarSeries(this); |
|
204 | 210 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
205 | 211 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
206 | 212 | QTest::newRow("pieSeries") << pie; |
|
207 | 213 | QTest::newRow("barSeries") << bar; |
|
208 | 214 | QTest::newRow("percentBarSeries") << percent; |
|
209 | 215 | QTest::newRow("stackedBarSeries") << stacked; |
|
210 | 216 | } |
|
211 | 217 | } |
|
212 | 218 | |
|
213 | 219 | void tst_QChart::addSeries() |
|
214 | 220 | { |
|
215 | 221 | QFETCH(QAbstractSeries *, series); |
|
216 | 222 | m_view->show(); |
|
217 | 223 | QTest::qWaitForWindowShown(m_view); |
|
218 | 224 | QVERIFY(!series->chart()); |
|
219 | 225 | QCOMPARE(m_chart->series().count(), 0); |
|
220 | 226 | m_chart->addSeries(series); |
|
221 | 227 | QCOMPARE(m_chart->series().count(), 1); |
|
222 | 228 | QCOMPARE(m_chart->series().first(), series); |
|
223 | 229 | QVERIFY(series->chart() == m_chart); |
|
224 | 230 | m_chart->createDefaultAxes(); |
|
225 | 231 | if(series->type()!=QAbstractSeries::SeriesTypePie){ |
|
226 | 232 | QVERIFY(m_chart->axisY(series)); |
|
227 | 233 | QVERIFY(m_chart->axisX(series)); |
|
228 | 234 | }else{ |
|
229 | 235 | QVERIFY(!m_chart->axisY(series)); |
|
230 | 236 | QVERIFY(!m_chart->axisX(series)); |
|
231 | 237 | } |
|
232 | 238 | m_chart->removeSeries(series); |
|
233 | 239 | QVERIFY(!series->chart()); |
|
234 | 240 | QCOMPARE(m_chart->series().count(), 0); |
|
235 | 241 | } |
|
236 | 242 | |
|
237 | 243 | void tst_QChart::animationOptions_data() |
|
238 | 244 | { |
|
239 | 245 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
240 | 246 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
241 | 247 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
242 | 248 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
243 | 249 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
244 | 250 | } |
|
245 | 251 | |
|
246 | 252 | void tst_QChart::animationOptions() |
|
247 | 253 | { |
|
248 | 254 | createTestData(); |
|
249 | 255 | QFETCH(QChart::AnimationOption, animationOptions); |
|
250 | 256 | m_chart->setAnimationOptions(animationOptions); |
|
251 | 257 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
252 | 258 | } |
|
253 | 259 | |
|
254 | 260 | void tst_QChart::axisX_data() |
|
255 | 261 | { |
|
256 | 262 | |
|
257 | 263 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
258 | 264 | QTest::addColumn<QAbstractSeries *>("series"); |
|
259 | 265 | |
|
260 | 266 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
261 | 267 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
262 | 268 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
263 | 269 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
264 | 270 | if (!isPolarTest()) { |
|
265 | 271 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
266 | 272 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
267 | 273 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
268 | 274 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
269 | 275 | } |
|
270 | 276 | |
|
271 | 277 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
272 | 278 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
273 | 279 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
274 | 280 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
275 | 281 | if (!isPolarTest()) { |
|
276 | 282 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
277 | 283 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
278 | 284 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
279 | 285 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
280 | 286 | } |
|
281 | 287 | } |
|
282 | 288 | |
|
283 | 289 | void tst_QChart::axisX() |
|
284 | 290 | { |
|
285 | 291 | QFETCH(QAbstractAxis*, axis); |
|
286 | 292 | QFETCH(QAbstractSeries*, series); |
|
287 | 293 | QVERIFY(!m_chart->axisX()); |
|
288 | 294 | m_view->show(); |
|
289 | 295 | QTest::qWaitForWindowShown(m_view); |
|
290 | 296 | m_chart->addSeries(series); |
|
291 | 297 | m_chart->setAxisX(axis,series); |
|
292 | 298 | QVERIFY(m_chart->axisX(series)==axis); |
|
293 | 299 | } |
|
294 | 300 | |
|
295 | 301 | void tst_QChart::axisY_data() |
|
296 | 302 | { |
|
297 | 303 | axisX_data(); |
|
298 | 304 | } |
|
299 | 305 | |
|
300 | 306 | |
|
301 | 307 | void tst_QChart::axisY() |
|
302 | 308 | { |
|
303 | 309 | QFETCH(QAbstractAxis*, axis); |
|
304 | 310 | QFETCH(QAbstractSeries*, series); |
|
305 | 311 | QVERIFY(!m_chart->axisY()); |
|
306 | 312 | m_view->show(); |
|
307 | 313 | QTest::qWaitForWindowShown(m_view); |
|
308 | 314 | m_chart->addSeries(series); |
|
309 | 315 | m_chart->setAxisY(axis,series); |
|
310 | 316 | QVERIFY(m_chart->axisY(series)==axis); |
|
311 | 317 | } |
|
312 | 318 | |
|
313 | 319 | void tst_QChart::backgroundBrush_data() |
|
314 | 320 | { |
|
315 | 321 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
316 | 322 | QTest::newRow("null") << QBrush(); |
|
317 | 323 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
318 | 324 | QTest::newRow("white") << QBrush(Qt::white); |
|
319 | 325 | QTest::newRow("black") << QBrush(Qt::black); |
|
320 | 326 | } |
|
321 | 327 | |
|
322 | 328 | void tst_QChart::backgroundBrush() |
|
323 | 329 | { |
|
324 | 330 | QFETCH(QBrush, backgroundBrush); |
|
325 | 331 | m_chart->setBackgroundBrush(backgroundBrush); |
|
326 | 332 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
327 | 333 | } |
|
328 | 334 | |
|
329 | 335 | void tst_QChart::backgroundPen_data() |
|
330 | 336 | { |
|
331 | 337 | QTest::addColumn<QPen>("backgroundPen"); |
|
332 | 338 | QTest::newRow("null") << QPen(); |
|
333 | 339 | QTest::newRow("blue") << QPen(Qt::blue); |
|
334 | 340 | QTest::newRow("white") << QPen(Qt::white); |
|
335 | 341 | QTest::newRow("black") << QPen(Qt::black); |
|
336 | 342 | } |
|
337 | 343 | |
|
338 | 344 | |
|
339 | 345 | void tst_QChart::backgroundPen() |
|
340 | 346 | { |
|
341 | 347 | QFETCH(QPen, backgroundPen); |
|
342 | 348 | m_chart->setBackgroundPen(backgroundPen); |
|
343 | 349 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
344 | 350 | } |
|
345 | 351 | |
|
346 | 352 | void tst_QChart::isBackgroundVisible_data() |
|
347 | 353 | { |
|
348 | 354 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
349 | 355 | QTest::newRow("true") << true; |
|
350 | 356 | QTest::newRow("false") << false; |
|
351 | 357 | } |
|
352 | 358 | |
|
353 | 359 | void tst_QChart::isBackgroundVisible() |
|
354 | 360 | { |
|
355 | 361 | QFETCH(bool, isBackgroundVisible); |
|
356 | 362 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
357 | 363 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
358 | 364 | } |
|
359 | 365 | |
|
366 | void tst_QChart::plotAreaBackgroundBrush_data() | |
|
367 | { | |
|
368 | QTest::addColumn<QBrush>("plotAreaBackgroundBrush"); | |
|
369 | QTest::newRow("null") << QBrush(); | |
|
370 | QTest::newRow("blue") << QBrush(Qt::blue); | |
|
371 | QTest::newRow("white") << QBrush(Qt::white); | |
|
372 | QTest::newRow("black") << QBrush(Qt::black); | |
|
373 | } | |
|
374 | ||
|
375 | void tst_QChart::plotAreaBackgroundBrush() | |
|
376 | { | |
|
377 | QFETCH(QBrush, plotAreaBackgroundBrush); | |
|
378 | m_chart->setPlotAreaBackgroundBrush(plotAreaBackgroundBrush); | |
|
379 | QCOMPARE(m_chart->plotAreaBackgroundBrush(), plotAreaBackgroundBrush); | |
|
380 | } | |
|
381 | ||
|
382 | void tst_QChart::plotAreaBackgroundPen_data() | |
|
383 | { | |
|
384 | QTest::addColumn<QPen>("plotAreaBackgroundPen"); | |
|
385 | QTest::newRow("null") << QPen(); | |
|
386 | QTest::newRow("blue") << QPen(Qt::blue); | |
|
387 | QTest::newRow("white") << QPen(Qt::white); | |
|
388 | QTest::newRow("black") << QPen(Qt::black); | |
|
389 | } | |
|
390 | ||
|
391 | ||
|
392 | void tst_QChart::plotAreaBackgroundPen() | |
|
393 | { | |
|
394 | QFETCH(QPen, plotAreaBackgroundPen); | |
|
395 | m_chart->setPlotAreaBackgroundPen(plotAreaBackgroundPen); | |
|
396 | QCOMPARE(m_chart->plotAreaBackgroundPen(), plotAreaBackgroundPen); | |
|
397 | } | |
|
398 | ||
|
399 | void tst_QChart::isPlotAreaBackgroundVisible_data() | |
|
400 | { | |
|
401 | QTest::addColumn<bool>("isPlotAreaBackgroundVisible"); | |
|
402 | QTest::newRow("true") << true; | |
|
403 | QTest::newRow("false") << false; | |
|
404 | } | |
|
405 | ||
|
406 | void tst_QChart::isPlotAreaBackgroundVisible() | |
|
407 | { | |
|
408 | QFETCH(bool, isPlotAreaBackgroundVisible); | |
|
409 | m_chart->setPlotAreaBackgroundVisible(isPlotAreaBackgroundVisible); | |
|
410 | QCOMPARE(m_chart->isPlotAreaBackgroundVisible(), isPlotAreaBackgroundVisible); | |
|
411 | } | |
|
360 | 412 | void tst_QChart::legend_data() |
|
361 | 413 | { |
|
362 | 414 | |
|
363 | 415 | } |
|
364 | 416 | |
|
365 | 417 | void tst_QChart::legend() |
|
366 | 418 | { |
|
367 | 419 | QLegend *legend = m_chart->legend(); |
|
368 | 420 | QVERIFY(legend); |
|
369 | 421 | |
|
370 | 422 | // Colors related signals |
|
371 | 423 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
372 | 424 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
373 | 425 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
374 | 426 | |
|
375 | 427 | // colorChanged |
|
376 | 428 | legend->setColor(QColor("aliceblue")); |
|
377 | 429 | QCOMPARE(colorSpy.count(), 1); |
|
378 | 430 | QBrush b = legend->brush(); |
|
379 | 431 | b.setColor(QColor("aqua")); |
|
380 | 432 | legend->setBrush(b); |
|
381 | 433 | QCOMPARE(colorSpy.count(), 2); |
|
382 | 434 | |
|
383 | 435 | // borderColorChanged |
|
384 | 436 | legend->setBorderColor(QColor("aliceblue")); |
|
385 | 437 | QCOMPARE(borderColorSpy.count(), 1); |
|
386 | 438 | QPen p = legend->pen(); |
|
387 | 439 | p.setColor(QColor("aqua")); |
|
388 | 440 | legend->setPen(p); |
|
389 | 441 | QCOMPARE(borderColorSpy.count(), 2); |
|
390 | 442 | |
|
391 | 443 | // labelColorChanged |
|
392 | 444 | legend->setLabelColor(QColor("lightsalmon")); |
|
393 | 445 | QCOMPARE(labelColorSpy.count(), 1); |
|
394 | 446 | b = legend->labelBrush(); |
|
395 | 447 | b.setColor(QColor("lightseagreen")); |
|
396 | 448 | legend->setLabelBrush(b); |
|
397 | 449 | QCOMPARE(labelColorSpy.count(), 2); |
|
398 | 450 | |
|
399 | 451 | // fontChanged |
|
400 | 452 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
401 | 453 | QFont f = legend->font(); |
|
402 | 454 | f.setBold(!f.bold()); |
|
403 | 455 | legend->setFont(f); |
|
404 | 456 | QCOMPARE(fontSpy.count(), 1); |
|
405 | 457 | } |
|
406 | 458 | |
|
407 | 459 | void tst_QChart::plotArea_data() |
|
408 | 460 | { |
|
409 | 461 | |
|
410 | 462 | } |
|
411 | 463 | |
|
412 | 464 | void tst_QChart::plotArea() |
|
413 | 465 | { |
|
414 | 466 | createTestData(); |
|
415 | 467 | QRectF rect = m_chart->geometry(); |
|
416 | 468 | QVERIFY(m_chart->plotArea().isValid()); |
|
417 | 469 | QVERIFY(m_chart->plotArea().height() < rect.height()); |
|
418 | 470 | QVERIFY(m_chart->plotArea().width() < rect.width()); |
|
419 | 471 | } |
|
420 | 472 | |
|
421 | 473 | void tst_QChart::removeAllSeries_data() |
|
422 | 474 | { |
|
423 | 475 | |
|
424 | 476 | } |
|
425 | 477 | |
|
426 | 478 | void tst_QChart::removeAllSeries() |
|
427 | 479 | { |
|
428 | 480 | QLineSeries* series0 = new QLineSeries(this); |
|
429 | 481 | QLineSeries* series1 = new QLineSeries(this); |
|
430 | 482 | QLineSeries* series2 = new QLineSeries(this); |
|
431 | 483 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
432 | 484 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
433 | 485 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
434 | 486 | |
|
435 | 487 | m_chart->addSeries(series0); |
|
436 | 488 | m_chart->addSeries(series1); |
|
437 | 489 | m_chart->addSeries(series2); |
|
438 | 490 | m_view->show(); |
|
439 | 491 | QTest::qWaitForWindowShown(m_view); |
|
440 | 492 | m_chart->createDefaultAxes(); |
|
441 | 493 | QCOMPARE(m_chart->axes().count(), 2); |
|
442 | 494 | QVERIFY(m_chart->axisY(series0)!=0); |
|
443 | 495 | QVERIFY(m_chart->axisY(series1)!=0); |
|
444 | 496 | QVERIFY(m_chart->axisY(series2)!=0); |
|
445 | 497 | |
|
446 | 498 | m_chart->removeAllSeries(); |
|
447 | 499 | QCOMPARE(m_chart->axes().count(), 2); |
|
448 | 500 | QVERIFY(m_chart->axisX() != 0); |
|
449 | 501 | QVERIFY(m_chart->axisY() != 0); |
|
450 | 502 | QCOMPARE(deleteSpy1.count(), 1); |
|
451 | 503 | QCOMPARE(deleteSpy2.count(), 1); |
|
452 | 504 | QCOMPARE(deleteSpy3.count(), 1); |
|
453 | 505 | } |
|
454 | 506 | |
|
455 | 507 | void tst_QChart::removeSeries_data() |
|
456 | 508 | { |
|
457 | 509 | axisX_data(); |
|
458 | 510 | } |
|
459 | 511 | |
|
460 | 512 | void tst_QChart::removeSeries() |
|
461 | 513 | { |
|
462 | 514 | QFETCH(QAbstractAxis *, axis); |
|
463 | 515 | QFETCH(QAbstractSeries *, series); |
|
464 | 516 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
465 | 517 | m_view->show(); |
|
466 | 518 | QTest::qWaitForWindowShown(m_view); |
|
467 | 519 | if(!axis) axis = m_chart->axisY(); |
|
468 | 520 | m_chart->addSeries(series); |
|
469 | 521 | m_chart->setAxisY(axis,series); |
|
470 | 522 | QCOMPARE(m_chart->axisY(series),axis); |
|
471 | 523 | m_chart->removeSeries(series); |
|
472 | 524 | QCOMPARE(m_chart->axes().count(), 1); |
|
473 | 525 | QVERIFY(m_chart->axisY() != 0); |
|
474 | 526 | QVERIFY(m_chart->axisY(series)==0); |
|
475 | 527 | QCOMPARE(deleteSpy.count(), 0); |
|
476 | 528 | } |
|
477 | 529 | |
|
478 | 530 | void tst_QChart::scroll_right_data() |
|
479 | 531 | { |
|
480 | 532 | QTest::addColumn<QAbstractSeries *>("series"); |
|
481 | 533 | |
|
482 | 534 | QLineSeries* series0 = new QLineSeries(this); |
|
483 | 535 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
484 | 536 | |
|
485 | 537 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; |
|
486 | 538 | |
|
487 | 539 | |
|
488 | 540 | } |
|
489 | 541 | |
|
490 | 542 | void tst_QChart::scroll_right() |
|
491 | 543 | { |
|
492 | 544 | QFETCH(QAbstractSeries *, series); |
|
493 | 545 | m_chart->addSeries(series); |
|
494 | 546 | m_chart->createDefaultAxes(); |
|
495 | 547 | m_view->show(); |
|
496 | 548 | QTest::qWaitForWindowShown(m_view); |
|
497 | 549 | QAbstractAxis * axis = m_chart->axisX(); |
|
498 | 550 | QVERIFY(axis!=0); |
|
499 | 551 | |
|
500 | 552 | switch(axis->type()) |
|
501 | 553 | { |
|
502 | 554 | case QAbstractAxis::AxisTypeValue:{ |
|
503 | 555 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
504 | 556 | QVERIFY(vaxis!=0); |
|
505 | 557 | qreal min = vaxis->min(); |
|
506 | 558 | qreal max = vaxis->max(); |
|
507 | 559 | QVERIFY(max>min); |
|
508 | 560 | m_chart->scroll(50, 0); |
|
509 | 561 | QVERIFY(min<vaxis->min()); |
|
510 | 562 | QVERIFY(max<vaxis->max()); |
|
511 | 563 | break; |
|
512 | 564 | } |
|
513 | 565 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
514 | 566 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
515 | 567 | QVERIFY(caxis!=0); |
|
516 | 568 | qreal min = caxis->min().toDouble(); |
|
517 | 569 | qreal max = caxis->max().toDouble(); |
|
518 | 570 | m_chart->scroll(50, 0); |
|
519 | 571 | QVERIFY(min<caxis->min().toDouble()); |
|
520 | 572 | QVERIFY(max<caxis->max().toDouble()); |
|
521 | 573 | break; |
|
522 | 574 | } |
|
523 | 575 | default: |
|
524 | 576 | qFatal("Unsupported type"); |
|
525 | 577 | break; |
|
526 | 578 | } |
|
527 | 579 | } |
|
528 | 580 | |
|
529 | 581 | void tst_QChart::scroll_left_data() |
|
530 | 582 | { |
|
531 | 583 | scroll_right_data(); |
|
532 | 584 | } |
|
533 | 585 | |
|
534 | 586 | void tst_QChart::scroll_left() |
|
535 | 587 | { |
|
536 | 588 | QFETCH(QAbstractSeries *, series); |
|
537 | 589 | m_chart->addSeries(series); |
|
538 | 590 | m_chart->createDefaultAxes(); |
|
539 | 591 | m_view->show(); |
|
540 | 592 | QTest::qWaitForWindowShown(m_view); |
|
541 | 593 | QAbstractAxis * axis = m_chart->axisX(); |
|
542 | 594 | QVERIFY(axis!=0); |
|
543 | 595 | |
|
544 | 596 | switch(axis->type()) |
|
545 | 597 | { |
|
546 | 598 | case QAbstractAxis::AxisTypeValue:{ |
|
547 | 599 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
548 | 600 | QVERIFY(vaxis!=0); |
|
549 | 601 | qreal min = vaxis->min(); |
|
550 | 602 | qreal max = vaxis->max(); |
|
551 | 603 | m_chart->scroll(-50, 0); |
|
552 | 604 | QVERIFY(min>vaxis->min()); |
|
553 | 605 | QVERIFY(max>vaxis->max()); |
|
554 | 606 | break; |
|
555 | 607 | } |
|
556 | 608 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
557 | 609 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
558 | 610 | QVERIFY(caxis!=0); |
|
559 | 611 | qreal min = caxis->min().toDouble(); |
|
560 | 612 | qreal max = caxis->max().toDouble(); |
|
561 | 613 | m_chart->scroll(-50, 0); |
|
562 | 614 | QVERIFY(min>caxis->min().toDouble()); |
|
563 | 615 | QVERIFY(max>caxis->max().toDouble()); |
|
564 | 616 | break; |
|
565 | 617 | } |
|
566 | 618 | default: |
|
567 | 619 | qFatal("Unsupported type"); |
|
568 | 620 | break; |
|
569 | 621 | } |
|
570 | 622 | } |
|
571 | 623 | |
|
572 | 624 | void tst_QChart::scroll_up_data() |
|
573 | 625 | { |
|
574 | 626 | scroll_right_data(); |
|
575 | 627 | } |
|
576 | 628 | |
|
577 | 629 | void tst_QChart::scroll_up() |
|
578 | 630 | { |
|
579 | 631 | QFETCH(QAbstractSeries *, series); |
|
580 | 632 | m_chart->addSeries(series); |
|
581 | 633 | m_chart->createDefaultAxes(); |
|
582 | 634 | m_view->show(); |
|
583 | 635 | QTest::qWaitForWindowShown(m_view); |
|
584 | 636 | QAbstractAxis * axis = m_chart->axisY(); |
|
585 | 637 | QVERIFY(axis!=0); |
|
586 | 638 | |
|
587 | 639 | switch(axis->type()) |
|
588 | 640 | { |
|
589 | 641 | case QAbstractAxis::AxisTypeValue:{ |
|
590 | 642 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
591 | 643 | QVERIFY(vaxis!=0); |
|
592 | 644 | qreal min = vaxis->min(); |
|
593 | 645 | qreal max = vaxis->max(); |
|
594 | 646 | m_chart->scroll(0, 50); |
|
595 | 647 | QVERIFY(min<vaxis->min()); |
|
596 | 648 | QVERIFY(max<vaxis->max()); |
|
597 | 649 | break; |
|
598 | 650 | } |
|
599 | 651 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
600 | 652 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
601 | 653 | QVERIFY(caxis!=0); |
|
602 | 654 | qreal min = caxis->min().toDouble(); |
|
603 | 655 | qreal max = caxis->max().toDouble(); |
|
604 | 656 | m_chart->scroll(0, 50); |
|
605 | 657 | QVERIFY(min<caxis->min().toDouble()); |
|
606 | 658 | QVERIFY(max<caxis->max().toDouble()); |
|
607 | 659 | break; |
|
608 | 660 | } |
|
609 | 661 | default: |
|
610 | 662 | qFatal("Unsupported type"); |
|
611 | 663 | break; |
|
612 | 664 | } |
|
613 | 665 | } |
|
614 | 666 | |
|
615 | 667 | void tst_QChart::scroll_down_data() |
|
616 | 668 | { |
|
617 | 669 | scroll_right_data(); |
|
618 | 670 | } |
|
619 | 671 | |
|
620 | 672 | void tst_QChart::scroll_down() |
|
621 | 673 | { |
|
622 | 674 | QFETCH(QAbstractSeries *, series); |
|
623 | 675 | m_chart->addSeries(series); |
|
624 | 676 | m_chart->createDefaultAxes(); |
|
625 | 677 | m_view->show(); |
|
626 | 678 | QTest::qWaitForWindowShown(m_view); |
|
627 | 679 | QAbstractAxis * axis = m_chart->axisY(); |
|
628 | 680 | QVERIFY(axis!=0); |
|
629 | 681 | |
|
630 | 682 | switch(axis->type()) |
|
631 | 683 | { |
|
632 | 684 | case QAbstractAxis::AxisTypeValue:{ |
|
633 | 685 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
634 | 686 | QVERIFY(vaxis!=0); |
|
635 | 687 | qreal min = vaxis->min(); |
|
636 | 688 | qreal max = vaxis->max(); |
|
637 | 689 | m_chart->scroll(0, -50); |
|
638 | 690 | QVERIFY(min>vaxis->min()); |
|
639 | 691 | QVERIFY(max>vaxis->max()); |
|
640 | 692 | break; |
|
641 | 693 | } |
|
642 | 694 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
643 | 695 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
644 | 696 | QVERIFY(caxis!=0); |
|
645 | 697 | qreal min = caxis->min().toDouble(); |
|
646 | 698 | qreal max = caxis->max().toDouble(); |
|
647 | 699 | m_chart->scroll(0, -50); |
|
648 | 700 | QVERIFY(min>caxis->min().toDouble()); |
|
649 | 701 | QVERIFY(max>caxis->max().toDouble()); |
|
650 | 702 | break; |
|
651 | 703 | } |
|
652 | 704 | default: |
|
653 | 705 | qFatal("Unsupported type"); |
|
654 | 706 | break; |
|
655 | 707 | } |
|
656 | 708 | } |
|
657 | 709 | |
|
658 | 710 | void tst_QChart::theme_data() |
|
659 | 711 | { |
|
660 | 712 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
661 | 713 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
662 | 714 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
663 | 715 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
664 | 716 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
665 | 717 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
666 | 718 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
667 | 719 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
668 | 720 | } |
|
669 | 721 | |
|
670 | 722 | void tst_QChart::theme() |
|
671 | 723 | { |
|
672 | 724 | QFETCH(QChart::ChartTheme, theme); |
|
673 | 725 | createTestData(); |
|
674 | 726 | m_chart->setTheme(theme); |
|
675 | 727 | QVERIFY(m_chart->theme()==theme); |
|
676 | 728 | } |
|
677 | 729 | |
|
678 | 730 | void tst_QChart::title_data() |
|
679 | 731 | { |
|
680 | 732 | QTest::addColumn<QString>("title"); |
|
681 | 733 | QTest::newRow("null") << QString(); |
|
682 | 734 | QTest::newRow("foo") << QString("foo"); |
|
683 | 735 | } |
|
684 | 736 | |
|
685 | 737 | void tst_QChart::title() |
|
686 | 738 | { |
|
687 | 739 | QFETCH(QString, title); |
|
688 | 740 | m_chart->setTitle(title); |
|
689 | 741 | QCOMPARE(m_chart->title(), title); |
|
690 | 742 | } |
|
691 | 743 | |
|
692 | 744 | void tst_QChart::titleBrush_data() |
|
693 | 745 | { |
|
694 | 746 | QTest::addColumn<QBrush>("titleBrush"); |
|
695 | 747 | QTest::newRow("null") << QBrush(); |
|
696 | 748 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
697 | 749 | QTest::newRow("white") << QBrush(Qt::white); |
|
698 | 750 | QTest::newRow("black") << QBrush(Qt::black); |
|
699 | 751 | } |
|
700 | 752 | |
|
701 | 753 | void tst_QChart::titleBrush() |
|
702 | 754 | { |
|
703 | 755 | QFETCH(QBrush, titleBrush); |
|
704 | 756 | m_chart->setTitleBrush(titleBrush); |
|
705 | 757 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
706 | 758 | } |
|
707 | 759 | |
|
708 | 760 | void tst_QChart::titleFont_data() |
|
709 | 761 | { |
|
710 | 762 | QTest::addColumn<QFont>("titleFont"); |
|
711 | 763 | QTest::newRow("null") << QFont(); |
|
712 | 764 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
713 | 765 | } |
|
714 | 766 | |
|
715 | 767 | void tst_QChart::titleFont() |
|
716 | 768 | { |
|
717 | 769 | QFETCH(QFont, titleFont); |
|
718 | 770 | m_chart->setTitleFont(titleFont); |
|
719 | 771 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
720 | 772 | } |
|
721 | 773 | |
|
722 | 774 | void tst_QChart::zoomIn_data() |
|
723 | 775 | { |
|
724 | 776 | QTest::addColumn<QRectF>("rect"); |
|
725 | 777 | QTest::newRow("null") << QRectF(); |
|
726 | 778 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
727 | 779 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
728 | 780 | } |
|
729 | 781 | |
|
730 | 782 | |
|
731 | 783 | void tst_QChart::zoomIn() |
|
732 | 784 | { |
|
733 | 785 | |
|
734 | 786 | QFETCH(QRectF, rect); |
|
735 | 787 | createTestData(); |
|
736 | 788 | m_chart->createDefaultAxes(); |
|
737 | 789 | QRectF marigns = m_chart->plotArea(); |
|
738 | 790 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
739 | 791 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
740 | 792 | QVERIFY(axisX!=0); |
|
741 | 793 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
742 | 794 | QVERIFY(axisY!=0); |
|
743 | 795 | qreal minX = axisX->min(); |
|
744 | 796 | qreal minY = axisY->min(); |
|
745 | 797 | qreal maxX = axisX->max(); |
|
746 | 798 | qreal maxY = axisY->max(); |
|
747 | 799 | m_chart->zoomIn(rect); |
|
748 | 800 | if(rect.isValid()){ |
|
749 | 801 | QVERIFY(minX<axisX->min()); |
|
750 | 802 | QVERIFY(maxX>axisX->max()); |
|
751 | 803 | QVERIFY(minY<axisY->min()); |
|
752 | 804 | QVERIFY(maxY>axisY->max()); |
|
753 | 805 | } |
|
754 | 806 | |
|
755 | 807 | } |
|
756 | 808 | |
|
757 | 809 | void tst_QChart::zoomOut_data() |
|
758 | 810 | { |
|
759 | 811 | |
|
760 | 812 | } |
|
761 | 813 | |
|
762 | 814 | void tst_QChart::zoomOut() |
|
763 | 815 | { |
|
764 | 816 | createTestData(); |
|
765 | 817 | m_chart->createDefaultAxes(); |
|
766 | 818 | |
|
767 | 819 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
768 | 820 | QVERIFY(axisX!=0); |
|
769 | 821 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
770 | 822 | QVERIFY(axisY!=0); |
|
771 | 823 | |
|
772 | 824 | qreal minX = axisX->min(); |
|
773 | 825 | qreal minY = axisY->min(); |
|
774 | 826 | qreal maxX = axisX->max(); |
|
775 | 827 | qreal maxY = axisY->max(); |
|
776 | 828 | |
|
777 | 829 | m_chart->zoomIn(); |
|
778 | 830 | |
|
779 | 831 | QVERIFY(minX < axisX->min()); |
|
780 | 832 | QVERIFY(maxX > axisX->max()); |
|
781 | 833 | QVERIFY(minY < axisY->min()); |
|
782 | 834 | QVERIFY(maxY > axisY->max()); |
|
783 | 835 | |
|
784 | 836 | m_chart->zoomOut(); |
|
785 | 837 | |
|
786 | 838 | // min x may be a zero value |
|
787 | 839 | if (qFuzzyIsNull(minX)) |
|
788 | 840 | QVERIFY(qFuzzyIsNull(axisX->min())); |
|
789 | 841 | else |
|
790 | 842 | QCOMPARE(minX, axisX->min()); |
|
791 | 843 | |
|
792 | 844 | // min y may be a zero value |
|
793 | 845 | if (qFuzzyIsNull(minY)) |
|
794 | 846 | QVERIFY(qFuzzyIsNull(axisY->min())); |
|
795 | 847 | else |
|
796 | 848 | QCOMPARE(minY, axisY->min()); |
|
797 | 849 | |
|
798 | 850 | QVERIFY(maxX == axisX->max()); |
|
799 | 851 | QVERIFY(maxY == axisY->max()); |
|
800 | 852 | |
|
801 | 853 | } |
|
802 | 854 | |
|
803 | 855 | void tst_QChart::createDefaultAxesForLineSeries_data() |
|
804 | 856 | { |
|
805 | 857 | QTest::addColumn<qreal>("series1minX"); |
|
806 | 858 | QTest::addColumn<qreal>("series1midX"); |
|
807 | 859 | QTest::addColumn<qreal>("series1maxX"); |
|
808 | 860 | QTest::addColumn<qreal>("series2minX"); |
|
809 | 861 | QTest::addColumn<qreal>("series2midX"); |
|
810 | 862 | QTest::addColumn<qreal>("series2maxX"); |
|
811 | 863 | QTest::addColumn<qreal>("overallminX"); |
|
812 | 864 | QTest::addColumn<qreal>("overallmaxX"); |
|
813 | 865 | QTest::addColumn<qreal>("series1minY"); |
|
814 | 866 | QTest::addColumn<qreal>("series1midY"); |
|
815 | 867 | QTest::addColumn<qreal>("series1maxY"); |
|
816 | 868 | QTest::addColumn<qreal>("series2minY"); |
|
817 | 869 | QTest::addColumn<qreal>("series2midY"); |
|
818 | 870 | QTest::addColumn<qreal>("series2maxY"); |
|
819 | 871 | QTest::addColumn<qreal>("overallminY"); |
|
820 | 872 | QTest::addColumn<qreal>("overallmaxY"); |
|
821 | 873 | QTest::newRow("series1hasMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 |
|
822 | 874 | << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0; |
|
823 | 875 | QTest::newRow("series2hasMinAndMax") << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
824 | 876 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
825 | 877 | QTest::newRow("series1hasMinAndMaxX_series2hasMinAndMaxY") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 |
|
826 | 878 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
827 | 879 | QTest::newRow("series1hasMin_series2hasMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
828 | 880 | << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; |
|
829 | 881 | QTest::newRow("bothSeriesHaveSameMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 |
|
830 | 882 | << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)1.1 << (qreal)0.6 << (qreal)1.6; |
|
831 | 883 | } |
|
832 | 884 | |
|
833 | 885 | void tst_QChart::createDefaultAxesForLineSeries() |
|
834 | 886 | { |
|
835 | 887 | QFETCH(qreal, series1minX); |
|
836 | 888 | QFETCH(qreal, series1midX); |
|
837 | 889 | QFETCH(qreal, series1maxX); |
|
838 | 890 | QFETCH(qreal, series2minX); |
|
839 | 891 | QFETCH(qreal, series2midX); |
|
840 | 892 | QFETCH(qreal, series2maxX); |
|
841 | 893 | QFETCH(qreal, series1minY); |
|
842 | 894 | QFETCH(qreal, series1midY); |
|
843 | 895 | QFETCH(qreal, series1maxY); |
|
844 | 896 | QFETCH(qreal, series2minY); |
|
845 | 897 | QFETCH(qreal, series2midY); |
|
846 | 898 | QFETCH(qreal, series2maxY); |
|
847 | 899 | QFETCH(qreal, overallminX); |
|
848 | 900 | QFETCH(qreal, overallmaxX); |
|
849 | 901 | QFETCH(qreal, overallminY); |
|
850 | 902 | QFETCH(qreal, overallmaxY); |
|
851 | 903 | QLineSeries* series1 = new QLineSeries(this); |
|
852 | 904 | series1->append(series1minX, series1minY); |
|
853 | 905 | series1->append(series1midX, series1midY); |
|
854 | 906 | series1->append(series1maxX, series1maxY); |
|
855 | 907 | QLineSeries* series2 = new QLineSeries(this); |
|
856 | 908 | series2->append(series2minX, series2minY); |
|
857 | 909 | series2->append(series2midX, series2midY); |
|
858 | 910 | series2->append(series2maxX, series2maxY); |
|
859 | 911 | QChart *chart = newQChartOrQPolarChart(); |
|
860 | 912 | chart->addSeries(series1); |
|
861 | 913 | chart->addSeries(series2); |
|
862 | 914 | chart->createDefaultAxes(); |
|
863 | 915 | QValueAxis *xAxis = (QValueAxis *)chart->axisX(); |
|
864 | 916 | QCOMPARE(xAxis->min(), overallminX); |
|
865 | 917 | QCOMPARE(xAxis->max(), overallmaxX); |
|
866 | 918 | QValueAxis *yAxis = (QValueAxis *)chart->axisY(); |
|
867 | 919 | QCOMPARE(yAxis->min(), overallminY); |
|
868 | 920 | QCOMPARE(yAxis->max(), overallmaxY); |
|
869 | 921 | QLineSeries *series3 = new QLineSeries(this); |
|
870 | 922 | // Numbers clearly out of existing range |
|
871 | 923 | series3->append(0, 0); |
|
872 | 924 | series3->append(100, 100); |
|
873 | 925 | // Adding a new series should not change the axes as they have not been told to update |
|
874 | 926 | chart->addSeries(series3); |
|
875 | 927 | QCOMPARE(xAxis->min(), overallminX); |
|
876 | 928 | QCOMPARE(xAxis->max(), overallmaxX); |
|
877 | 929 | QCOMPARE(yAxis->min(), overallminY); |
|
878 | 930 | QCOMPARE(yAxis->max(), overallmaxY); |
|
879 | 931 | } |
|
880 | 932 | |
|
881 | 933 | void tst_QChart::axisPolarOrientation() |
|
882 | 934 | { |
|
883 | 935 | QLineSeries* series1 = new QLineSeries(this); |
|
884 | 936 | series1->append(1, 2); |
|
885 | 937 | series1->append(2, 4); |
|
886 | 938 | series1->append(3, 8); |
|
887 | 939 | QPolarChart chart; |
|
888 | 940 | chart.addSeries(series1); |
|
889 | 941 | |
|
890 | 942 | QValueAxis *xAxis = new QValueAxis(); |
|
891 | 943 | QValueAxis *yAxis = new QValueAxis(); |
|
892 | 944 | chart.addAxis(xAxis, QPolarChart::PolarOrientationAngular); |
|
893 | 945 | chart.addAxis(yAxis, QPolarChart::PolarOrientationRadial); |
|
894 | 946 | |
|
895 | 947 | QList<QAbstractAxis *> xAxes = chart.axes(QPolarChart::PolarOrientationAngular); |
|
896 | 948 | QList<QAbstractAxis *> yAxes = chart.axes(QPolarChart::PolarOrientationRadial); |
|
897 | 949 | |
|
898 | 950 | QCOMPARE(xAxes.size(), 1); |
|
899 | 951 | QCOMPARE(yAxes.size(), 1); |
|
900 | 952 | QCOMPARE(xAxes[0], xAxis); |
|
901 | 953 | QCOMPARE(yAxes[0], yAxis); |
|
902 | 954 | |
|
903 | 955 | QCOMPARE(chart.axisPolarOrientation(xAxes[0]), QPolarChart::PolarOrientationAngular); |
|
904 | 956 | QCOMPARE(chart.axisPolarOrientation(yAxes[0]), QPolarChart::PolarOrientationRadial); |
|
905 | 957 | } |
|
906 | 958 | |
|
907 | 959 | QTEST_MAIN(tst_QChart) |
|
908 | 960 | #include "tst_qchart.moc" |
|
909 | 961 |
@@ -1,1136 +1,1199 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 "mainwindow.h" |
|
22 | 22 | #include "chartview.h" |
|
23 | 23 | #include <QScatterSeries> |
|
24 | 24 | #include <QLineSeries> |
|
25 | 25 | #include <QSplineSeries> |
|
26 | 26 | #include <QAreaSeries> |
|
27 | 27 | #include <QBarSeries> |
|
28 | 28 | #include <QBarSet> |
|
29 | 29 | #include <QValueAxis> |
|
30 | 30 | #include <QLogValueAxis> |
|
31 | 31 | #include <QDateTimeAxis> |
|
32 | 32 | #include <QCategoryAxis> |
|
33 | 33 | #include <QPolarChart> |
|
34 | 34 | #include <QDebug> |
|
35 | 35 | #include <qmath.h> |
|
36 | 36 | #include <QDateTime> |
|
37 | 37 | |
|
38 | 38 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
39 | 39 | #include "ui_mainwindow.h" |
|
40 | 40 | |
|
41 | 41 | MainWindow::MainWindow(QWidget *parent) : |
|
42 | 42 | QMainWindow(parent), |
|
43 | 43 | ui(new Ui::MainWindow), |
|
44 | 44 | m_angularTickCount(9), |
|
45 | 45 | m_radialTickCount(11), |
|
46 | 46 | m_labelsAngle(0), |
|
47 | 47 | m_angularMin(0.0), |
|
48 | 48 | m_angularMax(40000.0), |
|
49 | 49 | m_radialMin(0.0), |
|
50 | 50 | m_radialMax(30000.0), |
|
51 | 51 | m_angularShadesVisible(false), |
|
52 | 52 | m_radialShadesVisible(false), |
|
53 | 53 | m_labelsVisible(true), |
|
54 | 54 | m_titleVisible(true), |
|
55 | 55 | m_gridVisible(true), |
|
56 | 56 | m_arrowVisible(true), |
|
57 | 57 | m_angularShadesBrush(new QBrush(Qt::NoBrush)), |
|
58 | 58 | m_radialShadesBrush(new QBrush(Qt::NoBrush)), |
|
59 | 59 | m_labelBrush(new QBrush(Qt::black)), |
|
60 | 60 | m_titleBrush(new QBrush(Qt::black)), |
|
61 | m_backgroundBrush(new QBrush(Qt::white)), | |
|
62 | m_plotAreaBackgroundBrush(new QBrush(Qt::NoBrush)), | |
|
61 | 63 | m_angularShadesPen(new QPen(Qt::NoPen)), |
|
62 | 64 | m_radialShadesPen(new QPen(Qt::NoPen)), |
|
63 | 65 | m_labelPen(new QPen(Qt::NoPen)), |
|
64 | 66 | m_titlePen(new QPen(Qt::NoPen)), |
|
65 | 67 | m_gridPen(new QPen(QRgb(0x010101))), // Note: Pure black is default color, so it gets overridden by |
|
66 | 68 | m_arrowPen(new QPen(QRgb(0x010101))), // default theme if set to that initially. This is an example of workaround. |
|
69 | m_backgroundPen(new QPen(Qt::NoPen)), | |
|
70 | m_plotAreaBackgroundPen(new QPen(Qt::NoPen)), | |
|
67 | 71 | m_labelFormat(QString("%.2f")), |
|
68 | 72 | m_animationOptions(QChart::NoAnimation), |
|
69 | 73 | m_angularTitle(QString("Angular Title")), |
|
70 | 74 | m_radialTitle(QString("Radial Title")), |
|
71 | 75 | m_base(2.0), |
|
72 | 76 | m_chart(0), |
|
73 | 77 | m_angularAxis(0), |
|
74 | 78 | m_radialAxis(0), |
|
75 | 79 | m_angularAxisMode(AxisModeNone), |
|
76 | 80 | m_radialAxisMode(AxisModeNone), |
|
77 | 81 | m_series1(0), |
|
78 | 82 | m_series2(0), |
|
79 | 83 | m_series3(0), |
|
80 | 84 | m_series4(0), |
|
81 | 85 | m_series5(0), |
|
82 | 86 | m_series6(0), |
|
83 | 87 | m_series7(0), |
|
84 | 88 | m_dateFormat(QString("mm-ss-zzz")), |
|
85 | 89 | m_moreCategories(false) |
|
86 | 90 | { |
|
87 | 91 | ui->setupUi(this); |
|
88 | 92 | |
|
89 | 93 | ui->angularTicksSpin->setValue(m_angularTickCount); |
|
90 | 94 | ui->radialTicksSpin->setValue(m_radialTickCount); |
|
91 | 95 | ui->anglesSpin->setValue(m_labelsAngle); |
|
92 | 96 | ui->radialMinSpin->setValue(m_radialMin); |
|
93 | 97 | ui->radialMaxSpin->setValue(m_radialMax); |
|
94 | 98 | ui->angularMinSpin->setValue(m_angularMin); |
|
95 | 99 | ui->angularMaxSpin->setValue(m_angularMax); |
|
96 | 100 | ui->angularShadesComboBox->setCurrentIndex(0); |
|
97 | 101 | ui->radialShadesComboBox->setCurrentIndex(0); |
|
98 | 102 | ui->labelFormatEdit->setText(m_labelFormat); |
|
99 | 103 | ui->dateFormatEdit->setText(m_dateFormat); |
|
100 | 104 | ui->moreCategoriesCheckBox->setChecked(m_moreCategories); |
|
101 | 105 | |
|
102 | 106 | ui->series1checkBox->setChecked(true); |
|
103 | 107 | ui->series2checkBox->setChecked(true); |
|
104 | 108 | ui->series3checkBox->setChecked(true); |
|
105 | 109 | ui->series4checkBox->setChecked(true); |
|
106 | 110 | ui->series5checkBox->setChecked(true); |
|
107 | 111 | ui->series6checkBox->setChecked(true); |
|
108 | 112 | ui->series7checkBox->setChecked(true); |
|
109 | 113 | |
|
110 | 114 | m_currentLabelFont.setFamily(ui->labelFontComboBox->currentFont().family()); |
|
111 | 115 | m_currentLabelFont.setPixelSize(15); |
|
112 | 116 | m_currentTitleFont.setFamily(ui->titleFontComboBox->currentFont().family()); |
|
113 | 117 | m_currentTitleFont.setPixelSize(30); |
|
114 | 118 | |
|
115 | 119 | ui->labelFontSizeSpin->setValue(m_currentLabelFont.pixelSize()); |
|
116 | 120 | ui->titleFontSizeSpin->setValue(m_currentTitleFont.pixelSize()); |
|
117 | 121 | |
|
118 | 122 | ui->logBaseSpin->setValue(m_base); |
|
119 | 123 | |
|
120 | 124 | initXYValueChart(); |
|
121 | 125 | setAngularAxis(AxisModeValue); |
|
122 | 126 | setRadialAxis(AxisModeValue); |
|
123 | 127 | |
|
124 | 128 | ui->angularAxisComboBox->setCurrentIndex(int(m_angularAxisMode)); |
|
125 | 129 | ui->radialAxisComboBox->setCurrentIndex(int(m_radialAxisMode)); |
|
126 | 130 | |
|
127 | 131 | connect(ui->angularTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(angularTicksChanged(int))); |
|
128 | 132 | connect(ui->radialTicksSpin, SIGNAL(valueChanged(int)), this, SLOT(radialTicksChanged(int))); |
|
129 | 133 | connect(ui->anglesSpin, SIGNAL(valueChanged(int)), this, SLOT(anglesChanged(int))); |
|
130 | 134 | connect(ui->radialMinSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMinChanged(double))); |
|
131 | 135 | connect(ui->radialMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(radialMaxChanged(double))); |
|
132 | 136 | connect(ui->angularMinSpin, SIGNAL(valueChanged(double)), this, SLOT(angularMinChanged(double))); |
|
133 | 137 | connect(ui->angularMaxSpin, SIGNAL(valueChanged(double)), this, SLOT(angularMaxChanged(double))); |
|
134 | 138 | connect(ui->angularShadesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularShadesIndexChanged(int))); |
|
135 | 139 | connect(ui->radialShadesComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(radialShadesIndexChanged(int))); |
|
136 | 140 | connect(ui->animationsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(animationIndexChanged(int))); |
|
137 | 141 | connect(ui->labelFormatEdit, SIGNAL(textEdited(QString)), this, SLOT(labelFormatEdited(QString))); |
|
138 | 142 | connect(ui->labelFontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(labelFontChanged(QFont))); |
|
139 | 143 | connect(ui->labelFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(labelFontSizeChanged(int))); |
|
140 | 144 | connect(ui->labelComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(labelsIndexChanged(int))); |
|
141 | 145 | connect(ui->titleFontComboBox, SIGNAL(currentFontChanged(QFont)), this, SLOT(titleFontChanged(QFont))); |
|
142 | 146 | connect(ui->titleFontSizeSpin, SIGNAL(valueChanged(int)), this, SLOT(titleFontSizeChanged(int))); |
|
143 | 147 | connect(ui->titleComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(titleIndexChanged(int))); |
|
144 | 148 | connect(ui->gridComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(gridIndexChanged(int))); |
|
145 | 149 | connect(ui->arrowComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(arrowIndexChanged(int))); |
|
146 | 150 | connect(ui->logBaseSpin, SIGNAL(valueChanged(double)), this, SLOT(logBaseChanged(double))); |
|
147 | 151 | connect(ui->angularAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(angularAxisIndexChanged(int))); |
|
148 | 152 | connect(ui->radialAxisComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(radialAxisIndexChanged(int))); |
|
149 | 153 | connect(ui->niceNumbersCheckBox, SIGNAL(clicked()), this, SLOT(niceNumbersChecked())); |
|
150 | 154 | connect(ui->dateFormatEdit, SIGNAL(textEdited(QString)), this, SLOT(dateFormatEdited(QString))); |
|
151 | 155 | connect(ui->moreCategoriesCheckBox, SIGNAL(clicked()), this, SLOT(moreCategoriesChecked())); |
|
152 | 156 | connect(ui->series1checkBox, SIGNAL(clicked()), this, SLOT(series1CheckBoxChecked())); |
|
153 | 157 | connect(ui->series2checkBox, SIGNAL(clicked()), this, SLOT(series2CheckBoxChecked())); |
|
154 | 158 | connect(ui->series3checkBox, SIGNAL(clicked()), this, SLOT(series3CheckBoxChecked())); |
|
155 | 159 | connect(ui->series4checkBox, SIGNAL(clicked()), this, SLOT(series4CheckBoxChecked())); |
|
156 | 160 | connect(ui->series5checkBox, SIGNAL(clicked()), this, SLOT(series5CheckBoxChecked())); |
|
157 | 161 | connect(ui->series6checkBox, SIGNAL(clicked()), this, SLOT(series6CheckBoxChecked())); |
|
158 | 162 | connect(ui->series7checkBox, SIGNAL(clicked()), this, SLOT(series7CheckBoxChecked())); |
|
159 | 163 | connect(ui->themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(themeIndexChanged(int))); |
|
164 | connect(ui->backgroundComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(backgroundIndexChanged(int))); | |
|
165 | connect(ui->plotAreaComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(plotAreaIndexChanged(int))); | |
|
160 | 166 | |
|
161 | 167 | ui->chartView->setChart(m_chart); |
|
162 | 168 | ui->chartView->setRenderHint(QPainter::Antialiasing); |
|
163 | 169 | } |
|
164 | 170 | |
|
165 | 171 | MainWindow::~MainWindow() |
|
166 | 172 | { |
|
167 | 173 | delete ui; |
|
168 | 174 | delete m_angularShadesBrush; |
|
169 | 175 | delete m_radialShadesBrush; |
|
170 | 176 | delete m_angularShadesPen; |
|
171 | 177 | delete m_radialShadesPen; |
|
172 | 178 | } |
|
173 | 179 | |
|
174 | 180 | void MainWindow::initXYValueChart() |
|
175 | 181 | { |
|
176 | 182 | qreal seriesAngularMin = 1; |
|
177 | 183 | qreal seriesAngularMax = 46000; |
|
178 | 184 | qreal seriesRadialMin = 1; |
|
179 | 185 | qreal seriesRadialMax = 23500; |
|
180 | 186 | qreal radialDimension = seriesRadialMax - seriesRadialMin; |
|
181 | 187 | qreal angularDimension = seriesAngularMax - seriesAngularMin; |
|
182 | 188 | |
|
183 | 189 | // Scatter series, points outside min-max ranges should not be drawn |
|
184 | 190 | m_series1 = new QScatterSeries(); |
|
185 | 191 | m_series1->setName("scatter"); |
|
186 | 192 | qreal scatterCount = 10; |
|
187 | 193 | qreal scatterAngularStep = angularDimension / scatterCount; |
|
188 | 194 | qreal scatterRadialStep = radialDimension / scatterCount; |
|
189 | 195 | for (qreal i = 0.0; i < scatterCount; i++) { |
|
190 | 196 | m_series1->append((i * scatterAngularStep) + seriesAngularMin, (i * scatterRadialStep) + seriesRadialMin); |
|
191 | 197 | //qDebug() << m_series1->points().last(); |
|
192 | 198 | } |
|
193 | 199 | m_series1->setMarkerSize(10); |
|
194 | 200 | *m_series1 << QPointF(50, 50) << QPointF(150, 150) << QPointF(250, 250) << QPointF(350, 350) << QPointF(450, 450); |
|
195 | 201 | *m_series1 << QPointF(1050, 0.50) << QPointF(1150, 0.25) << QPointF(1250, 0.12) << QPointF(1350, 0.075) << QPointF(1450, 0.036); |
|
196 | 202 | *m_series1 << QPointF(0.50, 2000) << QPointF(0.25, 3500) << QPointF(0.12, 5000) << QPointF(0.075, 6500) << QPointF(0.036, 8000); |
|
197 | 203 | |
|
198 | 204 | // Line series, points outside min-max ranges should not be drawn, |
|
199 | 205 | // but lines should be properly interpolated at chart edges |
|
200 | 206 | m_series2 = new QLineSeries(); |
|
201 | 207 | m_series2->setName("line 1"); |
|
202 | 208 | qreal lineCount = 100; |
|
203 | 209 | qreal lineAngularStep = angularDimension / lineCount; |
|
204 | 210 | qreal lineRadialStep = radialDimension / lineCount; |
|
205 | 211 | for (qreal i = 0.0; i < lineCount; i++) { |
|
206 | 212 | m_series2->append((i * lineAngularStep) + seriesAngularMin, (i * lineRadialStep) + seriesRadialMin); |
|
207 | 213 | //qDebug() << m_series2->points().last(); |
|
208 | 214 | } |
|
209 | 215 | QPen series2Pen = QPen(Qt::blue, 10); |
|
210 | 216 | //series2Pen.setStyle(Qt::DashDotDotLine); |
|
211 | 217 | m_series2->setPen(series2Pen); |
|
212 | 218 | |
|
213 | 219 | m_series3 = new QLineSeries(); |
|
214 | 220 | m_series3->setName("Area upper"); |
|
215 | 221 | lineCount = 87; |
|
216 | 222 | lineAngularStep = angularDimension / lineCount; |
|
217 | 223 | lineRadialStep = radialDimension / lineCount; |
|
218 | 224 | for (qreal i = 1.0; i <= lineCount; i++) { |
|
219 | 225 | m_series3->append((i * lineAngularStep) + seriesAngularMin, (i * lineRadialStep) + seriesRadialMin + 200.0); |
|
220 | 226 | //qDebug() << m_series3->points().last(); |
|
221 | 227 | } |
|
222 | 228 | |
|
223 | 229 | m_series4 = new QLineSeries(); |
|
224 | 230 | m_series4->setName("Area lower"); |
|
225 | 231 | lineCount = 89; |
|
226 | 232 | lineAngularStep = angularDimension / lineCount; |
|
227 | 233 | lineRadialStep = radialDimension / lineCount; |
|
228 | 234 | for (qreal i = 1.0; i <= lineCount; i++) { |
|
229 | 235 | m_series4->append((i * lineAngularStep) + seriesAngularMin + 100.0, (i * lineRadialStep) + seriesRadialMin + i * 300.0); |
|
230 | 236 | //qDebug() << m_series4->points().last(); |
|
231 | 237 | } |
|
232 | 238 | |
|
233 | 239 | m_series5 = new QAreaSeries(); |
|
234 | 240 | m_series5->setName("area"); |
|
235 | 241 | m_series5->setUpperSeries(m_series3); |
|
236 | 242 | m_series5->setLowerSeries(m_series4); |
|
237 | 243 | m_series5->setOpacity(0.5); |
|
238 | 244 | |
|
239 | 245 | m_series6 = new QSplineSeries(); |
|
240 | 246 | m_series6->setName("spline"); |
|
241 | 247 | qreal ad = angularDimension / 20; |
|
242 | 248 | qreal rd = radialDimension / 10; |
|
243 | 249 | m_series6->append(seriesAngularMin, seriesRadialMin + rd * 2); |
|
244 | 250 | m_series6->append(seriesAngularMin + ad, seriesRadialMin + rd * 5); |
|
245 | 251 | m_series6->append(seriesAngularMin + ad * 2, seriesRadialMin + rd * 4); |
|
246 | 252 | m_series6->append(seriesAngularMin + ad * 3, seriesRadialMin + rd * 9); |
|
247 | 253 | m_series6->append(seriesAngularMin + ad * 4, seriesRadialMin + rd * 11); |
|
248 | 254 | m_series6->append(seriesAngularMin + ad * 5, seriesRadialMin + rd * 12); |
|
249 | 255 | m_series6->append(seriesAngularMin + ad * 6, seriesRadialMin + rd * 9); |
|
250 | 256 | m_series6->append(seriesAngularMin + ad * 7, seriesRadialMin + rd * 11); |
|
251 | 257 | m_series6->append(seriesAngularMin + ad * 8, seriesRadialMin + rd * 12); |
|
252 | 258 | m_series6->append(seriesAngularMin + ad * 9, seriesRadialMin + rd * 6); |
|
253 | 259 | m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 4); |
|
254 | 260 | m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 8); |
|
255 | 261 | m_series6->append(seriesAngularMin + ad * 11, seriesRadialMin + rd * 9); |
|
256 | 262 | m_series6->append(seriesAngularMin + ad * 12, seriesRadialMin + rd * 11); |
|
257 | 263 | m_series6->append(seriesAngularMin + ad * 13, seriesRadialMin + rd * 12); |
|
258 | 264 | m_series6->append(seriesAngularMin + ad * 14, seriesRadialMin + rd * 6); |
|
259 | 265 | m_series6->append(seriesAngularMin + ad * 15, seriesRadialMin + rd * 3); |
|
260 | 266 | m_series6->append(seriesAngularMin + ad * 16, seriesRadialMin + rd * 2); |
|
261 | 267 | m_series6->append(seriesAngularMin + ad * 17, seriesRadialMin + rd * 6); |
|
262 | 268 | m_series6->append(seriesAngularMin + ad * 18, seriesRadialMin + rd * 6); |
|
263 | 269 | m_series6->append(seriesAngularMin + ad * 19, seriesRadialMin + rd * 6); |
|
264 | 270 | m_series6->append(seriesAngularMin + ad * 20, seriesRadialMin + rd * 6); |
|
265 | 271 | m_series6->append(seriesAngularMin + ad * 19, seriesRadialMin + rd * 2); |
|
266 | 272 | m_series6->append(seriesAngularMin + ad * 18, seriesRadialMin + rd * 9); |
|
267 | 273 | m_series6->append(seriesAngularMin + ad * 17, seriesRadialMin + rd * 7); |
|
268 | 274 | m_series6->append(seriesAngularMin + ad * 16, seriesRadialMin + rd * 3); |
|
269 | 275 | m_series6->append(seriesAngularMin + ad * 15, seriesRadialMin + rd * 1); |
|
270 | 276 | m_series6->append(seriesAngularMin + ad * 14, seriesRadialMin + rd * 7); |
|
271 | 277 | m_series6->append(seriesAngularMin + ad * 13, seriesRadialMin + rd * 5); |
|
272 | 278 | m_series6->append(seriesAngularMin + ad * 12, seriesRadialMin + rd * 9); |
|
273 | 279 | m_series6->append(seriesAngularMin + ad * 11, seriesRadialMin + rd * 1); |
|
274 | 280 | m_series6->append(seriesAngularMin + ad * 10, seriesRadialMin + rd * 4); |
|
275 | 281 | m_series6->append(seriesAngularMin + ad * 9, seriesRadialMin + rd * 1); |
|
276 | 282 | m_series6->append(seriesAngularMin + ad * 8, seriesRadialMin + rd * 2); |
|
277 | 283 | m_series6->append(seriesAngularMin + ad * 7, seriesRadialMin + rd * 4); |
|
278 | 284 | m_series6->append(seriesAngularMin + ad * 6, seriesRadialMin + rd * 8); |
|
279 | 285 | m_series6->append(seriesAngularMin + ad * 5, seriesRadialMin + rd * 12); |
|
280 | 286 | m_series6->append(seriesAngularMin + ad * 4, seriesRadialMin + rd * 9); |
|
281 | 287 | m_series6->append(seriesAngularMin + ad * 3, seriesRadialMin + rd * 8); |
|
282 | 288 | m_series6->append(seriesAngularMin + ad * 2, seriesRadialMin + rd * 7); |
|
283 | 289 | m_series6->append(seriesAngularMin + ad, seriesRadialMin + rd * 4); |
|
284 | 290 | m_series6->append(seriesAngularMin, seriesRadialMin + rd * 10); |
|
285 | 291 | |
|
286 | 292 | m_series6->setPointsVisible(true); |
|
287 | 293 | QPen series6Pen = QPen(Qt::red, 10); |
|
288 | 294 | //series6Pen.setStyle(Qt::DashDotDotLine); |
|
289 | 295 | m_series6->setPen(series6Pen); |
|
290 | 296 | |
|
291 | 297 | // m_series7 shows points at category intersections |
|
292 | 298 | m_series7 = new QScatterSeries(); |
|
293 | 299 | m_series7->setName("Category check"); |
|
294 | 300 | m_series7->setMarkerSize(7); |
|
295 | 301 | m_series7->setBrush(QColor(Qt::red)); |
|
296 | 302 | m_series7->setMarkerShape(QScatterSeries::MarkerShapeRectangle); |
|
297 | 303 | *m_series7 << QPointF(1000, 1000) |
|
298 | 304 | << QPointF(1000, 2000) |
|
299 | 305 | << QPointF(1000, 4000) |
|
300 | 306 | << QPointF(1000, 9000) |
|
301 | 307 | << QPointF(1000, 14000) |
|
302 | 308 | << QPointF(1000, 16500) |
|
303 | 309 | << QPointF(1000, 19000) |
|
304 | 310 | |
|
305 | 311 | << QPointF(4000, 1000) |
|
306 | 312 | << QPointF(4000, 2000) |
|
307 | 313 | << QPointF(4000, 4000) |
|
308 | 314 | << QPointF(4000, 9000) |
|
309 | 315 | << QPointF(4000, 14000) |
|
310 | 316 | << QPointF(4000, 16500) |
|
311 | 317 | << QPointF(4000, 19000) |
|
312 | 318 | |
|
313 | 319 | << QPointF(7000, 1000) |
|
314 | 320 | << QPointF(7000, 2000) |
|
315 | 321 | << QPointF(7000, 4000) |
|
316 | 322 | << QPointF(7000, 9000) |
|
317 | 323 | << QPointF(7000, 14000) |
|
318 | 324 | << QPointF(7000, 16500) |
|
319 | 325 | << QPointF(7000, 19000) |
|
320 | 326 | |
|
321 | 327 | << QPointF(12000, 1000) |
|
322 | 328 | << QPointF(12000, 2000) |
|
323 | 329 | << QPointF(12000, 4000) |
|
324 | 330 | << QPointF(12000, 9000) |
|
325 | 331 | << QPointF(12000, 14000) |
|
326 | 332 | << QPointF(12000, 16500) |
|
327 | 333 | << QPointF(12000, 19000) |
|
328 | 334 | |
|
329 | 335 | << QPointF(17000, 1000) |
|
330 | 336 | << QPointF(17000, 2000) |
|
331 | 337 | << QPointF(17000, 4000) |
|
332 | 338 | << QPointF(17000, 9000) |
|
333 | 339 | << QPointF(17000, 14000) |
|
334 | 340 | << QPointF(17000, 16500) |
|
335 | 341 | << QPointF(17000, 19000) |
|
336 | 342 | |
|
337 | 343 | << QPointF(22000, 1000) |
|
338 | 344 | << QPointF(22000, 2000) |
|
339 | 345 | << QPointF(22000, 4000) |
|
340 | 346 | << QPointF(22000, 9000) |
|
341 | 347 | << QPointF(22000, 14000) |
|
342 | 348 | << QPointF(22000, 16500) |
|
343 | 349 | << QPointF(22000, 19000) |
|
344 | 350 | |
|
345 | 351 | << QPointF(28000, 1000) |
|
346 | 352 | << QPointF(28000, 2000) |
|
347 | 353 | << QPointF(28000, 4000) |
|
348 | 354 | << QPointF(28000, 9000) |
|
349 | 355 | << QPointF(28000, 14000) |
|
350 | 356 | << QPointF(28000, 16500) |
|
351 | 357 | << QPointF(28000, 19000); |
|
352 | 358 | |
|
353 | 359 | m_chart = new QPolarChart(); |
|
354 | 360 | |
|
355 | 361 | m_chart->addSeries(m_series1); |
|
356 | 362 | m_chart->addSeries(m_series2); |
|
357 | 363 | m_chart->addSeries(m_series3); |
|
358 | 364 | m_chart->addSeries(m_series4); |
|
359 | 365 | m_chart->addSeries(m_series5); |
|
360 | 366 | m_chart->addSeries(m_series6); |
|
361 | 367 | m_chart->addSeries(m_series7); |
|
362 | 368 | |
|
363 | 369 | connect(m_series1, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); |
|
364 | 370 | connect(m_series2, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); |
|
365 | 371 | connect(m_series3, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); |
|
366 | 372 | connect(m_series4, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); |
|
367 | 373 | connect(m_series5, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); |
|
368 | 374 | connect(m_series6, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); |
|
369 | 375 | connect(m_series7, SIGNAL(clicked(QPointF)), this, SLOT(seriesClicked(QPointF))); |
|
370 | 376 | connect(m_series1, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); |
|
371 | 377 | connect(m_series2, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); |
|
372 | 378 | connect(m_series3, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); |
|
373 | 379 | connect(m_series4, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); |
|
374 | 380 | connect(m_series5, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); |
|
375 | 381 | connect(m_series6, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); |
|
376 | 382 | connect(m_series7, SIGNAL(hovered(QPointF, bool)), this, SLOT(seriesHovered(QPointF, bool))); |
|
377 | 383 | |
|
378 | 384 | m_chart->setTitle("Use arrow keys to scroll and +/- to zoom"); |
|
379 | 385 | m_chart->setAnimationOptions(m_animationOptions); |
|
380 | 386 | //m_chart->legend()->setVisible(false); |
|
381 | 387 | m_chart->setAcceptHoverEvents(true); |
|
388 | m_chart->setBackgroundBrush(*m_backgroundBrush); | |
|
389 | m_chart->setBackgroundPen(*m_backgroundPen); | |
|
390 | m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush); | |
|
391 | m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen); | |
|
382 | 392 | } |
|
383 | 393 | |
|
384 | 394 | void MainWindow::setAngularAxis(MainWindow::AxisMode mode) |
|
385 | 395 | { |
|
386 | 396 | if (m_angularAxis) { |
|
387 | 397 | m_chart->removeAxis(m_angularAxis); |
|
388 | 398 | delete m_angularAxis; |
|
389 | 399 | m_angularAxis = 0; |
|
390 | 400 | } |
|
391 | 401 | |
|
392 | 402 | m_angularAxisMode = mode; |
|
393 | 403 | |
|
394 | 404 | switch (m_angularAxisMode) { |
|
395 | 405 | case AxisModeNone: |
|
396 | 406 | return; |
|
397 | 407 | case AxisModeValue: |
|
398 | 408 | m_angularAxis = new QValueAxis(); |
|
399 | 409 | static_cast<QValueAxis *>(m_angularAxis)->setTickCount(m_angularTickCount); |
|
400 | 410 | static_cast<QValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat); |
|
401 | 411 | break; |
|
402 | 412 | case AxisModeLogValue: |
|
403 | 413 | m_angularAxis = new QLogValueAxis(); |
|
404 | 414 | static_cast<QLogValueAxis *>(m_angularAxis)->setBase(m_base); |
|
405 | 415 | static_cast<QLogValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat); |
|
406 | 416 | break; |
|
407 | 417 | case AxisModeDateTime: |
|
408 | 418 | m_angularAxis = new QDateTimeAxis(); |
|
409 | 419 | static_cast<QDateTimeAxis *>(m_angularAxis)->setTickCount(m_angularTickCount); |
|
410 | 420 | static_cast<QDateTimeAxis *>(m_angularAxis)->setFormat(m_dateFormat); |
|
411 | 421 | break; |
|
412 | 422 | case AxisModeCategory: |
|
413 | 423 | m_angularAxis = new QCategoryAxis(); |
|
414 | 424 | applyCategories(); |
|
415 | 425 | break; |
|
416 | 426 | default: |
|
417 | 427 | qWarning() << "Unsupported AxisMode"; |
|
418 | 428 | break; |
|
419 | 429 | } |
|
420 | 430 | |
|
421 | 431 | m_angularAxis->setLabelsAngle(m_labelsAngle); |
|
422 | 432 | m_angularAxis->setLabelsFont(m_currentLabelFont); |
|
423 | 433 | m_angularAxis->setLabelsBrush(*m_labelBrush); |
|
424 | 434 | m_angularAxis->setLabelsPen(*m_labelPen); |
|
425 | 435 | m_angularAxis->setLabelsVisible(m_labelsVisible); |
|
426 | 436 | m_angularAxis->setShadesBrush(*m_angularShadesBrush); |
|
427 | 437 | m_angularAxis->setShadesPen(*m_angularShadesPen); |
|
428 | 438 | m_angularAxis->setShadesVisible(m_angularShadesVisible); |
|
429 | 439 | m_angularAxis->setTitleFont(m_currentTitleFont); |
|
430 | 440 | m_angularAxis->setTitleBrush(*m_titleBrush); |
|
431 | 441 | m_angularAxis->setTitlePen(*m_titlePen); |
|
432 | 442 | m_angularAxis->setTitleVisible(m_titleVisible); |
|
433 | 443 | m_angularAxis->setTitleText(m_angularTitle); |
|
434 | 444 | m_angularAxis->setGridLinePen(*m_gridPen); |
|
435 | 445 | m_angularAxis->setGridLineVisible(m_gridVisible); |
|
436 | 446 | m_angularAxis->setLinePen(*m_arrowPen); |
|
437 | 447 | m_angularAxis->setLineVisible(m_arrowVisible); |
|
438 | 448 | |
|
439 | 449 | m_chart->addAxis(m_angularAxis, QPolarChart::PolarOrientationAngular); |
|
440 | 450 | |
|
441 | 451 | m_series1->attachAxis(m_angularAxis); |
|
442 | 452 | m_series2->attachAxis(m_angularAxis); |
|
443 | 453 | m_series3->attachAxis(m_angularAxis); |
|
444 | 454 | m_series4->attachAxis(m_angularAxis); |
|
445 | 455 | m_series5->attachAxis(m_angularAxis); |
|
446 | 456 | m_series6->attachAxis(m_angularAxis); |
|
447 | 457 | m_series7->attachAxis(m_angularAxis); |
|
448 | 458 | |
|
449 | 459 | applyRanges(); |
|
450 | 460 | |
|
451 | 461 | //connect(m_angularAxis, SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(angularRangeChanged(qreal, qreal))); |
|
452 | 462 | } |
|
453 | 463 | |
|
454 | 464 | void MainWindow::setRadialAxis(MainWindow::AxisMode mode) |
|
455 | 465 | { |
|
456 | 466 | if (m_radialAxis) { |
|
457 | 467 | m_chart->removeAxis(m_radialAxis); |
|
458 | 468 | delete m_radialAxis; |
|
459 | 469 | m_radialAxis = 0; |
|
460 | 470 | } |
|
461 | 471 | |
|
462 | 472 | m_radialAxisMode = mode; |
|
463 | 473 | |
|
464 | 474 | switch (m_radialAxisMode) { |
|
465 | 475 | case AxisModeNone: |
|
466 | 476 | return; |
|
467 | 477 | case AxisModeValue: |
|
468 | 478 | m_radialAxis = new QValueAxis(); |
|
469 | 479 | static_cast<QValueAxis *>(m_radialAxis)->setTickCount(m_radialTickCount); |
|
470 | 480 | static_cast<QValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat); |
|
471 | 481 | break; |
|
472 | 482 | case AxisModeLogValue: |
|
473 | 483 | m_radialAxis = new QLogValueAxis(); |
|
474 | 484 | static_cast<QLogValueAxis *>(m_radialAxis)->setBase(m_base); |
|
475 | 485 | static_cast<QLogValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat); |
|
476 | 486 | break; |
|
477 | 487 | case AxisModeDateTime: |
|
478 | 488 | m_radialAxis = new QDateTimeAxis(); |
|
479 | 489 | static_cast<QDateTimeAxis *>(m_radialAxis)->setTickCount(m_radialTickCount); |
|
480 | 490 | static_cast<QDateTimeAxis *>(m_radialAxis)->setFormat(m_dateFormat); |
|
481 | 491 | break; |
|
482 | 492 | case AxisModeCategory: |
|
483 | 493 | m_radialAxis = new QCategoryAxis(); |
|
484 | 494 | applyCategories(); |
|
485 | 495 | break; |
|
486 | 496 | default: |
|
487 | 497 | qWarning() << "Unsupported AxisMode"; |
|
488 | 498 | break; |
|
489 | 499 | } |
|
490 | 500 | |
|
491 | 501 | m_radialAxis->setLabelsAngle(m_labelsAngle); |
|
492 | 502 | m_radialAxis->setLabelsFont(m_currentLabelFont); |
|
493 | 503 | m_radialAxis->setLabelsBrush(*m_labelBrush); |
|
494 | 504 | m_radialAxis->setLabelsPen(*m_labelPen); |
|
495 | 505 | m_radialAxis->setLabelsVisible(m_labelsVisible); |
|
496 | 506 | m_radialAxis->setShadesBrush(*m_radialShadesBrush); |
|
497 | 507 | m_radialAxis->setShadesPen(*m_radialShadesPen); |
|
498 | 508 | m_radialAxis->setShadesVisible(m_radialShadesVisible); |
|
499 | 509 | m_radialAxis->setTitleFont(m_currentTitleFont); |
|
500 | 510 | m_radialAxis->setTitleBrush(*m_titleBrush); |
|
501 | 511 | m_radialAxis->setTitlePen(*m_titlePen); |
|
502 | 512 | m_radialAxis->setTitleVisible(m_titleVisible); |
|
503 | 513 | m_radialAxis->setTitleText(m_radialTitle); |
|
504 | 514 | m_radialAxis->setGridLinePen(*m_gridPen); |
|
505 | 515 | m_radialAxis->setGridLineVisible(m_gridVisible); |
|
506 | 516 | m_radialAxis->setLinePen(*m_arrowPen); |
|
507 | 517 | m_radialAxis->setLineVisible(m_arrowVisible); |
|
508 | 518 | |
|
509 | 519 | m_chart->addAxis(m_radialAxis, QPolarChart::PolarOrientationRadial); |
|
510 | 520 | |
|
511 | 521 | m_series1->attachAxis(m_radialAxis); |
|
512 | 522 | m_series2->attachAxis(m_radialAxis); |
|
513 | 523 | m_series3->attachAxis(m_radialAxis); |
|
514 | 524 | m_series4->attachAxis(m_radialAxis); |
|
515 | 525 | m_series5->attachAxis(m_radialAxis); |
|
516 | 526 | m_series6->attachAxis(m_radialAxis); |
|
517 | 527 | m_series7->attachAxis(m_radialAxis); |
|
518 | 528 | |
|
519 | 529 | applyRanges(); |
|
520 | 530 | |
|
521 | 531 | series1CheckBoxChecked(); |
|
522 | 532 | series2CheckBoxChecked(); |
|
523 | 533 | series3CheckBoxChecked(); |
|
524 | 534 | series4CheckBoxChecked(); |
|
525 | 535 | series5CheckBoxChecked(); |
|
526 | 536 | series6CheckBoxChecked(); |
|
527 | 537 | series7CheckBoxChecked(); |
|
528 | 538 | |
|
529 | 539 | //connect(m_radialAxis, SIGNAL(rangeChanged(qreal, qreal)), this, SLOT(radialRangeChanged(qreal, qreal))); |
|
530 | 540 | } |
|
531 | 541 | |
|
532 | 542 | void MainWindow::applyRanges() |
|
533 | 543 | { |
|
534 | 544 | if (ui->niceNumbersCheckBox->isChecked()) { |
|
535 | 545 | if (m_angularAxisMode == AxisModeValue) { |
|
536 | 546 | static_cast<QValueAxis *>(m_angularAxis)->applyNiceNumbers(); |
|
537 | 547 | m_angularMin = static_cast<QValueAxis *>(m_angularAxis)->min(); |
|
538 | 548 | m_angularMax = static_cast<QValueAxis *>(m_angularAxis)->max(); |
|
539 | 549 | m_angularTickCount = static_cast<QValueAxis *>(m_angularAxis)->tickCount(); |
|
540 | 550 | } |
|
541 | 551 | if (m_radialAxisMode == AxisModeValue) { |
|
542 | 552 | static_cast<QValueAxis *>(m_radialAxis)->applyNiceNumbers(); |
|
543 | 553 | m_radialMin = static_cast<QValueAxis *>(m_radialAxis)->min(); |
|
544 | 554 | m_radialMax = static_cast<QValueAxis *>(m_radialAxis)->max(); |
|
545 | 555 | m_radialTickCount = static_cast<QValueAxis *>(m_radialAxis)->tickCount(); |
|
546 | 556 | } |
|
547 | 557 | } |
|
548 | 558 | |
|
549 | 559 | if (m_angularAxis) |
|
550 | 560 | m_angularAxis->setRange(m_angularMin, m_angularMax); |
|
551 | 561 | if (m_radialAxis) |
|
552 | 562 | m_radialAxis->setRange(m_radialMin, m_radialMax); |
|
553 | 563 | } |
|
554 | 564 | |
|
555 | 565 | void MainWindow::angularTicksChanged(int value) |
|
556 | 566 | { |
|
557 | 567 | m_angularTickCount = value; |
|
558 | 568 | if (m_angularAxisMode == AxisModeValue) |
|
559 | 569 | static_cast<QValueAxis *>(m_angularAxis)->setTickCount(m_angularTickCount); |
|
560 | 570 | else if (m_angularAxisMode == AxisModeDateTime) |
|
561 | 571 | static_cast<QDateTimeAxis *>(m_angularAxis)->setTickCount(m_angularTickCount); |
|
562 | 572 | } |
|
563 | 573 | |
|
564 | 574 | void MainWindow::radialTicksChanged(int value) |
|
565 | 575 | { |
|
566 | 576 | m_radialTickCount = value; |
|
567 | 577 | if (m_radialAxisMode == AxisModeValue) |
|
568 | 578 | static_cast<QValueAxis *>(m_radialAxis)->setTickCount(m_radialTickCount); |
|
569 | 579 | else if (m_radialAxisMode == AxisModeDateTime) |
|
570 | 580 | static_cast<QDateTimeAxis *>(m_radialAxis)->setTickCount(m_radialTickCount); |
|
571 | 581 | } |
|
572 | 582 | |
|
573 | 583 | void MainWindow::anglesChanged(int value) |
|
574 | 584 | { |
|
575 | 585 | m_labelsAngle = value; |
|
576 | 586 | m_radialAxis->setLabelsAngle(m_labelsAngle); |
|
577 | 587 | m_angularAxis->setLabelsAngle(m_labelsAngle); |
|
578 | 588 | } |
|
579 | 589 | |
|
580 | 590 | void MainWindow::angularMinChanged(double value) |
|
581 | 591 | { |
|
582 | 592 | m_angularMin = value; |
|
583 | 593 | if (m_angularAxisMode != AxisModeDateTime) { |
|
584 | 594 | m_angularAxis->setMin(m_angularMin); |
|
585 | 595 | } else { |
|
586 | 596 | QDateTime dateTime; |
|
587 | 597 | dateTime.setMSecsSinceEpoch(qint64(m_angularMin)); |
|
588 | 598 | m_angularAxis->setMin(dateTime); |
|
589 | 599 | } |
|
590 | 600 | } |
|
591 | 601 | |
|
592 | 602 | void MainWindow::angularMaxChanged(double value) |
|
593 | 603 | { |
|
594 | 604 | m_angularMax = value; |
|
595 | 605 | if (m_angularAxisMode != AxisModeDateTime) { |
|
596 | 606 | m_angularAxis->setMax(m_angularMax); |
|
597 | 607 | } else { |
|
598 | 608 | QDateTime dateTime; |
|
599 | 609 | dateTime.setMSecsSinceEpoch(qint64(m_angularMax)); |
|
600 | 610 | m_angularAxis->setMax(dateTime); |
|
601 | 611 | } |
|
602 | 612 | } |
|
603 | 613 | |
|
604 | 614 | void MainWindow::radialMinChanged(double value) |
|
605 | 615 | { |
|
606 | 616 | m_radialMin = value; |
|
607 | 617 | if (m_radialAxisMode != AxisModeDateTime) { |
|
608 | 618 | m_radialAxis->setMin(m_radialMin); |
|
609 | 619 | } else { |
|
610 | 620 | QDateTime dateTime; |
|
611 | 621 | dateTime.setMSecsSinceEpoch(qint64(m_radialMin)); |
|
612 | 622 | m_radialAxis->setMin(dateTime); |
|
613 | 623 | } |
|
614 | 624 | } |
|
615 | 625 | |
|
616 | 626 | void MainWindow::radialMaxChanged(double value) |
|
617 | 627 | { |
|
618 | 628 | m_radialMax = value; |
|
619 | 629 | if (m_radialAxisMode != AxisModeDateTime) { |
|
620 | 630 | m_radialAxis->setMax(m_radialMax); |
|
621 | 631 | } else { |
|
622 | 632 | QDateTime dateTime; |
|
623 | 633 | dateTime.setMSecsSinceEpoch(qint64(m_radialMax)); |
|
624 | 634 | m_radialAxis->setMax(dateTime); |
|
625 | 635 | } |
|
626 | 636 | } |
|
627 | 637 | |
|
628 | 638 | void MainWindow::angularShadesIndexChanged(int index) |
|
629 | 639 | { |
|
630 | 640 | delete m_angularShadesBrush; |
|
631 | 641 | delete m_angularShadesPen; |
|
632 | 642 | |
|
633 | 643 | switch (index) { |
|
634 | 644 | case 0: |
|
635 | 645 | m_angularShadesBrush = new QBrush(Qt::NoBrush); |
|
636 | 646 | m_angularShadesPen = new QPen(Qt::NoPen); |
|
637 | 647 | m_angularShadesVisible = false; |
|
638 | 648 | break; |
|
639 | 649 | case 1: |
|
640 | 650 | m_angularShadesBrush = new QBrush(Qt::lightGray); |
|
641 | 651 | m_angularShadesPen = new QPen(Qt::NoPen); |
|
642 | 652 | m_angularShadesVisible = true; |
|
643 | 653 | break; |
|
644 | 654 | case 2: |
|
645 | 655 | m_angularShadesBrush = new QBrush(Qt::yellow); |
|
646 | 656 | m_angularShadesPen = new QPen(Qt::DotLine); |
|
647 | 657 | m_angularShadesPen->setWidth(2); |
|
648 | 658 | m_angularShadesVisible = true; |
|
649 | 659 | break; |
|
650 | 660 | default: |
|
651 | 661 | break; |
|
652 | 662 | } |
|
653 | 663 | |
|
654 | 664 | m_angularAxis->setShadesBrush(*m_angularShadesBrush); |
|
655 | 665 | m_angularAxis->setShadesPen(*m_angularShadesPen); |
|
656 | 666 | m_angularAxis->setShadesVisible(m_angularShadesVisible); |
|
657 | 667 | } |
|
658 | 668 | |
|
659 | 669 | void MainWindow::radialShadesIndexChanged(int index) |
|
660 | 670 | { |
|
661 | 671 | delete m_radialShadesBrush; |
|
662 | 672 | delete m_radialShadesPen; |
|
663 | 673 | |
|
664 | 674 | switch (index) { |
|
665 | 675 | case 0: |
|
666 | 676 | m_radialShadesBrush = new QBrush(Qt::NoBrush); |
|
667 | 677 | m_radialShadesPen = new QPen(Qt::NoPen); |
|
668 | 678 | m_radialShadesVisible = false; |
|
669 | 679 | break; |
|
670 | 680 | case 1: |
|
671 | 681 | m_radialShadesBrush = new QBrush(Qt::green); |
|
672 | 682 | m_radialShadesPen = new QPen(Qt::NoPen); |
|
673 | 683 | m_radialShadesVisible = true; |
|
674 | 684 | break; |
|
675 | 685 | case 2: |
|
676 | 686 | m_radialShadesBrush = new QBrush(Qt::blue); |
|
677 | 687 | m_radialShadesPen = new QPen(Qt::DotLine); |
|
678 | 688 | m_radialShadesPen->setWidth(2); |
|
679 | 689 | m_radialShadesVisible = true; |
|
680 | 690 | break; |
|
681 | 691 | default: |
|
682 | 692 | break; |
|
683 | 693 | } |
|
684 | 694 | |
|
685 | 695 | m_radialAxis->setShadesBrush(*m_radialShadesBrush); |
|
686 | 696 | m_radialAxis->setShadesPen(*m_radialShadesPen); |
|
687 | 697 | m_radialAxis->setShadesVisible(m_radialShadesVisible); |
|
688 | 698 | } |
|
689 | 699 | |
|
690 | 700 | void MainWindow::labelFormatEdited(const QString &text) |
|
691 | 701 | { |
|
692 | 702 | m_labelFormat = text; |
|
693 | 703 | if (m_angularAxisMode == AxisModeValue) |
|
694 | 704 | static_cast<QValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat); |
|
695 | 705 | else if (m_angularAxisMode == AxisModeLogValue) |
|
696 | 706 | static_cast<QLogValueAxis *>(m_angularAxis)->setLabelFormat(m_labelFormat); |
|
697 | 707 | |
|
698 | 708 | if (m_radialAxisMode == AxisModeValue) |
|
699 | 709 | static_cast<QValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat); |
|
700 | 710 | else if (m_radialAxisMode == AxisModeLogValue) |
|
701 | 711 | static_cast<QLogValueAxis *>(m_radialAxis)->setLabelFormat(m_labelFormat); |
|
702 | 712 | } |
|
703 | 713 | |
|
704 | 714 | void MainWindow::labelFontChanged(const QFont &font) |
|
705 | 715 | { |
|
706 | 716 | m_currentLabelFont = font; |
|
707 | 717 | m_currentLabelFont.setPixelSize(ui->labelFontSizeSpin->value()); |
|
708 | 718 | m_angularAxis->setLabelsFont(m_currentLabelFont); |
|
709 | 719 | m_radialAxis->setLabelsFont(m_currentLabelFont); |
|
710 | 720 | } |
|
711 | 721 | |
|
712 | 722 | void MainWindow::labelFontSizeChanged(int value) |
|
713 | 723 | { |
|
714 | 724 | m_currentLabelFont = ui->labelFontComboBox->currentFont(); |
|
715 | 725 | m_currentLabelFont.setPixelSize(value); |
|
716 | 726 | m_angularAxis->setLabelsFont(m_currentLabelFont); |
|
717 | 727 | m_radialAxis->setLabelsFont(m_currentLabelFont); |
|
718 | 728 | } |
|
719 | 729 | |
|
720 | 730 | void MainWindow::animationIndexChanged(int index) |
|
721 | 731 | { |
|
722 | 732 | switch (index) { |
|
723 | 733 | case 0: |
|
724 | 734 | m_animationOptions = QChart::NoAnimation; |
|
725 | 735 | break; |
|
726 | 736 | case 1: |
|
727 | 737 | m_animationOptions = QChart::SeriesAnimations; |
|
728 | 738 | break; |
|
729 | 739 | case 2: |
|
730 | 740 | m_animationOptions = QChart::GridAxisAnimations; |
|
731 | 741 | break; |
|
732 | 742 | case 3: |
|
733 | 743 | m_animationOptions = QChart::AllAnimations; |
|
734 | 744 | break; |
|
735 | 745 | default: |
|
736 | 746 | break; |
|
737 | 747 | } |
|
738 | 748 | |
|
739 | 749 | m_chart->setAnimationOptions(m_animationOptions); |
|
740 | 750 | } |
|
741 | 751 | |
|
742 | 752 | void MainWindow::labelsIndexChanged(int index) |
|
743 | 753 | { |
|
744 | 754 | delete m_labelBrush; |
|
745 | 755 | delete m_labelPen; |
|
746 | 756 | |
|
747 | 757 | switch (index) { |
|
748 | 758 | case 0: |
|
749 | 759 | m_labelBrush = new QBrush(Qt::NoBrush); |
|
750 | 760 | m_labelPen = new QPen(Qt::NoPen); |
|
751 | 761 | m_labelsVisible = false; |
|
752 | 762 | break; |
|
753 | 763 | case 1: |
|
754 | 764 | m_labelBrush = new QBrush(Qt::black); |
|
755 | 765 | m_labelPen = new QPen(Qt::NoPen); |
|
756 | 766 | m_labelsVisible = true; |
|
757 | 767 | break; |
|
758 | 768 | case 2: |
|
759 | 769 | m_labelBrush = new QBrush(Qt::white); |
|
760 | 770 | m_labelPen = new QPen(Qt::blue); |
|
761 | 771 | m_labelsVisible = true; |
|
762 | 772 | break; |
|
763 | 773 | default: |
|
764 | 774 | break; |
|
765 | 775 | } |
|
766 | 776 | |
|
767 | 777 | m_radialAxis->setLabelsBrush(*m_labelBrush); |
|
768 | 778 | m_radialAxis->setLabelsPen(*m_labelPen); |
|
769 | 779 | m_radialAxis->setLabelsVisible(m_labelsVisible); |
|
770 | 780 | m_angularAxis->setLabelsBrush(*m_labelBrush); |
|
771 | 781 | m_angularAxis->setLabelsPen(*m_labelPen); |
|
772 | 782 | m_angularAxis->setLabelsVisible(m_labelsVisible); |
|
773 | 783 | } |
|
774 | 784 | |
|
775 | 785 | void MainWindow::titleIndexChanged(int index) |
|
776 | 786 | { |
|
777 | 787 | delete m_titleBrush; |
|
778 | 788 | delete m_titlePen; |
|
779 | 789 | |
|
780 | 790 | switch (index) { |
|
781 | 791 | case 0: |
|
782 | 792 | m_titleBrush = new QBrush(Qt::NoBrush); |
|
783 | 793 | m_titlePen = new QPen(Qt::NoPen); |
|
784 | 794 | m_titleVisible = false; |
|
785 | 795 | m_angularTitle = QString(); |
|
786 | 796 | m_radialTitle = QString(); |
|
787 | 797 | break; |
|
788 | 798 | case 1: |
|
789 | 799 | m_titleBrush = new QBrush(Qt::NoBrush); |
|
790 | 800 | m_titlePen = new QPen(Qt::NoPen); |
|
791 | 801 | m_titleVisible = true; |
|
792 | 802 | m_angularTitle = QString(); |
|
793 | 803 | m_radialTitle = QString(); |
|
794 | 804 | break; |
|
795 | 805 | case 2: |
|
796 | 806 | m_titleBrush = new QBrush(Qt::NoBrush); |
|
797 | 807 | m_titlePen = new QPen(Qt::NoPen); |
|
798 | 808 | m_titleVisible = false; |
|
799 | 809 | m_angularTitle = QString("Invisible Ang. Title!"); |
|
800 | 810 | m_radialTitle = QString("Invisible Rad. Title!"); |
|
801 | 811 | break; |
|
802 | 812 | case 3: |
|
803 | 813 | m_titleBrush = new QBrush(Qt::black); |
|
804 | 814 | m_titlePen = new QPen(Qt::NoPen); |
|
805 | 815 | m_titleVisible = true; |
|
806 | 816 | m_angularTitle = QString("Angular Title"); |
|
807 | 817 | m_radialTitle = QString("Radial Title"); |
|
808 | 818 | break; |
|
809 | 819 | case 4: |
|
810 | 820 | m_titleBrush = new QBrush(Qt::white); |
|
811 | 821 | m_titlePen = new QPen(Qt::blue); |
|
812 | 822 | m_titleVisible = true; |
|
813 | 823 | m_angularTitle = QString("Angular Blue Title"); |
|
814 | 824 | m_radialTitle = QString("Radial Blue Title"); |
|
815 | 825 | break; |
|
816 | 826 | default: |
|
817 | 827 | break; |
|
818 | 828 | } |
|
819 | 829 | |
|
820 | 830 | m_radialAxis->setTitleBrush(*m_titleBrush); |
|
821 | 831 | m_radialAxis->setTitlePen(*m_titlePen); |
|
822 | 832 | m_radialAxis->setTitleVisible(m_titleVisible); |
|
823 | 833 | m_radialAxis->setTitleText(m_radialTitle); |
|
824 | 834 | m_angularAxis->setTitleBrush(*m_titleBrush); |
|
825 | 835 | m_angularAxis->setTitlePen(*m_titlePen); |
|
826 | 836 | m_angularAxis->setTitleVisible(m_titleVisible); |
|
827 | 837 | m_angularAxis->setTitleText(m_angularTitle); |
|
828 | 838 | } |
|
829 | 839 | |
|
830 | 840 | void MainWindow::titleFontChanged(const QFont &font) |
|
831 | 841 | { |
|
832 | 842 | m_currentTitleFont = font; |
|
833 | 843 | m_currentTitleFont.setPixelSize(ui->titleFontSizeSpin->value()); |
|
834 | 844 | m_angularAxis->setTitleFont(m_currentTitleFont); |
|
835 | 845 | m_radialAxis->setTitleFont(m_currentTitleFont); |
|
836 | 846 | } |
|
837 | 847 | |
|
838 | 848 | void MainWindow::titleFontSizeChanged(int value) |
|
839 | 849 | { |
|
840 | 850 | m_currentTitleFont = ui->titleFontComboBox->currentFont(); |
|
841 | 851 | m_currentTitleFont.setPixelSize(value); |
|
842 | 852 | m_angularAxis->setTitleFont(m_currentTitleFont); |
|
843 | 853 | m_radialAxis->setTitleFont(m_currentTitleFont); |
|
844 | 854 | } |
|
845 | 855 | |
|
846 | 856 | void MainWindow::gridIndexChanged(int index) |
|
847 | 857 | { |
|
848 | 858 | delete m_gridPen; |
|
849 | 859 | |
|
850 | 860 | switch (index) { |
|
851 | 861 | case 0: |
|
852 | 862 | m_gridPen = new QPen(Qt::NoPen); |
|
853 | 863 | m_gridVisible = false; |
|
854 | 864 | break; |
|
855 | 865 | case 1: |
|
856 | 866 | m_gridPen = new QPen(Qt::black); |
|
857 | 867 | m_gridVisible = true; |
|
858 | 868 | break; |
|
859 | 869 | case 2: |
|
860 | 870 | m_gridPen = new QPen(Qt::red); |
|
861 | 871 | m_gridPen->setStyle(Qt::DashDotLine); |
|
862 | 872 | m_gridPen->setWidth(3); |
|
863 | 873 | m_gridVisible = true; |
|
864 | 874 | break; |
|
865 | 875 | default: |
|
866 | 876 | break; |
|
867 | 877 | } |
|
868 | 878 | |
|
869 | 879 | m_angularAxis->setGridLinePen(*m_gridPen); |
|
870 | 880 | m_angularAxis->setGridLineVisible(m_gridVisible); |
|
871 | 881 | m_radialAxis->setGridLinePen(*m_gridPen); |
|
872 | 882 | m_radialAxis->setGridLineVisible(m_gridVisible); |
|
873 | 883 | } |
|
874 | 884 | |
|
875 | 885 | void MainWindow::arrowIndexChanged(int index) |
|
876 | 886 | { |
|
877 | 887 | delete m_arrowPen; |
|
878 | 888 | |
|
879 | 889 | switch (index) { |
|
880 | 890 | case 0: |
|
881 | 891 | m_arrowPen = new QPen(Qt::NoPen); |
|
882 | 892 | m_arrowVisible = false; |
|
883 | 893 | break; |
|
884 | 894 | case 1: |
|
885 | 895 | m_arrowPen = new QPen(Qt::black); |
|
886 | 896 | m_arrowVisible = true; |
|
887 | 897 | break; |
|
888 | 898 | case 2: |
|
889 | 899 | m_arrowPen = new QPen(Qt::red); |
|
890 | 900 | m_arrowPen->setStyle(Qt::DashDotLine); |
|
891 | 901 | m_arrowPen->setWidth(3); |
|
892 | 902 | m_arrowVisible = true; |
|
893 | 903 | break; |
|
894 | 904 | default: |
|
895 | 905 | break; |
|
896 | 906 | } |
|
897 | 907 | |
|
898 | 908 | m_angularAxis->setLinePen(*m_arrowPen); |
|
899 | 909 | m_angularAxis->setLineVisible(m_arrowVisible); |
|
900 | 910 | m_radialAxis->setLinePen(*m_arrowPen); |
|
901 | 911 | m_radialAxis->setLineVisible(m_arrowVisible); |
|
902 | 912 | } |
|
903 | 913 | |
|
904 | 914 | void MainWindow::angularRangeChanged(qreal min, qreal max) |
|
905 | 915 | { |
|
906 | 916 | if (!qFuzzyCompare(ui->angularMinSpin->value(), min)) |
|
907 | 917 | ui->angularMinSpin->setValue(min); |
|
908 | 918 | if (!qFuzzyCompare(ui->angularMaxSpin->value(), max)) |
|
909 | 919 | ui->angularMaxSpin->setValue(max); |
|
910 | 920 | } |
|
911 | 921 | |
|
912 | 922 | void MainWindow::radialRangeChanged(qreal min, qreal max) |
|
913 | 923 | { |
|
914 | 924 | if (!qFuzzyCompare(ui->radialMinSpin->value(), min)) |
|
915 | 925 | ui->radialMinSpin->setValue(min); |
|
916 | 926 | if (!qFuzzyCompare(ui->radialMaxSpin->value(), max)) |
|
917 | 927 | ui->radialMaxSpin->setValue(max); |
|
918 | 928 | } |
|
919 | 929 | |
|
920 | 930 | void MainWindow::angularAxisIndexChanged(int index) |
|
921 | 931 | { |
|
922 | 932 | switch (index) { |
|
923 | 933 | case 0: |
|
924 | 934 | setAngularAxis(AxisModeNone); |
|
925 | 935 | break; |
|
926 | 936 | case 1: |
|
927 | 937 | setAngularAxis(AxisModeValue); |
|
928 | 938 | break; |
|
929 | 939 | case 2: |
|
930 | 940 | setAngularAxis(AxisModeLogValue); |
|
931 | 941 | break; |
|
932 | 942 | case 3: |
|
933 | 943 | setAngularAxis(AxisModeDateTime); |
|
934 | 944 | break; |
|
935 | 945 | case 4: |
|
936 | 946 | setAngularAxis(AxisModeCategory); |
|
937 | 947 | break; |
|
938 | 948 | default: |
|
939 | 949 | qWarning("Invalid Index!"); |
|
940 | 950 | } |
|
941 | 951 | } |
|
942 | 952 | |
|
943 | 953 | void MainWindow::radialAxisIndexChanged(int index) |
|
944 | 954 | { |
|
945 | 955 | switch (index) { |
|
946 | 956 | case 0: |
|
947 | 957 | setRadialAxis(AxisModeNone); |
|
948 | 958 | break; |
|
949 | 959 | case 1: |
|
950 | 960 | setRadialAxis(AxisModeValue); |
|
951 | 961 | break; |
|
952 | 962 | case 2: |
|
953 | 963 | setRadialAxis(AxisModeLogValue); |
|
954 | 964 | break; |
|
955 | 965 | case 3: |
|
956 | 966 | setRadialAxis(AxisModeDateTime); |
|
957 | 967 | break; |
|
958 | 968 | case 4: |
|
959 | 969 | setRadialAxis(AxisModeCategory); |
|
960 | 970 | break; |
|
961 | 971 | default: |
|
962 | 972 | qWarning("Invalid Index!"); |
|
963 | 973 | } |
|
964 | 974 | } |
|
965 | 975 | |
|
966 | 976 | void MainWindow::logBaseChanged(double value) |
|
967 | 977 | { |
|
968 | 978 | m_base = value; |
|
969 | 979 | if (m_angularAxisMode == AxisModeLogValue) |
|
970 | 980 | static_cast<QLogValueAxis *>(m_angularAxis)->setBase(m_base); |
|
971 | 981 | if (m_radialAxisMode == AxisModeLogValue) |
|
972 | 982 | static_cast<QLogValueAxis *>(m_radialAxis)->setBase(m_base); |
|
973 | 983 | } |
|
974 | 984 | |
|
975 | 985 | void MainWindow::niceNumbersChecked() |
|
976 | 986 | { |
|
977 | 987 | if (ui->niceNumbersCheckBox->isChecked()) |
|
978 | 988 | applyRanges(); |
|
979 | 989 | } |
|
980 | 990 | |
|
981 | 991 | void MainWindow::dateFormatEdited(const QString &text) |
|
982 | 992 | { |
|
983 | 993 | m_dateFormat = text; |
|
984 | 994 | if (m_angularAxisMode == AxisModeDateTime) |
|
985 | 995 | static_cast<QDateTimeAxis *>(m_angularAxis)->setFormat(m_dateFormat); |
|
986 | 996 | if (m_radialAxisMode == AxisModeDateTime) |
|
987 | 997 | static_cast<QDateTimeAxis *>(m_radialAxis)->setFormat(m_dateFormat); |
|
988 | 998 | } |
|
989 | 999 | |
|
990 | 1000 | void MainWindow::moreCategoriesChecked() |
|
991 | 1001 | { |
|
992 | 1002 | applyCategories(); |
|
993 | 1003 | m_moreCategories = ui->moreCategoriesCheckBox->isChecked(); |
|
994 | 1004 | } |
|
995 | 1005 | |
|
996 | 1006 | void MainWindow::series1CheckBoxChecked() |
|
997 | 1007 | { |
|
998 | 1008 | if (ui->series1checkBox->isChecked()) |
|
999 | 1009 | m_series1->setVisible(true); |
|
1000 | 1010 | else |
|
1001 | 1011 | m_series1->setVisible(false); |
|
1002 | 1012 | } |
|
1003 | 1013 | |
|
1004 | 1014 | void MainWindow::series2CheckBoxChecked() |
|
1005 | 1015 | { |
|
1006 | 1016 | if (ui->series2checkBox->isChecked()) |
|
1007 | 1017 | m_series2->setVisible(true); |
|
1008 | 1018 | else |
|
1009 | 1019 | m_series2->setVisible(false); |
|
1010 | 1020 | } |
|
1011 | 1021 | |
|
1012 | 1022 | void MainWindow::series3CheckBoxChecked() |
|
1013 | 1023 | { |
|
1014 | 1024 | if (ui->series3checkBox->isChecked()) |
|
1015 | 1025 | m_series3->setVisible(true); |
|
1016 | 1026 | else |
|
1017 | 1027 | m_series3->setVisible(false); |
|
1018 | 1028 | } |
|
1019 | 1029 | |
|
1020 | 1030 | void MainWindow::series4CheckBoxChecked() |
|
1021 | 1031 | { |
|
1022 | 1032 | if (ui->series4checkBox->isChecked()) |
|
1023 | 1033 | m_series4->setVisible(true); |
|
1024 | 1034 | else |
|
1025 | 1035 | m_series4->setVisible(false); |
|
1026 | 1036 | } |
|
1027 | 1037 | |
|
1028 | 1038 | void MainWindow::series5CheckBoxChecked() |
|
1029 | 1039 | { |
|
1030 | 1040 | if (ui->series5checkBox->isChecked()) |
|
1031 | 1041 | m_series5->setVisible(true); |
|
1032 | 1042 | else |
|
1033 | 1043 | m_series5->setVisible(false); |
|
1034 | 1044 | } |
|
1035 | 1045 | |
|
1036 | 1046 | void MainWindow::series6CheckBoxChecked() |
|
1037 | 1047 | { |
|
1038 | 1048 | if (ui->series6checkBox->isChecked()) |
|
1039 | 1049 | m_series6->setVisible(true); |
|
1040 | 1050 | else |
|
1041 | 1051 | m_series6->setVisible(false); |
|
1042 | 1052 | } |
|
1043 | 1053 | |
|
1044 | 1054 | void MainWindow::series7CheckBoxChecked() |
|
1045 | 1055 | { |
|
1046 | 1056 | if (ui->series7checkBox->isChecked()) |
|
1047 | 1057 | m_series7->setVisible(true); |
|
1048 | 1058 | else |
|
1049 | 1059 | m_series7->setVisible(false); |
|
1050 | 1060 | } |
|
1051 | 1061 | |
|
1052 | 1062 | void MainWindow::themeIndexChanged(int index) |
|
1053 | 1063 | { |
|
1054 | 1064 | m_chart->setTheme(QChart::ChartTheme(index)); |
|
1055 | 1065 | } |
|
1056 | 1066 | |
|
1057 | 1067 | void MainWindow::seriesHovered(QPointF point, bool state) |
|
1058 | 1068 | { |
|
1059 | 1069 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender()); |
|
1060 | 1070 | if (series) { |
|
1061 | 1071 | if (state) { |
|
1062 | 1072 | QString str("'%3' - %1 x %2"); |
|
1063 | 1073 | ui->hoverLabel->setText(str.arg(point.x()).arg(point.y()).arg(series->name())); |
|
1064 | 1074 | } else { |
|
1065 | 1075 | ui->hoverLabel->setText("No hover"); |
|
1066 | 1076 | } |
|
1067 | 1077 | } else { |
|
1068 | 1078 | qDebug() << "seriesHovered - invalid sender!"; |
|
1069 | 1079 | } |
|
1070 | 1080 | } |
|
1071 | 1081 | |
|
1072 | 1082 | void MainWindow::seriesClicked(const QPointF &point) |
|
1073 | 1083 | { |
|
1074 | 1084 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(sender()); |
|
1075 | 1085 | if (series) { |
|
1076 | 1086 | QString str("'%3' clicked at: %1 x %2"); |
|
1077 | 1087 | m_angularTitle = str.arg(point.x()).arg(point.y()).arg(series->name()); |
|
1078 | 1088 | m_angularAxis->setTitleText(m_angularTitle); |
|
1079 | 1089 | } else { |
|
1080 | 1090 | qDebug() << "seriesClicked - invalid sender!"; |
|
1081 | 1091 | } |
|
1082 | 1092 | } |
|
1083 | 1093 | |
|
1094 | void MainWindow::backgroundIndexChanged(int index) | |
|
1095 | { | |
|
1096 | delete m_backgroundBrush; | |
|
1097 | delete m_backgroundPen; | |
|
1098 | ||
|
1099 | switch (index) { | |
|
1100 | case 0: | |
|
1101 | m_backgroundBrush = new QBrush(Qt::white); | |
|
1102 | m_backgroundPen = new QPen(Qt::NoPen); | |
|
1103 | break; | |
|
1104 | case 1: | |
|
1105 | m_backgroundBrush = new QBrush(Qt::blue); | |
|
1106 | m_backgroundPen = new QPen(Qt::NoPen); | |
|
1107 | break; | |
|
1108 | case 2: | |
|
1109 | m_backgroundBrush = new QBrush(Qt::yellow); | |
|
1110 | m_backgroundPen = new QPen(Qt::black, 2); | |
|
1111 | break; | |
|
1112 | default: | |
|
1113 | break; | |
|
1114 | } | |
|
1115 | m_chart->setBackgroundBrush(*m_backgroundBrush); | |
|
1116 | m_chart->setBackgroundPen(*m_backgroundPen); | |
|
1117 | } | |
|
1118 | ||
|
1119 | void MainWindow::plotAreaIndexChanged(int index) | |
|
1120 | { | |
|
1121 | delete m_plotAreaBackgroundBrush; | |
|
1122 | delete m_plotAreaBackgroundPen; | |
|
1123 | ||
|
1124 | switch (index) { | |
|
1125 | case 0: | |
|
1126 | m_plotAreaBackgroundBrush = new QBrush(Qt::green); | |
|
1127 | m_plotAreaBackgroundPen = new QPen(Qt::green); | |
|
1128 | m_chart->setPlotAreaBackgroundVisible(false); | |
|
1129 | break; | |
|
1130 | case 1: | |
|
1131 | m_plotAreaBackgroundBrush = new QBrush(Qt::magenta); | |
|
1132 | m_plotAreaBackgroundPen = new QPen(Qt::NoPen); | |
|
1133 | m_chart->setPlotAreaBackgroundVisible(true); | |
|
1134 | break; | |
|
1135 | case 2: | |
|
1136 | m_plotAreaBackgroundBrush = new QBrush(Qt::lightGray); | |
|
1137 | m_plotAreaBackgroundPen = new QPen(Qt::red, 6); | |
|
1138 | m_chart->setPlotAreaBackgroundVisible(true); | |
|
1139 | break; | |
|
1140 | default: | |
|
1141 | break; | |
|
1142 | } | |
|
1143 | m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush); | |
|
1144 | m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen); | |
|
1145 | } | |
|
1146 | ||
|
1084 | 1147 | void MainWindow::applyCategories() |
|
1085 | 1148 | { |
|
1086 | 1149 | // Basic layout is three categories, extended has five |
|
1087 | 1150 | if (m_angularAxisMode == AxisModeCategory) { |
|
1088 | 1151 | QCategoryAxis *angCatAxis = static_cast<QCategoryAxis *>(m_angularAxis); |
|
1089 | 1152 | if (angCatAxis->count() == 0) { |
|
1090 | 1153 | angCatAxis->setStartValue(4000); |
|
1091 | 1154 | angCatAxis->append("Category A", 7000); |
|
1092 | 1155 | angCatAxis->append("Category B", 12000); |
|
1093 | 1156 | angCatAxis->append("Category C", 17000); |
|
1094 | 1157 | } |
|
1095 | 1158 | if (angCatAxis->count() == 3 && ui->moreCategoriesCheckBox->isChecked()) { |
|
1096 | 1159 | angCatAxis->setStartValue(1000); |
|
1097 | 1160 | angCatAxis->replaceLabel("Category A", "Cat A"); |
|
1098 | 1161 | angCatAxis->replaceLabel("Category B", "Cat B"); |
|
1099 | 1162 | angCatAxis->replaceLabel("Category C", "Cat C"); |
|
1100 | 1163 | angCatAxis->append("Cat D", 22000); |
|
1101 | 1164 | angCatAxis->append("Cat E", 28000); |
|
1102 | 1165 | } else if (angCatAxis->count() == 5 && !ui->moreCategoriesCheckBox->isChecked()) { |
|
1103 | 1166 | angCatAxis->setStartValue(4000); |
|
1104 | 1167 | angCatAxis->replaceLabel("Cat A", "Category A"); |
|
1105 | 1168 | angCatAxis->replaceLabel("Cat B", "Category B"); |
|
1106 | 1169 | angCatAxis->replaceLabel("Cat C", "Category C"); |
|
1107 | 1170 | angCatAxis->remove("Cat D"); |
|
1108 | 1171 | angCatAxis->remove("Cat E"); |
|
1109 | 1172 | } |
|
1110 | 1173 | } |
|
1111 | 1174 | |
|
1112 | 1175 | if (m_radialAxisMode == AxisModeCategory) { |
|
1113 | 1176 | QCategoryAxis *radCatAxis = static_cast<QCategoryAxis *>(m_radialAxis); |
|
1114 | 1177 | if (radCatAxis->count() == 0) { |
|
1115 | 1178 | radCatAxis->setStartValue(2000); |
|
1116 | 1179 | radCatAxis->append("Category 1", 4000); |
|
1117 | 1180 | radCatAxis->append("Category 2", 9000); |
|
1118 | 1181 | radCatAxis->append("Category 3", 14000); |
|
1119 | 1182 | } |
|
1120 | 1183 | if (radCatAxis->count() == 3 && ui->moreCategoriesCheckBox->isChecked()) { |
|
1121 | 1184 | radCatAxis->setStartValue(1000); |
|
1122 | 1185 | radCatAxis->replaceLabel("Category 1", "Cat 1"); |
|
1123 | 1186 | radCatAxis->replaceLabel("Category 2", "Cat 2"); |
|
1124 | 1187 | radCatAxis->replaceLabel("Category 3", "Cat 3"); |
|
1125 | 1188 | radCatAxis->append("Cat 4", 16500); |
|
1126 | 1189 | radCatAxis->append("Cat 5", 19000); |
|
1127 | 1190 | } else if (radCatAxis->count() == 5 && !ui->moreCategoriesCheckBox->isChecked()) { |
|
1128 | 1191 | radCatAxis->setStartValue(2000); |
|
1129 | 1192 | radCatAxis->replaceLabel("Cat 1", "Category 1"); |
|
1130 | 1193 | radCatAxis->replaceLabel("Cat 2", "Category 2"); |
|
1131 | 1194 | radCatAxis->replaceLabel("Cat 3", "Category 3"); |
|
1132 | 1195 | radCatAxis->remove("Cat 4"); |
|
1133 | 1196 | radCatAxis->remove("Cat 5"); |
|
1134 | 1197 | } |
|
1135 | 1198 | } |
|
1136 | 1199 | } |
@@ -1,155 +1,161 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 MAINWINDOW_H |
|
22 | 22 | #define MAINWINDOW_H |
|
23 | 23 | |
|
24 | 24 | #include <QPolarChart> |
|
25 | 25 | #include <QMainWindow> |
|
26 | 26 | #include <QFont> |
|
27 | 27 | #include <QChart> |
|
28 | 28 | #include <QScatterSeries> |
|
29 | 29 | #include <QLineSeries> |
|
30 | 30 | #include <QSplineSeries> |
|
31 | 31 | #include <QAreaSeries> |
|
32 | 32 | |
|
33 | 33 | namespace Ui { |
|
34 | 34 | class MainWindow; |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class QBrush; |
|
40 | 40 | class QPen; |
|
41 | 41 | |
|
42 | 42 | class MainWindow : public QMainWindow |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | |
|
46 | 46 | public: |
|
47 | 47 | explicit MainWindow(QWidget *parent = 0); |
|
48 | 48 | ~MainWindow(); |
|
49 | 49 | |
|
50 | 50 | public slots: |
|
51 | 51 | void angularTicksChanged(int value); |
|
52 | 52 | void radialTicksChanged(int value); |
|
53 | 53 | void anglesChanged(int value); |
|
54 | 54 | void angularMinChanged(double value); |
|
55 | 55 | void angularMaxChanged(double value); |
|
56 | 56 | void radialMinChanged(double value); |
|
57 | 57 | void radialMaxChanged(double value); |
|
58 | 58 | void angularShadesIndexChanged(int index); |
|
59 | 59 | void radialShadesIndexChanged(int index); |
|
60 | 60 | void labelFormatEdited(const QString &text); |
|
61 | 61 | void labelFontChanged(const QFont &font); |
|
62 | 62 | void labelFontSizeChanged(int value); |
|
63 | 63 | void animationIndexChanged(int index); |
|
64 | 64 | void labelsIndexChanged(int index); |
|
65 | 65 | void titleIndexChanged(int index); |
|
66 | 66 | void titleFontChanged(const QFont &font); |
|
67 | 67 | void titleFontSizeChanged(int value); |
|
68 | 68 | void gridIndexChanged(int index); |
|
69 | 69 | void arrowIndexChanged(int index); |
|
70 | 70 | void angularRangeChanged(qreal min, qreal max); |
|
71 | 71 | void radialRangeChanged(qreal min, qreal max); |
|
72 | 72 | void angularAxisIndexChanged(int index); |
|
73 | 73 | void radialAxisIndexChanged(int index); |
|
74 | 74 | void logBaseChanged(double value); |
|
75 | 75 | void niceNumbersChecked(); |
|
76 | 76 | void dateFormatEdited(const QString &text); |
|
77 | 77 | void moreCategoriesChecked(); |
|
78 | 78 | void series1CheckBoxChecked(); |
|
79 | 79 | void series2CheckBoxChecked(); |
|
80 | 80 | void series3CheckBoxChecked(); |
|
81 | 81 | void series4CheckBoxChecked(); |
|
82 | 82 | void series5CheckBoxChecked(); |
|
83 | 83 | void series6CheckBoxChecked(); |
|
84 | 84 | void series7CheckBoxChecked(); |
|
85 | 85 | void themeIndexChanged(int index); |
|
86 | 86 | void seriesHovered(QPointF point, bool state); |
|
87 | 87 | void seriesClicked(const QPointF &point); |
|
88 | void backgroundIndexChanged(int index); | |
|
89 | void plotAreaIndexChanged(int index); | |
|
88 | 90 | |
|
89 | 91 | private: |
|
90 | 92 | enum AxisMode { |
|
91 | 93 | AxisModeNone, |
|
92 | 94 | AxisModeValue, |
|
93 | 95 | AxisModeLogValue, |
|
94 | 96 | AxisModeDateTime, |
|
95 | 97 | AxisModeCategory |
|
96 | 98 | }; |
|
97 | 99 | |
|
98 | 100 | void initXYValueChart(); |
|
99 | 101 | void setAngularAxis(AxisMode mode); |
|
100 | 102 | void setRadialAxis(AxisMode mode); |
|
101 | 103 | |
|
102 | 104 | void applyRanges(); |
|
103 | 105 | void applyCategories(); |
|
104 | 106 | |
|
105 | 107 | Ui::MainWindow *ui; |
|
106 | 108 | |
|
107 | 109 | int m_angularTickCount; |
|
108 | 110 | int m_radialTickCount; |
|
109 | 111 | qreal m_labelsAngle; |
|
110 | 112 | qreal m_angularMin; |
|
111 | 113 | qreal m_angularMax; |
|
112 | 114 | qreal m_radialMin; |
|
113 | 115 | qreal m_radialMax; |
|
114 | 116 | bool m_angularShadesVisible; |
|
115 | 117 | bool m_radialShadesVisible; |
|
116 | 118 | bool m_labelsVisible; |
|
117 | 119 | bool m_titleVisible; |
|
118 | 120 | bool m_gridVisible; |
|
119 | 121 | bool m_arrowVisible; |
|
120 | 122 | QBrush *m_angularShadesBrush; |
|
121 | 123 | QBrush *m_radialShadesBrush; |
|
122 | 124 | QBrush *m_labelBrush; |
|
123 | 125 | QBrush *m_titleBrush; |
|
126 | QBrush *m_backgroundBrush; | |
|
127 | QBrush *m_plotAreaBackgroundBrush; | |
|
124 | 128 | QPen *m_angularShadesPen; |
|
125 | 129 | QPen *m_radialShadesPen; |
|
126 | 130 | QPen *m_labelPen; |
|
127 | 131 | QPen *m_titlePen; |
|
128 | 132 | QPen *m_gridPen; |
|
129 | 133 | QPen *m_arrowPen; |
|
134 | QPen *m_backgroundPen; | |
|
135 | QPen *m_plotAreaBackgroundPen; | |
|
130 | 136 | QString m_labelFormat; |
|
131 | 137 | QFont m_currentLabelFont; |
|
132 | 138 | QFont m_currentTitleFont; |
|
133 | 139 | QChart::AnimationOptions m_animationOptions; |
|
134 | 140 | QString m_angularTitle; |
|
135 | 141 | QString m_radialTitle; |
|
136 | 142 | qreal m_base; |
|
137 | 143 | QString m_dateFormat; |
|
138 | 144 | |
|
139 | 145 | QPolarChart *m_chart; |
|
140 | 146 | QAbstractAxis *m_angularAxis; |
|
141 | 147 | QAbstractAxis *m_radialAxis; |
|
142 | 148 | AxisMode m_angularAxisMode; |
|
143 | 149 | AxisMode m_radialAxisMode; |
|
144 | 150 | bool m_moreCategories; |
|
145 | 151 | |
|
146 | 152 | QScatterSeries *m_series1; |
|
147 | 153 | QLineSeries *m_series2; |
|
148 | 154 | QLineSeries *m_series3; |
|
149 | 155 | QLineSeries *m_series4; |
|
150 | 156 | QAreaSeries *m_series5; |
|
151 | 157 | QSplineSeries *m_series6; |
|
152 | 158 | QScatterSeries *m_series7; |
|
153 | 159 | }; |
|
154 | 160 | |
|
155 | 161 | #endif // MAINWINDOW_H |
@@ -1,929 +1,997 | |||
|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?> |
|
2 | 2 | <ui version="4.0"> |
|
3 | 3 | <class>MainWindow</class> |
|
4 | 4 | <widget class="QMainWindow" name="MainWindow"> |
|
5 | 5 | <property name="geometry"> |
|
6 | 6 | <rect> |
|
7 | 7 | <x>0</x> |
|
8 | 8 | <y>0</y> |
|
9 |
<width>1 |
|
|
10 |
<height>9 |
|
|
9 | <width>1193</width> | |
|
10 | <height>956</height> | |
|
11 | 11 | </rect> |
|
12 | 12 | </property> |
|
13 | 13 | <property name="windowTitle"> |
|
14 | 14 | <string>MainWindow</string> |
|
15 | 15 | </property> |
|
16 | 16 | <widget class="QWidget" name="centralWidget"> |
|
17 | 17 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
18 | 18 | <item> |
|
19 | 19 | <widget class="ChartView" name="chartView"/> |
|
20 | 20 | </item> |
|
21 | 21 | <item> |
|
22 | 22 | <widget class="QGroupBox" name="settingsBox"> |
|
23 | 23 | <property name="sizePolicy"> |
|
24 | 24 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> |
|
25 | 25 | <horstretch>0</horstretch> |
|
26 | 26 | <verstretch>0</verstretch> |
|
27 | 27 | </sizepolicy> |
|
28 | 28 | </property> |
|
29 | 29 | <property name="minimumSize"> |
|
30 | 30 | <size> |
|
31 | 31 | <width>200</width> |
|
32 | 32 | <height>0</height> |
|
33 | 33 | </size> |
|
34 | 34 | </property> |
|
35 | 35 | <property name="title"> |
|
36 | 36 | <string>Settings</string> |
|
37 | 37 | </property> |
|
38 | 38 | <widget class="QSpinBox" name="radialTicksSpin"> |
|
39 | 39 | <property name="geometry"> |
|
40 | 40 | <rect> |
|
41 | 41 | <x>110</x> |
|
42 | 42 | <y>90</y> |
|
43 | 43 | <width>71</width> |
|
44 | 44 | <height>22</height> |
|
45 | 45 | </rect> |
|
46 | 46 | </property> |
|
47 | 47 | </widget> |
|
48 | 48 | <widget class="QLabel" name="label"> |
|
49 | 49 | <property name="geometry"> |
|
50 | 50 | <rect> |
|
51 | 51 | <x>10</x> |
|
52 | 52 | <y>90</y> |
|
53 | 53 | <width>101</width> |
|
54 | 54 | <height>16</height> |
|
55 | 55 | </rect> |
|
56 | 56 | </property> |
|
57 | 57 | <property name="text"> |
|
58 | 58 | <string>Radial Tick count</string> |
|
59 | 59 | </property> |
|
60 | 60 | </widget> |
|
61 | 61 | <widget class="QLabel" name="label_2"> |
|
62 | 62 | <property name="geometry"> |
|
63 | 63 | <rect> |
|
64 | 64 | <x>10</x> |
|
65 | 65 | <y>120</y> |
|
66 | 66 | <width>101</width> |
|
67 | 67 | <height>16</height> |
|
68 | 68 | </rect> |
|
69 | 69 | </property> |
|
70 | 70 | <property name="text"> |
|
71 | 71 | <string>Angular Tick count</string> |
|
72 | 72 | </property> |
|
73 | 73 | </widget> |
|
74 | 74 | <widget class="QSpinBox" name="angularTicksSpin"> |
|
75 | 75 | <property name="geometry"> |
|
76 | 76 | <rect> |
|
77 | 77 | <x>110</x> |
|
78 | 78 | <y>120</y> |
|
79 | 79 | <width>71</width> |
|
80 | 80 | <height>22</height> |
|
81 | 81 | </rect> |
|
82 | 82 | </property> |
|
83 | 83 | </widget> |
|
84 | 84 | <widget class="QSpinBox" name="anglesSpin"> |
|
85 | 85 | <property name="geometry"> |
|
86 | 86 | <rect> |
|
87 | 87 | <x>110</x> |
|
88 | 88 | <y>150</y> |
|
89 | 89 | <width>71</width> |
|
90 | 90 | <height>22</height> |
|
91 | 91 | </rect> |
|
92 | 92 | </property> |
|
93 | 93 | <property name="minimum"> |
|
94 | 94 | <number>-9999</number> |
|
95 | 95 | </property> |
|
96 | 96 | <property name="maximum"> |
|
97 | 97 | <number>9999</number> |
|
98 | 98 | </property> |
|
99 | 99 | <property name="singleStep"> |
|
100 | 100 | <number>5</number> |
|
101 | 101 | </property> |
|
102 | 102 | </widget> |
|
103 | 103 | <widget class="QLabel" name="label_3"> |
|
104 | 104 | <property name="geometry"> |
|
105 | 105 | <rect> |
|
106 | 106 | <x>10</x> |
|
107 | 107 | <y>150</y> |
|
108 | 108 | <width>101</width> |
|
109 | 109 | <height>16</height> |
|
110 | 110 | </rect> |
|
111 | 111 | </property> |
|
112 | 112 | <property name="text"> |
|
113 | 113 | <string>Label angles</string> |
|
114 | 114 | </property> |
|
115 | 115 | </widget> |
|
116 | 116 | <widget class="QLabel" name="label_4"> |
|
117 | 117 | <property name="geometry"> |
|
118 | 118 | <rect> |
|
119 | 119 | <x>10</x> |
|
120 | 120 | <y>180</y> |
|
121 | 121 | <width>101</width> |
|
122 | 122 | <height>16</height> |
|
123 | 123 | </rect> |
|
124 | 124 | </property> |
|
125 | 125 | <property name="text"> |
|
126 | 126 | <string>Angular min</string> |
|
127 | 127 | </property> |
|
128 | 128 | </widget> |
|
129 | 129 | <widget class="QLabel" name="label_5"> |
|
130 | 130 | <property name="geometry"> |
|
131 | 131 | <rect> |
|
132 | 132 | <x>10</x> |
|
133 | 133 | <y>210</y> |
|
134 | 134 | <width>101</width> |
|
135 | 135 | <height>16</height> |
|
136 | 136 | </rect> |
|
137 | 137 | </property> |
|
138 | 138 | <property name="text"> |
|
139 | 139 | <string>Angular max</string> |
|
140 | 140 | </property> |
|
141 | 141 | </widget> |
|
142 | 142 | <widget class="QDoubleSpinBox" name="angularMinSpin"> |
|
143 | 143 | <property name="geometry"> |
|
144 | 144 | <rect> |
|
145 | 145 | <x>90</x> |
|
146 | 146 | <y>180</y> |
|
147 | 147 | <width>91</width> |
|
148 | 148 | <height>22</height> |
|
149 | 149 | </rect> |
|
150 | 150 | </property> |
|
151 | 151 | <property name="decimals"> |
|
152 | 152 | <number>5</number> |
|
153 | 153 | </property> |
|
154 | 154 | <property name="minimum"> |
|
155 | 155 | <double>-999999999.000000000000000</double> |
|
156 | 156 | </property> |
|
157 | 157 | <property name="maximum"> |
|
158 | 158 | <double>999999999.000000000000000</double> |
|
159 | 159 | </property> |
|
160 | 160 | <property name="singleStep"> |
|
161 | 161 | <double>10.000000000000000</double> |
|
162 | 162 | </property> |
|
163 | 163 | </widget> |
|
164 | 164 | <widget class="QDoubleSpinBox" name="angularMaxSpin"> |
|
165 | 165 | <property name="geometry"> |
|
166 | 166 | <rect> |
|
167 | 167 | <x>90</x> |
|
168 | 168 | <y>210</y> |
|
169 | 169 | <width>91</width> |
|
170 | 170 | <height>22</height> |
|
171 | 171 | </rect> |
|
172 | 172 | </property> |
|
173 | 173 | <property name="decimals"> |
|
174 | 174 | <number>5</number> |
|
175 | 175 | </property> |
|
176 | 176 | <property name="minimum"> |
|
177 | 177 | <double>-999999999.000000000000000</double> |
|
178 | 178 | </property> |
|
179 | 179 | <property name="maximum"> |
|
180 | 180 | <double>999999999.000000000000000</double> |
|
181 | 181 | </property> |
|
182 | 182 | <property name="singleStep"> |
|
183 | 183 | <double>10.000000000000000</double> |
|
184 | 184 | </property> |
|
185 | 185 | </widget> |
|
186 | 186 | <widget class="QDoubleSpinBox" name="radialMaxSpin"> |
|
187 | 187 | <property name="geometry"> |
|
188 | 188 | <rect> |
|
189 | 189 | <x>90</x> |
|
190 | 190 | <y>270</y> |
|
191 | 191 | <width>91</width> |
|
192 | 192 | <height>22</height> |
|
193 | 193 | </rect> |
|
194 | 194 | </property> |
|
195 | 195 | <property name="decimals"> |
|
196 | 196 | <number>5</number> |
|
197 | 197 | </property> |
|
198 | 198 | <property name="minimum"> |
|
199 | 199 | <double>-999999999.000000000000000</double> |
|
200 | 200 | </property> |
|
201 | 201 | <property name="maximum"> |
|
202 | 202 | <double>999999999.000000000000000</double> |
|
203 | 203 | </property> |
|
204 | 204 | <property name="singleStep"> |
|
205 | 205 | <double>10.000000000000000</double> |
|
206 | 206 | </property> |
|
207 | 207 | </widget> |
|
208 | 208 | <widget class="QDoubleSpinBox" name="radialMinSpin"> |
|
209 | 209 | <property name="geometry"> |
|
210 | 210 | <rect> |
|
211 | 211 | <x>90</x> |
|
212 | 212 | <y>240</y> |
|
213 | 213 | <width>91</width> |
|
214 | 214 | <height>22</height> |
|
215 | 215 | </rect> |
|
216 | 216 | </property> |
|
217 | 217 | <property name="decimals"> |
|
218 | 218 | <number>5</number> |
|
219 | 219 | </property> |
|
220 | 220 | <property name="minimum"> |
|
221 | 221 | <double>-999999999.000000000000000</double> |
|
222 | 222 | </property> |
|
223 | 223 | <property name="maximum"> |
|
224 | 224 | <double>999999999.000000000000000</double> |
|
225 | 225 | </property> |
|
226 | 226 | <property name="singleStep"> |
|
227 | 227 | <double>10.000000000000000</double> |
|
228 | 228 | </property> |
|
229 | 229 | </widget> |
|
230 | 230 | <widget class="QLabel" name="label_11"> |
|
231 | 231 | <property name="geometry"> |
|
232 | 232 | <rect> |
|
233 | 233 | <x>10</x> |
|
234 | 234 | <y>270</y> |
|
235 | 235 | <width>101</width> |
|
236 | 236 | <height>16</height> |
|
237 | 237 | </rect> |
|
238 | 238 | </property> |
|
239 | 239 | <property name="text"> |
|
240 | 240 | <string>Radial max</string> |
|
241 | 241 | </property> |
|
242 | 242 | </widget> |
|
243 | 243 | <widget class="QLabel" name="label_12"> |
|
244 | 244 | <property name="geometry"> |
|
245 | 245 | <rect> |
|
246 | 246 | <x>10</x> |
|
247 | 247 | <y>240</y> |
|
248 | 248 | <width>101</width> |
|
249 | 249 | <height>16</height> |
|
250 | 250 | </rect> |
|
251 | 251 | </property> |
|
252 | 252 | <property name="text"> |
|
253 | 253 | <string>Radial min</string> |
|
254 | 254 | </property> |
|
255 | 255 | </widget> |
|
256 | 256 | <widget class="QComboBox" name="angularShadesComboBox"> |
|
257 | 257 | <property name="geometry"> |
|
258 | 258 | <rect> |
|
259 | 259 | <x>10</x> |
|
260 | 260 | <y>300</y> |
|
261 | 261 | <width>171</width> |
|
262 | 262 | <height>22</height> |
|
263 | 263 | </rect> |
|
264 | 264 | </property> |
|
265 | 265 | <item> |
|
266 | 266 | <property name="text"> |
|
267 | 267 | <string>No angular shades</string> |
|
268 | 268 | </property> |
|
269 | 269 | </item> |
|
270 | 270 | <item> |
|
271 | 271 | <property name="text"> |
|
272 | 272 | <string>Gray angular shades</string> |
|
273 | 273 | </property> |
|
274 | 274 | </item> |
|
275 | 275 | <item> |
|
276 | 276 | <property name="text"> |
|
277 | 277 | <string>Yellow ang. shades + custom pen</string> |
|
278 | 278 | </property> |
|
279 | 279 | </item> |
|
280 | 280 | </widget> |
|
281 | 281 | <widget class="QComboBox" name="radialShadesComboBox"> |
|
282 | 282 | <property name="geometry"> |
|
283 | 283 | <rect> |
|
284 | 284 | <x>10</x> |
|
285 | 285 | <y>330</y> |
|
286 | 286 | <width>171</width> |
|
287 | 287 | <height>22</height> |
|
288 | 288 | </rect> |
|
289 | 289 | </property> |
|
290 | 290 | <item> |
|
291 | 291 | <property name="text"> |
|
292 | 292 | <string>No radial shades</string> |
|
293 | 293 | </property> |
|
294 | 294 | </item> |
|
295 | 295 | <item> |
|
296 | 296 | <property name="text"> |
|
297 | 297 | <string>Green radial shades</string> |
|
298 | 298 | </property> |
|
299 | 299 | </item> |
|
300 | 300 | <item> |
|
301 | 301 | <property name="text"> |
|
302 | 302 | <string>Blue rad. shades + custom pen</string> |
|
303 | 303 | </property> |
|
304 | 304 | </item> |
|
305 | 305 | </widget> |
|
306 | 306 | <widget class="QLabel" name="label_13"> |
|
307 | 307 | <property name="geometry"> |
|
308 | 308 | <rect> |
|
309 | 309 | <x>10</x> |
|
310 | 310 | <y>360</y> |
|
311 | 311 | <width>101</width> |
|
312 | 312 | <height>16</height> |
|
313 | 313 | </rect> |
|
314 | 314 | </property> |
|
315 | 315 | <property name="text"> |
|
316 | 316 | <string>Label format</string> |
|
317 | 317 | </property> |
|
318 | 318 | </widget> |
|
319 | 319 | <widget class="QLineEdit" name="labelFormatEdit"> |
|
320 | 320 | <property name="geometry"> |
|
321 | 321 | <rect> |
|
322 | 322 | <x>100</x> |
|
323 | 323 | <y>360</y> |
|
324 | 324 | <width>81</width> |
|
325 | 325 | <height>20</height> |
|
326 | 326 | </rect> |
|
327 | 327 | </property> |
|
328 | 328 | </widget> |
|
329 | 329 | <widget class="QLabel" name="label_14"> |
|
330 | 330 | <property name="geometry"> |
|
331 | 331 | <rect> |
|
332 | 332 | <x>10</x> |
|
333 | 333 | <y>390</y> |
|
334 | 334 | <width>101</width> |
|
335 | 335 | <height>16</height> |
|
336 | 336 | </rect> |
|
337 | 337 | </property> |
|
338 | 338 | <property name="text"> |
|
339 | 339 | <string>Label font size</string> |
|
340 | 340 | </property> |
|
341 | 341 | </widget> |
|
342 | 342 | <widget class="QFontComboBox" name="labelFontComboBox"> |
|
343 | 343 | <property name="geometry"> |
|
344 | 344 | <rect> |
|
345 | 345 | <x>10</x> |
|
346 | 346 | <y>420</y> |
|
347 | 347 | <width>171</width> |
|
348 | 348 | <height>22</height> |
|
349 | 349 | </rect> |
|
350 | 350 | </property> |
|
351 | 351 | </widget> |
|
352 | 352 | <widget class="QSpinBox" name="labelFontSizeSpin"> |
|
353 | 353 | <property name="geometry"> |
|
354 | 354 | <rect> |
|
355 | 355 | <x>100</x> |
|
356 | 356 | <y>390</y> |
|
357 | 357 | <width>81</width> |
|
358 | 358 | <height>22</height> |
|
359 | 359 | </rect> |
|
360 | 360 | </property> |
|
361 | 361 | <property name="minimum"> |
|
362 | 362 | <number>-100000</number> |
|
363 | 363 | </property> |
|
364 | 364 | <property name="maximum"> |
|
365 | 365 | <number>100000</number> |
|
366 | 366 | </property> |
|
367 | 367 | </widget> |
|
368 | 368 | <widget class="QComboBox" name="animationsComboBox"> |
|
369 | 369 | <property name="geometry"> |
|
370 | 370 | <rect> |
|
371 | 371 | <x>10</x> |
|
372 | 372 | <y>480</y> |
|
373 | 373 | <width>171</width> |
|
374 | 374 | <height>22</height> |
|
375 | 375 | </rect> |
|
376 | 376 | </property> |
|
377 | 377 | <item> |
|
378 | 378 | <property name="text"> |
|
379 | 379 | <string>No animations</string> |
|
380 | 380 | </property> |
|
381 | 381 | </item> |
|
382 | 382 | <item> |
|
383 | 383 | <property name="text"> |
|
384 | 384 | <string>Series animation</string> |
|
385 | 385 | </property> |
|
386 | 386 | </item> |
|
387 | 387 | <item> |
|
388 | 388 | <property name="text"> |
|
389 | 389 | <string>Grid animation</string> |
|
390 | 390 | </property> |
|
391 | 391 | </item> |
|
392 | 392 | <item> |
|
393 | 393 | <property name="text"> |
|
394 | 394 | <string>All animations</string> |
|
395 | 395 | </property> |
|
396 | 396 | </item> |
|
397 | 397 | </widget> |
|
398 | 398 | <widget class="QComboBox" name="labelComboBox"> |
|
399 | 399 | <property name="geometry"> |
|
400 | 400 | <rect> |
|
401 | 401 | <x>10</x> |
|
402 | 402 | <y>450</y> |
|
403 | 403 | <width>171</width> |
|
404 | 404 | <height>22</height> |
|
405 | 405 | </rect> |
|
406 | 406 | </property> |
|
407 | 407 | <property name="currentIndex"> |
|
408 | 408 | <number>1</number> |
|
409 | 409 | </property> |
|
410 | 410 | <item> |
|
411 | 411 | <property name="text"> |
|
412 | 412 | <string>No labels</string> |
|
413 | 413 | </property> |
|
414 | 414 | </item> |
|
415 | 415 | <item> |
|
416 | 416 | <property name="text"> |
|
417 | 417 | <string>Black label</string> |
|
418 | 418 | </property> |
|
419 | 419 | </item> |
|
420 | 420 | <item> |
|
421 | 421 | <property name="text"> |
|
422 | 422 | <string>White label + blue pen</string> |
|
423 | 423 | </property> |
|
424 | 424 | </item> |
|
425 | 425 | </widget> |
|
426 | 426 | <widget class="QSpinBox" name="titleFontSizeSpin"> |
|
427 | 427 | <property name="geometry"> |
|
428 | 428 | <rect> |
|
429 | 429 | <x>100</x> |
|
430 | 430 | <y>510</y> |
|
431 | 431 | <width>81</width> |
|
432 | 432 | <height>22</height> |
|
433 | 433 | </rect> |
|
434 | 434 | </property> |
|
435 | 435 | <property name="minimum"> |
|
436 | 436 | <number>-100000</number> |
|
437 | 437 | </property> |
|
438 | 438 | <property name="maximum"> |
|
439 | 439 | <number>100000</number> |
|
440 | 440 | </property> |
|
441 | 441 | </widget> |
|
442 | 442 | <widget class="QComboBox" name="titleComboBox"> |
|
443 | 443 | <property name="geometry"> |
|
444 | 444 | <rect> |
|
445 | 445 | <x>10</x> |
|
446 | 446 | <y>570</y> |
|
447 | 447 | <width>171</width> |
|
448 | 448 | <height>22</height> |
|
449 | 449 | </rect> |
|
450 | 450 | </property> |
|
451 | 451 | <property name="sizePolicy"> |
|
452 | 452 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
|
453 | 453 | <horstretch>0</horstretch> |
|
454 | 454 | <verstretch>0</verstretch> |
|
455 | 455 | </sizepolicy> |
|
456 | 456 | </property> |
|
457 | 457 | <property name="currentIndex"> |
|
458 | 458 | <number>3</number> |
|
459 | 459 | </property> |
|
460 | 460 | <item> |
|
461 | 461 | <property name="text"> |
|
462 | 462 | <string>Invisible empty title</string> |
|
463 | 463 | </property> |
|
464 | 464 | </item> |
|
465 | 465 | <item> |
|
466 | 466 | <property name="text"> |
|
467 | 467 | <string>Visible empty title</string> |
|
468 | 468 | </property> |
|
469 | 469 | </item> |
|
470 | 470 | <item> |
|
471 | 471 | <property name="text"> |
|
472 | 472 | <string>Invisible title</string> |
|
473 | 473 | </property> |
|
474 | 474 | </item> |
|
475 | 475 | <item> |
|
476 | 476 | <property name="text"> |
|
477 | 477 | <string>Black title</string> |
|
478 | 478 | </property> |
|
479 | 479 | </item> |
|
480 | 480 | <item> |
|
481 | 481 | <property name="text"> |
|
482 | 482 | <string>White title + blue pen</string> |
|
483 | 483 | </property> |
|
484 | 484 | </item> |
|
485 | 485 | </widget> |
|
486 | 486 | <widget class="QFontComboBox" name="titleFontComboBox"> |
|
487 | 487 | <property name="geometry"> |
|
488 | 488 | <rect> |
|
489 | 489 | <x>10</x> |
|
490 | 490 | <y>540</y> |
|
491 | 491 | <width>171</width> |
|
492 | 492 | <height>22</height> |
|
493 | 493 | </rect> |
|
494 | 494 | </property> |
|
495 | 495 | </widget> |
|
496 | 496 | <widget class="QLabel" name="label_15"> |
|
497 | 497 | <property name="geometry"> |
|
498 | 498 | <rect> |
|
499 | 499 | <x>10</x> |
|
500 | 500 | <y>510</y> |
|
501 | 501 | <width>101</width> |
|
502 | 502 | <height>16</height> |
|
503 | 503 | </rect> |
|
504 | 504 | </property> |
|
505 | 505 | <property name="text"> |
|
506 | 506 | <string>Title font size</string> |
|
507 | 507 | </property> |
|
508 | 508 | </widget> |
|
509 | 509 | <widget class="QComboBox" name="gridComboBox"> |
|
510 | 510 | <property name="geometry"> |
|
511 | 511 | <rect> |
|
512 | 512 | <x>10</x> |
|
513 | 513 | <y>600</y> |
|
514 | 514 | <width>171</width> |
|
515 | 515 | <height>22</height> |
|
516 | 516 | </rect> |
|
517 | 517 | </property> |
|
518 | 518 | <property name="sizePolicy"> |
|
519 | 519 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
|
520 | 520 | <horstretch>0</horstretch> |
|
521 | 521 | <verstretch>0</verstretch> |
|
522 | 522 | </sizepolicy> |
|
523 | 523 | </property> |
|
524 | 524 | <property name="currentIndex"> |
|
525 | 525 | <number>1</number> |
|
526 | 526 | </property> |
|
527 | 527 | <item> |
|
528 | 528 | <property name="text"> |
|
529 | 529 | <string>Invisible grid</string> |
|
530 | 530 | </property> |
|
531 | 531 | </item> |
|
532 | 532 | <item> |
|
533 | 533 | <property name="text"> |
|
534 | 534 | <string>Black grid</string> |
|
535 | 535 | </property> |
|
536 | 536 | </item> |
|
537 | 537 | <item> |
|
538 | 538 | <property name="text"> |
|
539 | 539 | <string>Custom grid pen</string> |
|
540 | 540 | </property> |
|
541 | 541 | </item> |
|
542 | 542 | </widget> |
|
543 | 543 | <widget class="QComboBox" name="arrowComboBox"> |
|
544 | 544 | <property name="geometry"> |
|
545 | 545 | <rect> |
|
546 | 546 | <x>10</x> |
|
547 | 547 | <y>630</y> |
|
548 | 548 | <width>171</width> |
|
549 | 549 | <height>22</height> |
|
550 | 550 | </rect> |
|
551 | 551 | </property> |
|
552 | 552 | <property name="sizePolicy"> |
|
553 | 553 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
|
554 | 554 | <horstretch>0</horstretch> |
|
555 | 555 | <verstretch>0</verstretch> |
|
556 | 556 | </sizepolicy> |
|
557 | 557 | </property> |
|
558 | 558 | <property name="currentIndex"> |
|
559 | 559 | <number>1</number> |
|
560 | 560 | </property> |
|
561 | 561 | <item> |
|
562 | 562 | <property name="text"> |
|
563 | 563 | <string>Invisible arrow</string> |
|
564 | 564 | </property> |
|
565 | 565 | </item> |
|
566 | 566 | <item> |
|
567 | 567 | <property name="text"> |
|
568 | 568 | <string>Black arrow</string> |
|
569 | 569 | </property> |
|
570 | 570 | </item> |
|
571 | 571 | <item> |
|
572 | 572 | <property name="text"> |
|
573 | 573 | <string>Custom arrow pen</string> |
|
574 | 574 | </property> |
|
575 | 575 | </item> |
|
576 | 576 | </widget> |
|
577 | 577 | <widget class="QComboBox" name="angularAxisComboBox"> |
|
578 | 578 | <property name="geometry"> |
|
579 | 579 | <rect> |
|
580 | 580 | <x>10</x> |
|
581 | 581 | <y>20</y> |
|
582 | 582 | <width>171</width> |
|
583 | 583 | <height>22</height> |
|
584 | 584 | </rect> |
|
585 | 585 | </property> |
|
586 | 586 | <property name="currentIndex"> |
|
587 | 587 | <number>1</number> |
|
588 | 588 | </property> |
|
589 | 589 | <item> |
|
590 | 590 | <property name="text"> |
|
591 | 591 | <string>No Angular Axis</string> |
|
592 | 592 | </property> |
|
593 | 593 | </item> |
|
594 | 594 | <item> |
|
595 | 595 | <property name="text"> |
|
596 | 596 | <string>Angular Value Axis</string> |
|
597 | 597 | </property> |
|
598 | 598 | </item> |
|
599 | 599 | <item> |
|
600 | 600 | <property name="text"> |
|
601 | 601 | <string>Angular Log Axis</string> |
|
602 | 602 | </property> |
|
603 | 603 | </item> |
|
604 | 604 | <item> |
|
605 | 605 | <property name="text"> |
|
606 | 606 | <string>Angular DateTime Axis</string> |
|
607 | 607 | </property> |
|
608 | 608 | </item> |
|
609 | 609 | <item> |
|
610 | 610 | <property name="text"> |
|
611 | 611 | <string>Angular Category Axis</string> |
|
612 | 612 | </property> |
|
613 | 613 | </item> |
|
614 | 614 | </widget> |
|
615 | 615 | <widget class="QComboBox" name="radialAxisComboBox"> |
|
616 | 616 | <property name="geometry"> |
|
617 | 617 | <rect> |
|
618 | 618 | <x>10</x> |
|
619 | 619 | <y>50</y> |
|
620 | 620 | <width>171</width> |
|
621 | 621 | <height>22</height> |
|
622 | 622 | </rect> |
|
623 | 623 | </property> |
|
624 | 624 | <property name="currentIndex"> |
|
625 | 625 | <number>1</number> |
|
626 | 626 | </property> |
|
627 | 627 | <item> |
|
628 | 628 | <property name="text"> |
|
629 | 629 | <string>No Radial Axis</string> |
|
630 | 630 | </property> |
|
631 | 631 | </item> |
|
632 | 632 | <item> |
|
633 | 633 | <property name="text"> |
|
634 | 634 | <string>Radial Value Axis</string> |
|
635 | 635 | </property> |
|
636 | 636 | </item> |
|
637 | 637 | <item> |
|
638 | 638 | <property name="text"> |
|
639 | 639 | <string>Radial Log Axis</string> |
|
640 | 640 | </property> |
|
641 | 641 | </item> |
|
642 | 642 | <item> |
|
643 | 643 | <property name="text"> |
|
644 | 644 | <string>Radial DateTime Axis</string> |
|
645 | 645 | </property> |
|
646 | 646 | </item> |
|
647 | 647 | <item> |
|
648 | 648 | <property name="text"> |
|
649 | 649 | <string>Radial Category Axis</string> |
|
650 | 650 | </property> |
|
651 | 651 | </item> |
|
652 | 652 | </widget> |
|
653 | 653 | <widget class="QLabel" name="label_16"> |
|
654 | 654 | <property name="geometry"> |
|
655 | 655 | <rect> |
|
656 | 656 | <x>10</x> |
|
657 | 657 | <y>660</y> |
|
658 | 658 | <width>101</width> |
|
659 | 659 | <height>16</height> |
|
660 | 660 | </rect> |
|
661 | 661 | </property> |
|
662 | 662 | <property name="text"> |
|
663 | 663 | <string>Log Base</string> |
|
664 | 664 | </property> |
|
665 | 665 | </widget> |
|
666 | 666 | <widget class="QDoubleSpinBox" name="logBaseSpin"> |
|
667 | 667 | <property name="geometry"> |
|
668 | 668 | <rect> |
|
669 | 669 | <x>90</x> |
|
670 | 670 | <y>660</y> |
|
671 | 671 | <width>91</width> |
|
672 | 672 | <height>22</height> |
|
673 | 673 | </rect> |
|
674 | 674 | </property> |
|
675 | 675 | <property name="decimals"> |
|
676 | 676 | <number>5</number> |
|
677 | 677 | </property> |
|
678 | 678 | <property name="minimum"> |
|
679 | 679 | <double>-999999999.000000000000000</double> |
|
680 | 680 | </property> |
|
681 | 681 | <property name="maximum"> |
|
682 | 682 | <double>999999999.000000000000000</double> |
|
683 | 683 | </property> |
|
684 | 684 | <property name="value"> |
|
685 | 685 | <double>8.000000000000000</double> |
|
686 | 686 | </property> |
|
687 | 687 | </widget> |
|
688 | 688 | <widget class="QCheckBox" name="niceNumbersCheckBox"> |
|
689 | 689 | <property name="geometry"> |
|
690 | 690 | <rect> |
|
691 | 691 | <x>10</x> |
|
692 | 692 | <y>690</y> |
|
693 | 693 | <width>91</width> |
|
694 | 694 | <height>16</height> |
|
695 | 695 | </rect> |
|
696 | 696 | </property> |
|
697 | 697 | <property name="text"> |
|
698 | 698 | <string>Nice Numbers</string> |
|
699 | 699 | </property> |
|
700 | 700 | </widget> |
|
701 | 701 | <widget class="QLineEdit" name="dateFormatEdit"> |
|
702 | 702 | <property name="geometry"> |
|
703 | 703 | <rect> |
|
704 | 704 | <x>100</x> |
|
705 | 705 | <y>710</y> |
|
706 | 706 | <width>81</width> |
|
707 | 707 | <height>20</height> |
|
708 | 708 | </rect> |
|
709 | 709 | </property> |
|
710 | 710 | </widget> |
|
711 | 711 | <widget class="QLabel" name="label_17"> |
|
712 | 712 | <property name="geometry"> |
|
713 | 713 | <rect> |
|
714 | 714 | <x>10</x> |
|
715 | 715 | <y>710</y> |
|
716 | 716 | <width>101</width> |
|
717 | 717 | <height>16</height> |
|
718 | 718 | </rect> |
|
719 | 719 | </property> |
|
720 | 720 | <property name="text"> |
|
721 | 721 | <string>DateTime format</string> |
|
722 | 722 | </property> |
|
723 | 723 | </widget> |
|
724 | 724 | <widget class="QCheckBox" name="moreCategoriesCheckBox"> |
|
725 | 725 | <property name="geometry"> |
|
726 | 726 | <rect> |
|
727 | 727 | <x>100</x> |
|
728 | 728 | <y>690</y> |
|
729 | 729 | <width>141</width> |
|
730 | 730 | <height>16</height> |
|
731 | 731 | </rect> |
|
732 | 732 | </property> |
|
733 | 733 | <property name="text"> |
|
734 | 734 | <string>More Categories</string> |
|
735 | 735 | </property> |
|
736 | 736 | </widget> |
|
737 | 737 | <widget class="QCheckBox" name="series1checkBox"> |
|
738 | 738 | <property name="geometry"> |
|
739 | 739 | <rect> |
|
740 | 740 | <x>10</x> |
|
741 | 741 | <y>730</y> |
|
742 | 742 | <width>31</width> |
|
743 | 743 | <height>16</height> |
|
744 | 744 | </rect> |
|
745 | 745 | </property> |
|
746 | 746 | <property name="text"> |
|
747 | 747 | <string>1</string> |
|
748 | 748 | </property> |
|
749 | 749 | </widget> |
|
750 | 750 | <widget class="QCheckBox" name="series2checkBox"> |
|
751 | 751 | <property name="geometry"> |
|
752 | 752 | <rect> |
|
753 | 753 | <x>40</x> |
|
754 | 754 | <y>730</y> |
|
755 | 755 | <width>31</width> |
|
756 | 756 | <height>16</height> |
|
757 | 757 | </rect> |
|
758 | 758 | </property> |
|
759 | 759 | <property name="text"> |
|
760 | 760 | <string>2</string> |
|
761 | 761 | </property> |
|
762 | 762 | </widget> |
|
763 | 763 | <widget class="QCheckBox" name="series3checkBox"> |
|
764 | 764 | <property name="geometry"> |
|
765 | 765 | <rect> |
|
766 | 766 | <x>70</x> |
|
767 | 767 | <y>730</y> |
|
768 | 768 | <width>31</width> |
|
769 | 769 | <height>16</height> |
|
770 | 770 | </rect> |
|
771 | 771 | </property> |
|
772 | 772 | <property name="text"> |
|
773 | 773 | <string>3</string> |
|
774 | 774 | </property> |
|
775 | 775 | </widget> |
|
776 | 776 | <widget class="QCheckBox" name="series4checkBox"> |
|
777 | 777 | <property name="geometry"> |
|
778 | 778 | <rect> |
|
779 | 779 | <x>10</x> |
|
780 | 780 | <y>750</y> |
|
781 | 781 | <width>31</width> |
|
782 | 782 | <height>16</height> |
|
783 | 783 | </rect> |
|
784 | 784 | </property> |
|
785 | 785 | <property name="text"> |
|
786 | 786 | <string>4</string> |
|
787 | 787 | </property> |
|
788 | 788 | </widget> |
|
789 | 789 | <widget class="QCheckBox" name="series5checkBox"> |
|
790 | 790 | <property name="geometry"> |
|
791 | 791 | <rect> |
|
792 | 792 | <x>40</x> |
|
793 | 793 | <y>750</y> |
|
794 | 794 | <width>31</width> |
|
795 | 795 | <height>16</height> |
|
796 | 796 | </rect> |
|
797 | 797 | </property> |
|
798 | 798 | <property name="text"> |
|
799 | 799 | <string>5</string> |
|
800 | 800 | </property> |
|
801 | 801 | </widget> |
|
802 | 802 | <widget class="QCheckBox" name="series6checkBox"> |
|
803 | 803 | <property name="geometry"> |
|
804 | 804 | <rect> |
|
805 | 805 | <x>70</x> |
|
806 | 806 | <y>750</y> |
|
807 | 807 | <width>31</width> |
|
808 | 808 | <height>16</height> |
|
809 | 809 | </rect> |
|
810 | 810 | </property> |
|
811 | 811 | <property name="text"> |
|
812 | 812 | <string>6</string> |
|
813 | 813 | </property> |
|
814 | 814 | </widget> |
|
815 | 815 | <widget class="QCheckBox" name="series7checkBox"> |
|
816 | 816 | <property name="geometry"> |
|
817 | 817 | <rect> |
|
818 | 818 | <x>100</x> |
|
819 | 819 | <y>740</y> |
|
820 | 820 | <width>31</width> |
|
821 | 821 | <height>16</height> |
|
822 | 822 | </rect> |
|
823 | 823 | </property> |
|
824 | 824 | <property name="text"> |
|
825 | 825 | <string>7</string> |
|
826 | 826 | </property> |
|
827 | 827 | </widget> |
|
828 | 828 | <widget class="QComboBox" name="themeComboBox"> |
|
829 | 829 | <property name="geometry"> |
|
830 | 830 | <rect> |
|
831 | 831 | <x>10</x> |
|
832 | 832 | <y>770</y> |
|
833 | 833 | <width>171</width> |
|
834 | 834 | <height>22</height> |
|
835 | 835 | </rect> |
|
836 | 836 | </property> |
|
837 | 837 | <property name="sizePolicy"> |
|
838 | 838 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
|
839 | 839 | <horstretch>0</horstretch> |
|
840 | 840 | <verstretch>0</verstretch> |
|
841 | 841 | </sizepolicy> |
|
842 | 842 | </property> |
|
843 | 843 | <property name="currentIndex"> |
|
844 | 844 | <number>0</number> |
|
845 | 845 | </property> |
|
846 | 846 | <item> |
|
847 | 847 | <property name="text"> |
|
848 | 848 | <string>Theme: Light</string> |
|
849 | 849 | </property> |
|
850 | 850 | </item> |
|
851 | 851 | <item> |
|
852 | 852 | <property name="text"> |
|
853 | 853 | <string>Theme: Blue Cerulean</string> |
|
854 | 854 | </property> |
|
855 | 855 | </item> |
|
856 | 856 | <item> |
|
857 | 857 | <property name="text"> |
|
858 | 858 | <string>Theme: Dark</string> |
|
859 | 859 | </property> |
|
860 | 860 | </item> |
|
861 | 861 | <item> |
|
862 | 862 | <property name="text"> |
|
863 | 863 | <string>Theme: Brown Sand</string> |
|
864 | 864 | </property> |
|
865 | 865 | </item> |
|
866 | 866 | <item> |
|
867 | 867 | <property name="text"> |
|
868 | 868 | <string>Theme: Blue Ncs</string> |
|
869 | 869 | </property> |
|
870 | 870 | </item> |
|
871 | 871 | <item> |
|
872 | 872 | <property name="text"> |
|
873 | 873 | <string>Theme: High Contrast</string> |
|
874 | 874 | </property> |
|
875 | 875 | </item> |
|
876 | 876 | <item> |
|
877 | 877 | <property name="text"> |
|
878 | 878 | <string>Theme: Blue Icy</string> |
|
879 | 879 | </property> |
|
880 | 880 | </item> |
|
881 | 881 | </widget> |
|
882 | 882 | <widget class="QLabel" name="hoverLabel"> |
|
883 | 883 | <property name="geometry"> |
|
884 | 884 | <rect> |
|
885 | 885 | <x>10</x> |
|
886 | 886 | <y>800</y> |
|
887 | 887 | <width>171</width> |
|
888 | 888 | <height>16</height> |
|
889 | 889 | </rect> |
|
890 | 890 | </property> |
|
891 | 891 | <property name="text"> |
|
892 | 892 | <string>Hover coordinates here!</string> |
|
893 | 893 | </property> |
|
894 | 894 | </widget> |
|
895 | <widget class="QComboBox" name="backgroundComboBox"> | |
|
896 | <property name="geometry"> | |
|
897 | <rect> | |
|
898 | <x>10</x> | |
|
899 | <y>820</y> | |
|
900 | <width>171</width> | |
|
901 | <height>22</height> | |
|
902 | </rect> | |
|
903 | </property> | |
|
904 | <property name="sizePolicy"> | |
|
905 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | |
|
906 | <horstretch>0</horstretch> | |
|
907 | <verstretch>0</verstretch> | |
|
908 | </sizepolicy> | |
|
909 | </property> | |
|
910 | <property name="currentIndex"> | |
|
911 | <number>0</number> | |
|
912 | </property> | |
|
913 | <item> | |
|
914 | <property name="text"> | |
|
915 | <string>Background: White</string> | |
|
916 | </property> | |
|
917 | </item> | |
|
918 | <item> | |
|
919 | <property name="text"> | |
|
920 | <string>Background: Blue</string> | |
|
921 | </property> | |
|
922 | </item> | |
|
923 | <item> | |
|
924 | <property name="text"> | |
|
925 | <string>Background: Yellow + Black Border</string> | |
|
926 | </property> | |
|
927 | </item> | |
|
928 | </widget> | |
|
929 | <widget class="QComboBox" name="plotAreaComboBox"> | |
|
930 | <property name="geometry"> | |
|
931 | <rect> | |
|
932 | <x>10</x> | |
|
933 | <y>850</y> | |
|
934 | <width>171</width> | |
|
935 | <height>22</height> | |
|
936 | </rect> | |
|
937 | </property> | |
|
938 | <property name="sizePolicy"> | |
|
939 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | |
|
940 | <horstretch>0</horstretch> | |
|
941 | <verstretch>0</verstretch> | |
|
942 | </sizepolicy> | |
|
943 | </property> | |
|
944 | <property name="currentIndex"> | |
|
945 | <number>0</number> | |
|
946 | </property> | |
|
947 | <item> | |
|
948 | <property name="text"> | |
|
949 | <string>PlotArea: Transparent</string> | |
|
950 | </property> | |
|
951 | </item> | |
|
952 | <item> | |
|
953 | <property name="text"> | |
|
954 | <string>PlotArea: Magenta</string> | |
|
955 | </property> | |
|
956 | </item> | |
|
957 | <item> | |
|
958 | <property name="text"> | |
|
959 | <string>PlotArea: Gray + Red Border</string> | |
|
960 | </property> | |
|
961 | </item> | |
|
962 | </widget> | |
|
895 | 963 | </widget> |
|
896 | 964 | </item> |
|
897 | 965 | </layout> |
|
898 | 966 | </widget> |
|
899 | 967 | <widget class="QMenuBar" name="menuBar"> |
|
900 | 968 | <property name="geometry"> |
|
901 | 969 | <rect> |
|
902 | 970 | <x>0</x> |
|
903 | 971 | <y>0</y> |
|
904 |
<width>1 |
|
|
972 | <width>1193</width> | |
|
905 | 973 | <height>21</height> |
|
906 | 974 | </rect> |
|
907 | 975 | </property> |
|
908 | 976 | </widget> |
|
909 | 977 | <widget class="QToolBar" name="mainToolBar"> |
|
910 | 978 | <attribute name="toolBarArea"> |
|
911 | 979 | <enum>TopToolBarArea</enum> |
|
912 | 980 | </attribute> |
|
913 | 981 | <attribute name="toolBarBreak"> |
|
914 | 982 | <bool>false</bool> |
|
915 | 983 | </attribute> |
|
916 | 984 | </widget> |
|
917 | 985 | <widget class="QStatusBar" name="statusBar"/> |
|
918 | 986 | </widget> |
|
919 | 987 | <layoutdefault spacing="6" margin="11"/> |
|
920 | 988 | <customwidgets> |
|
921 | 989 | <customwidget> |
|
922 | 990 | <class>ChartView</class> |
|
923 | 991 | <extends>QGraphicsView</extends> |
|
924 | 992 | <header>chartview.h</header> |
|
925 | 993 | </customwidget> |
|
926 | 994 | </customwidgets> |
|
927 | 995 | <resources/> |
|
928 | 996 | <connections/> |
|
929 | 997 | </ui> |
@@ -1,106 +1,107 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 | import QtQuick 1.0 |
|
22 |
import QtCommercial.Chart 1. |
|
|
22 | import QtCommercial.Chart 1.3 | |
|
23 | 23 | |
|
24 | 24 | ChartView { |
|
25 | 25 | id: chartView |
|
26 | 26 | title: "Chart Title" |
|
27 | 27 | anchors.fill: parent |
|
28 | 28 | property variant chart: chartView |
|
29 | 29 | |
|
30 | 30 | LineSeries { |
|
31 | 31 | name: "line" |
|
32 | 32 | XYPoint { x: 0; y: 0 } |
|
33 | 33 | XYPoint { x: 1.1; y: 2.1 } |
|
34 | 34 | XYPoint { x: 1.9; y: 3.3 } |
|
35 | 35 | XYPoint { x: 2.1; y: 2.1 } |
|
36 | 36 | XYPoint { x: 2.9; y: 4.9 } |
|
37 | 37 | XYPoint { x: 3.4; y: 3.0 } |
|
38 | 38 | XYPoint { x: 4.1; y: 3.3 } |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); |
|
42 | 42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); |
|
43 | 43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor); |
|
44 | 44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); |
|
45 | 45 | onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name); |
|
46 | 46 | onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name); |
|
47 | onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor); | |
|
47 | 48 | |
|
48 | 49 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible); |
|
49 | 50 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
50 | 51 | legend.onColorChanged: console.log("legend.onColorChanged: " + color); |
|
51 | 52 | legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); |
|
52 | 53 | legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); |
|
53 | 54 | margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top ); |
|
54 | 55 | margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom); |
|
55 | 56 | margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left); |
|
56 | 57 | margins.onRightChanged: console.log("chart.margins.onRightChanged: " + right); |
|
57 | 58 | onPlotAreaChanged: { |
|
58 | 59 | console.log("chart.onPlotAreaChanged, width: " + chartView.plotArea.width |
|
59 | 60 | + " height: " + chartView.plotArea.height |
|
60 | 61 | + " y: " + chartView.plotArea.y |
|
61 | 62 | + " x: " + chartView.plotArea.x); |
|
62 | 63 | marginVisualizer.opacity = 1.0; |
|
63 | 64 | } |
|
64 | 65 | |
|
65 | 66 | ValueAxis{ |
|
66 | 67 | onColorChanged: console.log("axisX.onColorChanged: " + color); |
|
67 | 68 | onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); |
|
68 | 69 | onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); |
|
69 | 70 | onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); |
|
70 | 71 | onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); |
|
71 | 72 | onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); |
|
72 | 73 | onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); |
|
73 | 74 | onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); |
|
74 | 75 | onMinChanged: console.log("axisX.onMinChanged: " + min); |
|
75 | 76 | onMaxChanged: console.log("axisX.onMaxChanged: " + max); |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | ValueAxis{ |
|
79 | 80 | onColorChanged: console.log("axisY.onColorChanged: " + color); |
|
80 | 81 | onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); |
|
81 | 82 | onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); |
|
82 | 83 | onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); |
|
83 | 84 | onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); |
|
84 | 85 | onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); |
|
85 | 86 | onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); |
|
86 | 87 | onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
87 | 88 | onMinChanged: console.log("axisY.onMinChanged: " + min); |
|
88 | 89 | onMaxChanged: console.log("axisY.onMaxChanged: " + max); |
|
89 | 90 | } |
|
90 | 91 | |
|
91 | 92 | Rectangle { |
|
92 | 93 | id: marginVisualizer |
|
93 | 94 | color: "transparent" |
|
94 | 95 | border.color: "red" |
|
95 | 96 | anchors.fill: parent |
|
96 | 97 | anchors.topMargin: chartView.minimumMargins.top |
|
97 | 98 | anchors.bottomMargin: chartView.minimumMargins.bottom |
|
98 | 99 | anchors.leftMargin: chartView.minimumMargins.left |
|
99 | 100 | anchors.rightMargin: chartView.minimumMargins.right |
|
100 | 101 | opacity: 0.0 |
|
101 | 102 | onOpacityChanged: if (opacity > 0.9) opacity = 0.0; |
|
102 | 103 | Behavior on opacity { |
|
103 | 104 | NumberAnimation { duration: 800 } |
|
104 | 105 | } |
|
105 | 106 | } |
|
106 | 107 | } |
@@ -1,116 +1,120 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 | import QtQuick 1.0 |
|
22 | 22 | |
|
23 | 23 | Flow { |
|
24 | 24 | anchors.fill: parent |
|
25 | 25 | property variant chart |
|
26 | 26 | flow: Flow.TopToBottom |
|
27 | 27 | spacing: 5 |
|
28 | 28 | Button { |
|
29 | 29 | text: "visible" |
|
30 | 30 | onClicked: chart.visible = !chart.visible; |
|
31 | 31 | } |
|
32 | 32 | Button { |
|
33 | 33 | text: "theme +" |
|
34 | 34 | onClicked: chart.theme++; |
|
35 | 35 | } |
|
36 | 36 | Button { |
|
37 | 37 | text: "theme -" |
|
38 | 38 | onClicked: chart.theme--; |
|
39 | 39 | } |
|
40 | 40 | Button { |
|
41 | 41 | text: "animation opt +" |
|
42 | 42 | onClicked: chart.animationOptions++; |
|
43 | 43 | } |
|
44 | 44 | Button { |
|
45 | 45 | text: "animation opt -" |
|
46 | 46 | onClicked: chart.animationOptions--; |
|
47 | 47 | } |
|
48 | 48 | Button { |
|
49 | 49 | text: "background color" |
|
50 | 50 | onClicked: chart.backgroundColor = main.nextColor(); |
|
51 | 51 | } |
|
52 | 52 | Button { |
|
53 | text: "plot area color" | |
|
54 | onClicked: chart.plotAreaColor = main.nextColor(); | |
|
55 | } | |
|
56 | Button { | |
|
53 | 57 | text: "drop shadow enabled" |
|
54 | 58 | onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled; |
|
55 | 59 | } |
|
56 | 60 | Button { |
|
57 | 61 | text: "zoom +" |
|
58 | 62 | onClicked: chart.zoom(2); |
|
59 | 63 | } |
|
60 | 64 | Button { |
|
61 | 65 | text: "zoom -" |
|
62 | 66 | onClicked: chart.zoom(0.5); |
|
63 | 67 | } |
|
64 | 68 | Button { |
|
65 | 69 | text: "scroll left" |
|
66 | 70 | onClicked: chart.scrollLeft(10); |
|
67 | 71 | } |
|
68 | 72 | Button { |
|
69 | 73 | text: "scroll right" |
|
70 | 74 | onClicked: chart.scrollRight(10); |
|
71 | 75 | } |
|
72 | 76 | Button { |
|
73 | 77 | text: "scroll up" |
|
74 | 78 | onClicked: chart.scrollUp(10); |
|
75 | 79 | } |
|
76 | 80 | Button { |
|
77 | 81 | text: "scroll down" |
|
78 | 82 | onClicked: chart.scrollDown(10); |
|
79 | 83 | } |
|
80 | 84 | Button { |
|
81 | 85 | text: "title color" |
|
82 | 86 | onClicked: chart.titleColor = main.nextColor(); |
|
83 | 87 | } |
|
84 | 88 | Button { |
|
85 | 89 | text: "top margin +" |
|
86 | 90 | onClicked: chart.margins.top += 5; |
|
87 | 91 | } |
|
88 | 92 | Button { |
|
89 | 93 | text: "top margin -" |
|
90 | 94 | onClicked: chart.margins.top -= 5; |
|
91 | 95 | } |
|
92 | 96 | Button { |
|
93 | 97 | text: "bottom margin +" |
|
94 | 98 | onClicked: chart.margins.bottom += 5; |
|
95 | 99 | } |
|
96 | 100 | Button { |
|
97 | 101 | text: "bottom margin -" |
|
98 | 102 | onClicked: chart.margins.bottom -= 5; |
|
99 | 103 | } |
|
100 | 104 | Button { |
|
101 | 105 | text: "left margin +" |
|
102 | 106 | onClicked: chart.margins.left += 5; |
|
103 | 107 | } |
|
104 | 108 | Button { |
|
105 | 109 | text: "left margin -" |
|
106 | 110 | onClicked: chart.margins.left -= 5; |
|
107 | 111 | } |
|
108 | 112 | Button { |
|
109 | 113 | text: "right margin +" |
|
110 | 114 | onClicked: chart.margins.right += 5; |
|
111 | 115 | } |
|
112 | 116 | Button { |
|
113 | 117 | text: "right margin -" |
|
114 | 118 | onClicked: chart.margins.right -= 5; |
|
115 | 119 | } |
|
116 | 120 | } |
@@ -1,106 +1,107 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 | import QtQuick 2.0 |
|
22 |
import QtCommercial.Chart 1. |
|
|
22 | import QtCommercial.Chart 1.3 | |
|
23 | 23 | |
|
24 | 24 | ChartView { |
|
25 | 25 | id: chartView |
|
26 | 26 | title: "Chart Title" |
|
27 | 27 | anchors.fill: parent |
|
28 | 28 | property variant chart: chartView |
|
29 | 29 | |
|
30 | 30 | LineSeries { |
|
31 | 31 | name: "line" |
|
32 | 32 | XYPoint { x: 0; y: 0 } |
|
33 | 33 | XYPoint { x: 1.1; y: 2.1 } |
|
34 | 34 | XYPoint { x: 1.9; y: 3.3 } |
|
35 | 35 | XYPoint { x: 2.1; y: 2.1 } |
|
36 | 36 | XYPoint { x: 2.9; y: 4.9 } |
|
37 | 37 | XYPoint { x: 3.4; y: 3.0 } |
|
38 | 38 | XYPoint { x: 4.1; y: 3.3 } |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); |
|
42 | 42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); |
|
43 | 43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor); |
|
44 | 44 | onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled); |
|
45 | 45 | onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name); |
|
46 | 46 | onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name); |
|
47 | onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor); | |
|
47 | 48 | |
|
48 | 49 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible); |
|
49 | 50 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
50 | 51 | legend.onColorChanged: console.log("legend.onColorChanged: " + color); |
|
51 | 52 | legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); |
|
52 | 53 | legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); |
|
53 | 54 | margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top ); |
|
54 | 55 | margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom); |
|
55 | 56 | margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left); |
|
56 | 57 | margins.onRightChanged: console.log("chart.margins.onRightChanged: " + right); |
|
57 | 58 | onPlotAreaChanged: { |
|
58 | 59 | console.log("chart.onPlotAreaChanged, width: " + chartView.plotArea.width |
|
59 | 60 | + " height: " + chartView.plotArea.height |
|
60 | 61 | + " y: " + chartView.plotArea.y |
|
61 | 62 | + " x: " + chartView.plotArea.x); |
|
62 | 63 | marginVisualizer.opacity = 1.0; |
|
63 | 64 | } |
|
64 | 65 | |
|
65 | 66 | ValueAxis{ |
|
66 | 67 | onColorChanged: console.log("axisX.onColorChanged: " + color); |
|
67 | 68 | onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible); |
|
68 | 69 | onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color); |
|
69 | 70 | onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible); |
|
70 | 71 | onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible); |
|
71 | 72 | onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible); |
|
72 | 73 | onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color); |
|
73 | 74 | onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color); |
|
74 | 75 | onMinChanged: console.log("axisX.onMinChanged: " + min); |
|
75 | 76 | onMaxChanged: console.log("axisX.onMaxChanged: " + max); |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | ValueAxis{ |
|
79 | 80 | onColorChanged: console.log("axisY.onColorChanged: " + color); |
|
80 | 81 | onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible); |
|
81 | 82 | onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color); |
|
82 | 83 | onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible); |
|
83 | 84 | onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible); |
|
84 | 85 | onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible); |
|
85 | 86 | onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color); |
|
86 | 87 | onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color); |
|
87 | 88 | onMinChanged: console.log("axisY.onMinChanged: " + min); |
|
88 | 89 | onMaxChanged: console.log("axisY.onMaxChanged: " + max); |
|
89 | 90 | } |
|
90 | 91 | |
|
91 | 92 | Rectangle { |
|
92 | 93 | id: marginVisualizer |
|
93 | 94 | color: "transparent" |
|
94 | 95 | border.color: "red" |
|
95 | 96 | anchors.fill: parent |
|
96 | 97 | anchors.topMargin: chartView.minimumMargins.top |
|
97 | 98 | anchors.bottomMargin: chartView.minimumMargins.bottom |
|
98 | 99 | anchors.leftMargin: chartView.minimumMargins.left |
|
99 | 100 | anchors.rightMargin: chartView.minimumMargins.right |
|
100 | 101 | opacity: 0.0 |
|
101 | 102 | onOpacityChanged: if (opacity > 0.9) opacity = 0.0; |
|
102 | 103 | Behavior on opacity { |
|
103 | 104 | NumberAnimation { duration: 800 } |
|
104 | 105 | } |
|
105 | 106 | } |
|
106 | 107 | } |
@@ -1,116 +1,120 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt 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 | import QtQuick 2.0 |
|
22 | 22 | |
|
23 | 23 | Flow { |
|
24 | 24 | anchors.fill: parent |
|
25 | 25 | property variant chart |
|
26 | 26 | flow: Flow.TopToBottom |
|
27 | 27 | spacing: 5 |
|
28 | 28 | Button { |
|
29 | 29 | text: "visible" |
|
30 | 30 | onClicked: chart.visible = !chart.visible; |
|
31 | 31 | } |
|
32 | 32 | Button { |
|
33 | 33 | text: "theme +" |
|
34 | 34 | onClicked: chart.theme++; |
|
35 | 35 | } |
|
36 | 36 | Button { |
|
37 | 37 | text: "theme -" |
|
38 | 38 | onClicked: chart.theme--; |
|
39 | 39 | } |
|
40 | 40 | Button { |
|
41 | 41 | text: "animation opt +" |
|
42 | 42 | onClicked: chart.animationOptions++; |
|
43 | 43 | } |
|
44 | 44 | Button { |
|
45 | 45 | text: "animation opt -" |
|
46 | 46 | onClicked: chart.animationOptions--; |
|
47 | 47 | } |
|
48 | 48 | Button { |
|
49 | 49 | text: "background color" |
|
50 | 50 | onClicked: chart.backgroundColor = main.nextColor(); |
|
51 | 51 | } |
|
52 | 52 | Button { |
|
53 | text: "plot area color" | |
|
54 | onClicked: chart.plotAreaColor = main.nextColor(); | |
|
55 | } | |
|
56 | Button { | |
|
53 | 57 | text: "drop shadow enabled" |
|
54 | 58 | onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled; |
|
55 | 59 | } |
|
56 | 60 | Button { |
|
57 | 61 | text: "zoom +" |
|
58 | 62 | onClicked: chart.zoom(2); |
|
59 | 63 | } |
|
60 | 64 | Button { |
|
61 | 65 | text: "zoom -" |
|
62 | 66 | onClicked: chart.zoom(0.5); |
|
63 | 67 | } |
|
64 | 68 | Button { |
|
65 | 69 | text: "scroll left" |
|
66 | 70 | onClicked: chart.scrollLeft(10); |
|
67 | 71 | } |
|
68 | 72 | Button { |
|
69 | 73 | text: "scroll right" |
|
70 | 74 | onClicked: chart.scrollRight(10); |
|
71 | 75 | } |
|
72 | 76 | Button { |
|
73 | 77 | text: "scroll up" |
|
74 | 78 | onClicked: chart.scrollUp(10); |
|
75 | 79 | } |
|
76 | 80 | Button { |
|
77 | 81 | text: "scroll down" |
|
78 | 82 | onClicked: chart.scrollDown(10); |
|
79 | 83 | } |
|
80 | 84 | Button { |
|
81 | 85 | text: "title color" |
|
82 | 86 | onClicked: chart.titleColor = main.nextColor(); |
|
83 | 87 | } |
|
84 | 88 | Button { |
|
85 | 89 | text: "top margin +" |
|
86 | 90 | onClicked: chart.margins.top += 5; |
|
87 | 91 | } |
|
88 | 92 | Button { |
|
89 | 93 | text: "top margin -" |
|
90 | 94 | onClicked: chart.margins.top -= 5; |
|
91 | 95 | } |
|
92 | 96 | Button { |
|
93 | 97 | text: "bottom margin +" |
|
94 | 98 | onClicked: chart.margins.bottom += 5; |
|
95 | 99 | } |
|
96 | 100 | Button { |
|
97 | 101 | text: "bottom margin -" |
|
98 | 102 | onClicked: chart.margins.bottom -= 5; |
|
99 | 103 | } |
|
100 | 104 | Button { |
|
101 | 105 | text: "left margin +" |
|
102 | 106 | onClicked: chart.margins.left += 5; |
|
103 | 107 | } |
|
104 | 108 | Button { |
|
105 | 109 | text: "left margin -" |
|
106 | 110 | onClicked: chart.margins.left -= 5; |
|
107 | 111 | } |
|
108 | 112 | Button { |
|
109 | 113 | text: "right margin +" |
|
110 | 114 | onClicked: chart.margins.right += 5; |
|
111 | 115 | } |
|
112 | 116 | Button { |
|
113 | 117 | text: "right margin -" |
|
114 | 118 | onClicked: chart.margins.right -= 5; |
|
115 | 119 | } |
|
116 | 120 | } |
General Comments 0
You need to be logged in to leave comments.
Login now