##// END OF EJS Templates
Axes docs update
Marek Rosa -
r1636:bfe729e55a2a
parent child
Show More
@@ -1,364 +1,367
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 /*!
96 Constructs an axis object which is a child of \a parent.
97 */
95 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
98 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
96 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
99 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
97 {
100 {
98 }
101 }
99
102
100 QBarCategoriesAxis::~QBarCategoriesAxis()
103 QBarCategoriesAxis::~QBarCategoriesAxis()
101 {
104 {
102 }
105 }
103
106
104 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
107 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
105 {
108 {
106
109
107 }
110 }
108
111
109 /*!
112 /*!
110 Appends \a categories to axis
113 Appends \a categories to axis
111 */
114 */
112 void QBarCategoriesAxis::append(const QStringList &categories)
115 void QBarCategoriesAxis::append(const QStringList &categories)
113 {
116 {
114 Q_D(QBarCategoriesAxis);
117 Q_D(QBarCategoriesAxis);
115 if (d->m_categories.isEmpty()) {
118 if (d->m_categories.isEmpty()) {
116 d->m_categories.append(categories);
119 d->m_categories.append(categories);
117 setRange(categories.first(),categories.last());
120 setRange(categories.first(),categories.last());
118 }else{
121 }else{
119 d->m_categories.append(categories);
122 d->m_categories.append(categories);
120 }
123 }
121
124
122 emit categoriesChanged();
125 emit categoriesChanged();
123 }
126 }
124
127
125 /*!
128 /*!
126 Appends \a category to axis
129 Appends \a category to axis
127 */
130 */
128 void QBarCategoriesAxis::append(const QString &category)
131 void QBarCategoriesAxis::append(const QString &category)
129 {
132 {
130 Q_D(QBarCategoriesAxis);
133 Q_D(QBarCategoriesAxis);
131 if (d->m_categories.isEmpty()) {
134 if (d->m_categories.isEmpty()) {
132 d->m_categories.append(category);
135 d->m_categories.append(category);
133 setRange(category,category);
136 setRange(category,category);
134 }else{
137 }else{
135 d->m_categories.append(category);
138 d->m_categories.append(category);
136 }
139 }
137 emit categoriesChanged();
140 emit categoriesChanged();
138 }
141 }
139
142
140 /*!
143 /*!
141 Removes \a category from axis
144 Removes \a category from axis
142 */
145 */
143 void QBarCategoriesAxis::remove(const QString &category)
146 void QBarCategoriesAxis::remove(const QString &category)
144 {
147 {
145 Q_D(QBarCategoriesAxis);
148 Q_D(QBarCategoriesAxis);
146 if (d->m_categories.contains(category)) {
149 if (d->m_categories.contains(category)) {
147 d->m_categories.removeAt(d->m_categories.indexOf(category));
150 d->m_categories.removeAt(d->m_categories.indexOf(category));
148 setRange(d->m_categories.first(),d->m_categories.last());
151 setRange(d->m_categories.first(),d->m_categories.last());
149 emit categoriesChanged();
152 emit categoriesChanged();
150 }
153 }
151 }
154 }
152
155
153 /*!
156 /*!
154 Inserts \a category to axis at \a index
157 Inserts \a category to axis at \a index
155 */
158 */
156 void QBarCategoriesAxis::insert(int index, const QString &category)
159 void QBarCategoriesAxis::insert(int index, const QString &category)
157 {
160 {
158 Q_D(QBarCategoriesAxis);
161 Q_D(QBarCategoriesAxis);
159 if (d->m_categories.isEmpty()) {
162 if (d->m_categories.isEmpty()) {
160 d->m_categories.insert(index,category);
163 d->m_categories.insert(index,category);
161 setRange(category,category);
164 setRange(category,category);
162 }else{
165 }else{
163
166
164 }
167 }
165 emit categoriesChanged();
168 emit categoriesChanged();
166 }
169 }
167
170
168 /*!
171 /*!
169 Removes all categories.
172 Removes all categories.
170 */
173 */
171 void QBarCategoriesAxis::clear()
174 void QBarCategoriesAxis::clear()
172 {
175 {
173 Q_D(QBarCategoriesAxis);
176 Q_D(QBarCategoriesAxis);
174 d->m_categories.clear();
177 d->m_categories.clear();
175 setRange(QString::null,QString::null);
178 setRange(QString::null,QString::null);
176 emit categoriesChanged();
179 emit categoriesChanged();
177 }
180 }
178
181
179 void QBarCategoriesAxis::setCategories(const QStringList &categories)
182 void QBarCategoriesAxis::setCategories(const QStringList &categories)
180 {
183 {
181 Q_D(QBarCategoriesAxis);
184 Q_D(QBarCategoriesAxis);
182 if(d->m_categories!=categories){
185 if(d->m_categories!=categories){
183 d->m_categories = categories;
186 d->m_categories = categories;
184 setRange(categories.first(),categories.last());
187 setRange(categories.first(),categories.last());
185 emit categoriesChanged();
188 emit categoriesChanged();
186 }
189 }
187 }
190 }
188
191
189 QStringList QBarCategoriesAxis::categories()
192 QStringList QBarCategoriesAxis::categories()
190 {
193 {
191 Q_D(QBarCategoriesAxis);
194 Q_D(QBarCategoriesAxis);
192 return d->m_categories;
195 return d->m_categories;
193 }
196 }
194
197
195 /*!
198 /*!
196 Returns number of categories.
199 Returns number of categories.
197 */
200 */
198 int QBarCategoriesAxis::count() const
201 int QBarCategoriesAxis::count() const
199 {
202 {
200 Q_D(const QBarCategoriesAxis);
203 Q_D(const QBarCategoriesAxis);
201 return d->m_categories.count();
204 return d->m_categories.count();
202 }
205 }
203
206
204 /*!
207 /*!
205 Returns category at \a index. Index must be valid.
208 Returns category at \a index. Index must be valid.
206 */
209 */
207 QString QBarCategoriesAxis::at(int index) const
210 QString QBarCategoriesAxis::at(int index) const
208 {
211 {
209 Q_D(const QBarCategoriesAxis);
212 Q_D(const QBarCategoriesAxis);
210 return d->m_categories.at(index);
213 return d->m_categories.at(index);
211 }
214 }
212
215
213 /*!
216 /*!
214 Sets minimum category to \a min.
217 Sets minimum category to \a min.
215 */
218 */
216 void QBarCategoriesAxis::setMin(const QString& min)
219 void QBarCategoriesAxis::setMin(const QString& min)
217 {
220 {
218 Q_D(QBarCategoriesAxis);
221 Q_D(QBarCategoriesAxis);
219 setRange(min,d->m_maxCategory);
222 setRange(min,d->m_maxCategory);
220 }
223 }
221
224
222 /*!
225 /*!
223 Returns minimum category.
226 Returns minimum category.
224 */
227 */
225 QString QBarCategoriesAxis::min() const
228 QString QBarCategoriesAxis::min() const
226 {
229 {
227 Q_D(const QBarCategoriesAxis);
230 Q_D(const QBarCategoriesAxis);
228 return d->m_minCategory;
231 return d->m_minCategory;
229 }
232 }
230
233
231 /*!
234 /*!
232 Sets maximum category to \a max.
235 Sets maximum category to \a max.
233 */
236 */
234 void QBarCategoriesAxis::setMax(const QString& max)
237 void QBarCategoriesAxis::setMax(const QString& max)
235 {
238 {
236 Q_D(QBarCategoriesAxis);
239 Q_D(QBarCategoriesAxis);
237 setRange(d->m_minCategory,max);
240 setRange(d->m_minCategory,max);
238 }
241 }
239
242
240 /*!
243 /*!
241 Returns maximum category
244 Returns maximum category
242 */
245 */
243 QString QBarCategoriesAxis::max() const
246 QString QBarCategoriesAxis::max() const
244 {
247 {
245 Q_D(const QBarCategoriesAxis);
248 Q_D(const QBarCategoriesAxis);
246 return d->m_maxCategory;
249 return d->m_maxCategory;
247 }
250 }
248
251
249 /*!
252 /*!
250 Sets range from \a minCategory to \a maxCategory
253 Sets range from \a minCategory to \a maxCategory
251 */
254 */
252 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
255 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
253 {
256 {
254 Q_D(QBarCategoriesAxis);
257 Q_D(QBarCategoriesAxis);
255
258
256 int minIndex = d->m_categories.indexOf(minCategory);
259 int minIndex = d->m_categories.indexOf(minCategory);
257 if (minIndex == -1) {
260 if (minIndex == -1) {
258 return;
261 return;
259 }
262 }
260 int maxIndex = d->m_categories.indexOf(maxCategory);
263 int maxIndex = d->m_categories.indexOf(maxCategory);
261 if (maxIndex == -1) {
264 if (maxIndex == -1) {
262 return;
265 return;
263 }
266 }
264
267
265 if (maxIndex <= minIndex) {
268 if (maxIndex <= minIndex) {
266 // max must be greater than min
269 // max must be greater than min
267 return;
270 return;
268 }
271 }
269
272
270 bool changed = false;
273 bool changed = false;
271 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
274 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
272 d->m_minCategory = minCategory;
275 d->m_minCategory = minCategory;
273 d->m_min = minIndex;
276 d->m_min = minIndex;
274 emit minChanged(minCategory);
277 emit minChanged(minCategory);
275 changed = true;
278 changed = true;
276 }
279 }
277
280
278 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
281 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
279 d->m_max = maxIndex;
282 d->m_max = maxIndex;
280 d->m_maxCategory = maxCategory;
283 d->m_maxCategory = maxCategory;
281 emit maxChanged(maxCategory);
284 emit maxChanged(maxCategory);
282 changed = true;
285 changed = true;
283 }
286 }
284
287
285 if ((changed)) {
288 if ((changed)) {
286 d->emitRange();
289 d->emitRange();
287 emit categoriesChanged();
290 emit categoriesChanged();
288 }
291 }
289 }
292 }
290
293
291 /*!
294 /*!
292 Returns the type of axis.
295 Returns the type of axis.
293 */
296 */
294 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
297 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
295 {
298 {
296 return AxisTypeCategories;
299 return AxisTypeCategories;
297 }
300 }
298
301
299 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
302 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
300
303
301 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
304 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
302 QAbstractAxisPrivate(q)
305 QAbstractAxisPrivate(q)
303 {
306 {
304
307
305 }
308 }
306
309
307 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
310 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
308 {
311 {
309
312
310 }
313 }
311
314
312 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
315 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
313 {
316 {
314 setRange(min,m_maxCategory);
317 setRange(min,m_maxCategory);
315 }
318 }
316
319
317 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
320 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
318 {
321 {
319 setRange(m_minCategory,max);
322 setRange(m_minCategory,max);
320 }
323 }
321
324
322 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
325 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
323 {
326 {
324 Q_Q(QBarCategoriesAxis);
327 Q_Q(QBarCategoriesAxis);
325 QString value1 = min.toString();
328 QString value1 = min.toString();
326 QString value2 = max.toString();
329 QString value2 = max.toString();
327 q->setRange(value1,value2);
330 q->setRange(value1,value2);
328 }
331 }
329
332
330 int QBarCategoriesAxisPrivate::ticksCount() const
333 int QBarCategoriesAxisPrivate::ticksCount() const
331 {
334 {
332 return m_categories.count()+1;
335 return m_categories.count()+1;
333 }
336 }
334
337
335 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
338 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
336 {
339 {
337 m_min = min;
340 m_min = min;
338 m_max = max;
341 m_max = max;
339 m_ticksCount = count;
342 m_ticksCount = count;
340 }
343 }
341
344
342 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
345 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
343 {
346 {
344 Q_Q( QBarCategoriesAxis);
347 Q_Q( QBarCategoriesAxis);
345 if(m_orientation == Qt::Vertical){
348 if(m_orientation == Qt::Vertical){
346 return new ChartCategoriesAxisY(q,presenter);
349 return new ChartCategoriesAxisY(q,presenter);
347 }else{
350 }else{
348 return new ChartCategoriesAxisX(q,presenter);
351 return new ChartCategoriesAxisX(q,presenter);
349 }
352 }
350 }
353 }
351
354
352 void QBarCategoriesAxisPrivate::emitRange()
355 void QBarCategoriesAxisPrivate::emitRange()
353 {
356 {
354 Q_Q( QBarCategoriesAxis);
357 Q_Q( QBarCategoriesAxis);
355 if(!q->signalsBlocked()) {
358 if(!q->signalsBlocked()) {
356 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
359 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
357 }
360 }
358 }
361 }
359
362
360
363
361 #include "moc_qbarcategoriesaxis.cpp"
364 #include "moc_qbarcategoriesaxis.cpp"
362 #include "moc_qbarcategoriesaxis_p.cpp"
365 #include "moc_qbarcategoriesaxis_p.cpp"
363
366
364 QTCOMMERCIALCHART_END_NAMESPACE
367 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,169 +1,171
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.
51 */
50 QIntervalAxis::QIntervalAxis(QObject *parent):
52 QIntervalAxis::QIntervalAxis(QObject *parent):
51 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
53 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
52 {
54 {
53 }
55 }
54
56
55 QIntervalAxis::~QIntervalAxis()
57 QIntervalAxis::~QIntervalAxis()
56 {
58 {
57 }
59 }
58
60
59 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
61 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
60 {
62 {
61
63
62 }
64 }
63
65
64 /*!
66 /*!
65 Appends \a categories to axis
67 Appends \a categories to axis
66 */
68 */
67 void QIntervalAxis::append(const QString& category, qreal x)
69 void QIntervalAxis::append(const QString& category, qreal x)
68 {
70 {
69 Q_D(QIntervalAxis);
71 Q_D(QIntervalAxis);
70 if (!d->m_categories.contains(category))
72 if (!d->m_categories.contains(category))
71 {
73 {
72 if(d->m_categories.isEmpty()){
74 if(d->m_categories.isEmpty()){
73 Range range(d->m_categoryMinimum,x);
75 Range range(d->m_categoryMinimum,x);
74 d->m_categoriesMap.insert(category,range);
76 d->m_categoriesMap.insert(category,range);
75 d->m_categories.append(category);
77 d->m_categories.append(category);
76 }else{
78 }else{
77 Range range = d->m_categoriesMap.value(d->m_categories.last());
79 Range range = d->m_categoriesMap.value(d->m_categories.last());
78 d->m_categoriesMap.insert(category,Range(range.first,x));
80 d->m_categoriesMap.insert(category,Range(range.first,x));
79 d->m_categories.append(category);
81 d->m_categories.append(category);
80 }
82 }
81 setRange(d->m_min,x);
83 setRange(d->m_min,x);
82 }
84 }
83 }
85 }
84
86
85 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
87 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
86 {
88 {
87 Q_D(QIntervalAxis);
89 Q_D(QIntervalAxis);
88 if(d->m_categories.isEmpty()){
90 if(d->m_categories.isEmpty()){
89 d->m_categoryMinimum=x;
91 d->m_categoryMinimum=x;
90 }else{
92 }else{
91 Range range = d->m_categoriesMap.value(d->m_categories.first());
93 Range range = d->m_categoriesMap.value(d->m_categories.first());
92 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
94 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
93 setRange(x,d->m_min);
95 setRange(x,d->m_min);
94 }
96 }
95 }
97 }
96
98
97 /*!
99 /*!
98 Removes \a category from axis
100 Removes \a category from axis
99 */
101 */
100 void QIntervalAxis::remove(const QString &category)
102 void QIntervalAxis::remove(const QString &category)
101 {
103 {
102 Q_UNUSED(category);
104 Q_UNUSED(category);
103 //TODO
105 //TODO
104 }
106 }
105
107
106 QStringList QIntervalAxis::categories()
108 QStringList QIntervalAxis::categories()
107 {
109 {
108 Q_D(QIntervalAxis);
110 Q_D(QIntervalAxis);
109 return d->m_categories;
111 return d->m_categories;
110 }
112 }
111
113
112 /*!
114 /*!
113 Returns number of categories.
115 Returns number of categories.
114 */
116 */
115 int QIntervalAxis::count() const
117 int QIntervalAxis::count() const
116 {
118 {
117 Q_D(const QIntervalAxis);
119 Q_D(const QIntervalAxis);
118 return d->m_categories.count();
120 return d->m_categories.count();
119 }
121 }
120
122
121 /*!
123 /*!
122 Returns the type of axis.
124 Returns the type of axis.
123 */
125 */
124 QAbstractAxis::AxisType QIntervalAxis::type() const
126 QAbstractAxis::AxisType QIntervalAxis::type() const
125 {
127 {
126 return AxisTypeCategories;
128 return AxisTypeCategories;
127 }
129 }
128
130
129 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
131 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
130
132
131 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
133 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
132 QValuesAxisPrivate(q),
134 QValuesAxisPrivate(q),
133 m_categoryMinimum(0)
135 m_categoryMinimum(0)
134 {
136 {
135
137
136 }
138 }
137
139
138 QIntervalAxisPrivate::~QIntervalAxisPrivate()
140 QIntervalAxisPrivate::~QIntervalAxisPrivate()
139 {
141 {
140
142
141 }
143 }
142
144
143 int QIntervalAxisPrivate::ticksCount() const
145 int QIntervalAxisPrivate::ticksCount() const
144 {
146 {
145 return m_categories.count()+1;
147 return m_categories.count()+1;
146 }
148 }
147
149
148 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
150 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
149 {
151 {
150 m_min = min;
152 m_min = min;
151 m_max = max;
153 m_max = max;
152 m_ticksCount = count;
154 m_ticksCount = count;
153 }
155 }
154
156
155 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
157 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
156 {
158 {
157 Q_UNUSED(presenter);
159 Q_UNUSED(presenter);
158 // Q_Q( QCategoriesAxis);
160 // Q_Q( QCategoriesAxis);
159 if(m_orientation == Qt::Vertical){
161 if(m_orientation == Qt::Vertical){
160 return 0;
162 return 0;
161 }else{
163 }else{
162 return 0;
164 return 0;
163 }
165 }
164 }
166 }
165
167
166 #include "moc_qintervalaxis.cpp"
168 #include "moc_qintervalaxis.cpp"
167 #include "moc_qintervalaxis_p.cpp"
169 #include "moc_qintervalaxis_p.cpp"
168
170
169 QTCOMMERCIALCHART_END_NAMESPACE
171 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,290 +1,293
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 /*!
109 Constructs an axis object which is a child of \a parent.
110 */
108 QValuesAxis::QValuesAxis(QObject *parent) :
111 QValuesAxis::QValuesAxis(QObject *parent) :
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
112 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
110 {
113 {
111
114
112 }
115 }
113
116
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
117 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
115 {
118 {
116
119
117 }
120 }
118
121
119 QValuesAxis::~QValuesAxis()
122 QValuesAxis::~QValuesAxis()
120 {
123 {
121
124
122 }
125 }
123
126
124 void QValuesAxis::setMin(qreal min)
127 void QValuesAxis::setMin(qreal min)
125 {
128 {
126 Q_D(QValuesAxis);
129 Q_D(QValuesAxis);
127 setRange(min,d->m_max);
130 setRange(min,d->m_max);
128 }
131 }
129
132
130 qreal QValuesAxis::min() const
133 qreal QValuesAxis::min() const
131 {
134 {
132 Q_D(const QValuesAxis);
135 Q_D(const QValuesAxis);
133 return d->m_min;
136 return d->m_min;
134 }
137 }
135
138
136 void QValuesAxis::setMax(qreal max)
139 void QValuesAxis::setMax(qreal max)
137 {
140 {
138 Q_D(QValuesAxis);
141 Q_D(QValuesAxis);
139 setRange(d->m_min,max);
142 setRange(d->m_min,max);
140 }
143 }
141
144
142 qreal QValuesAxis::max() const
145 qreal QValuesAxis::max() const
143 {
146 {
144 Q_D(const QValuesAxis);
147 Q_D(const QValuesAxis);
145 return d->m_max;
148 return d->m_max;
146 }
149 }
147
150
148 /*!
151 /*!
149 Sets range from \a min to \a max on the axis.
152 Sets range from \a min to \a max on the axis.
150 */
153 */
151 void QValuesAxis::setRange(qreal min, qreal max)
154 void QValuesAxis::setRange(qreal min, qreal max)
152 {
155 {
153 Q_D(QValuesAxis);
156 Q_D(QValuesAxis);
154 bool changed = false;
157 bool changed = false;
155 if (!qFuzzyIsNull(d->m_min - min)) {
158 if (!qFuzzyIsNull(d->m_min - min)) {
156 d->m_min = min;
159 d->m_min = min;
157 changed = true;
160 changed = true;
158 emit minChanged(min);
161 emit minChanged(min);
159 }
162 }
160
163
161 if (!qFuzzyIsNull(d->m_max - max)) {
164 if (!qFuzzyIsNull(d->m_max - max)) {
162 d->m_max = max;
165 d->m_max = max;
163 changed = true;
166 changed = true;
164 emit maxChanged(max);
167 emit maxChanged(max);
165 }
168 }
166
169
167 if (changed) {
170 if (changed) {
168 d->emitRange();
171 d->emitRange();
169 emit rangeChanged(d->m_min,d->m_max);
172 emit rangeChanged(d->m_min,d->m_max);
170 }
173 }
171 }
174 }
172
175
173 /*!
176 /*!
174 Sets \a count for ticks on the axis.
177 Sets \a count for ticks on the axis.
175 */
178 */
176 void QValuesAxis::setTicksCount(int count)
179 void QValuesAxis::setTicksCount(int count)
177 {
180 {
178 Q_D(QValuesAxis);
181 Q_D(QValuesAxis);
179 if (d->m_ticksCount != count) {
182 if (d->m_ticksCount != count) {
180 d->m_ticksCount = count;
183 d->m_ticksCount = count;
181 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
184 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
182 }
185 }
183 }
186 }
184
187
185 /*!
188 /*!
186 \fn int QValuesAxis::ticksCount() const
189 \fn int QValuesAxis::ticksCount() const
187 Return number of ticks on the axis
190 Return number of ticks on the axis
188 */
191 */
189 int QValuesAxis::ticksCount() const
192 int QValuesAxis::ticksCount() const
190 {
193 {
191 Q_D(const QValuesAxis);
194 Q_D(const QValuesAxis);
192 return d->m_ticksCount;
195 return d->m_ticksCount;
193 }
196 }
194
197
195 void QValuesAxis::setNiceNumbersEnabled(bool enable)
198 void QValuesAxis::setNiceNumbersEnabled(bool enable)
196 {
199 {
197 Q_D(QValuesAxis);
200 Q_D(QValuesAxis);
198 if (d->m_niceNumbers != enable){
201 if (d->m_niceNumbers != enable){
199 d->m_niceNumbers = enable;
202 d->m_niceNumbers = enable;
200 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
203 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
201 }
204 }
202 }
205 }
203
206
204 bool QValuesAxis::niceNumbersEnabled() const
207 bool QValuesAxis::niceNumbersEnabled() const
205 {
208 {
206 Q_D(const QValuesAxis);
209 Q_D(const QValuesAxis);
207 return d->m_niceNumbers;
210 return d->m_niceNumbers;
208 }
211 }
209
212
210 QAbstractAxis::AxisType QValuesAxis::type() const
213 QAbstractAxis::AxisType QValuesAxis::type() const
211 {
214 {
212 return AxisTypeValues;
215 return AxisTypeValues;
213 }
216 }
214
217
215 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
218 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
216
219
217 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
220 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
218 QAbstractAxisPrivate(q),
221 QAbstractAxisPrivate(q),
219 m_niceNumbers(false)
222 m_niceNumbers(false)
220 {
223 {
221
224
222 }
225 }
223
226
224 QValuesAxisPrivate::~QValuesAxisPrivate()
227 QValuesAxisPrivate::~QValuesAxisPrivate()
225 {
228 {
226
229
227 }
230 }
228
231
229 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
232 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
230 {
233 {
231 Q_Q(QValuesAxis);
234 Q_Q(QValuesAxis);
232 q->setRange(min,max);
235 q->setRange(min,max);
233 q->setTicksCount(count);
236 q->setTicksCount(count);
234 }
237 }
235
238
236
239
237 void QValuesAxisPrivate::setMin(const QVariant &min)
240 void QValuesAxisPrivate::setMin(const QVariant &min)
238 {
241 {
239 Q_Q(QValuesAxis);
242 Q_Q(QValuesAxis);
240 bool ok;
243 bool ok;
241 qreal value = min.toReal(&ok);
244 qreal value = min.toReal(&ok);
242 if(ok) q->setMin(value);
245 if(ok) q->setMin(value);
243 }
246 }
244
247
245 void QValuesAxisPrivate::setMax(const QVariant &max)
248 void QValuesAxisPrivate::setMax(const QVariant &max)
246 {
249 {
247 Q_Q(QValuesAxis);
250 Q_Q(QValuesAxis);
248 bool ok;
251 bool ok;
249 qreal value = max.toReal(&ok);
252 qreal value = max.toReal(&ok);
250 if(ok) q->setMax(value);
253 if(ok) q->setMax(value);
251 }
254 }
252
255
253 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
256 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
254 {
257 {
255 Q_Q(QValuesAxis);
258 Q_Q(QValuesAxis);
256 bool ok1;
259 bool ok1;
257 bool ok2;
260 bool ok2;
258 qreal value1 = min.toReal(&ok1);
261 qreal value1 = min.toReal(&ok1);
259 qreal value2 = max.toReal(&ok2);
262 qreal value2 = max.toReal(&ok2);
260 if(ok1&&ok2) q->setRange(value1,value2);
263 if(ok1&&ok2) q->setRange(value1,value2);
261 }
264 }
262
265
263 int QValuesAxisPrivate::ticksCount() const
266 int QValuesAxisPrivate::ticksCount() const
264 {
267 {
265 return m_ticksCount;
268 return m_ticksCount;
266 }
269 }
267
270
268 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
271 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
269 {
272 {
270 Q_Q(QValuesAxis);
273 Q_Q(QValuesAxis);
271 if(m_orientation == Qt::Vertical){
274 if(m_orientation == Qt::Vertical){
272 return new ChartValuesAxisY(q,presenter);
275 return new ChartValuesAxisY(q,presenter);
273 }else{
276 }else{
274 return new ChartValuesAxisX(q,presenter);
277 return new ChartValuesAxisX(q,presenter);
275 }
278 }
276
279
277 }
280 }
278
281
279 void QValuesAxisPrivate::emitRange()
282 void QValuesAxisPrivate::emitRange()
280 {
283 {
281 Q_Q(QValuesAxis);
284 Q_Q(QValuesAxis);
282 if(!q->signalsBlocked()) {
285 if(!q->signalsBlocked()) {
283 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
286 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
284 }
287 }
285 }
288 }
286
289
287 #include "moc_qvaluesaxis.cpp"
290 #include "moc_qvaluesaxis.cpp"
288 #include "moc_qvaluesaxis_p.cpp"
291 #include "moc_qvaluesaxis_p.cpp"
289
292
290 QTCOMMERCIALCHART_END_NAMESPACE
293 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now