##// END OF EJS Templates
Fix explicitly set default pen/brush/font getting overridden by theme...
Miikka Heikkinen -
r2516:567bb8091928
parent child
Show More
@@ -1,452 +1,453
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 "qareaseries.h"
22 22 #include "qareaseries_p.h"
23 23 #include "qlineseries.h"
24 24 #include "areachartitem_p.h"
25 25 #include "abstractdomain_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "qvalueaxis.h"
29 29 #include "qarealegendmarker.h"
30 30 #include "qchart_p.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QAreaSeries
36 36 \brief The QAreaSeries class is used for making area charts.
37 37
38 38 \mainclass
39 39
40 40 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
41 41 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
42 42 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
43 43 In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases
44 44 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
45 45
46 46 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
47 47 \image examples_areachart.png
48 48 */
49 49 /*!
50 50 \qmlclass AreaSeries QAreaSeries
51 51
52 52 The following QML shows how to create a simple area chart:
53 53 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
54 54 \beginfloatleft
55 55 \image demos_qmlchart4.png
56 56 \endfloat
57 57 \clearfloat
58 58 */
59 59
60 60 /*!
61 61 \property QAreaSeries::upperSeries
62 62 \brief The upper one of the two line series used to define area series boundaries.
63 63 */
64 64 /*!
65 65 \qmlproperty LineSeries AreaSeries::upperSeries
66 66 The upper one of the two line series used to define area series boundaries.
67 67 */
68 68
69 69 /*!
70 70 \property QAreaSeries::lowerSeries
71 71 The lower one of the two line series used to define are series boundaries. Note if
72 72 QAreaSeries was constructed without a\ lowerSeries this is null.
73 73 */
74 74 /*!
75 75 \qmlproperty LineSeries AreaSeries::lowerSeries
76 76 The lower one of the two line series used to define are series boundaries. Note if
77 77 AreaSeries was constructed without a\ lowerSeries this is null.
78 78 */
79 79
80 80 /*!
81 81 \property QAreaSeries::color
82 82 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
83 83 \sa QAreaSeries::brush()
84 84 */
85 85 /*!
86 86 \qmlproperty color AreaSeries::color
87 87 Fill (brush) color of the series.
88 88 */
89 89
90 90 /*!
91 91 \property QAreaSeries::borderColor
92 92 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
93 93 \sa QAreaSeries::pen()
94 94 */
95 95 /*!
96 96 \qmlproperty color AreaSeries::borderColor
97 97 Line (pen) color of the series.
98 98 */
99 99
100 100 /*!
101 101 \qmlproperty real AreaSeries::borderWidth
102 102 The width of the border line. By default the width is 2.0.
103 103 */
104 104
105 105 /*!
106 106 \fn QPen QAreaSeries::pen() const
107 107 \brief Returns the pen used to draw line for this series.
108 108 \sa setPen()
109 109 */
110 110
111 111 /*!
112 112 \fn QPen QAreaSeries::brush() const
113 113 \brief Returns the brush used to draw line for this series.
114 114 \sa setBrush()
115 115 */
116 116
117 117 /*!
118 118 \fn void QAreaSeries::colorChanged(QColor color)
119 119 \brief Signal is emitted when the fill (brush) color has changed to \a color.
120 120 */
121 121 /*!
122 122 \qmlsignal AreaSeries::onColorChanged(color color)
123 123 Signal is emitted when the fill (brush) color has changed to \a color.
124 124 */
125 125
126 126 /*!
127 127 \fn void QAreaSeries::borderColorChanged(QColor color)
128 128 \brief Signal is emitted when the line (pen) color has changed to \a color.
129 129 */
130 130 /*!
131 131 \qmlsignal AreaSeries::onBorderColorChanged(color color)
132 132 Signal is emitted when the line (pen) color has changed to \a color.
133 133 */
134 134
135 135 /*!
136 136 \fn void QAreaSeries::clicked(const QPointF& point)
137 137 \brief Signal is emitted when user clicks the \a point on area chart.
138 138 */
139 139 /*!
140 140 \qmlsignal AreaSeries::onClicked(QPointF point)
141 141 Signal is emitted when user clicks the \a point on area chart.
142 142 */
143 143
144 144 /*!
145 145 \fn void QAreaSeries::hovered(const QPointF &point, bool state)
146 146 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
147 147 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
148 148 the series.
149 149 */
150 150 /*!
151 151 \qmlsignal AreaSeries::onHovered(point point, bool state)
152 152 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
153 153 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
154 154 the series.
155 155 */
156 156
157 157 /*!
158 158 \fn void QAreaSeries::selected()
159 159 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
160 160 implemented by the user of QAreaSeries API.
161 161 */
162 162 /*!
163 163 \qmlsignal AreaSeries::onSelected()
164 164 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
165 165 implemented by the user of AreaSeries API.
166 166 */
167 167
168 168 /*!
169 169 \fn void QAreaSeriesPrivate::updated()
170 170 \brief \internal
171 171 */
172 172
173 173 /*!
174 174 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
175 175 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
176 176 When series object is added to QChartView or QChart instance ownerships is transferred.
177 177 */
178 178 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
179 179 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries)
180 180 {
181 181 }
182 182
183 183 /*!
184 184 Constructs area series object without upper or lower series with \a parent object.
185 185 */
186 186 QAreaSeries::QAreaSeries(QObject *parent)
187 187 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
188 188 {
189 189 }
190 190
191 191 /*!
192 192 Destroys the object.
193 193 */
194 194 QAreaSeries::~QAreaSeries()
195 195 {
196 196 Q_D(QAreaSeries);
197 197 if (d->m_chart)
198 198 d->m_chart->removeSeries(this);
199 199 }
200 200
201 201 /*!
202 202 Returns QChartSeries::SeriesTypeArea.
203 203 */
204 204 QAbstractSeries::SeriesType QAreaSeries::type() const
205 205 {
206 206 return QAbstractSeries::SeriesTypeArea;
207 207 }
208 208
209 209 /*!
210 210 Sets the \a series that is to be used as the area chart upper series.
211 211 */
212 212 void QAreaSeries::setUpperSeries(QLineSeries *series)
213 213 {
214 214 Q_D(QAreaSeries);
215 215 if (d->m_upperSeries != series)
216 216 d->m_upperSeries = series;
217 217 }
218 218
219 219 QLineSeries *QAreaSeries::upperSeries() const
220 220 {
221 221 Q_D(const QAreaSeries);
222 222 return d->m_upperSeries;
223 223 }
224 224
225 225 /*!
226 226 Sets the \a series that is to be used as the area chart lower series.
227 227 */
228 228 void QAreaSeries::setLowerSeries(QLineSeries *series)
229 229 {
230 230 Q_D(QAreaSeries);
231 231 d->m_lowerSeries = series;
232 232 }
233 233
234 234 QLineSeries *QAreaSeries::lowerSeries() const
235 235 {
236 236 Q_D(const QAreaSeries);
237 237 return d->m_lowerSeries;
238 238 }
239 239
240 240 /*!
241 241 Sets \a pen used for drawing area outline.
242 242 */
243 243 void QAreaSeries::setPen(const QPen &pen)
244 244 {
245 245 Q_D(QAreaSeries);
246 246 if (d->m_pen != pen) {
247 247 d->m_pen = pen;
248 248 emit d->updated();
249 249 }
250 250 }
251 251
252 252 QPen QAreaSeries::pen() const
253 253 {
254 254 Q_D(const QAreaSeries);
255 255 return d->m_pen;
256 256 }
257 257
258 258 /*!
259 259 Sets \a brush used for filling the area.
260 260 */
261 261 void QAreaSeries::setBrush(const QBrush &brush)
262 262 {
263 263 Q_D(QAreaSeries);
264 264 if (d->m_brush != brush) {
265 265 bool emitColorChanged = brush.color() != d->m_brush.color();
266 266 d->m_brush = brush;
267 267 emit d->updated();
268 268 if (emitColorChanged)
269 269 emit colorChanged(brush.color());
270 270 }
271 271 }
272 272
273 273 QBrush QAreaSeries::brush() const
274 274 {
275 275 Q_D(const QAreaSeries);
276 276 return d->m_brush;
277 277 }
278 278
279 279 void QAreaSeries::setColor(const QColor &color)
280 280 {
281 281 QBrush b = brush();
282 282 if (b == QBrush())
283 283 b.setStyle(Qt::SolidPattern);
284 284 b.setColor(color);
285 285 setBrush(b);
286 286 }
287 287
288 288 QColor QAreaSeries::color() const
289 289 {
290 290 return brush().color();
291 291 }
292 292
293 293 void QAreaSeries::setBorderColor(const QColor &color)
294 294 {
295 295 QPen p = pen();
296 296 if (p.color() != color) {
297 297 p.setColor(color);
298 298 setPen(p);
299 299 emit borderColorChanged(color);
300 300 }
301 301 }
302 302
303 303 QColor QAreaSeries::borderColor() const
304 304 {
305 305 return pen().color();
306 306 }
307 307
308 308 /*!
309 309 Sets if data points are \a visible and should be drawn on line.
310 310 */
311 311 void QAreaSeries::setPointsVisible(bool visible)
312 312 {
313 313 Q_D(QAreaSeries);
314 314 if (d->m_pointsVisible != visible) {
315 315 d->m_pointsVisible = visible;
316 316 emit d->updated();
317 317 }
318 318 }
319 319
320 320 /*!
321 321 Returns if the points are drawn for this series.
322 322 \sa setPointsVisible()
323 323 */
324 324 bool QAreaSeries::pointsVisible() const
325 325 {
326 326 Q_D(const QAreaSeries);
327 327 return d->m_pointsVisible;
328 328 }
329 329
330 330 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
331 331
332 332 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
333 333 : QAbstractSeriesPrivate(q),
334 m_brush(QChartPrivate::defaultBrush()),
335 m_pen(QChartPrivate::defaultPen()),
334 336 m_upperSeries(upperSeries),
335 337 m_lowerSeries(lowerSeries),
336 338 m_pointsVisible(false)
337 339 {
338 340 }
339 341
340 342 void QAreaSeriesPrivate::initializeDomain()
341 343 {
342 344 Q_Q(QAreaSeries);
343 345
344 346 qreal minX(domain()->minX());
345 347 qreal minY(domain()->minY());
346 348 qreal maxX(domain()->maxX());
347 349 qreal maxY(domain()->maxY());
348 350
349 351 QLineSeries *upperSeries = q->upperSeries();
350 352 QLineSeries *lowerSeries = q->lowerSeries();
351 353
352 354 const QList<QPointF>& points = upperSeries->points();
353 355
354 356 for (int i = 0; i < points.count(); i++) {
355 357 qreal x = points[i].x();
356 358 qreal y = points[i].y();
357 359 minX = qMin(minX, x);
358 360 minY = qMin(minY, y);
359 361 maxX = qMax(maxX, x);
360 362 maxY = qMax(maxY, y);
361 363 }
362 364 if (lowerSeries) {
363 365
364 366 const QList<QPointF>& points = lowerSeries->points();
365 367
366 368 for (int i = 0; i < points.count(); i++) {
367 369 qreal x = points[i].x();
368 370 qreal y = points[i].y();
369 371 minX = qMin(minX, x);
370 372 minY = qMin(minY, y);
371 373 maxX = qMax(maxX, x);
372 374 maxY = qMax(maxY, y);
373 375 }
374 376 }
375 377
376 378 domain()->setRange(minX, maxX, minY, maxY);
377 379 }
378 380
379 381 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
380 382 {
381 383 Q_Q(QAreaSeries);
382 384 AreaChartItem *area = new AreaChartItem(q,parent);
383 385 m_item.reset(area);
384 386 QAbstractSeriesPrivate::initializeGraphics(parent);
385 387 }
386 388 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
387 389 {
388 390 Q_Q(QAreaSeries);
389 391 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
390 392 if (options.testFlag(QChart::SeriesAnimations)) {
391 393 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
392 394 if (q->lowerSeries())
393 395 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
394 396 }else{
395 397 area->upperLineItem()->setAnimation(0);
396 398 if (q->lowerSeries())
397 399 area->lowerLineItem()->setAnimation(0);
398 400 }
399 401 QAbstractSeriesPrivate::initializeAnimations(options);
400 402 }
401 403
402 404 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
403 405 {
404 406 Q_Q(QAreaSeries);
405 407 QList<QLegendMarker*> list;
406 408 return list << new QAreaLegendMarker(q,legend);
407 409 }
408 410
409 411
410 412 void QAreaSeriesPrivate::initializeAxes()
411 413 {
412 414
413 415 }
414 416
415 417 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
416 418 {
417 419 Q_UNUSED(orientation);
418 420 return QAbstractAxis::AxisTypeValue;
419 421 }
420 422
421 423 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
422 424 {
423 425 Q_UNUSED(orientation);
424 426 return 0;
425 427 }
426 428
427 429 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
428 430 {
429 431 Q_Q(QAreaSeries);
430 QPen pen;
431 QBrush brush;
432 432
433 433 const QList<QGradient> gradients = theme->seriesGradients();
434 434 const QList<QColor> colors = theme->seriesColors();
435 435
436 if (forced || pen == m_pen) {
436 if (forced || QChartPrivate::defaultPen() == m_pen) {
437 QPen pen;
437 438 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
438 439 pen.setWidthF(2);
439 440 q->setPen(pen);
440 441 }
441 442
442 if (forced || brush == m_brush) {
443 if (forced || QChartPrivate::defaultBrush() == m_brush) {
443 444 QBrush brush(colors.at(index % colors.size()));
444 445 q->setBrush(brush);
445 446 }
446 447 }
447 448
448 449
449 450 #include "moc_qareaseries.cpp"
450 451 #include "moc_qareaseries_p.cpp"
451 452
452 453 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,999 +1,990
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 "qabstractaxis.h"
22 22 #include "qabstractaxis_p.h"
23 23 #include "chartdataset_p.h"
24 24 #include "charttheme_p.h"
25 #include "qchart_p.h"
25 26
26 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 28
28 29 /*!
29 30 \class QAbstractAxis
30 31 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 32 \mainclass
32 33
33 34 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
34 35 that would result in different domains is not supported, such as specifying
35 36 QValueAxis and QLogValueAxis on the same orientation.
36 37
37 38 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
38 39 and shades can be individually controlled.
39 40 */
40 41
41 42 /*!
42 43 \qmlclass AbstractAxis QAbstractAxis
43 44 \brief The AbstractAxis is a base element used for specialized axis elements
44 45
45 46 Each series can be bound to only one horizontal and vertical axis.
46 47
47 48 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
48 49 and shades can be individually controlled.
49 50 */
50 51
51 52 /*!
52 53 \enum QAbstractAxis::AxisType
53 54
54 55 The type of the series object.
55 56
56 57 \value AxisTypeNoAxis
57 58 \value AxisTypeValue
58 59 \value AxisTypeBarCategory
59 60 \value AxisTypeCategory
60 61 \value AxisTypeDateTime
61 62 \value AxisTypeLogValue
62 63 */
63 64
64 65 /*!
65 66 *\fn void QAbstractAxis::type() const
66 67 Returns the type of the axis
67 68 */
68 69
69 70 /*!
70 71 \property QAbstractAxis::lineVisible
71 72 The visibility of the axis line
72 73 */
73 74 /*!
74 75 \qmlproperty bool AbstractAxis::lineVisible
75 76 The visibility of the axis line
76 77 */
77 78
78 79 /*!
79 80 \property QAbstractAxis::linePen
80 81 The pen of the line.
81 82 */
82 83
83 84 /*!
84 85 \property QAbstractAxis::labelsVisible
85 86 Defines if axis labels are visible.
86 87 */
87 88 /*!
88 89 \qmlproperty bool AbstractAxis::labelsVisible
89 90 Defines if axis labels are visible.
90 91 */
91 92
92 93 /*!
93 94 \property QAbstractAxis::labelsPen
94 95 The pen of the labels.
95 96 */
96 97
97 98 /*!
98 99 \property QAbstractAxis::labelsBrush
99 100 The brush of the labels.
100 101 */
101 102
102 103 /*!
103 104 \property QAbstractAxis::visible
104 105 The visibility of the axis.
105 106 */
106 107 /*!
107 108 \qmlproperty bool AbstractAxis::visible
108 109 The visibility of the axis.
109 110 */
110 111
111 112 /*!
112 113 \property QAbstractAxis::gridVisible
113 114 The visibility of the grid lines.
114 115 */
115 116 /*!
116 117 \qmlproperty bool AbstractAxis::gridVisible
117 118 The visibility of the grid lines.
118 119 */
119 120
120 121 /*!
121 122 \property QAbstractAxis::color
122 123 The color of the axis and ticks.
123 124 */
124 125 /*!
125 126 \qmlproperty color AbstractAxis::color
126 127 The color of the axis and ticks.
127 128 */
128 129
129 130 /*!
130 131 \property QAbstractAxis::gridLinePen
131 132 The pen of the grid line.
132 133 */
133 134
134 135 /*!
135 136 \property QAbstractAxis::labelsFont
136 137 The font of the axis labels.
137 138 */
138 139
139 140 /*!
140 141 \qmlproperty Font AbstractAxis::labelsFont
141 142 The font of the axis labels.
142 143
143 144 See the \l {Font} {QML Font Element} for detailed documentation.
144 145 */
145 146
146 147 /*!
147 148 \property QAbstractAxis::labelsColor
148 149 The color of the axis labels.
149 150 */
150 151 /*!
151 152 \qmlproperty color AbstractAxis::labelsColor
152 153 The color of the axis labels.
153 154 */
154 155
155 156 /*!
156 157 \property QAbstractAxis::labelsAngle
157 158 The angle of the axis labels in degrees.
158 159 */
159 160 /*!
160 161 \qmlproperty int AbstractAxis::labelsAngle
161 162 The angle of the axis labels in degrees.
162 163 */
163 164
164 165 /*!
165 166 \property QAbstractAxis::shadesVisible
166 167 The visibility of the axis shades.
167 168 */
168 169 /*!
169 170 \qmlproperty bool AbstractAxis::shadesVisible
170 171 The visibility of the axis shades.
171 172 */
172 173
173 174 /*!
174 175 \property QAbstractAxis::shadesColor
175 176 The fill (brush) color of the axis shades.
176 177 */
177 178 /*!
178 179 \qmlproperty color AbstractAxis::shadesColor
179 180 The fill (brush) color of the axis shades.
180 181 */
181 182
182 183 /*!
183 184 \property QAbstractAxis::shadesBorderColor
184 185 The border (pen) color of the axis shades.
185 186 */
186 187 /*!
187 188 \qmlproperty color AbstractAxis::shadesBorderColor
188 189 The border (pen) color of the axis shades.
189 190 */
190 191
191 192 /*!
192 193 \property QAbstractAxis::shadesPen
193 194 The pen of the axis shades (area between grid lines).
194 195 */
195 196
196 197 /*!
197 198 \property QAbstractAxis::shadesBrush
198 199 The brush of the axis shades (area between grid lines).
199 200 */
200 201
201 202 /*!
202 203 \property QAbstractAxis::titleVisible
203 204 The visibility of the axis title. By default the value is true.
204 205 */
205 206 /*!
206 207 \qmlproperty bool AbstractAxis::titleVisible
207 208 The visibility of the axis title. By default the value is true.
208 209 */
209 210
210 211 /*!
211 212 \property QAbstractAxis::titleText
212 213 The title of the axis. Empty by default.
213 214 */
214 215 /*!
215 216 \qmlproperty String AbstractAxis::titleText
216 217 The title of the axis. Empty by default.
217 218 */
218 219
219 220 /*!
220 221 \property QAbstractAxis::titlePen
221 222 The pen of the title text.
222 223 */
223 224
224 225 /*!
225 226 \property QAbstractAxis::titleBrush
226 227 The brush of the title text.
227 228 */
228 229
229 230 /*!
230 231 \property QAbstractAxis::titleFont
231 232 The font of the title of the axis.
232 233 */
233 234 /*!
234 235 \qmlproperty Font AbstractAxis::titleFont
235 236 The font of the title of the axis.
236 237 */
237 238
238 239 /*!
239 240 \property QAbstractAxis::orientation
240 241 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
241 242 */
242 243 /*!
243 244 \qmlproperty Qt.Orientation AbstractAxis::orientation
244 245 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
245 246 */
246 247
247 248 /*!
248 249 \property QAbstractAxis::alignment
249 250 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
250 251 */
251 252 /*!
252 253 \qmlproperty alignment AbstractAxis::alignment
253 254 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
254 255 */
255 256
256 257 /*!
257 258 \fn void QAbstractAxis::visibleChanged(bool visible)
258 259 Visibility of the axis has changed to \a visible.
259 260 */
260 261 /*!
261 262 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
262 263 Visibility of the axis has changed to \a visible.
263 264 */
264 265
265 266 /*!
266 267 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
267 268 The pen of the line of the axis has changed to \a pen.
268 269 */
269 270
270 271 /*!
271 272 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
272 273 Visibility of the axis line has changed to \a visible.
273 274 */
274 275 /*!
275 276 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
276 277 Visibility of the axis line has changed to \a visible.
277 278 */
278 279
279 280 /*!
280 281 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
281 282 Visibility of the labels of the axis has changed to \a visible.
282 283 */
283 284 /*!
284 285 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
285 286 Visibility of the labels of the axis has changed to \a visible.
286 287 */
287 288
288 289 /*!
289 290 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
290 291 The font of the axis labels has changed to \a font.
291 292 */
292 293 /*!
293 294 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
294 295 The font of the axis labels has changed to \a font.
295 296 */
296 297
297 298 /*!
298 299 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
299 300 The pen of the axis labels has changed to \a pen.
300 301 */
301 302
302 303 /*!
303 304 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
304 305 The brush of the axis labels has changed to \a brush.
305 306 */
306 307
307 308 /*!
308 309 \fn void QAbstractAxis::labelsAngleChanged(int angle)
309 310 The angle of the axis labels has changed to \a angle.
310 311 */
311 312 /*!
312 313 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
313 314 The angle of the axis labels has changed to \a angle.
314 315 */
315 316
316 317 /*!
317 318 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
318 319 Visibility of the grid lines of the axis has changed to \a visible.
319 320 */
320 321 /*!
321 322 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
322 323 Visibility of the grid lines of the axis has changed to \a visible.
323 324 */
324 325
325 326 /*!
326 327 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
327 328 The pen of the grid line has changed to \a pen.
328 329 */
329 330
330 331 /*!
331 332 \fn void QAbstractAxis::colorChanged(QColor color)
332 333 Emitted if the \a color of the axis is changed.
333 334 */
334 335 /*!
335 336 \qmlsignal AbstractAxis::onColorChanged(QColor color)
336 337 Emitted if the \a color of the axis is changed.
337 338 */
338 339
339 340 /*!
340 341 \fn void QAbstractAxis::labelsColorChanged(QColor color)
341 342 Emitted if the \a color of the axis labels is changed.
342 343 */
343 344 /*!
344 345 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
345 346 Emitted if the \a color of the axis labels is changed.
346 347 */
347 348
348 349 /*!
349 350 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
350 351 Visibility of the title text of the axis has changed to \a visible.
351 352 */
352 353 /*!
353 354 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
354 355 Visibility of the title text of the axis has changed to \a visible.
355 356 */
356 357
357 358 /*!
358 359 \fn void QAbstractAxis::titleTextChanged(const QString& text)
359 360 The text of the axis title has changed to \a text.
360 361 */
361 362 /*!
362 363 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
363 364 The text of the axis title has changed to \a text.
364 365 */
365 366
366 367 /*!
367 368 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
368 369 The pen of the axis shades has changed to \a pen.
369 370 */
370 371
371 372 /*!
372 373 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
373 374 The brush of the axis title has changed to \a brush.
374 375 */
375 376
376 377 /*!
377 378 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
378 379 The font of the axis title has changed to \a font.
379 380 */
380 381 /*!
381 382 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
382 383 The font of the axis title has changed to \a font.
383 384 */
384 385
385 386 /*!
386 387 \fn void QAbstractAxis::shadesVisibleChanged(bool)
387 388 Emitted if the visibility of the axis shades is changed to \a visible.
388 389 */
389 390 /*!
390 391 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
391 392 Emitted if the visibility of the axis shades is changed to \a visible.
392 393 */
393 394
394 395 /*!
395 396 \fn void QAbstractAxis::shadesColorChanged(QColor color)
396 397 Emitted if the \a color of the axis shades is changed.
397 398 */
398 399 /*!
399 400 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
400 401 Emitted if the \a color of the axis shades is changed.
401 402 */
402 403
403 404 /*!
404 405 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
405 406 Emitted if the border \a color of the axis shades is changed.
406 407 */
407 408 /*!
408 409 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
409 410 Emitted if the border \a color of the axis shades is changed.
410 411 */
411 412
412 413 /*!
413 414 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
414 415 The brush of the axis shades has changed to \a brush.
415 416 */
416 417
417 418 /*!
418 419 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
419 420 The pen of the axis shades has changed to \a pen.
420 421 */
421 422
422 423 /*!
423 424 \internal
424 425 Constructs new axis object which is a child of \a parent. Ownership is taken by
425 426 QChart when axis added.
426 427 */
427 428
428 429 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
429 430 : QObject(parent),
430 431 d_ptr(&d)
431 432 {
432 433 }
433 434
434 435 /*!
435 436 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
436 437 */
437 438
438 439 QAbstractAxis::~QAbstractAxis()
439 440 {
440 441 if (d_ptr->m_chart)
441 442 qFatal("Still binded axis detected !");
442 443 }
443 444
444 445 /*!
445 446 Sets \a pen used to draw axis line and ticks.
446 447 */
447 448 void QAbstractAxis::setLinePen(const QPen &pen)
448 449 {
449 450 if (d_ptr->m_axisPen != pen) {
450 451 d_ptr->m_axisPen = pen;
451 452 emit linePenChanged(pen);
452 453 }
453 454 }
454 455
455 456 /*!
456 457 Returns pen used to draw axis and ticks.
457 458 */
458 459 QPen QAbstractAxis::linePen() const
459 460 {
460 461 return d_ptr->m_axisPen;
461 462 }
462 463
463 464 //TODO: remove me 2.0
464 465 void QAbstractAxis::setLinePenColor(QColor color)
465 466 {
466 467 QPen p = d_ptr->m_axisPen;
467 468 if (p.color() != color) {
468 469 p.setColor(color);
469 470 setLinePen(p);
470 471 emit colorChanged(color);
471 472 }
472 473 }
473 474
474 475 QColor QAbstractAxis::linePenColor() const
475 476 {
476 477 return d_ptr->m_axisPen.color();
477 478 }
478 479
479 480 /*!
480 481 Sets if axis and ticks are \a visible.
481 482 */
482 483 void QAbstractAxis::setLineVisible(bool visible)
483 484 {
484 485 if (d_ptr->m_arrowVisible != visible) {
485 486 d_ptr->m_arrowVisible = visible;
486 487 emit lineVisibleChanged(visible);
487 488 }
488 489 }
489 490
490 491 bool QAbstractAxis::isLineVisible() const
491 492 {
492 493 return d_ptr->m_arrowVisible;
493 494 }
494 495
495 496 void QAbstractAxis::setGridLineVisible(bool visible)
496 497 {
497 498 if (d_ptr->m_gridLineVisible != visible) {
498 499 d_ptr->m_gridLineVisible = visible;
499 500 emit gridVisibleChanged(visible);
500 501 }
501 502 }
502 503
503 504 bool QAbstractAxis::isGridLineVisible() const
504 505 {
505 506 return d_ptr->m_gridLineVisible;
506 507 }
507 508
508 509 /*!
509 510 Sets \a pen used to draw grid line.
510 511 */
511 512 void QAbstractAxis::setGridLinePen(const QPen &pen)
512 513 {
513 514 if (d_ptr->m_gridLinePen != pen) {
514 515 d_ptr->m_gridLinePen = pen;
515 516 emit gridLinePenChanged(pen);
516 517 }
517 518 }
518 519
519 520 /*!
520 521 Returns pen used to draw grid.
521 522 */
522 523 QPen QAbstractAxis::gridLinePen() const
523 524 {
524 525 return d_ptr->m_gridLinePen;
525 526 }
526 527
527 528 void QAbstractAxis::setLabelsVisible(bool visible)
528 529 {
529 530 if (d_ptr->m_labelsVisible != visible) {
530 531 d_ptr->m_labelsVisible = visible;
531 532 emit labelsVisibleChanged(visible);
532 533 }
533 534 }
534 535
535 536 bool QAbstractAxis::labelsVisible() const
536 537 {
537 538 return d_ptr->m_labelsVisible;
538 539 }
539 540
540 541 /*!
541 542 Sets \a pen used to draw labels.
542 543 */
543 544 void QAbstractAxis::setLabelsPen(const QPen &pen)
544 545 {
545 546 if (d_ptr->m_labelsPen != pen) {
546 547 d_ptr->m_labelsPen = pen;
547 548 emit labelsPenChanged(pen);
548 549 }
549 550 }
550 551
551 552 /*!
552 553 Returns the pen used to labels.
553 554 */
554 555 QPen QAbstractAxis::labelsPen() const
555 556 {
556 557 return d_ptr->m_labelsPen;
557 558 }
558 559
559 560 /*!
560 561 Sets \a brush used to draw labels.
561 562 */
562 563 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
563 564 {
564 565 if (d_ptr->m_labelsBrush != brush) {
565 566 d_ptr->m_labelsBrush = brush;
566 567 emit labelsBrushChanged(brush);
567 568 }
568 569 }
569 570
570 571 /*!
571 572 Returns brush used to draw labels.
572 573 */
573 574 QBrush QAbstractAxis::labelsBrush() const
574 575 {
575 576 return d_ptr->m_labelsBrush;
576 577 }
577 578
578 579 /*!
579 580 Sets \a font used to draw labels.
580 581 */
581 582 void QAbstractAxis::setLabelsFont(const QFont &font)
582 583 {
583 584 if (d_ptr->m_labelsFont != font) {
584 585 d_ptr->m_labelsFont = font;
585 586 emit labelsFontChanged(font);
586 587 }
587 588 }
588 589
589 590 /*!
590 591 Returns font used to draw labels.
591 592 */
592 593 QFont QAbstractAxis::labelsFont() const
593 594 {
594 595 return d_ptr->m_labelsFont;
595 596 }
596 597
597 598 void QAbstractAxis::setLabelsAngle(int angle)
598 599 {
599 600 if (d_ptr->m_labelsAngle != angle) {
600 601 d_ptr->m_labelsAngle = angle;
601 602 emit labelsAngleChanged(angle);
602 603 }
603 604 }
604 605
605 606 int QAbstractAxis::labelsAngle() const
606 607 {
607 608 return d_ptr->m_labelsAngle;
608 609 }
609 610 //TODO: remove me 2.0
610 611 void QAbstractAxis::setLabelsColor(QColor color)
611 612 {
612 613 QBrush b = d_ptr->m_labelsBrush;
613 614 if (b.color() != color) {
614 615 b.setColor(color);
615 616 setLabelsBrush(b);
616 617 emit labelsColorChanged(color);
617 618 }
618 619 }
619 620
620 621 QColor QAbstractAxis::labelsColor() const
621 622 {
622 623 return d_ptr->m_labelsBrush.color();
623 624 }
624 625
625 626 void QAbstractAxis::setTitleVisible(bool visible)
626 627 {
627 628 if (d_ptr->m_titleVisible != visible) {
628 629 d_ptr->m_titleVisible = visible;
629 630 emit titleVisibleChanged(visible);
630 631 }
631 632 }
632 633
633 634 bool QAbstractAxis::isTitleVisible() const
634 635 {
635 636 return d_ptr->m_titleVisible;
636 637 }
637 638
638 639 /*!
639 640 Sets \a pen used to draw title.
640 641 */
641 642 void QAbstractAxis::setTitlePen(const QPen &pen)
642 643 {
643 644 if (d_ptr->m_titlePen != pen) {
644 645 d_ptr->m_titlePen = pen;
645 646 emit titlePenChanged(pen);
646 647 }
647 648 }
648 649
649 650 /*!
650 651 Returns the pen used to title.
651 652 */
652 653 QPen QAbstractAxis::titlePen() const
653 654 {
654 655 return d_ptr->m_titlePen;
655 656 }
656 657
657 658 /*!
658 659 Sets \a brush used to draw title.
659 660 */
660 661 void QAbstractAxis::setTitleBrush(const QBrush &brush)
661 662 {
662 663 if (d_ptr->m_titleBrush != brush) {
663 664 d_ptr->m_titleBrush = brush;
664 665 emit titleBrushChanged(brush);
665 666 }
666 667 }
667 668
668 669 /*!
669 670 Returns brush used to draw title.
670 671 */
671 672 QBrush QAbstractAxis::titleBrush() const
672 673 {
673 674 return d_ptr->m_titleBrush;
674 675 }
675 676
676 677 /*!
677 678 Sets \a font used to draw title.
678 679 */
679 680 void QAbstractAxis::setTitleFont(const QFont &font)
680 681 {
681 682 if (d_ptr->m_titleFont != font) {
682 683 d_ptr->m_titleFont = font;
683 684 emit titleFontChanged(font);
684 685 }
685 686 }
686 687
687 688 /*!
688 689 Returns font used to draw title.
689 690 */
690 691 QFont QAbstractAxis::titleFont() const
691 692 {
692 693 return d_ptr->m_titleFont;
693 694 }
694 695
695 696 void QAbstractAxis::setTitleText(const QString &title)
696 697 {
697 698 if (d_ptr->m_title != title) {
698 699 d_ptr->m_title = title;
699 700 emit titleTextChanged(title);
700 701 }
701 702 }
702 703
703 704 QString QAbstractAxis::titleText() const
704 705 {
705 706 return d_ptr->m_title;
706 707 }
707 708
708 709
709 710 void QAbstractAxis::setShadesVisible(bool visible)
710 711 {
711 712 if (d_ptr->m_shadesVisible != visible) {
712 713 d_ptr->m_shadesVisible = visible;
713 714 emit shadesVisibleChanged(visible);
714 715 }
715 716 }
716 717
717 718 bool QAbstractAxis::shadesVisible() const
718 719 {
719 720 return d_ptr->m_shadesVisible;
720 721 }
721 722
722 723 /*!
723 724 Sets \a pen used to draw shades.
724 725 */
725 726 void QAbstractAxis::setShadesPen(const QPen &pen)
726 727 {
727 728 if (d_ptr->m_shadesPen != pen) {
728 729 d_ptr->m_shadesPen = pen;
729 730 emit shadesPenChanged(pen);
730 731 }
731 732 }
732 733
733 734 /*!
734 735 Returns pen used to draw shades.
735 736 */
736 737 QPen QAbstractAxis::shadesPen() const
737 738 {
738 739 return d_ptr->m_shadesPen;
739 740 }
740 741
741 742 /*!
742 743 Sets \a brush used to draw shades.
743 744 */
744 745 void QAbstractAxis::setShadesBrush(const QBrush &brush)
745 746 {
746 747 if (d_ptr->m_shadesBrush != brush) {
747 748 d_ptr->m_shadesBrush = brush;
748 749 emit shadesBrushChanged(brush);
749 750 }
750 751 }
751 752
752 753 /*!
753 754 Returns brush used to draw shades.
754 755 */
755 756 QBrush QAbstractAxis::shadesBrush() const
756 757 {
757 758 return d_ptr->m_shadesBrush;
758 759 }
759 760
760 761 void QAbstractAxis::setShadesColor(QColor color)
761 762 {
762 763 QBrush b = d_ptr->m_shadesBrush;
763 764 if (b.color() != color) {
764 765 b.setColor(color);
765 766 setShadesBrush(b);
766 767 emit shadesColorChanged(color);
767 768 }
768 769 }
769 770
770 771 QColor QAbstractAxis::shadesColor() const
771 772 {
772 773 return d_ptr->m_shadesBrush.color();
773 774 }
774 775
775 776 void QAbstractAxis::setShadesBorderColor(QColor color)
776 777 {
777 778 QPen p = d_ptr->m_shadesPen;
778 779 if (p.color() != color) {
779 780 p.setColor(color);
780 781 setShadesPen(p);
781 782 emit shadesColorChanged(color);
782 783 }
783 784 }
784 785
785 786 QColor QAbstractAxis::shadesBorderColor() const
786 787 {
787 788 return d_ptr->m_shadesPen.color();
788 789 }
789 790
790 791
791 792 bool QAbstractAxis::isVisible() const
792 793 {
793 794 return d_ptr->m_visible;
794 795 }
795 796
796 797 /*!
797 798 Sets axis, shades, labels and grid lines to be visible.
798 799 */
799 800 void QAbstractAxis::setVisible(bool visible)
800 801 {
801 802 if (d_ptr->m_visible != visible) {
802 803 d_ptr->m_visible = visible;
803 804 emit visibleChanged(visible);
804 805 }
805 806 }
806 807
807 808
808 809 /*!
809 810 Sets axis, shades, labels and grid lines to be visible.
810 811 */
811 812 void QAbstractAxis::show()
812 813 {
813 814 setVisible(true);
814 815 }
815 816
816 817 /*!
817 818 Sets axis, shades, labels and grid lines to not be visible.
818 819 */
819 820 void QAbstractAxis::hide()
820 821 {
821 822 setVisible(false);
822 823 }
823 824
824 825 /*!
825 826 Sets the minimum value shown on the axis.
826 827 Depending on the actual axis type the \a min parameter is converted to appropriate type.
827 828 If the conversion is impossible then the function call does nothing
828 829 */
829 830 void QAbstractAxis::setMin(const QVariant &min)
830 831 {
831 832 d_ptr->setMin(min);
832 833 }
833 834
834 835 /*!
835 836 Sets the maximum value shown on the axis.
836 837 Depending on the actual axis type the \a max parameter is converted to appropriate type.
837 838 If the conversion is impossible then the function call does nothing
838 839 */
839 840 void QAbstractAxis::setMax(const QVariant &max)
840 841 {
841 842 d_ptr->setMax(max);
842 843 }
843 844
844 845 /*!
845 846 Sets the range shown on the axis.
846 847 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
847 848 If the conversion is impossible then the function call does nothing.
848 849 */
849 850 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
850 851 {
851 852 d_ptr->setRange(min, max);
852 853 }
853 854
854 855
855 856 /*!
856 857 Returns the orientation in which the axis is being used (Vertical or Horizontal)
857 858 */
858 859 // NOTE: should have const but it breaks BC:
859 860 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
860 861 Qt::Orientation QAbstractAxis::orientation()
861 862 {
862 863 return d_ptr->orientation();
863 864 }
864 865
865 866 Qt::Alignment QAbstractAxis::alignment() const
866 867 {
867 868 return d_ptr->alignment();
868 869 }
869 870
870 871 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
871 872
872 873 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
873 874 : q_ptr(q),
874 875 m_chart(0),
875 876 m_alignment(0),
876 877 m_orientation(Qt::Orientation(0)),
877 878 m_visible(true),
878 879 m_arrowVisible(true),
880 m_axisPen(QChartPrivate::defaultPen()),
881 m_axisBrush(QChartPrivate::defaultBrush()),
879 882 m_gridLineVisible(true),
883 m_gridLinePen(QChartPrivate::defaultPen()),
880 884 m_labelsVisible(true),
885 m_labelsPen(QChartPrivate::defaultPen()),
886 m_labelsBrush(QChartPrivate::defaultBrush()),
887 m_labelsFont(QChartPrivate::defaultFont()),
881 888 m_labelsAngle(0),
882 889 m_titleVisible(true),
890 m_titlePen(QChartPrivate::defaultPen()),
891 m_titleBrush(QChartPrivate::defaultBrush()),
892 m_titleFont(QChartPrivate::defaultFont()),
883 893 m_shadesVisible(false),
884 m_shadesBrush(Qt::SolidPattern),
894 m_shadesBrush(QChartPrivate::defaultBrush()),
895 m_shadesPen(QChartPrivate::defaultPen()),
885 896 m_shadesOpacity(1.0),
886 897 m_dirty(false)
887 898 {
888
889 899 }
890 900
891 901 QAbstractAxisPrivate::~QAbstractAxisPrivate()
892 902 {
893 903 }
894 904
895 905 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
896 906 {
897 907 switch(alignment) {
898 908 case Qt::AlignTop:
899 909 case Qt::AlignBottom:
900 910 m_orientation = Qt::Horizontal;
901 911 break;
902 912 case Qt::AlignLeft:
903 913 case Qt::AlignRight:
904 914 m_orientation = Qt::Vertical;
905 915 break;
906 916 default:
907 917 qWarning()<<"No alignment specified !";
908 918 break;
909 919 };
910 920 m_alignment=alignment;
911 921 }
912 922
913 923 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
914 924 {
915 QPen pen;
916 QBrush brush;
917 QFont font;
918
919 bool axisX = m_orientation == Qt::Horizontal;
920
921 925 //TODO: introduce axis brush
922 if (m_visible) {
923 if (m_arrowVisible) {
924 if (forced || pen == m_axisPen) {
926 if (forced || QChartPrivate::defaultPen() == m_axisPen)
925 927 q_ptr->setLinePen(theme->axisLinePen());
926 }
927 }
928 if (m_gridLineVisible) {
929 if (forced || pen == m_gridLinePen) {
928
929 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
930 930 q_ptr->setGridLinePen(theme->girdLinePen());
931 }
932 }
933 if (m_labelsVisible) {
934 if (forced || brush == m_labelsBrush){
931
932 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
935 933 q_ptr->setLabelsBrush(theme->labelBrush());
936 }
937 if (forced || pen == m_labelsPen){
934 if (forced || QChartPrivate::defaultPen() == m_labelsPen)
938 935 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
939 }
940 if (forced || font == m_labelsFont){
936 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
941 937 q_ptr->setLabelsFont(theme->labelFont());
942 }
943 }
944 if (m_titleVisible) {
945 if (forced || brush == m_titleBrush){
938
939 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
946 940 q_ptr->setTitleBrush(theme->labelBrush());
947 }
948 if (forced || pen == m_titlePen){
949 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
950 }
951 if (forced || font == m_titleFont){
941 if (forced || QChartPrivate::defaultPen() == m_titlePen)
942 q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons
943 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
952 944 QFont font(m_labelsFont);
953 945 font.setBold(true);
954 946 q_ptr->setTitleFont(font);
955 947 }
956 }
957 if (forced || m_shadesVisible) {
958 if (forced || brush == m_shadesBrush){
948
949 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
959 950 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
960 }
961 if (forced || pen == m_shadesPen){
951 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
962 952 q_ptr->setShadesPen(theme->backgroundShadesPen());
963 }
953
954 bool axisX = m_orientation == Qt::Horizontal;
964 955 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
965 956 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
966 957 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
967 958 q_ptr->setShadesVisible(true);
968 }
969 }
959 } else if (forced) {
960 q_ptr->setShadesVisible(false);
970 961 }
971 962 }
972 963
973 964 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
974 965 {
975 966 setRange(min,max);
976 967 }
977 968
978 969 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
979 970 {
980 971 Q_UNUSED(parent);
981 972 }
982 973
983 974 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
984 975 {
985 976 ChartAxisElement *axis = m_item.data();
986 977 Q_ASSERT(axis);
987 978 if (options.testFlag(QChart::GridAxisAnimations)) {
988 979 axis->setAnimation(new AxisAnimation(axis));
989 980 } else {
990 981 axis->setAnimation(0);
991 982 }
992 983 }
993 984
994 985
995 986
996 987 #include "moc_qabstractaxis.cpp"
997 988 #include "moc_qabstractaxis_p.cpp"
998 989
999 990 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,129 +1,130
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 QABSTRACTAXIS_P_H
31 31 #define QABSTRACTAXIS_P_H
32 32
33 33 #include "qabstractaxis.h"
34 34 #include "chartaxiselement_p.h"
35 35 #include "qchart.h"
36 36 #include <QDebug>
37 37
38 38 class QGraphicsItem;
39 39
40 40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 41
42 42 class ChartPresenter;
43 43 class AbstractDomain;
44 44 class QChart;
45 45 class QAbstractSeries;
46 46 class ChartTheme;
47 47 class ChartElement;
48 48
49 49 class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject
50 50 {
51 51 Q_OBJECT
52 52 public:
53 53 QAbstractAxisPrivate(QAbstractAxis *q);
54 54 ~QAbstractAxisPrivate();
55 55
56 56 public:
57 57 Qt::Alignment alignment() const { return m_alignment; }
58 58 Qt::Orientation orientation() const { return m_orientation; }
59 59 void setAlignment( Qt::Alignment alignment);
60 60
61 61 virtual void initializeDomain(AbstractDomain *domain) = 0;
62 62 virtual void initializeGraphics(QGraphicsItem *parent) = 0;
63 63 virtual void initializeTheme(ChartTheme* theme, bool forced = false);
64 64 virtual void initializeAnimations(QChart::AnimationOptions options);
65 65
66 66 //interface for manipulating range form base class
67 67 virtual void setMin(const QVariant &min) = 0;
68 68 virtual void setMax(const QVariant &max) = 0;
69 69 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
70 70
71 71 //interface manipulating range form domain
72 72 virtual void setRange(qreal min, qreal max) = 0;
73 73 virtual qreal min() = 0;
74 74 virtual qreal max() = 0;
75 75
76 76 ChartAxisElement *axisItem() { return m_item.data(); }
77 77
78 78 public Q_SLOTS:
79 79 void handleRangeChanged(qreal min, qreal max);
80 80
81 81 Q_SIGNALS:
82 82 void rangeChanged(qreal min, qreal max);
83 83
84 84 protected:
85 85 QAbstractAxis *q_ptr;
86 86 QChart *m_chart;
87 87 QScopedPointer<ChartAxisElement> m_item;
88
88 89 private:
89 90 QList<QAbstractSeries*> m_series;
90 91
91 92 Qt::Alignment m_alignment;
92 93 Qt::Orientation m_orientation;
93 94
94 95 bool m_visible;
95 96
96 97 bool m_arrowVisible;
97 98 QPen m_axisPen;
98 99 QBrush m_axisBrush;
99 100
100 101 bool m_gridLineVisible;
101 102 QPen m_gridLinePen;
102 103
103 104 bool m_labelsVisible;
104 105 QPen m_labelsPen;
105 106 QBrush m_labelsBrush;
106 107 QFont m_labelsFont;
107 108 int m_labelsAngle;
108 109
109 110 bool m_titleVisible;
110 111 QPen m_titlePen;
111 112 QBrush m_titleBrush;
112 113 QFont m_titleFont;
113 114 QString m_title;
114 115
115 116 bool m_shadesVisible;
116 117 QPen m_shadesPen;
117 118 QBrush m_shadesBrush;
118 119 qreal m_shadesOpacity;
119 120
120 121 bool m_dirty;
121 122
122 123 friend class QAbstractAxis;
123 124 friend class ChartDataSet;
124 125 friend class ChartPresenter;
125 126 };
126 127
127 128 QTCOMMERCIALCHART_END_NAMESPACE
128 129
129 130 #endif
@@ -1,901 +1,899
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 "qabstractbarseries.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "abstractdomain_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "qvalueaxis.h"
29 29 #include "qbarcategoryaxis.h"
30 30 #include "qbarlegendmarker.h"
31 31 #include "baranimation_p.h"
32 32 #include "abstractbarchartitem_p.h"
33 #include "qchart_p.h"
33 34
34 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 36
36 37 /*!
37 38 \class QAbstractBarSeries
38 39 \brief Series for creating a bar chart
39 40 \mainclass
40 41
41 42 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
42 43 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
43 44 and y-value is the height of the bar. The category names are ignored with this series and x-axis
44 45 shows the x-values.
45 46
46 47 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
47 48 \image examples_barchart.png
48 49
49 50 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
50 51 */
51 52 /*!
52 53 \qmlclass AbstractBarSeries QAbstractBarSeries
53 54 \inherits QAbstractSeries
54 55
55 56 The following QML shows how to create a simple bar chart:
56 57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
57 58
58 59 \beginfloatleft
59 60 \image demos_qmlchart6.png
60 61 \endfloat
61 62 \clearfloat
62 63 */
63 64
64 65 /*!
65 66 \qmlproperty AbstractAxis AbstractBarSeries::axisX
66 67 The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for
67 68 the series.
68 69 \sa axisXTop
69 70 */
70 71
71 72 /*!
72 73 \qmlproperty AbstractAxis AbstractBarSeries::axisY
73 74 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
74 75 the series.
75 76 \sa axisYRight
76 77 */
77 78
78 79 /*!
79 80 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
80 81 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
81 82 axisXTop, but not both.
82 83 \sa axisX
83 84 */
84 85
85 86 /*!
86 87 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
87 88 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
88 89 or axisYRight, but not both.
89 90 \sa axisY
90 91 */
91 92
92 93 /*!
93 94 \property QAbstractBarSeries::barWidth
94 95 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
95 96 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
96 97 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
97 98 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
98 99 \sa QBarSeries
99 100 */
100 101 /*!
101 102 \qmlproperty real AbstractBarSeries::barWidth
102 103 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
103 104 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
104 105 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
105 106 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
106 107 */
107 108
108 109 /*!
109 110 \property QAbstractBarSeries::count
110 111 Holds the number of sets in series.
111 112 */
112 113 /*!
113 114 \qmlproperty int AbstractBarSeries::count
114 115 Holds the number of sets in series.
115 116 */
116 117
117 118 /*!
118 119 \property QAbstractBarSeries::labelsVisible
119 120 Defines the visibility of the labels in series
120 121 */
121 122 /*!
122 123 \qmlproperty bool AbstractBarSeries::labelsVisible
123 124 Defines the visibility of the labels in series
124 125 */
125 126
126 127 /*!
127 128 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
128 129 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
129 130 Clicked bar inside set is indexed by \a index
130 131 */
131 132 /*!
132 133 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
133 134 The signal is emitted if the user clicks with a mouse on top of BarSet.
134 135 Clicked bar inside set is indexed by \a index
135 136 */
136 137
137 138 /*!
138 139 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
139 140
140 141 The signal is emitted if mouse is hovered on top of series.
141 142 Parameter \a barset is the pointer of barset, where hover happened.
142 143 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
143 144 */
144 145 /*!
145 146 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
146 147
147 148 The signal is emitted if mouse is hovered on top of series.
148 149 Parameter \a barset is the pointer of barset, where hover happened.
149 150 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
150 151 */
151 152
152 153 /*!
153 154 \fn void QAbstractBarSeries::countChanged()
154 155 This signal is emitted when barset count has been changed, for example by append or remove.
155 156 */
156 157 /*!
157 158 \qmlsignal AbstractBarSeries::onCountChanged()
158 159 This signal is emitted when barset count has been changed, for example by append or remove.
159 160 */
160 161
161 162 /*!
162 163 \fn void QAbstractBarSeries::labelsVisibleChanged()
163 164 This signal is emitted when labels visibility have changed.
164 165 \sa isLabelsVisible(), setLabelsVisible()
165 166 */
166 167
167 168 /*!
168 169 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
169 170 This signal is emitted when \a sets have been added to the series.
170 171 \sa append(), insert()
171 172 */
172 173 /*!
173 174 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
174 175 Emitted when \a barset has been added to the series.
175 176 */
176 177
177 178 /*!
178 179 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
179 180 This signal is emitted when \a sets have been removed from the series.
180 181 \sa remove()
181 182 */
182 183 /*!
183 184 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
184 185 Emitted when \a barset has been removed from the series.
185 186 */
186 187
187 188 /*!
188 189 \qmlmethod BarSet AbstractBarSeries::at(int index)
189 190 Returns bar set at \a index. Returns null if the index is not valid.
190 191 */
191 192
192 193 /*!
193 194 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
194 195 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
195 196 For example:
196 197 \code
197 198 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
198 199 \endcode
199 200 */
200 201
201 202 /*!
202 203 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
203 204 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
204 205 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
205 206 appended.
206 207 \sa AbstractBarSeries::append()
207 208 */
208 209
209 210 /*!
210 211 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
211 212 Removes the barset from the series. Returns true if successful, false otherwise.
212 213 */
213 214
214 215 /*!
215 216 \qmlmethod AbstractBarSeries::clear()
216 217 Removes all barsets from the series.
217 218 */
218 219
219 220 /*!
220 221 Destructs abstractbarseries and owned barsets.
221 222 */
222 223 QAbstractBarSeries::~QAbstractBarSeries()
223 224 {
224 225
225 226 }
226 227
227 228 /*!
228 229 \internal
229 230 */
230 231 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
231 232 : QAbstractSeries(o, parent)
232 233 {
233 234 Q_D(QAbstractSeries);
234 235 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
235 236 }
236 237
237 238 /*!
238 239 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
239 240 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
240 241 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
241 242 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
242 243 */
243 244 void QAbstractBarSeries::setBarWidth(qreal width)
244 245 {
245 246 Q_D(QAbstractBarSeries);
246 247 d->setBarWidth(width);
247 248 }
248 249
249 250 /*!
250 251 Returns the width of the bars of the series.
251 252 \sa setBarWidth()
252 253 */
253 254 qreal QAbstractBarSeries::barWidth() const
254 255 {
255 256 Q_D(const QAbstractBarSeries);
256 257 return d->barWidth();
257 258 }
258 259
259 260 /*!
260 261 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
261 262 Returns true, if appending succeeded.
262 263 */
263 264 bool QAbstractBarSeries::append(QBarSet *set)
264 265 {
265 266 Q_D(QAbstractBarSeries);
266 267 bool success = d->append(set);
267 268 if (success) {
268 269 QList<QBarSet *> sets;
269 270 sets.append(set);
270 271 set->setParent(this);
271 272 emit barsetsAdded(sets);
272 273 emit countChanged();
273 274 }
274 275 return success;
275 276 }
276 277
277 278 /*!
278 279 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
279 280 was successful.
280 281 Returns true, if set was removed.
281 282 */
282 283 bool QAbstractBarSeries::remove(QBarSet *set)
283 284 {
284 285 Q_D(QAbstractBarSeries);
285 286 bool success = d->remove(set);
286 287 if (success) {
287 288 QList<QBarSet *> sets;
288 289 sets.append(set);
289 290 set->setParent(0);
290 291 emit barsetsRemoved(sets);
291 292 emit countChanged();
292 293 delete set;
293 294 set = 0;
294 295 }
295 296 return success;
296 297 }
297 298
298 299 /*!
299 300 Takes a single \a set from the series. Does not delete the barset object.
300 301
301 302 NOTE: The series remains as the barset's parent object. You must set the
302 303 parent object to take full ownership.
303 304
304 305 Returns true if take was successful.
305 306 */
306 307 bool QAbstractBarSeries::take(QBarSet *set)
307 308 {
308 309 Q_D(QAbstractBarSeries);
309 310 bool success = d->remove(set);
310 311 if (success) {
311 312 QList<QBarSet *> sets;
312 313 sets.append(set);
313 314 emit barsetsRemoved(sets);
314 315 emit countChanged();
315 316 }
316 317 return success;
317 318 }
318 319
319 320 /*!
320 321 Adds a list of barsets to series. Takes ownership of \a sets.
321 322 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
322 323 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
323 324 and function returns false.
324 325 */
325 326 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
326 327 {
327 328 Q_D(QAbstractBarSeries);
328 329 bool success = d->append(sets);
329 330 if (success) {
330 331 emit barsetsAdded(sets);
331 332 emit countChanged();
332 333 }
333 334 return success;
334 335 }
335 336
336 337 /*!
337 338 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
338 339 Returns true, if inserting succeeded.
339 340
340 341 */
341 342 bool QAbstractBarSeries::insert(int index, QBarSet *set)
342 343 {
343 344 Q_D(QAbstractBarSeries);
344 345 bool success = d->insert(index, set);
345 346 if (success) {
346 347 QList<QBarSet *> sets;
347 348 sets.append(set);
348 349 emit barsetsAdded(sets);
349 350 emit countChanged();
350 351 }
351 352 return success;
352 353 }
353 354
354 355 /*!
355 356 Removes all barsets from the series. Deletes removed sets.
356 357 */
357 358 void QAbstractBarSeries::clear()
358 359 {
359 360 Q_D(QAbstractBarSeries);
360 361 QList<QBarSet *> sets = barSets();
361 362 bool success = d->remove(sets);
362 363 if (success) {
363 364 emit barsetsRemoved(sets);
364 365 emit countChanged();
365 366 foreach (QBarSet *set, sets)
366 367 delete set;
367 368 }
368 369 }
369 370
370 371 /*!
371 372 Returns number of sets in series.
372 373 */
373 374 int QAbstractBarSeries::count() const
374 375 {
375 376 Q_D(const QAbstractBarSeries);
376 377 return d->m_barSets.count();
377 378 }
378 379
379 380 /*!
380 381 Returns a list of sets in series. Keeps ownership of sets.
381 382 */
382 383 QList<QBarSet *> QAbstractBarSeries::barSets() const
383 384 {
384 385 Q_D(const QAbstractBarSeries);
385 386 return d->m_barSets;
386 387 }
387 388
388 389 /*!
389 390 Sets the visibility of labels in series to \a visible
390 391 */
391 392 void QAbstractBarSeries::setLabelsVisible(bool visible)
392 393 {
393 394 Q_D(QAbstractBarSeries);
394 395 if (d->m_labelsVisible != visible) {
395 396 d->setLabelsVisible(visible);
396 397 emit labelsVisibleChanged();
397 398 }
398 399 }
399 400
400 401 /*!
401 402 Returns the visibility of labels
402 403 */
403 404 bool QAbstractBarSeries::isLabelsVisible() const
404 405 {
405 406 Q_D(const QAbstractBarSeries);
406 407 return d->m_labelsVisible;
407 408 }
408 409
409 410 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
410 411
411 412 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
412 413 QAbstractSeriesPrivate(q),
413 414 m_barWidth(0.5), // Default value is 50% of category width
414 415 m_labelsVisible(false),
415 416 m_visible(true)
416 417 {
417 418 }
418 419
419 420 int QAbstractBarSeriesPrivate::categoryCount() const
420 421 {
421 422 // No categories defined. return count of longest set.
422 423 int count = 0;
423 424 for (int i = 0; i < m_barSets.count(); i++) {
424 425 if (m_barSets.at(i)->count() > count)
425 426 count = m_barSets.at(i)->count();
426 427 }
427 428
428 429 return count;
429 430 }
430 431
431 432 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
432 433 {
433 434 if (width < 0.0)
434 435 width = 0.0;
435 436 m_barWidth = width;
436 437 emit updatedLayout();
437 438 }
438 439
439 440 qreal QAbstractBarSeriesPrivate::barWidth() const
440 441 {
441 442 return m_barWidth;
442 443 }
443 444
444 445 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
445 446 {
446 447 return m_barSets.at(index);
447 448 }
448 449
449 450 void QAbstractBarSeriesPrivate::setVisible(bool visible)
450 451 {
451 452 m_visible = visible;
452 453 emit visibleChanged();
453 454 }
454 455
455 456 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
456 457 {
457 458 m_labelsVisible = visible;
458 459 emit labelsVisibleChanged(visible);
459 460 }
460 461
461 462 qreal QAbstractBarSeriesPrivate::min()
462 463 {
463 464 if (m_barSets.count() <= 0)
464 465 return 0;
465 466
466 467 qreal min = INT_MAX;
467 468
468 469 for (int i = 0; i < m_barSets.count(); i++) {
469 470 int categoryCount = m_barSets.at(i)->count();
470 471 for (int j = 0; j < categoryCount; j++) {
471 472 qreal temp = m_barSets.at(i)->at(j);
472 473 if (temp < min)
473 474 min = temp;
474 475 }
475 476 }
476 477 return min;
477 478 }
478 479
479 480 qreal QAbstractBarSeriesPrivate::max()
480 481 {
481 482 if (m_barSets.count() <= 0)
482 483 return 0;
483 484
484 485 qreal max = INT_MIN;
485 486
486 487 for (int i = 0; i < m_barSets.count(); i++) {
487 488 int categoryCount = m_barSets.at(i)->count();
488 489 for (int j = 0; j < categoryCount; j++) {
489 490 qreal temp = m_barSets.at(i)->at(j);
490 491 if (temp > max)
491 492 max = temp;
492 493 }
493 494 }
494 495
495 496 return max;
496 497 }
497 498
498 499 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
499 500 {
500 501 if ((set < 0) || (set >= m_barSets.count()))
501 502 return 0; // No set, no value.
502 503 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
503 504 return 0; // No category, no value.
504 505
505 506 return m_barSets.at(set)->at(category);
506 507 }
507 508
508 509 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
509 510 {
510 511 if ((set < 0) || (set >= m_barSets.count()))
511 512 return 0; // No set, no value.
512 513 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
513 514 return 0; // No category, no value.
514 515
515 516 qreal value = m_barSets.at(set)->at(category);
516 517 qreal sum = categorySum(category);
517 518 if (qFuzzyCompare(sum, 0))
518 519 return 0;
519 520
520 521 return value / sum;
521 522 }
522 523
523 524 qreal QAbstractBarSeriesPrivate::categorySum(int category)
524 525 {
525 526 qreal sum(0);
526 527 int count = m_barSets.count(); // Count sets
527 528 for (int set = 0; set < count; set++) {
528 529 if (category < m_barSets.at(set)->count())
529 530 sum += m_barSets.at(set)->at(category);
530 531 }
531 532 return sum;
532 533 }
533 534
534 535 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
535 536 {
536 537 qreal sum(0);
537 538 int count = m_barSets.count(); // Count sets
538 539 for (int set = 0; set < count; set++) {
539 540 if (category < m_barSets.at(set)->count())
540 541 sum += qAbs(m_barSets.at(set)->at(category));
541 542 }
542 543 return sum;
543 544 }
544 545
545 546 qreal QAbstractBarSeriesPrivate::maxCategorySum()
546 547 {
547 548 qreal max = INT_MIN;
548 549 int count = categoryCount();
549 550 for (int i = 0; i < count; i++) {
550 551 qreal sum = categorySum(i);
551 552 if (sum > max)
552 553 max = sum;
553 554 }
554 555 return max;
555 556 }
556 557
557 558 qreal QAbstractBarSeriesPrivate::minX()
558 559 {
559 560 if (m_barSets.count() <= 0)
560 561 return 0;
561 562
562 563 qreal min = INT_MAX;
563 564
564 565 for (int i = 0; i < m_barSets.count(); i++) {
565 566 int categoryCount = m_barSets.at(i)->count();
566 567 for (int j = 0; j < categoryCount; j++) {
567 568 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
568 569 if (temp < min)
569 570 min = temp;
570 571 }
571 572 }
572 573 return min;
573 574 }
574 575
575 576 qreal QAbstractBarSeriesPrivate::maxX()
576 577 {
577 578 if (m_barSets.count() <= 0)
578 579 return 0;
579 580
580 581 qreal max = INT_MIN;
581 582
582 583 for (int i = 0; i < m_barSets.count(); i++) {
583 584 int categoryCount = m_barSets.at(i)->count();
584 585 for (int j = 0; j < categoryCount; j++) {
585 586 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
586 587 if (temp > max)
587 588 max = temp;
588 589 }
589 590 }
590 591
591 592 return max;
592 593 }
593 594
594 595 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
595 596 {
596 597 // Returns top (sum of all positive values) of category.
597 598 // Returns 0, if all values are negative
598 599 qreal top(0);
599 600 int count = m_barSets.count();
600 601 for (int set = 0; set < count; set++) {
601 602 if (category < m_barSets.at(set)->count()) {
602 603 qreal temp = m_barSets.at(set)->at(category);
603 604 if (temp > 0) {
604 605 top += temp;
605 606 }
606 607 }
607 608 }
608 609 return top;
609 610 }
610 611
611 612 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
612 613 {
613 614 // Returns bottom (sum of all negative values) of category
614 615 // Returns 0, if all values are positive
615 616 qreal bottom(0);
616 617 int count = m_barSets.count();
617 618 for (int set = 0; set < count; set++) {
618 619 if (category < m_barSets.at(set)->count()) {
619 620 qreal temp = m_barSets.at(set)->at(category);
620 621 if (temp < 0) {
621 622 bottom += temp;
622 623 }
623 624 }
624 625 }
625 626 return bottom;
626 627 }
627 628
628 629 qreal QAbstractBarSeriesPrivate::top()
629 630 {
630 631 // Returns top of all categories
631 632 qreal top(0);
632 633 int count = categoryCount();
633 634 for (int i = 0; i < count; i++) {
634 635 qreal temp = categoryTop(i);
635 636 if (temp > top)
636 637 top = temp;
637 638 }
638 639 return top;
639 640 }
640 641
641 642 qreal QAbstractBarSeriesPrivate::bottom()
642 643 {
643 644 // Returns bottom of all categories
644 645 qreal bottom(0);
645 646 int count = categoryCount();
646 647 for (int i = 0; i < count; i++) {
647 648 qreal temp = categoryBottom(i);
648 649 if (temp < bottom)
649 650 bottom = temp;
650 651 }
651 652 return bottom;
652 653 }
653 654
654 655
655 656 void QAbstractBarSeriesPrivate::initializeDomain()
656 657 {
657 658 qreal minX(domain()->minX());
658 659 qreal minY(domain()->minY());
659 660 qreal maxX(domain()->maxX());
660 661 qreal maxY(domain()->maxY());
661 662
662 663 qreal seriesMinX = this->minX();
663 664 qreal seriesMaxX = this->maxX();
664 665 qreal y = max();
665 666 minX = qMin(minX, seriesMinX - (qreal)0.5);
666 667 minY = qMin(minY, y);
667 668 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
668 669 maxY = qMax(maxY, y);
669 670
670 671 domain()->setRange(minX, maxX, minY, maxY);
671 672 }
672 673
673 674 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
674 675 {
675 676 Q_Q(QAbstractBarSeries);
676 677 QList<QLegendMarker*> markers;
677 678
678 679 foreach(QBarSet* set, q->barSets()) {
679 680 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
680 681 markers << marker;
681 682 }
682 683 return markers;
683 684 }
684 685
685 686
686 687 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
687 688 {
688 689 if ((m_barSets.contains(set)) || (set == 0))
689 690 return false; // Fail if set is already in list or set is null.
690 691
691 692 m_barSets.append(set);
692 693 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
693 694 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
694 695 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
695 696
696 697 emit restructuredBars(); // this notifies barchartitem
697 698 return true;
698 699 }
699 700
700 701 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
701 702 {
702 703 if (!m_barSets.contains(set))
703 704 return false; // Fail if set is not in list
704 705
705 706 m_barSets.removeOne(set);
706 707 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
707 708 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
708 709 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
709 710
710 711 emit restructuredBars(); // this notifies barchartitem
711 712 return true;
712 713 }
713 714
714 715 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
715 716 {
716 717 foreach (QBarSet *set, sets) {
717 718 if ((set == 0) || (m_barSets.contains(set)))
718 719 return false; // Fail if any of the sets is null or is already appended.
719 720 if (sets.count(set) != 1)
720 721 return false; // Also fail if same set is more than once in given list.
721 722 }
722 723
723 724 foreach (QBarSet *set, sets) {
724 725 m_barSets.append(set);
725 726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
726 727 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 728 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 729 }
729 730
730 731 emit restructuredBars(); // this notifies barchartitem
731 732 return true;
732 733 }
733 734
734 735 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
735 736 {
736 737 if (sets.count() == 0)
737 738 return false;
738 739
739 740 foreach (QBarSet *set, sets) {
740 741 if ((set == 0) || (!m_barSets.contains(set)))
741 742 return false; // Fail if any of the sets is null or is not in series
742 743 if (sets.count(set) != 1)
743 744 return false; // Also fail if same set is more than once in given list.
744 745 }
745 746
746 747 foreach (QBarSet *set, sets) {
747 748 m_barSets.removeOne(set);
748 749 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
749 750 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
750 751 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
751 752 }
752 753
753 754 emit restructuredBars(); // this notifies barchartitem
754 755
755 756 return true;
756 757 }
757 758
758 759 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
759 760 {
760 761 if ((m_barSets.contains(set)) || (set == 0))
761 762 return false; // Fail if set is already in list or set is null.
762 763
763 764 m_barSets.insert(index, set);
764 765 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
765 766 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
766 767 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
767 768
768 769 emit restructuredBars(); // this notifies barchartitem
769 770 return true;
770 771 }
771 772
772 773 void QAbstractBarSeriesPrivate::initializeAxes()
773 774 {
774 775 Q_Q(QAbstractBarSeries);
775 776
776 777 foreach(QAbstractAxis* axis, m_axes) {
777 778
778 779 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
779 780 switch (q->type()) {
780 781 case QAbstractSeries::SeriesTypeHorizontalBar:
781 782 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
782 783 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
783 784 if (axis->orientation() == Qt::Vertical)
784 785 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
785 786 break;
786 787 case QAbstractSeries::SeriesTypeBar:
787 788 case QAbstractSeries::SeriesTypePercentBar:
788 789 case QAbstractSeries::SeriesTypeStackedBar:
789 790 if (axis->orientation() == Qt::Horizontal)
790 791 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
791 792 break;
792 793 default:
793 794 qWarning() << "Unexpected series type";
794 795 break;
795 796 }
796 797 }
797 798 }
798 799 }
799 800
800 801 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
801 802 {
802 803 Q_Q(const QAbstractBarSeries);
803 804
804 805 switch (q->type()) {
805 806 case QAbstractSeries::SeriesTypeHorizontalBar:
806 807 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
807 808 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
808 809 if (orientation == Qt::Vertical)
809 810 return QAbstractAxis::AxisTypeBarCategory;
810 811 break;
811 812 case QAbstractSeries::SeriesTypeBar:
812 813 case QAbstractSeries::SeriesTypePercentBar:
813 814 case QAbstractSeries::SeriesTypeStackedBar:
814 815 if (orientation == Qt::Horizontal)
815 816 return QAbstractAxis::AxisTypeBarCategory;
816 817 break;
817 818 default:
818 819 qWarning() << "Unexpected series type";
819 820 break;
820 821 }
821 822 return QAbstractAxis::AxisTypeValue;
822 823
823 824 }
824 825
825 826 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
826 827 {
827 828 QStringList categories;
828 829 if (axis->categories().isEmpty()) {
829 830 for (int i(1); i < categoryCount() + 1; i++)
830 831 categories << QString::number(i);
831 832 axis->append(categories);
832 833 }
833 834 }
834 835
835 836 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
836 837 {
837 838 Q_UNUSED(orientation);
838 839 return 0;
839 840 }
840 841
841 842 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
842 843 {
843 844 const QList<QGradient> gradients = theme->seriesGradients();
844 845
845 QBrush brush;
846 QPen pen;
847
848 846 qreal takeAtPos = 0.5;
849 847 qreal step = 0.2;
850 848 if (m_barSets.count() > 1) {
851 849 step = 1.0 / (qreal) m_barSets.count();
852 850 if (m_barSets.count() % gradients.count())
853 851 step *= gradients.count();
854 852 else
855 853 step *= (gradients.count() - 1);
856 854 }
857 855
858 856 for (int i(0); i < m_barSets.count(); i++) {
859 857 int colorIndex = (index + i) % gradients.count();
860 858 if (i > 0 && i %gradients.count() == 0) {
861 859 // There is no dedicated base color for each sets, generate more colors
862 860 takeAtPos += step;
863 861 if (takeAtPos == 1.0)
864 862 takeAtPos += step;
865 863 takeAtPos -= (int) takeAtPos;
866 864 }
867 if (forced || brush == m_barSets.at(i)->brush())
865 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->brush())
868 866 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
869 867
870 868 // Pick label color from the opposite end of the gradient.
871 869 // 0.3 as a boundary seems to work well.
872 if (forced || brush == m_barSets.at(i)->labelBrush()) {
870 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->labelBrush()) {
873 871 if (takeAtPos < 0.3)
874 872 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1));
875 873 else
876 874 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
877 875 }
878 876
879 if (forced || pen == m_barSets.at(i)->pen()) {
877 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->pen()) {
880 878 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
881 879 m_barSets.at(i)->setPen(c);
882 880 }
883 881 }
884 882 }
885 883
886 884 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
887 885 {
888 886 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
889 887 Q_ASSERT(bar);
890 888 if (options.testFlag(QChart::SeriesAnimations)) {
891 889 bar->setAnimation(new BarAnimation(bar));
892 890 }else{
893 891 bar->setAnimation(0);
894 892 }
895 893 QAbstractSeriesPrivate::initializeAnimations(options);
896 894 }
897 895
898 896 #include "moc_qabstractbarseries.cpp"
899 897 #include "moc_qabstractbarseries_p.cpp"
900 898
901 899 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,645 +1,649
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 "qbarset.h"
22 22 #include "qbarset_p.h"
23 23 #include "charthelpers_p.h"
24 #include "qchart_p.h"
24 25
25 26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 27
27 28 /*!
28 29 \class QBarSet
29 30 \brief Building block for different bar charts
30 31
31 32 QBarSet represents one set of bars. Set of bars contains one data value for each category.
32 33 First value of set is assumed to belong to first category, second to second category and so on.
33 34 If set has fewer values than there are categories, then the missing values are assumed to be
34 35 at the end of set. For missing values in middle of a set, numerical value of zero is used.
35 36
36 37 \mainclass
37 38
38 39 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
39 40 */
40 41 /*!
41 42 \qmlclass BarSet QBarSet
42 43
43 44 BarSet represents one set of bars. Set of bars contains one data value for each category.
44 45 First value of set is assumed to belong to first category, second to second category and so on.
45 46 If set has fewer values than there are categories, then the missing values are assumed to be
46 47 at the end of set. For missing values in middle of a set, numerical value of zero is used.
47 48 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
48 49 */
49 50
50 51 /*!
51 52 \property QBarSet::label
52 53 Defines the label of the barSet.
53 54 */
54 55 /*!
55 56 \qmlproperty string BarSet::label
56 57 Defines the label of the barSet.
57 58 */
58 59
59 60 /*!
60 61 \property QBarSet::pen
61 62 \brief Defines the pen used by the barSet.
62 63 */
63 64
64 65 /*!
65 66 \property QBarSet::brush
66 67 \brief Defines the brush used by the barSet.
67 68 */
68 69
69 70 /*!
70 71 \property QBarSet::labelBrush
71 72 \brief Defines the brush used by the barSet's label.
72 73 */
73 74
74 75 /*!
75 76 \property QBarSet::labelFont
76 77 \brief Defines the font used by the barSet's label.
77 78 */
78 79
79 80 /*!
80 81 \qmlproperty Font BarSet::labelFont
81 82 Defines the font used by the barSet's label.
82 83
83 84 See the \l {Font} {QML Font Element} for detailed documentation.
84 85 */
85 86
86 87 /*!
87 88 \property QBarSet::color
88 89 The fill (brush) color of the bar set.
89 90 */
90 91 /*!
91 92 \qmlproperty color BarSet::color
92 93 The fill (brush) color of the bar set.
93 94 */
94 95
95 96 /*!
96 97 \property QBarSet::borderColor
97 98 The line (pen) color of the bar set.
98 99 */
99 100 /*!
100 101 \qmlproperty color BarSet::borderColor
101 102 The line (pen) color of the bar set.
102 103 */
103 104
104 105 /*!
105 106 \qmlproperty real BarSet::borderWidth
106 107 The width of the border line. By default the width is 2.0.
107 108 */
108 109
109 110 /*!
110 111 \property QBarSet::labelColor
111 112 The text (label) color of the bar set.
112 113 */
113 114 /*!
114 115 \qmlproperty color BarSet::labelColor
115 116 The text (label) color of the bar set.
116 117 */
117 118
118 119 /*!
119 120 \fn void QBarSet::clicked(int index)
120 121
121 122 The signal is emitted if the user clicks with a mouse on top of barset.
122 123 Clicked bar inside set is indexed by \a index
123 124 */
124 125
125 126 /*!
126 127 \fn void QBarSet::hovered(bool status)
127 128
128 129 The signal is emitted if mouse is hovered on top of barset.
129 130 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
130 131 */
131 132
132 133
133 134 /*!
134 135 \fn void QBarSet::labelChanged()
135 136 This signal is emitted when the label of the barSet has changed.
136 137 \sa label
137 138 */
138 139 /*!
139 140 \qmlsignal BarSet::onLabelChanged()
140 141 This signal is emitted when the label of the barSet has changed.
141 142 */
142 143
143 144 /*!
144 145 \fn void QBarSet::penChanged()
145 146 This signal is emitted when the pen of the barSet has changed.
146 147 \sa pen
147 148 */
148 149
149 150 /*!
150 151 \fn void QBarSet::brushChanged()
151 152 This signal is emitted when the brush of the barSet has changed.
152 153 \sa brush
153 154 */
154 155
155 156 /*!
156 157 \fn void QBarSet::labelBrushChanged()
157 158 This signal is emitted when the brush of the barSet's label has changed.
158 159 \sa labelBrush
159 160 */
160 161
161 162 /*!
162 163 \fn void QBarSet::labelFontChanged()
163 164 This signal is emitted when the font of the barSet's label has changed.
164 165 \sa labelBrush
165 166 */
166 167
167 168 /*!
168 169 \fn void QBarSet::colorChanged(QColor)
169 170 This signal is emitted when the fill (brush) color of the set has changed to \a color.
170 171 */
171 172 /*!
172 173 \qmlsignal BarSet::onColorChanged(color color)
173 174 This signal is emitted when the fill (brush) color of the set has changed to \a color.
174 175 */
175 176
176 177 /*!
177 178 \fn void QBarSet::borderColorChanged(QColor)
178 179 This signal is emitted when the line (pen) color of the set has changed to \a color.
179 180 */
180 181 /*!
181 182 \qmlsignal BarSet::onBorderColorChanged(color color)
182 183 This signal is emitted when the line (pen) color of the set has changed to \a color.
183 184 */
184 185
185 186 /*!
186 187 \fn void QBarSet::labelColorChanged(QColor)
187 188 This signal is emitted when the text (label) color of the set has changed to \a color.
188 189 */
189 190 /*!
190 191 \qmlsignal BarSet::onLabelColorChanged(color color)
191 192 This signal is emitted when the text (label) color of the set has changed to \a color.
192 193 */
193 194
194 195 /*!
195 196 \fn void QBarSet::valuesAdded(int index, int count)
196 197 This signal is emitted when new values have been added to the set.
197 198 Parameter \a index indicates the position of the first inserted value.
198 199 Parameter \a count is the number of inserted values.
199 200 \sa append(), insert()
200 201 */
201 202 /*!
202 203 \qmlsignal BarSet::onValuesAdded(int index, int count)
203 204 This signal is emitted when new values have been added to the set.
204 205 Parameter \a index indicates the position of the first inserted value.
205 206 Parameter \a count is the number of inserted values.
206 207 */
207 208
208 209 /*!
209 210 \fn void QBarSet::valuesRemoved(int index, int count)
210 211 This signal is emitted values have been removed from the set.
211 212 Parameter \a index indicates the position of the first removed value.
212 213 Parameter \a count is the number of removed values.
213 214 \sa remove()
214 215 */
215 216 /*!
216 217 \qmlsignal BarSet::onValuesRemoved(int index, int count)
217 218 This signal is emitted values have been removed from the set.
218 219 Parameter \a index indicates the position of the first removed value.
219 220 Parameter \a count is the number of removed values.
220 221 */
221 222
222 223 /*!
223 224 \fn void QBarSet::valueChanged(int index)
224 225 This signal is emitted values the value in the set has been modified.
225 226 Parameter \a index indicates the position of the modified value.
226 227 \sa at()
227 228 */
228 229 /*!
229 230 \qmlsignal BarSet::onValueChanged(int index)
230 231 This signal is emitted values the value in the set has been modified.
231 232 Parameter \a index indicates the position of the modified value.
232 233 */
233 234
234 235 /*!
235 236 \qmlproperty int BarSet::count
236 237 The count of values on the barset
237 238 */
238 239
239 240 /*!
240 241 \qmlproperty QVariantList BarSet::values
241 242 The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of
242 243 reals as values, the values are automatically completed to points by using the index of a value as it's
243 244 x-coordinate. For example:
244 245 \code
245 246 myBarSet1.values = [0, 5, 1, 5];
246 247 myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)];
247 248 \endcode
248 249 */
249 250
250 251 /*!
251 252 Constructs QBarSet with a label of \a label and with parent of \a parent.
252 253 */
253 254 QBarSet::QBarSet(const QString label, QObject *parent)
254 255 : QObject(parent),
255 256 d_ptr(new QBarSetPrivate(label, this))
256 257 {
257 258 }
258 259
259 260 /*!
260 261 Destroys the barset.
261 262 */
262 263 QBarSet::~QBarSet()
263 264 {
264 265 // NOTE: d_ptr destroyed by QObject
265 266 }
266 267
267 268 /*!
268 269 Sets new \a label for set.
269 270 */
270 271 void QBarSet::setLabel(const QString label)
271 272 {
272 273 d_ptr->m_label = label;
273 274 emit labelChanged();
274 275 }
275 276
276 277 /*!
277 278 Returns label of the set.
278 279 */
279 280 QString QBarSet::label() const
280 281 {
281 282 return d_ptr->m_label;
282 283 }
283 284
284 285 /*!
285 286 Appends new value \a value to the end of set.
286 287 */
287 288 void QBarSet::append(const qreal value)
288 289 {
289 290 // Convert to QPointF
290 291 int index = d_ptr->m_values.count();
291 292 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
292 293 emit valuesAdded(index, 1);
293 294 }
294 295
295 296 /*!
296 297 Appends a list of reals to set. Works like append with single real value. The \a values in list
297 298 are appended to end of barset
298 299 \sa append()
299 300 */
300 301 void QBarSet::append(const QList<qreal> &values)
301 302 {
302 303 int index = d_ptr->m_values.count();
303 304 d_ptr->append(values);
304 305 emit valuesAdded(index, values.count());
305 306 }
306 307
307 308 /*!
308 309 Convenience operator. Same as append, with real \a value.
309 310 \sa append()
310 311 */
311 312 QBarSet &QBarSet::operator << (const qreal &value)
312 313 {
313 314 append(value);
314 315 return *this;
315 316 }
316 317
317 318 /*!
318 319 Inserts new \a value on the \a index position.
319 320 The value that is currently at this postion is moved to position index + 1
320 321 \sa remove()
321 322 */
322 323 void QBarSet::insert(const int index, const qreal value)
323 324 {
324 325 d_ptr->insert(index, value);
325 326 emit valuesAdded(index, 1);
326 327 }
327 328
328 329 /*!
329 330 Removes \a count number of values from the set starting at \a index.
330 331 \sa insert()
331 332 */
332 333 void QBarSet::remove(const int index, const int count)
333 334 {
334 335 int removedCount = d_ptr->remove(index, count);
335 336 if (removedCount > 0)
336 337 emit valuesRemoved(index, removedCount);
337 338 return;
338 339 }
339 340
340 341 /*!
341 342 Sets a new value \a value to set, indexed by \a index.
342 343 */
343 344 void QBarSet::replace(const int index, const qreal value)
344 345 {
345 346 if (index >= 0 && index < d_ptr->m_values.count()) {
346 347 d_ptr->replace(index, value);
347 348 emit valueChanged(index);
348 349 }
349 350 }
350 351
351 352
352 353 /*!
353 354 Returns value of set indexed by \a index.
354 355 If the index is out of bounds 0.0 is returned.
355 356 */
356 357 qreal QBarSet::at(const int index) const
357 358 {
358 359 if (index < 0 || index >= d_ptr->m_values.count())
359 360 return 0;
360 361 return d_ptr->m_values.at(index).y();
361 362 }
362 363
363 364 /*!
364 365 Returns value of set indexed by \a index.
365 366 If the index is out of bounds 0.0 is returned.
366 367 */
367 368 qreal QBarSet::operator [](const int index) const
368 369 {
369 370 return at(index);
370 371 }
371 372
372 373 /*!
373 374 Returns count of values in set.
374 375 */
375 376 int QBarSet::count() const
376 377 {
377 378 return d_ptr->m_values.count();
378 379 }
379 380
380 381 /*!
381 382 Returns sum of all values in barset.
382 383 */
383 384 qreal QBarSet::sum() const
384 385 {
385 386 qreal total(0);
386 387 for (int i = 0; i < d_ptr->m_values.count(); i++)
387 388 total += d_ptr->m_values.at(i).y();
388 389 return total;
389 390 }
390 391
391 392 /*!
392 393 Sets pen for set. Bars of this set are drawn using \a pen
393 394 */
394 395 void QBarSet::setPen(const QPen &pen)
395 396 {
396 397 if (d_ptr->m_pen != pen) {
397 398 d_ptr->m_pen = pen;
398 399 emit d_ptr->updatedBars();
399 400 emit penChanged();
400 401 }
401 402 }
402 403
403 404 /*!
404 405 Returns pen of the set.
405 406 */
406 407 QPen QBarSet::pen() const
407 408 {
408 409 return d_ptr->m_pen;
409 410 }
410 411
411 412 /*!
412 413 Sets brush for the set. Bars of this set are drawn using \a brush
413 414 */
414 415 void QBarSet::setBrush(const QBrush &brush)
415 416 {
416 417 if (d_ptr->m_brush != brush) {
417 418 d_ptr->m_brush = brush;
418 419 emit d_ptr->updatedBars();
419 420 emit brushChanged();
420 421 }
421 422 }
422 423
423 424 /*!
424 425 Returns brush of the set.
425 426 */
426 427 QBrush QBarSet::brush() const
427 428 {
428 429 return d_ptr->m_brush;
429 430 }
430 431
431 432 /*!
432 433 Sets \a brush of the values that are drawn on top of this barset
433 434 */
434 435 void QBarSet::setLabelBrush(const QBrush &brush)
435 436 {
436 437 if (d_ptr->m_labelBrush != brush) {
437 438 d_ptr->m_labelBrush = brush;
438 439 emit d_ptr->updatedBars();
439 440 emit labelBrushChanged();
440 441 }
441 442 }
442 443
443 444 /*!
444 445 Returns brush of the values that are drawn on top of this barset
445 446 */
446 447 QBrush QBarSet::labelBrush() const
447 448 {
448 449 return d_ptr->m_labelBrush;
449 450 }
450 451
451 452 /*!
452 453 Sets the \a font for values that are drawn on top of this barset
453 454 */
454 455 void QBarSet::setLabelFont(const QFont &font)
455 456 {
456 457 if (d_ptr->m_labelFont != font) {
457 458 d_ptr->m_labelFont = font;
458 459 emit d_ptr->updatedBars();
459 460 emit labelFontChanged();
460 461 }
461 462
462 463 }
463 464
464 465 /*!
465 466 Returns the pen for values that are drawn on top of this barset
466 467 */
467 468 QFont QBarSet::labelFont() const
468 469 {
469 470 return d_ptr->m_labelFont;
470 471 }
471 472
472 473 /*!
473 474 Returns the color of the brush of barset.
474 475 */
475 476 QColor QBarSet::color()
476 477 {
477 478 return brush().color();
478 479 }
479 480
480 481 /*!
481 482 Sets the \a color of brush for this barset
482 483 */
483 484 void QBarSet::setColor(QColor color)
484 485 {
485 486 QBrush b = brush();
486 487 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
487 488 b.setColor(color);
488 489 if (b.style() == Qt::NoBrush) {
489 490 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
490 491 // This prevents theme to override color defined in QML side:
491 492 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
492 493 // The color must be obeyed, since user wanted it.
493 494 b.setStyle(Qt::SolidPattern);
494 495 }
495 496 setBrush(b);
496 497 emit colorChanged(color);
497 498 }
498 499 }
499 500
500 501 /*!
501 502 Returns the color of pen of this barset
502 503 */
503 504 QColor QBarSet::borderColor()
504 505 {
505 506 return pen().color();
506 507 }
507 508
508 509 /*!
509 510 Sets the color of pen for this barset
510 511 */
511 512 void QBarSet::setBorderColor(QColor color)
512 513 {
513 514 QPen p = pen();
514 515 if (p.color() != color) {
515 516 p.setColor(color);
516 517 setPen(p);
517 518 emit borderColorChanged(color);
518 519 }
519 520 }
520 521
521 522 /*!
522 523 Returns the color of labels of this barset
523 524 */
524 525 QColor QBarSet::labelColor()
525 526 {
526 527 return labelBrush().color();
527 528 }
528 529
529 530 /*!
530 531 Sets the color of labels for this barset
531 532 */
532 533 void QBarSet::setLabelColor(QColor color)
533 534 {
534 535 QBrush b = labelBrush();
535 536 if (b == QBrush())
536 537 b.setStyle(Qt::SolidPattern);
537 538
538 539 if (b.color() != color) {
539 540 b.setColor(color);
540 541 setLabelBrush(b);
541 542 emit labelColorChanged(color);
542 543 }
543 544 }
544 545
545 546 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
546 547
547 548 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
548 549 q_ptr(parent),
549 m_label(label)
550 m_label(label),
551 m_pen(QChartPrivate::defaultPen()),
552 m_brush(QChartPrivate::defaultBrush()),
553 m_labelBrush(QChartPrivate::defaultBrush())
550 554 {
551 555 }
552 556
553 557 QBarSetPrivate::~QBarSetPrivate()
554 558 {
555 559 }
556 560
557 561 void QBarSetPrivate::append(QPointF value)
558 562 {
559 563 if (isValidValue(value)) {
560 564 m_values.append(value);
561 565 emit restructuredBars();
562 566 }
563 567 }
564 568
565 569 void QBarSetPrivate::append(QList<QPointF> values)
566 570 {
567 571 for (int i = 0; i < values.count(); i++) {
568 572 if (isValidValue(values.at(i)))
569 573 m_values.append(values.at(i));
570 574 }
571 575 emit restructuredBars();
572 576 }
573 577
574 578 void QBarSetPrivate::append(QList<qreal> values)
575 579 {
576 580 int index = m_values.count();
577 581 for (int i = 0; i < values.count(); i++) {
578 582 if (isValidValue(values.at(i))) {
579 583 m_values.append(QPointF(index, values.at(i)));
580 584 index++;
581 585 }
582 586 }
583 587 emit restructuredBars();
584 588 }
585 589
586 590 void QBarSetPrivate::insert(const int index, const qreal value)
587 591 {
588 592 m_values.insert(index, QPointF(index, value));
589 593 emit restructuredBars();
590 594 }
591 595
592 596 void QBarSetPrivate::insert(const int index, const QPointF value)
593 597 {
594 598 m_values.insert(index, value);
595 599 emit restructuredBars();
596 600 }
597 601
598 602 int QBarSetPrivate::remove(const int index, const int count)
599 603 {
600 604 int removeCount = count;
601 605
602 606 if ((index < 0) || (m_values.count() == 0))
603 607 return 0; // Invalid index or not values in list, remove nothing.
604 608 else if ((index + count) > m_values.count())
605 609 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
606 610
607 611 int c = 0;
608 612 while (c < removeCount) {
609 613 m_values.removeAt(index);
610 614 c++;
611 615 }
612 616 emit restructuredBars();
613 617 return removeCount;
614 618 }
615 619
616 620 void QBarSetPrivate::replace(const int index, const qreal value)
617 621 {
618 622 m_values.replace(index, QPointF(index, value));
619 623 emit updatedLayout();
620 624 }
621 625
622 626 void QBarSetPrivate::replace(const int index, const QPointF value)
623 627 {
624 628 m_values.replace(index, value);
625 629 emit updatedLayout();
626 630 }
627 631
628 632 qreal QBarSetPrivate::pos(const int index)
629 633 {
630 634 if (index < 0 || index >= m_values.count())
631 635 return 0;
632 636 return m_values.at(index).x();
633 637 }
634 638
635 639 qreal QBarSetPrivate::value(const int index)
636 640 {
637 641 if (index < 0 || index >= m_values.count())
638 642 return 0;
639 643 return m_values.at(index).y();
640 644 }
641 645
642 646 #include "moc_qbarset.cpp"
643 647 #include "moc_qbarset_p.cpp"
644 648
645 649 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,382 +1,383
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 45 m_plotAreaBackground(0),
46 46 m_title(0)
47 47 {
48 48 if (type == QChart::ChartTypeCartesian)
49 49 m_layout = new CartesianChartLayout(this);
50 50 else if (type == QChart::ChartTypePolar)
51 51 m_layout = new PolarChartLayout(this);
52 52 Q_ASSERT(m_layout);
53 53 }
54 54
55 55 ChartPresenter::~ChartPresenter()
56 56 {
57 57
58 58 }
59 59
60 60 void ChartPresenter::setGeometry(const QRectF rect)
61 61 {
62 62 if (m_rect != rect) {
63 63 m_rect = rect;
64 64 foreach (ChartItem *chart, m_chartItems) {
65 65 chart->domain()->setSize(rect.size());
66 66 chart->setPos(rect.topLeft());
67 67 }
68 68 }
69 69 }
70 70
71 71 QRectF ChartPresenter::geometry() const
72 72 {
73 73 return m_rect;
74 74 }
75 75
76 76 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
77 77 {
78 78 axis->d_ptr->initializeGraphics(rootItem());
79 79 axis->d_ptr->initializeAnimations(m_options);
80 80 ChartAxisElement *item = axis->d_ptr->axisItem();
81 81 item->setPresenter(this);
82 82 item->setThemeManager(m_chart->d_ptr->m_themeManager);
83 83 m_axisItems<<item;
84 84 m_axes<<axis;
85 85 m_layout->invalidate();
86 86 }
87 87
88 88 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
89 89 {
90 90 ChartAxisElement *item = axis->d_ptr->m_item.take();
91 91 item->hide();
92 92 item->disconnect();
93 93 item->deleteLater();
94 94 m_axisItems.removeAll(item);
95 95 m_axes.removeAll(axis);
96 96 m_layout->invalidate();
97 97 }
98 98
99 99
100 100 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series)
101 101 {
102 102 series->d_ptr->initializeGraphics(rootItem());
103 103 series->d_ptr->initializeAnimations(m_options);
104 104 ChartItem *chart = series->d_ptr->chartItem();
105 105 chart->setPresenter(this);
106 106 chart->setThemeManager(m_chart->d_ptr->m_themeManager);
107 107 chart->domain()->setSize(m_rect.size());
108 108 chart->setPos(m_rect.topLeft());
109 109 chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored
110 110 m_chartItems<<chart;
111 111 m_series<<series;
112 112 m_layout->invalidate();
113 113 }
114 114
115 115 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
116 116 {
117 117 ChartItem *chart = series->d_ptr->m_item.take();
118 118 chart->hide();
119 119 chart->disconnect();
120 120 chart->deleteLater();
121 121 m_chartItems.removeAll(chart);
122 122 m_series.removeAll(series);
123 123 m_layout->invalidate();
124 124 }
125 125
126 126 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
127 127 {
128 128 if (m_options != options) {
129 129 m_options = options;
130 130
131 131 foreach(QAbstractSeries* series, m_series){
132 132 series->d_ptr->initializeAnimations(m_options);
133 133 }
134 134 foreach(QAbstractAxis* axis, m_axes){
135 135 axis->d_ptr->initializeAnimations(m_options);
136 136 }
137 137 }
138 138 }
139 139
140 140 void ChartPresenter::setState(State state,QPointF point)
141 141 {
142 142 m_state=state;
143 143 m_statePoint=point;
144 144 }
145 145
146 146 QChart::AnimationOptions ChartPresenter::animationOptions() const
147 147 {
148 148 return m_options;
149 149 }
150 150
151 151 void ChartPresenter::createBackgroundItem()
152 152 {
153 153 if (!m_background) {
154 154 m_background = new ChartBackground(rootItem());
155 m_background->setPen(Qt::NoPen);
155 m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default
156 m_background->setBrush(QChartPrivate::defaultBrush());
156 157 m_background->setZValue(ChartPresenter::BackgroundZValue);
157 158 }
158 159 }
159 160
160 161 void ChartPresenter::createPlotAreaBackgroundItem()
161 162 {
162 163 if (!m_plotAreaBackground) {
163 164 if (m_chart->chartType() == QChart::ChartTypeCartesian)
164 165 m_plotAreaBackground = new QGraphicsRectItem(rootItem());
165 166 else
166 167 m_plotAreaBackground = new QGraphicsEllipseItem(rootItem());
167 168 // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes
168 169 // antialising artifacts with axis lines for some reason.
169 170 m_plotAreaBackground->setPen(QPen(Qt::transparent));
170 171 m_plotAreaBackground->setBrush(Qt::NoBrush);
171 172 m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue);
172 173 m_plotAreaBackground->setVisible(false);
173 174 }
174 175 }
175 176
176 177 void ChartPresenter::createTitleItem()
177 178 {
178 179 if (!m_title) {
179 180 m_title = new ChartTitle(rootItem());
180 181 m_title->setZValue(ChartPresenter::BackgroundZValue);
181 182 }
182 183 }
183 184
184 185
185 186 void ChartPresenter::handleAnimationFinished()
186 187 {
187 188 m_animations.removeAll(qobject_cast<ChartAnimation *>(sender()));
188 189 if (m_animations.empty())
189 190 emit animationsFinished();
190 191 }
191 192
192 193 void ChartPresenter::startAnimation(ChartAnimation *animation)
193 194 {
194 195 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
195 196 QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection);
196 197 if (!m_animations.isEmpty())
197 198 m_animations.append(animation);
198 199 QTimer::singleShot(0, animation, SLOT(start()));
199 200 }
200 201
201 202 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
202 203 {
203 204 createBackgroundItem();
204 205 m_background->setBrush(brush);
205 206 m_layout->invalidate();
206 207 }
207 208
208 209 QBrush ChartPresenter::backgroundBrush() const
209 210 {
210 211 if (!m_background)
211 212 return QBrush();
212 213 return m_background->brush();
213 214 }
214 215
215 216 void ChartPresenter::setBackgroundPen(const QPen &pen)
216 217 {
217 218 createBackgroundItem();
218 219 m_background->setPen(pen);
219 220 m_layout->invalidate();
220 221 }
221 222
222 223 QPen ChartPresenter::backgroundPen() const
223 224 {
224 225 if (!m_background)
225 226 return QPen();
226 227 return m_background->pen();
227 228 }
228 229
229 230 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
230 231 {
231 232 createPlotAreaBackgroundItem();
232 233 m_plotAreaBackground->setBrush(brush);
233 234 m_layout->invalidate();
234 235 }
235 236
236 237 QBrush ChartPresenter::plotAreaBackgroundBrush() const
237 238 {
238 239 if (!m_plotAreaBackground)
239 240 return QBrush();
240 241 return m_plotAreaBackground->brush();
241 242 }
242 243
243 244 void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen)
244 245 {
245 246 createPlotAreaBackgroundItem();
246 247 m_plotAreaBackground->setPen(pen);
247 248 m_layout->invalidate();
248 249 }
249 250
250 251 QPen ChartPresenter::plotAreaBackgroundPen() const
251 252 {
252 253 if (!m_plotAreaBackground)
253 254 return QPen();
254 255 return m_plotAreaBackground->pen();
255 256 }
256 257
257 258 void ChartPresenter::setTitle(const QString &title)
258 259 {
259 260 createTitleItem();
260 261 m_title->setText(title);
261 262 m_layout->invalidate();
262 263 }
263 264
264 265 QString ChartPresenter::title() const
265 266 {
266 267 if (!m_title)
267 268 return QString();
268 269 return m_title->text();
269 270 }
270 271
271 272 void ChartPresenter::setTitleFont(const QFont &font)
272 273 {
273 274 createTitleItem();
274 275 m_title->setFont(font);
275 276 m_layout->invalidate();
276 277 }
277 278
278 279 QFont ChartPresenter::titleFont() const
279 280 {
280 281 if (!m_title)
281 282 return QFont();
282 283 return m_title->font();
283 284 }
284 285
285 286 void ChartPresenter::setTitleBrush(const QBrush &brush)
286 287 {
287 288 createTitleItem();
288 289 m_title->setBrush(brush);
289 290 m_layout->invalidate();
290 291 }
291 292
292 293 QBrush ChartPresenter::titleBrush() const
293 294 {
294 295 if (!m_title)
295 296 return QBrush();
296 297 return m_title->brush();
297 298 }
298 299
299 300 void ChartPresenter::setBackgroundVisible(bool visible)
300 301 {
301 302 createBackgroundItem();
302 303 m_background->setVisible(visible);
303 304 }
304 305
305 306
306 307 bool ChartPresenter::isBackgroundVisible() const
307 308 {
308 309 if (!m_background)
309 310 return false;
310 311 return m_background->isVisible();
311 312 }
312 313
313 314 void ChartPresenter::setPlotAreaBackgroundVisible(bool visible)
314 315 {
315 316 createPlotAreaBackgroundItem();
316 317 m_plotAreaBackground->setVisible(visible);
317 318 }
318 319
319 320 bool ChartPresenter::isPlotAreaBackgroundVisible() const
320 321 {
321 322 if (!m_plotAreaBackground)
322 323 return false;
323 324 return m_plotAreaBackground->isVisible();
324 325 }
325 326
326 327 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
327 328 {
328 329 createBackgroundItem();
329 330 m_background->setDropShadowEnabled(enabled);
330 331 }
331 332
332 333 bool ChartPresenter::isBackgroundDropShadowEnabled() const
333 334 {
334 335 if (!m_background)
335 336 return false;
336 337 return m_background->isDropShadowEnabled();
337 338 }
338 339
339 340
340 341 AbstractChartLayout *ChartPresenter::layout()
341 342 {
342 343 return m_layout;
343 344 }
344 345
345 346 QLegend *ChartPresenter::legend()
346 347 {
347 348 return m_chart->legend();
348 349 }
349 350
350 351 void ChartPresenter::setVisible(bool visible)
351 352 {
352 353 m_chart->setVisible(visible);
353 354 }
354 355
355 356 ChartBackground *ChartPresenter::backgroundElement()
356 357 {
357 358 return m_background;
358 359 }
359 360
360 361 QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement()
361 362 {
362 363 return m_plotAreaBackground;
363 364 }
364 365
365 366 QList<ChartAxisElement *> ChartPresenter::axisItems() const
366 367 {
367 368 return m_axisItems;
368 369 }
369 370
370 371 QList<ChartItem *> ChartPresenter::chartItems() const
371 372 {
372 373 return m_chartItems;
373 374 }
374 375
375 376 ChartTitle *ChartPresenter::titleElement()
376 377 {
377 378 return m_title;
378 379 }
379 380
380 381 #include "moc_chartpresenter_p.cpp"
381 382
382 383 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,267 +1,248
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 if(m_theme.isNull() || theme != m_theme->id())
45 {
44 if (m_theme.isNull() || theme != m_theme->id()) {
46 45 switch (theme) {
47 46 case QChart::ChartThemeLight:
48 47 m_theme.reset(new ChartThemeLight());
49 48 break;
50 49 case QChart::ChartThemeBlueCerulean:
51 50 m_theme.reset(new ChartThemeBlueCerulean());
52 51 break;
53 52 case QChart::ChartThemeDark:
54 53 m_theme.reset(new ChartThemeDark());
55 54 break;
56 55 case QChart::ChartThemeBrownSand:
57 56 m_theme.reset(new ChartThemeBrownSand());
58 57 break;
59 58 case QChart::ChartThemeBlueNcs:
60 59 m_theme.reset(new ChartThemeBlueNcs());
61 60 break;
62 61 case QChart::ChartThemeHighContrast:
63 62 m_theme.reset(new ChartThemeHighContrast());
64 63 break;
65 64 case QChart::ChartThemeBlueIcy:
66 65 m_theme.reset(new ChartThemeBlueIcy());
67 66 break;
68 67 default:
69 68 m_theme.reset(new ChartThemeSystem());
70 69 break;
71 70 }
72 71
73 if(!m_theme.isNull())
74 {
75 decorateChart(m_chart,m_theme.data(),true);
76 decorateLegend(m_chart->legend(),m_theme.data(),true);
77 foreach(QAbstractAxis* axis, m_axisList) {
72 if (!m_theme.isNull()) {
73 decorateChart(m_chart,m_theme.data());
74 decorateLegend(m_chart->legend(),m_theme.data());
75 foreach (QAbstractAxis* axis, m_axisList)
78 76 axis->d_ptr->initializeTheme(m_theme.data(),true);
79 }
80 foreach(QAbstractSeries* series, m_seriesMap.keys()) {
77 foreach (QAbstractSeries* series, m_seriesMap.keys())
81 78 series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),true);
82 79 }
83
84 }
85 80 }
86 81 }
87 82
88 void ChartThemeManager::decorateChart(QChart *chart,ChartTheme* theme,bool force) const
83 // decorateChart is only called when theme is forcibly initialized
84 void ChartThemeManager::decorateChart(QChart *chart, ChartTheme *theme) const
89 85 {
90 QBrush brush;
91
92 if (force || brush == chart->backgroundBrush())
93 86 chart->setBackgroundBrush(theme->chartBackgroundGradient());
94 87
95 if (force) {
96 // Always clear plotArea brush when forced update, do not touch otherwise
97 88 QPen pen(Qt::transparent);
89 QBrush brush;
98 90 chart->setPlotAreaBackgroundBrush(brush);
99 91 chart->setPlotAreaBackgroundPen(pen);
100 92 chart->setPlotAreaBackgroundVisible(false);
101 }
102 93
103 94 chart->setTitleFont(theme->masterFont());
104 95 chart->setTitleBrush(theme->labelBrush());
105 96 chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled());
106 97 }
107 98
108 void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme* theme, bool force) const
99 // decorateLegend is only called when theme is forcibly initialized
100 void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme *theme) const
109 101 {
110 QPen pen;
111 QBrush brush;
112 QFont font;
113
114 if (force || pen == legend->pen())
115 102 legend->setPen(theme->axisLinePen());
116
117 if (force || brush == legend->brush())
118 103 legend->setBrush(theme->chartBackgroundGradient());
119
120 if (force || font == legend->font())
121 104 legend->setFont(theme->labelFont());
122
123 if (force || brush == legend->labelBrush())
124 105 legend->setLabelBrush(theme->labelBrush());
125 106 }
126 107
127 108 int ChartThemeManager::createIndexKey(QList<int> keys) const
128 109 {
129 110 qSort(keys);
130 111
131 112 int key = 0;
132 113 QList<int>::iterator i;
133 114 i = keys.begin();
134 115
135 116 while (i != keys.end()) {
136 117 if (*i != key)
137 118 break;
138 119 key++;
139 120 i++;
140 121 }
141 122
142 123 return key;
143 124 }
144 125
145 126 int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const
146 127 {
147 128 int count = 0;
148 129 QList<QAbstractSeries *> series = m_seriesMap.keys();
149 130 foreach(QAbstractSeries *s, series) {
150 131 if (s->type() == type)
151 132 count++;
152 133 }
153 134 return count;
154 135 }
155 136
156 137 void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series)
157 138 {
158 139 int key = createIndexKey(m_seriesMap.values());
159 140 m_seriesMap.insert(series,key);
160 141 series->d_ptr->initializeTheme(key,m_theme.data(),false);
161 142 }
162 143
163 144 void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series)
164 145 {
165 146 m_seriesMap.remove(series);
166 147 }
167 148
168 149 void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis)
169 150 {
170 151 m_axisList.append(axis);
171 152 axis->d_ptr->initializeTheme(m_theme.data(),false);
172 153 }
173 154
174 155 void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis)
175 156 {
176 157 m_axisList.removeAll(axis);
177 158 }
178 159
179 160 void ChartThemeManager::updateSeries(QAbstractSeries *series)
180 161 {
181 162 if(m_seriesMap.contains(series)){
182 163 series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false);
183 164 }
184 165 }
185 166 QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors)
186 167 {
187 168 QList<QGradient> result;
188 169 // Generate gradients in HSV color space
189 170 foreach (const QColor &color, colors) {
190 171 QLinearGradient g;
191 172 qreal h = color.hsvHueF();
192 173 qreal s = color.hsvSaturationF();
193 174
194 175 // TODO: tune the algorithm to give nice results with most base colors defined in
195 176 // most themes. The rest of the gradients we can define manually in theme specific
196 177 // implementation.
197 178 QColor start = color;
198 179 start.setHsvF(h, 0.0, 1.0);
199 180 g.setColorAt(0.0, start);
200 181
201 182 g.setColorAt(0.5, color);
202 183
203 184 QColor end = color;
204 185 end.setHsvF(h, s, 0.25);
205 186 g.setColorAt(1.0, end);
206 187
207 188 result << g;
208 189 }
209 190
210 191 return result;
211 192 }
212 193
213 194
214 195 QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos)
215 196 {
216 197 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
217 198 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
218 199 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
219 200 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
220 201 QColor c;
221 202 c.setRgbF(r, g, b);
222 203 return c;
223 204 }
224 205
225 206 QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos)
226 207 {
227 208 Q_ASSERT(pos >= 0 && pos <= 1.0);
228 209
229 210 QGradientStops stops = gradient.stops();
230 211 int count = stops.count();
231 212
232 213 // find previous stop relative to position
233 214 QGradientStop prev = stops.first();
234 215 for (int i = 0; i < count; i++) {
235 216 QGradientStop stop = stops.at(i);
236 217 if (pos > stop.first)
237 218 prev = stop;
238 219
239 220 // given position is actually a stop position?
240 221 if (pos == stop.first) {
241 222 //qDebug() << "stop color" << pos;
242 223 return stop.second;
243 224 }
244 225 }
245 226
246 227 // find next stop relative to position
247 228 QGradientStop next = stops.last();
248 229 for (int i = count - 1; i >= 0; i--) {
249 230 QGradientStop stop = stops.at(i);
250 231 if (pos < stop.first)
251 232 next = stop;
252 233 }
253 234
254 235 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
255 236
256 237 qreal range = next.first - prev.first;
257 238 qreal posDelta = pos - prev.first;
258 239 qreal relativePos = posDelta / range;
259 240
260 241 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
261 242
262 243 return colorAt(prev.second, next.second, relativePos);
263 244 }
264 245
265 246 #include "moc_chartthememanager_p.cpp"
266 247
267 248 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,84 +1,84
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 CHARTTHEMEMANAGER_H
31 31 #define CHARTTHEMEMANAGER_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "qchart.h"
35 35 #include <QColor>
36 36 #include <QGradientStops>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39 class ChartTheme;
40 40
41 41 class ChartThemeManager: public QObject
42 42 {
43 43 Q_OBJECT
44 44 public:
45 45 enum BackgroundShadesMode {
46 46 BackgroundShadesNone = 0,
47 47 BackgroundShadesVertical,
48 48 BackgroundShadesHorizontal,
49 49 BackgroundShadesBoth
50 50 };
51 51
52 52 public:
53 53 explicit ChartThemeManager(QChart* chart);
54 54 void setTheme(QChart::ChartTheme theme);
55 55 ChartTheme* theme() const { return m_theme.data(); }
56 void decorateChart(QChart *chart, ChartTheme* theme, bool force = false) const;
57 void decorateLegend(QLegend *legend, ChartTheme* theme, bool force = false) const;
56 void decorateChart(QChart *chart, ChartTheme* theme) const;
57 void decorateLegend(QLegend *legend, ChartTheme* theme) const;
58 58 void updateSeries(QAbstractSeries *series);
59 59
60 60 public:
61 61 static QList<QGradient> generateSeriesGradients(const QList<QColor>& colors);
62 62 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
63 63 static QColor colorAt(const QGradient &gradient, qreal pos);
64 64
65 65 private:
66 66 int createIndexKey(QList<int> keys) const;
67 67 int seriesCount(QAbstractSeries::SeriesType type) const;
68 68
69 69 public Q_SLOTS:
70 70 void handleSeriesAdded(QAbstractSeries *series);
71 71 void handleSeriesRemoved(QAbstractSeries *series);
72 72 void handleAxisAdded(QAbstractAxis *axis);
73 73 void handleAxisRemoved(QAbstractAxis *axis);
74 74
75 75 protected:
76 76 QScopedPointer<ChartTheme> m_theme;
77 77 QMap<QAbstractSeries *,int> m_seriesMap;
78 78 QList<QAbstractAxis *> m_axisList;
79 79 QChart* m_chart;
80 80 };
81 81
82 82 QTCOMMERCIALCHART_END_NAMESPACE
83 83
84 84 #endif // CHARTTHEME_H
@@ -1,162 +1,162
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 "qlineseries.h"
22 22 #include "qlineseries_p.h"
23 23 #include "linechartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26
26 #include "qchart_p.h"
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 /*!
30 30 \class QLineSeries
31 31 \brief The QLineSeries class is used for making line charts.
32 32
33 33 \mainclass
34 34
35 35 A line chart is used to show information as a series of data points
36 36 connected by straight lines.
37 37
38 38 \image examples_linechart.png
39 39
40 40 Creating basic line chart is simple:
41 41 \code
42 42 QLineSeries* series = new QLineSeries();
43 43 series->append(0, 6);
44 44 series->append(2, 4);
45 45 ...
46 46 chart->addSeries(series);
47 47 \endcode
48 48 */
49 49 /*!
50 50 \qmlclass LineSeries QLineSeries
51 51 \inherits XYSeries
52 52
53 53 The following QML shows how to create a simple line chart:
54 54 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
55 55 \beginfloatleft
56 56 \image demos_qmlchart2.png
57 57 \endfloat
58 58 \clearfloat
59 59 */
60 60
61 61 /*!
62 62 \fn virtual SeriesType QLineSeries::type() const
63 63 \brief Returns type of series.
64 64 \sa QAbstractSeries, SeriesType
65 65 */
66 66
67 67 /*!
68 68 \qmlproperty real LineSeries::width
69 69 The width of the line. By default the width is 2.0.
70 70 */
71 71
72 72 /*!
73 73 \qmlproperty Qt::PenStyle LineSeries::style
74 74 Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine,
75 75 Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API.
76 76 By default the style is Qt.SolidLine.
77 77 */
78 78
79 79 /*!
80 80 \qmlproperty Qt::PenCapStyle LineSeries::capStyle
81 81 Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By
82 82 default the cap style is Qt.SquareCap.
83 83 */
84 84
85 85 /*!
86 86 Constructs empty series object which is a child of \a parent.
87 87 When series object is added to QChartView or QChart instance ownerships is transferred.
88 88 */
89 89 QLineSeries::QLineSeries(QObject *parent)
90 90 : QXYSeries(*new QLineSeriesPrivate(this), parent)
91 91 {
92 92
93 93 }
94 94
95 95 /*!
96 96 \internal
97 97 */
98 98 QLineSeries::QLineSeries(QLineSeriesPrivate &d, QObject *parent)
99 99 : QXYSeries(d, parent)
100 100 {
101 101
102 102 }
103 103 /*!
104 104 Destroys the object. Series added to QChartView or QChart instances are owned by those,
105 105 and are deleted when mentioned object are destroyed.
106 106 */
107 107 QLineSeries::~QLineSeries()
108 108 {
109 109 Q_D(QLineSeries);
110 110 if (d->m_chart)
111 111 d->m_chart->removeSeries(this);
112 112 }
113 113
114 114 QAbstractSeries::SeriesType QLineSeries::type() const
115 115 {
116 116 return QAbstractSeries::SeriesTypeLine;
117 117 }
118 118
119 119 /*
120 120 QDebug operator<< (QDebug debug, const QLineSeries series)
121 121 {
122 122 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
123 123 int size = series.d_func()->m_x.size();
124 124 for (int i=0; i<size; i++) {
125 125 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
126 126 }
127 127 return debug.space();
128 128 }
129 129 */
130 130
131 131 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
132 132
133 133 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries *q)
134 134 : QXYSeriesPrivate(q)
135 135 {
136 136
137 137 };
138 138
139 139 void QLineSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
140 140 {
141 141 Q_Q(QLineSeries);
142 142 LineChartItem *line = new LineChartItem(q,parent);
143 143 m_item.reset(line);
144 144 QAbstractSeriesPrivate::initializeGraphics(parent);
145 145 }
146 146
147 147 void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
148 148 {
149 149 Q_Q(QLineSeries);
150 150 const QList<QColor> colors = theme->seriesColors();
151 151
152 if (forced || QChartPrivate::defaultPen() == m_pen) {
152 153 QPen pen;
153 if (forced || pen == m_pen) {
154 154 pen.setColor(colors.at(index % colors.size()));
155 155 pen.setWidthF(2);
156 156 q->setPen(pen);
157 157 }
158 158 }
159 159
160 160 #include "moc_qlineseries.cpp"
161 161
162 162 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,754 +1,784
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 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 133 \property QChart::plotAreaBackgroundVisible
134 134 Specifies whether the chart plot area background is visible or not.
135 135 \note By default the plot area background is not visible and the plot area uses
136 136 the general chart background.
137 137 \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
138 138 */
139 139
140 140 /*!
141 141 \internal
142 142 Constructs a chart object of \a type which is a child of a \a parent.
143 143 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
144 144 This constructor is called only by subclasses.
145 145 */
146 146 QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags)
147 147 : QGraphicsWidget(parent, wFlags),
148 148 d_ptr(new QChartPrivate(this, type))
149 149 {
150 150 d_ptr->init();
151 151 }
152 152
153 153 /*!
154 154 Constructs a chart object which is a child of a \a parent.
155 155 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
156 156 */
157 157 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
158 158 : QGraphicsWidget(parent, wFlags),
159 159 d_ptr(new QChartPrivate(this, ChartTypeCartesian))
160 160 {
161 161 d_ptr->init();
162 162 }
163 163
164 164 /*!
165 165 Destroys the chart object and its children, like series and axis objects added to it.
166 166 */
167 167 QChart::~QChart()
168 168 {
169 169 //start by deleting dataset, it will remove all series and axes
170 170 delete d_ptr->m_dataset;
171 171 d_ptr->m_dataset = 0;
172 172 }
173 173
174 174 /*!
175 175 Adds the \a series onto the chart and takes the ownership of it.
176 176
177 177 \note A newly added series is attached to no axes by default, including any axes that were created for the chart
178 178 using createDefaultAxes() before the series was added to the chart. If no axes are attached to
179 179 the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges
180 180 that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other
181 181 series that have properly attached axes, so always make sure you either call createDefaultAxes() after
182 182 a series has been added or explicitly attach axes for the series.
183 183
184 184 \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis()
185 185 */
186 186 void QChart::addSeries(QAbstractSeries *series)
187 187 {
188 188 Q_ASSERT(series);
189 189 d_ptr->m_dataset->addSeries(series);
190 190 }
191 191
192 192 /*!
193 193 Removes the \a series from the chart.
194 194 The chart releases its ownership of the specified \a series object.
195 195
196 196 \sa addSeries(), removeAllSeries()
197 197 */
198 198 void QChart::removeSeries(QAbstractSeries *series)
199 199 {
200 200 Q_ASSERT(series);
201 201 d_ptr->m_dataset->removeSeries(series);
202 202 }
203 203
204 204 /*!
205 205 Removes and deletes all series objects that have been added to the chart.
206 206
207 207 \sa addSeries(), removeSeries()
208 208 */
209 209 void QChart::removeAllSeries()
210 210 {
211 211 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
212 212 removeSeries(s);
213 213 delete s;
214 214 }
215 215 }
216 216
217 217 /*!
218 218 Sets the \a brush that is used for painting the background of the chart area.
219 219 */
220 220 void QChart::setBackgroundBrush(const QBrush &brush)
221 221 {
222 222 d_ptr->m_presenter->setBackgroundBrush(brush);
223 223 }
224 224
225 225 /*!
226 226 Gets the brush that is used for painting the background of the chart area.
227 227 */
228 228 QBrush QChart::backgroundBrush() const
229 229 {
230 230 return d_ptr->m_presenter->backgroundBrush();
231 231 }
232 232
233 233 /*!
234 234 Sets the \a pen that is used for painting the background of the chart area.
235 235 */
236 236 void QChart::setBackgroundPen(const QPen &pen)
237 237 {
238 238 d_ptr->m_presenter->setBackgroundPen(pen);
239 239 }
240 240
241 241 /*!
242 242 Gets the pen that is used for painting the background of the chart area.
243 243 */
244 244 QPen QChart::backgroundPen() const
245 245 {
246 246 return d_ptr->m_presenter->backgroundPen();
247 247 }
248 248
249 249 void QChart::setTitle(const QString &title)
250 250 {
251 251 d_ptr->m_presenter->setTitle(title);
252 252 }
253 253
254 254 QString QChart::title() const
255 255 {
256 256 return d_ptr->m_presenter->title();
257 257 }
258 258
259 259 /*!
260 260 Sets the \a font that is used for drawing the chart title.
261 261 */
262 262 void QChart::setTitleFont(const QFont &font)
263 263 {
264 264 d_ptr->m_presenter->setTitleFont(font);
265 265 }
266 266
267 267 /*!
268 268 Gets the font that is used for drawing the chart title.
269 269 */
270 270 QFont QChart::titleFont() const
271 271 {
272 272 return d_ptr->m_presenter->titleFont();
273 273 }
274 274
275 275 /*!
276 276 Sets the \a brush used for drawing the title text.
277 277 */
278 278 void QChart::setTitleBrush(const QBrush &brush)
279 279 {
280 280 d_ptr->m_presenter->setTitleBrush(brush);
281 281 }
282 282
283 283 /*!
284 284 Returns the brush used for drawing the title text.
285 285 */
286 286 QBrush QChart::titleBrush() const
287 287 {
288 288 return d_ptr->m_presenter->titleBrush();
289 289 }
290 290
291 291 void QChart::setTheme(QChart::ChartTheme theme)
292 292 {
293 293 d_ptr->m_themeManager->setTheme(theme);
294 294 }
295 295
296 296 QChart::ChartTheme QChart::theme() const
297 297 {
298 298 return d_ptr->m_themeManager->theme()->id();
299 299 }
300 300
301 301 /*!
302 302 Zooms in the view by a factor of two.
303 303 */
304 304 void QChart::zoomIn()
305 305 {
306 306 d_ptr->zoomIn(2.0);
307 307 }
308 308
309 309 /*!
310 310 Zooms in the view to a maximum level at which \a rect is still fully visible.
311 311 \note This is not supported for polar charts.
312 312 */
313 313 void QChart::zoomIn(const QRectF &rect)
314 314 {
315 315 if (d_ptr->m_type == QChart::ChartTypePolar)
316 316 return;
317 317 d_ptr->zoomIn(rect);
318 318 }
319 319
320 320 /*!
321 321 Zooms out the view by a factor of two.
322 322 */
323 323 void QChart::zoomOut()
324 324 {
325 325 d_ptr->zoomOut(2.0);
326 326 }
327 327
328 328 /*!
329 329 Zooms in the view by a custom \a factor.
330 330
331 331 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
332 332 */
333 333 void QChart::zoom(qreal factor)
334 334 {
335 335 if (qFuzzyCompare(factor, 0))
336 336 return;
337 337
338 338 if (qFuzzyCompare(factor, (qreal)1.0))
339 339 return;
340 340
341 341 if (factor < 0)
342 342 return;
343 343
344 344 if (factor > 1.0)
345 345 d_ptr->zoomIn(factor);
346 346 else
347 347 d_ptr->zoomOut(1.0 / factor);
348 348 }
349 349
350 350 /*!
351 351 Returns a pointer to the horizontal axis attached to the specified \a series.
352 352 If no \a series is specified, the first horizontal axis added to the chart is returned.
353 353
354 354 \sa addAxis(), QAbstractSeries::attachAxis()
355 355 */
356 356 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
357 357 {
358 358 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
359 359 if (axisList.count())
360 360 return axisList[0];
361 361 return 0;
362 362 }
363 363
364 364 /*!
365 365 Returns a pointer to the vertical axis attached to the specified \a series.
366 366 If no \a series is specified, the first vertical axis added to the chart is returned.
367 367
368 368 \sa addAxis(), QAbstractSeries::attachAxis()
369 369 */
370 370 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
371 371 {
372 372 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
373 373 if (axisList.count())
374 374 return axisList[0];
375 375 return 0;
376 376 }
377 377
378 378 /*!
379 379 Returns the axes attached to the \a series with \a orientation. If no \a series is provided,
380 380 then all axes added to the chart with the specified orientation are returned.
381 381 \sa addAxis(), createDefaultAxes()
382 382 */
383 383 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
384 384 {
385 385 QList<QAbstractAxis *> result ;
386 386
387 387 if (series) {
388 388 foreach (QAbstractAxis *axis, series->attachedAxes()){
389 389 if (orientation.testFlag(axis->orientation()))
390 390 result << axis;
391 391 }
392 392 } else {
393 393 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
394 394 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
395 395 result << axis;
396 396 }
397 397 }
398 398
399 399 return result;
400 400 }
401 401
402 402 /*!
403 403 Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to
404 404 the chart will be deleted.
405 405
406 406 \note This function has to be called after all series have been added to the chart. The axes created by this function
407 407 will NOT get automatically attached to any series added to the chart after this function has been called.
408 408 A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing
409 409 if there are other series with properly attached axes also present.
410 410
411 411 \table
412 412 \header
413 413 \o Series type
414 414 \o X-axis
415 415 \o Y-axis
416 416 \row
417 417 \o QXYSeries
418 418 \o QValueAxis
419 419 \o QValueAxis
420 420 \row
421 421 \o QBarSeries
422 422 \o QBarCategoryAxis
423 423 \o QValueAxis
424 424 \row
425 425 \o QPieSeries
426 426 \o None
427 427 \o None
428 428 \endtable
429 429
430 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.
431 431 If there are several series of different types added to the chart, then each series gets its own axes pair.
432 432
433 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.
434 434 QPieSeries does not create any axes.
435 435
436 436 \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis()
437 437 */
438 438 void QChart::createDefaultAxes()
439 439 {
440 440 d_ptr->m_dataset->createDefaultAxes();
441 441 }
442 442
443 443 /*!
444 444 Returns the legend object of the chart. Ownership stays with the chart.
445 445 */
446 446 QLegend *QChart::legend() const
447 447 {
448 448 return d_ptr->m_legend;
449 449 }
450 450
451 451 void QChart::setMinimumMargins(const QMargins &margins)
452 452 {
453 453 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
454 454 d_ptr->m_presenter->layout()->setMargins(margins);
455 455 }
456 456
457 457 QMargins QChart::minimumMargins() const
458 458 {
459 459 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
460 460 return d_ptr->m_presenter->layout()->margins();
461 461 }
462 462
463 463 void QChart::setMargins(const QMargins &margins)
464 464 {
465 465 d_ptr->m_presenter->layout()->setMargins(margins);
466 466 }
467 467
468 468 QMargins QChart::margins() const
469 469 {
470 470 return d_ptr->m_presenter->layout()->margins();
471 471 }
472 472
473 473 QChart::ChartType QChart::chartType() const
474 474 {
475 475 return d_ptr->m_type;
476 476 }
477 477
478 478 /*!
479 479 Returns the the rectangle within which the drawing of the chart is done.
480 480 It does not include the area defined by margins.
481 481 */
482 482 QRectF QChart::plotArea() const
483 483 {
484 484 return d_ptr->m_presenter->geometry();
485 485 }
486 486
487 487 /*!
488 488 Sets the \a brush for the background of the plot area of the chart.
489 489
490 490 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
491 491 */
492 492 void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
493 493 {
494 494 d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush);
495 495 }
496 496
497 497 /*!
498 498 Returns the brush for the background of the plot area of the chart.
499 499
500 500 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
501 501 */
502 502 QBrush QChart::plotAreaBackgroundBrush() const
503 503 {
504 504 return d_ptr->m_presenter->plotAreaBackgroundBrush();
505 505 }
506 506
507 507 /*!
508 508 Sets the \a pen for the background of the plot area of the chart.
509 509
510 510 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
511 511 */
512 512 void QChart::setPlotAreaBackgroundPen(const QPen &pen)
513 513 {
514 514 d_ptr->m_presenter->setPlotAreaBackgroundPen(pen);
515 515 }
516 516
517 517 /*!
518 518 Returns the pen for the background of the plot area of the chart.
519 519
520 520 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
521 521 */
522 522 QPen QChart::plotAreaBackgroundPen() const
523 523 {
524 524 return d_ptr->m_presenter->plotAreaBackgroundPen();
525 525 }
526 526
527 527 void QChart::setPlotAreaBackgroundVisible(bool visible)
528 528 {
529 529 d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible);
530 530 }
531 531
532 532 bool QChart::isPlotAreaBackgroundVisible() const
533 533 {
534 534 return d_ptr->m_presenter->isPlotAreaBackgroundVisible();
535 535 }
536 536
537 537 void QChart::setAnimationOptions(AnimationOptions options)
538 538 {
539 539 d_ptr->m_presenter->setAnimationOptions(options);
540 540 }
541 541
542 542 QChart::AnimationOptions QChart::animationOptions() const
543 543 {
544 544 return d_ptr->m_presenter->animationOptions();
545 545 }
546 546
547 547 /*!
548 548 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
549 549
550 550 For polar charts, \a dx indicates the angle along angular axis instead of distance.
551 551 */
552 552 void QChart::scroll(qreal dx, qreal dy)
553 553 {
554 554 d_ptr->scroll(dx,dy);
555 555 }
556 556
557 557 void QChart::setBackgroundVisible(bool visible)
558 558 {
559 559 d_ptr->m_presenter->setBackgroundVisible(visible);
560 560 }
561 561
562 562 bool QChart::isBackgroundVisible() const
563 563 {
564 564 return d_ptr->m_presenter->isBackgroundVisible();
565 565 }
566 566
567 567 void QChart::setDropShadowEnabled(bool enabled)
568 568 {
569 569 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
570 570 }
571 571
572 572 bool QChart::isDropShadowEnabled() const
573 573 {
574 574 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
575 575 }
576 576
577 577 /*!
578 578 Returns all series that are added to the chart.
579 579
580 580 \sa addSeries(), removeSeries(), removeAllSeries()
581 581 */
582 582 QList<QAbstractSeries *> QChart::series() const
583 583 {
584 584 return d_ptr->m_dataset->series();
585 585 }
586 586
587 587 /*!
588 588 Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis.
589 589 The chart takes ownership of both the \a axis and the \a series.
590 590 Any horizontal axes previously attached to the \a series are deleted.
591 591
592 592 \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis()
593 593 */
594 594 void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series)
595 595 {
596 596 QList<QAbstractAxis*> list = axes(Qt::Horizontal, series);
597 597
598 598 foreach (QAbstractAxis* a, list) {
599 599 d_ptr->m_dataset->removeAxis(a);
600 600 delete a;
601 601 }
602 602
603 603 if (!d_ptr->m_dataset->axes().contains(axis))
604 604 d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom);
605 605 d_ptr->m_dataset->attachAxis(series, axis);
606 606 }
607 607
608 608 /*!
609 609 Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis.
610 610 The chart takes ownership of both the \a axis and the \a series.
611 611 Any vertical axes previously attached to the \a series are deleted.
612 612
613 613 \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis()
614 614 */
615 615 void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series)
616 616 {
617 617 QList<QAbstractAxis*> list = axes(Qt::Vertical, series);
618 618
619 619 foreach (QAbstractAxis* a, list) {
620 620 d_ptr->m_dataset->removeAxis(a);
621 621 delete a;
622 622 }
623 623
624 624 if (!d_ptr->m_dataset->axes().contains(axis))
625 625 d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft);
626 626 d_ptr->m_dataset->attachAxis(series, axis);
627 627 }
628 628
629 629 /*!
630 630 Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
631 631
632 632 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
633 633 */
634 634 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
635 635 {
636 636 d_ptr->m_dataset->addAxis(axis, alignment);
637 637 }
638 638
639 639 /*!
640 640 Removes the \a axis from the chart.
641 641 The chart releases its ownership of the specified \a axis object.
642 642
643 643 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
644 644 */
645 645 void QChart::removeAxis(QAbstractAxis *axis)
646 646 {
647 647 d_ptr->m_dataset->removeAxis(axis);
648 648 }
649 649
650 650 /*!
651 651 Returns the value in the \a series domain that corresponds to the \a position relative to chart widget.
652 652 */
653 653 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
654 654 {
655 655 return d_ptr->m_dataset->mapToValue(position, series);
656 656 }
657 657
658 658 /*!
659 659 Returns the position on the chart widget that corresponds to the \a value in the \a series domain.
660 660 */
661 661 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
662 662 {
663 663 return d_ptr->m_dataset->mapToPosition(value, series);
664 664 }
665 665
666 666 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
667 667
668 668 QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type):
669 669 q_ptr(q),
670 670 m_legend(0),
671 671 m_dataset(new ChartDataSet(q)),
672 672 m_presenter(new ChartPresenter(q, type)),
673 673 m_themeManager(new ChartThemeManager(q)),
674 674 m_type(type)
675 675 {
676 676 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
677 677 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
678 678 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
679 679 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
680 680 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
681 681 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
682 682 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
683 683 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
684 684 }
685 685
686 686 QChartPrivate::~QChartPrivate()
687 687 {
688 688 }
689 689
690 // Hackish solution to the problem of explicitly assigning the default pen/brush/font
691 // to a series or axis and having theme override it:
692 // Initialize pens, brushes, and fonts to something nobody is likely to ever use,
693 // so that default theme initialization will always set these properly.
694 QPen &QChartPrivate::defaultPen()
695 {
696 static QPen *defaultPen = 0;
697 if (!defaultPen)
698 defaultPen = new QPen(QColor(1, 2, 0), 0.93247536);
699 return *defaultPen;
700 }
701
702 QBrush &QChartPrivate::defaultBrush()
703 {
704 static QBrush *defaultBrush = 0;
705 if (!defaultBrush)
706 defaultBrush = new QBrush(QColor(1, 2, 0), Qt::Dense7Pattern);
707 return *defaultBrush;
708 }
709
710 QFont &QChartPrivate::defaultFont()
711 {
712 static QFont *defaultFont = 0;
713 if (!defaultFont) {
714 defaultFont = new QFont();
715 defaultFont->setPointSizeF(8.34563465);
716 }
717 return *defaultFont;
718 }
719
690 720 void QChartPrivate::init()
691 721 {
692 722 m_legend = new LegendScroller(q_ptr);
693 723 q_ptr->setTheme(QChart::ChartThemeLight);
694 724 q_ptr->setLayout(m_presenter->layout());
695 725 }
696 726
697 727 void QChartPrivate::zoomIn(qreal factor)
698 728 {
699 729 QRectF rect = m_presenter->geometry();
700 730 rect.setWidth(rect.width() / factor);
701 731 rect.setHeight(rect.height() / factor);
702 732 rect.moveCenter(m_presenter->geometry().center());
703 733 zoomIn(rect);
704 734 }
705 735
706 736 void QChartPrivate::zoomIn(const QRectF &rect)
707 737 {
708 738 if (!rect.isValid())
709 739 return;
710 740
711 741 QRectF r = rect.normalized();
712 742 const QRectF geometry = m_presenter->geometry();
713 743 r.translate(-geometry.topLeft());
714 744
715 745 if (!r.isValid())
716 746 return;
717 747
718 748 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
719 749 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
720 750 m_dataset->zoomInDomain(r);
721 751 m_presenter->setState(ChartPresenter::ShowState,QPointF());
722 752
723 753 }
724 754
725 755 void QChartPrivate::zoomOut(qreal factor)
726 756 {
727 757 const QRectF geometry = m_presenter->geometry();
728 758
729 759 QRectF r;
730 760 r.setSize(geometry.size() / factor);
731 761 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
732 762 if (!r.isValid())
733 763 return;
734 764
735 765 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
736 766 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
737 767 m_dataset->zoomOutDomain(r);
738 768 m_presenter->setState(ChartPresenter::ShowState,QPointF());
739 769 }
740 770
741 771 void QChartPrivate::scroll(qreal dx, qreal dy)
742 772 {
743 773 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
744 774 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
745 775 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
746 776 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
747 777
748 778 m_dataset->scrollDomain(dx, dy);
749 779 m_presenter->setState(ChartPresenter::ShowState,QPointF());
750 780 }
751 781
752 782 #include "moc_qchart.cpp"
753 783
754 784 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,68
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 QCHART_P_H
31 31 #define QCHART_P_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "qchart.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class ChartThemeManager;
39 39 class ChartPresenter;
40 40 class QLegend;
41 41 class ChartDataSet;
42 42
43 43 class QChartPrivate
44 44 {
45 45
46 46 public:
47 47 QChartPrivate(QChart *q, QChart::ChartType type);
48 48 ~QChartPrivate();
49 49 QChart *q_ptr;
50 50 QLegend *m_legend;
51 51 ChartDataSet *m_dataset;
52 52 ChartPresenter *m_presenter;
53 53 ChartThemeManager *m_themeManager;
54 54 QChart::ChartType m_type;
55 55
56 static QPen &defaultPen();
57 static QBrush &defaultBrush();
58 static QFont &defaultFont();
59
56 60 void init();
57 61 void zoomIn(qreal factor);
58 62 void zoomOut(qreal factor);
59 63 void zoomIn(const QRectF &rect);
60 64 void scroll(qreal dx, qreal dy);
61 65 };
62 66
63 67 QTCOMMERCIALCHART_END_NAMESPACE
64 68 #endif
@@ -1,301 +1,301
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 "qscatterseries.h"
22 22 #include "qscatterseries_p.h"
23 23 #include "scatterchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "scatteranimation_p.h"
27 #include "qchart_p.h"
27 28
28 29 /*!
29 30 \class QScatterSeries
30 31 \brief The QScatterSeries class is used for making scatter charts.
31 32
32 33 \mainclass
33 34
34 35 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
35 36 and the vertical axis.
36 37
37 38 \image examples_scatterchart.png
38 39
39 40 Creating basic scatter chart is simple:
40 41 \code
41 42 QScatterSeries* series = new QScatterSeries();
42 43 series->append(0, 6);
43 44 series->append(2, 4);
44 45 ...
45 46 chart->addSeries(series);
46 47 \endcode
47 48 */
48 49 /*!
49 50 \qmlclass ScatterSeries QScatterSeries
50 51 \inherits XYSeries
51 52
52 53 The following QML shows how to create a chart with two simple scatter series:
53 54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
54 55
55 56 \beginfloatleft
56 57 \image demos_qmlchart5.png
57 58 \endfloat
58 59 \clearfloat
59 60 */
60 61
61 62 /*!
62 63 \enum QScatterSeries::MarkerShape
63 64
64 65 This enum describes the shape used when rendering marker items.
65 66
66 67 \value MarkerShapeCircle
67 68 \value MarkerShapeRectangle
68 69 */
69 70
70 71 /*!
71 72 \property QScatterSeries::color
72 73 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
73 74 \sa QScatterSeries::brush()
74 75 */
75 76
76 77 /*!
77 78 \property QScatterSeries::borderColor
78 79 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
79 80 \sa QScatterSeries::pen()
80 81 */
81 82 /*!
82 83 \qmlproperty color ScatterSeries::borderColor
83 84 Border (pen) color of the series.
84 85 */
85 86
86 87 /*!
87 88 \qmlproperty real ScatterSeries::borderWidth
88 89 The width of the border line. By default the width is 2.0.
89 90 */
90 91
91 92 /*!
92 93 \property QScatterSeries::markerShape
93 94 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
94 95 */
95 96 /*!
96 97 \qmlproperty MarkerShape ScatterSeries::markerShape
97 98 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
98 99 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
99 100 The default shape is ScatterSeries.MarkerShapeCircle.
100 101 */
101 102
102 103 /*!
103 104 \property QScatterSeries::markerSize
104 105 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
105 106 */
106 107 /*!
107 108 \qmlproperty real ScatterSeries::markerSize
108 109 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
109 110 */
110 111
111 112 /*!
112 113 \fn void QScatterSeries::colorChanged(QColor color)
113 114 Signal is emitted when the fill (brush) color has changed to \a color.
114 115 */
115 116
116 117 /*!
117 118 \fn void QScatterSeries::borderColorChanged(QColor color)
118 119 Signal is emitted when the line (pen) color has changed to \a color.
119 120 */
120 121 /*!
121 122 \qmlsignal ScatterSeries::borderColorChanged(color color)
122 123 Signal is emitted when the line (pen) color has changed to \a color.
123 124 */
124 125
125 126 /*!
126 127 \fn QChartSeriesType QScatterSeries::type() const
127 128 Returns QChartSeries::SeriesTypeScatter.
128 129 \sa QAbstractSeries, SeriesType
129 130 */
130 131
131 132 QTCOMMERCIALCHART_BEGIN_NAMESPACE
132 133
133 134 /*!
134 135 Constructs a series object which is a child of \a parent.
135 136 */
136 137 QScatterSeries::QScatterSeries(QObject *parent)
137 138 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
138 139 {
139 140 }
140 141
141 142 /*!
142 143 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
143 144 */
144 145 QScatterSeries::~QScatterSeries()
145 146 {
146 147 Q_D(QScatterSeries);
147 148 if (d->m_chart)
148 149 d->m_chart->removeSeries(this);
149 150 }
150 151
151 152 QAbstractSeries::SeriesType QScatterSeries::type() const
152 153 {
153 154 return QAbstractSeries::SeriesTypeScatter;
154 155 }
155 156
156 157 /*!
157 158 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
158 159 pen from chart theme is used.
159 160 \sa QChart::setTheme()
160 161 */
161 162 void QScatterSeries::setPen(const QPen &pen)
162 163 {
163 164 Q_D(QXYSeries);
164 165 if (d->m_pen != pen) {
165 166 bool emitColorChanged = d->m_pen.color() != pen.color();
166 167 d->m_pen = pen;
167 168 emit d->updated();
168 169 if (emitColorChanged)
169 170 emit borderColorChanged(pen.color());
170 171 }
171 172 }
172 173
173 174 /*!
174 175 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
175 176 from chart theme setting is used.
176 177 \sa QChart::setTheme()
177 178 */
178 179 void QScatterSeries::setBrush(const QBrush &brush)
179 180 {
180 181 Q_D(QScatterSeries);
181 182 if (d->m_brush != brush) {
182 183 bool emitColorChanged = d->m_brush.color() != brush.color();
183 184 d->m_brush = brush;
184 185 emit d->updated();
185 186 if (emitColorChanged)
186 187 emit colorChanged(brush.color());
187 188 }
188 189 }
189 190
190 191 void QScatterSeries::setColor(const QColor &color)
191 192 {
192 193 QBrush b = brush();
193 194 if (b == QBrush())
194 195 b.setStyle(Qt::SolidPattern);
195 196 b.setColor(color);
196 197 setBrush(b);
197 198 }
198 199
199 200 QColor QScatterSeries::color() const
200 201 {
201 202 return brush().color();
202 203 }
203 204
204 205 void QScatterSeries::setBorderColor(const QColor &color)
205 206 {
206 207 QPen p = pen();
207 208 if (p.color() != color) {
208 209 p.setColor(color);
209 210 setPen(p);
210 211 }
211 212 }
212 213
213 214 QColor QScatterSeries::borderColor() const
214 215 {
215 216 return pen().color();
216 217 }
217 218
218 219 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
219 220 {
220 221 Q_D(const QScatterSeries);
221 222 return d->m_shape;
222 223 }
223 224
224 225 void QScatterSeries::setMarkerShape(MarkerShape shape)
225 226 {
226 227 Q_D(QScatterSeries);
227 228 if (d->m_shape != shape) {
228 229 d->m_shape = shape;
229 230 emit d->updated();
230 231 }
231 232 }
232 233
233 234 qreal QScatterSeries::markerSize() const
234 235 {
235 236 Q_D(const QScatterSeries);
236 237 return d->m_size;
237 238 }
238 239
239 240 void QScatterSeries::setMarkerSize(qreal size)
240 241 {
241 242 Q_D(QScatterSeries);
242 243
243 244 if (!qFuzzyCompare(d->m_size, size)) {
244 245 d->m_size = size;
245 246 emit d->updated();
246 247 }
247 248 }
248 249
249 250 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
250 251
251 252 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
252 253 : QXYSeriesPrivate(q),
253 254 m_shape(QScatterSeries::MarkerShapeCircle),
254 255 m_size(15.0)
255 256 {
256 257 }
257 258
258 259 void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
259 260 {
260 261 Q_Q(QScatterSeries);
261 262 ScatterChartItem *scatter = new ScatterChartItem(q,parent);
262 263 m_item.reset(scatter);
263 264 QAbstractSeriesPrivate::initializeGraphics(parent);
264 265 }
265 266
266 267 void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
267 268 {
268 269 Q_Q(QScatterSeries);
269 QPen pen;
270 QBrush brush;
271 270 const QList<QColor> colors = theme->seriesColors();
272 271 const QList<QGradient> gradients = theme->seriesGradients();
273 272
274 if (forced || pen == m_pen) {
273 if (forced || QChartPrivate::defaultPen() == m_pen) {
274 QPen pen;
275 275 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
276 276 pen.setWidthF(2);
277 277 q->setPen(pen);
278 278 }
279 279
280 if (forced || brush == m_brush) {
280 if (forced || QChartPrivate::defaultBrush() == m_brush) {
281 281 QBrush brush(colors.at(index % colors.size()));
282 282 q->setBrush(brush);
283 283 }
284 284 }
285 285
286 286 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
287 287 {
288 288 ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data());
289 289 Q_ASSERT(item);
290 290
291 291 if (options.testFlag(QChart::SeriesAnimations))
292 292 item->setAnimation(new ScatterAnimation(item));
293 293 else
294 294 item->setAnimation(0);
295 295
296 296 QAbstractSeriesPrivate::initializeAnimations(options);
297 297 }
298 298
299 299 #include "moc_qscatterseries.cpp"
300 300
301 301 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,152 +1,153
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 "qsplineseries.h"
22 22 #include "qsplineseries_p.h"
23 23 #include "splinechartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "splineanimation_p.h"
27 #include "qchart_p.h"
27 28
28 29 /*!
29 30 \class QSplineSeries
30 31 \brief Series type used to store data needed to draw a spline.
31 32
32 33 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
33 34 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
34 35
35 36 \image examples_splinechart.png
36 37
37 38 Creating basic spline chart is simple:
38 39 \code
39 40 QSplineSeries* series = new QSplineSeries();
40 41 series->append(0, 6);
41 42 series->append(2, 4);
42 43 ...
43 44 chart->addSeries(series);
44 45 \endcode
45 46 */
46 47
47 48 /*!
48 49 \qmlclass SplineSeries QSplineSeries
49 50 \inherits XYSeries
50 51
51 52 The following QML shows how to create a simple spline chart:
52 53 \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1
53 54 \beginfloatleft
54 55 \image demos_qmlchart3.png
55 56 \endfloat
56 57 \clearfloat
57 58 */
58 59
59 60 /*!
60 61 \fn QSeriesType QSplineSeries::type() const
61 62 Returns the type of the series
62 63 */
63 64
64 65 /*!
65 66 \qmlproperty real SplineSeries::width
66 67 The width of the line. By default the width is 2.0.
67 68 */
68 69
69 70 /*!
70 71 \qmlproperty Qt::PenStyle SplineSeries::style
71 72 Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine,
72 73 Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API.
73 74 By default the style is Qt.SolidLine.
74 75 */
75 76
76 77 /*!
77 78 \qmlproperty Qt::PenCapStyle SplineSeries::capStyle
78 79 Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By
79 80 default the cap style is Qt.SquareCap.
80 81 */
81 82
82 83 QTCOMMERCIALCHART_BEGIN_NAMESPACE
83 84
84 85 /*!
85 86 Constructs empty series object which is a child of \a parent.
86 87 When series object is added to a QChart instance then the ownerships is transferred.
87 88 */
88 89
89 90 QSplineSeries::QSplineSeries(QObject *parent)
90 91 : QLineSeries(*new QSplineSeriesPrivate(this), parent)
91 92 {
92 93 }
93 94
94 95 /*!
95 96 Destroys the object.
96 97 */
97 98 QSplineSeries::~QSplineSeries()
98 99 {
99 100 Q_D(QSplineSeries);
100 101 if (d->m_chart)
101 102 d->m_chart->removeSeries(this);
102 103 }
103 104
104 105 QAbstractSeries::SeriesType QSplineSeries::type() const
105 106 {
106 107 return QAbstractSeries::SeriesTypeSpline;
107 108 }
108 109
109 110 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110 111
111 112 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q)
112 113 : QLineSeriesPrivate(q)
113 114 {
114 115 }
115 116
116 117 void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
117 118 {
118 119 Q_Q(QSplineSeries);
119 120 SplineChartItem *spline = new SplineChartItem(q,parent);
120 121 m_item.reset(spline);
121 122 QAbstractSeriesPrivate::initializeGraphics(parent);
122 123 }
123 124
124 125 void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
125 126 {
126 127 Q_Q(QSplineSeries);
127 128 const QList<QColor> colors = theme->seriesColors();
128 129
130 if (forced || QChartPrivate::defaultPen() == m_pen) {
129 131 QPen pen;
130 if (forced || pen == m_pen) {
131 132 pen.setColor(colors.at(index % colors.size()));
132 133 pen.setWidthF(2);
133 134 q->setPen(pen);
134 135 }
135 136 }
136 137
137 138 void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
138 139 {
139 140 SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data());
140 141 Q_ASSERT(item);
141 142 if (options.testFlag(QChart::SeriesAnimations)) {
142 143 item->setAnimation(new SplineAnimation(item));
143 144 }else{
144 145 item->setAnimation(0);
145 146 }
146 147 QAbstractSeriesPrivate::initializeAnimations(options);
147 148 }
148 149
149 150 #include "moc_qsplineseries.cpp"
150 151 #include "moc_qsplineseries_p.cpp"
151 152
152 153 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,89 +1,91
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 CHARTTHEME_H
31 31 #define CHARTTHEME_H
32 32
33 33 #include "chartthememanager_p.h"
34 34 #include <QColor>
35 35 #include <QGradientStops>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class ChartTheme
40 40 {
41 41
42 42 public:
43 43 enum BackgroundShadesMode {
44 44 BackgroundShadesNone = 0,
45 45 BackgroundShadesVertical,
46 46 BackgroundShadesHorizontal,
47 47 BackgroundShadesBoth
48 48 };
49 49
50 50 protected:
51 51 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight):m_id(id),
52 52 m_backgroundShades(BackgroundShadesNone),
53 m_backgroundDropShadowEnabled(false){};
53 m_backgroundShadesBrush(Qt::SolidPattern),
54 m_backgroundDropShadowEnabled(false)
55 {};
54 56 public:
55 57 QChart::ChartTheme id() const { return m_id; }
56 58 QList<QGradient> seriesGradients() const { return m_seriesGradients; }
57 59 QList<QColor> seriesColors() const { return m_seriesColors; }
58 60 QLinearGradient chartBackgroundGradient() const { return m_chartBackgroundGradient; }
59 61 QFont masterFont() const { return m_masterFont; }
60 62 QFont labelFont() const { return m_labelFont; }
61 63 QBrush labelBrush() const { return m_labelBrush; }
62 64 QPen axisLinePen() const { return m_axisLinePen; }
63 65 QPen backgroundShadesPen() const { return m_backgroundShadesPen; }
64 66 QBrush backgroundShadesBrush() const { return m_backgroundShadesBrush; }
65 67 BackgroundShadesMode backgroundShades() const { return m_backgroundShades; }
66 68 bool isBackgroundDropShadowEnabled() const { return m_backgroundDropShadowEnabled; }
67 69 QPen girdLinePen() const { return m_gridLinePen; }
68 70
69 71 protected:
70 72 QChart::ChartTheme m_id;
71 73 QList<QColor> m_seriesColors;
72 74 QList<QGradient> m_seriesGradients;
73 75 QLinearGradient m_chartBackgroundGradient;
74 76
75 77 QFont m_masterFont;
76 78 QFont m_labelFont;
77 79 QBrush m_labelBrush;
78 80 QPen m_axisLinePen;
79 81 QPen m_backgroundShadesPen;
80 82 QBrush m_backgroundShadesBrush;
81 83 BackgroundShadesMode m_backgroundShades;
82 84 bool m_backgroundDropShadowEnabled;
83 85 QPen m_gridLinePen;
84 86
85 87 };
86 88
87 89 QTCOMMERCIALCHART_END_NAMESPACE
88 90
89 91 #endif // CHARTTHEME_H
@@ -1,587 +1,590
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 "qxyseries.h"
22 22 #include "qxyseries_p.h"
23 23 #include "abstractdomain_p.h"
24 24 #include "qvalueaxis.h"
25 25 #include "xychart_p.h"
26 26 #include "qxylegendmarker.h"
27 27 #include "charthelpers_p.h"
28 #include "qchart_p.h"
28 29
29 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 31
31 32 /*!
32 33 \class QXYSeries
33 34 \brief The QXYSeries class is a base class for line, spline and scatter series.
34 35 */
35 36 /*!
36 37 \qmlclass XYSeries
37 38 \inherits AbstractSeries
38 39 The XYSeries class is a base class for line, spline and scatter series.
39 40
40 41 The class cannot be instantiated directly.
41 42 */
42 43
43 44 /*!
44 45 \qmlproperty AbstractAxis XYSeries::axisX
45 46 The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for
46 47 the series.
47 48 \sa axisXTop
48 49 */
49 50
50 51 /*!
51 52 \qmlproperty AbstractAxis XYSeries::axisY
52 53 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
53 54 the series.
54 55 \sa axisYRight
55 56 */
56 57
57 58 /*!
58 59 \qmlproperty AbstractAxis XYSeries::axisXTop
59 60 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
60 61 axisXTop, but not both.
61 62 \sa axisX
62 63 */
63 64
64 65 /*!
65 66 \qmlproperty AbstractAxis XYSeries::axisYRight
66 67 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
67 68 or axisYRight, but not both.
68 69 \sa axisY
69 70 */
70 71
71 72 /*!
72 73 \qmlproperty AbstractAxis XYSeries::axisAngular
73 74 The angular axis used for the series, drawn around the polar chart view.
74 75 \sa axisX
75 76 */
76 77
77 78 /*!
78 79 \qmlproperty AbstractAxis XYSeries::axisRadial
79 80 The radial axis used for the series, drawn inside the polar chart view.
80 81 \sa axisY
81 82 */
82 83
83 84 /*!
84 85 \property QXYSeries::pointsVisible
85 86 Controls if the data points are visible and should be drawn.
86 87 */
87 88 /*!
88 89 \qmlproperty bool XYSeries::pointsVisible
89 90 Controls if the data points are visible and should be drawn.
90 91 */
91 92
92 93 /*!
93 94 \fn QPen QXYSeries::pen() const
94 95 \brief Returns pen used to draw points for series.
95 96 \sa setPen()
96 97 */
97 98
98 99 /*!
99 100 \fn QBrush QXYSeries::brush() const
100 101 \brief Returns brush used to draw points for series.
101 102 \sa setBrush()
102 103 */
103 104
104 105 /*!
105 106 \property QXYSeries::color
106 107 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
107 108 fill (brush) color in case of QScatterSeries or QAreaSeries.
108 109 \sa QXYSeries::pen(), QXYSeries::brush()
109 110 */
110 111 /*!
111 112 \qmlproperty color XYSeries::color
112 113 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
113 114 fill (brush) color in case of ScatterSeries or AreaSeries.
114 115 */
115 116
116 117 /*!
117 118 \fn void QXYSeries::clicked(const QPointF& point)
118 119 \brief Signal is emitted when user clicks the \a point on chart.
119 120 */
120 121 /*!
121 122 \qmlsignal XYSeries::onClicked(QPointF point)
122 123 Signal is emitted when user clicks the \a point on chart. For example:
123 124 \code
124 125 LineSeries {
125 126 XYPoint { x: 0; y: 0 }
126 127 XYPoint { x: 1.1; y: 2.1 }
127 128 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
128 129 }
129 130 \endcode
130 131 */
131 132
132 133 /*!
133 134 \fn void QXYSeries::hovered(const QPointF &point, bool state)
134 135 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
135 136 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
136 137 the series.
137 138 */
138 139 /*!
139 140 \qmlsignal XYSeries::onHovered(point point, bool state)
140 141 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
141 142 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
142 143 the series.
143 144 */
144 145
145 146 /*!
146 147 \fn void QXYSeries::pointReplaced(int index)
147 148 Signal is emitted when a point has been replaced at \a index.
148 149 \sa replace()
149 150 */
150 151 /*!
151 152 \qmlsignal XYSeries::onPointReplaced(int index)
152 153 Signal is emitted when a point has been replaced at \a index.
153 154 */
154 155
155 156 /*!
156 157 \fn void QXYSeries::pointsReplaced()
157 158 Signal is emitted when all points have been replaced with other points.
158 159 \sa replace()
159 160 */
160 161 /*!
161 162 \qmlsignal XYSeries::onPointsReplaced()
162 163 */
163 164
164 165 /*!
165 166 \fn void QXYSeries::pointAdded(int index)
166 167 Signal is emitted when a point has been added at \a index.
167 168 \sa append(), insert()
168 169 */
169 170 /*!
170 171 \qmlsignal XYSeries::onPointAdded(int index)
171 172 Signal is emitted when a point has been added at \a index.
172 173 */
173 174
174 175 /*!
175 176 \fn void QXYSeries::pointRemoved(int index)
176 177 Signal is emitted when a point has been removed from \a index.
177 178 \sa remove()
178 179 */
179 180 /*!
180 181 \qmlsignal XYSeries::onPointRemoved(int index)
181 182 Signal is emitted when a point has been removed from \a index.
182 183 */
183 184
184 185 /*!
185 186 \fn void QXYSeries::colorChanged(QColor color)
186 187 \brief Signal is emitted when the line (pen) color has changed to \a color.
187 188 */
188 189 /*!
189 190 \qmlsignal XYSeries::onColorChanged(color color)
190 191 Signal is emitted when the line (pen) color has changed to \a color.
191 192 */
192 193
193 194 /*!
194 195 \fn void QXYSeriesPrivate::updated()
195 196 \brief \internal
196 197 */
197 198
198 199 /*!
199 200 \qmlmethod XYSeries::append(real x, real y)
200 201 Append point (\a x, \a y) to the series
201 202 */
202 203
203 204 /*!
204 205 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
205 206 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
206 207 exist.
207 208 */
208 209
209 210 /*!
210 211 \qmlmethod XYSeries::remove(real x, real y)
211 212 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
212 213 */
213 214
214 215 /*!
215 216 \qmlmethod XYSeries::insert(int index, real x, real y)
216 217 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
217 218 points. If index is the same as or bigger than count, the point is appended to the list of points.
218 219 */
219 220
220 221 /*!
221 222 \qmlmethod QPointF XYSeries::at(int index)
222 223 Returns point at \a index. Returns (0, 0) if the index is not valid.
223 224 */
224 225
225 226 /*!
226 227 \internal
227 228
228 229 Constructs empty series object which is a child of \a parent.
229 230 When series object is added to QChart instance ownerships is transferred.
230 231 */
231 232 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
232 233 : QAbstractSeries(d, parent)
233 234 {
234 235 }
235 236
236 237 /*!
237 238 Destroys the object. Series added to QChart instances are owned by those,
238 239 and are destroyed when QChart instances are destroyed.
239 240 */
240 241 QXYSeries::~QXYSeries()
241 242 {
242 243 }
243 244
244 245 /*!
245 246 Adds data point (\a x, \a y) to the series.
246 247 */
247 248 void QXYSeries::append(qreal x, qreal y)
248 249 {
249 250 append(QPointF(x, y));
250 251 }
251 252
252 253 /*!
253 254 This is an overloaded function.
254 255 Adds data \a point to the series.
255 256 */
256 257 void QXYSeries::append(const QPointF &point)
257 258 {
258 259 Q_D(QXYSeries);
259 260
260 261 if (isValidValue(point)) {
261 262 d->m_points << point;
262 263 emit pointAdded(d->m_points.count() - 1);
263 264 }
264 265 }
265 266
266 267 /*!
267 268 This is an overloaded function.
268 269 Adds list of data \a points to the series.
269 270 */
270 271 void QXYSeries::append(const QList<QPointF> &points)
271 272 {
272 273 foreach (const QPointF &point , points)
273 274 append(point);
274 275 }
275 276
276 277 /*!
277 278 Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY).
278 279 \sa QXYSeries::pointReplaced()
279 280 */
280 281 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
281 282 {
282 283 replace(QPointF(oldX, oldY), QPointF(newX, newY));
283 284 }
284 285
285 286 /*!
286 287 Replaces \a oldPoint with \a newPoint.
287 288 \sa QXYSeries::pointReplaced()
288 289 */
289 290 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
290 291 {
291 292 Q_D(QXYSeries);
292 293 int index = d->m_points.indexOf(oldPoint);
293 294 if (index == -1)
294 295 return;
295 296 replace(index, newPoint);
296 297 }
297 298
298 299 /*!
299 300 Replaces the point at \a index with data point (\a newX, \a newY).
300 301 \sa QXYSeries::pointReplaced()
301 302 */
302 303 void QXYSeries::replace(int index, qreal newX, qreal newY)
303 304 {
304 305 replace(index, QPointF(newX, newY));
305 306 }
306 307
307 308 /*!
308 309 Replaces the point at \a index with \a newPoint.
309 310 \sa QXYSeries::pointReplaced()
310 311 */
311 312 void QXYSeries::replace(int index, const QPointF &newPoint)
312 313 {
313 314 Q_D(QXYSeries);
314 315 if (isValidValue(newPoint)) {
315 316 d->m_points[index] = newPoint;
316 317 emit pointReplaced(index);
317 318 }
318 319 }
319 320
320 321 /*!
321 322 Replaces the current points with \a points.
322 323 \note This is much faster than replacing data points one by one,
323 324 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
324 325 when the points have been replaced.
325 326 \sa QXYSeries::pointsReplaced()
326 327 */
327 328 void QXYSeries::replace(QList<QPointF> points)
328 329 {
329 330 Q_D(QXYSeries);
330 331 d->m_points = points.toVector();
331 332 emit pointsReplaced();
332 333 }
333 334
334 335 /*!
335 336 Removes the point (\a x, \a y) from the series.
336 337 */
337 338 void QXYSeries::remove(qreal x, qreal y)
338 339 {
339 340 remove(QPointF(x, y));
340 341 }
341 342
342 343 /*!
343 344 Removes the \a point from the series.
344 345 */
345 346 void QXYSeries::remove(const QPointF &point)
346 347 {
347 348 Q_D(QXYSeries);
348 349 int index = d->m_points.indexOf(point);
349 350 if (index == -1)
350 351 return;
351 352 remove(index);
352 353 }
353 354
354 355 /*!
355 356 Removes the point at \a index from the series.
356 357 */
357 358 void QXYSeries::remove(int index)
358 359 {
359 360 Q_D(QXYSeries);
360 361 d->m_points.remove(index);
361 362 emit pointRemoved(index);
362 363 }
363 364
364 365 /*!
365 366 Inserts a \a point in the series at \a index position.
366 367 */
367 368 void QXYSeries::insert(int index, const QPointF &point)
368 369 {
369 370 Q_D(QXYSeries);
370 371 if (isValidValue(point)) {
371 372 d->m_points.insert(index, point);
372 373 emit pointAdded(index);
373 374 }
374 375 }
375 376
376 377 /*!
377 378 Removes all points from the series.
378 379 */
379 380 void QXYSeries::clear()
380 381 {
381 382 Q_D(QXYSeries);
382 383 for (int i = d->m_points.size() - 1; i >= 0; i--)
383 384 remove(d->m_points.at(i));
384 385 }
385 386
386 387 /*!
387 388 Returns list of points in the series.
388 389 */
389 390 QList<QPointF> QXYSeries::points() const
390 391 {
391 392 Q_D(const QXYSeries);
392 393 return d->m_points.toList();
393 394 }
394 395
395 396 /*!
396 397 Returns point at \a index in internal points vector.
397 398 */
398 399 const QPointF &QXYSeries::at(int index) const
399 400 {
400 401 Q_D(const QXYSeries);
401 402 return d->m_points.at(index);
402 403 }
403 404
404 405 /*!
405 406 Returns number of data points within series.
406 407 */
407 408 int QXYSeries::count() const
408 409 {
409 410 Q_D(const QXYSeries);
410 411 return d->m_points.count();
411 412 }
412 413
413 414
414 415 /*!
415 416 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
416 417 pen from chart theme is used.
417 418 \sa QChart::setTheme()
418 419 */
419 420 void QXYSeries::setPen(const QPen &pen)
420 421 {
421 422 Q_D(QXYSeries);
422 423 if (d->m_pen != pen) {
423 424 bool emitColorChanged = d->m_pen.color() != pen.color();
424 425 d->m_pen = pen;
425 426 emit d->updated();
426 427 if (emitColorChanged)
427 428 emit colorChanged(pen.color());
428 429 }
429 430 }
430 431
431 432 QPen QXYSeries::pen() const
432 433 {
433 434 Q_D(const QXYSeries);
434 435 return d->m_pen;
435 436 }
436 437
437 438 /*!
438 439 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
439 440 from chart theme setting is used.
440 441 \sa QChart::setTheme()
441 442 */
442 443 void QXYSeries::setBrush(const QBrush &brush)
443 444 {
444 445 Q_D(QXYSeries);
445 446 if (d->m_brush != brush) {
446 447 d->m_brush = brush;
447 448 emit d->updated();
448 449 }
449 450 }
450 451
451 452 QBrush QXYSeries::brush() const
452 453 {
453 454 Q_D(const QXYSeries);
454 455 return d->m_brush;
455 456 }
456 457
457 458 void QXYSeries::setColor(const QColor &color)
458 459 {
459 460 QPen p = pen();
460 461 if (p.color() != color) {
461 462 p.setColor(color);
462 463 setPen(p);
463 464 }
464 465 }
465 466
466 467 QColor QXYSeries::color() const
467 468 {
468 469 return pen().color();
469 470 }
470 471
471 472 void QXYSeries::setPointsVisible(bool visible)
472 473 {
473 474 Q_D(QXYSeries);
474 475 if (d->m_pointsVisible != visible) {
475 476 d->m_pointsVisible = visible;
476 477 emit d->updated();
477 478 }
478 479 }
479 480
480 481 bool QXYSeries::pointsVisible() const
481 482 {
482 483 Q_D(const QXYSeries);
483 484 return d->m_pointsVisible;
484 485 }
485 486
486 487
487 488 /*!
488 489 Stream operator for adding a data \a point to the series.
489 490 \sa append()
490 491 */
491 492 QXYSeries &QXYSeries::operator<< (const QPointF &point)
492 493 {
493 494 append(point);
494 495 return *this;
495 496 }
496 497
497 498
498 499 /*!
499 500 Stream operator for adding a list of \a points to the series.
500 501 \sa append()
501 502 */
502 503
503 504 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
504 505 {
505 506 append(points);
506 507 return *this;
507 508 }
508 509
509 510 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
510 511
511 512
512 513 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
513 514 : QAbstractSeriesPrivate(q),
515 m_pen(QChartPrivate::defaultPen()),
516 m_brush(QChartPrivate::defaultBrush()),
514 517 m_pointsVisible(false)
515 518 {
516 519 }
517 520
518 521 void QXYSeriesPrivate::initializeDomain()
519 522 {
520 523 qreal minX(0);
521 524 qreal minY(0);
522 525 qreal maxX(1);
523 526 qreal maxY(1);
524 527
525 528 Q_Q(QXYSeries);
526 529
527 530 const QList<QPointF>& points = q->points();
528 531
529 532 if (!points.isEmpty()) {
530 533 minX = points[0].x();
531 534 minY = points[0].y();
532 535 maxX = minX;
533 536 maxY = minY;
534 537
535 538 for (int i = 0; i < points.count(); i++) {
536 539 qreal x = points[i].x();
537 540 qreal y = points[i].y();
538 541 minX = qMin(minX, x);
539 542 minY = qMin(minY, y);
540 543 maxX = qMax(maxX, x);
541 544 maxY = qMax(maxY, y);
542 545 }
543 546 }
544 547
545 548 domain()->setRange(minX, maxX, minY, maxY);
546 549 }
547 550
548 551 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
549 552 {
550 553 Q_Q(QXYSeries);
551 554 QList<QLegendMarker*> list;
552 555 return list << new QXYLegendMarker(q,legend);
553 556 }
554 557
555 558 void QXYSeriesPrivate::initializeAxes()
556 559 {
557 560
558 561 }
559 562
560 563 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
561 564 {
562 565 Q_UNUSED(orientation);
563 566 return QAbstractAxis::AxisTypeValue;
564 567 }
565 568
566 569 QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
567 570 {
568 571 Q_UNUSED(orientation);
569 572 return 0;
570 573 }
571 574
572 575 void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
573 576 {
574 577 XYChart *item = static_cast<XYChart *>(m_item.data());
575 578 Q_ASSERT(item);
576 579 if (options.testFlag(QChart::SeriesAnimations)) {
577 580 item->setAnimation(new XYAnimation(item));
578 581 }else{
579 582 item->setAnimation(0);
580 583 }
581 584 QAbstractSeriesPrivate::initializeAnimations(options);
582 585 }
583 586
584 587 #include "moc_qxyseries.cpp"
585 588 #include "moc_qxyseries_p.cpp"
586 589
587 590 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now