##// END OF EJS Templates
Adds axis domain intialization
Michal Klocek -
r1695:c8cbc9ab609f
parent child
Show More
@@ -1,92 +1,90
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 import QtQuick 1.1
22 22 import QtCommercial.Chart 1.0
23 23
24 24 Rectangle {
25 25 width: 360
26 26 height: 360
27 27 property int currentIndex: -1
28 28
29 29 //![1]
30 30 ChartView {
31 31 id: chartView
32 32 title: "Driver Speeds, lap 1"
33 33 anchors.fill: parent
34 34 legend.alignment: Qt.AlignTop
35 35 animationOptions: ChartView.SeriesAnimations
36 36 }
37 37 //![1]
38 38
39 39 //![2]
40 40 // An example XmlListModel containing F1 legend drivers' speeds at speed traps
41 41 SpeedsXml {
42 42 id: speedsXml
43 43 onStatusChanged: {
44 44 if (status == XmlListModel.Ready) {
45 45 timer.start();
46 46 }
47 47 }
48 48 }
49 49 //![2]
50 50
51 51 //![3]
52 52 // A timer to mimic refreshing the data dynamically
53 53 Timer {
54 54 id: timer
55 55 interval: 700
56 56 repeat: true
57 57 triggeredOnStart: true
58 58 running: false
59 59 onTriggered: {
60 60 currentIndex++;
61 61 if (currentIndex < speedsXml.count) {
62 62 // Check if there is a series for the data already (we are using driver name to identify series)
63 63 var lineSeries = chartView.series(speedsXml.get(currentIndex).driver);
64 if (!lineSeries)
64 if (!lineSeries){
65 65 lineSeries = chartView.createSeries(ChartView.SeriesTypeLine, speedsXml.get(currentIndex).driver);
66
67 if (currentIndex < 3) {
68 66 chartView.createDefaultAxes();
69 67 chartView.axisY(lineSeries).min = 0;
70 68 chartView.axisY(lineSeries).max = 250
71 69 }
72 70
73 71 lineSeries.append(currentIndex, speedsXml.get(currentIndex).speed);
74 72
75 73 // Make the x-axis range dynamic
76 74 if (currentIndex > 9)
77 75 chartView.axisX(lineSeries).min = currentIndex - 10;
78 76 else
79 77 chartView.axisX(lineSeries).min = 0;
80 78
81 79 chartView.axisX(lineSeries).max = currentIndex + 1;
82 80 } else {
83 81 // No more data, change x-axis range to show all the data
84 82 timer.stop();
85 83 chartView.animationOptions = ChartView.AllAnimations;
86 84 chartView.axisX(lineSeries).min = 0;
87 85 chartView.axisX(lineSeries).max = currentIndex + 1;
88 86 }
89 87 }
90 88 }
91 89 //![3]
92 90 }
@@ -1,95 +1,94
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QBarSeries>
25 25 #include <QBarSet>
26 26 #include <QLegend>
27 27 #include <QBarCategoriesAxis>
28 28 #include <QHorizontalBarSeries>
29 29
30 30 QTCOMMERCIALCHART_USE_NAMESPACE
31 31
32 32 int main(int argc, char *argv[])
33 33 {
34 34 QApplication a(argc, argv);
35 35
36 36 //![1]
37 37 QBarSet *set0 = new QBarSet("Jane");
38 38 QBarSet *set1 = new QBarSet("John");
39 39 QBarSet *set2 = new QBarSet("Axel");
40 40 QBarSet *set3 = new QBarSet("Mary");
41 41 QBarSet *set4 = new QBarSet("Samantha");
42 42
43 43 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
44 44 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
45 45 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
46 46 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
47 47 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
48 48 //![1]
49 49
50 50 //![2]
51 51 QHorizontalBarSeries *series = new QHorizontalBarSeries();
52 52 series->append(set0);
53 53 series->append(set1);
54 54 series->append(set2);
55 55 series->append(set3);
56 56 series->append(set4);
57 57
58 58 //![2]
59 59
60 60 //![3]
61 61 QChart* chart = new QChart();
62 62 chart->addSeries(series);
63 63 chart->setTitle("Simple horizontal barchart example");
64 64 chart->createDefaultAxes();
65 65 chart->setAnimationOptions(QChart::SeriesAnimations);
66 66 //![3]
67 67
68 68 //![4]
69 69 QStringList categories;
70 70 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
71 71 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
72 72 axis->append(categories);
73 chart->createDefaultAxes();
74 73 chart->setAxisY(axis,series);
75 74 //![4]
76 75
77 76 //![5]
78 77 chart->legend()->setVisible(true);
79 78 chart->legend()->setAlignment(Qt::AlignBottom);
80 79 //![5]
81 80
82 81 //![6]
83 82 QChartView* chartView = new QChartView(chart);
84 83 chartView->setRenderHint(QPainter::Antialiasing);
85 84 //![6]
86 85
87 86 //![7]
88 87 QMainWindow window;
89 88 window.setCentralWidget(chartView);
90 89 window.resize(400, 300);
91 90 window.show();
92 91 //![7]
93 92
94 93 return a.exec();
95 94 }
@@ -1,406 +1,397
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qareaseries.h"
22 22 #include "qareaseries_p.h"
23 23 #include "qlineseries.h"
24 24 #include "areachartitem_p.h"
25 25 #include "legendmarker_p.h"
26 26 #include "domain_p.h"
27 27 #include "chartdataset_p.h"
28 28 #include "charttheme_p.h"
29 29 #include "chartanimator_p.h"
30 30 #include "qvaluesaxis.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 counstucted wihtout 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 counstucted wihtout 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 \fn QPen QAreaSeries::pen() const
102 102 \brief Returns the pen used to draw line for this series.
103 103 \sa setPen()
104 104 */
105 105
106 106 /*!
107 107 \fn QPen QAreaSeries::brush() const
108 108 \brief Returns the brush used to draw line for this series.
109 109 \sa setBrush()
110 110 */
111 111
112 112 /*!
113 113 \fn void QAreaSeries::colorChanged(QColor color)
114 114 \brief Signal is emitted when the fill (brush) color has changed to \a color.
115 115 */
116 116 /*!
117 117 \qmlsignal AreaSeries::onColorChanged(color color)
118 118 Signal is emitted when the fill (brush) color has changed to \a color.
119 119 */
120 120
121 121 /*!
122 122 \fn void QAreaSeries::borderColorChanged(QColor color)
123 123 \brief Signal is emitted when the line (pen) color has changed to \a color.
124 124 */
125 125 /*!
126 126 \qmlsignal AreaSeries::onBorderColorChanged(color color)
127 127 Signal is emitted when the line (pen) color has changed to \a color.
128 128 */
129 129
130 130 /*!
131 131 \fn void QAreaSeries::clicked(const QPointF& point)
132 132 \brief Signal is emitted when user clicks the \a point on area chart.
133 133 */
134 134 /*!
135 135 \qmlsignal AreaSeries::onClicked(QPointF point)
136 136 Signal is emitted when user clicks the \a point on area chart.
137 137 */
138 138
139 139 /*!
140 140 \fn void QAreaSeries::selected()
141 141 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
142 142 implemented by the user of QAreaSeries API.
143 143 */
144 144 /*!
145 145 \qmlsignal AreaSeries::onSelected()
146 146 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
147 147 implemented by the user of AreaSeries API.
148 148 */
149 149
150 150 /*!
151 151 \fn void QAreaSeriesPrivate::updated()
152 152 \brief \internal
153 153 */
154 154
155 155 /*!
156 156 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
157 157 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
158 158 When series object is added to QChartView or QChart instance ownerships is transferred.
159 159 */
160 160 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
161 161 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
162 162 {
163 163 }
164 164
165 165 /*!
166 166 Constructs area series object without upper or lower series with \a parent object.
167 167 */
168 168 QAreaSeries::QAreaSeries(QObject *parent)
169 169 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
170 170 {
171 171 }
172 172
173 173 /*!
174 174 Destroys the object.
175 175 */
176 176 QAreaSeries::~QAreaSeries()
177 177 {
178 178 }
179 179
180 180 /*!
181 181 Returns QChartSeries::SeriesTypeArea.
182 182 */
183 183 QAbstractSeries::SeriesType QAreaSeries::type() const
184 184 {
185 185 return QAbstractSeries::SeriesTypeArea;
186 186 }
187 187
188 188 /*!
189 189 Sets the \a series that is to be used as the area chart upper series.
190 190 */
191 191 void QAreaSeries::setUpperSeries(QLineSeries* series)
192 192 {
193 193 Q_D(QAreaSeries);
194 194 d->m_upperSeries = series;
195 195 }
196 196
197 197 QLineSeries* QAreaSeries::upperSeries() const
198 198 {
199 199 Q_D(const QAreaSeries);
200 200 return d->m_upperSeries;
201 201 }
202 202
203 203 /*!
204 204 Sets the \a series that is to be used as the area chart lower series.
205 205 */
206 206 void QAreaSeries::setLowerSeries(QLineSeries* series)
207 207 {
208 208 Q_D(QAreaSeries);
209 209 d->m_lowerSeries = series;
210 210 }
211 211
212 212 QLineSeries* QAreaSeries::lowerSeries() const
213 213 {
214 214 Q_D(const QAreaSeries);
215 215 return d->m_lowerSeries;
216 216 }
217 217
218 218 /*!
219 219 Sets \a pen used for drawing area outline.
220 220 */
221 221 void QAreaSeries::setPen(const QPen &pen)
222 222 {
223 223 Q_D(QAreaSeries);
224 224 if (d->m_pen != pen) {
225 225 d->m_pen = pen;
226 226 emit d->updated();
227 227 }
228 228 }
229 229
230 230 QPen QAreaSeries::pen() const
231 231 {
232 232 Q_D(const QAreaSeries);
233 233 return d->m_pen;
234 234 }
235 235
236 236 /*!
237 237 Sets \a brush used for filling the area.
238 238 */
239 239 void QAreaSeries::setBrush(const QBrush &brush)
240 240 {
241 241 Q_D(QAreaSeries);
242 242 if (d->m_brush != brush) {
243 243 d->m_brush = brush;
244 244 emit d->updated();
245 245 }
246 246 }
247 247
248 248 QBrush QAreaSeries::brush() const
249 249 {
250 250 Q_D(const QAreaSeries);
251 251 return d->m_brush;
252 252 }
253 253
254 254 void QAreaSeries::setColor(const QColor &color)
255 255 {
256 256 QBrush b = brush();
257 257 if (b.color() != color) {
258 258 b.setColor(color);
259 259 setBrush(b);
260 260 emit colorChanged(color);
261 261 }
262 262 }
263 263
264 264 QColor QAreaSeries::color() const
265 265 {
266 266 return brush().color();
267 267 }
268 268
269 269 void QAreaSeries::setBorderColor(const QColor &color)
270 270 {
271 271 QPen p = pen();
272 272 if (p.color() != color) {
273 273 p.setColor(color);
274 274 setPen(p);
275 275 emit borderColorChanged(color);
276 276 }
277 277 }
278 278
279 279 QColor QAreaSeries::borderColor() const
280 280 {
281 281 return pen().color();
282 282 }
283 283
284 284 /*!
285 285 Sets if data points are \a visible and should be drawn on line.
286 286 */
287 287 void QAreaSeries::setPointsVisible(bool visible)
288 288 {
289 289 Q_D(QAreaSeries);
290 290 if (d->m_pointsVisible != visible) {
291 291 d->m_pointsVisible = visible;
292 292 emit d->updated();
293 293 }
294 294 }
295 295
296 296 /*!
297 297 Returns if the points are drawn for this series.
298 298 \sa setPointsVisible()
299 299 */
300 300 bool QAreaSeries::pointsVisible() const
301 301 {
302 302 Q_D(const QAreaSeries);
303 303 return d->m_pointsVisible;
304 304 }
305 305
306 306 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
307 307
308 308 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
309 309 QAbstractSeriesPrivate(q),
310 310 m_upperSeries(upperSeries),
311 311 m_lowerSeries(lowerSeries),
312 312 m_pointsVisible(false)
313 313 {
314 314 }
315 315
316 316 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
317 317 {
318 318 Q_Q(QAreaSeries);
319 319
320 320 qreal minX(domain.minX());
321 321 qreal minY(domain.minY());
322 322 qreal maxX(domain.maxX());
323 323 qreal maxY(domain.maxY());
324 324 int tickXCount(domain.tickXCount());
325 325 int tickYCount(domain.tickYCount());
326 326
327 327 QLineSeries* upperSeries = q->upperSeries();
328 328 QLineSeries* lowerSeries = q->lowerSeries();
329 329
330 330 const QList<QPointF>& points = upperSeries->points();
331 331
332 332 for (int i = 0; i < points.count(); i++)
333 333 {
334 334 qreal x = points[i].x();
335 335 qreal y = points[i].y();
336 336 minX = qMin(minX, x);
337 337 minY = qMin(minY, y);
338 338 maxX = qMax(maxX, x);
339 339 maxY = qMax(maxY, y);
340 340 }
341 341 if(lowerSeries) {
342 342
343 343 const QList<QPointF>& points = lowerSeries->points();
344 344
345 345 for (int i = 0; i < points.count(); i++)
346 346 {
347 347 qreal x = points[i].x();
348 348 qreal y = points[i].y();
349 349 minX = qMin(minX, x);
350 350 minY = qMin(minY, y);
351 351 maxX = qMax(maxX, x);
352 352 maxY = qMax(maxY, y);
353 353 }}
354 354
355 355 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
356 356 }
357 357
358 358 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
359 359 {
360 360 Q_Q(QAreaSeries);
361 361
362 362 AreaChartItem* area = new AreaChartItem(q,presenter);
363 363 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
364 364 area->upperLineItem()->setAnimator(presenter->animator());
365 365 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
366 366 if(q->lowerSeries()) {
367 367 area->lowerLineItem()->setAnimator(presenter->animator());
368 368 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
369 369 }
370 370 }
371 371 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
372 372 return area;
373 373 }
374 374
375 375 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
376 376 {
377 377 Q_Q(QAreaSeries);
378 378 QList<LegendMarker*> list;
379 379 return list << new AreaLegendMarker(q,legend);
380 380 }
381 381
382 382
383 void QAreaSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
383 void QAreaSeriesPrivate::initializeAxis(QAbstractAxis* axis)
384 384 {
385 385 Q_UNUSED(axis);
386 386 }
387 387
388 void QAreaSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
389 {
390 Q_UNUSED(axis);
391 }
392
393 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisXType() const
394 {
395 return QAbstractAxis::AxisTypeValues;
396 }
397
398 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisYType() const
388 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
399 389 {
390 Q_UNUSED(orientation);
400 391 return QAbstractAxis::AxisTypeValues;
401 392 }
402 393
403 394 #include "moc_qareaseries.cpp"
404 395 #include "moc_qareaseries_p.cpp"
405 396
406 397 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,69 +1,67
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QAREASERIES_P_H
31 31 #define QAREASERIES_P_H
32 32
33 33 #include "qabstractseries_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QAreaSeries;
38 38
39 39 class QAreaSeriesPrivate: public QAbstractSeriesPrivate
40 40 {
41 41 Q_OBJECT
42 42
43 43 public:
44 44 QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q);
45 45
46 46 void scaleDomain(Domain& domain);
47 47 Chart* createGraphics(ChartPresenter* presenter);
48 48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
49 void initializeAxisX(QAbstractAxis* axis);
50 void initializeAxisY(QAbstractAxis* axis);
51 QAbstractAxis::AxisType defaultAxisXType() const;
52 QAbstractAxis::AxisType defaultAxisYType() const;
49 void initializeAxis(QAbstractAxis* axis);
50 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
53 51
54 52 Q_SIGNALS:
55 53 void updated();
56 54
57 55 protected:
58 56 QBrush m_brush;
59 57 QPen m_pen;
60 58 QLineSeries* m_upperSeries;
61 59 QLineSeries* m_lowerSeries;
62 60 bool m_pointsVisible;
63 61 private:
64 62 Q_DECLARE_PUBLIC(QAreaSeries);
65 63 };
66 64
67 65 QTCOMMERCIALCHART_END_NAMESPACE
68 66
69 67 #endif
@@ -1,628 +1,634
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qabstractaxis.h"
22 22 #include "qabstractaxis_p.h"
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /*!
27 27 \class QAbstractAxis
28 28 \brief The QAbstractAxis class is used for manipulating chart's axis.
29 29 \mainclass
30 30
31 31 There is only one x Axis visible at the time, however there can be multiple y axes.
32 32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 34 */
35 35
36 36 /*!
37 37 \qmlclass AbstractAxis QAbstractAxis
38 38 \brief The Axis element is used for manipulating chart's axes
39 39
40 40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
41 41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
42 42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 43
44 44 To access Axes you can use ChartView API. For example:
45 45 \code
46 46 ChartView {
47 47 axisX.min: 0
48 48 axisX.max: 3
49 49 axisX.ticksCount: 4
50 50 axisY.min: 0
51 51 axisY.max: 4
52 52 // Add a few series...
53 53 }
54 54 \endcode
55 55 */
56 56
57 57 /*!
58 58 \enum QAbstractAxis::AxisType
59 59
60 60 The type of the series object.
61 61
62 62 \value AxisTypeNoAxis
63 63 \value AxisTypeValues
64 64 \value AxisTypeCategories
65 65 */
66 66
67 67 /*!
68 68 *\fn void QAbstractAxis::type() const
69 69 Returns the type of the axis
70 70 */
71 71
72 72 /*!
73 73 \property QAbstractAxis::arrowVisible
74 74 The visibility of the axis arrow
75 75 */
76 76 /*!
77 77 \qmlproperty bool AbstractAxis::arrrowVisible
78 78 The visibility of the axis arrow
79 79 */
80 80
81 81 /*!
82 82 \property QAbstractAxis::labelsVisible
83 83 Defines if axis labels are visible.
84 84 */
85 85 /*!
86 86 \qmlproperty bool AbstractAxis::labelsVisible
87 87 Defines if axis labels are visible.
88 88 */
89 89
90 90 /*!
91 91 \property QAbstractAxis::visible
92 92 The visibility of the axis.
93 93 */
94 94 /*!
95 95 \qmlproperty bool AbstractAxis::visible
96 96 The visibility of the axis.
97 97 */
98 98
99 99 /*!
100 100 \property QAbstractAxis::gridVisible
101 101 The visibility of the grid lines.
102 102 */
103 103 /*!
104 104 \qmlproperty bool AbstractAxis::gridVisible
105 105 The visibility of the grid lines.
106 106 */
107 107
108 108 /*!
109 109 \property QAbstractAxis::color
110 110 The color of the axis and ticks.
111 111 */
112 112 /*!
113 113 \qmlproperty color AbstractAxis::color
114 114 The color of the axis and ticks.
115 115 */
116 116
117 117 /*!
118 118 \property QAbstractAxis::labelsFont
119 119 The font of the axis labels.
120 120 */
121 121
122 122 /*!
123 123 \qmlproperty Font AbstractAxis::labelsFont
124 124 The font of the axis labels.
125 125
126 126 See the \l {Font} {QML Font Element} for detailed documentation.
127 127 */
128 128
129 129 /*!
130 130 \property QAbstractAxis::labelsColor
131 131 The color of the axis labels.
132 132 */
133 133 /*!
134 134 \qmlproperty color AbstractAxis::labelsColor
135 135 The color of the axis labels.
136 136 */
137 137
138 138 /*!
139 139 \property QAbstractAxis::labelsAngle
140 140 The angle of the axis labels in degrees.
141 141 */
142 142 /*!
143 143 \qmlproperty int AbstractAxis::labelsAngle
144 144 The angle of the axis labels in degrees.
145 145 */
146 146
147 147 /*!
148 148 \property QAbstractAxis::shadesVisible
149 149 The visibility of the axis shades.
150 150 */
151 151 /*!
152 152 \qmlproperty bool AbstractAxis::shadesVisible
153 153 The visibility of the axis shades.
154 154 */
155 155
156 156 /*!
157 157 \property QAbstractAxis::shadesColor
158 158 The fill (brush) color of the axis shades.
159 159 */
160 160 /*!
161 161 \qmlproperty color AbstractAxis::shadesColor
162 162 The fill (brush) color of the axis shades.
163 163 */
164 164
165 165 /*!
166 166 \property QAbstractAxis::shadesBorderColor
167 167 The border (pen) color of the axis shades.
168 168 */
169 169 /*!
170 170 \qmlproperty color AbstractAxis::shadesBorderColor
171 171 The border (pen) color of the axis shades.
172 172 */
173 173
174 174 /*!
175 175 \fn void QAbstractAxis::visibleChanged(bool visible)
176 176 Visiblity of the axis has changed to \a visible.
177 177 */
178 178 /*!
179 179 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
180 180 Visiblity of the axis has changed to \a visible.
181 181 */
182 182
183 183 /*!
184 184 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
185 185 Visiblity of the axis arrow has changed to \a visible.
186 186 */
187 187 /*!
188 188 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
189 189 Visiblity of the axis arrow has changed to \a visible.
190 190 */
191 191
192 192 /*!
193 193 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
194 194 Visiblity of the labels of the axis has changed to \a visible.
195 195 */
196 196 /*!
197 197 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
198 198 Visiblity of the labels of the axis has changed to \a visible.
199 199 */
200 200
201 201 /*!
202 202 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
203 203 Visiblity of the grid lines of the axis has changed to \a visible.
204 204 */
205 205 /*!
206 206 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
207 207 Visiblity of the grid lines of the axis has changed to \a visible.
208 208 */
209 209
210 210 /*!
211 211 \fn void QAbstractAxis::colorChanged(QColor color)
212 212 Emitted if the \a color of the axis is changed.
213 213 */
214 214 /*!
215 215 \qmlsignal AbstractAxis::onColorChanged(QColor color)
216 216 Emitted if the \a color of the axis is changed.
217 217 */
218 218
219 219 /*!
220 220 \fn void QAbstractAxis::labelsColorChanged(QColor color)
221 221 Emitted if the \a color of the axis labels is changed.
222 222 */
223 223 /*!
224 224 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
225 225 Emitted if the \a color of the axis labels is changed.
226 226 */
227 227
228 228 /*!
229 229 \fn void QAbstractAxis::shadesVisibleChanged(bool)
230 230 Emitted if the visibility of the axis shades is changed to \a visible.
231 231 */
232 232 /*!
233 233 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
234 234 Emitted if the visibility of the axis shades is changed to \a visible.
235 235 */
236 236
237 237 /*!
238 238 \fn void QAbstractAxis::shadesColorChanged(QColor color)
239 239 Emitted if the \a color of the axis shades is changed.
240 240 */
241 241 /*!
242 242 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
243 243 Emitted if the \a color of the axis shades is changed.
244 244 */
245 245
246 246 /*!
247 247 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
248 248 Emitted if the border \a color of the axis shades is changed.
249 249 */
250 250 /*!
251 251 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
252 252 Emitted if the border \a color of the axis shades is changed.
253 253 */
254 254
255 255 /*!
256 256 \internal
257 257 Constructs new axis object which is a child of \a parent. Ownership is taken by
258 258 QChart when axis added.
259 259 */
260 260
261 261 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
262 262 QObject(parent),
263 263 d_ptr(&d)
264 264 {
265 265 }
266 266
267 267 /*!
268 268 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
269 269 */
270 270
271 271 QAbstractAxis::~QAbstractAxis()
272 272 {
273 273 }
274 274
275 275 /*!
276 276 Sets \a pen used to draw axis line and ticks.
277 277 */
278 278 void QAbstractAxis::setAxisPen(const QPen &pen)
279 279 {
280 280 if (d_ptr->m_axisPen!=pen) {
281 281 d_ptr->m_axisPen = pen;
282 282 emit d_ptr->updated();
283 283 }
284 284 }
285 285
286 286 /*!
287 287 Returns pen used to draw axis and ticks.
288 288 */
289 289 QPen QAbstractAxis::axisPen() const
290 290 {
291 291 return d_ptr->m_axisPen;
292 292 }
293 293
294 294 void QAbstractAxis::setAxisPenColor(QColor color)
295 295 {
296 296 QPen p = d_ptr->m_axisPen;
297 297 if (p.color() != color) {
298 298 p.setColor(color);
299 299 setAxisPen(p);
300 300 emit colorChanged(color);
301 301 }
302 302 }
303 303
304 304 QColor QAbstractAxis::axisPenColor() const
305 305 {
306 306 return d_ptr->m_axisPen.color();
307 307 }
308 308
309 309 /*!
310 310 Sets if axis and ticks are \a visible.
311 311 */
312 312 void QAbstractAxis::setArrowVisible(bool visible)
313 313 {
314 314 if (d_ptr->m_arrowVisible != visible) {
315 315 d_ptr->m_arrowVisible = visible;
316 316 emit d_ptr->updated();
317 317 emit arrowVisibleChanged(visible);
318 318 }
319 319 }
320 320
321 321 bool QAbstractAxis::isArrowVisible() const
322 322 {
323 323 return d_ptr->m_arrowVisible;
324 324 }
325 325
326 326 void QAbstractAxis::setGridLineVisible(bool visible)
327 327 {
328 328 if (d_ptr->m_gridLineVisible != visible) {
329 329 d_ptr->m_gridLineVisible = visible;
330 330 emit d_ptr->updated();
331 331 emit gridVisibleChanged(visible);
332 332 }
333 333 }
334 334
335 335 bool QAbstractAxis::isGridLineVisible() const
336 336 {
337 337 return d_ptr->m_gridLineVisible;
338 338 }
339 339
340 340 /*!
341 341 Sets \a pen used to draw grid line.
342 342 */
343 343 void QAbstractAxis::setGridLinePen(const QPen &pen)
344 344 {
345 345 if (d_ptr->m_gridLinePen != pen) {
346 346 d_ptr->m_gridLinePen = pen;
347 347 emit d_ptr->updated();
348 348 }
349 349 }
350 350
351 351 /*!
352 352 Returns pen used to draw grid.
353 353 */
354 354 QPen QAbstractAxis::gridLinePen() const
355 355 {
356 356 return d_ptr->m_gridLinePen;
357 357 }
358 358
359 359 void QAbstractAxis::setLabelsVisible(bool visible)
360 360 {
361 361 if (d_ptr->m_labelsVisible != visible) {
362 362 d_ptr->m_labelsVisible = visible;
363 363 emit d_ptr->updated();
364 364 emit labelsVisibleChanged(visible);
365 365 }
366 366 }
367 367
368 368 bool QAbstractAxis::labelsVisible() const
369 369 {
370 370 return d_ptr->m_labelsVisible;
371 371 }
372 372
373 373 /*!
374 374 Sets \a pen used to draw labels.
375 375 */
376 376 void QAbstractAxis::setLabelsPen(const QPen &pen)
377 377 {
378 378 if (d_ptr->m_labelsPen != pen) {
379 379 d_ptr->m_labelsPen = pen;
380 380 emit d_ptr->updated();
381 381 }
382 382 }
383 383
384 384 /*!
385 385 Returns the pen used to labels.
386 386 */
387 387 QPen QAbstractAxis::labelsPen() const
388 388 {
389 389 return d_ptr->m_labelsPen;
390 390 }
391 391
392 392 /*!
393 393 Sets \a brush used to draw labels.
394 394 */
395 395 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
396 396 {
397 397 if (d_ptr->m_labelsBrush != brush) {
398 398 d_ptr->m_labelsBrush = brush;
399 399 emit d_ptr->updated();
400 400 }
401 401 }
402 402
403 403 /*!
404 404 Returns brush used to draw labels.
405 405 */
406 406 QBrush QAbstractAxis::labelsBrush() const
407 407 {
408 408 return d_ptr->m_labelsBrush;
409 409 }
410 410
411 411 /*!
412 412 Sets \a font used to draw labels.
413 413 */
414 414 void QAbstractAxis::setLabelsFont(const QFont &font)
415 415 {
416 416 if (d_ptr->m_labelsFont != font) {
417 417 d_ptr->m_labelsFont = font;
418 418 emit d_ptr->updated();
419 419 }
420 420 }
421 421
422 422 /*!
423 423 Returns font used to draw labels.
424 424 */
425 425 QFont QAbstractAxis::labelsFont() const
426 426 {
427 427 return d_ptr->m_labelsFont;
428 428 }
429 429
430 430 void QAbstractAxis::setLabelsAngle(int angle)
431 431 {
432 432 if (d_ptr->m_labelsAngle != angle) {
433 433 d_ptr->m_labelsAngle = angle;
434 434 emit d_ptr->updated();
435 435 }
436 436 }
437 437
438 438 int QAbstractAxis::labelsAngle() const
439 439 {
440 440 return d_ptr->m_labelsAngle;
441 441 }
442 442
443 443 void QAbstractAxis::setLabelsColor(QColor color)
444 444 {
445 445 QBrush b = d_ptr->m_labelsBrush;
446 446 if (b.color() != color) {
447 447 b.setColor(color);
448 448 setLabelsBrush(b);
449 449 emit labelsColorChanged(color);
450 450 }
451 451 }
452 452
453 453 QColor QAbstractAxis::labelsColor() const
454 454 {
455 455 return d_ptr->m_labelsBrush.color();
456 456 }
457 457
458 458 void QAbstractAxis::setShadesVisible(bool visible)
459 459 {
460 460 if (d_ptr->m_shadesVisible != visible) {
461 461 d_ptr->m_shadesVisible = visible;
462 462 emit d_ptr->updated();
463 463 emit shadesVisibleChanged(visible);
464 464 }
465 465 }
466 466
467 467 bool QAbstractAxis::shadesVisible() const
468 468 {
469 469 return d_ptr->m_shadesVisible;
470 470 }
471 471
472 472 /*!
473 473 Sets \a pen used to draw shades.
474 474 */
475 475 void QAbstractAxis::setShadesPen(const QPen &pen)
476 476 {
477 477 if (d_ptr->m_shadesPen != pen) {
478 478 d_ptr->m_shadesPen = pen;
479 479 emit d_ptr->updated();
480 480 }
481 481 }
482 482
483 483 /*!
484 484 Returns pen used to draw shades.
485 485 */
486 486 QPen QAbstractAxis::shadesPen() const
487 487 {
488 488 return d_ptr->m_shadesPen;
489 489 }
490 490
491 491 /*!
492 492 Sets \a brush used to draw shades.
493 493 */
494 494 void QAbstractAxis::setShadesBrush(const QBrush &brush)
495 495 {
496 496 if (d_ptr->m_shadesBrush != brush) {
497 497 d_ptr->m_shadesBrush = brush;
498 498 emit d_ptr->updated();
499 499 emit shadesColorChanged(brush.color());
500 500 }
501 501 }
502 502
503 503 /*!
504 504 Returns brush used to draw shades.
505 505 */
506 506 QBrush QAbstractAxis::shadesBrush() const
507 507 {
508 508 return d_ptr->m_shadesBrush;
509 509 }
510 510
511 511 void QAbstractAxis::setShadesColor(QColor color)
512 512 {
513 513 QBrush b = d_ptr->m_shadesBrush;
514 514 b.setColor(color);
515 515 setShadesBrush(b);
516 516 }
517 517
518 518 QColor QAbstractAxis::shadesColor() const
519 519 {
520 520 return d_ptr->m_shadesBrush.color();
521 521 }
522 522
523 523 void QAbstractAxis::setShadesBorderColor(QColor color)
524 524 {
525 525 QPen p = d_ptr->m_shadesPen;
526 526 p.setColor(color);
527 527 setShadesPen(p);
528 528 }
529 529
530 530 QColor QAbstractAxis::shadesBorderColor() const
531 531 {
532 532 return d_ptr->m_shadesPen.color();
533 533 }
534 534
535 535
536 536 bool QAbstractAxis::isVisible() const
537 537 {
538 538 return d_ptr->m_visible;
539 539 }
540 540
541 541 /*!
542 542 Sets axis, shades, labels and grid lines to be visible.
543 543 */
544 544 void QAbstractAxis::setVisible(bool visible)
545 545 {
546 546 if(d_ptr->m_visible!=visible){
547 547 d_ptr->m_visible=visible;
548 548 emit visibleChanged(visible);
549 549 emit d_ptr->updated();
550 550 }
551 551 }
552 552
553 553
554 554 /*!
555 555 Sets axis, shades, labels and grid lines to be visible.
556 556 */
557 557 void QAbstractAxis::show()
558 558 {
559 559 setVisible(true);
560 560 }
561 561
562 562 /*!
563 563 Sets axis, shades, labels and grid lines to not be visible.
564 564 */
565 565 void QAbstractAxis::hide()
566 566 {
567 567 setVisible(false);
568 568 }
569 569
570 570 /*!
571 571 Sets the minimum value shown on the axis.
572 572 Depending on the actual axis type the \a min paramter is converted to appropriate type.
573 573 If the conversion is impossible then the function call does nothing
574 574 */
575 575 void QAbstractAxis::setMin(const QVariant &min)
576 576 {
577 577 d_ptr->setMin(min);
578 578 }
579 579
580 580 /*!
581 581 Sets the maximum value shown on the axis.
582 582 Depending on the actual axis type the \a max paramter is converted to appropriate type.
583 583 If the conversion is impossible then the function call does nothing
584 584 */
585 585 void QAbstractAxis::setMax(const QVariant &max)
586 586 {
587 587 d_ptr->setMax(max);
588 588 }
589 589
590 590 /*!
591 591 Sets the range shown on the axis.
592 592 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
593 593 If the conversion is impossible then the function call does nothing.
594 594 */
595 595 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
596 596 {
597 597 d_ptr->setRange(min,max);
598 598 }
599 599
600
601 Qt::Orientation QAbstractAxis::orientation()
602 {
603 return d_ptr->m_orientation;
604 }
605
600 606 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
601 607
602 608 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
603 609 q_ptr(q),
604 610 m_visible(false),
605 611 m_arrowVisible(true),
606 612 m_gridLineVisible(true),
607 613 m_labelsVisible(true),
608 614 m_labelsAngle(0),
609 615 m_shadesVisible(false),
610 616 m_shadesBrush(Qt::SolidPattern),
611 617 m_shadesOpacity(1.0),
612 618 m_orientation(Qt::Orientation(0)),
613 619 m_min(0),
614 620 m_max(0),
615 621 m_ticksCount(5)
616 622 {
617 623
618 624 }
619 625
620 626 QAbstractAxisPrivate::~QAbstractAxisPrivate()
621 627 {
622 628
623 629 }
624 630
625 631 #include "moc_qabstractaxis.cpp"
626 632 #include "moc_qabstractaxis_p.cpp"
627 633
628 634 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,139 +1,141
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QABSTRACTAXIS_H
22 22 #define QABSTRACTAXIS_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QPen>
26 26 #include <QFont>
27 27 #include <QVariant>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QAbstractAxisPrivate;
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 34 {
35 35 Q_OBJECT
36 36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 37 Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged)
38 38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
39 39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
40 40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
41 41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
42 42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
43 43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
44 44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
45 45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
46 46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
47 47
48 48 public:
49 49
50 50 enum AxisType {
51 51 AxisTypeNoAxis = 0x0,
52 52 AxisTypeValues = 0x1,
53 53 AxisTypeCategories = 0x2
54 54 };
55 55
56 56 Q_DECLARE_FLAGS(AxisTypes, AxisType)
57 57
58 58 protected:
59 59 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
60 60
61 61 public:
62 62 ~QAbstractAxis();
63 63
64 64 virtual AxisType type() const = 0;
65 65
66 66 //visibilty hadnling
67 67 bool isVisible() const;
68 68 void setVisible(bool visible = true);
69 69
70 70
71 71 //axis handling
72 72 bool isArrowVisible() const;
73 73 void setArrowVisible(bool visible = true);
74 74 void setAxisPen(const QPen &pen);
75 75 QPen axisPen() const;
76 76 void setAxisPenColor(QColor color);
77 77 QColor axisPenColor() const;
78 78
79 79 //grid handling
80 80 bool isGridLineVisible() const;
81 81 void setGridLineVisible(bool visible = true);
82 82 void setGridLinePen(const QPen &pen);
83 83 QPen gridLinePen() const;
84 84
85 85 //labels handling
86 86 bool labelsVisible() const;
87 87 void setLabelsVisible(bool visible = true);
88 88 void setLabelsPen(const QPen &pen);
89 89 QPen labelsPen() const;
90 90 void setLabelsBrush(const QBrush &brush);
91 91 QBrush labelsBrush() const;
92 92 void setLabelsFont(const QFont &font);
93 93 QFont labelsFont() const;
94 94 void setLabelsAngle(int angle);
95 95 int labelsAngle() const;
96 96 void setLabelsColor(QColor color);
97 97 QColor labelsColor() const;
98 98
99 99 //shades handling
100 100 bool shadesVisible() const;
101 101 void setShadesVisible(bool visible = true);
102 102 void setShadesPen(const QPen &pen);
103 103 QPen shadesPen() const;
104 104 void setShadesBrush(const QBrush &brush);
105 105 QBrush shadesBrush() const;
106 106 void setShadesColor(QColor color);
107 107 QColor shadesColor() const;
108 108 void setShadesBorderColor(QColor color);
109 109 QColor shadesBorderColor() const;
110 110
111 Qt::Orientation orientation();
112
111 113 //range handling
112 114 void setMin(const QVariant &min);
113 115 void setMax(const QVariant &max);
114 116 void setRange(const QVariant &min, const QVariant &max);
115 117
116 118 void show();
117 119 void hide();
118 120
119 121 Q_SIGNALS:
120 122 void visibleChanged(bool visible);
121 123 void arrowVisibleChanged(bool visible);
122 124 void labelsVisibleChanged(bool visible);
123 125 void gridVisibleChanged(bool visible);
124 126 void colorChanged(QColor color);
125 127 void labelsColorChanged(QColor color);
126 128 void shadesVisibleChanged(bool visible);
127 129 void shadesColorChanged(QColor color);
128 130 void shadesBorderColorChanged(QColor color);
129 131
130 132 protected:
131 133 QScopedPointer<QAbstractAxisPrivate> d_ptr;
132 134 Q_DISABLE_COPY(QAbstractAxis);
133 135 friend class ChartDataSet;
134 136 friend class ChartAxis;
135 137 friend class ChartPresenter;
136 138 };
137 139
138 140 QTCOMMERCIALCHART_END_NAMESPACE
139 141 #endif
@@ -1,96 +1,96
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QABSTRACTAXIS_P_H
31 31 #define QABSTRACTAXIS_P_H
32 32
33 33 #include "qabstractaxis.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class ChartPresenter;
38 38 class ChartAxis;
39 39 class Domain;
40 40
41 41 class QAbstractAxisPrivate : public QObject
42 42 {
43 43 Q_OBJECT
44 44 public:
45 45 QAbstractAxisPrivate(QAbstractAxis *q);
46 46 ~QAbstractAxisPrivate();
47 47
48 48 Q_SIGNALS:
49 49 void updated();
50 50
51 51 public:
52 52 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
53 53 virtual void emitRange() = 0;
54 virtual void initialize(Domain* domain) = 0;
54 virtual void intializeDomain(Domain* domain) = 0;
55 55
56 56 protected:
57 57 virtual void setMin(const QVariant &min) = 0;
58 58 virtual void setMax(const QVariant &max) = 0;
59 59 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
60 60 virtual int ticksCount() const = 0;
61 61
62 62 public:
63 63 QAbstractAxis *q_ptr;
64 64 bool m_visible;
65 65
66 66 bool m_arrowVisible;
67 67 QPen m_axisPen;
68 68 QBrush m_axisBrush;
69 69
70 70 bool m_gridLineVisible;
71 71 QPen m_gridLinePen;
72 72
73 73 bool m_labelsVisible;
74 74 QPen m_labelsPen;
75 75 QBrush m_labelsBrush;
76 76 QFont m_labelsFont;
77 77 int m_labelsAngle;
78 78
79 79 bool m_shadesVisible;
80 80 QPen m_shadesPen;
81 81 QBrush m_shadesBrush;
82 82 qreal m_shadesOpacity;
83 83
84 84 Qt::Orientation m_orientation;
85 85
86 86 // range
87 87 qreal m_min;
88 88 qreal m_max;
89 89 int m_ticksCount;
90 90
91 91 friend class QAbstractAxis;
92 92 };
93 93
94 94 QTCOMMERCIALCHART_END_NAMESPACE
95 95
96 96 #endif
@@ -1,442 +1,442
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarcategoriesaxis.h"
22 22 #include "qbarcategoriesaxis_p.h"
23 23 #include "chartcategoriesaxisx_p.h"
24 24 #include "chartcategoriesaxisy_p.h"
25 25 #include "domain_p.h"
26 26 #include <qmath.h>
27 27 #include <QDebug>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30 /*!
31 31 \class QBarCategoriesAxis
32 32 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
33 33 \mainclass
34 34
35 35 BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades.
36 36 Categories are drawn between ticks. Note that you can use this also with lineseries too.
37 37 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
38 38 */
39 39
40 40 /*!
41 41 \qmlclass BarCategoriesAxis QBarCategoriesAxis
42 42 \brief The Axis element is used for manipulating chart's axes.
43 43
44 44 Axis can be setup to show axis line with tick marks, grid lines and shades.
45 45 Categories are drawn between ticks. Note that you can use this also with lineseries too.
46 46
47 47 To access BarCategoriesAxis you can use ChartView API. For example:
48 48 \code
49 49 ChartView {
50 50 BarCategoriesAxis {
51 51 id: categoryAxis
52 52 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
53 53 }
54 54 // Add a few series...
55 55 }
56 56 \endcode
57 57 */
58 58
59 59 /*!
60 60 \property QBarCategoriesAxis::categories
61 61 Defines the categories of axis
62 62 */
63 63 /*!
64 64 \qmlproperty QStringList BarCategoriesAxis::categories
65 65 Defines the categories of axis
66 66 */
67 67
68 68 /*!
69 69 \property QBarCategoriesAxis::min
70 70 Defines the minimum value on the axis.
71 71 */
72 72 /*!
73 73 \qmlproperty QString BarCategoriesAxis::min
74 74 Defines the minimum value on the axis.
75 75 */
76 76
77 77 /*!
78 78 \property QBarCategoriesAxis::max
79 79 Defines the maximum value on the axis.
80 80 */
81 81 /*!
82 82 \qmlproperty QString BarCategoriesAxis::max
83 83 Defines the maximum value on the axis.
84 84 */
85 85
86 86
87 87 /*!
88 88 \fn void QBarCategoriesAxis::categoriesChanged()
89 89 Axis emits signal when the categories of the axis has changed.
90 90 */
91 91 /*!
92 92 \fn void QBarCategoriesAxis::minChanged(const QString &min)
93 93 Axis emits signal when \a min of axis has changed.
94 94 */
95 95 /*!
96 96 \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min)
97 97 Axis emits signal when \a min of axis has changed.
98 98 */
99 99
100 100 /*!
101 101 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
102 102 Axis emits signal when \a max of axis has changed.
103 103 */
104 104 /*!
105 105 \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max)
106 106 Axis emits signal when \a max of axis has changed.
107 107 */
108 108
109 109 /*!
110 110 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
111 111 Axis emits signal when \a min or \a max of axis has changed.
112 112 */
113 113
114 114 /*!
115 115 Constructs an axis object which is a child of \a parent.
116 116 */
117 117 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
118 118 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
119 119 {
120 120 }
121 121
122 122 /*!
123 123 Destroys the object
124 124 */
125 125 QBarCategoriesAxis::~QBarCategoriesAxis()
126 126 {
127 127 }
128 128
129 129 /*!
130 130 \internal
131 131 */
132 132 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
133 133 {
134 134
135 135 }
136 136
137 137 /*!
138 138 Appends \a categories to axis
139 139 */
140 140 void QBarCategoriesAxis::append(const QStringList &categories)
141 141 {
142 142 if(categories.isEmpty()) return;
143 143
144 144 Q_D(QBarCategoriesAxis);
145 145 if (d->m_categories.isEmpty()) {
146 146 d->m_categories.append(categories);
147 147 setRange(categories.first(),categories.last());
148 148 }else{
149 149 d->m_categories.append(categories);
150 150 }
151 151 emit d->updated();
152 152 emit categoriesChanged();
153 153 }
154 154
155 155 /*!
156 156 Appends \a category to axis
157 157 */
158 158 void QBarCategoriesAxis::append(const QString &category)
159 159 {
160 160 Q_D(QBarCategoriesAxis);
161 161 if (d->m_categories.isEmpty()) {
162 162 d->m_categories.append(category);
163 163 setRange(category,category);
164 164 }else{
165 165 d->m_categories.append(category);
166 166 }
167 167 emit d->updated();
168 168 emit categoriesChanged();
169 169 }
170 170
171 171 /*!
172 172 Removes \a category from axis
173 173 */
174 174 void QBarCategoriesAxis::remove(const QString &category)
175 175 {
176 176 Q_D(QBarCategoriesAxis);
177 177 if (d->m_categories.contains(category)) {
178 178 d->m_categories.removeAt(d->m_categories.indexOf(category));
179 179 setRange(d->m_categories.first(),d->m_categories.last());
180 180 emit d->updated();
181 181 emit categoriesChanged();
182 182 }
183 183 }
184 184
185 185 /*!
186 186 Inserts \a category to axis at \a index
187 187 */
188 188 void QBarCategoriesAxis::insert(int index, const QString &category)
189 189 {
190 190 Q_D(QBarCategoriesAxis);
191 191 if (d->m_categories.isEmpty()) {
192 192 d->m_categories.insert(index,category);
193 193 setRange(category,category);
194 194 }else{
195 195 d->m_categories.insert(index,category);
196 196 }
197 197 emit d->updated();
198 198 emit categoriesChanged();
199 199 }
200 200
201 201 /*!
202 202 Removes all categories.
203 203 */
204 204 void QBarCategoriesAxis::clear()
205 205 {
206 206 Q_D(QBarCategoriesAxis);
207 207 d->m_categories.clear();
208 208 setRange(QString::null,QString::null);
209 209 emit d->updated();
210 210 emit categoriesChanged();
211 211 }
212 212
213 213 void QBarCategoriesAxis::setCategories(const QStringList &categories)
214 214 {
215 215 Q_D(QBarCategoriesAxis);
216 216 if(d->m_categories!=categories){
217 217 d->m_categories = categories;
218 218 setRange(categories.first(),categories.last());
219 219 emit d->updated();
220 220 emit categoriesChanged();
221 221 }
222 222 }
223 223
224 224 QStringList QBarCategoriesAxis::categories()
225 225 {
226 226 Q_D(QBarCategoriesAxis);
227 227 return d->m_categories;
228 228 }
229 229
230 230 /*!
231 231 Returns number of categories.
232 232 */
233 233 int QBarCategoriesAxis::count() const
234 234 {
235 235 Q_D(const QBarCategoriesAxis);
236 236 return d->m_categories.count();
237 237 }
238 238
239 239 /*!
240 240 Returns category at \a index. Index must be valid.
241 241 */
242 242 QString QBarCategoriesAxis::at(int index) const
243 243 {
244 244 Q_D(const QBarCategoriesAxis);
245 245 return d->m_categories.at(index);
246 246 }
247 247
248 248 /*!
249 249 Sets minimum category to \a min.
250 250 */
251 251 void QBarCategoriesAxis::setMin(const QString& min)
252 252 {
253 253 Q_D(QBarCategoriesAxis);
254 254 setRange(min,d->m_maxCategory);
255 255 }
256 256
257 257 /*!
258 258 Returns minimum category.
259 259 */
260 260 QString QBarCategoriesAxis::min() const
261 261 {
262 262 Q_D(const QBarCategoriesAxis);
263 263 return d->m_minCategory;
264 264 }
265 265
266 266 /*!
267 267 Sets maximum category to \a max.
268 268 */
269 269 void QBarCategoriesAxis::setMax(const QString& max)
270 270 {
271 271 Q_D(QBarCategoriesAxis);
272 272 setRange(d->m_minCategory,max);
273 273 }
274 274
275 275 /*!
276 276 Returns maximum category
277 277 */
278 278 QString QBarCategoriesAxis::max() const
279 279 {
280 280 Q_D(const QBarCategoriesAxis);
281 281 return d->m_maxCategory;
282 282 }
283 283
284 284 /*!
285 285 Sets range from \a minCategory to \a maxCategory
286 286 */
287 287 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
288 288 {
289 289 Q_D(QBarCategoriesAxis);
290 290
291 291 int minIndex = d->m_categories.indexOf(minCategory);
292 292 if (minIndex == -1) {
293 293 return;
294 294 }
295 295 int maxIndex = d->m_categories.indexOf(maxCategory);
296 296 if (maxIndex == -1) {
297 297 return;
298 298 }
299 299
300 300 if (maxIndex <= minIndex) {
301 301 // max must be greater than min
302 302 return;
303 303 }
304 304
305 305 bool changed = false;
306 306 if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) {
307 307 d->m_minCategory = minCategory;
308 308 d->m_min = minIndex;
309 309 emit minChanged(minCategory);
310 310 changed = true;
311 311 }
312 312
313 313 if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) {
314 314 d->m_max = maxIndex;
315 315 d->m_maxCategory = maxCategory;
316 316 emit maxChanged(maxCategory);
317 317 changed = true;
318 318 }
319 319
320 320 if (changed) {
321 321 d->emitRange();
322 322 }
323 323 }
324 324
325 325 /*!
326 326 Returns the type of the axis
327 327 */
328 328 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
329 329 {
330 330 return AxisTypeCategories;
331 331 }
332 332
333 333 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
334 334
335 335 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
336 336 QAbstractAxisPrivate(q)
337 337 {
338 338
339 339 }
340 340
341 341 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
342 342 {
343 343
344 344 }
345 345
346 346 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
347 347 {
348 348 setRange(min,m_maxCategory);
349 349 }
350 350
351 351 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
352 352 {
353 353 setRange(m_minCategory,max);
354 354 }
355 355
356 356 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
357 357 {
358 358 Q_Q(QBarCategoriesAxis);
359 359 QString value1 = min.toString();
360 360 QString value2 = max.toString();
361 361 q->setRange(value1,value2);
362 362 }
363 363
364 364 int QBarCategoriesAxisPrivate::ticksCount() const
365 365 {
366 366 return m_categories.count()+1;
367 367 }
368 368
369 369 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
370 370 {
371 371 // Q_Q(QBarCategoriesAxis);
372 372 m_min = min;
373 373 m_max = max;
374 374 m_ticksCount = count;
375 375 // TODO: causes crash in some situations. added to known issues
376 376 /*
377 377 int minIndex = qFloor(min);
378 378 int maxIndex = qFloor(max);
379 379
380 380 if (minIndex < 0) {
381 381 minIndex = 0;
382 382 }
383 383 if (maxIndex > m_categories.count()-1){
384 384 maxIndex = m_categories.count()-1;
385 385 if (maxIndex<0) {
386 386 maxIndex = 0;
387 387 }
388 388 }
389 389
390 390 bool changed = false;
391 391 if (m_minCategory != m_categories.at(minIndex)) {
392 392 m_minCategory = m_categories.at(minIndex);
393 393 emit q->minChanged(m_minCategory);
394 394 changed = true;
395 395 }
396 396
397 397 if (m_maxCategory != m_categories.at(maxIndex)) {
398 398 m_maxCategory = m_categories.at(maxIndex);
399 399 emit q->maxChanged(m_maxCategory);
400 400 changed = true;
401 401 }
402 402
403 403 if (changed) {
404 404 emit q->rangeChanged(m_minCategory, m_maxCategory);
405 405 }
406 406 */
407 407 }
408 408
409 409 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
410 410 {
411 411 Q_Q(QBarCategoriesAxis);
412 412 if(m_orientation == Qt::Vertical){
413 413 return new ChartCategoriesAxisY(q,presenter);
414 414 }else{
415 415 return new ChartCategoriesAxisX(q,presenter);
416 416 }
417 417 }
418 418
419 419 void QBarCategoriesAxisPrivate::emitRange()
420 420 {
421 421 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
422 422 }
423 423
424 void QBarCategoriesAxisPrivate::initialize(Domain* domain)
424 void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain)
425 425 {
426 426 Q_UNUSED(domain);
427 427 // TODO: this causes crash now. added to known issues.
428 428 /*
429 429 if (qFuzzyCompare(m_max, m_min)) {
430 430 if(m_orientation==Qt::Vertical){
431 431 handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount());
432 432 }else{
433 433 handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount());
434 434 }
435 435 }
436 436 */
437 437 }
438 438
439 439 #include "moc_qbarcategoriesaxis.cpp"
440 440 #include "moc_qbarcategoriesaxis_p.cpp"
441 441
442 442 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,77 +1,77
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QBARCATEGORIESAXIS_P_H
31 31 #define QBARCATEGORIESAXIS_P_H
32 32
33 33 #include "qbarcategoriesaxis.h"
34 34 #include "qabstractaxis_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class Domain;
39 39
40 40 class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate
41 41 {
42 42 Q_OBJECT
43 43
44 44 public:
45 45 QBarCategoriesAxisPrivate(QBarCategoriesAxis *q);
46 46 ~QBarCategoriesAxisPrivate();
47 47
48 48 public:
49 49 ChartAxis* createGraphics(ChartPresenter* presenter);
50 void initialize(Domain* domain);
50 void intializeDomain(Domain* domain);
51 51 void emitRange();
52 52
53 53 private:
54 54 //range handling
55 55 void setMin(const QVariant &min);
56 56 void setMax(const QVariant &max);
57 57 void setRange(const QVariant &min, const QVariant &max);
58 58 int ticksCount() const;
59 59
60 60 Q_SIGNALS:
61 61 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
62 62
63 63 public Q_SLOTS:
64 64 void handleAxisRangeChanged(qreal min, qreal max,int count);
65 65
66 66 private:
67 67 QStringList m_categories;
68 68 QString m_minCategory;
69 69 QString m_maxCategory;
70 70
71 71 private:
72 72 Q_DECLARE_PUBLIC(QBarCategoriesAxis)
73 73 };
74 74
75 75 QTCOMMERCIALCHART_END_NAMESPACE
76 76
77 77 #endif // QBARCATEGORIESAXIS_P_H
@@ -1,323 +1,326
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qvaluesaxis.h"
22 22 #include "qvaluesaxis_p.h"
23 23 #include "chartvaluesaxisx_p.h"
24 24 #include "chartvaluesaxisy_p.h"
25 25 #include "domain_p.h"
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 /*!
30 30 \class QValuesAxis
31 31 \brief The QValuesAxis class is used for manipulating chart's axis.
32 32 \mainclass
33 33
34 34 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
35 35 Values of axis are drawn to position of ticks
36 36 */
37 37
38 38 /*!
39 39 \qmlclass ValuesAxis QValuesAxis
40 40 \brief The ValuesAxis element is used for manipulating chart's axes
41 41
42 42 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
43 43 Values of axis are drawn to position of ticks
44 44
45 45 To access Axes you can use ChartView API. For example:
46 46 \code
47 47 ChartView {
48 48 ValuesAxis {
49 49 id: xAxis
50 50 min: 0
51 51 max: 10
52 52 }
53 53 // Add a few series...
54 54 }
55 55 \endcode
56 56 */
57 57
58 58 /*!
59 59 \property QValuesAxis::min
60 60 Defines the minimum value on the axis.
61 61 */
62 62 /*!
63 63 \qmlproperty real ValuesAxis::min
64 64 Defines the minimum value on the axis.
65 65 */
66 66
67 67 /*!
68 68 \property QValuesAxis::max
69 69 Defines the maximum value on the axis.
70 70 */
71 71 /*!
72 72 \qmlproperty real ValuesAxis::max
73 73 Defines the maximum value on the axis.
74 74 */
75 75
76 76 /*!
77 77 \fn void QValuesAxis::minChanged(qreal min)
78 78 Axis emits signal when \a min of axis has changed.
79 79 */
80 80 /*!
81 81 \qmlsignal ValuesAxis::onMinChanged(real min)
82 82 Axis emits signal when \a min of axis has changed.
83 83 */
84 84
85 85 /*!
86 86 \fn void QValuesAxis::maxChanged(qreal max)
87 87 Axis emits signal when \a max of axis has changed.
88 88 */
89 89 /*!
90 90 \qmlsignal ValuesAxis::onMaxChanged(real max)
91 91 Axis emits signal when \a max of axis has changed.
92 92 */
93 93
94 94 /*!
95 95 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
96 96 Axis emits signal when \a min or \a max of axis has changed.
97 97 */
98 98
99 99 /*!
100 100 \property QValuesAxis::ticksCount
101 101 The number of tick marks for the axis.
102 102 */
103 103
104 104 /*!
105 105 \qmlproperty int ValuesAxis::ticksCount
106 106 The number of tick marks for the axis.
107 107 */
108 108
109 109 /*!
110 110 \property QValuesAxis::niceNumbersEnabled
111 111 Whether the nice numbers algorithm is enabled or not for the axis.
112 112 */
113 113
114 114 /*!
115 115 \qmlproperty bool ValuesAxis::niceNumbersEnabled
116 116 Whether the nice numbers algorithm is enabled or not for the axis.
117 117 */
118 118
119 119 /*!
120 120 Constructs an axis object which is a child of \a parent.
121 121 */
122 122 QValuesAxis::QValuesAxis(QObject *parent) :
123 123 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
124 124 {
125 125
126 126 }
127 127
128 128 /*!
129 129 \internal
130 130 */
131 131 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
132 132 {
133 133
134 134 }
135 135
136 136 /*!
137 137 Destroys the object
138 138 */
139 139 QValuesAxis::~QValuesAxis()
140 140 {
141 141
142 142 }
143 143
144 144 void QValuesAxis::setMin(qreal min)
145 145 {
146 146 Q_D(QValuesAxis);
147 147 setRange(min,d->m_max);
148 148 }
149 149
150 150 qreal QValuesAxis::min() const
151 151 {
152 152 Q_D(const QValuesAxis);
153 153 return d->m_min;
154 154 }
155 155
156 156 void QValuesAxis::setMax(qreal max)
157 157 {
158 158 Q_D(QValuesAxis);
159 159 setRange(d->m_min,max);
160 160 }
161 161
162 162 qreal QValuesAxis::max() const
163 163 {
164 164 Q_D(const QValuesAxis);
165 165 return d->m_max;
166 166 }
167 167
168 168 /*!
169 169 Sets range from \a min to \a max on the axis.
170 170 */
171 171 void QValuesAxis::setRange(qreal min, qreal max)
172 172 {
173 173 Q_D(QValuesAxis);
174
175 174 bool changed = false;
176 175 if (!qFuzzyIsNull(d->m_min - min)) {
177 176 d->m_min = min;
178 177 changed = true;
179 178 emit minChanged(min);
180 179 }
181 180
182 181 if (!qFuzzyIsNull(d->m_max - max)) {
183 182 d->m_max = max;
184 183 changed = true;
185 184 emit maxChanged(max);
186 185 }
187 186
188 187 if (changed) {
189 188 d->emitRange();
190 189 emit rangeChanged(d->m_min,d->m_max);
191 190 }
192 191 }
193 192
194 193 /*!
195 194 Sets \a count for ticks on the axis.
196 195 */
197 196 void QValuesAxis::setTicksCount(int count)
198 197 {
199 198 Q_D(QValuesAxis);
200 199 if (d->m_ticksCount != count) {
201 200 d->m_ticksCount = count;
202 201 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
203 202 }
204 203 }
205 204
206 205 /*!
207 206 \fn int QValuesAxis::ticksCount() const
208 207 Return number of ticks on the axis
209 208 */
210 209 int QValuesAxis::ticksCount() const
211 210 {
212 211 Q_D(const QValuesAxis);
213 212 return d->m_ticksCount;
214 213 }
215 214
216 215 void QValuesAxis::setNiceNumbersEnabled(bool enable)
217 216 {
218 217 Q_D(QValuesAxis);
219 218 if (d->m_niceNumbers != enable){
220 219 d->m_niceNumbers = enable;
221 220 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
222 221 }
223 222 }
224 223
225 224 bool QValuesAxis::niceNumbersEnabled() const
226 225 {
227 226 Q_D(const QValuesAxis);
228 227 return d->m_niceNumbers;
229 228 }
230 229
231 230 /*!
232 231 Returns the type of the axis
233 232 */
234 233 QAbstractAxis::AxisType QValuesAxis::type() const
235 234 {
236 235 return AxisTypeValues;
237 236 }
238 237
239 238 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
240 239
241 240 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
242 241 QAbstractAxisPrivate(q),
243 242 m_niceNumbers(false)
244 243 {
245 244
246 245 }
247 246
248 247 QValuesAxisPrivate::~QValuesAxisPrivate()
249 248 {
250 249
251 250 }
252 251
253 252 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
254 253 {
255 254 Q_Q(QValuesAxis);
256 255 q->setRange(min,max);
257 256 q->setTicksCount(count);
258 257 }
259 258
260 259
261 260 void QValuesAxisPrivate::setMin(const QVariant &min)
262 261 {
263 262 Q_Q(QValuesAxis);
264 263 bool ok;
265 264 qreal value = min.toReal(&ok);
266 265 if(ok) q->setMin(value);
267 266 }
268 267
269 268 void QValuesAxisPrivate::setMax(const QVariant &max)
270 269 {
271 270
272 271 Q_Q(QValuesAxis);
273 272 bool ok;
274 273 qreal value = max.toReal(&ok);
275 274 if(ok) q->setMax(value);
276 275 }
277 276
278 277 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
279 278 {
280 279 Q_Q(QValuesAxis);
281 280 bool ok1;
282 281 bool ok2;
283 282 qreal value1 = min.toReal(&ok1);
284 283 qreal value2 = max.toReal(&ok2);
285 284 if(ok1&&ok2) q->setRange(value1,value2);
286 285 }
287 286
288 287 int QValuesAxisPrivate::ticksCount() const
289 288 {
290 289 return m_ticksCount;
291 290 }
292 291
293 292 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
294 293 {
295 294 Q_Q(QValuesAxis);
296 295 if(m_orientation == Qt::Vertical){
297 296 return new ChartValuesAxisY(q,presenter);
298 297 }else{
299 298 return new ChartValuesAxisX(q,presenter);
300 299 }
301 300
302 301 }
303 302
304 303 void QValuesAxisPrivate::emitRange()
305 304 {
306 305 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
307 306 }
308 307
309 void QValuesAxisPrivate::initialize(Domain* domain)
308 void QValuesAxisPrivate::intializeDomain(Domain* domain)
310 309 {
311 310 if(qFuzzyCompare(m_max,m_min)) {
312 311 if(m_orientation==Qt::Vertical){
313 handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount());
312 m_min = domain->minY();
313 m_max = domain->maxY();
314 m_ticksCount = domain->tickYCount();
314 315 }else{
315 handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount());
316 m_min = domain->minX();
317 m_max = domain->maxX();
318 m_ticksCount = domain->tickXCount();
316 319 }
317 320 }
318 321 }
319 322
320 323 #include "moc_qvaluesaxis.cpp"
321 324 #include "moc_qvaluesaxis_p.cpp"
322 325
323 326 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,69 +1,69
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QVALUESAXIS_P_H
31 31 #define QVALUESAXIS_P_H
32 32
33 33 #include "qvaluesaxis.h"
34 34 #include "qabstractaxis_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QValuesAxisPrivate : public QAbstractAxisPrivate
39 39 {
40 40 Q_OBJECT
41 41 public:
42 42 QValuesAxisPrivate(QValuesAxis *q);
43 43 ~QValuesAxisPrivate();
44 44
45 45 Q_SIGNALS:
46 46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
47 47
48 48 public Q_SLOTS:
49 49 void handleAxisRangeChanged(qreal min, qreal max,int count);
50 50
51 51 public:
52 52 ChartAxis* createGraphics(ChartPresenter* presenter);
53 void initialize(Domain* domain);
53 void intializeDomain(Domain* domain);
54 54 void emitRange();
55 55
56 56 protected:
57 57 void setMin(const QVariant &min);
58 58 void setMax(const QVariant &max);
59 59 void setRange(const QVariant &min, const QVariant &max);
60 60 int ticksCount() const;
61 61
62 62 private:
63 63 bool m_niceNumbers;
64 64 Q_DECLARE_PUBLIC(QValuesAxis)
65 65 };
66 66
67 67 QTCOMMERCIALCHART_END_NAMESPACE
68 68
69 69 #endif // QVALUESAXIS_P_H
@@ -1,737 +1,729
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qabstractbarseries.h"
22 22 #include "qabstractbarseries_p.h"
23 23 #include "qbarset.h"
24 24 #include "qbarset_p.h"
25 25 #include "domain_p.h"
26 26 #include "legendmarker_p.h"
27 27 #include "chartdataset_p.h"
28 28 #include "charttheme_p.h"
29 29 #include "chartanimator_p.h"
30 30 #include "qvaluesaxis.h"
31 31 #include "qbarcategoriesaxis.h"
32 32
33 33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 34
35 35 /*!
36 36 \class QAbstractBarSeries
37 37 \brief Series for creating a bar chart
38 38 \mainclass
39 39
40 40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
41 41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
42 42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
43 43 shows the x-values.
44 44
45 45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
46 46 \image examples_barchart.png
47 47
48 48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
49 49 */
50 50 /*!
51 51 \qmlclass AbstractBarSeries QAbstractBarSeries
52 52 \inherits QAbstractSeries
53 53
54 54 The following QML shows how to create a simple bar chart:
55 55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
56 56
57 57 \beginfloatleft
58 58 \image demos_qmlchart6.png
59 59 \endfloat
60 60 \clearfloat
61 61 */
62 62
63 63 /*!
64 64 \property QAbstractBarSeries::barWidth
65 65 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
66 66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
67 67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
68 68 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
69 69 \sa QBarSeries
70 70 */
71 71 /*!
72 72 \qmlproperty real AbstractBarSeries::barWidth
73 73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
74 74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
75 75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
76 76 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
77 77 */
78 78
79 79 /*!
80 80 \property QAbstractBarSeries::count
81 81 Holds the number of sets in series.
82 82 */
83 83 /*!
84 84 \qmlproperty int AbstractBarSeries::count
85 85 Holds the number of sets in series.
86 86 */
87 87
88 88 /*!
89 89 \property QAbstractBarSeries::labelsVisible
90 90 Defines the visibility of the labels in series
91 91 */
92 92 /*!
93 93 \qmlproperty bool AbstractBarSeries::labelsVisible
94 94 Defines the visibility of the labels in series
95 95 */
96 96
97 97 /*!
98 98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
99 99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
100 100 Clicked bar inside set is indexed by \a index
101 101 */
102 102 /*!
103 103 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
104 104 The signal is emitted if the user clicks with a mouse on top of BarSet.
105 105 Clicked bar inside set is indexed by \a index
106 106 */
107 107
108 108 /*!
109 109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
110 110
111 111 The signal is emitted if mouse is hovered on top of series.
112 112 Parameter \a barset is the pointer of barset, where hover happened.
113 113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
114 114 */
115 115 /*!
116 116 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
117 117
118 118 The signal is emitted if mouse is hovered on top of series.
119 119 Parameter \a barset is the pointer of barset, where hover happened.
120 120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
121 121 */
122 122
123 123 /*!
124 124 \fn void QAbstractBarSeries::countChanged()
125 125 This signal is emitted when barset count has been changed, for example by append or remove.
126 126 */
127 127 /*!
128 128 \qmlsignal AbstractBarSeries::onCountChanged()
129 129 This signal is emitted when barset count has been changed, for example by append or remove.
130 130 */
131 131
132 132 /*!
133 133 \fn void QAbstractBarSeries::labelsVisibleChanged()
134 134 This signal is emitted when labels visibility have changed.
135 135 \sa isLabelsVisible(), setLabelsVisible()
136 136 */
137 137
138 138 /*!
139 139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
140 140 This signal is emitted when \a sets have been added to the series.
141 141 \sa append(), insert()
142 142 */
143 143 /*!
144 144 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
145 145 Emitted when \a barset has been added to the series.
146 146 */
147 147
148 148 /*!
149 149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
150 150 This signal is emitted when \a sets have been removed from the series.
151 151 \sa remove()
152 152 */
153 153 /*!
154 154 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
155 155 Emitted when \a barset has been removed from the series.
156 156 */
157 157
158 158 /*!
159 159 \qmlmethod BarSet AbstractBarSeries::at(int index)
160 160 Returns bar set at \a index. Returns null if the index is not valid.
161 161 */
162 162
163 163 /*!
164 164 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
165 165 Adds 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.
166 166 For example:
167 167 \code
168 168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 170 \endcode
171 171 */
172 172
173 173 /*!
174 174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
175 175 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.
176 176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
177 177 appended.
178 178 \sa AbstractBarSeries::append()
179 179 */
180 180
181 181 /*!
182 182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
183 183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 184 */
185 185
186 186 /*!
187 187 \qmlmethod AbstractBarSeries::clear()
188 188 Removes all barsets from the series.
189 189 */
190 190
191 191 /*!
192 192 Constructs empty QAbstractBarSeries.
193 193 QAbstractBarSeries is QObject which is a child of a \a parent.
194 194 */
195 195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
196 196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
197 197 {
198 198 }
199 199
200 200 /*!
201 201 Destructs abstractbarseries and owned barsets.
202 202 */
203 203 QAbstractBarSeries::~QAbstractBarSeries()
204 204 {
205 205 Q_D(QAbstractBarSeries);
206 206 if(d->m_dataset){
207 207 d->m_dataset->removeSeries(this);
208 208 }
209 209 }
210 210
211 211 /*!
212 212 \internal
213 213 */
214 214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
215 215 QAbstractSeries(d,parent)
216 216 {
217 217 }
218 218
219 219 /*!
220 220 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
221 221 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
222 222 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
223 223 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
224 224 */
225 225 void QAbstractBarSeries::setBarWidth(qreal width)
226 226 {
227 227 Q_D(QAbstractBarSeries);
228 228 d->setBarWidth(width);
229 229 }
230 230
231 231 /*!
232 232 Returns the width of the bars of the series.
233 233 \sa setBarWidth()
234 234 */
235 235 qreal QAbstractBarSeries::barWidth() const
236 236 {
237 237 Q_D(const QAbstractBarSeries);
238 238 return d->barWidth();
239 239 }
240 240
241 241 /*!
242 242 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.
243 243 Returns true, if appending succeeded.
244 244 */
245 245 bool QAbstractBarSeries::append(QBarSet *set)
246 246 {
247 247 Q_D(QAbstractBarSeries);
248 248 bool success = d->append(set);
249 249 if (success) {
250 250 QList<QBarSet*> sets;
251 251 sets.append(set);
252 252 emit barsetsAdded(sets);
253 253 emit countChanged();
254 254 }
255 255 return success;
256 256 }
257 257
258 258 /*!
259 259 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
260 260 Returns true, if set was removed.
261 261 */
262 262 bool QAbstractBarSeries::remove(QBarSet *set)
263 263 {
264 264 Q_D(QAbstractBarSeries);
265 265 bool success = d->remove(set);
266 266 if (success) {
267 267 QList<QBarSet*> sets;
268 268 sets.append(set);
269 269 emit barsetsRemoved(sets);
270 270 emit countChanged();
271 271 }
272 272 return success;
273 273 }
274 274
275 275 /*!
276 276 Adds a list of barsets to series. Takes ownership of \a sets.
277 277 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
278 278 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
279 279 and function returns false.
280 280 */
281 281 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
282 282 {
283 283 Q_D(QAbstractBarSeries);
284 284 bool success = d->append(sets);
285 285 if (success) {
286 286 emit barsetsAdded(sets);
287 287 emit countChanged();
288 288 }
289 289 return success;
290 290 }
291 291
292 292 /*!
293 293 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.
294 294 Returns true, if inserting succeeded.
295 295
296 296 */
297 297 bool QAbstractBarSeries::insert(int index, QBarSet *set)
298 298 {
299 299 Q_D(QAbstractBarSeries);
300 300 bool success = d->insert(index, set);
301 301 if (success) {
302 302 QList<QBarSet*> sets;
303 303 sets.append(set);
304 304 emit barsetsAdded(sets);
305 305 emit countChanged();
306 306 }
307 307 return success;
308 308 }
309 309
310 310 /*!
311 311 Removes all of the bar sets from the series
312 312 */
313 313 void QAbstractBarSeries::clear()
314 314 {
315 315 Q_D(QAbstractBarSeries);
316 316 QList<QBarSet *> sets = barSets();
317 317 bool success = d->remove(sets);
318 318 if (success) {
319 319 emit barsetsRemoved(sets);
320 320 emit countChanged();
321 321 }
322 322 }
323 323
324 324 /*!
325 325 Returns number of sets in series.
326 326 */
327 327 int QAbstractBarSeries::count() const
328 328 {
329 329 Q_D(const QAbstractBarSeries);
330 330 return d->m_barSets.count();
331 331 }
332 332
333 333 /*!
334 334 Returns a list of sets in series. Keeps ownership of sets.
335 335 */
336 336 QList<QBarSet*> QAbstractBarSeries::barSets() const
337 337 {
338 338 Q_D(const QAbstractBarSeries);
339 339 return d->m_barSets;
340 340 }
341 341
342 342 /*!
343 343 Sets the visibility of labels in series to \a visible
344 344 */
345 345 void QAbstractBarSeries::setLabelsVisible(bool visible)
346 346 {
347 347 Q_D(QAbstractBarSeries);
348 348 if (d->m_labelsVisible != visible) {
349 349 d->setLabelsVisible(visible);
350 350 emit labelsVisibleChanged();
351 351 }
352 352 }
353 353
354 354 /*!
355 355 Returns the visibility of labels
356 356 */
357 357 bool QAbstractBarSeries::isLabelsVisible() const
358 358 {
359 359 Q_D(const QAbstractBarSeries);
360 360 return d->m_labelsVisible;
361 361 }
362 362
363 363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
364 364
365 365 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
366 366 QAbstractSeriesPrivate(q),
367 367 m_barWidth(0.5), // Default value is 50% of category width
368 368 m_labelsVisible(false),
369 369 m_visible(true)
370 370 {
371 371 }
372 372
373 373 int QAbstractBarSeriesPrivate::categoryCount() const
374 374 {
375 375 // No categories defined. return count of longest set.
376 376 int count = 0;
377 377 for (int i=0; i<m_barSets.count(); i++) {
378 378 if (m_barSets.at(i)->count() > count) {
379 379 count = m_barSets.at(i)->count();
380 380 }
381 381 }
382 382
383 383 return count;
384 384 }
385 385
386 386 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
387 387 {
388 388 if (width < 0.0) {
389 389 width = 0.0;
390 390 }
391 391 m_barWidth = width;
392 392 emit updatedBars();
393 393 }
394 394
395 395 qreal QAbstractBarSeriesPrivate::barWidth() const
396 396 {
397 397 return m_barWidth;
398 398 }
399 399
400 400 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
401 401 {
402 402 return m_barSets.at(index);
403 403 }
404 404
405 405 void QAbstractBarSeriesPrivate::setVisible(bool visible)
406 406 {
407 407 m_visible = visible;
408 408 emit updatedBars();
409 409 }
410 410
411 411 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
412 412 {
413 413 m_labelsVisible = visible;
414 414 emit labelsVisibleChanged(visible);
415 415 }
416 416
417 417 qreal QAbstractBarSeriesPrivate::min()
418 418 {
419 419 if (m_barSets.count() <= 0) {
420 420 return 0;
421 421 }
422 422 qreal min = INT_MAX;
423 423
424 424 for (int i = 0; i < m_barSets.count(); i++) {
425 425 int categoryCount = m_barSets.at(i)->count();
426 426 for (int j = 0; j < categoryCount; j++) {
427 427 qreal temp = m_barSets.at(i)->at(j);
428 428 if (temp < min)
429 429 min = temp;
430 430 }
431 431 }
432 432 return min;
433 433 }
434 434
435 435 qreal QAbstractBarSeriesPrivate::max()
436 436 {
437 437 if (m_barSets.count() <= 0) {
438 438 return 0;
439 439 }
440 440 qreal max = INT_MIN;
441 441
442 442 for (int i = 0; i < m_barSets.count(); i++) {
443 443 int categoryCount = m_barSets.at(i)->count();
444 444 for (int j = 0; j < categoryCount; j++) {
445 445 qreal temp = m_barSets.at(i)->at(j);
446 446 if (temp > max)
447 447 max = temp;
448 448 }
449 449 }
450 450
451 451 return max;
452 452 }
453 453
454 454 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
455 455 {
456 456 if ((set < 0) || (set >= m_barSets.count())) {
457 457 // No set, no value.
458 458 return 0;
459 459 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
460 460 // No category, no value.
461 461 return 0;
462 462 }
463 463
464 464 return m_barSets.at(set)->at(category);
465 465 }
466 466
467 467 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
468 468 {
469 469 if ((set < 0) || (set >= m_barSets.count())) {
470 470 // No set, no value.
471 471 return 0;
472 472 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
473 473 // No category, no value.
474 474 return 0;
475 475 }
476 476
477 477 qreal value = m_barSets.at(set)->at(category);
478 478 qreal sum = categorySum(category);
479 479 if ( qFuzzyIsNull(sum) ) {
480 480 return 0;
481 481 }
482 482
483 483 return value / sum;
484 484 }
485 485
486 486 qreal QAbstractBarSeriesPrivate::categorySum(int category)
487 487 {
488 488 qreal sum(0);
489 489 int count = m_barSets.count(); // Count sets
490 490 for (int set = 0; set < count; set++) {
491 491 if (category < m_barSets.at(set)->count())
492 492 sum += m_barSets.at(set)->at(category);
493 493 }
494 494 return sum;
495 495 }
496 496
497 497 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
498 498 {
499 499 qreal sum(0);
500 500 int count = m_barSets.count(); // Count sets
501 501 for (int set = 0; set < count; set++) {
502 502 if (category < m_barSets.at(set)->count())
503 503 sum += qAbs(m_barSets.at(set)->at(category));
504 504 }
505 505 return sum;
506 506 }
507 507
508 508 qreal QAbstractBarSeriesPrivate::maxCategorySum()
509 509 {
510 510 qreal max = INT_MIN;
511 511 int count = categoryCount();
512 512 for (int i = 0; i < count; i++) {
513 513 qreal sum = categorySum(i);
514 514 if (sum > max)
515 515 max = sum;
516 516 }
517 517 return max;
518 518 }
519 519
520 520 qreal QAbstractBarSeriesPrivate::minX()
521 521 {
522 522 if (m_barSets.count() <= 0) {
523 523 return 0;
524 524 }
525 525 qreal min = INT_MAX;
526 526
527 527 for (int i = 0; i < m_barSets.count(); i++) {
528 528 int categoryCount = m_barSets.at(i)->count();
529 529 for (int j = 0; j < categoryCount; j++) {
530 530 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
531 531 if (temp < min)
532 532 min = temp;
533 533 }
534 534 }
535 535 return min;
536 536 }
537 537
538 538 qreal QAbstractBarSeriesPrivate::maxX()
539 539 {
540 540 if (m_barSets.count() <= 0) {
541 541 return 0;
542 542 }
543 543 qreal max = INT_MIN;
544 544
545 545 for (int i = 0; i < m_barSets.count(); i++) {
546 546 int categoryCount = m_barSets.at(i)->count();
547 547 for (int j = 0; j < categoryCount; j++) {
548 548 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
549 549 if (temp > max)
550 550 max = temp;
551 551 }
552 552 }
553 553
554 554 return max;
555 555 }
556 556
557 557
558 558 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
559 559 {
560 560 qreal minX(domain.minX());
561 561 qreal minY(domain.minY());
562 562 qreal maxX(domain.maxX());
563 563 qreal maxY(domain.maxY());
564 564 int tickXCount(domain.tickXCount());
565 565 int tickYCount(domain.tickYCount());
566 566
567 567 qreal seriesMinX = this->minX();
568 568 qreal seriesMaxX = this->maxX();
569 569 qreal y = max();
570 570 minX = qMin(minX, seriesMinX - (qreal)0.5);
571 571 minY = qMin(minY, y);
572 572 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
573 573 maxY = qMax(maxY, y);
574 574 tickXCount = categoryCount()+1;
575 575
576 576 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
577 577 }
578 578
579 579 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
580 580 {
581 581 Q_UNUSED(presenter);
582 582 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
583 583 return 0;
584 584 }
585 585
586 586 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
587 587 {
588 588 Q_Q(QAbstractBarSeries);
589 589 QList<LegendMarker*> markers;
590 590 foreach(QBarSet* set, q->barSets()) {
591 591 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
592 592 markers << marker;
593 593 }
594 594
595 595 return markers;
596 596 }
597 597
598 598 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
599 599 {
600 600 Q_Q(QAbstractBarSeries);
601 601 if ((m_barSets.contains(set)) || (set == 0)) {
602 602 // Fail if set is already in list or set is null.
603 603 return false;
604 604 }
605 605 m_barSets.append(set);
606 606 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
607 607 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
608 608 emit restructuredBars(); // this notifies barchartitem
609 609 if (m_dataset) {
610 610 m_dataset->updateSeries(q); // this notifies legend
611 611 }
612 612 return true;
613 613 }
614 614
615 615 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
616 616 {
617 617 Q_Q(QAbstractBarSeries);
618 618 if (!m_barSets.contains(set)) {
619 619 // Fail if set is not in list
620 620 return false;
621 621 }
622 622 m_barSets.removeOne(set);
623 623 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
624 624 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
625 625 emit restructuredBars(); // this notifies barchartitem
626 626 if (m_dataset) {
627 627 m_dataset->updateSeries(q); // this notifies legend
628 628 }
629 629 return true;
630 630 }
631 631
632 632 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
633 633 {
634 634 Q_Q(QAbstractBarSeries);
635 635 foreach (QBarSet* set, sets) {
636 636 if ((set == 0) || (m_barSets.contains(set))) {
637 637 // Fail if any of the sets is null or is already appended.
638 638 return false;
639 639 }
640 640 if (sets.count(set) != 1) {
641 641 // Also fail if same set is more than once in given list.
642 642 return false;
643 643 }
644 644 }
645 645
646 646 foreach (QBarSet* set, sets) {
647 647 m_barSets.append(set);
648 648 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
649 649 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
650 650 }
651 651 emit restructuredBars(); // this notifies barchartitem
652 652 if (m_dataset) {
653 653 m_dataset->updateSeries(q); // this notifies legend
654 654 }
655 655 return true;
656 656 }
657 657
658 658 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
659 659 {
660 660 Q_Q(QAbstractBarSeries);
661 661 if (sets.count() == 0) {
662 662 return false;
663 663 }
664 664 foreach (QBarSet* set, sets) {
665 665 if ((set == 0) || (!m_barSets.contains(set))) {
666 666 // Fail if any of the sets is null or is not in series
667 667 return false;
668 668 }
669 669 if (sets.count(set) != 1) {
670 670 // Also fail if same set is more than once in given list.
671 671 return false;
672 672 }
673 673 }
674 674
675 675 foreach (QBarSet* set, sets) {
676 676 m_barSets.removeOne(set);
677 677 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
678 678 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
679 679 }
680 680
681 681 emit restructuredBars(); // this notifies barchartitem
682 682 if (m_dataset) {
683 683 m_dataset->updateSeries(q); // this notifies legend
684 684 }
685 685 return true;
686 686 }
687 687
688 688 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
689 689 {
690 690 Q_Q(QAbstractBarSeries);
691 691 if ((m_barSets.contains(set)) || (set == 0)) {
692 692 // Fail if set is already in list or set is null.
693 693 return false;
694 694 }
695 695 m_barSets.insert(index, set);
696 696 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
697 697 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
698 698 emit restructuredBars(); // this notifies barchartitem
699 699 if (m_dataset) {
700 700 m_dataset->updateSeries(q); // this notifies legend
701 701 }
702 702 return true;
703 703 }
704 704
705 void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
705 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
706 706 {
707 if(axis->type()==QAbstractAxis::AxisTypeCategories)
707 if(axis->type()==QAbstractAxis::AxisTypeCategories && axis->orientation()==Qt::Horizontal)
708 708 {
709 709 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
710 710 Q_ASSERT(cataxis);
711 711 QStringList categories;
712 712 for (int i(1); i < categoryCount()+1; i++)
713 713 categories << QString::number(i);
714 714 cataxis->append(categories);
715 715 }
716 716 }
717 717
718 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
719 {
720 Q_UNUSED(axis)
721 }
722
723 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const
718 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
724 719 {
720 Q_UNUSED(orientation);
725 721 return QAbstractAxis::AxisTypeNoAxis;
726 722 }
727 723
728 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const
729 {
730 return QAbstractAxis::AxisTypeNoAxis;
731 }
732 724
733 725 #include "moc_qabstractbarseries.cpp"
734 726 #include "moc_qabstractbarseries_p.cpp"
735 727
736 728
737 729 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,99 +1,97
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QABSTRACTBARSERIES_P_H
31 31 #define QABSTRACTBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries.h"
34 34 #include "qabstractseries_p.h"
35 35 #include <QStringList>
36 36 #include <QAbstractSeries>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class QBarModelMapper;
41 41
42 42 class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate
43 43 {
44 44 Q_OBJECT
45 45 public:
46 46 QAbstractBarSeriesPrivate(QAbstractBarSeries *parent);
47 47 int categoryCount() const;
48 48
49 49 void setBarWidth(qreal width);
50 50 qreal barWidth() const;
51 51
52 52 void setVisible(bool visible);
53 53 void setLabelsVisible(bool visible);
54 54
55 55 void scaleDomain(Domain& domain);
56 56 Chart* createGraphics(ChartPresenter* presenter);
57 57 QList<LegendMarker*> createLegendMarker(QLegend* legend);
58 58
59 void initializeAxisX(QAbstractAxis* axis);
60 void initializeAxisY(QAbstractAxis* axis);
61 QAbstractAxis::AxisType defaultAxisXType() const;
62 QAbstractAxis::AxisType defaultAxisYType() const;
59 void initializeAxis(QAbstractAxis* axis);
60 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
63 61
64 62 bool append(QBarSet *set);
65 63 bool remove(QBarSet *set);
66 64 bool append(QList<QBarSet* > sets);
67 65 bool remove(QList<QBarSet* > sets);
68 66 bool insert(int index, QBarSet *set);
69 67
70 68 QBarSet* barsetAt(int index);
71 69 qreal min();
72 70 qreal max();
73 71 qreal valueAt(int set, int category);
74 72 qreal percentageAt(int set, int category);
75 73 qreal categorySum(int category);
76 74 qreal absoluteCategorySum(int category);
77 75 qreal maxCategorySum();
78 76 qreal minX();
79 77 qreal maxX();
80 78
81 79 Q_SIGNALS:
82 80 void clicked(int index, QBarSet *barset);
83 81 void updatedBars();
84 82 void restructuredBars();
85 83 void labelsVisibleChanged(bool visible);
86 84
87 85 protected:
88 86 QList<QBarSet *> m_barSets;
89 87 qreal m_barWidth;
90 88 bool m_labelsVisible;
91 89 bool m_visible;
92 90
93 91 private:
94 92 Q_DECLARE_PUBLIC(QAbstractBarSeries)
95 93 };
96 94
97 95 QTCOMMERCIALCHART_END_NAMESPACE
98 96
99 97 #endif // QABSTRACTBARSERIES_P_H
@@ -1,129 +1,127
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarseries.h"
22 22 #include "qbarseries_p.h"
23 23 #include "barchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27 #include "baranimation_p.h"
28 28 #include "qvaluesaxis.h"
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 /*!
33 33 \class QBarSeries
34 34 \brief Series for creating bar chart
35 35 \mainclass
36 36
37 37 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 38 as groups, where bars in same category are grouped next to each other. QBarSeries groups the data
39 39 from sets to categories, which are defined by a QStringList.
40 40
41 41 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
42 42 \image examples_barchart.png
43 43
44 44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
45 45 */
46 46 /*!
47 47 \qmlclass BarSeries QBarSeries
48 48 \inherits AbstractBarSeries
49 49
50 50 The following QML shows how to create a simple grouped bar chart:
51 51 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
52 52 \beginfloatleft
53 53 \image demos_qmlchart6.png
54 54 \endfloat
55 55 \clearfloat
56 56 */
57 57
58 58 /*!
59 59 Constructs empty QBarSeries.
60 60 QBarSeries is QObject which is a child of a \a parent.
61 61 */
62 62 QBarSeries::QBarSeries(QObject *parent)
63 63 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
64 64 {
65 65 }
66 66
67 67 /*!
68 68 Returns QChartSeries::SeriesTypeBar.
69 69 */
70 70 QAbstractSeries::SeriesType QBarSeries::type() const
71 71 {
72 72 return QAbstractSeries::SeriesTypeBar;
73 73 }
74 74
75 75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 76
77 77 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
78 78 {
79 79
80 80 }
81 81
82 82 void QBarSeriesPrivate::scaleDomain(Domain& domain)
83 83 {
84 84 qreal minX(domain.minX());
85 85 qreal minY(domain.minY());
86 86 qreal maxX(domain.maxX());
87 87 qreal maxY(domain.maxY());
88 88 int tickXCount(domain.tickXCount());
89 89 int tickYCount(domain.tickYCount());
90 90
91 91 qreal x = categoryCount();
92 92 qreal y = max();
93 93 minX = qMin(minX, - (qreal)0.5);
94 94 minY = qMin(minY, y);
95 95 maxX = qMax(maxX, x - (qreal)0.5);
96 96 maxY = qMax(maxY, y);
97 97 tickXCount = x+1;
98 98
99 99 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
100 100 }
101 101
102 102
103 103 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
104 104 {
105 105 Q_Q(QBarSeries);
106 106
107 107 BarChartItem* bar = new BarChartItem(q,presenter);
108 108 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
109 109 bar->setAnimator(presenter->animator());
110 110 bar->setAnimation(new BarAnimation(bar));
111 111 }
112 112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
113 113 return bar;
114 114 }
115 115
116 QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisXType() const
116 QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
117 117 {
118 if(orientation==Qt::Horizontal)
118 119 return QAbstractAxis::AxisTypeCategories;
119 }
120
121 QAbstractAxis::AxisType QBarSeriesPrivate::defaultAxisYType() const
122 {
120 else
123 121 return QAbstractAxis::AxisTypeValues;
124 122 }
125 123
126 124 #include "moc_qbarseries.cpp"
127 125
128 126 QTCOMMERCIALCHART_END_NAMESPACE
129 127
@@ -1,55 +1,55
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QBARSERIES_P_H
31 31 #define QBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "domain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38
39 39 class QBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 40 {
41 41 public:
42 42 QBarSeriesPrivate(QBarSeries* q);
43 43 Chart* createGraphics(ChartPresenter* presenter);
44 44 void scaleDomain(Domain& domain);
45 45
46 QAbstractAxis::AxisType defaultAxisXType() const;
47 QAbstractAxis::AxisType defaultAxisYType() const;
46 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
47
48 48
49 49 private:
50 50 Q_DECLARE_PUBLIC(QBarSeries)
51 51 };
52 52
53 53 QTCOMMERCIALCHART_END_NAMESPACE
54 54
55 55 #endif // QBARSERIES_P_H
@@ -1,78 +1,90
1 1 #include "qhorizontalbarseries.h"
2 2 #include "qhorizontalbarseries_p.h"
3 3 #include "horizontalbarchartitem_p.h"
4 4 #include "horizontalbaranimation_p.h"
5 #include "qbarcategoriesaxis.h"
5 6
6 7 #include "chartdataset_p.h"
7 8 #include "charttheme_p.h"
8 9
9 10
10 11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 12
12 13 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) :
13 14 QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
14 15 {
15 16 }
16 17
17 18 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
18 19 {
19 20 return QAbstractSeries::SeriesTypeHorizontalBar;
20 21 }
21 22
22 23
23 24
24 25 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25 26
26 27 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) : QAbstractBarSeriesPrivate(q)
27 28 {
28 29
29 30 }
30 31
31 32 void QHorizontalBarSeriesPrivate::scaleDomain(Domain& domain)
32 33 {
33 34 qreal minX(domain.minX());
34 35 qreal minY(domain.minY());
35 36 qreal maxX(domain.maxX());
36 37 qreal maxY(domain.maxY());
37 38 int tickXCount(domain.tickXCount());
38 39 int tickYCount(domain.tickYCount());
39 40
40 41 qreal y = categoryCount();
41 42 qreal x = max();
42 43 minX = qMin(minX, x);
43 44 minY = qMin(minY, - (qreal)0.5);
44 45 maxX = qMax(maxX, x);
45 46 maxY = qMax(maxY, y - (qreal)0.5);
46 47 tickYCount = y+1;
47 48
48 49 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
49 50 }
50 51
51 52
52 53 Chart* QHorizontalBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
53 54 {
54 55 Q_Q(QHorizontalBarSeries);
55 56
56 57 HorizontalBarChartItem* bar = new HorizontalBarChartItem(q,presenter);
57 58 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
58 59 bar->setAnimator(presenter->animator());
59 60 bar->setAnimation(new HorizontalBarAnimation(bar));
60 61 }
61 62 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
62 63 return bar;
63 64 }
64 65
65 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisXType() const
66 void QHorizontalBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
66 67 {
67 return QAbstractAxis::AxisTypeValues;
68
69 if(axis->type()==QAbstractAxis::AxisTypeCategories && axis->orientation()==Qt::Vertical)
70 {
71 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
72 Q_ASSERT(cataxis);
73 QStringList categories;
74 for (int i(1); i < categoryCount()+1; i++)
75 categories << QString::number(i);
76 cataxis->append(categories);
77 }
68 78 }
69 79
70 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisYType() const
80 QAbstractAxis::AxisType QHorizontalBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
71 81 {
82 if(orientation==Qt::Vertical)
72 83 return QAbstractAxis::AxisTypeCategories;
84 else
85 return QAbstractAxis::AxisTypeValues;
73 86 }
74 87
75
76 88 #include "moc_qhorizontalbarseries.cpp"
77 89
78 90 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,53
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QHORIZONTALBARSERIES_P_H
31 31 #define QHORIZONTALBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "domain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QHorizontalBarSeriesPrivate: public QAbstractBarSeriesPrivate
39 39 {
40 40 public:
41 41 QHorizontalBarSeriesPrivate(QHorizontalBarSeries* q);
42 42 Chart* createGraphics(ChartPresenter* presenter);
43 43 void scaleDomain(Domain& domain);
44 QAbstractAxis::AxisType defaultAxisXType() const;
45 QAbstractAxis::AxisType defaultAxisYType() const;
44 void initializeAxis(QAbstractAxis* axis);
45 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
46 46
47 47 private:
48 48 Q_DECLARE_PUBLIC(QHorizontalBarSeries)
49 49 };
50 50
51 51 QTCOMMERCIALCHART_END_NAMESPACE
52 52
53 53 #endif // QHORIZONTALBARSERIES_P_H
@@ -1,128 +1,127
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpercentbarseries.h"
22 22 #include "qpercentbarseries_p.h"
23 23 #include "percentbarchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27 #include "qvaluesaxis.h"
28 28 #include "percentbaranimation_p.h"
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 /*!
33 33 \class QPercentBarSeries
34 34 \brief Series for creating percent bar chart
35 35 \mainclass
36 36
37 37 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 38 as stacks, where each bar is shown as percentage of all bars in that category.
39 39 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
40 40
41 41 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
42 42 \image examples_percentbarchart.png
43 43
44 44 \sa QBarSet, QStackedBarSeries, QAbstractBarSeries
45 45 */
46 46 /*!
47 47 \qmlclass PercentBarSeries QPercentBarSeries
48 48 \inherits QAbstractBarSeries
49 49
50 50 The following QML shows how to create a simple percent bar chart:
51 51 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
52 52 \beginfloatleft
53 53 \image demos_qmlchart8.png
54 54 \endfloat
55 55 \clearfloat
56 56 */
57 57
58 58 /*!
59 59 Constructs empty QPercentBarSeries.
60 60 QPercentBarSeries is QObject which is a child of a \a parent.
61 61 */
62 62 QPercentBarSeries::QPercentBarSeries(QObject *parent)
63 63 : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent)
64 64 {
65 65 }
66 66
67 67 /*!
68 68 Returns QChartSeries::SeriesTypePercentBar.
69 69 */
70 70 QAbstractSeries::SeriesType QPercentBarSeries::type() const
71 71 {
72 72 return QAbstractSeries::SeriesTypePercentBar;
73 73 }
74 74
75 75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 76
77 77 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
78 78 {
79 79
80 80 }
81 81
82 82 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
83 83 {
84 84 qreal minX(domain.minX());
85 85 qreal minY(domain.minY());
86 86 qreal maxX(domain.maxX());
87 87 qreal maxY(domain.maxY());
88 88 int tickXCount(domain.tickXCount());
89 89 int tickYCount(domain.tickYCount());
90 90
91 91 qreal x = categoryCount();
92 92 minX = qMin(minX, - (qreal)0.5);
93 93 maxX = qMax(maxX, x - (qreal)0.5);
94 94 minY = 0;
95 95 maxY = 100;
96 96 tickXCount = x+1;
97 97
98 98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
99 99 }
100 100
101 101
102 102 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
103 103 {
104 104 Q_Q(QPercentBarSeries);
105 105
106 106 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
107 107 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
108 108 bar->setAnimator(presenter->animator());
109 109 bar->setAnimation(new PercentBarAnimation(bar));
110 110 }
111 111 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
112 112 return bar;
113 113 }
114 114
115 QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisXType() const
115 QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
116 116 {
117 if(orientation==Qt::Horizontal)
117 118 return QAbstractAxis::AxisTypeCategories;
118 }
119
120 QAbstractAxis::AxisType QPercentBarSeriesPrivate::defaultAxisYType() const
121 {
119 else
122 120 return QAbstractAxis::AxisTypeValues;
123 121 }
124 122
123
125 124 #include "moc_qpercentbarseries.cpp"
126 125
127 126 QTCOMMERCIALCHART_END_NAMESPACE
128 127
@@ -1,54 +1,53
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QPERCENTBARSERIES_P_H
31 31 #define QPERCENTBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "domain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38
39 39 class QPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 40 {
41 41 public:
42 42 QPercentBarSeriesPrivate(QPercentBarSeries* q);
43 43 void scaleDomain(Domain& domain);
44 44 Chart* createGraphics(ChartPresenter* presenter);
45 QAbstractAxis::AxisType defaultAxisXType() const;
46 QAbstractAxis::AxisType defaultAxisYType() const;
45 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
47 46
48 47 private:
49 48 Q_DECLARE_PUBLIC(QPercentBarSeries)
50 49 };
51 50
52 51 QTCOMMERCIALCHART_END_NAMESPACE
53 52
54 53 #endif
@@ -1,131 +1,129
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qstackedbarseries.h"
22 22 #include "qstackedbarseries_p.h"
23 23 #include "stackedbarchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27 #include "qvaluesaxis.h"
28 28 #include "stackedbaranimation_p.h"
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 /*!
33 33 \class QStackedBarSeries
34 34 \brief Series for creating stacked bar chart
35 35 \mainclass
36 36
37 37 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 38 as stacks, where bars in same category are stacked on top of each other.
39 39 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
40 40
41 41 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
42 42 \image examples_stackedbarchart.png
43 43
44 44 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries
45 45 */
46 46
47 47 /*!
48 48 \qmlclass StackedBarSeries QStackedBarSeries
49 49 \inherits AbstractBarSeries
50 50
51 51 The following QML shows how to create a simple stacked bar chart:
52 52 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
53 53 \beginfloatleft
54 54 \image demos_qmlchart7.png
55 55 \endfloat
56 56 \clearfloat
57 57 */
58 58
59 59 /*!
60 60 Constructs empty QStackedBarSeries.
61 61 QStackedBarSeries is QObject which is a child of a \a parent.
62 62 */
63 63 QStackedBarSeries::QStackedBarSeries(QObject *parent)
64 64 : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent)
65 65 {
66 66 }
67 67
68 68 /*!
69 69 Returns QChartSeries::SeriesTypeStackedBar.
70 70 */
71 71 QAbstractSeries::SeriesType QStackedBarSeries::type() const
72 72 {
73 73 return QAbstractSeries::SeriesTypeStackedBar;
74 74 }
75 75
76 76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77 77
78 78 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
79 79 {
80 80
81 81 }
82 82
83 83 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
84 84 {
85 85 qreal minX(domain.minX());
86 86 qreal minY(domain.minY());
87 87 qreal maxX(domain.maxX());
88 88 qreal maxY(domain.maxY());
89 89 int tickXCount(domain.tickXCount());
90 90 int tickYCount(domain.tickYCount());
91 91
92 92 qreal x = categoryCount();
93 93 qreal y = maxCategorySum();
94 94 minX = qMin(minX, - (qreal)0.5);
95 95 minY = qMin(minY, y);
96 96 maxX = qMax(maxX, x - (qreal)0.5);
97 97 maxY = qMax(maxY, y);
98 98 tickXCount = x+1;
99 99
100 100 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
101 101 }
102 102
103 103
104 104 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
105 105 {
106 106 Q_Q(QStackedBarSeries);
107 107
108 108 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
109 109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
110 110 bar->setAnimator(presenter->animator());
111 111 bar->setAnimation(new StackedBarAnimation(bar));
112 112 }
113 113 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
114 114 return bar;
115 115 }
116 116
117 QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisXType() const
117 QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
118 118 {
119 if(orientation==Qt::Horizontal)
119 120 return QAbstractAxis::AxisTypeCategories;
120 }
121
122 QAbstractAxis::AxisType QStackedBarSeriesPrivate::defaultAxisYType() const
123 {
121 else
124 122 return QAbstractAxis::AxisTypeValues;
125 123 }
126 124
127 125
128 126 #include "moc_qstackedbarseries.cpp"
129 127
130 128 QTCOMMERCIALCHART_END_NAMESPACE
131 129
@@ -1,54 +1,53
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QSTACKEDBARSERIES_P_H
31 31 #define QSTACKEDBARSERIES_P_H
32 32
33 33 #include "qabstractbarseries_p.h"
34 34 #include "domain_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38
39 39 class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 40 {
41 41 public:
42 42 QStackedBarSeriesPrivate(QStackedBarSeries* q);
43 43 Chart* createGraphics(ChartPresenter* presenter);
44 44 void scaleDomain(Domain& domain);
45 QAbstractAxis::AxisType defaultAxisXType() const;
46 QAbstractAxis::AxisType defaultAxisYType() const;
45 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
47 46
48 47 private:
49 48 Q_DECLARE_PUBLIC(QStackedBarSeries)
50 49 };
51 50
52 51 QTCOMMERCIALCHART_END_NAMESPACE
53 52
54 53 #endif
@@ -1,467 +1,429
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartdataset_p.h"
22 22 #include "qchart.h"
23 23 #include "qvaluesaxis.h"
24 24 #include "qbarcategoriesaxis.h"
25 25 #include "qvaluesaxis_p.h"
26 26 #include "qabstractseries_p.h"
27 27 #include "qabstractbarseries.h"
28 28 #include "qstackedbarseries.h"
29 29 #include "qpercentbarseries.h"
30 30 #include "qpieseries.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
35 m_domainIndex(0)
34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent)
36 35 {
37 36
38 37 }
39 38
40 39 ChartDataSet::~ChartDataSet()
41 40 {
42 41 removeAllSeries();
43 42 }
44 43
45 44 void ChartDataSet::addSeries(QAbstractSeries* series)
46 45 {
47 46 Domain* domain = m_seriesDomainMap.value(series);
48 47
49 48 if(domain) {
50 49 qWarning() << "Can not add series. Series already on the chart";
51 50 return;
52 51 }
53 52
53 domain = new Domain(series);
54 m_seriesDomainMap.insert(series,domain);
55 series->d_ptr->scaleDomain(*domain);
56
57 createSeriesIndex(series);
58
54 59 series->setParent(this); // take ownership
60 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
61 series->d_ptr->m_dataset = this;
55 62
56 domain = new Domain(series);
63 emit seriesAdded(series,domain);
64
65 }
66
67 void ChartDataSet::removeSeries(QAbstractSeries* series)
68 {
69
70 if(!m_seriesDomainMap.contains(series)) {
71 qWarning()<<"Can not remove series. Series not found on the chart.";
72 return;
73 }
74
75 emit seriesRemoved(series);
76
77 Domain* domain = m_seriesDomainMap.take(series);
78 delete domain;
79 domain = 0;
80
81 removeSeriesIndex(series);
82
83 series->setParent(0);
84 series->d_ptr->m_chart = 0;
85 series->d_ptr->m_dataset = 0;
86
87 removeAxes(series);
88 }
57 89
58 m_seriesDomainMap.insert(series,domain);
59 90
60 series->d_ptr->scaleDomain(*domain);
61 91
92 void ChartDataSet::createSeriesIndex(QAbstractSeries* series)
93 {
62 94 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
63 95
64 96 int key=0;
65 97 while (i.hasNext()) {
66 98 i.next();
67 99 if(i.key()!=key) {
68 100 break;
69 101 }
70 102 key++;
71 103 }
72 104
73 105 m_indexSeriesMap.insert(key,series);
106 }
74 107
75 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
76 series->d_ptr->m_dataset = this;
77
78 emit seriesAdded(series,domain);
79
108 void ChartDataSet::removeSeriesIndex(QAbstractSeries* series)
109 {
110 int key = seriesIndex(series);
111 Q_ASSERT(key!=-1);
112 m_indexSeriesMap.remove(key);
80 113 }
81 114
82 115 void ChartDataSet::createDefaultAxes()
83 116 {
84 117
85 118 if(m_seriesDomainMap.isEmpty()) return;
86 119
87 120 QAbstractAxis::AxisTypes typeX(0);
88 121 QAbstractAxis::AxisTypes typeY(0);
89 122
90 123 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
91 124 while (i.hasNext()) {
92 125 i.next();
93 126 removeAxes(i.key());
94 127 }
95 128
96 129 i.toFront();
97 130
98 131 while (i.hasNext()) {
99 132 i.next();
100 133 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
101 134 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
102 135 if(axisX) typeX&=axisX->type();
103 else typeX|=i.key()->d_ptr->defaultAxisXType();
136 else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal);
104 137 if(axisY) typeY&=axisY->type();
105 else typeY|=i.key()->d_ptr->defaultAxisYType();
138 else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical);
106 139 }
107 140
108
109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
110 {
111 i.toFront();
112 while (i.hasNext()) {
113 i.next();
114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
115 if(!axis) continue;
116 i.key()->d_ptr->initializeAxisX(axis);
117 addAxisX(axis,i.key());
118 emit axisAdded(axis,i.value());
119 }
120
121 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
122 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
123 i.toFront();
124 while (i.hasNext()) {
125 i.next();
126 i.key()->d_ptr->initializeAxisX(axis);
127 addAxisX(axis,i.key());
141 createAxes(typeX,Qt::Horizontal);
142 createAxes(typeY,Qt::Vertical);
128 143 }
129 emit axisAdded(axis,i.value());
130 144
131 }
145 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation)
146 {
147 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
132 148
133 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
149 if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories))
134 150 {
135 i.toFront();
136 151 while (i.hasNext()) {
137 152 i.next();
138 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
139 i.key()->d_ptr->initializeAxisY(axis);
140 addAxisY(axis,i.key());
153 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation);
154 if(!axis) continue;
155 initializeAxis(axis,i.key());
141 156 emit axisAdded(axis,i.value());
142 157 }
143 158
144 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
145 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
159 }
160 else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
161 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation);
146 162 i.toFront();
147 163 while (i.hasNext()) {
148 164 i.next();
149 i.key()->d_ptr->initializeAxisY(axis);
150 addAxisY(axis,i.key());
165 initializeAxis(axis,i.key());
151 166 }
152 167 emit axisAdded(axis,i.value());
153
154 168 }
155 169 }
156 170
157 171
158 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
172 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation)
159 173 {
160 174 QAbstractAxis* axis =0;
161 175
162 176 switch(type) {
163 177 case QAbstractAxis::AxisTypeValues:
164 178 axis = new QValuesAxis(this);
165 179 break;
166 180 case QAbstractAxis::AxisTypeCategories:
167 181 axis = new QBarCategoriesAxis(this);
168 182 break;
169 183 default:
170 184 axis = 0;
171 185 break;
172 186 }
173 187
188 if(axis)
189 axis->d_ptr->m_orientation=orientation;
190
174 191 return axis;
175 192 }
176 193
177 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
194 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
195 {
178 196 Domain* domain = m_seriesDomainMap.value(series);
179 axis->d_ptr->m_orientation=Qt::Horizontal;
180 //TODO:axis->d_ptr->initialize(domain);
197 axis->d_ptr->intializeDomain(domain);
198 series->d_ptr->initializeAxis(axis);
199 if(axis->orientation()==Qt::Horizontal) {
181 200 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
182 201 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
183 202 m_seriesAxisXMap.insert(series,axis);
184 203 }
185
186 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
187 Domain* domain = m_seriesDomainMap.value(series);
188 axis->d_ptr->m_orientation=Qt::Vertical;
189 //TODO:axis->d_ptr->initialize(domain);
204 else {
190 205 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
191 206 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
192 207 m_seriesAxisYMap.insert(series,axis);
193 208 }
194
195 void ChartDataSet::removeSeries(QAbstractSeries* series)
196 {
197 Domain* domain = m_seriesDomainMap.take(series);
198
199 if(!domain) {
200 qWarning()<<"Can not remove series. Series not found on the chart.";
201 }
202
203 emit seriesRemoved(series);
204
205 delete domain;
206 domain = 0;
207
208 int key = seriesIndex(series);
209 Q_ASSERT(key!=-1);
210
211 m_indexSeriesMap.remove(key);
212
213 series->setParent(0);
214 series->d_ptr->m_chart = 0;
215 series->d_ptr->m_dataset = 0;
216
217 removeAxes(series);
209 axis->d_ptr->emitRange();
218 210 }
219 211
220 212 void ChartDataSet::removeAxes(QAbstractSeries* series)
221 213 {
222 214 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
223 215
224 216 if(axisX) {
225 217 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
226 218 int x = axesX.indexOf(axisX);
227 219
228 220 if(x==-1) {
229 221 emit axisRemoved(axisX);
230 222 axisX->deleteLater();
231 223 }
232 224 }
233 225
234 226 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
235 227
236 228 if(axisY) {
237 229 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
238 230
239 231 int y = axesY.indexOf(axisY);
240 232
241 233 if(y==-1) {
242 234 emit axisRemoved(axisY);
243 235 axisY->deleteLater();
244 236 }
245 237 }
246 238 }
247 239
248 240 void ChartDataSet::removeAllSeries()
249 241 {
250 242 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
251 243 foreach(QAbstractSeries *s , series) {
252 244 removeSeries(s);
253 245 }
254 246
255 247 Q_ASSERT(m_seriesAxisXMap.count()==0);
256 248 Q_ASSERT(m_seriesAxisXMap.count()==0);
257 249 Q_ASSERT(m_seriesDomainMap.count()==0);
258 250
259 251 qDeleteAll(series);
260 252 }
261 253
262 254 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
263 255 {
264 256 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
265 257
266 258
267 259 blockAxisSignals(true);
268 260
269 261 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
270 262
271 263 while (i.hasNext()) {
272 264 i.next();
273 265 i.value()->zoomIn(rect,size);
274 266 }
275 267
276 268 blockAxisSignals(false);
277 269
278 270 }
279 271
280 272 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
281 273 {
282 274 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
283 275
284 276 blockAxisSignals(true);
285 277
286 278 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
287 279
288 280 while (i.hasNext()) {
289 281 i.next();
290 282 i.value()->zoomOut(rect,size);
291 283 }
292 284
293 285 blockAxisSignals(false);
294 286 }
295 287
296 288 void ChartDataSet::blockAxisSignals(bool enabled)
297 289 {
298 290 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
299 Q_UNUSED(enabled);
300 291 while (i.hasNext()) {
301 292 i.next();
302 293 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
303 294 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
304 if(axisX) axisX->d_ptr->blockSignals(true);
305 if(axisY) axisY->d_ptr->blockSignals(true);
295 if(axisX) axisX->d_ptr->blockSignals(enabled);
296 if(axisY) axisY->d_ptr->blockSignals(enabled);
306 297 }
307 298 }
308 299
309 300 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
310 301 {
311 302 int count=0;
312 303 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
313 304 while (i.hasNext()) {
314 305 i.next();
315 306 if(i.key()->type()==type) count++;
316 307 }
317 308 return count;
318 309 }
319 310
320 311 int ChartDataSet::seriesIndex(QAbstractSeries *series)
321 312 {
322 313 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
323 314 while (i.hasNext()) {
324 315 i.next();
325 316 if (i.value() == series)
326 317 return i.key();
327 318 }
328 319 return -1;
329 320 }
330 321
331 322 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
332 323 {
333 324 if(series == 0) {
334 325
335 326 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap);
336 327
337 328 while (i.hasNext()) {
338 329 i.next();
339 330 if(i.value()->isVisible()) return i.value();
340 331 }
341 332 return 0;
342 333 }
343 334 return m_seriesAxisXMap.value(series);
344 335 }
345 336
346 337 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
347 338 {
348 339 if(series == 0) {
349 340 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap);
350 341
351 342 while (i.hasNext()) {
352 343 i.next();
353 344 if(i.value()->isVisible()) return i.value();
354 345 }
355 346 return 0;
356 347 }
357 348 return m_seriesAxisYMap.value(series);
358 349 }
359 350
360 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
351 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation)
361 352 {
362 353 Q_ASSERT(axis);
354
363 355 Domain* domain = m_seriesDomainMap.value(series);
364 356
365 357 if(!domain) {
366 358 qWarning() << "Series not found on the chart.";
367 359 return;
368 360 }
369 361
370 if(axis->d_ptr->m_orientation==Qt::Vertical) {
362 if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) {
371 363 qWarning()<<"Axis already defined as axis Y";
372 364 return;
373 365 }
374 366
375 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
376 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
377
378 if(oldAxis) {
379
380 int x = axesX.indexOf(oldAxis);
381 if(x==-1) {
382 emit axisRemoved(oldAxis);
383 oldAxis->deleteLater();
384 }
385 }
386
387 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
388 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
389
390 int x = axesX.indexOf(axis);
391 if(x==-1) {
392 axis->d_ptr->m_orientation=Qt::Horizontal;
393 emit axisAdded(axis,domain);
367 if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) {
368 qWarning()<<"Axis already defined as axis X";
369 return;
394 370 }
395 371
396 m_seriesAxisXMap.insert(series,axis);
397 axis->d_ptr->emitRange();
398 }
372 axis->d_ptr->m_orientation=orientation;
399 373
400 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
401 {
402 Q_ASSERT(axis);
403 Domain* domain = m_seriesDomainMap.value(series);
374 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
404 375
405 if(!domain) {
406 qWarning() << "Series not found on the chart.";
407 return;
408 }
376 if(orientation==Qt::Vertical) {
377 seriesAxisMap= &m_seriesAxisYMap;
409 378
410 if(axis->d_ptr->m_orientation==Qt::Horizontal) {
411 qWarning()<<"Axis already defined as axis X";
412 return;
379 }else{
380 seriesAxisMap= &m_seriesAxisXMap;
413 381 }
414 382
415 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
416 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
383 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
384 QList<QAbstractAxis*> axes = seriesAxisMap->values();
417 385
418 386 if(oldAxis) {
419 int y = axesY.indexOf(oldAxis);
420 if(y==-1) {
387 if(axes.indexOf(oldAxis)==-1) {
421 388 emit axisRemoved(oldAxis);
422 389 oldAxis->deleteLater();
423 390 }
424 391 }
425 392
426 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
427 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
428
429 int y = axesY.indexOf(axis);
430 if(y==-1) {
431 axis->d_ptr->m_orientation=Qt::Vertical;
393 if(axes.indexOf(axis)==-1) {
394 initializeAxis(axis,series);
432 395 emit axisAdded(axis,domain);
396 }else{
397 initializeAxis(axis,series);
433 398 }
434
435 m_seriesAxisYMap.insert(series,axis);
436 axis->d_ptr->emitRange();
437 399 }
438 400
439 401 Domain* ChartDataSet::domain(QAbstractSeries *series) const
440 402 {
441 403 return m_seriesDomainMap.value(series);
442 404 }
443 405
444 406 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
445 407 {
446 408 blockAxisSignals(true);
447 409 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
448 410 while (i.hasNext()) {
449 411 i.next();
450 412 i.value()->move(dx,dy,size);
451 413 }
452 414 blockAxisSignals(false);
453 415 }
454 416
455 417 QList<QAbstractSeries*> ChartDataSet::series() const
456 418 {
457 419 return m_seriesDomainMap.keys();
458 420 }
459 421
460 422 void ChartDataSet::updateSeries(QAbstractSeries *series)
461 423 {
462 424 emit seriesUpdated(series);
463 425 }
464 426
465 427 #include "moc_chartdataset_p.cpp"
466 428
467 429 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,98 +1,99
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef CHARTDATASET_P_H
31 31 #define CHARTDATASET_P_H
32 32
33 33 #include "qabstractseries.h"
34 34 #include "domain_p.h"
35 35 #include "qabstractaxis_p.h"
36 36 #include <QVector>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class QAbstractAxis;
41 41
42 42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
43 43 {
44 44 Q_OBJECT
45 45 public:
46 46 ChartDataSet(QChart* parent=0);
47 47 virtual ~ChartDataSet();
48 48
49 49 void addSeries(QAbstractSeries* series);
50 50 void removeSeries(QAbstractSeries* series);
51 51 void removeAllSeries();
52 52 void updateSeries(QAbstractSeries* series);
53 53
54 54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
55 55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
56 56 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
57 57
58 58 int seriesCount(QAbstractSeries::SeriesType type);
59 59 int seriesIndex(QAbstractSeries *series);
60 60
61 61 QAbstractAxis* axisX(QAbstractSeries *series) const;
62 62 QAbstractAxis* axisY(QAbstractSeries *series) const;
63 63
64 void setAxisX(QAbstractSeries *series, QAbstractAxis *axis);
65 void setAxisY(QAbstractSeries *series, QAbstractAxis *axis);
64 void setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation);
66 65
67 66 QList<QAbstractSeries*> series() const;
68 67 Domain* domain(QAbstractSeries *series) const;
69 68
70 69 void createDefaultAxes();
71 70
72 71 Q_SIGNALS:
73 72 void seriesAdded(QAbstractSeries* series, Domain* domain);
74 73 void seriesRemoved(QAbstractSeries* series);
75 74 void seriesUpdated(QAbstractSeries* series);
76 75 void axisAdded(QAbstractAxis* axis,Domain* domain);
77 76 void axisRemoved(QAbstractAxis* axis);
78 77
79 78 private:
80 79 void calculateDomain(QAbstractSeries* series,Domain* domain);
81 QAbstractAxis* createAxis(QAbstractAxis::AxisType type);
82 void addAxisX(QAbstractAxis* axis,QAbstractSeries* series);
83 void addAxisY(QAbstractAxis* axis,QAbstractSeries* series);
80 void createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation);
81 QAbstractAxis* createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation);
82 void initializeAxis(QAbstractAxis* axis,QAbstractSeries* series);
84 83 void removeAxes(QAbstractSeries* series);
85 84 void blockAxisSignals(bool enabled);
85 void createSeriesIndex(QAbstractSeries* series);
86 void removeSeriesIndex(QAbstractSeries* series);
86 87
87 88 private:
88 89 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
89 90 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
90 91 QMap<QAbstractSeries*, Domain*> m_seriesDomainMap;
91 92 QMap<int, QAbstractSeries*> m_indexSeriesMap;
92 93 int m_domainIndex;
93 94
94 95 };
95 96
96 97 QTCOMMERCIALCHART_END_NAMESPACE
97 98
98 99 #endif /* CHARTENGINE_P_H_ */
@@ -1,816 +1,807
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpieseries.h"
22 22 #include "qpieseries_p.h"
23 23 #include "qpieslice.h"
24 24 #include "qpieslice_p.h"
25 25 #include "pieslicedata_p.h"
26 26 #include "chartdataset_p.h"
27 27 #include "charttheme_p.h"
28 28 #include "chartanimator_p.h"
29 29 #include "legendmarker_p.h"
30 30 #include "qabstractaxis.h"
31 31
32 32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 33
34 34 /*!
35 35 \class QPieSeries
36 36 \brief Pie series API for QtCommercial Charts
37 37
38 38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 40 The actual slice size is determined by that relative value.
41 41
42 42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
43 43 These relate to the actual chart rectangle.
44 44
45 45 By default the pie is defined as a full pie but it can also be a partial pie.
46 46 This can be done by setting a starting angle and angle span to the series.
47 47 Full pie is 360 degrees where 0 is at 12 a'clock.
48 48
49 49 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
50 50 \image examples_piechart.png
51 51 */
52 52 /*!
53 53 \qmlclass PieSeries QPieSeries
54 54 \inherits AbstractSeries
55 55
56 56 The following QML shows how to create a simple pie chart.
57 57
58 58 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
59 59
60 60 \beginfloatleft
61 61 \image demos_qmlchart1.png
62 62 \endfloat
63 63 \clearfloat
64 64 */
65 65
66 66 /*!
67 67 \property QPieSeries::horizontalPosition
68 68 \brief Defines the horizontal position of the pie.
69 69
70 70 The value is a relative value to the chart rectangle where:
71 71
72 72 \list
73 73 \o 0.0 is the absolute left.
74 74 \o 1.0 is the absolute right.
75 75 \endlist
76 76 Default value is 0.5 (center).
77 77 \sa verticalPosition
78 78 */
79 79
80 80 /*!
81 81 \qmlproperty real PieSeries::horizontalPosition
82 82
83 83 Defines the horizontal position of the pie.
84 84
85 85 The value is a relative value to the chart rectangle where:
86 86
87 87 \list
88 88 \o 0.0 is the absolute left.
89 89 \o 1.0 is the absolute right.
90 90 \endlist
91 91 Default value is 0.5 (center).
92 92 \sa verticalPosition
93 93 */
94 94
95 95 /*!
96 96 \property QPieSeries::verticalPosition
97 97 \brief Defines the vertical position of the pie.
98 98
99 99 The value is a relative value to the chart rectangle where:
100 100
101 101 \list
102 102 \o 0.0 is the absolute top.
103 103 \o 1.0 is the absolute bottom.
104 104 \endlist
105 105 Default value is 0.5 (center).
106 106 \sa horizontalPosition
107 107 */
108 108
109 109 /*!
110 110 \qmlproperty real PieSeries::verticalPosition
111 111
112 112 Defines the vertical position of the pie.
113 113
114 114 The value is a relative value to the chart rectangle where:
115 115
116 116 \list
117 117 \o 0.0 is the absolute top.
118 118 \o 1.0 is the absolute bottom.
119 119 \endlist
120 120 Default value is 0.5 (center).
121 121 \sa horizontalPosition
122 122 */
123 123
124 124 /*!
125 125 \property QPieSeries::size
126 126 \brief Defines the pie size.
127 127
128 128 The value is a relative value to the chart rectangle where:
129 129
130 130 \list
131 131 \o 0.0 is the minimum size (pie not drawn).
132 132 \o 1.0 is the maximum size that can fit the chart.
133 133 \endlist
134 134
135 135 Default value is 0.7.
136 136 */
137 137
138 138 /*!
139 139 \qmlproperty real PieSeries::size
140 140
141 141 Defines the pie size.
142 142
143 143 The value is a relative value to the chart rectangle where:
144 144
145 145 \list
146 146 \o 0.0 is the minimum size (pie not drawn).
147 147 \o 1.0 is the maximum size that can fit the chart.
148 148 \endlist
149 149
150 150 Default value is 0.7.
151 151 */
152 152
153 153 /*!
154 154 \property QPieSeries::startAngle
155 155 \brief Defines the starting angle of the pie.
156 156
157 157 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
158 158
159 159 Default is value is 0.
160 160 */
161 161
162 162 /*!
163 163 \qmlproperty real PieSeries::startAngle
164 164
165 165 Defines the starting angle of the pie.
166 166
167 167 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
168 168
169 169 Default is value is 0.
170 170 */
171 171
172 172 /*!
173 173 \property QPieSeries::endAngle
174 174 \brief Defines the ending angle of the pie.
175 175
176 176 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
177 177
178 178 Default is value is 360.
179 179 */
180 180
181 181 /*!
182 182 \qmlproperty real PieSeries::endAngle
183 183
184 184 Defines the ending angle of the pie.
185 185
186 186 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
187 187
188 188 Default is value is 360.
189 189 */
190 190
191 191 /*!
192 192 \property QPieSeries::count
193 193
194 194 Number of slices in the series.
195 195 */
196 196
197 197 /*!
198 198 \qmlproperty int PieSeries::count
199 199
200 200 Number of slices in the series.
201 201 */
202 202
203 203 /*!
204 204 \fn void QPieSeries::countChanged()
205 205 Emitted when the slice count has changed.
206 206 \sa count
207 207 */
208 208 /*!
209 209 \qmlsignal PieSeries::onCountChanged()
210 210 Emitted when the slice count has changed.
211 211 */
212 212
213 213 /*!
214 214 \property QPieSeries::sum
215 215
216 216 Sum of all slices.
217 217
218 218 The series keeps track of the sum of all slices it holds.
219 219 */
220 220
221 221 /*!
222 222 \qmlproperty real PieSeries::sum
223 223
224 224 Sum of all slices.
225 225
226 226 The series keeps track of the sum of all slices it holds.
227 227 */
228 228
229 229 /*!
230 230 \fn void QPieSeries::sumChanged()
231 231 Emitted when the sum of all slices has changed.
232 232 \sa sum
233 233 */
234 234 /*!
235 235 \qmlsignal PieSeries::onSumChanged()
236 236 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
237 237 change value of a slice.
238 238 */
239 239
240 240 /*!
241 241 \fn void QPieSeries::added(QList<QPieSlice*> slices)
242 242
243 243 This signal is emitted when \a slices have been added to the series.
244 244
245 245 \sa append(), insert()
246 246 */
247 247 /*!
248 248 \qmlsignal PieSeries::onAdded(PieSlice slice)
249 249 Emitted when \a slice has been added to the series.
250 250 */
251 251
252 252 /*!
253 253 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
254 254 This signal is emitted when \a slices have been removed from the series.
255 255 \sa remove()
256 256 */
257 257 /*!
258 258 \qmlsignal PieSeries::onRemoved(PieSlice slice)
259 259 Emitted when \a slice has been removed from the series.
260 260 */
261 261
262 262 /*!
263 263 \fn void QPieSeries::clicked(QPieSlice* slice)
264 264 This signal is emitted when a \a slice has been clicked.
265 265 \sa QPieSlice::clicked()
266 266 */
267 267 /*!
268 268 \qmlsignal PieSeries::onClicked(PieSlice slice)
269 269 This signal is emitted when a \a slice has been clicked.
270 270 */
271 271
272 272 /*!
273 273 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
274 274 This signal is emitted when user has hovered over or away from the \a slice.
275 275 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
276 276 \sa QPieSlice::hovered()
277 277 */
278 278 /*!
279 279 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
280 280 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
281 281 over the slice and false when hover has moved away from the slice.
282 282 */
283 283
284 284 /*!
285 285 \qmlmethod PieSlice PieSeries::at(int index)
286 286 Returns slice at \a index. Returns null if the index is not valid.
287 287 */
288 288
289 289 /*!
290 290 \qmlmethod PieSlice PieSeries::find(string label)
291 291 Returns the first slice with \a label. Returns null if the index is not valid.
292 292 */
293 293
294 294 /*!
295 295 \qmlmethod PieSlice PieSeries::append(string label, real value)
296 296 Adds a new slice with \a label and \a value to the pie.
297 297 */
298 298
299 299 /*!
300 300 \qmlmethod bool PieSeries::remove(PieSlice slice)
301 301 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
302 302 */
303 303
304 304 /*!
305 305 \qmlmethod PieSeries::clear()
306 306 Removes all slices from the pie.
307 307 */
308 308
309 309 /*!
310 310 Constructs a series object which is a child of \a parent.
311 311 */
312 312 QPieSeries::QPieSeries(QObject *parent) :
313 313 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
314 314 {
315 315
316 316 }
317 317
318 318 /*!
319 319 Destroys the series and its slices.
320 320 */
321 321 QPieSeries::~QPieSeries()
322 322 {
323 323 // NOTE: d_prt destroyed by QObject
324 324 }
325 325
326 326 /*!
327 327 Returns QChartSeries::SeriesTypePie.
328 328 */
329 329 QAbstractSeries::SeriesType QPieSeries::type() const
330 330 {
331 331 return QAbstractSeries::SeriesTypePie;
332 332 }
333 333
334 334 /*!
335 335 Appends a single \a slice to the series.
336 336 Slice ownership is passed to the series.
337 337
338 338 Returns true if append was succesfull.
339 339 */
340 340 bool QPieSeries::append(QPieSlice* slice)
341 341 {
342 342 return append(QList<QPieSlice*>() << slice);
343 343 }
344 344
345 345 /*!
346 346 Appends an array of \a slices to the series.
347 347 Slice ownership is passed to the series.
348 348
349 349 Returns true if append was successfull.
350 350 */
351 351 bool QPieSeries::append(QList<QPieSlice*> slices)
352 352 {
353 353 Q_D(QPieSeries);
354 354
355 355 if (slices.count() == 0)
356 356 return false;
357 357
358 358 foreach (QPieSlice* s, slices) {
359 359 if (!s || d->m_slices.contains(s))
360 360 return false;
361 361 if (s->series()) // already added to some series
362 362 return false;
363 363 }
364 364
365 365 foreach (QPieSlice* s, slices) {
366 366 s->setParent(this);
367 367 QPieSlicePrivate::fromSlice(s)->m_series = this;
368 368 d->m_slices << s;
369 369 }
370 370
371 371 d->updateDerivativeData();
372 372
373 373 foreach (QPieSlice* s, slices) {
374 374 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
375 375 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
376 376 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
377 377 }
378 378
379 379 emit added(slices);
380 380 emit countChanged();
381 381
382 382 return true;
383 383 }
384 384
385 385 /*!
386 386 Appends a single \a slice to the series and returns a reference to the series.
387 387 Slice ownership is passed to the series.
388 388 */
389 389 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
390 390 {
391 391 append(slice);
392 392 return *this;
393 393 }
394 394
395 395
396 396 /*!
397 397 Appends a single slice to the series with give \a value and \a label.
398 398 Slice ownership is passed to the series.
399 399 */
400 400 QPieSlice* QPieSeries::append(QString label, qreal value)
401 401 {
402 402 QPieSlice* slice = new QPieSlice(label, value);
403 403 append(slice);
404 404 return slice;
405 405 }
406 406
407 407 /*!
408 408 Inserts a single \a slice to the series before the slice at \a index position.
409 409 Slice ownership is passed to the series.
410 410
411 411 Returns true if insert was successfull.
412 412 */
413 413 bool QPieSeries::insert(int index, QPieSlice* slice)
414 414 {
415 415 Q_D(QPieSeries);
416 416
417 417 if (index < 0 || index > d->m_slices.count())
418 418 return false;
419 419
420 420 if (!slice || d->m_slices.contains(slice))
421 421 return false;
422 422
423 423 if (slice->series()) // already added to some series
424 424 return false;
425 425
426 426 slice->setParent(this);
427 427 QPieSlicePrivate::fromSlice(slice)->m_series = this;
428 428 d->m_slices.insert(index, slice);
429 429
430 430 d->updateDerivativeData();
431 431
432 432 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
433 433 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
434 434 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
435 435
436 436 emit added(QList<QPieSlice*>() << slice);
437 437 emit countChanged();
438 438
439 439 return true;
440 440 }
441 441
442 442 /*!
443 443 Removes a single \a slice from the series and deletes the slice.
444 444
445 445 Do not reference the pointer after this call.
446 446
447 447 Returns true if remove was successfull.
448 448 */
449 449 bool QPieSeries::remove(QPieSlice* slice)
450 450 {
451 451 Q_D(QPieSeries);
452 452
453 453 if (!d->m_slices.removeOne(slice))
454 454 return false;
455 455
456 456 d->updateDerivativeData();
457 457
458 458 emit removed(QList<QPieSlice*>() << slice);
459 459 emit countChanged();
460 460
461 461 delete slice;
462 462 slice = 0;
463 463
464 464 return true;
465 465 }
466 466
467 467 /*!
468 468 Clears all slices from the series.
469 469 */
470 470 void QPieSeries::clear()
471 471 {
472 472 Q_D(QPieSeries);
473 473 if (d->m_slices.count() == 0)
474 474 return;
475 475
476 476 QList<QPieSlice*> slices = d->m_slices;
477 477 foreach (QPieSlice* s, d->m_slices) {
478 478 d->m_slices.removeOne(s);
479 479 delete s;
480 480 }
481 481
482 482 d->updateDerivativeData();
483 483
484 484 emit removed(slices);
485 485 emit countChanged();
486 486 }
487 487
488 488 /*!
489 489 Returns a list of slices that belong to this series.
490 490 */
491 491 QList<QPieSlice*> QPieSeries::slices() const
492 492 {
493 493 Q_D(const QPieSeries);
494 494 return d->m_slices;
495 495 }
496 496
497 497 /*!
498 498 returns the number of the slices in this series.
499 499 */
500 500 int QPieSeries::count() const
501 501 {
502 502 Q_D(const QPieSeries);
503 503 return d->m_slices.count();
504 504 }
505 505
506 506 /*!
507 507 Returns true is the series is empty.
508 508 */
509 509 bool QPieSeries::isEmpty() const
510 510 {
511 511 Q_D(const QPieSeries);
512 512 return d->m_slices.isEmpty();
513 513 }
514 514
515 515 /*!
516 516 Returns the sum of all slice values in this series.
517 517
518 518 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
519 519 */
520 520 qreal QPieSeries::sum() const
521 521 {
522 522 Q_D(const QPieSeries);
523 523 return d->m_sum;
524 524 }
525 525
526 526 void QPieSeries::setDonut(bool donut)
527 527 {
528 528 Q_D(QPieSeries);
529 529 d->m_donutChart = donut;
530 530 d->updateDerivativeData();
531 531 }
532 532
533 533 bool QPieSeries::donut() const
534 534 {
535 535 Q_D(const QPieSeries);
536 536 return d->m_donutChart;
537 537 }
538 538
539 539 void QPieSeries::setDonutInnerSize(qreal innerSize)
540 540 {
541 541 Q_D(QPieSeries);
542 542
543 543 if (innerSize < 0.0)
544 544 innerSize = 0.0;
545 545 if (innerSize > 1.0)
546 546 innerSize = 1.0;
547 547
548 548 d->m_donutRelativeInnerSize = innerSize;
549 549 d->updateDerivativeData();
550 550 emit d->pieSizeChanged();
551 551 }
552 552
553 553 qreal QPieSeries::donutInnerSize() const
554 554 {
555 555 Q_D(const QPieSeries);
556 556 return d->m_donutRelativeInnerSize;
557 557 }
558 558
559 559 void QPieSeries::setHorizontalPosition(qreal relativePosition)
560 560 {
561 561 Q_D(QPieSeries);
562 562
563 563 if (relativePosition < 0.0)
564 564 relativePosition = 0.0;
565 565 if (relativePosition > 1.0)
566 566 relativePosition = 1.0;
567 567
568 568 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
569 569 d->m_pieRelativeHorPos = relativePosition;
570 570 emit d->horizontalPositionChanged();
571 571 }
572 572 }
573 573
574 574 qreal QPieSeries::horizontalPosition() const
575 575 {
576 576 Q_D(const QPieSeries);
577 577 return d->m_pieRelativeHorPos;
578 578 }
579 579
580 580 void QPieSeries::setVerticalPosition(qreal relativePosition)
581 581 {
582 582 Q_D(QPieSeries);
583 583
584 584 if (relativePosition < 0.0)
585 585 relativePosition = 0.0;
586 586 if (relativePosition > 1.0)
587 587 relativePosition = 1.0;
588 588
589 589 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
590 590 d->m_pieRelativeVerPos = relativePosition;
591 591 emit d->verticalPositionChanged();
592 592 }
593 593 }
594 594
595 595 qreal QPieSeries::verticalPosition() const
596 596 {
597 597 Q_D(const QPieSeries);
598 598 return d->m_pieRelativeVerPos;
599 599 }
600 600
601 601 void QPieSeries::setPieSize(qreal relativeSize)
602 602 {
603 603 Q_D(QPieSeries);
604 604
605 605 if (relativeSize < 0.0)
606 606 relativeSize = 0.0;
607 607 if (relativeSize > 1.0)
608 608 relativeSize = 1.0;
609 609
610 610 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
611 611 d->m_pieRelativeSize = relativeSize;
612 612 emit d->pieSizeChanged();
613 613 }
614 614 }
615 615
616 616 qreal QPieSeries::pieSize() const
617 617 {
618 618 Q_D(const QPieSeries);
619 619 return d->m_pieRelativeSize;
620 620 }
621 621
622 622
623 623 void QPieSeries::setPieStartAngle(qreal angle)
624 624 {
625 625 Q_D(QPieSeries);
626 626 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
627 627 return;
628 628 d->m_pieStartAngle = angle;
629 629 d->updateDerivativeData();
630 630 emit d->pieStartAngleChanged();
631 631 }
632 632
633 633 qreal QPieSeries::pieStartAngle() const
634 634 {
635 635 Q_D(const QPieSeries);
636 636 return d->m_pieStartAngle;
637 637 }
638 638
639 639 /*!
640 640 Sets the end angle of the pie.
641 641
642 642 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
643 643
644 644 \a angle must be greater than start angle.
645 645
646 646 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
647 647 */
648 648 void QPieSeries::setPieEndAngle(qreal angle)
649 649 {
650 650 Q_D(QPieSeries);
651 651 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
652 652 return;
653 653 d->m_pieEndAngle = angle;
654 654 d->updateDerivativeData();
655 655 emit d->pieEndAngleChanged();
656 656 }
657 657
658 658 /*!
659 659 Returns the end angle of the pie.
660 660
661 661 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
662 662
663 663 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
664 664 */
665 665 qreal QPieSeries::pieEndAngle() const
666 666 {
667 667 Q_D(const QPieSeries);
668 668 return d->m_pieEndAngle;
669 669 }
670 670
671 671 /*!
672 672 Sets the all the slice labels \a visible or invisible.
673 673
674 674 Note that this affects only the current slices in the series.
675 675 If user adds a new slice the default label visibility is false.
676 676
677 677 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
678 678 */
679 679 void QPieSeries::setLabelsVisible(bool visible)
680 680 {
681 681 Q_D(QPieSeries);
682 682 foreach (QPieSlice* s, d->m_slices)
683 683 s->setLabelVisible(visible);
684 684 }
685 685
686 686 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
687 687
688 688
689 689 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
690 690 QAbstractSeriesPrivate(parent),
691 691 m_pieRelativeHorPos(0.5),
692 692 m_pieRelativeVerPos(0.5),
693 693 m_pieRelativeSize(0.7),
694 694 m_pieStartAngle(0),
695 695 m_pieEndAngle(360),
696 696 m_sum(0),
697 697 m_donutChart(false),
698 698 m_donutRelativeInnerSize(0.5)
699 699 {
700 700 }
701 701
702 702 QPieSeriesPrivate::~QPieSeriesPrivate()
703 703 {
704 704 }
705 705
706 706 void QPieSeriesPrivate::updateDerivativeData()
707 707 {
708 708 // calculate sum of all slices
709 709 qreal sum = 0;
710 710 foreach (QPieSlice* s, m_slices)
711 711 sum += s->value();
712 712
713 713 if (!qFuzzyIsNull(m_sum - sum)) {
714 714 m_sum = sum;
715 715 emit q_func()->sumChanged();
716 716 }
717 717
718 718 // nothing to show..
719 719 if (qFuzzyIsNull(m_sum))
720 720 return;
721 721
722 722 // update slice attributes
723 723 qreal sliceAngle = m_pieStartAngle;
724 724 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
725 725 QVector<QPieSlice*> changed;
726 726 foreach (QPieSlice* s, m_slices) {
727 727 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
728 728 d->setPercentage(s->value() / m_sum);
729 729 d->setStartAngle(sliceAngle);
730 730 d->setAngleSpan(pieSpan * s->percentage());
731 731 sliceAngle += s->angleSpan();
732 732 }
733 733
734 734
735 735 emit calculatedDataChanged();
736 736 }
737 737
738 738 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
739 739 {
740 740 return series->d_func();
741 741 }
742 742
743 743 void QPieSeriesPrivate::sliceValueChanged()
744 744 {
745 745 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
746 746 updateDerivativeData();
747 747 }
748 748
749 749 void QPieSeriesPrivate::sliceClicked()
750 750 {
751 751 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
752 752 Q_ASSERT(m_slices.contains(slice));
753 753 Q_Q(QPieSeries);
754 754 emit q->clicked(slice);
755 755 }
756 756
757 757 void QPieSeriesPrivate::sliceHovered(bool state)
758 758 {
759 759 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
760 760 Q_ASSERT(m_slices.contains(slice));
761 761 Q_Q(QPieSeries);
762 762 emit q->hovered(slice, state);
763 763 }
764 764
765 765 void QPieSeriesPrivate::scaleDomain(Domain& domain)
766 766 {
767 767 Q_UNUSED(domain);
768 768 // does not apply to pie
769 769 }
770 770
771 771 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
772 772 {
773 773 Q_Q(QPieSeries);
774 774 PieChartItem* pie = new PieChartItem(q,presenter);
775 775 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
776 776 presenter->animator()->addAnimation(pie);
777 777 }
778 778 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
779 779 return pie;
780 780 }
781 781
782 782 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
783 783 {
784 784 Q_Q(QPieSeries);
785 785 QList<LegendMarker*> markers;
786 786 foreach(QPieSlice* slice, q->slices()) {
787 787 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
788 788 markers << marker;
789 789 }
790 790 return markers;
791 791 }
792 792
793 void QPieSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
793 void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis)
794 794 {
795 795 Q_UNUSED(axis);
796 796 }
797 797
798 void QPieSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
799 {
800 Q_UNUSED(axis);
801 }
802
803 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisXType() const
804 {
805 return QAbstractAxis::AxisTypeNoAxis;
806 }
807
808 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisYType() const
798 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
809 799 {
800 Q_UNUSED(orientation);
810 801 return QAbstractAxis::AxisTypeNoAxis;
811 802 }
812 803
813 804 #include "moc_qpieseries.cpp"
814 805 #include "moc_qpieseries_p.cpp"
815 806
816 807 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,90 +1,88
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QPIESERIES_P_H
31 31 #define QPIESERIES_P_H
32 32
33 33 #include "qpieseries.h"
34 34 #include "qabstractseries_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37 class QLegendPrivate;
38 38
39 39 class QPieSeriesPrivate : public QAbstractSeriesPrivate
40 40 {
41 41 Q_OBJECT
42 42
43 43 public:
44 44 QPieSeriesPrivate(QPieSeries *parent);
45 45 ~QPieSeriesPrivate();
46 46
47 47 void scaleDomain(Domain& domain);
48 48 Chart* createGraphics(ChartPresenter *presenter);
49 49 QList<LegendMarker*> createLegendMarker(QLegend *legend);
50 void initializeAxisX(QAbstractAxis* axis);
51 void initializeAxisY(QAbstractAxis* axis);
52 QAbstractAxis::AxisType defaultAxisXType() const;
53 QAbstractAxis::AxisType defaultAxisYType() const;
50 void initializeAxis(QAbstractAxis* axis);
51 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
54 52
55 53 void updateDerivativeData();
56 54
57 55 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
58 56
59 57 signals:
60 58 void calculatedDataChanged();
61 59 void pieSizeChanged();
62 60 void pieStartAngleChanged();
63 61 void pieEndAngleChanged();
64 62 void horizontalPositionChanged();
65 63 void verticalPositionChanged();
66 64
67 65 public Q_SLOTS:
68 66 void sliceValueChanged();
69 67 void sliceClicked();
70 68 void sliceHovered(bool state);
71 69
72 70 private:
73 71 QList<QPieSlice*> m_slices;
74 72 qreal m_pieRelativeHorPos;
75 73 qreal m_pieRelativeVerPos;
76 74 qreal m_pieRelativeSize;
77 75 qreal m_pieStartAngle;
78 76 qreal m_pieEndAngle;
79 77 qreal m_sum;
80 78 bool m_donutChart;
81 79 qreal m_donutRelativeInnerSize;
82 80
83 81 private:
84 82 friend class QLegendPrivate;
85 83 Q_DECLARE_PUBLIC(QPieSeries)
86 84 };
87 85
88 86 QTCOMMERCIALCHART_END_NAMESPACE
89 87
90 88 #endif // QPIESERIES_P_H
@@ -1,73 +1,71
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QABSTRACTSERIES_P_H
31 31 #define QABSTRACTSERIES_P_H
32 32
33 33 #include "qabstractseries.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class Domain;
38 38 class ChartPresenter;
39 39 class Chart;
40 40 class LegendMarker;
41 41 class QLegend;
42 42 class ChartDataSet;
43 43 class QAbstractAxis;
44 44
45 45 class QAbstractSeriesPrivate : public QObject
46 46 {
47 47 Q_OBJECT
48 48 public:
49 49 QAbstractSeriesPrivate(QAbstractSeries *q);
50 50 ~QAbstractSeriesPrivate();
51 51
52 52 virtual void scaleDomain(Domain& domain) = 0;
53 53 virtual Chart* createGraphics(ChartPresenter* presenter) = 0;
54 54 virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0;
55 virtual void initializeAxisX(QAbstractAxis* axis) = 0;
56 virtual void initializeAxisY(QAbstractAxis* axis) = 0;
57 virtual QAbstractAxis::AxisType defaultAxisXType() const = 0;
58 virtual QAbstractAxis::AxisType defaultAxisYType() const = 0;
55 virtual void initializeAxis(QAbstractAxis* axis) = 0;
56 virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0;
59 57
60 58 protected:
61 59 QAbstractSeries *q_ptr;
62 60 QChart *m_chart;
63 61 ChartDataSet *m_dataset;
64 62 QString m_name;
65 63 bool m_visible;
66 64
67 65 friend class QAbstractSeries;
68 66 friend class ChartDataSet;
69 67 };
70 68
71 69 QTCOMMERCIALCHART_END_NAMESPACE
72 70
73 71 #endif
@@ -1,504 +1,504
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "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 <QGraphicsScene>
28 28 #include <QGraphicsSceneResizeEvent>
29 29 #include <QGraphicsLayout>
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 /*!
34 34 \enum QChart::ChartTheme
35 35
36 36 This enum describes the theme used by the chart.
37 37
38 38 \value ChartThemeLight The default theme
39 39 \value ChartThemeBlueCerulean
40 40 \value ChartThemeDark
41 41 \value ChartThemeBrownSand
42 42 \value ChartThemeBlueNcs
43 43 \value ChartThemeHighContrast
44 44 \value ChartThemeBlueIcy
45 45 */
46 46
47 47 /*!
48 48 \enum QChart::AnimationOption
49 49
50 50 For enabling/disabling animations. Defaults to NoAnimation.
51 51
52 52 \value NoAnimation
53 53 \value GridAxisAnimations
54 54 \value SeriesAnimations
55 55 \value AllAnimations
56 56 */
57 57
58 58 /*!
59 59 \class QChart
60 60 \brief QtCommercial chart API.
61 61
62 62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 63 representation of different types of series and other chart related objects like
64 64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 65 convenience class QChartView instead of QChart.
66 66 \sa QChartView
67 67 */
68 68
69 69 /*!
70 70 \property QChart::animationOptions
71 71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 72 */
73 73
74 74 /*!
75 75 \property QChart::backgroundVisible
76 76 Whether the chart background is visible or not.
77 77 \sa setBackgroundBrush(), setBackgroundPen()
78 78 */
79 79
80 80 /*!
81 81 \property QChart::dropShadowEnabled
82 82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
84 84 */
85 85
86 86 /*!
87 87 \property QChart::margins
88 88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
89 89 */
90 90
91 91 /*!
92 92 \property QChart::theme
93 93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 95 different themes.
96 96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 97 */
98 98
99 99 /*!
100 100 \property QChart::title
101 101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
102 102 */
103 103
104 104 /*!
105 105 \fn void QChart::marginsChanged(QRectF newMargins)
106 106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
107 107 modify axes or hide/show legend.
108 108 */
109 109
110 110 /*!
111 111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
112 112 */
113 113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
114 114 d_ptr(new QChartPrivate())
115 115 {
116 116 d_ptr->m_dataset = new ChartDataSet(this);
117 117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
118 118 d_ptr->createConnections();
119 119 d_ptr->m_legend = new LegendScroller(this);
120 120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
121 121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
122 122 setLayout(d_ptr->m_presenter->layout());
123 123 }
124 124
125 125 /*!
126 126 Destroys the object and it's children, like series and axis objects added to it.
127 127 */
128 128 QChart::~QChart()
129 129 {
130 130 //delete first presenter , since this is a root of all the graphical items
131 131 setLayout(0);
132 132 delete d_ptr->m_presenter;
133 133 d_ptr->m_presenter=0;
134 134 }
135 135
136 136 /*!
137 137 Adds the \a series onto the chart and takes the ownership of the object.
138 138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 139 the y axis).
140 140
141 141 \sa removeSeries(), removeAllSeries()
142 142 */
143 143 void QChart::addSeries(QAbstractSeries *series)
144 144 {
145 145 Q_ASSERT(series);
146 146 d_ptr->m_dataset->addSeries(series);
147 147 }
148 148
149 149 /*!
150 150 Removes the \a series specified in a perameter from the QChartView.
151 151 It releses its ownership of the specified QChartSeries object.
152 152 It does not delete the pointed QChartSeries data object
153 153 \sa addSeries(), removeAllSeries()
154 154 */
155 155 void QChart::removeSeries(QAbstractSeries *series)
156 156 {
157 157 Q_ASSERT(series);
158 158 d_ptr->m_dataset->removeSeries(series);
159 159 }
160 160
161 161 /*!
162 162 Removes all the QChartSeries that have been added to the QChartView
163 163 It also deletes the pointed QChartSeries data objects
164 164 \sa addSeries(), removeSeries()
165 165 */
166 166 void QChart::removeAllSeries()
167 167 {
168 168 d_ptr->m_dataset->removeAllSeries();
169 169 }
170 170
171 171 /*!
172 172 Sets the \a brush that is used for painting the background of the chart area.
173 173 */
174 174 void QChart::setBackgroundBrush(const QBrush& brush)
175 175 {
176 176 d_ptr->m_presenter->setBackgroundBrush(brush);
177 177 }
178 178
179 179 /*!
180 180 Gets the brush that is used for painting the background of the chart area.
181 181 */
182 182 QBrush QChart::backgroundBrush() const
183 183 {
184 184 return d_ptr->m_presenter->backgroundBrush();
185 185 }
186 186
187 187 /*!
188 188 Sets the \a pen that is used for painting the background of the chart area.
189 189 */
190 190 void QChart::setBackgroundPen(const QPen& pen)
191 191 {
192 192 d_ptr->m_presenter->setBackgroundPen(pen);
193 193 }
194 194
195 195 /*!
196 196 Gets the pen that is used for painting the background of the chart area.
197 197 */
198 198 QPen QChart::backgroundPen() const
199 199 {
200 200 return d_ptr->m_presenter->backgroundPen();
201 201 }
202 202
203 203 /*!
204 204 Sets the chart \a title. The description text that is drawn above the chart.
205 205 */
206 206 void QChart::setTitle(const QString& title)
207 207 {
208 208 d_ptr->m_presenter->setTitle(title);
209 209 }
210 210
211 211 /*!
212 212 Returns the chart title. The description text that is drawn above the chart.
213 213 */
214 214 QString QChart::title() const
215 215 {
216 216 return d_ptr->m_presenter->title();
217 217 }
218 218
219 219 /*!
220 220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 221 */
222 222 void QChart::setTitleFont(const QFont& font)
223 223 {
224 224 d_ptr->m_presenter->setTitleFont(font);
225 225 }
226 226
227 227 /*!
228 228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 229 */
230 230 QFont QChart::titleFont() const
231 231 {
232 232 return d_ptr->m_presenter->titleFont();
233 233 }
234 234
235 235 /*!
236 236 Sets the \a brush used for rendering the title text.
237 237 */
238 238 void QChart::setTitleBrush(const QBrush &brush)
239 239 {
240 240 d_ptr->m_presenter->setTitleBrush(brush);
241 241 }
242 242
243 243 /*!
244 244 Returns the brush used for rendering the title text.
245 245 */
246 246 QBrush QChart::titleBrush() const
247 247 {
248 248 return d_ptr->m_presenter->titleBrush();
249 249 }
250 250
251 251 void QChart::setTheme(QChart::ChartTheme theme)
252 252 {
253 253 d_ptr->m_presenter->setTheme(theme);
254 254 }
255 255
256 256 QChart::ChartTheme QChart::theme() const
257 257 {
258 258 return d_ptr->m_presenter->theme();
259 259 }
260 260
261 261 /*!
262 262 Zooms in the view by a factor of 2
263 263 */
264 264 void QChart::zoomIn()
265 265 {
266 266 d_ptr->m_presenter->zoomIn(2.0);
267 267 }
268 268
269 269 /*!
270 270 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 271 */
272 272 void QChart::zoomIn(const QRectF& rect)
273 273 {
274 274 if (!rect.isValid()) return;
275 275 d_ptr->m_presenter->zoomIn(rect);
276 276 }
277 277
278 278 /*!
279 279 Restores the view zoom level to the previous one.
280 280 */
281 281 void QChart::zoomOut()
282 282 {
283 283 d_ptr->m_presenter->zoomOut(2.0);
284 284 }
285 285
286 286 /*!
287 287 Zooms in the view by a \a factor.
288 288
289 289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 290 */
291 291 void QChart::zoom(qreal factor)
292 292 {
293 293 if (qFuzzyIsNull(factor))
294 294 return;
295 295
296 296 if (qFuzzyCompare(factor, (qreal)1.0))
297 297 return;
298 298
299 299 if (factor < 0)
300 300 return;
301 301
302 302 if (factor > 1.0)
303 303 d_ptr->m_presenter->zoomIn(factor);
304 304 else
305 305 d_ptr->m_presenter->zoomOut(1.0 / factor);
306 306 }
307 307
308 308 /*!
309 309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
310 310 If no series is provided then pointer to currently visible axis is provided
311 311 */
312 312 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
313 313 {
314 314 return d_ptr->m_dataset->axisX(series);
315 315 }
316 316
317 317 /*!
318 318 Returns the pointer to the y axis object of the chart asociated with the specified \a series
319 319 If no series is provided then pointer to currently visible axis is provided
320 320 */
321 321 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
322 322 {
323 323 return d_ptr->m_dataset->axisY(series);
324 324 }
325 325
326 326 /*!
327 327 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
328 328
329 329 Creates the axes for the chart based on the series that has already been added to the chart.
330 330
331 331 \table
332 332 \header
333 333 \o Series type
334 334 \o X-axis
335 335 \o Y-axis
336 336 \row
337 337 \o QXYSeries
338 338 \o QValuesAxis
339 339 \o QValuesAxis
340 340 \row
341 341 \o QBarSeries
342 342 \o QBarCategoriesAxis
343 343 \o QValuesAxis
344 344 \row
345 345 \o QPieSeries
346 346 \o None
347 347 \o None
348 348 \endtable
349 349
350 350 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
351 351 If there are sevaral series added of different types then each series gets its own axes pair.
352 352
353 353 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
354 354
355 355 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
356 356 QPieSeries does not create any axes.
357 357
358 358 \sa axisX(), axisY(), setAxisX(), setAxisY()
359 359 */
360 360 void QChart::createDefaultAxes()
361 361 {
362 362 d_ptr->m_dataset->createDefaultAxes();
363 363 }
364 364
365 365 /*!
366 366 Returns the legend object of the chart. Ownership stays in chart.
367 367 */
368 368 QLegend* QChart::legend() const
369 369 {
370 370 return d_ptr->m_legend;
371 371 }
372 372
373 373 /*!
374 374 Returns the rect that contains information about margins (distance between chart widget edge and axes).
375 375 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
376 376 */
377 377 QRectF QChart::margins() const
378 378 {
379 379 return d_ptr->m_presenter->margins();
380 380 }
381 381
382 382 /*!
383 383 Returns the the rect within which the drawing of the chart is done.
384 384 It does not include the area defines by margins.
385 385 */
386 386 QRectF QChart::plotArea() const
387 387 {
388 388 return d_ptr->m_presenter->geometry();
389 389 }
390 390
391 391 ///*!
392 392 // TODO: Dummy.
393 393 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
394 394 // */
395 395 //void QChart::adjustViewToSeries(QAbstractSeries* series)
396 396 //{
397 397 // //
398 398 //}
399 399
400 400 /*!
401 401 Sets animation \a options for the chart
402 402 */
403 403 void QChart::setAnimationOptions(AnimationOptions options)
404 404 {
405 405 d_ptr->m_presenter->setAnimationOptions(options);
406 406 }
407 407
408 408 QChart::AnimationOptions QChart::animationOptions() const
409 409 {
410 410 return d_ptr->m_presenter->animationOptions();
411 411 }
412 412
413 413 /*!
414 414 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
415 415 */
416 416 void QChart::scroll(qreal dx, qreal dy)
417 417 {
418 418 d_ptr->m_presenter->scroll(dx, dy);
419 419 }
420 420
421 421 void QChart::setBackgroundVisible(bool visible)
422 422 {
423 423 d_ptr->m_presenter->setBackgroundVisible(visible);
424 424 }
425 425
426 426 bool QChart::isBackgroundVisible() const
427 427 {
428 428 return d_ptr->m_presenter->isBackgroundVisible();
429 429 }
430 430
431 431 void QChart::setDropShadowEnabled(bool enabled)
432 432 {
433 433 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
434 434 }
435 435
436 436 bool QChart::isDropShadowEnabled() const
437 437 {
438 438 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
439 439 }
440 440
441 441 /*!
442 442 Returns all the series that are added to the chart.
443 443
444 444 \sa addSeries(), removeSeries(), removeAllSeries()
445 445 */
446 446 QList<QAbstractSeries*> QChart::series() const
447 447 {
448 448 return d_ptr->m_dataset->series();
449 449 }
450 450 /*!
451 451 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
452 452 */
453 453 void QChart::setMarginsMinimum(const QRectF& margins)
454 454 {
455 455 d_ptr->m_presenter->setMarginsMinimum(margins);
456 456 }
457 457
458 458 /*!
459 459 Sets \a axis to the chart, which will control the presentation of the \a series
460 460
461 461 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
462 462 */
463 463 void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series)
464 464 {
465 d_ptr->m_dataset->setAxisX(series,axis);
465 d_ptr->m_dataset->setAxis(series,axis,Qt::Horizontal);
466 466 }
467 467
468 468 /*!
469 469 Sets \a axis to the chart, which will control the presentation of the \a series
470 470
471 471 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
472 472 */
473 473 void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series)
474 474 {
475 d_ptr->m_dataset->setAxisY(series,axis);
475 d_ptr->m_dataset->setAxis(series,axis,Qt::Vertical);
476 476 }
477 477
478 478 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
479 479
480 480 QChartPrivate::QChartPrivate():
481 481 m_legend(0),
482 482 m_dataset(0),
483 483 m_presenter(0)
484 484 {
485 485
486 486 }
487 487
488 488 QChartPrivate::~QChartPrivate()
489 489 {
490 490
491 491 }
492 492
493 493 void QChartPrivate::createConnections()
494 494 {
495 495 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
496 496 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
497 497 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
498 498 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
499 499 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
500 500 }
501 501
502 502 #include "moc_qchart.cpp"
503 503
504 504 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,461 +1,452
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qxyseries.h"
22 22 #include "qxyseries_p.h"
23 23 #include "domain_p.h"
24 24 #include "legendmarker_p.h"
25 25 #include "qvaluesaxis.h"
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 /*!
30 30 \class QXYSeries
31 31 \brief The QXYSeries class is a base class for line, spline and scatter series.
32 32 */
33 33 /*!
34 34 \qmlclass XYSeries
35 35 \inherits AbstractSeries
36 36 The XYSeries class is a base class for line, spline and scatter series.
37 37
38 38 The class cannot be instantiated directly.
39 39 */
40 40
41 41 /*!
42 42 \property QXYSeries::pointsVisible
43 43 Controls if the data points are visible and should be drawn.
44 44 */
45 45 /*!
46 46 \qmlproperty bool XYSeries::pointsVisible
47 47 Controls if the data points are visible and should be drawn.
48 48 */
49 49
50 50 /*!
51 51 \fn QPen QXYSeries::pen() const
52 52 \brief Returns pen used to draw points for series.
53 53 \sa setPen()
54 54 */
55 55
56 56 /*!
57 57 \fn QBrush QXYSeries::brush() const
58 58 \brief Returns brush used to draw points for series.
59 59 \sa setBrush()
60 60 */
61 61
62 62 /*!
63 63 \property QXYSeries::color
64 64 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
65 65 fill (brush) color in case of QScatterSeries or QAreaSeries.
66 66 \sa QXYSeries::pen(), QXYSeries::brush()
67 67 */
68 68 /*!
69 69 \qmlproperty color XYSeries::color
70 70 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
71 71 fill (brush) color in case of ScatterSeries or AreaSeries.
72 72 */
73 73
74 74 /*!
75 75 \fn void QXYSeries::clicked(const QPointF& point)
76 76 \brief Signal is emitted when user clicks the \a point on chart.
77 77 */
78 78 /*!
79 79 \qmlsignal XYSeries::onClicked(QPointF point)
80 80 Signal is emitted when user clicks the \a point on chart. For example:
81 81 \code
82 82 LineSeries {
83 83 XYPoint { x: 0; y: 0 }
84 84 XYPoint { x: 1.1; y: 2.1 }
85 85 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
86 86 }
87 87 \endcode
88 88 */
89 89
90 90 /*!
91 91 \fn void QXYSeries::pointReplaced(int index)
92 92 Signal is emitted when a point has been replaced at \a index.
93 93 \sa replace()
94 94 */
95 95 /*!
96 96 \qmlsignal XYSeries::onPointReplaced(int index)
97 97 Signal is emitted when a point has been replaced at \a index.
98 98 */
99 99
100 100 /*!
101 101 \fn void QXYSeries::pointAdded(int index)
102 102 Signal is emitted when a point has been added at \a index.
103 103 \sa append(), insert()
104 104 */
105 105 /*!
106 106 \qmlsignal XYSeries::onPointAdded(int index)
107 107 Signal is emitted when a point has been added at \a index.
108 108 */
109 109
110 110 /*!
111 111 \fn void QXYSeries::pointRemoved(int index)
112 112 Signal is emitted when a point has been removed from \a index.
113 113 \sa remove()
114 114 */
115 115 /*!
116 116 \qmlsignal XYSeries::onPointRemoved(int index)
117 117 Signal is emitted when a point has been removed from \a index.
118 118 */
119 119
120 120 /*!
121 121 \fn void QXYSeries::colorChanged(QColor color)
122 122 \brief Signal is emitted when the line (pen) color has changed to \a color.
123 123 */
124 124 /*!
125 125 \qmlsignal XYSeries::onColorChanged(color color)
126 126 Signal is emitted when the line (pen) color has changed to \a color.
127 127 */
128 128
129 129 /*!
130 130 \fn void QXYSeriesPrivate::updated()
131 131 \brief \internal
132 132 */
133 133
134 134 /*!
135 135 \qmlmethod XYSeries::append(real x, real y)
136 136 Append point (\a x, \a y) to the series
137 137 */
138 138
139 139 /*!
140 140 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
141 141 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
142 142 exist.
143 143 */
144 144
145 145 /*!
146 146 \qmlmethod XYSeries::remove(real x, real y)
147 147 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
148 148 */
149 149
150 150 /*!
151 151 \qmlmethod XYSeries::insert(int index, real x, real y)
152 152 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
153 153 points. If index is the same as or bigger than count, the point is appended to the list of points.
154 154 */
155 155
156 156 /*!
157 157 \qmlmethod QPointF XYSeries::at(int index)
158 158 Returns point at \a index. Returns (0, 0) if the index is not valid.
159 159 */
160 160
161 161 /*!
162 162 \internal
163 163
164 164 Constructs empty series object which is a child of \a parent.
165 165 When series object is added to QChartView or QChart instance ownerships is transferred.
166 166 */
167 167 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
168 168 {
169 169 }
170 170
171 171 /*!
172 172 Destroys the object. Series added to QChartView or QChart instances are owned by those,
173 173 and are deleted when mentioned object are destroyed.
174 174 */
175 175 QXYSeries::~QXYSeries()
176 176 {
177 177 }
178 178
179 179 /*!
180 180 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
181 181 */
182 182 void QXYSeries::append(qreal x,qreal y)
183 183 {
184 184 append(QPointF(x,y));
185 185 }
186 186
187 187 /*!
188 188 This is an overloaded function.
189 189 Adds data \a point to the series. Points are connected with lines on the chart.
190 190 */
191 191 void QXYSeries::append(const QPointF &point)
192 192 {
193 193 Q_D(QXYSeries);
194 194 d->m_points<<point;
195 195 // emit d->pointAdded(d->m_points.count()-1);
196 196 emit pointAdded(d->m_points.count()-1);
197 197 }
198 198
199 199 /*!
200 200 This is an overloaded function.
201 201 Adds list of data \a points to the series. Points are connected with lines on the chart.
202 202 */
203 203 void QXYSeries::append(const QList<QPointF> &points)
204 204 {
205 205 foreach(const QPointF& point , points) {
206 206 append(point);
207 207 }
208 208 }
209 209
210 210 /*!
211 211 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
212 212 */
213 213 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
214 214 {
215 215 replace(QPointF(oldX,oldY),QPointF(newX,newY));
216 216 }
217 217
218 218 /*!
219 219 Replaces \a oldPoint with \a newPoint.
220 220 */
221 221 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
222 222 {
223 223 Q_D(QXYSeries);
224 224 int index = d->m_points.indexOf(oldPoint);
225 225 if(index==-1) return;
226 226 d->m_points[index] = newPoint;
227 227 // emit d->pointReplaced(index);
228 228 emit pointReplaced(index);
229 229 }
230 230
231 231 /*!
232 232 Removes current \a x and \a y value.
233 233 */
234 234 void QXYSeries::remove(qreal x,qreal y)
235 235 {
236 236 remove(QPointF(x,y));
237 237 }
238 238
239 239 /*!
240 240 Removes current \a point x value.
241 241
242 242 Note: point y value is ignored.
243 243 */
244 244 void QXYSeries::remove(const QPointF &point)
245 245 {
246 246 Q_D(QXYSeries);
247 247 int index = d->m_points.indexOf(point);
248 248 if(index==-1) return;
249 249 d->m_points.remove(index);
250 250 // emit d->pointRemoved(index);
251 251 emit pointRemoved(index);
252 252 }
253 253
254 254 /*!
255 255 Inserts a \a point in the series at \a index position.
256 256 */
257 257 void QXYSeries::insert(int index, const QPointF &point)
258 258 {
259 259 Q_D(QXYSeries);
260 260 d->m_points.insert(index, point);
261 261 // emit d->pointAdded(index);
262 262 emit pointAdded(index);
263 263 }
264 264
265 265 /*!
266 266 Removes all points from the series.
267 267 */
268 268 void QXYSeries::clear()
269 269 {
270 270 Q_D(QXYSeries);
271 271 for (int i = d->m_points.size() - 1; i >= 0; i--)
272 272 remove(d->m_points.at(i));
273 273 }
274 274
275 275 /*!
276 276 \internal \a pos
277 277 */
278 278 QList<QPointF> QXYSeries::points() const
279 279 {
280 280 Q_D(const QXYSeries);
281 281 return d->m_points.toList();
282 282 }
283 283
284 284 /*!
285 285 Returns number of data points within series.
286 286 */
287 287 int QXYSeries::count() const
288 288 {
289 289 Q_D(const QXYSeries);
290 290 return d->m_points.count();
291 291 }
292 292
293 293
294 294 /*!
295 295 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
296 296 pen from chart theme is used.
297 297 \sa QChart::setTheme()
298 298 */
299 299 void QXYSeries::setPen(const QPen &pen)
300 300 {
301 301 Q_D(QXYSeries);
302 302 if (d->m_pen != pen) {
303 303 bool emitColorChanged = d->m_pen.color() != pen.color();
304 304 d->m_pen = pen;
305 305 emit d->updated();
306 306 if (emitColorChanged)
307 307 emit colorChanged(pen.color());
308 308 }
309 309 }
310 310
311 311 QPen QXYSeries::pen() const
312 312 {
313 313 Q_D(const QXYSeries);
314 314 return d->m_pen;
315 315 }
316 316
317 317 /*!
318 318 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
319 319 from chart theme setting is used.
320 320 \sa QChart::setTheme()
321 321 */
322 322 void QXYSeries::setBrush(const QBrush &brush)
323 323 {
324 324 Q_D(QXYSeries);
325 325 if (d->m_brush!=brush) {
326 326 d->m_brush = brush;
327 327 emit d->updated();
328 328 }
329 329 }
330 330
331 331 QBrush QXYSeries::brush() const
332 332 {
333 333 Q_D(const QXYSeries);
334 334 return d->m_brush;
335 335 }
336 336
337 337 void QXYSeries::setColor(const QColor &color)
338 338 {
339 339 QPen p = pen();
340 340 if (p.color() != color) {
341 341 p.setColor(color);
342 342 setPen(p);
343 343 }
344 344 }
345 345
346 346 QColor QXYSeries::color() const
347 347 {
348 348 return pen().color();
349 349 }
350 350
351 351 void QXYSeries::setPointsVisible(bool visible)
352 352 {
353 353 Q_D(QXYSeries);
354 354 if (d->m_pointsVisible != visible){
355 355 d->m_pointsVisible = visible;
356 356 emit d->updated();
357 357 }
358 358 }
359 359
360 360 bool QXYSeries::pointsVisible() const
361 361 {
362 362 Q_D(const QXYSeries);
363 363 return d->m_pointsVisible;
364 364 }
365 365
366 366
367 367 /*!
368 368 Stream operator for adding a data \a point to the series.
369 369 \sa append()
370 370 */
371 371 QXYSeries& QXYSeries::operator<< (const QPointF &point)
372 372 {
373 373 append(point);
374 374 return *this;
375 375 }
376 376
377 377
378 378 /*!
379 379 Stream operator for adding a list of \a points to the series.
380 380 \sa append()
381 381 */
382 382
383 383 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
384 384 {
385 385 append(points);
386 386 return *this;
387 387 }
388 388
389 389 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
390 390
391 391
392 392 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
393 393 QAbstractSeriesPrivate(q),
394 394 m_pointsVisible(false)
395 395 {
396 396 }
397 397
398 398 void QXYSeriesPrivate::scaleDomain(Domain& domain)
399 399 {
400 400 qreal minX(domain.minX());
401 401 qreal minY(domain.minY());
402 402 qreal maxX(domain.maxX());
403 403 qreal maxY(domain.maxY());
404 404 int tickXCount(domain.tickXCount());
405 405 int tickYCount(domain.tickYCount());
406 406
407 407 Q_Q(QXYSeries);
408 408
409 409 const QList<QPointF>& points = q->points();
410 410
411 411
412 412 if (points.isEmpty()){
413 413 minX = qMin(minX, (qreal)0.0);
414 414 minY = qMin(minY, (qreal)0.0);
415 415 maxX = qMax(maxX, (qreal)1.0);
416 416 maxY = qMax(maxY, (qreal)1.0);
417 417 }
418 418
419 419 for (int i = 0; i < points.count(); i++) {
420 420 qreal x = points[i].x();
421 421 qreal y = points[i].y();
422 422 minX = qMin(minX, x);
423 423 minY = qMin(minY, y);
424 424 maxX = qMax(maxX, x);
425 425 maxY = qMax(maxY, y);
426 426 }
427 427
428 428 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
429 429 }
430 430
431 431 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
432 432 {
433 433 Q_Q(QXYSeries);
434 434 QList<LegendMarker*> list;
435 435 return list << new XYLegendMarker(q,legend);
436 436 }
437 437
438 void QXYSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
438 void QXYSeriesPrivate::initializeAxis(QAbstractAxis* axis)
439 439 {
440 440 Q_UNUSED(axis);
441 441 }
442 442
443 void QXYSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
444 {
445 Q_UNUSED(axis);
446 }
447
448 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisXType() const
449 {
450 return QAbstractAxis::AxisTypeValues;
451 }
452
453 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisYType() const
443 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
454 444 {
445 Q_UNUSED(orientation);
455 446 return QAbstractAxis::AxisTypeValues;
456 447 }
457 448
458 449 #include "moc_qxyseries.cpp"
459 450 #include "moc_qxyseries_p.cpp"
460 451
461 452 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,74 +1,72
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QXYSERIES_P_H
31 31 #define QXYSERIES_P_H
32 32
33 33 #include "qabstractseries_p.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class QXYSeries;
38 38 class QAbstractAxis;
39 39
40 40 class QXYSeriesPrivate: public QAbstractSeriesPrivate
41 41 {
42 42 Q_OBJECT
43 43
44 44 public:
45 45 QXYSeriesPrivate(QXYSeries* q);
46 46
47 47 void scaleDomain(Domain& domain);
48 48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
49 49
50 void initializeAxisX(QAbstractAxis* axis);
51 void initializeAxisY(QAbstractAxis* axis);
52 QAbstractAxis::AxisType defaultAxisXType() const;
53 QAbstractAxis::AxisType defaultAxisYType() const;
50 void initializeAxis(QAbstractAxis* axis);
51 QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const;
54 52
55 53 Q_SIGNALS:
56 54 void updated();
57 55 // void pointReplaced(int index);
58 56 // void pointRemoved(int index);
59 57 // void pointAdded(int index);
60 58
61 59 protected:
62 60 QVector<QPointF> m_points;
63 61 QPen m_pen;
64 62 QBrush m_brush;
65 63 bool m_pointsVisible;
66 64
67 65 private:
68 66 Q_DECLARE_PUBLIC(QXYSeries)
69 67 friend class QScatterSeries;
70 68 };
71 69
72 70 QTCOMMERCIALCHART_END_NAMESPACE
73 71
74 72 #endif
@@ -1,791 +1,788
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtTest/QtTest>
22 22 #include <qchartview.h>
23 23 #include <qlineseries.h>
24 24 #include <qareaseries.h>
25 25 #include <qscatterseries.h>
26 26 #include <qsplineseries.h>
27 27 #include <qpieseries.h>
28 28 #include <qabstractbarseries.h>
29 29 #include <qbarseries.h>
30 30 #include <qpercentbarseries.h>
31 31 #include <qstackedbarseries.h>
32 32 #include <qvaluesaxis.h>
33 33 #include <qbarcategoriesaxis.h>
34 34
35 35 QTCOMMERCIALCHART_USE_NAMESPACE
36 36
37 37 Q_DECLARE_METATYPE(QAbstractAxis *)
38 38 Q_DECLARE_METATYPE(QValuesAxis *)
39 39 Q_DECLARE_METATYPE(QBarCategoriesAxis *)
40 40 Q_DECLARE_METATYPE(QAbstractSeries *)
41 41 Q_DECLARE_METATYPE(QChart::AnimationOption)
42 42 Q_DECLARE_METATYPE(QBrush)
43 43 Q_DECLARE_METATYPE(QPen)
44 44 Q_DECLARE_METATYPE(QChart::ChartTheme)
45 45
46 46 class tst_QChart : public QObject
47 47 {
48 48 Q_OBJECT
49 49
50 50 public slots:
51 51 void initTestCase();
52 52 void cleanupTestCase();
53 53 void init();
54 54 void cleanup();
55 55
56 56 private slots:
57 57 void qchart_data();
58 58 void qchart();
59 59 void addSeries_data();
60 60 void addSeries();
61 61 void animationOptions_data();
62 62 void animationOptions();
63 63 void axisX_data();
64 64 void axisX();
65 65 void axisY_data();
66 66 void axisY();
67 67 void backgroundBrush_data();
68 68 void backgroundBrush();
69 69 void backgroundPen_data();
70 70 void backgroundPen();
71 71 void isBackgroundVisible_data();
72 72 void isBackgroundVisible();
73 73 void legend_data();
74 74 void legend();
75 75 void margins_data();
76 76 void margins();
77 77 void removeAllSeries_data();
78 78 void removeAllSeries();
79 79 void removeSeries_data();
80 80 void removeSeries();
81 81 void scroll_right_data();
82 82 void scroll_right();
83 83 void scroll_left_data();
84 84 void scroll_left();
85 85 void scroll_up_data();
86 86 void scroll_up();
87 87 void scroll_down_data();
88 88 void scroll_down();
89 89 void theme_data();
90 90 void theme();
91 91 void title_data();
92 92 void title();
93 93 void titleBrush_data();
94 94 void titleBrush();
95 95 void titleFont_data();
96 96 void titleFont();
97 97 void zoomIn_data();
98 98 void zoomIn();
99 99 void zoomOut_data();
100 100 void zoomOut();
101 101
102 102 private:
103 103 void createTestData();
104 104
105 105 private:
106 106 QChartView* m_view;
107 107 QChart* m_chart;
108 108 };
109 109
110 110 void tst_QChart::initTestCase()
111 111 {
112 112
113 113 }
114 114
115 115 void tst_QChart::cleanupTestCase()
116 116 {
117 117
118 118 }
119 119
120 120 void tst_QChart::init()
121 121 {
122 122 m_view = new QChartView(new QChart());
123 123 m_chart = m_view->chart();
124 124 }
125 125
126 126 void tst_QChart::cleanup()
127 127 {
128 128 delete m_view;
129 129 m_view = 0;
130 130 m_chart = 0;
131 131 }
132 132
133 133
134 134 void tst_QChart::createTestData()
135 135 {
136 136 QLineSeries* series0 = new QLineSeries(this);
137 137 *series0 << QPointF(0, 0) << QPointF(100, 100);
138 138 m_chart->addSeries(series0);
139 139 m_view->show();
140 140 QTest::qWaitForWindowShown(m_view);
141 141 }
142 142
143 143 void tst_QChart::qchart_data()
144 144 {
145 145 }
146 146
147 147 void tst_QChart::qchart()
148 148 {
149 149 QVERIFY(m_chart);
150 150 QVERIFY(m_chart->legend());
151 151 QVERIFY(m_chart->legend()->isVisible());
152 152
153 153 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
154 154 QVERIFY(!m_chart->axisX());
155 155 QVERIFY(!m_chart->axisY());
156 156 QVERIFY(m_chart->backgroundBrush()!=QBrush());
157 157 QVERIFY(m_chart->backgroundPen()!=QPen());
158 158 QCOMPARE(m_chart->isBackgroundVisible(), true);
159 159
160 160 QVERIFY(m_chart->margins().top()>0);
161 161 QVERIFY(m_chart->margins().left()>0);
162 162 QVERIFY(m_chart->margins().right()>0);
163 163 QVERIFY(m_chart->margins().bottom()>0);
164 164
165 165 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
166 166 QCOMPARE(m_chart->title(), QString());
167 167
168 168 //QCOMPARE(m_chart->titleBrush(),QBrush());
169 169 //QCOMPARE(m_chart->titleFont(),QFont());
170 170
171 171 m_chart->removeAllSeries();
172 172 m_chart->scroll(0,0);
173 173
174 174 m_chart->zoomIn();
175 175 m_chart->zoomIn(QRectF());
176 176 m_chart->zoomOut();
177 177 }
178 178
179 179 void tst_QChart::addSeries_data()
180 180 {
181 181 QTest::addColumn<QAbstractSeries *>("series");
182 182
183 183 QAbstractSeries* line = new QLineSeries(this);
184 184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
185 185 QAbstractSeries* scatter = new QScatterSeries(this);
186 186 QAbstractSeries* spline = new QSplineSeries(this);
187 187 QAbstractSeries* pie = new QPieSeries(this);
188 188 QAbstractSeries* bar = new QBarSeries(this);
189 189 QAbstractSeries* percent = new QPercentBarSeries(this);
190 190 QAbstractSeries* stacked = new QStackedBarSeries(this);
191 191
192 192 QTest::newRow("lineSeries") << line;
193 193 QTest::newRow("areaSeries") << area;
194 194 QTest::newRow("scatterSeries") << scatter;
195 195 QTest::newRow("splineSeries") << spline;
196 196 QTest::newRow("pieSeries") << pie;
197 197 QTest::newRow("barSeries") << bar;
198 198 QTest::newRow("percentBarSeries") << percent;
199 199 QTest::newRow("stackedBarSeries") << stacked;
200 200
201 201 }
202 202
203 203 void tst_QChart::addSeries()
204 204 {
205 205 QFETCH(QAbstractSeries *, series);
206 206 m_view->show();
207 207 QTest::qWaitForWindowShown(m_view);
208 208 QVERIFY(!series->chart());
209 209 QCOMPARE(m_chart->series().count(), 0);
210 210 m_chart->addSeries(series);
211 211 QCOMPARE(m_chart->series().count(), 1);
212 212 QCOMPARE(m_chart->series().first(), series);
213 213 QVERIFY(series->chart() == m_chart);
214 214 m_chart->createDefaultAxes();
215 215 if(series->type()!=QAbstractSeries::SeriesTypePie){
216 216 QVERIFY(m_chart->axisY(series));
217 217 QVERIFY(m_chart->axisX(series));
218 218 }else{
219 219 QVERIFY(!m_chart->axisY(series));
220 220 QVERIFY(!m_chart->axisX(series));
221 221 }
222 222 m_chart->removeSeries(series);
223 223 QVERIFY(!series->chart());
224 224 QCOMPARE(m_chart->series().count(), 0);
225 225 }
226 226
227 227 void tst_QChart::animationOptions_data()
228 228 {
229 229 QTest::addColumn<QChart::AnimationOption>("animationOptions");
230 230 QTest::newRow("AllAnimations") << QChart::AllAnimations;
231 231 QTest::newRow("NoAnimation") << QChart::NoAnimation;
232 232 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
233 233 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
234 234 }
235 235
236 236 void tst_QChart::animationOptions()
237 237 {
238 238 createTestData();
239 239 QFETCH(QChart::AnimationOption, animationOptions);
240 240 m_chart->setAnimationOptions(animationOptions);
241 241 QCOMPARE(m_chart->animationOptions(), animationOptions);
242 242 }
243 243
244 244 void tst_QChart::axisX_data()
245 245 {
246 246
247 247 QTest::addColumn<QAbstractAxis*>("axis");
248 248 QTest::addColumn<QAbstractSeries *>("series");
249 249
250 250 QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QLineSeries(this);
251 251 QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
252 252 QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QScatterSeries(this);
253 253 QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QSplineSeries(this);
254 254 QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QPieSeries(this);
255 255 QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QBarSeries(this);
256 256 QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
257 257 QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoriesAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
258 258
259 259 QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValuesAxis() << (QAbstractSeries*) new QLineSeries(this);
260 260 QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValuesAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this));
261 261 QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValuesAxis() << (QAbstractSeries*) new QScatterSeries(this);
262 262 QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValuesAxis() << (QAbstractSeries*) new QSplineSeries(this);
263 263 QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValuesAxis() << (QAbstractSeries*) new QPieSeries(this);
264 264 QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValuesAxis() << (QAbstractSeries*) new QBarSeries(this);
265 265 QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValuesAxis() << (QAbstractSeries*) new QPercentBarSeries(this);
266 266 QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValuesAxis() << (QAbstractSeries*) new QStackedBarSeries(this);
267 267
268 268 }
269 269
270 270 void tst_QChart::axisX()
271 271 {
272 272 QFETCH(QAbstractAxis*, axis);
273 273 QFETCH(QAbstractSeries*, series);
274 274 QVERIFY(!m_chart->axisX());
275 275 m_view->show();
276 276 QTest::qWaitForWindowShown(m_view);
277 277 m_chart->addSeries(series);
278 278 m_chart->setAxisX(axis,series);
279 279 QVERIFY(m_chart->axisX(series)==axis);
280 280 }
281 281
282 282 void tst_QChart::axisY_data()
283 283 {
284 284 axisX_data();
285 285 }
286 286
287 287
288 288 void tst_QChart::axisY()
289 289 {
290 290 QFETCH(QAbstractAxis*, axis);
291 291 QFETCH(QAbstractSeries*, series);
292 292 QVERIFY(!m_chart->axisY());
293 293 m_view->show();
294 294 QTest::qWaitForWindowShown(m_view);
295 295 m_chart->addSeries(series);
296 296 m_chart->setAxisY(axis,series);
297 297 QVERIFY(m_chart->axisY(series)==axis);
298 298 }
299 299
300 300 void tst_QChart::backgroundBrush_data()
301 301 {
302 302 QTest::addColumn<QBrush>("backgroundBrush");
303 303 QTest::newRow("null") << QBrush();
304 304 QTest::newRow("blue") << QBrush(Qt::blue);
305 305 QTest::newRow("white") << QBrush(Qt::white);
306 306 QTest::newRow("black") << QBrush(Qt::black);
307 307 }
308 308
309 309 void tst_QChart::backgroundBrush()
310 310 {
311 311 QFETCH(QBrush, backgroundBrush);
312 312 m_chart->setBackgroundBrush(backgroundBrush);
313 313 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
314 314 }
315 315
316 316 void tst_QChart::backgroundPen_data()
317 317 {
318 318 QTest::addColumn<QPen>("backgroundPen");
319 319 QTest::newRow("null") << QPen();
320 320 QTest::newRow("blue") << QPen(Qt::blue);
321 321 QTest::newRow("white") << QPen(Qt::white);
322 322 QTest::newRow("black") << QPen(Qt::black);
323 323 }
324 324
325 325
326 326 void tst_QChart::backgroundPen()
327 327 {
328 328 QFETCH(QPen, backgroundPen);
329 329 m_chart->setBackgroundPen(backgroundPen);
330 330 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
331 331 }
332 332
333 333 void tst_QChart::isBackgroundVisible_data()
334 334 {
335 335 QTest::addColumn<bool>("isBackgroundVisible");
336 336 QTest::newRow("true") << true;
337 337 QTest::newRow("false") << false;
338 338 }
339 339
340 340 void tst_QChart::isBackgroundVisible()
341 341 {
342 342 QFETCH(bool, isBackgroundVisible);
343 343 m_chart->setBackgroundVisible(isBackgroundVisible);
344 344 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
345 345 }
346 346
347 347 void tst_QChart::legend_data()
348 348 {
349 349
350 350 }
351 351
352 352 void tst_QChart::legend()
353 353 {
354 354 QLegend *legend = m_chart->legend();
355 355 QVERIFY(legend);
356 356
357 357 // Colors related signals
358 358 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
359 359 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
360 360 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
361 361
362 362 // colorChanged
363 363 legend->setColor(QColor("aliceblue"));
364 364 QCOMPARE(colorSpy.count(), 1);
365 365 QBrush b = legend->brush();
366 366 b.setColor(QColor("aqua"));
367 367 legend->setBrush(b);
368 368 QCOMPARE(colorSpy.count(), 2);
369 369
370 370 // borderColorChanged
371 371 legend->setBorderColor(QColor("aliceblue"));
372 372 QCOMPARE(borderColorSpy.count(), 1);
373 373 QPen p = legend->pen();
374 374 p.setColor(QColor("aqua"));
375 375 legend->setPen(p);
376 376 QCOMPARE(borderColorSpy.count(), 2);
377 377
378 378 // labelColorChanged
379 379 legend->setLabelColor(QColor("lightsalmon"));
380 380 QCOMPARE(labelColorSpy.count(), 1);
381 381 b = legend->labelBrush();
382 382 b.setColor(QColor("lightseagreen"));
383 383 legend->setLabelBrush(b);
384 384 QCOMPARE(labelColorSpy.count(), 2);
385 385
386 386 // fontChanged
387 387 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
388 388 QFont f = legend->font();
389 389 f.setBold(!f.bold());
390 390 legend->setFont(f);
391 391 QCOMPARE(fontSpy.count(), 1);
392 392 }
393 393
394 394 void tst_QChart::margins_data()
395 395 {
396 396
397 397 }
398 398
399 399 void tst_QChart::margins()
400 400 {
401 401 createTestData();
402 402 QRectF rect = m_chart->geometry();
403 403 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
404 404 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
405 405 }
406 406
407 407 void tst_QChart::removeAllSeries_data()
408 408 {
409 409
410 410 }
411 411
412 412 void tst_QChart::removeAllSeries()
413 413 {
414 414 QLineSeries* series0 = new QLineSeries(this);
415 415 QLineSeries* series1 = new QLineSeries(this);
416 416 QLineSeries* series2 = new QLineSeries(this);
417 417 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
418 418 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
419 419 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
420 420
421 421 m_chart->addSeries(series0);
422 422 m_chart->addSeries(series1);
423 423 m_chart->addSeries(series2);
424 424 m_view->show();
425 425 QTest::qWaitForWindowShown(m_view);
426 426 m_chart->createDefaultAxes();
427 427 QVERIFY(m_chart->axisY(series0)!=0);
428 428 QVERIFY(m_chart->axisY(series1)!=0);
429 429 QVERIFY(m_chart->axisY(series2)!=0);
430 430
431 431 m_chart->removeAllSeries();
432 432 QVERIFY(m_chart->axisY(series0)==0);
433 433 QVERIFY(m_chart->axisY(series1)==0);
434 434 QVERIFY(m_chart->axisY(series2)==0);
435 435 QCOMPARE(deleteSpy1.count(), 1);
436 436 QCOMPARE(deleteSpy2.count(), 1);
437 437 QCOMPARE(deleteSpy3.count(), 1);
438 438 }
439 439
440 440 void tst_QChart::removeSeries_data()
441 441 {
442 442 axisX_data();
443 443 }
444 444
445 445 void tst_QChart::removeSeries()
446 446 {
447 447 QFETCH(QAbstractAxis *, axis);
448 448 QFETCH(QAbstractSeries *, series);
449 449 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
450 450 m_view->show();
451 451 QTest::qWaitForWindowShown(m_view);
452 452 if(!axis) axis = m_chart->axisY();
453 453 m_chart->addSeries(series);
454 454 m_chart->setAxisY(axis,series);
455 455 QCOMPARE(m_chart->axisY(series),axis);
456 456 m_chart->removeSeries(series);
457 457 QVERIFY(m_chart->axisY(series)==0);
458 458 QCOMPARE(deleteSpy.count(), 0);
459 459 }
460 460
461 461 void tst_QChart::scroll_right_data()
462 462 {
463 463 QTest::addColumn<QAbstractSeries *>("series");
464 464
465 465 QLineSeries* series0 = new QLineSeries(this);
466 466 *series0 << QPointF(0, 0) << QPointF(100, 100);
467 467
468 QLineSeries* series1 = new QLineSeries(this);
469 *series1 << QPointF(0, 0) << QPointF(100, 100);
470
471 468 QTest::newRow("lineSeries") << (QAbstractSeries*) series0;
472 469
473 470
474 471 }
475 472
476 473 void tst_QChart::scroll_right()
477 474 {
478 475 QFETCH(QAbstractSeries *, series);
479 476 m_chart->addSeries(series);
480 477 m_chart->createDefaultAxes();
481 478 m_view->show();
482 479 QTest::qWaitForWindowShown(m_view);
483 480 QAbstractAxis * axis = m_chart->axisX();
484 481 QVERIFY(axis!=0);
485 482
486 483 switch(axis->type())
487 484 {
488 485 case QAbstractAxis::AxisTypeValues:{
489 486 QValuesAxis* vaxis = qobject_cast<QValuesAxis*>(axis);
490 487 QVERIFY(vaxis!=0);
491 488 qreal min = vaxis->min();
492 489 qreal max = vaxis->max();
493 490 QVERIFY(max>min);
494 491 m_chart->scroll(50, 0);
495 492 QVERIFY(min<vaxis->min());
496 493 QVERIFY(max<vaxis->max());
497 494 break;
498 495 }
499 496 case QAbstractAxis::AxisTypeCategories:{
500 497 QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis);
501 498 QVERIFY(caxis!=0);
502 499 qreal min = caxis->min().toDouble();
503 500 qreal max = caxis->max().toDouble();
504 501 m_chart->scroll(50, 0);
505 502 QVERIFY(min<caxis->min().toDouble());
506 503 QVERIFY(max<caxis->max().toDouble());
507 504 break;
508 505 }
509 506 default:
510 507 qFatal("Unsupported type");
511 508 break;
512 509 }
513 510 }
514 511
515 512 void tst_QChart::scroll_left_data()
516 513 {
517 514 scroll_right_data();
518 515 }
519 516
520 517 void tst_QChart::scroll_left()
521 518 {
522 519 QFETCH(QAbstractSeries *, series);
523 520 m_chart->addSeries(series);
524 521 m_chart->createDefaultAxes();
525 522 m_view->show();
526 523 QTest::qWaitForWindowShown(m_view);
527 524 QAbstractAxis * axis = m_chart->axisX();
528 525 QVERIFY(axis!=0);
529 526
530 527 switch(axis->type())
531 528 {
532 529 case QAbstractAxis::AxisTypeValues:{
533 530 QValuesAxis* vaxis = qobject_cast<QValuesAxis*>(axis);
534 531 QVERIFY(vaxis!=0);
535 532 qreal min = vaxis->min();
536 533 qreal max = vaxis->max();
537 534 m_chart->scroll(-50, 0);
538 535 QVERIFY(min>vaxis->min());
539 536 QVERIFY(max>vaxis->max());
540 537 break;
541 538 }
542 539 case QAbstractAxis::AxisTypeCategories:{
543 540 QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis);
544 541 QVERIFY(caxis!=0);
545 542 qreal min = caxis->min().toDouble();
546 543 qreal max = caxis->max().toDouble();
547 544 m_chart->scroll(-50, 0);
548 545 QVERIFY(min>caxis->min().toDouble());
549 546 QVERIFY(max>caxis->max().toDouble());
550 547 break;
551 548 }
552 549 default:
553 550 qFatal("Unsupported type");
554 551 break;
555 552 }
556 553 }
557 554
558 555 void tst_QChart::scroll_up_data()
559 556 {
560 557 scroll_right_data();
561 558 }
562 559
563 560 void tst_QChart::scroll_up()
564 561 {
565 562 QFETCH(QAbstractSeries *, series);
566 563 m_chart->addSeries(series);
567 564 m_chart->createDefaultAxes();
568 565 m_view->show();
569 566 QTest::qWaitForWindowShown(m_view);
570 567 QAbstractAxis * axis = m_chart->axisY();
571 568 QVERIFY(axis!=0);
572 569
573 570 switch(axis->type())
574 571 {
575 572 case QAbstractAxis::AxisTypeValues:{
576 573 QValuesAxis* vaxis = qobject_cast<QValuesAxis*>(axis);
577 574 QVERIFY(vaxis!=0);
578 575 qreal min = vaxis->min();
579 576 qreal max = vaxis->max();
580 577 m_chart->scroll(0, 50);
581 578 QVERIFY(min<vaxis->min());
582 579 QVERIFY(max<vaxis->max());
583 580 break;
584 581 }
585 582 case QAbstractAxis::AxisTypeCategories:{
586 583 QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis);
587 584 QVERIFY(caxis!=0);
588 585 qreal min = caxis->min().toDouble();
589 586 qreal max = caxis->max().toDouble();
590 587 m_chart->scroll(0, 50);
591 588 QVERIFY(min<caxis->min().toDouble());
592 589 QVERIFY(max<caxis->max().toDouble());
593 590 break;
594 591 }
595 592 default:
596 593 qFatal("Unsupported type");
597 594 break;
598 595 }
599 596 }
600 597
601 598 void tst_QChart::scroll_down_data()
602 599 {
603 600 scroll_right_data();
604 601 }
605 602
606 603 void tst_QChart::scroll_down()
607 604 {
608 605 QFETCH(QAbstractSeries *, series);
609 606 m_chart->addSeries(series);
610 607 m_chart->createDefaultAxes();
611 608 m_view->show();
612 609 QTest::qWaitForWindowShown(m_view);
613 610 QAbstractAxis * axis = m_chart->axisY();
614 611 QVERIFY(axis!=0);
615 612
616 613 switch(axis->type())
617 614 {
618 615 case QAbstractAxis::AxisTypeValues:{
619 616 QValuesAxis* vaxis = qobject_cast<QValuesAxis*>(axis);
620 617 QVERIFY(vaxis!=0);
621 618 qreal min = vaxis->min();
622 619 qreal max = vaxis->max();
623 620 m_chart->scroll(0, -50);
624 621 QVERIFY(min>vaxis->min());
625 622 QVERIFY(max>vaxis->max());
626 623 break;
627 624 }
628 625 case QAbstractAxis::AxisTypeCategories:{
629 626 QBarCategoriesAxis* caxis = qobject_cast<QBarCategoriesAxis*>(axis);
630 627 QVERIFY(caxis!=0);
631 628 qreal min = caxis->min().toDouble();
632 629 qreal max = caxis->max().toDouble();
633 630 m_chart->scroll(0, -50);
634 631 QVERIFY(min>caxis->min().toDouble());
635 632 QVERIFY(max>caxis->max().toDouble());
636 633 break;
637 634 }
638 635 default:
639 636 qFatal("Unsupported type");
640 637 break;
641 638 }
642 639 }
643 640
644 641 void tst_QChart::theme_data()
645 642 {
646 643 QTest::addColumn<QChart::ChartTheme>("theme");
647 644 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
648 645 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
649 646 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
650 647 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
651 648 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
652 649 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
653 650 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
654 651 }
655 652
656 653 void tst_QChart::theme()
657 654 {
658 655 QFETCH(QChart::ChartTheme, theme);
659 656 createTestData();
660 657 m_chart->setTheme(theme);
661 658 QVERIFY(m_chart->theme()==theme);
662 659 }
663 660
664 661 void tst_QChart::title_data()
665 662 {
666 663 QTest::addColumn<QString>("title");
667 664 QTest::newRow("null") << QString();
668 665 QTest::newRow("foo") << QString("foo");
669 666 }
670 667
671 668 void tst_QChart::title()
672 669 {
673 670 QFETCH(QString, title);
674 671 m_chart->setTitle(title);
675 672 QCOMPARE(m_chart->title(), title);
676 673 }
677 674
678 675 void tst_QChart::titleBrush_data()
679 676 {
680 677 QTest::addColumn<QBrush>("titleBrush");
681 678 QTest::newRow("null") << QBrush();
682 679 QTest::newRow("blue") << QBrush(Qt::blue);
683 680 QTest::newRow("white") << QBrush(Qt::white);
684 681 QTest::newRow("black") << QBrush(Qt::black);
685 682 }
686 683
687 684 void tst_QChart::titleBrush()
688 685 {
689 686 QFETCH(QBrush, titleBrush);
690 687 m_chart->setTitleBrush(titleBrush);
691 688 QCOMPARE(m_chart->titleBrush(), titleBrush);
692 689 }
693 690
694 691 void tst_QChart::titleFont_data()
695 692 {
696 693 QTest::addColumn<QFont>("titleFont");
697 694 QTest::newRow("null") << QFont();
698 695 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
699 696 }
700 697
701 698 void tst_QChart::titleFont()
702 699 {
703 700 QFETCH(QFont, titleFont);
704 701 m_chart->setTitleFont(titleFont);
705 702 QCOMPARE(m_chart->titleFont(), titleFont);
706 703 }
707 704
708 705 void tst_QChart::zoomIn_data()
709 706 {
710 707 QTest::addColumn<QRectF>("rect");
711 708 QTest::newRow("null") << QRectF();
712 709 QTest::newRow("100x100") << QRectF(10,10,100,100);
713 710 QTest::newRow("200x200") << QRectF(10,10,200,200);
714 711 }
715 712
716 713
717 714 void tst_QChart::zoomIn()
718 715 {
719 716
720 717 QFETCH(QRectF, rect);
721 718 createTestData();
722 719 m_chart->createDefaultAxes();
723 720 QRectF marigns = m_chart->margins();
724 721 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
725 722 QValuesAxis* axisX = qobject_cast<QValuesAxis*>(m_chart->axisX());
726 723 QVERIFY(axisX!=0);
727 724 QValuesAxis* axisY = qobject_cast<QValuesAxis*>(m_chart->axisY());
728 725 QVERIFY(axisY!=0);
729 726 qreal minX = axisX->min();
730 727 qreal minY = axisY->min();
731 728 qreal maxX = axisX->max();
732 729 qreal maxY = axisY->max();
733 730 m_chart->zoomIn(rect);
734 731 if(rect.isValid()){
735 732 QVERIFY(minX<axisX->min());
736 733 QVERIFY(maxX>axisX->max());
737 734 QVERIFY(minY<axisY->min());
738 735 QVERIFY(maxY>axisY->max());
739 736 }
740 737
741 738 }
742 739
743 740 void tst_QChart::zoomOut_data()
744 741 {
745 742
746 743 }
747 744
748 745 void tst_QChart::zoomOut()
749 746 {
750 747 createTestData();
751 748 m_chart->createDefaultAxes();
752 749
753 750 QValuesAxis* axisX = qobject_cast<QValuesAxis*>(m_chart->axisX());
754 751 QVERIFY(axisX!=0);
755 752 QValuesAxis* axisY = qobject_cast<QValuesAxis*>(m_chart->axisY());
756 753 QVERIFY(axisY!=0);
757 754
758 755 qreal minX = axisX->min();
759 756 qreal minY = axisY->min();
760 757 qreal maxX = axisX->max();
761 758 qreal maxY = axisY->max();
762 759
763 760 m_chart->zoomIn();
764 761
765 762 QVERIFY(minX < axisX->min());
766 763 QVERIFY(maxX > axisX->max());
767 764 QVERIFY(minY < axisY->min());
768 765 QVERIFY(maxY > axisY->max());
769 766
770 767 m_chart->zoomOut();
771 768
772 769 // min x may be a zero value
773 770 if (qFuzzyIsNull(minX))
774 771 QVERIFY(qFuzzyIsNull(axisX->min()));
775 772 else
776 773 QCOMPARE(minX, axisX->min());
777 774
778 775 // min y may be a zero value
779 776 if (qFuzzyIsNull(minY))
780 777 QVERIFY(qFuzzyIsNull(axisY->min()));
781 778 else
782 779 QCOMPARE(minY, axisY->min());
783 780
784 781 QVERIFY(maxX == axisX->max());
785 782 QVERIFY(maxY == axisY->max());
786 783
787 784 }
788 785
789 786 QTEST_MAIN(tst_QChart)
790 787 #include "tst_qchart.moc"
791 788
General Comments 0
You need to be logged in to leave comments. Login now