@@ -1,456 +1,471 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarcategoriesaxis.h" |
|
21 | #include "qbarcategoriesaxis.h" | |
22 | #include "qbarcategoriesaxis_p.h" |
|
22 | #include "qbarcategoriesaxis_p.h" | |
23 | #include "chartcategoriesaxisx_p.h" |
|
23 | #include "chartcategoriesaxisx_p.h" | |
24 | #include "chartcategoriesaxisy_p.h" |
|
24 | #include "chartcategoriesaxisy_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QBarCategoriesAxis |
|
31 | \class QBarCategoriesAxis | |
32 | \brief The QBarCategoriesAxis class is used for manipulating chart's axis. |
|
32 | \brief The QBarCategoriesAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \qmlclass BarCategoriesAxis QBarCategoriesAxis |
|
41 | \qmlclass BarCategoriesAxis QBarCategoriesAxis | |
42 | \brief The Axis element is used for manipulating chart's axes. |
|
42 | \brief The Axis element is used for manipulating chart's axes. | |
43 |
|
43 | |||
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
45 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
46 |
|
46 | |||
47 | To access BarCategoriesAxis you can use ChartView API. For example: |
|
47 | To access BarCategoriesAxis you can use ChartView API. For example: | |
48 | \code |
|
48 | \code | |
49 | ChartView { |
|
49 | ChartView { | |
50 | BarCategoriesAxis { |
|
50 | BarCategoriesAxis { | |
51 | id: categoryAxis |
|
51 | id: categoryAxis | |
52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
52 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] | |
53 | } |
|
53 | } | |
54 | // Add a few series... |
|
54 | // Add a few series... | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QBarCategoriesAxis::categories |
|
60 | \property QBarCategoriesAxis::categories | |
61 | Defines the categories of axis |
|
61 | Defines the categories of axis | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty QStringList BarCategoriesAxis::categories |
|
64 | \qmlproperty QStringList BarCategoriesAxis::categories | |
65 | Defines the categories of axis |
|
65 | Defines the categories of axis | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarCategoriesAxis::min |
|
69 | \property QBarCategoriesAxis::min | |
70 | Defines the minimum value on the axis. |
|
70 | Defines the minimum value on the axis. | |
71 | */ |
|
71 | */ | |
72 | /*! |
|
72 | /*! | |
73 | \qmlproperty QString BarCategoriesAxis::min |
|
73 | \qmlproperty QString BarCategoriesAxis::min | |
74 | Defines the minimum value on the axis. |
|
74 | Defines the minimum value on the axis. | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \property QBarCategoriesAxis::max |
|
78 | \property QBarCategoriesAxis::max | |
79 | Defines the maximum value on the axis. |
|
79 | Defines the maximum value on the axis. | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty QString BarCategoriesAxis::max |
|
82 | \qmlproperty QString BarCategoriesAxis::max | |
83 | Defines the maximum value on the axis. |
|
83 | Defines the maximum value on the axis. | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \fn void QBarCategoriesAxis::categoriesChanged() |
|
88 | \fn void QBarCategoriesAxis::categoriesChanged() | |
89 | Axis emits signal when the categories of the axis has changed. |
|
89 | Axis emits signal when the categories of the axis has changed. | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \fn void QBarCategoriesAxis::minChanged(const QString &min) |
|
92 | \fn void QBarCategoriesAxis::minChanged(const QString &min) | |
93 | Axis emits signal when \a min of axis has changed. |
|
93 | Axis emits signal when \a min of axis has changed. | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) |
|
96 | \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min) | |
97 | Axis emits signal when \a min of axis has changed. |
|
97 | Axis emits signal when \a min of axis has changed. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn void QBarCategoriesAxis::maxChanged(const QString &max) |
|
101 | \fn void QBarCategoriesAxis::maxChanged(const QString &max) | |
102 | Axis emits signal when \a max of axis has changed. |
|
102 | Axis emits signal when \a max of axis has changed. | |
103 | */ |
|
103 | */ | |
104 | /*! |
|
104 | /*! | |
105 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) |
|
105 | \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max) | |
106 | Axis emits signal when \a max of axis has changed. |
|
106 | Axis emits signal when \a max of axis has changed. | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max) |
|
110 | \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max) | |
111 | Axis emits signal when \a min or \a max of axis has changed. |
|
111 | Axis emits signal when \a min or \a max of axis has changed. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | Constructs an axis object which is a child of \a parent. |
|
115 | Constructs an axis object which is a child of \a parent. | |
116 | */ |
|
116 | */ | |
117 | QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): |
|
117 | QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): | |
118 | QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) |
|
118 | QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Destroys the object |
|
123 | Destroys the object | |
124 | */ |
|
124 | */ | |
125 | QBarCategoriesAxis::~QBarCategoriesAxis() |
|
125 | QBarCategoriesAxis::~QBarCategoriesAxis() | |
126 | { |
|
126 | { | |
127 | Q_D(QBarCategoriesAxis); |
|
127 | Q_D(QBarCategoriesAxis); | |
128 | if(d->m_dataset){ |
|
128 | if(d->m_dataset){ | |
129 | d->m_dataset->removeAxis(this); |
|
129 | d->m_dataset->removeAxis(this); | |
130 | } |
|
130 | } | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \internal |
|
134 | \internal | |
135 | */ |
|
135 | */ | |
136 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
136 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) | |
137 | { |
|
137 | { | |
138 |
|
138 | |||
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | /*! |
|
141 | /*! | |
142 | Appends \a categories to axis |
|
142 | Appends \a categories to axis | |
143 | */ |
|
143 | */ | |
144 | void QBarCategoriesAxis::append(const QStringList &categories) |
|
144 | void QBarCategoriesAxis::append(const QStringList &categories) | |
145 | { |
|
145 | { | |
146 | if(categories.isEmpty()) return; |
|
146 | if(categories.isEmpty()) return; | |
147 |
|
147 | |||
148 | Q_D(QBarCategoriesAxis); |
|
148 | Q_D(QBarCategoriesAxis); | |
149 | if (d->m_categories.isEmpty()) { |
|
149 | if (d->m_categories.isEmpty()) { | |
150 | d->m_categories.append(categories); |
|
150 | d->m_categories.append(categories); | |
151 | setRange(categories.first(),categories.last()); |
|
151 | setRange(categories.first(),categories.last()); | |
152 | }else{ |
|
152 | }else{ | |
153 | d->m_categories.append(categories); |
|
153 | d->m_categories.append(categories); | |
154 | d->emitUpdated(); |
|
154 | d->emitUpdated(); | |
155 | } |
|
155 | } | |
156 | emit categoriesChanged(); |
|
156 | emit categoriesChanged(); | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Appends \a category to axis |
|
160 | Appends \a category to axis | |
161 | */ |
|
161 | */ | |
162 | void QBarCategoriesAxis::append(const QString &category) |
|
162 | void QBarCategoriesAxis::append(const QString &category) | |
163 | { |
|
163 | { | |
164 | Q_D(QBarCategoriesAxis); |
|
164 | Q_D(QBarCategoriesAxis); | |
165 | if (d->m_categories.isEmpty()) { |
|
165 | if (d->m_categories.isEmpty()) { | |
166 | d->m_categories.append(category); |
|
166 | d->m_categories.append(category); | |
167 | setRange(category,category); |
|
167 | setRange(category,category); | |
168 | }else{ |
|
168 | }else{ | |
169 | d->m_categories.append(category); |
|
169 | d->m_categories.append(category); | |
170 | d->emitUpdated(); |
|
170 | d->emitUpdated(); | |
171 | } |
|
171 | } | |
172 | emit categoriesChanged(); |
|
172 | emit categoriesChanged(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | Removes \a category from axis |
|
176 | Removes \a category from axis | |
177 | */ |
|
177 | */ | |
178 | void QBarCategoriesAxis::remove(const QString &category) |
|
178 | void QBarCategoriesAxis::remove(const QString &category) | |
179 | { |
|
179 | { | |
180 | Q_D(QBarCategoriesAxis); |
|
180 | Q_D(QBarCategoriesAxis); | |
181 | if (d->m_categories.contains(category)) { |
|
181 | if (d->m_categories.contains(category)) { | |
182 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
182 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
183 | if(!d->m_categories.isEmpty()) |
|
183 | if(!d->m_categories.isEmpty()) | |
184 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
184 | setRange(d->m_categories.first(),d->m_categories.last()); | |
185 | else |
|
185 | else | |
186 | setRange(QString::null,QString::null); |
|
186 | setRange(QString::null,QString::null); | |
187 | emit categoriesChanged(); |
|
187 | emit categoriesChanged(); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Inserts \a category to axis at \a index |
|
192 | Inserts \a category to axis at \a index | |
193 | */ |
|
193 | */ | |
194 | void QBarCategoriesAxis::insert(int index, const QString &category) |
|
194 | void QBarCategoriesAxis::insert(int index, const QString &category) | |
195 | { |
|
195 | { | |
196 | Q_D(QBarCategoriesAxis); |
|
196 | Q_D(QBarCategoriesAxis); | |
197 | if (d->m_categories.isEmpty()) { |
|
197 | if (d->m_categories.isEmpty()) { | |
198 | d->m_categories.insert(index,category); |
|
198 | d->m_categories.insert(index,category); | |
199 | setRange(category,category); |
|
199 | setRange(category,category); | |
200 | }else{ |
|
200 | }else{ | |
201 | d->m_categories.insert(index,category); |
|
201 | d->m_categories.insert(index,category); | |
202 | d->emitUpdated(); |
|
202 | d->emitUpdated(); | |
203 | } |
|
203 | } | |
204 | emit categoriesChanged(); |
|
204 | emit categoriesChanged(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
|
208 | Replaces \a oldCategory with \a newCategory. | |||
|
209 | If \a oldCategory does not exits on the axis nothing is done. | |||
|
210 | */ | |||
|
211 | void QBarCategoriesAxis::replace(const QString &oldCategory, const QString &newCategory) | |||
|
212 | { | |||
|
213 | Q_D(QBarCategoriesAxis); | |||
|
214 | int pos = d->m_categories.indexOf(oldCategory); | |||
|
215 | if (pos != -1) { | |||
|
216 | d->m_categories.replace(pos, newCategory); | |||
|
217 | d->emitUpdated(); | |||
|
218 | emit categoriesChanged(); | |||
|
219 | } | |||
|
220 | } | |||
|
221 | ||||
|
222 | /*! | |||
208 | Removes all categories. |
|
223 | Removes all categories. | |
209 | */ |
|
224 | */ | |
210 | void QBarCategoriesAxis::clear() |
|
225 | void QBarCategoriesAxis::clear() | |
211 | { |
|
226 | { | |
212 | Q_D(QBarCategoriesAxis); |
|
227 | Q_D(QBarCategoriesAxis); | |
213 | d->m_categories.clear(); |
|
228 | d->m_categories.clear(); | |
214 | setRange(QString::null,QString::null); |
|
229 | setRange(QString::null,QString::null); | |
215 | emit categoriesChanged(); |
|
230 | emit categoriesChanged(); | |
216 | } |
|
231 | } | |
217 |
|
232 | |||
218 | void QBarCategoriesAxis::setCategories(const QStringList &categories) |
|
233 | void QBarCategoriesAxis::setCategories(const QStringList &categories) | |
219 | { |
|
234 | { | |
220 | Q_D(QBarCategoriesAxis); |
|
235 | Q_D(QBarCategoriesAxis); | |
221 | if(d->m_categories!=categories) { |
|
236 | if(d->m_categories!=categories) { | |
222 | d->m_categories = categories; |
|
237 | d->m_categories = categories; | |
223 | setRange(categories.first(),categories.last()); |
|
238 | setRange(categories.first(),categories.last()); | |
224 | emit categoriesChanged(); |
|
239 | emit categoriesChanged(); | |
225 | } |
|
240 | } | |
226 | } |
|
241 | } | |
227 |
|
242 | |||
228 | QStringList QBarCategoriesAxis::categories() |
|
243 | QStringList QBarCategoriesAxis::categories() | |
229 | { |
|
244 | { | |
230 | Q_D(QBarCategoriesAxis); |
|
245 | Q_D(QBarCategoriesAxis); | |
231 | return d->m_categories; |
|
246 | return d->m_categories; | |
232 | } |
|
247 | } | |
233 |
|
248 | |||
234 | /*! |
|
249 | /*! | |
235 | Returns number of categories. |
|
250 | Returns number of categories. | |
236 | */ |
|
251 | */ | |
237 | int QBarCategoriesAxis::count() const |
|
252 | int QBarCategoriesAxis::count() const | |
238 | { |
|
253 | { | |
239 | Q_D(const QBarCategoriesAxis); |
|
254 | Q_D(const QBarCategoriesAxis); | |
240 | return d->m_categories.count(); |
|
255 | return d->m_categories.count(); | |
241 | } |
|
256 | } | |
242 |
|
257 | |||
243 | /*! |
|
258 | /*! | |
244 | Returns category at \a index. Index must be valid. |
|
259 | Returns category at \a index. Index must be valid. | |
245 | */ |
|
260 | */ | |
246 | QString QBarCategoriesAxis::at(int index) const |
|
261 | QString QBarCategoriesAxis::at(int index) const | |
247 | { |
|
262 | { | |
248 | Q_D(const QBarCategoriesAxis); |
|
263 | Q_D(const QBarCategoriesAxis); | |
249 | return d->m_categories.at(index); |
|
264 | return d->m_categories.at(index); | |
250 | } |
|
265 | } | |
251 |
|
266 | |||
252 | /*! |
|
267 | /*! | |
253 | Sets minimum category to \a min. |
|
268 | Sets minimum category to \a min. | |
254 | */ |
|
269 | */ | |
255 | void QBarCategoriesAxis::setMin(const QString& min) |
|
270 | void QBarCategoriesAxis::setMin(const QString& min) | |
256 | { |
|
271 | { | |
257 | Q_D(QBarCategoriesAxis); |
|
272 | Q_D(QBarCategoriesAxis); | |
258 | setRange(min,d->m_maxCategory); |
|
273 | setRange(min,d->m_maxCategory); | |
259 | } |
|
274 | } | |
260 |
|
275 | |||
261 | /*! |
|
276 | /*! | |
262 | Returns minimum category. |
|
277 | Returns minimum category. | |
263 | */ |
|
278 | */ | |
264 | QString QBarCategoriesAxis::min() const |
|
279 | QString QBarCategoriesAxis::min() const | |
265 | { |
|
280 | { | |
266 | Q_D(const QBarCategoriesAxis); |
|
281 | Q_D(const QBarCategoriesAxis); | |
267 | return d->m_minCategory; |
|
282 | return d->m_minCategory; | |
268 | } |
|
283 | } | |
269 |
|
284 | |||
270 | /*! |
|
285 | /*! | |
271 | Sets maximum category to \a max. |
|
286 | Sets maximum category to \a max. | |
272 | */ |
|
287 | */ | |
273 | void QBarCategoriesAxis::setMax(const QString& max) |
|
288 | void QBarCategoriesAxis::setMax(const QString& max) | |
274 | { |
|
289 | { | |
275 | Q_D(QBarCategoriesAxis); |
|
290 | Q_D(QBarCategoriesAxis); | |
276 | setRange(d->m_minCategory,max); |
|
291 | setRange(d->m_minCategory,max); | |
277 | } |
|
292 | } | |
278 |
|
293 | |||
279 | /*! |
|
294 | /*! | |
280 | Returns maximum category |
|
295 | Returns maximum category | |
281 | */ |
|
296 | */ | |
282 | QString QBarCategoriesAxis::max() const |
|
297 | QString QBarCategoriesAxis::max() const | |
283 | { |
|
298 | { | |
284 | Q_D(const QBarCategoriesAxis); |
|
299 | Q_D(const QBarCategoriesAxis); | |
285 | return d->m_maxCategory; |
|
300 | return d->m_maxCategory; | |
286 | } |
|
301 | } | |
287 |
|
302 | |||
288 | /*! |
|
303 | /*! | |
289 | Sets range from \a minCategory to \a maxCategory |
|
304 | Sets range from \a minCategory to \a maxCategory | |
290 | */ |
|
305 | */ | |
291 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
306 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) | |
292 | { |
|
307 | { | |
293 | Q_D(QBarCategoriesAxis); |
|
308 | Q_D(QBarCategoriesAxis); | |
294 |
|
309 | |||
295 | bool changed = false; |
|
310 | bool changed = false; | |
296 |
|
311 | |||
297 | //special case |
|
312 | //special case | |
298 | if(minCategory.isNull() && maxCategory.isNull()){ |
|
313 | if(minCategory.isNull() && maxCategory.isNull()){ | |
299 | d->m_minCategory = minCategory; |
|
314 | d->m_minCategory = minCategory; | |
300 | d->m_maxCategory = maxCategory; |
|
315 | d->m_maxCategory = maxCategory; | |
301 | d->m_min = 0; |
|
316 | d->m_min = 0; | |
302 | d->m_max = 0; |
|
317 | d->m_max = 0; | |
303 | emit minChanged(minCategory); |
|
318 | emit minChanged(minCategory); | |
304 | emit maxChanged(maxCategory); |
|
319 | emit maxChanged(maxCategory); | |
305 | d->m_count=0; |
|
320 | d->m_count=0; | |
306 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
321 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); | |
307 | d->emitUpdated(); |
|
322 | d->emitUpdated(); | |
308 | } |
|
323 | } | |
309 |
|
324 | |||
310 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; |
|
325 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; | |
311 |
|
326 | |||
312 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { |
|
327 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { | |
313 | d->m_minCategory = minCategory; |
|
328 | d->m_minCategory = minCategory; | |
314 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
|
329 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; | |
315 | changed = true; |
|
330 | changed = true; | |
316 | emit minChanged(minCategory); |
|
331 | emit minChanged(minCategory); | |
317 | } |
|
332 | } | |
318 |
|
333 | |||
319 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { |
|
334 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { | |
320 | d->m_maxCategory = maxCategory; |
|
335 | d->m_maxCategory = maxCategory; | |
321 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; |
|
336 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; | |
322 | changed = true; |
|
337 | changed = true; | |
323 | emit maxChanged(maxCategory); |
|
338 | emit maxChanged(maxCategory); | |
324 | } |
|
339 | } | |
325 |
|
340 | |||
326 | if (changed) { |
|
341 | if (changed) { | |
327 | d->m_count=d->m_max - d->m_min; |
|
342 | d->m_count=d->m_max - d->m_min; | |
328 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
343 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); | |
329 | d->emitUpdated(); |
|
344 | d->emitUpdated(); | |
330 | } |
|
345 | } | |
331 | } |
|
346 | } | |
332 |
|
347 | |||
333 | /*! |
|
348 | /*! | |
334 | Returns the type of the axis |
|
349 | Returns the type of the axis | |
335 | */ |
|
350 | */ | |
336 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const |
|
351 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const | |
337 | { |
|
352 | { | |
338 | return AxisTypeCategories; |
|
353 | return AxisTypeCategories; | |
339 | } |
|
354 | } | |
340 |
|
355 | |||
341 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
356 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
342 |
|
357 | |||
343 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): |
|
358 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): | |
344 | QAbstractAxisPrivate(q), |
|
359 | QAbstractAxisPrivate(q), | |
345 | m_min(0.0), |
|
360 | m_min(0.0), | |
346 | m_max(0.0), |
|
361 | m_max(0.0), | |
347 | m_count(0) |
|
362 | m_count(0) | |
348 | { |
|
363 | { | |
349 |
|
364 | |||
350 | } |
|
365 | } | |
351 |
|
366 | |||
352 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
367 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() | |
353 | { |
|
368 | { | |
354 |
|
369 | |||
355 | } |
|
370 | } | |
356 |
|
371 | |||
357 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
372 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) | |
358 | { |
|
373 | { | |
359 | setRange(min,m_maxCategory); |
|
374 | setRange(min,m_maxCategory); | |
360 | } |
|
375 | } | |
361 |
|
376 | |||
362 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
377 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) | |
363 | { |
|
378 | { | |
364 | setRange(m_minCategory,max); |
|
379 | setRange(m_minCategory,max); | |
365 | } |
|
380 | } | |
366 |
|
381 | |||
367 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
382 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
368 | { |
|
383 | { | |
369 | Q_Q(QBarCategoriesAxis); |
|
384 | Q_Q(QBarCategoriesAxis); | |
370 | QString value1 = min.toString(); |
|
385 | QString value1 = min.toString(); | |
371 | QString value2 = max.toString(); |
|
386 | QString value2 = max.toString(); | |
372 | q->setRange(value1,value2); |
|
387 | q->setRange(value1,value2); | |
373 | } |
|
388 | } | |
374 |
|
389 | |||
375 | void QBarCategoriesAxisPrivate::handleDomainUpdated() |
|
390 | void QBarCategoriesAxisPrivate::handleDomainUpdated() | |
376 | { |
|
391 | { | |
377 | Q_Q(QBarCategoriesAxis); |
|
392 | Q_Q(QBarCategoriesAxis); | |
378 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
393 | Domain* domain = qobject_cast<Domain*>(sender()); | |
379 |
|
394 | |||
380 | if(m_orientation==Qt::Horizontal) { |
|
395 | if(m_orientation==Qt::Horizontal) { | |
381 | m_min = domain->minX(); |
|
396 | m_min = domain->minX(); | |
382 | m_max = domain->maxX(); |
|
397 | m_max = domain->maxX(); | |
383 | } |
|
398 | } | |
384 | else if(m_orientation==Qt::Vertical) { |
|
399 | else if(m_orientation==Qt::Vertical) { | |
385 | m_min = domain->minY(); |
|
400 | m_min = domain->minY(); | |
386 | m_max = domain->maxY(); |
|
401 | m_max = domain->maxY(); | |
387 | } |
|
402 | } | |
388 |
|
403 | |||
389 | bool changed = false; |
|
404 | bool changed = false; | |
390 |
|
405 | |||
391 | int min = m_min + 0.5; |
|
406 | int min = m_min + 0.5; | |
392 | if(min>=0 && min<m_categories.count()) { |
|
407 | if(min>=0 && min<m_categories.count()) { | |
393 | QString minCategory = m_categories.at(min); |
|
408 | QString minCategory = m_categories.at(min); | |
394 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { |
|
409 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { | |
395 | m_minCategory=minCategory; |
|
410 | m_minCategory=minCategory; | |
396 | changed=true; |
|
411 | changed=true; | |
397 | emit q->minChanged(minCategory); |
|
412 | emit q->minChanged(minCategory); | |
398 | } |
|
413 | } | |
399 | } |
|
414 | } | |
400 | int max = m_max - 0.5; |
|
415 | int max = m_max - 0.5; | |
401 | if(max>=0 && max<m_categories.count()) { |
|
416 | if(max>=0 && max<m_categories.count()) { | |
402 | QString maxCategory = m_categories.at(max); |
|
417 | QString maxCategory = m_categories.at(max); | |
403 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { |
|
418 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { | |
404 | m_maxCategory=maxCategory; |
|
419 | m_maxCategory=maxCategory; | |
405 | emit q->maxChanged(maxCategory); |
|
420 | emit q->maxChanged(maxCategory); | |
406 | } |
|
421 | } | |
407 | } |
|
422 | } | |
408 |
|
423 | |||
409 | if (changed) { |
|
424 | if (changed) { | |
410 | emit q->rangeChanged(m_minCategory,m_maxCategory); |
|
425 | emit q->rangeChanged(m_minCategory,m_maxCategory); | |
411 | } |
|
426 | } | |
412 | } |
|
427 | } | |
413 |
|
428 | |||
414 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
429 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) | |
415 | { |
|
430 | { | |
416 | Q_Q(QBarCategoriesAxis); |
|
431 | Q_Q(QBarCategoriesAxis); | |
417 | if(m_orientation == Qt::Vertical){ |
|
432 | if(m_orientation == Qt::Vertical){ | |
418 | return new ChartCategoriesAxisY(q,presenter); |
|
433 | return new ChartCategoriesAxisY(q,presenter); | |
419 | }else{ |
|
434 | }else{ | |
420 | return new ChartCategoriesAxisX(q,presenter); |
|
435 | return new ChartCategoriesAxisX(q,presenter); | |
421 | } |
|
436 | } | |
422 | } |
|
437 | } | |
423 |
|
438 | |||
424 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) |
|
439 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) | |
425 | { |
|
440 | { | |
426 |
|
441 | |||
427 | Q_Q(QBarCategoriesAxis); |
|
442 | Q_Q(QBarCategoriesAxis); | |
428 | if(m_max==m_min) { |
|
443 | if(m_max==m_min) { | |
429 | int min; |
|
444 | int min; | |
430 | int max; |
|
445 | int max; | |
431 | if(m_orientation==Qt::Vertical) { |
|
446 | if(m_orientation==Qt::Vertical) { | |
432 | min = domain->minY() + 0.5; |
|
447 | min = domain->minY() + 0.5; | |
433 | max = domain->maxY() - 0.5; |
|
448 | max = domain->maxY() - 0.5; | |
434 | } |
|
449 | } | |
435 | else { |
|
450 | else { | |
436 | min = domain->minX() + 0.5; |
|
451 | min = domain->minX() + 0.5; | |
437 | max = domain->maxX() - 0.5; |
|
452 | max = domain->maxX() - 0.5; | |
438 | } |
|
453 | } | |
439 |
|
454 | |||
440 | if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count()) |
|
455 | if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count()) | |
441 | q->setRange(m_categories.at(min),m_categories.at(max)); |
|
456 | q->setRange(m_categories.at(min),m_categories.at(max)); | |
442 | } |
|
457 | } | |
443 | else { |
|
458 | else { | |
444 | if(m_orientation==Qt::Vertical) { |
|
459 | if(m_orientation==Qt::Vertical) { | |
445 | domain->setRangeY(m_min, m_max); |
|
460 | domain->setRangeY(m_min, m_max); | |
446 | } |
|
461 | } | |
447 | else { |
|
462 | else { | |
448 | domain->setRangeX(m_min, m_max); |
|
463 | domain->setRangeX(m_min, m_max); | |
449 | } |
|
464 | } | |
450 | } |
|
465 | } | |
451 | } |
|
466 | } | |
452 |
|
467 | |||
453 | #include "moc_qbarcategoriesaxis.cpp" |
|
468 | #include "moc_qbarcategoriesaxis.cpp" | |
454 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
469 | #include "moc_qbarcategoriesaxis_p.cpp" | |
455 |
|
470 | |||
456 | QTCOMMERCIALCHART_END_NAMESPACE |
|
471 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,78 +1,79 | |||||
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 QBARCATEGORIESAXIS_H |
|
21 | #ifndef QBARCATEGORIESAXIS_H | |
22 | #define QBARCATEGORIESAXIS_H |
|
22 | #define QBARCATEGORIESAXIS_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 QBarCategoriesAxisPrivate; |
|
28 | class QBarCategoriesAxisPrivate; | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QBarCategoriesAxis : public QAbstractAxis |
|
30 | class QTCOMMERCIALCHART_EXPORT QBarCategoriesAxis : 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) |
|
34 | Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged) | |
35 | Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged) |
|
35 | Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged) | |
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | explicit QBarCategoriesAxis(QObject *parent = 0); |
|
38 | explicit QBarCategoriesAxis(QObject *parent = 0); | |
39 | ~QBarCategoriesAxis(); |
|
39 | ~QBarCategoriesAxis(); | |
40 |
|
40 | |||
41 | protected: |
|
41 | protected: | |
42 | QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent = 0); |
|
42 | QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent = 0); | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | AxisType type() const; |
|
45 | AxisType type() const; | |
46 | void append(const QStringList &categories); |
|
46 | void append(const QStringList &categories); | |
47 | void append(const QString &category); |
|
47 | void append(const QString &category); | |
48 | void remove(const QString &category); |
|
48 | void remove(const QString &category); | |
49 | void insert(int index, const QString &category); |
|
49 | void insert(int index, const QString &category); | |
|
50 | void replace(const QString &oldCategory, const QString &newCategory); | |||
50 | void clear(); |
|
51 | void clear(); | |
51 | void setCategories(const QStringList &categories); |
|
52 | void setCategories(const QStringList &categories); | |
52 | QStringList categories(); |
|
53 | QStringList categories(); | |
53 | int count() const; |
|
54 | int count() const; | |
54 | QString at(int index) const; |
|
55 | QString at(int index) const; | |
55 |
|
56 | |||
56 | //range handling |
|
57 | //range handling | |
57 | void setMin(const QString& minCategory); |
|
58 | void setMin(const QString& minCategory); | |
58 | QString min() const; |
|
59 | QString min() const; | |
59 | void setMax(const QString& maxCategory); |
|
60 | void setMax(const QString& maxCategory); | |
60 | QString max() const; |
|
61 | QString max() const; | |
61 | void setRange(const QString& minCategory, const QString& maxCategory); |
|
62 | void setRange(const QString& minCategory, const QString& maxCategory); | |
62 |
|
63 | |||
63 | Q_SIGNALS: |
|
64 | Q_SIGNALS: | |
64 | void categoriesChanged(); |
|
65 | void categoriesChanged(); | |
65 | void minChanged(const QString &min); |
|
66 | void minChanged(const QString &min); | |
66 | void maxChanged(const QString &max); |
|
67 | void maxChanged(const QString &max); | |
67 | void rangeChanged(const QString &min, const QString &max); |
|
68 | void rangeChanged(const QString &min, const QString &max); | |
68 |
|
69 | |||
69 | private: |
|
70 | private: | |
70 | Q_DECLARE_PRIVATE(QBarCategoriesAxis) |
|
71 | Q_DECLARE_PRIVATE(QBarCategoriesAxis) | |
71 | Q_DISABLE_COPY(QBarCategoriesAxis) |
|
72 | Q_DISABLE_COPY(QBarCategoriesAxis) | |
72 | friend class ChartCategoriesAxisX; |
|
73 | friend class ChartCategoriesAxisX; | |
73 | friend class ChartCategoriesAxisY; |
|
74 | friend class ChartCategoriesAxisY; | |
74 | }; |
|
75 | }; | |
75 |
|
76 | |||
76 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE | |
77 |
|
78 | |||
78 | #endif // QCATEGORIESAXIS_H |
|
79 | #endif // QCATEGORIESAXIS_H |
General Comments 0
You need to be logged in to leave comments.
Login now