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