##// END OF EJS Templates
Refactor categories implementation...
Michal Klocek -
r1611:9f1825280c4a
parent child
Show More
@@ -1,93 +1,93
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QABSTRACTAXIS_P_H
30 #ifndef QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
32
32
33 #include "qabstractaxis.h"
33 #include "qabstractaxis.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class ChartPresenter;
37 class ChartPresenter;
38 class ChartAxis;
38 class ChartAxis;
39
39
40 class QAbstractAxisPrivate : public QObject
40 class QAbstractAxisPrivate : public QObject
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 QAbstractAxisPrivate(QAbstractAxis *q);
44 QAbstractAxisPrivate(QAbstractAxis *q);
45 ~QAbstractAxisPrivate();
45 ~QAbstractAxisPrivate();
46
46
47 Q_SIGNALS:
47 Q_SIGNALS:
48 void updated();
48 void updated();
49
49
50 public:
50 public:
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
52 virtual void updateRange() = 0;
52 virtual void emitRange() = 0;
53
53
54 protected:
54 protected:
55 virtual void setMin(const QVariant &min) = 0;
55 virtual void setMin(const QVariant &min) = 0;
56 virtual void setMax(const QVariant &max) = 0;
56 virtual void setMax(const QVariant &max) = 0;
57 virtual void setRange(const QVariant &min, const QVariant &max, bool force = false) = 0;
57 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
58 virtual int ticksCount() const = 0;
58 virtual int ticksCount() const = 0;
59
59
60 public:
60 public:
61 QAbstractAxis *q_ptr;
61 QAbstractAxis *q_ptr;
62
62
63 bool m_axisVisible;
63 bool m_axisVisible;
64 QPen m_axisPen;
64 QPen m_axisPen;
65 QBrush m_axisBrush;
65 QBrush m_axisBrush;
66
66
67 bool m_gridLineVisible;
67 bool m_gridLineVisible;
68 QPen m_gridLinePen;
68 QPen m_gridLinePen;
69
69
70 bool m_labelsVisible;
70 bool m_labelsVisible;
71 QPen m_labelsPen;
71 QPen m_labelsPen;
72 QBrush m_labelsBrush;
72 QBrush m_labelsBrush;
73 QFont m_labelsFont;
73 QFont m_labelsFont;
74 int m_labelsAngle;
74 int m_labelsAngle;
75
75
76 bool m_shadesVisible;
76 bool m_shadesVisible;
77 QPen m_shadesPen;
77 QPen m_shadesPen;
78 QBrush m_shadesBrush;
78 QBrush m_shadesBrush;
79 qreal m_shadesOpacity;
79 qreal m_shadesOpacity;
80
80
81 Qt::Orientation m_orientation;
81 Qt::Orientation m_orientation;
82
82
83 // range
83 // range
84 qreal m_min;
84 qreal m_min;
85 qreal m_max;
85 qreal m_max;
86 int m_ticksCount;
86 int m_ticksCount;
87
87
88 friend class QAbstractAxis;
88 friend class QAbstractAxis;
89 };
89 };
90
90
91 QTCOMMERCIALCHART_END_NAMESPACE
91 QTCOMMERCIALCHART_END_NAMESPACE
92
92
93 #endif
93 #endif
@@ -1,296 +1,297
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 "qcategoriesaxis.h"
21 #include "qcategoriesaxis.h"
22 #include "qcategoriesaxis_p.h"
22 #include "qcategoriesaxis_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
27
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
29
29 QCategoriesAxis::QCategoriesAxis(QObject *parent):
30 QCategoriesAxis::QCategoriesAxis(QObject *parent):
30 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
31 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
31 {
32 {
32 }
33 }
33
34
34 QCategoriesAxis::~QCategoriesAxis()
35 QCategoriesAxis::~QCategoriesAxis()
35 {
36 {
36 }
37 }
37
38
38 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
39 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
39 {
40 {
40
41
41 }
42 }
42
43
43 /*!
44 /*!
44 Appends \a categories to axis
45 Appends \a categories to axis
45 */
46 */
46 void QCategoriesAxis::append(const QStringList &categories)
47 void QCategoriesAxis::append(const QStringList &categories)
47 {
48 {
48 Q_D(QCategoriesAxis);
49 Q_D(QCategoriesAxis);
49 if (d->m_categories.isEmpty()) {
50 if (d->m_categories.isEmpty()) {
50 d->m_minCategory = categories.first();
51 d->m_categories.append(categories);
51 d->m_maxCategory = categories.last();
52 setRange(categories.first(),categories.last());
53 }else{
54 d->m_categories.append(categories);
52 }
55 }
53
56
54 d->m_categories.append(categories);
55 emit categoriesChanged();
57 emit categoriesChanged();
56 }
58 }
57
59
58 /*!
60 /*!
59 Appends \a category to axis
61 Appends \a category to axis
60 */
62 */
61 void QCategoriesAxis::append(const QString &category)
63 void QCategoriesAxis::append(const QString &category)
62 {
64 {
63 Q_D(QCategoriesAxis);
65 Q_D(QCategoriesAxis);
64 if (d->m_categories.isEmpty()) {
66 if (d->m_categories.isEmpty()) {
65 d->m_minCategory = category;
67 d->m_categories.append(category);
66 d->m_maxCategory = category;
68 setRange(category,category);
67 }
69 }else{
68
70 d->m_categories.append(category);
69 d->m_categories.append(category);
71 }
70 emit categoriesChanged();
72 emit categoriesChanged();
71 }
73 }
72
74
73 /*!
75 /*!
74 Removes \a category from axis
76 Removes \a category from axis
75 */
77 */
76 void QCategoriesAxis::remove(const QString &category)
78 void QCategoriesAxis::remove(const QString &category)
77 {
79 {
78 Q_D(QCategoriesAxis);
80 Q_D(QCategoriesAxis);
79 if (d->m_categories.contains(category)) {
81 if (d->m_categories.contains(category)) {
80 d->m_categories.removeAt(d->m_categories.indexOf(category));
82 d->m_categories.removeAt(d->m_categories.indexOf(category));
81 d->m_minCategory = d->m_categories.first();
83 setRange(d->m_categories.first(),d->m_categories.last());
82 d->m_maxCategory = d->m_categories.last();
83 emit categoriesChanged();
84 emit categoriesChanged();
84 }
85 }
85 }
86 }
86
87
87 /*!
88 /*!
88 Inserts \a category to axis at \a index
89 Inserts \a category to axis at \a index
89 */
90 */
90 void QCategoriesAxis::insert(int index, const QString &category)
91 void QCategoriesAxis::insert(int index, const QString &category)
91 {
92 {
92 Q_D(QCategoriesAxis);
93 Q_D(QCategoriesAxis);
93 if (d->m_categories.isEmpty()) {
94 if (d->m_categories.isEmpty()) {
94 d->m_minCategory = category;
95 d->m_categories.insert(index,category);
95 d->m_maxCategory = category;
96 setRange(category,category);
97 }else{
98
96 }
99 }
97 d->m_categories.insert(index,category);
98 emit categoriesChanged();
100 emit categoriesChanged();
99 }
101 }
100
102
101 /*!
103 /*!
102 Removes all categories.
104 Removes all categories.
103 */
105 */
104 void QCategoriesAxis::clear()
106 void QCategoriesAxis::clear()
105 {
107 {
106 Q_D(QCategoriesAxis);
108 Q_D(QCategoriesAxis);
107 d->m_categories.clear();
109 d->m_categories.clear();
108 d->m_minCategory.clear();
110 setRange(QString::null,QString::null);
109 d->m_maxCategory.clear();
110 emit categoriesChanged();
111 emit categoriesChanged();
111 }
112 }
112
113
113 void QCategoriesAxis::setCategories(const QStringList &categories)
114 void QCategoriesAxis::setCategories(const QStringList &categories)
114 {
115 {
115 Q_D(QCategoriesAxis);
116 Q_D(QCategoriesAxis);
117 if(d->m_categories!=categories){
116 d->m_categories = categories;
118 d->m_categories = categories;
117 d->m_minCategory = categories.first();
119 setRange(categories.first(),categories.last());
118 d->m_maxCategory = categories.last();
119 emit categoriesChanged();
120 emit categoriesChanged();
121 }
120 }
122 }
121
123
122 QStringList QCategoriesAxis::categories()
124 QStringList QCategoriesAxis::categories()
123 {
125 {
124 Q_D(QCategoriesAxis);
126 Q_D(QCategoriesAxis);
125 return d->m_categories;
127 return d->m_categories;
126 }
128 }
127
129
128 /*!
130 /*!
129 Returns number of categories.
131 Returns number of categories.
130 */
132 */
131 int QCategoriesAxis::count() const
133 int QCategoriesAxis::count() const
132 {
134 {
133 Q_D(const QCategoriesAxis);
135 Q_D(const QCategoriesAxis);
134 return d->m_categories.count();
136 return d->m_categories.count();
135 }
137 }
136
138
137 /*!
139 /*!
138 Returns category at \a index. Index must be valid.
140 Returns category at \a index. Index must be valid.
139 */
141 */
140 QString QCategoriesAxis::at(int index) const
142 QString QCategoriesAxis::at(int index) const
141 {
143 {
142 Q_D(const QCategoriesAxis);
144 Q_D(const QCategoriesAxis);
143 return d->m_categories.at(index);
145 return d->m_categories.at(index);
144 }
146 }
145
147
146 /*!
148 /*!
147 Sets minimum category to \a min.
149 Sets minimum category to \a min.
148 */
150 */
149 void QCategoriesAxis::setMin(const QString& min)
151 void QCategoriesAxis::setMin(const QString& min)
150 {
152 {
151 Q_D(QCategoriesAxis);
153 Q_D(QCategoriesAxis);
152 setRange(min,d->m_maxCategory);
154 setRange(min,d->m_maxCategory);
153 }
155 }
154
156
155 /*!
157 /*!
156 Returns minimum category.
158 Returns minimum category.
157 */
159 */
158 QString QCategoriesAxis::min() const
160 QString QCategoriesAxis::min() const
159 {
161 {
160 Q_D(const QCategoriesAxis);
162 Q_D(const QCategoriesAxis);
161 return d->m_minCategory;
163 return d->m_minCategory;
162 }
164 }
163
165
164 /*!
166 /*!
165 Sets maximum category to \a max.
167 Sets maximum category to \a max.
166 */
168 */
167 void QCategoriesAxis::setMax(const QString& max)
169 void QCategoriesAxis::setMax(const QString& max)
168 {
170 {
169 Q_D(QCategoriesAxis);
171 Q_D(QCategoriesAxis);
170 setRange(d->m_minCategory,max);
172 setRange(d->m_minCategory,max);
171 }
173 }
172
174
173 /*!
175 /*!
174 Returns maximum category
176 Returns maximum category
175 */
177 */
176 QString QCategoriesAxis::max() const
178 QString QCategoriesAxis::max() const
177 {
179 {
178 Q_D(const QCategoriesAxis);
180 Q_D(const QCategoriesAxis);
179 return d->m_maxCategory;
181 return d->m_maxCategory;
180 }
182 }
181
183
182 /*!
184 /*!
183 Sets range from \a minCategory to \a maxCategory
185 Sets range from \a minCategory to \a maxCategory
184 */
186 */
185 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
187 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
186 {
188 {
187 Q_D(QCategoriesAxis);
189 Q_D(QCategoriesAxis);
188
190
189 int minIndex = d->m_categories.indexOf(minCategory);
191 int minIndex = d->m_categories.indexOf(minCategory);
190 if (minIndex == -1) {
192 if (minIndex == -1) {
191 return;
193 return;
192 }
194 }
193 int maxIndex = d->m_categories.indexOf(maxCategory);
195 int maxIndex = d->m_categories.indexOf(maxCategory);
194 if (maxIndex == -1) {
196 if (maxIndex == -1) {
195 return;
197 return;
196 }
198 }
197
199
198 if (maxIndex <= minIndex) {
200 if (maxIndex <= minIndex) {
199 // max must be greater than min
201 // max must be greater than min
200 return;
202 return;
201 }
203 }
202
204
203 d->m_minCategory = minCategory;
204 d->m_maxCategory = maxCategory;
205
206 bool changed = false;
205 bool changed = false;
207 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
206 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
207 d->m_minCategory = minCategory;
208 d->m_min = minIndex;
208 d->m_min = minIndex;
209 changed = true;
209 changed = true;
210 }
210 }
211
211
212 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
212 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
213 d->m_max = maxIndex;
213 d->m_max = maxIndex;
214 d->m_maxCategory = maxCategory;
214 changed = true;
215 changed = true;
215 }
216 }
216
217
217 if ((changed)) {
218 if ((changed)) {
218 if(!signalsBlocked()){
219 d->emitRange();
219 emit d->changed(d->m_min -0.5, d->m_max +0.5, qCeil(d->m_max + 0.5) -qCeil(d->m_min - 0.5) +1, false);
220 }
221 emit categoriesChanged();
220 emit categoriesChanged();
222 }
221 }
223 }
222 }
224
223
225 /*!
224 /*!
226 Returns the type of axis.
225 Returns the type of axis.
227 */
226 */
228 QAbstractAxis::AxisType QCategoriesAxis::type() const
227 QAbstractAxis::AxisType QCategoriesAxis::type() const
229 {
228 {
230 return AxisTypeCategories;
229 return AxisTypeCategories;
231 }
230 }
232
231
233 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
232 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
234
233
235 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
234 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
236 QAbstractAxisPrivate(q)
235 QAbstractAxisPrivate(q)
237 {
236 {
238
237
239 }
238 }
240
239
241 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
240 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
242 {
241 {
243
242
244 }
243 }
245
244
246 void QCategoriesAxisPrivate::setMin(const QVariant &min)
245 void QCategoriesAxisPrivate::setMin(const QVariant &min)
247 {
246 {
248 setRange(min,m_maxCategory);
247 setRange(min,m_maxCategory);
249 }
248 }
250
249
251 void QCategoriesAxisPrivate::setMax(const QVariant &max)
250 void QCategoriesAxisPrivate::setMax(const QVariant &max)
252 {
251 {
253 setRange(m_minCategory,max);
252 setRange(m_minCategory,max);
254 }
253 }
255
254
256 void QCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
255 void QCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
257 {
256 {
258 Q_UNUSED(force); // TODO: use this?
259 Q_Q(QCategoriesAxis);
257 Q_Q(QCategoriesAxis);
260 QString value1 = min.toString();
258 QString value1 = min.toString();
261 QString value2 = max.toString();
259 QString value2 = max.toString();
262 q->setRange(value1,value2);
260 q->setRange(value1,value2);
263 }
261 }
264
262
265 int QCategoriesAxisPrivate::ticksCount() const
263 int QCategoriesAxisPrivate::ticksCount() const
266 {
264 {
267 return m_categories.count()+1;
265 return m_categories.count()+1;
268 }
266 }
269
267
270 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
268 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
271 {
269 {
272 m_min = min;
270 m_min = min;
273 m_max = max;
271 m_max = max;
274 m_ticksCount = count;
272 m_ticksCount = count;
275 }
273 }
276
274
277 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
275 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
278 {
276 {
279 Q_Q( QCategoriesAxis);
277 Q_Q( QCategoriesAxis);
280 if(m_orientation == Qt::Vertical){
278 if(m_orientation == Qt::Vertical){
281 return new ChartCategoriesAxisY(q,presenter);
279 return new ChartCategoriesAxisY(q,presenter);
282 }else{
280 }else{
283 return new ChartCategoriesAxisX(q,presenter);
281 return new ChartCategoriesAxisX(q,presenter);
284 }
282 }
285 }
283 }
286
284
287 void QCategoriesAxisPrivate::updateRange()
285 void QCategoriesAxisPrivate::emitRange()
288 {
286 {
289 setRange(m_min,m_max,true);
287 Q_Q( QCategoriesAxis);
288 if(!q->signalsBlocked()) {
289 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
290 }
290 }
291 }
291
292
292
293
293 #include "moc_qcategoriesaxis.cpp"
294 #include "moc_qcategoriesaxis.cpp"
294 #include "moc_qcategoriesaxis_p.cpp"
295 #include "moc_qcategoriesaxis_p.cpp"
295
296
296 QTCOMMERCIALCHART_END_NAMESPACE
297 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,71 +1,76
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 QCATEGORIESAXIS_H
21 #ifndef QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QCategoriesAxisPrivate;
28 class QCategoriesAxisPrivate;
29
29
30 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QAbstractAxis
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34 Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged)
34
36
35 public:
37 public:
36 explicit QCategoriesAxis(QObject *parent = 0);
38 explicit QCategoriesAxis(QObject *parent = 0);
37 ~QCategoriesAxis();
39 ~QCategoriesAxis();
38
40
39 protected:
41 protected:
40 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
42 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
41
43
42 public:
44 public:
43 AxisType type() const;
45 AxisType type() const;
44 void append(const QStringList &categories);
46 void append(const QStringList &categories);
45 void append(const QString &category);
47 void append(const QString &category);
46 void remove(const QString &category);
48 void remove(const QString &category);
47 void insert(int index, const QString &category);
49 void insert(int index, const QString &category);
48 void clear();
50 void clear();
49 void setCategories(const QStringList &categories);
51 void setCategories(const QStringList &categories);
50 QStringList categories();
52 QStringList categories();
51 int count() const;
53 int count() const;
52 QString at(int index) const;
54 QString at(int index) const;
53
55
54 //range handling
56 //range handling
55 void setMin(const QString& minCategory);
57 void setMin(const QString& minCategory);
56 QString min() const;
58 QString min() const;
57 void setMax(const QString& maxCategory);
59 void setMax(const QString& maxCategory);
58 QString max() const;
60 QString max() const;
59 void setRange(const QString& minCategory, const QString& maxCategory);
61 void setRange(const QString& minCategory, const QString& maxCategory);
60
62
61 Q_SIGNALS:
63 Q_SIGNALS:
62 void categoriesChanged();
64 void categoriesChanged();
65 void minChanged(const QString &min);
66 void maxChanged(const QString &max);
67 void rangeChanged(const QString &min, const QString &max);
63
68
64 private:
69 private:
65 Q_DECLARE_PRIVATE(QCategoriesAxis)
70 Q_DECLARE_PRIVATE(QCategoriesAxis)
66 Q_DISABLE_COPY(QCategoriesAxis)
71 Q_DISABLE_COPY(QCategoriesAxis)
67 };
72 };
68
73
69 QTCOMMERCIALCHART_END_NAMESPACE
74 QTCOMMERCIALCHART_END_NAMESPACE
70
75
71 #endif // QCATEGORIESAXIS_H
76 #endif // QCATEGORIESAXIS_H
@@ -1,74 +1,74
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QCATEGORIESAXIS_P_H
30 #ifndef QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
32
32
33 #include "qcategoriesaxis.h"
33 #include "qcategoriesaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QCategoriesAxisPrivate : public QAbstractAxisPrivate
38 class QCategoriesAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41
41
42 public:
42 public:
43 QCategoriesAxisPrivate(QCategoriesAxis *q);
43 QCategoriesAxisPrivate(QCategoriesAxis *q);
44 ~QCategoriesAxisPrivate();
44 ~QCategoriesAxisPrivate();
45
45
46 public:
46 public:
47 ChartAxis* createGraphics(ChartPresenter* presenter);
47 ChartAxis* createGraphics(ChartPresenter* presenter);
48 void updateRange();
48 void emitRange();
49
49
50 private:
50 private:
51 //range handling
51 //range handling
52 void setMin(const QVariant &min);
52 void setMin(const QVariant &min);
53 void setMax(const QVariant &max);
53 void setMax(const QVariant &max);
54 void setRange(const QVariant &min, const QVariant &max, bool force = false);
54 void setRange(const QVariant &min, const QVariant &max);
55 int ticksCount() const;
55 int ticksCount() const;
56
56
57 Q_SIGNALS:
57 Q_SIGNALS:
58 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
58 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
59
59
60 public Q_SLOTS:
60 public Q_SLOTS:
61 void handleAxisRangeChanged(qreal min, qreal max,int count);
61 void handleAxisRangeChanged(qreal min, qreal max,int count);
62
62
63 private:
63 private:
64 QStringList m_categories;
64 QStringList m_categories;
65 QString m_minCategory;
65 QString m_minCategory;
66 QString m_maxCategory;
66 QString m_maxCategory;
67
67
68 private:
68 private:
69 Q_DECLARE_PUBLIC(QCategoriesAxis)
69 Q_DECLARE_PUBLIC(QCategoriesAxis)
70 };
70 };
71
71
72 QTCOMMERCIALCHART_END_NAMESPACE
72 QTCOMMERCIALCHART_END_NAMESPACE
73
73
74 #endif // QCATEGORIESAXIS_P_H
74 #endif // QCATEGORIESAXIS_P_H
@@ -1,290 +1,290
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 QValuesAxis::QValuesAxis(QObject *parent) :
108 QValuesAxis::QValuesAxis(QObject *parent) :
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
110 {
110 {
111
111
112 }
112 }
113
113
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
115 {
115 {
116
116
117 }
117 }
118
118
119 QValuesAxis::~QValuesAxis()
119 QValuesAxis::~QValuesAxis()
120 {
120 {
121
121
122 }
122 }
123
123
124 void QValuesAxis::setMin(qreal min)
124 void QValuesAxis::setMin(qreal min)
125 {
125 {
126 Q_D(QValuesAxis);
126 Q_D(QValuesAxis);
127 setRange(min,d->m_max);
127 setRange(min,d->m_max);
128 }
128 }
129
129
130 qreal QValuesAxis::min() const
130 qreal QValuesAxis::min() const
131 {
131 {
132 Q_D(const QValuesAxis);
132 Q_D(const QValuesAxis);
133 return d->m_min;
133 return d->m_min;
134 }
134 }
135
135
136 void QValuesAxis::setMax(qreal max)
136 void QValuesAxis::setMax(qreal max)
137 {
137 {
138 Q_D(QValuesAxis);
138 Q_D(QValuesAxis);
139 setRange(d->m_min,max);
139 setRange(d->m_min,max);
140 }
140 }
141
141
142 qreal QValuesAxis::max() const
142 qreal QValuesAxis::max() const
143 {
143 {
144 Q_D(const QValuesAxis);
144 Q_D(const QValuesAxis);
145 return d->m_max;
145 return d->m_max;
146 }
146 }
147
147
148 /*!
148 /*!
149 Sets range from \a min to \a max on the axis.
149 Sets range from \a min to \a max on the axis.
150 */
150 */
151 void QValuesAxis::setRange(qreal min, qreal max)
151 void QValuesAxis::setRange(qreal min, qreal max)
152 {
152 {
153 Q_D(QValuesAxis);
153 Q_D(QValuesAxis);
154 bool changed = false;
154 bool changed = false;
155 if (!qFuzzyIsNull(d->m_min - min)) {
155 if (!qFuzzyIsNull(d->m_min - min)) {
156 d->m_min = min;
156 d->m_min = min;
157 changed = true;
157 changed = true;
158 emit minChanged(min);
158 emit minChanged(min);
159 }
159 }
160
160
161 if (!qFuzzyIsNull(d->m_max - max)) {
161 if (!qFuzzyIsNull(d->m_max - max)) {
162 d->m_max = max;
162 d->m_max = max;
163 changed = true;
163 changed = true;
164 emit maxChanged(max);
164 emit maxChanged(max);
165 }
165 }
166
166
167 if (changed) {
167 if (changed) {
168 d->emitRange();
168 emit rangeChanged(d->m_min,d->m_max);
169 emit rangeChanged(d->m_min,d->m_max);
169 if(!signalsBlocked()){
170 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
171 }
172 }
170 }
173 }
171 }
174
172
175 /*!
173 /*!
176 Sets \a count for ticks on the axis.
174 Sets \a count for ticks on the axis.
177 */
175 */
178 void QValuesAxis::setTicksCount(int count)
176 void QValuesAxis::setTicksCount(int count)
179 {
177 {
180 Q_D(QValuesAxis);
178 Q_D(QValuesAxis);
181 if (d->m_ticksCount != count) {
179 if (d->m_ticksCount != count) {
182 d->m_ticksCount = count;
180 d->m_ticksCount = count;
183 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
181 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
184 }
182 }
185 }
183 }
186
184
187 /*!
185 /*!
188 \fn int QValuesAxis::ticksCount() const
186 \fn int QValuesAxis::ticksCount() const
189 Return number of ticks on the axis
187 Return number of ticks on the axis
190 */
188 */
191 int QValuesAxis::ticksCount() const
189 int QValuesAxis::ticksCount() const
192 {
190 {
193 Q_D(const QValuesAxis);
191 Q_D(const QValuesAxis);
194 return d->m_ticksCount;
192 return d->m_ticksCount;
195 }
193 }
196
194
197 void QValuesAxis::setNiceNumbersEnabled(bool enable)
195 void QValuesAxis::setNiceNumbersEnabled(bool enable)
198 {
196 {
199 Q_D(QValuesAxis);
197 Q_D(QValuesAxis);
200 if (d->m_niceNumbers != enable){
198 if (d->m_niceNumbers != enable){
201 d->m_niceNumbers = enable;
199 d->m_niceNumbers = enable;
202 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
200 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
203 }
201 }
204 }
202 }
205
203
206 bool QValuesAxis::niceNumbersEnabled() const
204 bool QValuesAxis::niceNumbersEnabled() const
207 {
205 {
208 Q_D(const QValuesAxis);
206 Q_D(const QValuesAxis);
209 return d->m_niceNumbers;
207 return d->m_niceNumbers;
210 }
208 }
211
209
212 QAbstractAxis::AxisType QValuesAxis::type() const
210 QAbstractAxis::AxisType QValuesAxis::type() const
213 {
211 {
214 return AxisTypeValues;
212 return AxisTypeValues;
215 }
213 }
216
214
217 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
215 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
218
216
219 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
217 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
220 QAbstractAxisPrivate(q),
218 QAbstractAxisPrivate(q),
221 m_niceNumbers(false)
219 m_niceNumbers(false)
222 {
220 {
223
221
224 }
222 }
225
223
226 QValuesAxisPrivate::~QValuesAxisPrivate()
224 QValuesAxisPrivate::~QValuesAxisPrivate()
227 {
225 {
228
226
229 }
227 }
230
228
231 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
229 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
232 {
230 {
233 Q_Q(QValuesAxis);
231 Q_Q(QValuesAxis);
234 q->setRange(min,max);
232 q->setRange(min,max);
235 q->setTicksCount(count);
233 q->setTicksCount(count);
236 }
234 }
237
235
238
236
239 void QValuesAxisPrivate::setMin(const QVariant &min)
237 void QValuesAxisPrivate::setMin(const QVariant &min)
240 {
238 {
241 Q_Q(QValuesAxis);
239 Q_Q(QValuesAxis);
242 bool ok;
240 bool ok;
243 qreal value = min.toReal(&ok);
241 qreal value = min.toReal(&ok);
244 if(ok) q->setMin(value);
242 if(ok) q->setMin(value);
245 }
243 }
246
244
247 void QValuesAxisPrivate::setMax(const QVariant &max)
245 void QValuesAxisPrivate::setMax(const QVariant &max)
248 {
246 {
249 Q_Q(QValuesAxis);
247 Q_Q(QValuesAxis);
250 bool ok;
248 bool ok;
251 qreal value = max.toReal(&ok);
249 qreal value = max.toReal(&ok);
252 if(ok) q->setMax(value);
250 if(ok) q->setMax(value);
253 }
251 }
254
252
255 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
253 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
256 {
254 {
257 Q_UNUSED(force); // TODO: use this
258 Q_Q(QValuesAxis);
255 Q_Q(QValuesAxis);
259 bool ok1;
256 bool ok1;
260 bool ok2;
257 bool ok2;
261 qreal value1 = min.toReal(&ok1);
258 qreal value1 = min.toReal(&ok1);
262 qreal value2 = max.toReal(&ok2);
259 qreal value2 = max.toReal(&ok2);
263 if(ok1&&ok2) q->setRange(value1,value2);
260 if(ok1&&ok2) q->setRange(value1,value2);
264 }
261 }
265
262
266 int QValuesAxisPrivate::ticksCount() const
263 int QValuesAxisPrivate::ticksCount() const
267 {
264 {
268 return m_ticksCount;
265 return m_ticksCount;
269 }
266 }
270
267
271 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
268 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
272 {
269 {
273 Q_Q(QValuesAxis);
270 Q_Q(QValuesAxis);
274 if(m_orientation == Qt::Vertical){
271 if(m_orientation == Qt::Vertical){
275 return new ChartValuesAxisY(q,presenter);
272 return new ChartValuesAxisY(q,presenter);
276 }else{
273 }else{
277 return new ChartValuesAxisX(q,presenter);
274 return new ChartValuesAxisX(q,presenter);
278 }
275 }
279
276
280 }
277 }
281
278
282 void QValuesAxisPrivate::updateRange()
279 void QValuesAxisPrivate::emitRange()
283 {
280 {
284 setRange(m_min,m_max,true);
281 Q_Q(QValuesAxis);
282 if(!q->signalsBlocked()) {
283 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
284 }
285 }
285 }
286
286
287 #include "moc_qvaluesaxis.cpp"
287 #include "moc_qvaluesaxis.cpp"
288 #include "moc_qvaluesaxis_p.cpp"
288 #include "moc_qvaluesaxis_p.cpp"
289
289
290 QTCOMMERCIALCHART_END_NAMESPACE
290 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,68 +1,68
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QVALUESAXIS_P_H
30 #ifndef QVALUESAXIS_P_H
31 #define QVALUESAXIS_P_H
31 #define QVALUESAXIS_P_H
32
32
33 #include "qvaluesaxis.h"
33 #include "qvaluesaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QValuesAxisPrivate : public QAbstractAxisPrivate
38 class QValuesAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 QValuesAxisPrivate(QValuesAxis *q);
42 QValuesAxisPrivate(QValuesAxis *q);
43 ~QValuesAxisPrivate();
43 ~QValuesAxisPrivate();
44
44
45 Q_SIGNALS:
45 Q_SIGNALS:
46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
47
47
48 public Q_SLOTS:
48 public Q_SLOTS:
49 void handleAxisRangeChanged(qreal min, qreal max,int count);
49 void handleAxisRangeChanged(qreal min, qreal max,int count);
50
50
51 public:
51 public:
52 ChartAxis* createGraphics(ChartPresenter* presenter);
52 ChartAxis* createGraphics(ChartPresenter* presenter);
53 void updateRange();
53 void emitRange();
54
54
55 protected:
55 protected:
56 void setMin(const QVariant &min);
56 void setMin(const QVariant &min);
57 void setMax(const QVariant &max);
57 void setMax(const QVariant &max);
58 void setRange(const QVariant &min, const QVariant &max, bool force = false);
58 void setRange(const QVariant &min, const QVariant &max);
59 int ticksCount() const;
59 int ticksCount() const;
60
60
61 private:
61 private:
62 bool m_niceNumbers;
62 bool m_niceNumbers;
63 Q_DECLARE_PUBLIC(QValuesAxis)
63 Q_DECLARE_PUBLIC(QValuesAxis)
64 };
64 };
65
65
66 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
67
67
68 #endif // QVALUESAXIS_P_H
68 #endif // QVALUESAXIS_P_H
@@ -1,447 +1,446
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 "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qvaluesaxis.h"
23 #include "qvaluesaxis.h"
24 #include "qcategoriesaxis.h"
24 #include "qcategoriesaxis.h"
25 #include "qvaluesaxis_p.h"
25 #include "qvaluesaxis_p.h"
26 #include "qabstractseries_p.h"
26 #include "qabstractseries_p.h"
27 #include "qabstractbarseries.h"
27 #include "qabstractbarseries.h"
28 #include "qstackedbarseries.h"
28 #include "qstackedbarseries.h"
29 #include "qpercentbarseries.h"
29 #include "qpercentbarseries.h"
30 #include "qpieseries.h"
30 #include "qpieseries.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
35 m_domainIndex(0)
35 m_domainIndex(0)
36 {
36 {
37
37
38 }
38 }
39
39
40 ChartDataSet::~ChartDataSet()
40 ChartDataSet::~ChartDataSet()
41 {
41 {
42 removeAllSeries();
42 removeAllSeries();
43 }
43 }
44
44
45 void ChartDataSet::addSeries(QAbstractSeries* series)
45 void ChartDataSet::addSeries(QAbstractSeries* series)
46 {
46 {
47 Domain* domain = m_seriesDomainMap.value(series);
47 Domain* domain = m_seriesDomainMap.value(series);
48
48
49 if(domain) {
49 if(domain) {
50 qWarning() << "Can not add series. Series already on the chart";
50 qWarning() << "Can not add series. Series already on the chart";
51 return;
51 return;
52 }
52 }
53
53
54 series->setParent(this); // take ownership
54 series->setParent(this); // take ownership
55
55
56 domain = new Domain(series);
56 domain = new Domain(series);
57
57
58 m_seriesDomainMap.insert(series,domain);
58 m_seriesDomainMap.insert(series,domain);
59
59
60 series->d_ptr->scaleDomain(*domain);
60 series->d_ptr->scaleDomain(*domain);
61
61
62 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
62 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
63
63
64 int key=0;
64 int key=0;
65 while (i.hasNext()) {
65 while (i.hasNext()) {
66 i.next();
66 i.next();
67 if(i.key()!=key) {
67 if(i.key()!=key) {
68 break;
68 break;
69 }
69 }
70 key++;
70 key++;
71 }
71 }
72
72
73 m_indexSeriesMap.insert(key,series);
73 m_indexSeriesMap.insert(key,series);
74
74
75 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
75 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
76 series->d_ptr->m_dataset = this;
76 series->d_ptr->m_dataset = this;
77
77
78 emit seriesAdded(series,domain);
78 emit seriesAdded(series,domain);
79
79
80 }
80 }
81
81
82 void ChartDataSet::createDefaultAxes()
82 void ChartDataSet::createDefaultAxes()
83 {
83 {
84
84
85 if(m_seriesDomainMap.isEmpty()) return;
85 if(m_seriesDomainMap.isEmpty()) return;
86
86
87 QAbstractAxis::AxisTypes typeX(0);
87 QAbstractAxis::AxisTypes typeX(0);
88 QAbstractAxis::AxisTypes typeY(0);
88 QAbstractAxis::AxisTypes typeY(0);
89
89
90 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
90 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
91 while (i.hasNext()) {
91 while (i.hasNext()) {
92 i.next();
92 i.next();
93 removeAxes(i.key());
93 removeAxes(i.key());
94 }
94 }
95
95
96 i.toFront();
96 i.toFront();
97
97
98 while (i.hasNext()) {
98 while (i.hasNext()) {
99 i.next();
99 i.next();
100 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
100 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
101 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
101 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
102 if(axisX) typeX&=axisX->type();
102 if(axisX) typeX&=axisX->type();
103 else typeX|=i.key()->d_ptr->defaultAxisXType();
103 else typeX|=i.key()->d_ptr->defaultAxisXType();
104 if(axisY) typeY&=axisY->type();
104 if(axisY) typeY&=axisY->type();
105 else typeY|=i.key()->d_ptr->defaultAxisYType();
105 else typeY|=i.key()->d_ptr->defaultAxisYType();
106 }
106 }
107
107
108
108
109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
110 {
110 {
111 i.toFront();
111 i.toFront();
112 while (i.hasNext()) {
112 while (i.hasNext()) {
113 i.next();
113 i.next();
114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
115 i.key()->d_ptr->initializeAxisX(axis);
115 i.key()->d_ptr->initializeAxisX(axis);
116 addAxisX(axis,i.key());
116 addAxisX(axis,i.key());
117 emit axisAdded(axis,i.value());
117 emit axisAdded(axis,i.value());
118 }
118 }
119
119
120 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
120 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
121 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
121 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
122 i.toFront();
122 i.toFront();
123 while (i.hasNext()) {
123 while (i.hasNext()) {
124 i.next();
124 i.next();
125 i.key()->d_ptr->initializeAxisX(axis);
125 i.key()->d_ptr->initializeAxisX(axis);
126 addAxisX(axis,i.key());
126 addAxisX(axis,i.key());
127 }
127 }
128 emit axisAdded(axis,i.value());
128 emit axisAdded(axis,i.value());
129
129
130 }
130 }
131
131
132 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
132 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
133 {
133 {
134 i.toFront();
134 i.toFront();
135 while (i.hasNext()) {
135 while (i.hasNext()) {
136 i.next();
136 i.next();
137 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
137 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
138 i.key()->d_ptr->initializeAxisY(axis);
138 i.key()->d_ptr->initializeAxisY(axis);
139 addAxisY(axis,i.key());
139 addAxisY(axis,i.key());
140 emit axisAdded(axis,i.value());
140 emit axisAdded(axis,i.value());
141 }
141 }
142
142
143 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
143 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
144 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
144 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
145 i.toFront();
145 i.toFront();
146 while (i.hasNext()) {
146 while (i.hasNext()) {
147 i.next();
147 i.next();
148 i.key()->d_ptr->initializeAxisY(axis);
148 i.key()->d_ptr->initializeAxisY(axis);
149 addAxisY(axis,i.key());
149 addAxisY(axis,i.key());
150 }
150 }
151 emit axisAdded(axis,i.value());
151 emit axisAdded(axis,i.value());
152
152
153 }
153 }
154 }
154 }
155
155
156
156
157 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
157 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
158 {
158 {
159 QAbstractAxis* axis =0;
159 QAbstractAxis* axis =0;
160
160
161 switch(type) {
161 switch(type) {
162 case QAbstractAxis::AxisTypeValues:
162 case QAbstractAxis::AxisTypeValues:
163 axis = new QValuesAxis(this);
163 axis = new QValuesAxis(this);
164 break;
164 break;
165 case QAbstractAxis::AxisTypeCategories:
165 case QAbstractAxis::AxisTypeCategories:
166 axis = new QCategoriesAxis(this);
166 axis = new QCategoriesAxis(this);
167 break;
167 break;
168 default:
168 default:
169 axis = 0;
169 axis = 0;
170 break;
170 break;
171 }
171 }
172
172
173 return axis;
173 return axis;
174 }
174 }
175
175
176 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
176 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
177 Domain* domain = m_seriesDomainMap.value(series);
177 Domain* domain = m_seriesDomainMap.value(series);
178 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
178 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
179 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
179 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
180 axis->d_ptr->m_orientation=Qt::Horizontal;
180 axis->d_ptr->m_orientation=Qt::Horizontal;
181 m_seriesAxisXMap.insert(series,axis);
181 m_seriesAxisXMap.insert(series,axis);
182 }
182 }
183
183
184 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
184 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
185 Domain* domain = m_seriesDomainMap.value(series);
185 Domain* domain = m_seriesDomainMap.value(series);
186 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
186 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
187 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
187 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
188 axis->d_ptr->m_orientation=Qt::Vertical;
188 axis->d_ptr->m_orientation=Qt::Vertical;
189 m_seriesAxisYMap.insert(series,axis);
189 m_seriesAxisYMap.insert(series,axis);
190 }
190 }
191
191
192 void ChartDataSet::removeSeries(QAbstractSeries* series)
192 void ChartDataSet::removeSeries(QAbstractSeries* series)
193 {
193 {
194 Domain* domain = m_seriesDomainMap.take(series);
194 Domain* domain = m_seriesDomainMap.take(series);
195
195
196 if(!domain) {
196 if(!domain) {
197 qWarning()<<"Can not remove series. Series not found on the chart.";
197 qWarning()<<"Can not remove series. Series not found on the chart.";
198 }
198 }
199
199
200 emit seriesRemoved(series);
200 emit seriesRemoved(series);
201
201
202 delete domain;
202 delete domain;
203 domain = 0;
203 domain = 0;
204
204
205 int key = seriesIndex(series);
205 int key = seriesIndex(series);
206 Q_ASSERT(key!=-1);
206 Q_ASSERT(key!=-1);
207
207
208 m_indexSeriesMap.remove(key);
208 m_indexSeriesMap.remove(key);
209
209
210 series->setParent(0);
210 series->setParent(0);
211 series->d_ptr->m_chart = 0;
211 series->d_ptr->m_chart = 0;
212 series->d_ptr->m_dataset = 0;
212 series->d_ptr->m_dataset = 0;
213
213
214 removeAxes(series);
214 removeAxes(series);
215 }
215 }
216
216
217 void ChartDataSet::removeAxes(QAbstractSeries* series)
217 void ChartDataSet::removeAxes(QAbstractSeries* series)
218 {
218 {
219 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
219 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
220
220
221 if(axisX) {
221 if(axisX) {
222 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
222 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
223 int x = axesX.indexOf(axisX);
223 int x = axesX.indexOf(axisX);
224
224
225 if(x==-1) {
225 if(x==-1) {
226 emit axisRemoved(axisX);
226 emit axisRemoved(axisX);
227 axisX->deleteLater();
227 axisX->deleteLater();
228 }
228 }
229 }
229 }
230
230
231 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
231 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
232
232
233 if(axisY) {
233 if(axisY) {
234 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
234 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
235
235
236 int y = axesY.indexOf(axisY);
236 int y = axesY.indexOf(axisY);
237
237
238 if(y==-1) {
238 if(y==-1) {
239 emit axisRemoved(axisY);
239 emit axisRemoved(axisY);
240 axisY->deleteLater();
240 axisY->deleteLater();
241 }
241 }
242 }
242 }
243 }
243 }
244
244
245 void ChartDataSet::removeAllSeries()
245 void ChartDataSet::removeAllSeries()
246 {
246 {
247 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
247 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
248 foreach(QAbstractSeries *s , series) {
248 foreach(QAbstractSeries *s , series) {
249 removeSeries(s);
249 removeSeries(s);
250 }
250 }
251
251
252 Q_ASSERT(m_seriesAxisXMap.count()==0);
252 Q_ASSERT(m_seriesAxisXMap.count()==0);
253 Q_ASSERT(m_seriesAxisXMap.count()==0);
253 Q_ASSERT(m_seriesAxisXMap.count()==0);
254 Q_ASSERT(m_seriesDomainMap.count()==0);
254 Q_ASSERT(m_seriesDomainMap.count()==0);
255
255
256 qDeleteAll(series);
256 qDeleteAll(series);
257 }
257 }
258
258
259 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
259 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
260 {
260 {
261 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
261 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
262
262
263 blockAxisSignals(true);
263 blockAxisSignals(true);
264
264
265 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
265 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
266
266
267 while (i.hasNext()) {
267 while (i.hasNext()) {
268 i.next();
268 i.next();
269 i.value()->zoomIn(rect,size);
269 i.value()->zoomIn(rect,size);
270 }
270 }
271
271
272 blockAxisSignals(false);
272 blockAxisSignals(false);
273
273
274 }
274 }
275
275
276 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
276 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
277 {
277 {
278 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
278 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
279
279
280 blockAxisSignals(true);
280 blockAxisSignals(true);
281
281
282 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
282 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
283
283
284 while (i.hasNext()) {
284 while (i.hasNext()) {
285 i.next();
285 i.next();
286 i.value()->zoomOut(rect,size);
286 i.value()->zoomOut(rect,size);
287 }
287 }
288
288
289 blockAxisSignals(false);
289 blockAxisSignals(false);
290 }
290 }
291
291
292 void ChartDataSet::blockAxisSignals(bool enabled)
292 void ChartDataSet::blockAxisSignals(bool enabled)
293 {
293 {
294 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
294 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
295
295
296 while (i.hasNext()) {
296 while (i.hasNext()) {
297 i.next();
297 i.next();
298 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
298 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
299 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
299 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
300 if(axisX) axisX->blockSignals(enabled);
300 if(axisX) axisX->blockSignals(enabled);
301 if(axisY) axisY->blockSignals(enabled);
301 if(axisY) axisY->blockSignals(enabled);
302 }
302 }
303 }
303 }
304
304
305 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
305 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
306 {
306 {
307 int count=0;
307 int count=0;
308 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
308 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
309 while (i.hasNext()) {
309 while (i.hasNext()) {
310 i.next();
310 i.next();
311 if(i.key()->type()==type) count++;
311 if(i.key()->type()==type) count++;
312 }
312 }
313 return count;
313 return count;
314 }
314 }
315
315
316 int ChartDataSet::seriesIndex(QAbstractSeries *series)
316 int ChartDataSet::seriesIndex(QAbstractSeries *series)
317 {
317 {
318 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
318 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
319 while (i.hasNext()) {
319 while (i.hasNext()) {
320 i.next();
320 i.next();
321 if (i.value() == series)
321 if (i.value() == series)
322 return i.key();
322 return i.key();
323 }
323 }
324 return -1;
324 return -1;
325 }
325 }
326
326
327 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
327 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
328 {
328 {
329 if(series == 0) return m_seriesAxisXMap.begin().value();
329 if(series == 0) return m_seriesAxisXMap.begin().value();
330 return m_seriesAxisXMap.value(series);
330 return m_seriesAxisXMap.value(series);
331 }
331 }
332
332
333 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
333 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
334 {
334 {
335 if(series == 0) return m_seriesAxisYMap.begin().value();
335 if(series == 0) return m_seriesAxisYMap.begin().value();
336 return m_seriesAxisYMap.value(series);
336 return m_seriesAxisYMap.value(series);
337 }
337 }
338
338
339 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
339 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
340 {
340 {
341 Q_ASSERT(axis);
341 Q_ASSERT(axis);
342 Domain* domain = m_seriesDomainMap.value(series);
342 Domain* domain = m_seriesDomainMap.value(series);
343
343
344 if(!domain) {
344 if(!domain) {
345 qWarning() << "Series not found on the chart.";
345 qWarning() << "Series not found on the chart.";
346 return;
346 return;
347 }
347 }
348
348
349 if(axis->d_ptr->m_orientation==Qt::Vertical) {
349 if(axis->d_ptr->m_orientation==Qt::Vertical) {
350 qWarning()<<"Axis already defined as axis Y";
350 qWarning()<<"Axis already defined as axis Y";
351 return;
351 return;
352 }
352 }
353
353
354 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
354 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
355 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
355 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
356
356
357 if(oldAxis) {
357 if(oldAxis) {
358
358
359 int x = axesX.indexOf(oldAxis);
359 int x = axesX.indexOf(oldAxis);
360 if(x==-1) {
360 if(x==-1) {
361 emit axisRemoved(oldAxis);
361 emit axisRemoved(oldAxis);
362 oldAxis->deleteLater();
362 oldAxis->deleteLater();
363 }
363 }
364 }
364 }
365
365
366 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
366 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
367 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
367 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
368
368
369 int x = axesX.indexOf(axis);
369 int x = axesX.indexOf(axis);
370 if(x==-1) {
370 if(x==-1) {
371 axis->d_ptr->m_orientation=Qt::Horizontal;
371 axis->d_ptr->m_orientation=Qt::Horizontal;
372 emit axisAdded(axis,domain);
372 emit axisAdded(axis,domain);
373 }
373 }
374
374
375 m_seriesAxisXMap.insert(series,axis);
375 m_seriesAxisXMap.insert(series,axis);
376
376 axis->d_ptr->emitRange();
377 // Force range update
378 axis->d_ptr->updateRange();
379 }
377 }
380
378
381 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
379 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
382 {
380 {
383 Q_ASSERT(axis);
381 Q_ASSERT(axis);
384 Domain* domain = m_seriesDomainMap.value(series);
382 Domain* domain = m_seriesDomainMap.value(series);
385
383
386 if(!domain) {
384 if(!domain) {
387 qWarning() << "Series not found on the chart.";
385 qWarning() << "Series not found on the chart.";
388 return;
386 return;
389 }
387 }
390
388
391 if(axis->d_ptr->m_orientation==Qt::Horizontal) {
389 if(axis->d_ptr->m_orientation==Qt::Horizontal) {
392 qWarning()<<"Axis already defined as axis X";
390 qWarning()<<"Axis already defined as axis X";
393 return;
391 return;
394 }
392 }
395
393
396 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
394 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
397 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
395 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
398
396
399 if(oldAxis) {
397 if(oldAxis) {
400 int y = axesY.indexOf(oldAxis);
398 int y = axesY.indexOf(oldAxis);
401 if(y==-1) {
399 if(y==-1) {
402 emit axisRemoved(oldAxis);
400 emit axisRemoved(oldAxis);
403 oldAxis->deleteLater();
401 oldAxis->deleteLater();
404 }
402 }
405 }
403 }
406
404
407 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
405 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
408 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
406 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
409
407
410 int y = axesY.indexOf(axis);
408 int y = axesY.indexOf(axis);
411 if(y==-1) {
409 if(y==-1) {
412 axis->d_ptr->m_orientation=Qt::Vertical;
410 axis->d_ptr->m_orientation=Qt::Vertical;
413 emit axisAdded(axis,domain);
411 emit axisAdded(axis,domain);
414 }
412 }
415
413
416 m_seriesAxisYMap.insert(series,axis);
414 m_seriesAxisYMap.insert(series,axis);
415 axis->d_ptr->emitRange();
417 }
416 }
418
417
419 Domain* ChartDataSet::domain(QAbstractSeries *series) const
418 Domain* ChartDataSet::domain(QAbstractSeries *series) const
420 {
419 {
421 return m_seriesDomainMap.value(series);
420 return m_seriesDomainMap.value(series);
422 }
421 }
423
422
424 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
423 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
425 {
424 {
426 blockAxisSignals(true);
425 blockAxisSignals(true);
427 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
426 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
428 while (i.hasNext()) {
427 while (i.hasNext()) {
429 i.next();
428 i.next();
430 i.value()->move(dx,dy,size);
429 i.value()->move(dx,dy,size);
431 }
430 }
432 blockAxisSignals(false);
431 blockAxisSignals(false);
433 }
432 }
434
433
435 QList<QAbstractSeries*> ChartDataSet::series() const
434 QList<QAbstractSeries*> ChartDataSet::series() const
436 {
435 {
437 return m_seriesAxisXMap.keys();
436 return m_seriesAxisXMap.keys();
438 }
437 }
439
438
440 void ChartDataSet::updateSeries(QAbstractSeries *series)
439 void ChartDataSet::updateSeries(QAbstractSeries *series)
441 {
440 {
442 emit seriesUpdated(series);
441 emit seriesUpdated(series);
443 }
442 }
444
443
445 #include "moc_chartdataset_p.cpp"
444 #include "moc_chartdataset_p.cpp"
446
445
447 QTCOMMERCIALCHART_END_NAMESPACE
446 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now