##// END OF EJS Templates
Various docs fixes
Marek Rosa -
r1638:039a92a11dcb
parent child
Show More
@@ -1,367 +1,373
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarcategoriesaxis.h"
21 #include "qbarcategoriesaxis.h"
22 #include "qbarcategoriesaxis_p.h"
22 #include "qbarcategoriesaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
29 /*!
30 \class QBarCategoriesAxis
30 \class QBarCategoriesAxis
31 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
31 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
32 \mainclass
32 \mainclass
33
33
34 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 */
35 */
36
36
37 /*!
37 /*!
38 \qmlclass Axis QBarCategoriesAxis
38 \qmlclass Axis QBarCategoriesAxis
39 \brief The Axis element is used for manipulating chart's axes.
39 \brief The Axis element is used for manipulating chart's axes.
40
40
41 Axis can be setup to show axis line with tick marks, grid lines and shades.
41 Axis can be setup to show axis line with tick marks, grid lines and shades.
42
42
43 To access Axes you can use ChartView API. For example:
43 To access Axes you can use ChartView API. For example:
44 \code
44 \code
45 ChartView {
45 ChartView {
46 axisX.min: "Feb"
46 axisX.min: "Feb"
47 axisX.max: "Jun"
47 axisX.max: "Jun"
48 // Add a few series...
48 // Add a few series...
49 }
49 }
50 \endcode
50 \endcode
51 */
51 */
52
52
53 /*!
53 /*!
54 \property QBarCategoriesAxis::categories
54 \property QBarCategoriesAxis::categories
55 Defines the categories of axis
55 Defines the categories of axis
56 */
56 */
57 /*!
57 /*!
58 \qmlproperty QStringList Axis::categories
58 \qmlproperty QStringList Axis::categories
59 Defines the categories of axis
59 Defines the categories of axis
60 */
60 */
61
61
62 /*!
62 /*!
63 \property QBarCategoriesAxis::min
63 \property QBarCategoriesAxis::min
64 Defines the minimum value on the axis.
64 Defines the minimum value on the axis.
65 */
65 */
66 /*!
66 /*!
67 \qmlproperty real Axis::min
67 \qmlproperty real Axis::min
68 Defines the minimum value on the axis.
68 Defines the minimum value on the axis.
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QBarCategoriesAxis::max
72 \property QBarCategoriesAxis::max
73 Defines the maximum value on the axis.
73 Defines the maximum value on the axis.
74 */
74 */
75 /*!
75 /*!
76 \qmlproperty real Axis::max
76 \qmlproperty real Axis::max
77 Defines the maximum value on the axis.
77 Defines the maximum value on the axis.
78 */
78 */
79
79
80 /*!
80 /*!
81 \fn void QBarCategoriesAxis::minChanged(const QString &min)
81 \fn void QBarCategoriesAxis::minChanged(const QString &min)
82 Axis emits signal when \a min of axis has changed.
82 Axis emits signal when \a min of axis has changed.
83 */
83 */
84
84
85 /*!
85 /*!
86 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
86 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
87 Axis emits signal when \a max of axis has changed.
87 Axis emits signal when \a max of axis has changed.
88 */
88 */
89
89
90 /*!
90 /*!
91 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
91 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
92 Axis emits signal when \a min or \a max of axis has changed.
92 Axis emits signal when \a min or \a max of axis has changed.
93 */
93 */
94
94
95 /*!
95 /*!
96 Constructs an axis object which is a child of \a parent.
96 Constructs an axis object which is a child of \a parent.
97 */
97 */
98 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
98 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
99 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
99 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
100 {
100 {
101 }
101 }
102
102
103 /*!
104 Destroys the object
105 */
103 QBarCategoriesAxis::~QBarCategoriesAxis()
106 QBarCategoriesAxis::~QBarCategoriesAxis()
104 {
107 {
105 }
108 }
106
109
110 /*!
111 \internal
112 */
107 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
113 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
108 {
114 {
109
115
110 }
116 }
111
117
112 /*!
118 /*!
113 Appends \a categories to axis
119 Appends \a categories to axis
114 */
120 */
115 void QBarCategoriesAxis::append(const QStringList &categories)
121 void QBarCategoriesAxis::append(const QStringList &categories)
116 {
122 {
117 Q_D(QBarCategoriesAxis);
123 Q_D(QBarCategoriesAxis);
118 if (d->m_categories.isEmpty()) {
124 if (d->m_categories.isEmpty()) {
119 d->m_categories.append(categories);
125 d->m_categories.append(categories);
120 setRange(categories.first(),categories.last());
126 setRange(categories.first(),categories.last());
121 }else{
127 }else{
122 d->m_categories.append(categories);
128 d->m_categories.append(categories);
123 }
129 }
124
130
125 emit categoriesChanged();
131 emit categoriesChanged();
126 }
132 }
127
133
128 /*!
134 /*!
129 Appends \a category to axis
135 Appends \a category to axis
130 */
136 */
131 void QBarCategoriesAxis::append(const QString &category)
137 void QBarCategoriesAxis::append(const QString &category)
132 {
138 {
133 Q_D(QBarCategoriesAxis);
139 Q_D(QBarCategoriesAxis);
134 if (d->m_categories.isEmpty()) {
140 if (d->m_categories.isEmpty()) {
135 d->m_categories.append(category);
141 d->m_categories.append(category);
136 setRange(category,category);
142 setRange(category,category);
137 }else{
143 }else{
138 d->m_categories.append(category);
144 d->m_categories.append(category);
139 }
145 }
140 emit categoriesChanged();
146 emit categoriesChanged();
141 }
147 }
142
148
143 /*!
149 /*!
144 Removes \a category from axis
150 Removes \a category from axis
145 */
151 */
146 void QBarCategoriesAxis::remove(const QString &category)
152 void QBarCategoriesAxis::remove(const QString &category)
147 {
153 {
148 Q_D(QBarCategoriesAxis);
154 Q_D(QBarCategoriesAxis);
149 if (d->m_categories.contains(category)) {
155 if (d->m_categories.contains(category)) {
150 d->m_categories.removeAt(d->m_categories.indexOf(category));
156 d->m_categories.removeAt(d->m_categories.indexOf(category));
151 setRange(d->m_categories.first(),d->m_categories.last());
157 setRange(d->m_categories.first(),d->m_categories.last());
152 emit categoriesChanged();
158 emit categoriesChanged();
153 }
159 }
154 }
160 }
155
161
156 /*!
162 /*!
157 Inserts \a category to axis at \a index
163 Inserts \a category to axis at \a index
158 */
164 */
159 void QBarCategoriesAxis::insert(int index, const QString &category)
165 void QBarCategoriesAxis::insert(int index, const QString &category)
160 {
166 {
161 Q_D(QBarCategoriesAxis);
167 Q_D(QBarCategoriesAxis);
162 if (d->m_categories.isEmpty()) {
168 if (d->m_categories.isEmpty()) {
163 d->m_categories.insert(index,category);
169 d->m_categories.insert(index,category);
164 setRange(category,category);
170 setRange(category,category);
165 }else{
171 }else{
166
172
167 }
173 }
168 emit categoriesChanged();
174 emit categoriesChanged();
169 }
175 }
170
176
171 /*!
177 /*!
172 Removes all categories.
178 Removes all categories.
173 */
179 */
174 void QBarCategoriesAxis::clear()
180 void QBarCategoriesAxis::clear()
175 {
181 {
176 Q_D(QBarCategoriesAxis);
182 Q_D(QBarCategoriesAxis);
177 d->m_categories.clear();
183 d->m_categories.clear();
178 setRange(QString::null,QString::null);
184 setRange(QString::null,QString::null);
179 emit categoriesChanged();
185 emit categoriesChanged();
180 }
186 }
181
187
182 void QBarCategoriesAxis::setCategories(const QStringList &categories)
188 void QBarCategoriesAxis::setCategories(const QStringList &categories)
183 {
189 {
184 Q_D(QBarCategoriesAxis);
190 Q_D(QBarCategoriesAxis);
185 if(d->m_categories!=categories){
191 if(d->m_categories!=categories){
186 d->m_categories = categories;
192 d->m_categories = categories;
187 setRange(categories.first(),categories.last());
193 setRange(categories.first(),categories.last());
188 emit categoriesChanged();
194 emit categoriesChanged();
189 }
195 }
190 }
196 }
191
197
192 QStringList QBarCategoriesAxis::categories()
198 QStringList QBarCategoriesAxis::categories()
193 {
199 {
194 Q_D(QBarCategoriesAxis);
200 Q_D(QBarCategoriesAxis);
195 return d->m_categories;
201 return d->m_categories;
196 }
202 }
197
203
198 /*!
204 /*!
199 Returns number of categories.
205 Returns number of categories.
200 */
206 */
201 int QBarCategoriesAxis::count() const
207 int QBarCategoriesAxis::count() const
202 {
208 {
203 Q_D(const QBarCategoriesAxis);
209 Q_D(const QBarCategoriesAxis);
204 return d->m_categories.count();
210 return d->m_categories.count();
205 }
211 }
206
212
207 /*!
213 /*!
208 Returns category at \a index. Index must be valid.
214 Returns category at \a index. Index must be valid.
209 */
215 */
210 QString QBarCategoriesAxis::at(int index) const
216 QString QBarCategoriesAxis::at(int index) const
211 {
217 {
212 Q_D(const QBarCategoriesAxis);
218 Q_D(const QBarCategoriesAxis);
213 return d->m_categories.at(index);
219 return d->m_categories.at(index);
214 }
220 }
215
221
216 /*!
222 /*!
217 Sets minimum category to \a min.
223 Sets minimum category to \a min.
218 */
224 */
219 void QBarCategoriesAxis::setMin(const QString& min)
225 void QBarCategoriesAxis::setMin(const QString& min)
220 {
226 {
221 Q_D(QBarCategoriesAxis);
227 Q_D(QBarCategoriesAxis);
222 setRange(min,d->m_maxCategory);
228 setRange(min,d->m_maxCategory);
223 }
229 }
224
230
225 /*!
231 /*!
226 Returns minimum category.
232 Returns minimum category.
227 */
233 */
228 QString QBarCategoriesAxis::min() const
234 QString QBarCategoriesAxis::min() const
229 {
235 {
230 Q_D(const QBarCategoriesAxis);
236 Q_D(const QBarCategoriesAxis);
231 return d->m_minCategory;
237 return d->m_minCategory;
232 }
238 }
233
239
234 /*!
240 /*!
235 Sets maximum category to \a max.
241 Sets maximum category to \a max.
236 */
242 */
237 void QBarCategoriesAxis::setMax(const QString& max)
243 void QBarCategoriesAxis::setMax(const QString& max)
238 {
244 {
239 Q_D(QBarCategoriesAxis);
245 Q_D(QBarCategoriesAxis);
240 setRange(d->m_minCategory,max);
246 setRange(d->m_minCategory,max);
241 }
247 }
242
248
243 /*!
249 /*!
244 Returns maximum category
250 Returns maximum category
245 */
251 */
246 QString QBarCategoriesAxis::max() const
252 QString QBarCategoriesAxis::max() const
247 {
253 {
248 Q_D(const QBarCategoriesAxis);
254 Q_D(const QBarCategoriesAxis);
249 return d->m_maxCategory;
255 return d->m_maxCategory;
250 }
256 }
251
257
252 /*!
258 /*!
253 Sets range from \a minCategory to \a maxCategory
259 Sets range from \a minCategory to \a maxCategory
254 */
260 */
255 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
261 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
256 {
262 {
257 Q_D(QBarCategoriesAxis);
263 Q_D(QBarCategoriesAxis);
258
264
259 int minIndex = d->m_categories.indexOf(minCategory);
265 int minIndex = d->m_categories.indexOf(minCategory);
260 if (minIndex == -1) {
266 if (minIndex == -1) {
261 return;
267 return;
262 }
268 }
263 int maxIndex = d->m_categories.indexOf(maxCategory);
269 int maxIndex = d->m_categories.indexOf(maxCategory);
264 if (maxIndex == -1) {
270 if (maxIndex == -1) {
265 return;
271 return;
266 }
272 }
267
273
268 if (maxIndex <= minIndex) {
274 if (maxIndex <= minIndex) {
269 // max must be greater than min
275 // max must be greater than min
270 return;
276 return;
271 }
277 }
272
278
273 bool changed = false;
279 bool changed = false;
274 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
280 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
275 d->m_minCategory = minCategory;
281 d->m_minCategory = minCategory;
276 d->m_min = minIndex;
282 d->m_min = minIndex;
277 emit minChanged(minCategory);
283 emit minChanged(minCategory);
278 changed = true;
284 changed = true;
279 }
285 }
280
286
281 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
287 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
282 d->m_max = maxIndex;
288 d->m_max = maxIndex;
283 d->m_maxCategory = maxCategory;
289 d->m_maxCategory = maxCategory;
284 emit maxChanged(maxCategory);
290 emit maxChanged(maxCategory);
285 changed = true;
291 changed = true;
286 }
292 }
287
293
288 if ((changed)) {
294 if ((changed)) {
289 d->emitRange();
295 d->emitRange();
290 emit categoriesChanged();
296 emit categoriesChanged();
291 }
297 }
292 }
298 }
293
299
294 /*!
300 /*!
295 Returns the type of the axis
301 Returns the type of the axis
296 */
302 */
297 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
303 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
298 {
304 {
299 return AxisTypeCategories;
305 return AxisTypeCategories;
300 }
306 }
301
307
302 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
308 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
303
309
304 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
310 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
305 QAbstractAxisPrivate(q)
311 QAbstractAxisPrivate(q)
306 {
312 {
307
313
308 }
314 }
309
315
310 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
316 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
311 {
317 {
312
318
313 }
319 }
314
320
315 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
321 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
316 {
322 {
317 setRange(min,m_maxCategory);
323 setRange(min,m_maxCategory);
318 }
324 }
319
325
320 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
326 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
321 {
327 {
322 setRange(m_minCategory,max);
328 setRange(m_minCategory,max);
323 }
329 }
324
330
325 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
331 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
326 {
332 {
327 Q_Q(QBarCategoriesAxis);
333 Q_Q(QBarCategoriesAxis);
328 QString value1 = min.toString();
334 QString value1 = min.toString();
329 QString value2 = max.toString();
335 QString value2 = max.toString();
330 q->setRange(value1,value2);
336 q->setRange(value1,value2);
331 }
337 }
332
338
333 int QBarCategoriesAxisPrivate::ticksCount() const
339 int QBarCategoriesAxisPrivate::ticksCount() const
334 {
340 {
335 return m_categories.count()+1;
341 return m_categories.count()+1;
336 }
342 }
337
343
338 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
344 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
339 {
345 {
340 m_min = min;
346 m_min = min;
341 m_max = max;
347 m_max = max;
342 m_ticksCount = count;
348 m_ticksCount = count;
343 }
349 }
344
350
345 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
351 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
346 {
352 {
347 Q_Q( QBarCategoriesAxis);
353 Q_Q( QBarCategoriesAxis);
348 if(m_orientation == Qt::Vertical){
354 if(m_orientation == Qt::Vertical){
349 return new ChartCategoriesAxisY(q,presenter);
355 return new ChartCategoriesAxisY(q,presenter);
350 }else{
356 }else{
351 return new ChartCategoriesAxisX(q,presenter);
357 return new ChartCategoriesAxisX(q,presenter);
352 }
358 }
353 }
359 }
354
360
355 void QBarCategoriesAxisPrivate::emitRange()
361 void QBarCategoriesAxisPrivate::emitRange()
356 {
362 {
357 Q_Q( QBarCategoriesAxis);
363 Q_Q( QBarCategoriesAxis);
358 if(!q->signalsBlocked()) {
364 if(!q->signalsBlocked()) {
359 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
365 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
360 }
366 }
361 }
367 }
362
368
363
369
364 #include "moc_qbarcategoriesaxis.cpp"
370 #include "moc_qbarcategoriesaxis.cpp"
365 #include "moc_qbarcategoriesaxis_p.cpp"
371 #include "moc_qbarcategoriesaxis_p.cpp"
366
372
367 QTCOMMERCIALCHART_END_NAMESPACE
373 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,171 +1,177
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qintervalaxis.h"
21 #include "qintervalaxis.h"
22 #include "qintervalaxis_p.h"
22 #include "qintervalaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
29 /*!
30 \class QIntervalAxis
30 \class QIntervalAxis
31 \brief The QIntervalAxis class is used for manipulating chart's axis.
31 \brief The QIntervalAxis class is used for manipulating chart's axis.
32 \mainclass
32 \mainclass
33
33
34 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 */
35 */
36
36
37 /*!
37 /*!
38 \qmlclass Axis QIntervalAxis
38 \qmlclass Axis QIntervalAxis
39 \brief The Axis element is used for manipulating chart's axes.
39 \brief The Axis element is used for manipulating chart's axes.
40
40
41 Axis can be setup to show axis line with tick marks, grid lines and shades.
41 Axis can be setup to show axis line with tick marks, grid lines and shades.
42
42
43 To access Axes you can use ChartView API. For example:
43 To access Axes you can use ChartView API. For example:
44 \code
44 \code
45 // TODO :)
45 // TODO :)
46 \endcode
46 \endcode
47 */
47 */
48
48
49 /*!
49 /*!
50 Constructs an axis object which is a child of \a parent.
50 Constructs an axis object which is a child of \a parent.
51 */
51 */
52 QIntervalAxis::QIntervalAxis(QObject *parent):
52 QIntervalAxis::QIntervalAxis(QObject *parent):
53 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
53 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
54 {
54 {
55 }
55 }
56
56
57 /*!
58 Destroys the object
59 */
57 QIntervalAxis::~QIntervalAxis()
60 QIntervalAxis::~QIntervalAxis()
58 {
61 {
59 }
62 }
60
63
64 /*!
65 \internal
66 */
61 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
67 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
62 {
68 {
63
69
64 }
70 }
65
71
66 /*!
72 /*!
67 Appends \a categories to axis
73 Appends \a categories to axis
68 */
74 */
69 void QIntervalAxis::append(const QString& category, qreal x)
75 void QIntervalAxis::append(const QString& category, qreal x)
70 {
76 {
71 Q_D(QIntervalAxis);
77 Q_D(QIntervalAxis);
72 if (!d->m_categories.contains(category))
78 if (!d->m_categories.contains(category))
73 {
79 {
74 if(d->m_categories.isEmpty()){
80 if(d->m_categories.isEmpty()){
75 Range range(d->m_categoryMinimum,x);
81 Range range(d->m_categoryMinimum,x);
76 d->m_categoriesMap.insert(category,range);
82 d->m_categoriesMap.insert(category,range);
77 d->m_categories.append(category);
83 d->m_categories.append(category);
78 }else{
84 }else{
79 Range range = d->m_categoriesMap.value(d->m_categories.last());
85 Range range = d->m_categoriesMap.value(d->m_categories.last());
80 d->m_categoriesMap.insert(category,Range(range.first,x));
86 d->m_categoriesMap.insert(category,Range(range.first,x));
81 d->m_categories.append(category);
87 d->m_categories.append(category);
82 }
88 }
83 setRange(d->m_min,x);
89 setRange(d->m_min,x);
84 }
90 }
85 }
91 }
86
92
87 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
93 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
88 {
94 {
89 Q_D(QIntervalAxis);
95 Q_D(QIntervalAxis);
90 if(d->m_categories.isEmpty()){
96 if(d->m_categories.isEmpty()){
91 d->m_categoryMinimum=x;
97 d->m_categoryMinimum=x;
92 }else{
98 }else{
93 Range range = d->m_categoriesMap.value(d->m_categories.first());
99 Range range = d->m_categoriesMap.value(d->m_categories.first());
94 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
100 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
95 setRange(x,d->m_min);
101 setRange(x,d->m_min);
96 }
102 }
97 }
103 }
98
104
99 /*!
105 /*!
100 Removes \a category from axis
106 Removes \a category from axis
101 */
107 */
102 void QIntervalAxis::remove(const QString &category)
108 void QIntervalAxis::remove(const QString &category)
103 {
109 {
104 Q_UNUSED(category);
110 Q_UNUSED(category);
105 //TODO
111 //TODO
106 }
112 }
107
113
108 QStringList QIntervalAxis::categories()
114 QStringList QIntervalAxis::categories()
109 {
115 {
110 Q_D(QIntervalAxis);
116 Q_D(QIntervalAxis);
111 return d->m_categories;
117 return d->m_categories;
112 }
118 }
113
119
114 /*!
120 /*!
115 Returns number of categories.
121 Returns number of categories.
116 */
122 */
117 int QIntervalAxis::count() const
123 int QIntervalAxis::count() const
118 {
124 {
119 Q_D(const QIntervalAxis);
125 Q_D(const QIntervalAxis);
120 return d->m_categories.count();
126 return d->m_categories.count();
121 }
127 }
122
128
123 /*!
129 /*!
124 Returns the type of the axis
130 Returns the type of the axis
125 */
131 */
126 QAbstractAxis::AxisType QIntervalAxis::type() const
132 QAbstractAxis::AxisType QIntervalAxis::type() const
127 {
133 {
128 return AxisTypeCategories;
134 return AxisTypeCategories;
129 }
135 }
130
136
131 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
137 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
132
138
133 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
139 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
134 QValuesAxisPrivate(q),
140 QValuesAxisPrivate(q),
135 m_categoryMinimum(0)
141 m_categoryMinimum(0)
136 {
142 {
137
143
138 }
144 }
139
145
140 QIntervalAxisPrivate::~QIntervalAxisPrivate()
146 QIntervalAxisPrivate::~QIntervalAxisPrivate()
141 {
147 {
142
148
143 }
149 }
144
150
145 int QIntervalAxisPrivate::ticksCount() const
151 int QIntervalAxisPrivate::ticksCount() const
146 {
152 {
147 return m_categories.count()+1;
153 return m_categories.count()+1;
148 }
154 }
149
155
150 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
156 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
151 {
157 {
152 m_min = min;
158 m_min = min;
153 m_max = max;
159 m_max = max;
154 m_ticksCount = count;
160 m_ticksCount = count;
155 }
161 }
156
162
157 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
163 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
158 {
164 {
159 Q_UNUSED(presenter);
165 Q_UNUSED(presenter);
160 // Q_Q( QCategoriesAxis);
166 // Q_Q( QCategoriesAxis);
161 if(m_orientation == Qt::Vertical){
167 if(m_orientation == Qt::Vertical){
162 return 0;
168 return 0;
163 }else{
169 }else{
164 return 0;
170 return 0;
165 }
171 }
166 }
172 }
167
173
168 #include "moc_qintervalaxis.cpp"
174 #include "moc_qintervalaxis.cpp"
169 #include "moc_qintervalaxis_p.cpp"
175 #include "moc_qintervalaxis_p.cpp"
170
176
171 QTCOMMERCIALCHART_END_NAMESPACE
177 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,296 +1,302
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvaluesaxis.h"
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
22 #include "qvaluesaxis_p.h"
23 #include "chartvaluesaxisx_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
24 #include "chartvaluesaxisy_p.h"
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 /*!
28 /*!
29 \class QValuesAxis
29 \class QValuesAxis
30 \brief The QValuesAxis class is used for manipulating chart's axis.
30 \brief The QValuesAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass Axis QValuesAxis
37 \qmlclass Axis QValuesAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
41
41
42 To access Axes you can use ChartView API. For example:
42 To access Axes you can use ChartView API. For example:
43 \code
43 \code
44 ChartView {
44 ChartView {
45 axisX.min: 0
45 axisX.min: 0
46 axisX.max: 3
46 axisX.max: 3
47 axisX.ticksCount: 4
47 axisX.ticksCount: 4
48 axisY.min: 0
48 axisY.min: 0
49 axisY.max: 4
49 axisY.max: 4
50 // Add a few series...
50 // Add a few series...
51 }
51 }
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \property QValuesAxis::min
56 \property QValuesAxis::min
57 Defines the minimum value on the axis.
57 Defines the minimum value on the axis.
58 */
58 */
59 /*!
59 /*!
60 \qmlproperty real Axis::min
60 \qmlproperty real Axis::min
61 Defines the minimum value on the axis.
61 Defines the minimum value on the axis.
62 */
62 */
63
63
64 /*!
64 /*!
65 \property QValuesAxis::max
65 \property QValuesAxis::max
66 Defines the maximum value on the axis.
66 Defines the maximum value on the axis.
67 */
67 */
68 /*!
68 /*!
69 \qmlproperty real Axis::max
69 \qmlproperty real Axis::max
70 Defines the maximum value on the axis.
70 Defines the maximum value on the axis.
71 */
71 */
72
72
73 /*!
73 /*!
74 \fn void QValuesAxis::minChanged(qreal min)
74 \fn void QValuesAxis::minChanged(qreal min)
75 Axis emits signal when \a min of axis has changed.
75 Axis emits signal when \a min of axis has changed.
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn void QValuesAxis::maxChanged(qreal max)
79 \fn void QValuesAxis::maxChanged(qreal max)
80 Axis emits signal when \a max of axis has changed.
80 Axis emits signal when \a max of axis has changed.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
85 Axis emits signal when \a min or \a max of axis has changed.
85 Axis emits signal when \a min or \a max of axis has changed.
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QValuesAxis::ticksCount
89 \property QValuesAxis::ticksCount
90 The number of tick marks for the axis.
90 The number of tick marks for the axis.
91 */
91 */
92
92
93 /*!
93 /*!
94 \qmlproperty int Axis::ticksCount
94 \qmlproperty int Axis::ticksCount
95 The number of tick marks for the axis.
95 The number of tick marks for the axis.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QValuesAxis::niceNumbersEnabled
99 \property QValuesAxis::niceNumbersEnabled
100 Whether the nice numbers algorithm is enabled or not for the axis.
100 Whether the nice numbers algorithm is enabled or not for the axis.
101 */
101 */
102
102
103 /*!
103 /*!
104 \qmlproperty bool Axis::niceNumbersEnabled
104 \qmlproperty bool Axis::niceNumbersEnabled
105 Whether the nice numbers algorithm is enabled or not for the axis.
105 Whether the nice numbers algorithm is enabled or not for the axis.
106 */
106 */
107
107
108 /*!
108 /*!
109 Constructs an axis object which is a child of \a parent.
109 Constructs an axis object which is a child of \a parent.
110 */
110 */
111 QValuesAxis::QValuesAxis(QObject *parent) :
111 QValuesAxis::QValuesAxis(QObject *parent) :
112 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
112 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
113 {
113 {
114
114
115 }
115 }
116
116
117 /*!
118 \internal
119 */
117 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
120 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
118 {
121 {
119
122
120 }
123 }
121
124
125 /*!
126 Destroys the object
127 */
122 QValuesAxis::~QValuesAxis()
128 QValuesAxis::~QValuesAxis()
123 {
129 {
124
130
125 }
131 }
126
132
127 void QValuesAxis::setMin(qreal min)
133 void QValuesAxis::setMin(qreal min)
128 {
134 {
129 Q_D(QValuesAxis);
135 Q_D(QValuesAxis);
130 setRange(min,d->m_max);
136 setRange(min,d->m_max);
131 }
137 }
132
138
133 qreal QValuesAxis::min() const
139 qreal QValuesAxis::min() const
134 {
140 {
135 Q_D(const QValuesAxis);
141 Q_D(const QValuesAxis);
136 return d->m_min;
142 return d->m_min;
137 }
143 }
138
144
139 void QValuesAxis::setMax(qreal max)
145 void QValuesAxis::setMax(qreal max)
140 {
146 {
141 Q_D(QValuesAxis);
147 Q_D(QValuesAxis);
142 setRange(d->m_min,max);
148 setRange(d->m_min,max);
143 }
149 }
144
150
145 qreal QValuesAxis::max() const
151 qreal QValuesAxis::max() const
146 {
152 {
147 Q_D(const QValuesAxis);
153 Q_D(const QValuesAxis);
148 return d->m_max;
154 return d->m_max;
149 }
155 }
150
156
151 /*!
157 /*!
152 Sets range from \a min to \a max on the axis.
158 Sets range from \a min to \a max on the axis.
153 */
159 */
154 void QValuesAxis::setRange(qreal min, qreal max)
160 void QValuesAxis::setRange(qreal min, qreal max)
155 {
161 {
156 Q_D(QValuesAxis);
162 Q_D(QValuesAxis);
157 bool changed = false;
163 bool changed = false;
158 if (!qFuzzyIsNull(d->m_min - min)) {
164 if (!qFuzzyIsNull(d->m_min - min)) {
159 d->m_min = min;
165 d->m_min = min;
160 changed = true;
166 changed = true;
161 emit minChanged(min);
167 emit minChanged(min);
162 }
168 }
163
169
164 if (!qFuzzyIsNull(d->m_max - max)) {
170 if (!qFuzzyIsNull(d->m_max - max)) {
165 d->m_max = max;
171 d->m_max = max;
166 changed = true;
172 changed = true;
167 emit maxChanged(max);
173 emit maxChanged(max);
168 }
174 }
169
175
170 if (changed) {
176 if (changed) {
171 d->emitRange();
177 d->emitRange();
172 emit rangeChanged(d->m_min,d->m_max);
178 emit rangeChanged(d->m_min,d->m_max);
173 }
179 }
174 }
180 }
175
181
176 /*!
182 /*!
177 Sets \a count for ticks on the axis.
183 Sets \a count for ticks on the axis.
178 */
184 */
179 void QValuesAxis::setTicksCount(int count)
185 void QValuesAxis::setTicksCount(int count)
180 {
186 {
181 Q_D(QValuesAxis);
187 Q_D(QValuesAxis);
182 if (d->m_ticksCount != count) {
188 if (d->m_ticksCount != count) {
183 d->m_ticksCount = count;
189 d->m_ticksCount = count;
184 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
190 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
185 }
191 }
186 }
192 }
187
193
188 /*!
194 /*!
189 \fn int QValuesAxis::ticksCount() const
195 \fn int QValuesAxis::ticksCount() const
190 Return number of ticks on the axis
196 Return number of ticks on the axis
191 */
197 */
192 int QValuesAxis::ticksCount() const
198 int QValuesAxis::ticksCount() const
193 {
199 {
194 Q_D(const QValuesAxis);
200 Q_D(const QValuesAxis);
195 return d->m_ticksCount;
201 return d->m_ticksCount;
196 }
202 }
197
203
198 void QValuesAxis::setNiceNumbersEnabled(bool enable)
204 void QValuesAxis::setNiceNumbersEnabled(bool enable)
199 {
205 {
200 Q_D(QValuesAxis);
206 Q_D(QValuesAxis);
201 if (d->m_niceNumbers != enable){
207 if (d->m_niceNumbers != enable){
202 d->m_niceNumbers = enable;
208 d->m_niceNumbers = enable;
203 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
209 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
204 }
210 }
205 }
211 }
206
212
207 bool QValuesAxis::niceNumbersEnabled() const
213 bool QValuesAxis::niceNumbersEnabled() const
208 {
214 {
209 Q_D(const QValuesAxis);
215 Q_D(const QValuesAxis);
210 return d->m_niceNumbers;
216 return d->m_niceNumbers;
211 }
217 }
212
218
213 /*!
219 /*!
214 Returns the type of the axis
220 Returns the type of the axis
215 */
221 */
216 QAbstractAxis::AxisType QValuesAxis::type() const
222 QAbstractAxis::AxisType QValuesAxis::type() const
217 {
223 {
218 return AxisTypeValues;
224 return AxisTypeValues;
219 }
225 }
220
226
221 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
222
228
223 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
229 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
224 QAbstractAxisPrivate(q),
230 QAbstractAxisPrivate(q),
225 m_niceNumbers(false)
231 m_niceNumbers(false)
226 {
232 {
227
233
228 }
234 }
229
235
230 QValuesAxisPrivate::~QValuesAxisPrivate()
236 QValuesAxisPrivate::~QValuesAxisPrivate()
231 {
237 {
232
238
233 }
239 }
234
240
235 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
241 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
236 {
242 {
237 Q_Q(QValuesAxis);
243 Q_Q(QValuesAxis);
238 q->setRange(min,max);
244 q->setRange(min,max);
239 q->setTicksCount(count);
245 q->setTicksCount(count);
240 }
246 }
241
247
242
248
243 void QValuesAxisPrivate::setMin(const QVariant &min)
249 void QValuesAxisPrivate::setMin(const QVariant &min)
244 {
250 {
245 Q_Q(QValuesAxis);
251 Q_Q(QValuesAxis);
246 bool ok;
252 bool ok;
247 qreal value = min.toReal(&ok);
253 qreal value = min.toReal(&ok);
248 if(ok) q->setMin(value);
254 if(ok) q->setMin(value);
249 }
255 }
250
256
251 void QValuesAxisPrivate::setMax(const QVariant &max)
257 void QValuesAxisPrivate::setMax(const QVariant &max)
252 {
258 {
253 Q_Q(QValuesAxis);
259 Q_Q(QValuesAxis);
254 bool ok;
260 bool ok;
255 qreal value = max.toReal(&ok);
261 qreal value = max.toReal(&ok);
256 if(ok) q->setMax(value);
262 if(ok) q->setMax(value);
257 }
263 }
258
264
259 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
265 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
260 {
266 {
261 Q_Q(QValuesAxis);
267 Q_Q(QValuesAxis);
262 bool ok1;
268 bool ok1;
263 bool ok2;
269 bool ok2;
264 qreal value1 = min.toReal(&ok1);
270 qreal value1 = min.toReal(&ok1);
265 qreal value2 = max.toReal(&ok2);
271 qreal value2 = max.toReal(&ok2);
266 if(ok1&&ok2) q->setRange(value1,value2);
272 if(ok1&&ok2) q->setRange(value1,value2);
267 }
273 }
268
274
269 int QValuesAxisPrivate::ticksCount() const
275 int QValuesAxisPrivate::ticksCount() const
270 {
276 {
271 return m_ticksCount;
277 return m_ticksCount;
272 }
278 }
273
279
274 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
280 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
275 {
281 {
276 Q_Q(QValuesAxis);
282 Q_Q(QValuesAxis);
277 if(m_orientation == Qt::Vertical){
283 if(m_orientation == Qt::Vertical){
278 return new ChartValuesAxisY(q,presenter);
284 return new ChartValuesAxisY(q,presenter);
279 }else{
285 }else{
280 return new ChartValuesAxisX(q,presenter);
286 return new ChartValuesAxisX(q,presenter);
281 }
287 }
282
288
283 }
289 }
284
290
285 void QValuesAxisPrivate::emitRange()
291 void QValuesAxisPrivate::emitRange()
286 {
292 {
287 Q_Q(QValuesAxis);
293 Q_Q(QValuesAxis);
288 if(!q->signalsBlocked()) {
294 if(!q->signalsBlocked()) {
289 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
295 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
290 }
296 }
291 }
297 }
292
298
293 #include "moc_qvaluesaxis.cpp"
299 #include "moc_qvaluesaxis.cpp"
294 #include "moc_qvaluesaxis_p.cpp"
300 #include "moc_qvaluesaxis_p.cpp"
295
301
296 QTCOMMERCIALCHART_END_NAMESPACE
302 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,84 +1,84
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef ABSTRACTBARSERIES_H
21 #ifndef ABSTRACTBARSERIES_H
22 #define ABSTRACTBARSERIES_H
22 #define ABSTRACTBARSERIES_H
23
23
24 #include <qabstractseries.h>
24 #include <qabstractseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QBarSet;
29 class QBarSet;
30 class QAbstractBarSeriesPrivate;
30 class QAbstractBarSeriesPrivate;
31
31
32 // Container for series
32 // Container for series
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39
39
40 protected:
40 protected:
41 explicit QAbstractBarSeries(QObject *parent = 0);
41 explicit QAbstractBarSeries(QObject *parent = 0);
42
42
43 public:
43 public:
44 virtual ~QAbstractBarSeries();
44 virtual ~QAbstractBarSeries();
45
45
46 virtual QAbstractSeries::SeriesType type() const = 0;
46 // virtual QAbstractSeries::SeriesType type() const = 0;
47
47
48 void setBarWidth(qreal width);
48 void setBarWidth(qreal width);
49 qreal barWidth() const;
49 qreal barWidth() const;
50
50
51 bool append(QBarSet *set);
51 bool append(QBarSet *set);
52 bool remove(QBarSet *set);
52 bool remove(QBarSet *set);
53 bool append(QList<QBarSet* > sets);
53 bool append(QList<QBarSet* > sets);
54 bool insert(int index, QBarSet *set);
54 bool insert(int index, QBarSet *set);
55 int count() const;
55 int count() const;
56 QList<QBarSet*> barSets() const;
56 QList<QBarSet*> barSets() const;
57 void clear();
57 void clear();
58
58
59 void setLabelsVisible(bool visible = true);
59 void setLabelsVisible(bool visible = true);
60 bool isLabelsVisible() const;
60 bool isLabelsVisible() const;
61
61
62 protected:
62 protected:
63 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0);
63 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0);
64
64
65 Q_SIGNALS:
65 Q_SIGNALS:
66 void clicked(int index, QBarSet *barset);
66 void clicked(int index, QBarSet *barset);
67 void hovered(bool status, QBarSet *barset);
67 void hovered(bool status, QBarSet *barset);
68 void countChanged();
68 void countChanged();
69 void labelsVisibleChanged();
69 void labelsVisibleChanged();
70
70
71 void barsetsAdded(QList<QBarSet*> sets);
71 void barsetsAdded(QList<QBarSet*> sets);
72 void barsetsRemoved(QList<QBarSet*> sets);
72 void barsetsRemoved(QList<QBarSet*> sets);
73
73
74 protected:
74 protected:
75 Q_DECLARE_PRIVATE(QAbstractBarSeries)
75 Q_DECLARE_PRIVATE(QAbstractBarSeries)
76 friend class BarChartItem;
76 friend class BarChartItem;
77 friend class PercentBarChartItem;
77 friend class PercentBarChartItem;
78 friend class StackedBarChartItem;
78 friend class StackedBarChartItem;
79 friend class GroupedBarChartItem;
79 friend class GroupedBarChartItem;
80 };
80 };
81
81
82 QTCOMMERCIALCHART_END_NAMESPACE
82 QTCOMMERCIALCHART_END_NAMESPACE
83
83
84 #endif // ABSTRACTBARSERIES_H
84 #endif // ABSTRACTBARSERIES_H
@@ -1,189 +1,199
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractseries.h"
21 #include "qabstractseries.h"
22 #include "qabstractseries_p.h"
22 #include "qabstractseries_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 /*!
27 /*!
28 \class QAbstractSeries
28 \class QAbstractSeries
29 \brief Base class for all QtCommercial Chart series.
29 \brief Base class for all QtCommercial Chart series.
30 \mainclass
30 \mainclass
31
31
32 Usually you use the series type specific inherited classes instead of the base class.
32 Usually you use the series type specific inherited classes instead of the base class.
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
34 QPercentBarSeries, QPieSeries
34 QPercentBarSeries, QPieSeries
35 */
35 */
36 /*!
36 /*!
37 \qmlclass AbstractSeries
37 \qmlclass AbstractSeries
38 AbstractSeries is the base class for all series.
38 AbstractSeries is the base class for all series.
39 The class cannot be instantiated by the user.
39 The class cannot be instantiated by the user.
40 */
40 */
41
41
42 /*!
42 /*!
43 \enum QAbstractSeries::SeriesType
43 \enum QAbstractSeries::SeriesType
44
44
45 The type of the series object.
45 The type of the series object.
46
46
47 \value SeriesTypeLine
47 \value SeriesTypeLine
48 \value SeriesTypeArea
48 \value SeriesTypeArea
49 \value SeriesTypeBar
49 \value SeriesTypeBar
50 \value SeriesTypeStackedBar
50 \value SeriesTypeStackedBar
51 \value SeriesTypePercentBar
51 \value SeriesTypePercentBar
52 \value SeriesTypePie
52 \value SeriesTypePie
53 \value SeriesTypeScatter
53 \value SeriesTypeScatter
54 \value SeriesTypeSpline
54 \value SeriesTypeSpline
55 */
55 */
56
56
57 /*!
57 /*!
58 \property QAbstractSeries::type
58 \property QAbstractSeries::type
59 The type of the series.
59 The type of the series.
60 */
60 */
61 /*!
61 /*!
62 \qmlproperty ChartView.SeriesType AbstractSeries::type
62 \qmlproperty ChartView.SeriesType AbstractSeries::type
63 The type of the series.
63 The type of the series.
64 */
64 */
65
65
66 /*!
66 /*!
67 \property QAbstractSeries::name
67 \property QAbstractSeries::name
68 \brief name of the series property. The name is shown in legend for QXYSeries.
68 \brief name of the series property. The name is shown in legend for QXYSeries.
69 */
69 */
70 /*!
70 /*!
71 \qmlproperty string AbstractSeries::name
71 \qmlproperty string AbstractSeries::name
72 Name of the series. The name is shown in legend for QXYSeries.
72 Name of the series. The name is shown in legend for QXYSeries.
73 */
73 */
74
74
75 /*!
75 /*!
76 \fn void QAbstractSeries::nameChanged()
76 \fn void QAbstractSeries::nameChanged()
77 This signal is emitted when the series name changes.
77 This signal is emitted when the series name changes.
78 */
78 */
79 /*!
79 /*!
80 \qmlsignal AbstractSeries::nameChanged()
80 \qmlsignal AbstractSeries::nameChanged()
81 This signal is emitted when the series name changes.
81 This signal is emitted when the series name changes.
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QAbstractSeries::visible
85 \property QAbstractSeries::visible
86 \brief whether the series is visible or not; true by default.
86 \brief whether the series is visible or not; true by default.
87 */
87 */
88
88
89 /*!
89 /*!
90 \fn void QAbstractSeries::visibleChanged()
90 \fn void QAbstractSeries::visibleChanged()
91 Emitted when the series visibility changes.
91 Emitted when the series visibility changes.
92 */
92 */
93
93
94 /*!
94 /*!
95 \internal
95 \internal
96 \brief Constructs ChartSeries object with \a parent.
96 \brief Constructs ChartSeries object with \a parent.
97 */
97 */
98 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
98 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
99 QObject(parent),
99 QObject(parent),
100 d_ptr(&d)
100 d_ptr(&d)
101 {
101 {
102 }
102 }
103
103
104 /*!
104 /*!
105 \brief Virtual destructor for the chart series.
105 \brief Virtual destructor for the chart series.
106 */
106 */
107 QAbstractSeries::~QAbstractSeries()
107 QAbstractSeries::~QAbstractSeries()
108 {
108 {
109 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
109 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
110 }
110 }
111
111
112 void QAbstractSeries::setName(const QString& name)
112 void QAbstractSeries::setName(const QString& name)
113 {
113 {
114 if (name != d_ptr->m_name) {
114 if (name != d_ptr->m_name) {
115 d_ptr->m_name = name;
115 d_ptr->m_name = name;
116 emit nameChanged();
116 emit nameChanged();
117 }
117 }
118 }
118 }
119
119
120 QString QAbstractSeries::name() const
120 QString QAbstractSeries::name() const
121 {
121 {
122 return d_ptr->m_name;
122 return d_ptr->m_name;
123 }
123 }
124
124
125 /*!
125 /*!
126 Sets the visibility of series to \a visible
126 Sets the visibility of series to \a visible
127 */
127 */
128 void QAbstractSeries::setVisible(bool visible)
128 void QAbstractSeries::setVisible(bool visible)
129 {
129 {
130 if (visible != d_ptr->m_visible) {
130 if (visible != d_ptr->m_visible) {
131 d_ptr->m_visible = visible;
131 d_ptr->m_visible = visible;
132 emit visibleChanged();
132 emit visibleChanged();
133 }
133 }
134 }
134 }
135
135
136 /*!
136 /*!
137 Returns the visibility of series
137 Returns the visibility of series
138 */
138 */
139 bool QAbstractSeries::isVisible() const
139 bool QAbstractSeries::isVisible() const
140 {
140 {
141 return d_ptr->m_visible;
141 return d_ptr->m_visible;
142 }
142 }
143
143
144 /*!
144 /*!
145 \brief Returns the chart where series belongs to.
145 \brief Returns the chart where series belongs to.
146
146
147 Set automatically when the series is added to the chart
147 Set automatically when the series is added to the chart
148 and unset when the series is removed from the chart.
148 and unset when the series is removed from the chart.
149 */
149 */
150 QChart* QAbstractSeries::chart() const
150 QChart* QAbstractSeries::chart() const
151 {
151 {
152 return d_ptr->m_chart;
152 return d_ptr->m_chart;
153 }
153 }
154
154
155 void QAbstractSeries::adjustView()
155 void QAbstractSeries::adjustView()
156 {
156 {
157 //TODO:
157 //TODO:
158 }
158 }
159
159
160 /*!
161 \brief Sets the visibility of the series to true
162
163 \sa setVisible(), isVisible()
164 */
160 void QAbstractSeries::show()
165 void QAbstractSeries::show()
161 {
166 {
162 setVisible(true);
167 setVisible(true);
163 }
168 }
164
169
170 /*!
171 \brief Sets the visibility of the series to false
172
173 \sa setVisible(), isVisible()
174 */
165 void QAbstractSeries::hide()
175 void QAbstractSeries::hide()
166 {
176 {
167 setVisible(false);
177 setVisible(false);
168 }
178 }
169
179
170 ///////////////////////////////////////////////////////////////////////////////////////////////////
180 ///////////////////////////////////////////////////////////////////////////////////////////////////
171
181
172 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
182 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
173 q_ptr(q),
183 q_ptr(q),
174 m_chart(0),
184 m_chart(0),
175 m_dataset(0),
185 m_dataset(0),
176 m_visible(true)
186 m_visible(true)
177 {
187 {
178 }
188 }
179
189
180 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
190 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
181 {
191 {
182 }
192 }
183
193
184 #include "moc_qabstractseries.cpp"
194 #include "moc_qabstractseries.cpp"
185 #include "moc_qabstractseries_p.cpp"
195 #include "moc_qabstractseries_p.cpp"
186
196
187 QTCOMMERCIALCHART_END_NAMESPACE
197 QTCOMMERCIALCHART_END_NAMESPACE
188
198
189
199
@@ -1,465 +1,485
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include <QGraphicsScene>
27 #include <QGraphicsScene>
28 #include <QGraphicsSceneResizeEvent>
28 #include <QGraphicsSceneResizeEvent>
29 #include <QGraphicsLayout>
29 #include <QGraphicsLayout>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \enum QChart::ChartTheme
34 \enum QChart::ChartTheme
35
35
36 This enum describes the theme used by the chart.
36 This enum describes the theme used by the chart.
37
37
38 \value ChartThemeLight The default theme
38 \value ChartThemeLight The default theme
39 \value ChartThemeBlueCerulean
39 \value ChartThemeBlueCerulean
40 \value ChartThemeDark
40 \value ChartThemeDark
41 \value ChartThemeBrownSand
41 \value ChartThemeBrownSand
42 \value ChartThemeBlueNcs
42 \value ChartThemeBlueNcs
43 \value ChartThemeHighContrast
43 \value ChartThemeHighContrast
44 \value ChartThemeBlueIcy
44 \value ChartThemeBlueIcy
45 */
45 */
46
46
47 /*!
47 /*!
48 \enum QChart::AnimationOption
48 \enum QChart::AnimationOption
49
49
50 For enabling/disabling animations. Defaults to NoAnimation.
50 For enabling/disabling animations. Defaults to NoAnimation.
51
51
52 \value NoAnimation
52 \value NoAnimation
53 \value GridAxisAnimations
53 \value GridAxisAnimations
54 \value SeriesAnimations
54 \value SeriesAnimations
55 \value AllAnimations
55 \value AllAnimations
56 */
56 */
57
57
58 /*!
58 /*!
59 \class QChart
59 \class QChart
60 \brief QtCommercial chart API.
60 \brief QtCommercial chart API.
61
61
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 representation of different types of series and other chart related objects like
63 representation of different types of series and other chart related objects like
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 convenience class QChartView instead of QChart.
65 convenience class QChartView instead of QChart.
66 \sa QChartView
66 \sa QChartView
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QChart::animationOptions
70 \property QChart::animationOptions
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QChart::backgroundVisible
75 \property QChart::backgroundVisible
76 Whether the chart background is visible or not.
76 Whether the chart background is visible or not.
77 \sa setBackgroundBrush(), setBackgroundPen()
77 \sa setBackgroundBrush(), setBackgroundPen()
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QChart::dropShadowEnabled
81 \property QChart::dropShadowEnabled
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
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 \property QChart::margins
87 \property QChart::margins
88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
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 \property QChart::theme
92 \property QChart::theme
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 different themes.
95 different themes.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QChart::title
100 \property QChart::title
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
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 \fn void QChart::marginsChanged(QRectF newMargins)
105 \fn void QChart::marginsChanged(QRectF newMargins)
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
107 modify axes or hide/show legend.
107 modify axes or hide/show legend.
108 */
108 */
109
109
110 /*!
110 /*!
111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
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 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
114 d_ptr(new QChartPrivate())
114 d_ptr(new QChartPrivate())
115 {
115 {
116 d_ptr->m_dataset = new ChartDataSet(this);
116 d_ptr->m_dataset = new ChartDataSet(this);
117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
118 d_ptr->createConnections();
118 d_ptr->createConnections();
119 d_ptr->m_legend = new LegendScroller(this);
119 d_ptr->m_legend = new LegendScroller(this);
120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
122 setLayout(d_ptr->m_presenter->layout());
122 setLayout(d_ptr->m_presenter->layout());
123 }
123 }
124
124
125 /*!
125 /*!
126 Destroys the object and it's children, like series and axis objects added to it.
126 Destroys the object and it's children, like series and axis objects added to it.
127 */
127 */
128 QChart::~QChart()
128 QChart::~QChart()
129 {
129 {
130 //delete first presenter , since this is a root of all the graphical items
130 //delete first presenter , since this is a root of all the graphical items
131 setLayout(0);
131 setLayout(0);
132 delete d_ptr->m_presenter;
132 delete d_ptr->m_presenter;
133 d_ptr->m_presenter=0;
133 d_ptr->m_presenter=0;
134 }
134 }
135
135
136 /*!
136 /*!
137 Adds the \a series onto the chart and takes the ownership of the object.
137 Adds the \a series onto the chart and takes the ownership of the object.
138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 the y axis).
139 the y axis).
140
140
141 \sa removeSeries(), removeAllSeries()
141 \sa removeSeries(), removeAllSeries()
142 */
142 */
143 void QChart::addSeries(QAbstractSeries *series)
143 void QChart::addSeries(QAbstractSeries *series)
144 {
144 {
145 Q_ASSERT(series);
145 Q_ASSERT(series);
146 d_ptr->m_dataset->addSeries(series);
146 d_ptr->m_dataset->addSeries(series);
147 }
147 }
148
148
149 /*!
149 /*!
150 Removes the \a series specified in a perameter from the QChartView.
150 Removes the \a series specified in a perameter from the QChartView.
151 It releses its ownership of the specified QChartSeries object.
151 It releses its ownership of the specified QChartSeries object.
152 It does not delete the pointed QChartSeries data object
152 It does not delete the pointed QChartSeries data object
153 \sa addSeries(), removeAllSeries()
153 \sa addSeries(), removeAllSeries()
154 */
154 */
155 void QChart::removeSeries(QAbstractSeries *series)
155 void QChart::removeSeries(QAbstractSeries *series)
156 {
156 {
157 Q_ASSERT(series);
157 Q_ASSERT(series);
158 d_ptr->m_dataset->removeSeries(series);
158 d_ptr->m_dataset->removeSeries(series);
159 }
159 }
160
160
161 /*!
161 /*!
162 Removes all the QChartSeries that have been added to the QChartView
162 Removes all the QChartSeries that have been added to the QChartView
163 It also deletes the pointed QChartSeries data objects
163 It also deletes the pointed QChartSeries data objects
164 \sa addSeries(), removeSeries()
164 \sa addSeries(), removeSeries()
165 */
165 */
166 void QChart::removeAllSeries()
166 void QChart::removeAllSeries()
167 {
167 {
168 d_ptr->m_dataset->removeAllSeries();
168 d_ptr->m_dataset->removeAllSeries();
169 }
169 }
170
170
171 /*!
171 /*!
172 Sets the \a brush that is used for painting the background of the chart area.
172 Sets the \a brush that is used for painting the background of the chart area.
173 */
173 */
174 void QChart::setBackgroundBrush(const QBrush& brush)
174 void QChart::setBackgroundBrush(const QBrush& brush)
175 {
175 {
176 d_ptr->m_presenter->setBackgroundBrush(brush);
176 d_ptr->m_presenter->setBackgroundBrush(brush);
177 }
177 }
178
178
179 /*!
179 /*!
180 Gets the brush that is used for painting the background of the chart area.
180 Gets the brush that is used for painting the background of the chart area.
181 */
181 */
182 QBrush QChart::backgroundBrush() const
182 QBrush QChart::backgroundBrush() const
183 {
183 {
184 return d_ptr->m_presenter->backgroundBrush();
184 return d_ptr->m_presenter->backgroundBrush();
185 }
185 }
186
186
187 /*!
187 /*!
188 Sets the \a pen that is used for painting the background of the chart area.
188 Sets the \a pen that is used for painting the background of the chart area.
189 */
189 */
190 void QChart::setBackgroundPen(const QPen& pen)
190 void QChart::setBackgroundPen(const QPen& pen)
191 {
191 {
192 d_ptr->m_presenter->setBackgroundPen(pen);
192 d_ptr->m_presenter->setBackgroundPen(pen);
193 }
193 }
194
194
195 /*!
195 /*!
196 Gets the pen that is used for painting the background of the chart area.
196 Gets the pen that is used for painting the background of the chart area.
197 */
197 */
198 QPen QChart::backgroundPen() const
198 QPen QChart::backgroundPen() const
199 {
199 {
200 return d_ptr->m_presenter->backgroundPen();
200 return d_ptr->m_presenter->backgroundPen();
201 }
201 }
202
202
203 /*!
203 /*!
204 Sets the chart \a title. The description text that is drawn above the chart.
204 Sets the chart \a title. The description text that is drawn above the chart.
205 */
205 */
206 void QChart::setTitle(const QString& title)
206 void QChart::setTitle(const QString& title)
207 {
207 {
208 d_ptr->m_presenter->setTitle(title);
208 d_ptr->m_presenter->setTitle(title);
209 }
209 }
210
210
211 /*!
211 /*!
212 Returns the chart title. The description text that is drawn above the chart.
212 Returns the chart title. The description text that is drawn above the chart.
213 */
213 */
214 QString QChart::title() const
214 QString QChart::title() const
215 {
215 {
216 return d_ptr->m_presenter->title();
216 return d_ptr->m_presenter->title();
217 }
217 }
218
218
219 /*!
219 /*!
220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 */
221 */
222 void QChart::setTitleFont(const QFont& font)
222 void QChart::setTitleFont(const QFont& font)
223 {
223 {
224 d_ptr->m_presenter->setTitleFont(font);
224 d_ptr->m_presenter->setTitleFont(font);
225 }
225 }
226
226
227 /*!
227 /*!
228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 */
229 */
230 QFont QChart::titleFont() const
230 QFont QChart::titleFont() const
231 {
231 {
232 return d_ptr->m_presenter->titleFont();
232 return d_ptr->m_presenter->titleFont();
233 }
233 }
234
234
235 /*!
235 /*!
236 Sets the \a brush used for rendering the title text.
236 Sets the \a brush used for rendering the title text.
237 */
237 */
238 void QChart::setTitleBrush(const QBrush &brush)
238 void QChart::setTitleBrush(const QBrush &brush)
239 {
239 {
240 d_ptr->m_presenter->setTitleBrush(brush);
240 d_ptr->m_presenter->setTitleBrush(brush);
241 }
241 }
242
242
243 /*!
243 /*!
244 Returns the brush used for rendering the title text.
244 Returns the brush used for rendering the title text.
245 */
245 */
246 QBrush QChart::titleBrush() const
246 QBrush QChart::titleBrush() const
247 {
247 {
248 return d_ptr->m_presenter->titleBrush();
248 return d_ptr->m_presenter->titleBrush();
249 }
249 }
250
250
251 void QChart::setTheme(QChart::ChartTheme theme)
251 void QChart::setTheme(QChart::ChartTheme theme)
252 {
252 {
253 d_ptr->m_presenter->setTheme(theme);
253 d_ptr->m_presenter->setTheme(theme);
254 }
254 }
255
255
256 QChart::ChartTheme QChart::theme() const
256 QChart::ChartTheme QChart::theme() const
257 {
257 {
258 return d_ptr->m_presenter->theme();
258 return d_ptr->m_presenter->theme();
259 }
259 }
260
260
261 /*!
261 /*!
262 Zooms in the view by a factor of 2
262 Zooms in the view by a factor of 2
263 */
263 */
264 void QChart::zoomIn()
264 void QChart::zoomIn()
265 {
265 {
266 d_ptr->m_presenter->zoomIn(2.0);
266 d_ptr->m_presenter->zoomIn(2.0);
267 }
267 }
268
268
269 /*!
269 /*!
270 Zooms in the view to a maximum level at which \a rect is still fully visible.
270 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 */
271 */
272 void QChart::zoomIn(const QRectF& rect)
272 void QChart::zoomIn(const QRectF& rect)
273 {
273 {
274 if (!rect.isValid()) return;
274 if (!rect.isValid()) return;
275 d_ptr->m_presenter->zoomIn(rect);
275 d_ptr->m_presenter->zoomIn(rect);
276 }
276 }
277
277
278 /*!
278 /*!
279 Restores the view zoom level to the previous one.
279 Restores the view zoom level to the previous one.
280 */
280 */
281 void QChart::zoomOut()
281 void QChart::zoomOut()
282 {
282 {
283 d_ptr->m_presenter->zoomOut(2.0);
283 d_ptr->m_presenter->zoomOut(2.0);
284 }
284 }
285
285
286 /*!
286 /*!
287 Zooms in the view by a \a factor.
287 Zooms in the view by a \a factor.
288
288
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 */
290 */
291 void QChart::zoom(qreal factor)
291 void QChart::zoom(qreal factor)
292 {
292 {
293 if (qFuzzyIsNull(factor))
293 if (qFuzzyIsNull(factor))
294 return;
294 return;
295
295
296 if (qFuzzyCompare(factor, 1.0))
296 if (qFuzzyCompare(factor, 1.0))
297 return;
297 return;
298
298
299 if (factor < 0)
299 if (factor < 0)
300 return;
300 return;
301
301
302 if (factor > 1.0)
302 if (factor > 1.0)
303 d_ptr->m_presenter->zoomIn(factor);
303 d_ptr->m_presenter->zoomIn(factor);
304 else
304 else
305 d_ptr->m_presenter->zoomOut(1.0 / factor);
305 d_ptr->m_presenter->zoomOut(1.0 / factor);
306 }
306 }
307
307
308 /*!
308 /*!
309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
310 If no series is provided then pointer to currently visible axis is provided
310 */
311 */
311 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
312 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
312 {
313 {
313 return d_ptr->m_dataset->axisX(series);
314 return d_ptr->m_dataset->axisX(series);
314 }
315 }
315
316
316 /*!
317 /*!
317 Returns the pointer to the y axis object of the chart asociated with the specified \a series
318 Returns the pointer to the y axis object of the chart asociated with the specified \a series
319 If no series is provided then pointer to currently visible axis is provided
318 */
320 */
319 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
321 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
320 {
322 {
321 return d_ptr->m_dataset->axisY(series);
323 return d_ptr->m_dataset->axisY(series);
322 }
324 }
323
325
324 /*!
326 /*!
325 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.
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.
326
328
327 Creates the axes for the chart based on the series that has already been added to the chart.
329 Creates the axes for the chart based on the series that has already been added to the chart.
328 If QXYSeries derived series has been added to the chart then QValuesAxes are created as X and Y axes for the series.
330
329 If QBarSeries or series types derived from it has been added then QBarCategoriesAxis is created as X axis and QValueAxis as Y axis.
331 \table
332 \header
333 \o Series type
334 \o X-axis
335 \o Y-axis
336 \row
337 \o QXYSeries
338 \o QValuesAxis
339 \o QValuesAxis
340 \row
341 \o QBarSeries
342 \o QBarCategoriesAxis
343 \o QValuesAxis
344 \row
345 \o QPieSeries
346 \o None
347 \o None
348 \endtable
349
330 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.
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.
331 If there are sevaral series added of different types then each series gets its own axes pair.
351 If there are sevaral series added of different types then each series gets its own axes pair.
332
352
333 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.
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.
334
354
335 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
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.
336 QPieSeries does not create any axes.
356 QPieSeries does not create any axes.
337
357
338 \sa axisX(), axisY(), setAxisX(), setAxisY()
358 \sa axisX(), axisY(), setAxisX(), setAxisY()
339 */
359 */
340 void QChart::createDefaultAxes()
360 void QChart::createDefaultAxes()
341 {
361 {
342 d_ptr->m_dataset->createDefaultAxes();
362 d_ptr->m_dataset->createDefaultAxes();
343 }
363 }
344
364
345 /*!
365 /*!
346 Returns the legend object of the chart. Ownership stays in chart.
366 Returns the legend object of the chart. Ownership stays in chart.
347 */
367 */
348 QLegend* QChart::legend() const
368 QLegend* QChart::legend() const
349 {
369 {
350 return d_ptr->m_legend;
370 return d_ptr->m_legend;
351 }
371 }
352
372
353 /*!
373 /*!
354 Returns the rect that contains information about margins (distance between chart widget edge and axes).
374 Returns the rect that contains information about margins (distance between chart widget edge and axes).
355 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
375 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
356 */
376 */
357 QRectF QChart::margins() const
377 QRectF QChart::margins() const
358 {
378 {
359 return d_ptr->m_presenter->margins();
379 return d_ptr->m_presenter->margins();
360 }
380 }
361
381
362 /*!
382 /*!
363 Sets animation \a options for the chart
383 Sets animation \a options for the chart
364 */
384 */
365
385
366 void QChart::setAnimationOptions(AnimationOptions options)
386 void QChart::setAnimationOptions(AnimationOptions options)
367 {
387 {
368 d_ptr->m_presenter->setAnimationOptions(options);
388 d_ptr->m_presenter->setAnimationOptions(options);
369 }
389 }
370
390
371 QChart::AnimationOptions QChart::animationOptions() const
391 QChart::AnimationOptions QChart::animationOptions() const
372 {
392 {
373 return d_ptr->m_presenter->animationOptions();
393 return d_ptr->m_presenter->animationOptions();
374 }
394 }
375
395
376 /*!
396 /*!
377 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
397 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
378 */
398 */
379 void QChart::scroll(qreal dx, qreal dy)
399 void QChart::scroll(qreal dx, qreal dy)
380 {
400 {
381 d_ptr->m_presenter->scroll(dx, dy);
401 d_ptr->m_presenter->scroll(dx, dy);
382 }
402 }
383
403
384 void QChart::setBackgroundVisible(bool visible)
404 void QChart::setBackgroundVisible(bool visible)
385 {
405 {
386 d_ptr->m_presenter->setBackgroundVisible(visible);
406 d_ptr->m_presenter->setBackgroundVisible(visible);
387 }
407 }
388
408
389 bool QChart::isBackgroundVisible() const
409 bool QChart::isBackgroundVisible() const
390 {
410 {
391 return d_ptr->m_presenter->isBackgroundVisible();
411 return d_ptr->m_presenter->isBackgroundVisible();
392 }
412 }
393
413
394 void QChart::setDropShadowEnabled(bool enabled)
414 void QChart::setDropShadowEnabled(bool enabled)
395 {
415 {
396 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
416 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
397 }
417 }
398
418
399 bool QChart::isDropShadowEnabled() const
419 bool QChart::isDropShadowEnabled() const
400 {
420 {
401 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
421 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
402 }
422 }
403
423
404 /*!
424 /*!
405 Returns all the series that are added to the chart.
425 Returns all the series that are added to the chart.
406
426
407 \sa addSeries(), removeSeries(), removeAllSeries()
427 \sa addSeries(), removeSeries(), removeAllSeries()
408 */
428 */
409 QList<QAbstractSeries*> QChart::series() const
429 QList<QAbstractSeries*> QChart::series() const
410 {
430 {
411 return d_ptr->m_dataset->series();
431 return d_ptr->m_dataset->series();
412 }
432 }
413
433
414 void QChart::setMarginsMinimum(const QRectF& margins)
434 void QChart::setMarginsMinimum(const QRectF& margins)
415 {
435 {
416 d_ptr->m_presenter->setMarginsMinimum(margins);
436 d_ptr->m_presenter->setMarginsMinimum(margins);
417 }
437 }
418
438
419 /*!
439 /*!
420 Sets \a axis to the chart, which will control the presentation of the \a series
440 Sets \a axis to the chart, which will control the presentation of the \a series
421
441
422 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
442 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
423 */
443 */
424 void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series)
444 void QChart::setAxisX(QAbstractAxis* axis , QAbstractSeries *series)
425 {
445 {
426 d_ptr->m_dataset->setAxisX(series,axis);
446 d_ptr->m_dataset->setAxisX(series,axis);
427 }
447 }
428
448
429 /*!
449 /*!
430 Sets \a axis to the chart, which will control the presentation of the \a series
450 Sets \a axis to the chart, which will control the presentation of the \a series
431
451
432 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
452 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
433 */
453 */
434 void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series)
454 void QChart::setAxisY( QAbstractAxis* axis , QAbstractSeries *series)
435 {
455 {
436 d_ptr->m_dataset->setAxisY(series,axis);
456 d_ptr->m_dataset->setAxisY(series,axis);
437 }
457 }
438
458
439 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
459 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
440
460
441 QChartPrivate::QChartPrivate():
461 QChartPrivate::QChartPrivate():
442 m_legend(0),
462 m_legend(0),
443 m_dataset(0),
463 m_dataset(0),
444 m_presenter(0)
464 m_presenter(0)
445 {
465 {
446
466
447 }
467 }
448
468
449 QChartPrivate::~QChartPrivate()
469 QChartPrivate::~QChartPrivate()
450 {
470 {
451
471
452 }
472 }
453
473
454 void QChartPrivate::createConnections()
474 void QChartPrivate::createConnections()
455 {
475 {
456 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
476 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
457 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
477 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
458 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
478 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
459 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
479 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
460 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
480 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
461 }
481 }
462
482
463 #include "moc_qchart.cpp"
483 #include "moc_qchart.cpp"
464
484
465 QTCOMMERCIALCHART_END_NAMESPACE
485 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now