@@ -1,401 +1,432 | |||||
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 <qmath.h> |
|
26 | #include <qmath.h> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
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 | } |
|
127 | } | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \internal |
|
130 | \internal | |
131 | */ |
|
131 | */ | |
132 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
132 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) | |
133 | { |
|
133 | { | |
134 |
|
134 | |||
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | Appends \a categories to axis |
|
138 | Appends \a categories to axis | |
139 | */ |
|
139 | */ | |
140 | void QBarCategoriesAxis::append(const QStringList &categories) |
|
140 | void QBarCategoriesAxis::append(const QStringList &categories) | |
141 | { |
|
141 | { | |
142 | if(categories.isEmpty()) return; |
|
142 | if(categories.isEmpty()) return; | |
143 |
|
143 | |||
144 | Q_D(QBarCategoriesAxis); |
|
144 | Q_D(QBarCategoriesAxis); | |
145 | if (d->m_categories.isEmpty()) { |
|
145 | if (d->m_categories.isEmpty()) { | |
146 |
|
|
146 | d->m_categories.append(categories); | |
147 |
|
|
147 | setRange(categories.first(),categories.last()); | |
148 | }else{ |
|
148 | }else{ | |
149 |
|
|
149 | d->m_categories.append(categories); | |
150 | } |
|
150 | } | |
151 | emit d->updated(); |
|
151 | emit d->updated(); | |
152 | emit categoriesChanged(); |
|
152 | emit categoriesChanged(); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | Appends \a category to axis |
|
156 | Appends \a category to axis | |
157 | */ |
|
157 | */ | |
158 | void QBarCategoriesAxis::append(const QString &category) |
|
158 | void QBarCategoriesAxis::append(const QString &category) | |
159 | { |
|
159 | { | |
160 |
|
|
160 | Q_D(QBarCategoriesAxis); | |
161 |
|
|
161 | if (d->m_categories.isEmpty()) { | |
162 |
|
|
162 | d->m_categories.append(category); | |
163 |
|
|
163 | setRange(category,category); | |
164 |
|
|
164 | }else{ | |
165 |
|
|
165 | d->m_categories.append(category); | |
166 | } |
|
166 | } | |
167 |
|
|
167 | emit d->updated(); | |
168 |
|
|
168 | emit categoriesChanged(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Removes \a category from axis |
|
172 | Removes \a category from axis | |
173 | */ |
|
173 | */ | |
174 | void QBarCategoriesAxis::remove(const QString &category) |
|
174 | void QBarCategoriesAxis::remove(const QString &category) | |
175 | { |
|
175 | { | |
176 | Q_D(QBarCategoriesAxis); |
|
176 | Q_D(QBarCategoriesAxis); | |
177 | if (d->m_categories.contains(category)) { |
|
177 | if (d->m_categories.contains(category)) { | |
178 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
178 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
179 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
179 | setRange(d->m_categories.first(),d->m_categories.last()); | |
180 | emit d->updated(); |
|
180 | emit d->updated(); | |
181 | emit categoriesChanged(); |
|
181 | emit categoriesChanged(); | |
182 | } |
|
182 | } | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Inserts \a category to axis at \a index |
|
186 | Inserts \a category to axis at \a index | |
187 | */ |
|
187 | */ | |
188 | void QBarCategoriesAxis::insert(int index, const QString &category) |
|
188 | void QBarCategoriesAxis::insert(int index, const QString &category) | |
189 | { |
|
189 | { | |
190 | Q_D(QBarCategoriesAxis); |
|
190 | Q_D(QBarCategoriesAxis); | |
191 | if (d->m_categories.isEmpty()) { |
|
191 | if (d->m_categories.isEmpty()) { | |
192 |
|
|
192 | d->m_categories.insert(index,category); | |
193 |
|
|
193 | setRange(category,category); | |
194 | }else{ |
|
194 | }else{ | |
195 | d->m_categories.insert(index,category); |
|
195 | d->m_categories.insert(index,category); | |
196 | } |
|
196 | } | |
197 | emit d->updated(); |
|
197 | emit d->updated(); | |
198 | emit categoriesChanged(); |
|
198 | emit categoriesChanged(); | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | Removes all categories. |
|
202 | Removes all categories. | |
203 | */ |
|
203 | */ | |
204 | void QBarCategoriesAxis::clear() |
|
204 | void QBarCategoriesAxis::clear() | |
205 | { |
|
205 | { | |
206 | Q_D(QBarCategoriesAxis); |
|
206 | Q_D(QBarCategoriesAxis); | |
207 | d->m_categories.clear(); |
|
207 | d->m_categories.clear(); | |
208 | setRange(QString::null,QString::null); |
|
208 | setRange(QString::null,QString::null); | |
209 | emit d->updated(); |
|
209 | emit d->updated(); | |
210 | emit categoriesChanged(); |
|
210 | emit categoriesChanged(); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | void QBarCategoriesAxis::setCategories(const QStringList &categories) |
|
213 | void QBarCategoriesAxis::setCategories(const QStringList &categories) | |
214 | { |
|
214 | { | |
215 | Q_D(QBarCategoriesAxis); |
|
215 | Q_D(QBarCategoriesAxis); | |
216 | if(d->m_categories!=categories){ |
|
216 | if(d->m_categories!=categories){ | |
217 | d->m_categories = categories; |
|
217 | d->m_categories = categories; | |
218 | setRange(categories.first(),categories.last()); |
|
218 | setRange(categories.first(),categories.last()); | |
219 | emit d->updated(); |
|
219 | emit d->updated(); | |
220 | emit categoriesChanged(); |
|
220 | emit categoriesChanged(); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | QStringList QBarCategoriesAxis::categories() |
|
224 | QStringList QBarCategoriesAxis::categories() | |
225 | { |
|
225 | { | |
226 | Q_D(QBarCategoriesAxis); |
|
226 | Q_D(QBarCategoriesAxis); | |
227 | return d->m_categories; |
|
227 | return d->m_categories; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | Returns number of categories. |
|
231 | Returns number of categories. | |
232 | */ |
|
232 | */ | |
233 | int QBarCategoriesAxis::count() const |
|
233 | int QBarCategoriesAxis::count() const | |
234 | { |
|
234 | { | |
235 | Q_D(const QBarCategoriesAxis); |
|
235 | Q_D(const QBarCategoriesAxis); | |
236 | return d->m_categories.count(); |
|
236 | return d->m_categories.count(); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | Returns category at \a index. Index must be valid. |
|
240 | Returns category at \a index. Index must be valid. | |
241 | */ |
|
241 | */ | |
242 | QString QBarCategoriesAxis::at(int index) const |
|
242 | QString QBarCategoriesAxis::at(int index) const | |
243 | { |
|
243 | { | |
244 | Q_D(const QBarCategoriesAxis); |
|
244 | Q_D(const QBarCategoriesAxis); | |
245 | return d->m_categories.at(index); |
|
245 | return d->m_categories.at(index); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | /*! |
|
248 | /*! | |
249 | Sets minimum category to \a min. |
|
249 | Sets minimum category to \a min. | |
250 | */ |
|
250 | */ | |
251 | void QBarCategoriesAxis::setMin(const QString& min) |
|
251 | void QBarCategoriesAxis::setMin(const QString& min) | |
252 | { |
|
252 | { | |
253 | Q_D(QBarCategoriesAxis); |
|
253 | Q_D(QBarCategoriesAxis); | |
254 | setRange(min,d->m_maxCategory); |
|
254 | setRange(min,d->m_maxCategory); | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | /*! |
|
257 | /*! | |
258 | Returns minimum category. |
|
258 | Returns minimum category. | |
259 | */ |
|
259 | */ | |
260 | QString QBarCategoriesAxis::min() const |
|
260 | QString QBarCategoriesAxis::min() const | |
261 | { |
|
261 | { | |
262 | Q_D(const QBarCategoriesAxis); |
|
262 | Q_D(const QBarCategoriesAxis); | |
263 | return d->m_minCategory; |
|
263 | return d->m_minCategory; | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | /*! |
|
266 | /*! | |
267 | Sets maximum category to \a max. |
|
267 | Sets maximum category to \a max. | |
268 | */ |
|
268 | */ | |
269 | void QBarCategoriesAxis::setMax(const QString& max) |
|
269 | void QBarCategoriesAxis::setMax(const QString& max) | |
270 | { |
|
270 | { | |
271 | Q_D(QBarCategoriesAxis); |
|
271 | Q_D(QBarCategoriesAxis); | |
272 | setRange(d->m_minCategory,max); |
|
272 | setRange(d->m_minCategory,max); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Returns maximum category |
|
276 | Returns maximum category | |
277 | */ |
|
277 | */ | |
278 | QString QBarCategoriesAxis::max() const |
|
278 | QString QBarCategoriesAxis::max() const | |
279 | { |
|
279 | { | |
280 | Q_D(const QBarCategoriesAxis); |
|
280 | Q_D(const QBarCategoriesAxis); | |
281 | return d->m_maxCategory; |
|
281 | return d->m_maxCategory; | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | /*! |
|
284 | /*! | |
285 | Sets range from \a minCategory to \a maxCategory |
|
285 | Sets range from \a minCategory to \a maxCategory | |
286 | */ |
|
286 | */ | |
287 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
287 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) | |
288 | { |
|
288 | { | |
289 | Q_D(QBarCategoriesAxis); |
|
289 | Q_D(QBarCategoriesAxis); | |
290 |
|
290 | |||
291 | int minIndex = d->m_categories.indexOf(minCategory); |
|
291 | int minIndex = d->m_categories.indexOf(minCategory); | |
292 | if (minIndex == -1) { |
|
292 | if (minIndex == -1) { | |
293 | return; |
|
293 | return; | |
294 | } |
|
294 | } | |
295 | int maxIndex = d->m_categories.indexOf(maxCategory); |
|
295 | int maxIndex = d->m_categories.indexOf(maxCategory); | |
296 | if (maxIndex == -1) { |
|
296 | if (maxIndex == -1) { | |
297 | return; |
|
297 | return; | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | if (maxIndex <= minIndex) { |
|
300 | if (maxIndex <= minIndex) { | |
301 | // max must be greater than min |
|
301 | // max must be greater than min | |
302 | return; |
|
302 | return; | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | bool changed = false; |
|
305 | bool changed = false; | |
306 | if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) { |
|
306 | if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) { | |
307 |
|
|
307 | d->m_minCategory = minCategory; | |
308 | d->m_min = minIndex; |
|
308 | d->m_min = minIndex; | |
309 | emit minChanged(minCategory); |
|
309 | emit minChanged(minCategory); | |
310 | changed = true; |
|
310 | changed = true; | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) { |
|
313 | if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) { | |
314 | d->m_max = maxIndex; |
|
314 | d->m_max = maxIndex; | |
315 | d->m_maxCategory = maxCategory; |
|
315 | d->m_maxCategory = maxCategory; | |
316 | emit maxChanged(maxCategory); |
|
316 | emit maxChanged(maxCategory); | |
317 | changed = true; |
|
317 | changed = true; | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | if (changed) { |
|
320 | if (changed) { | |
321 | d->emitRange(); |
|
321 | d->emitRange(); | |
322 | } |
|
322 | } | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | /*! |
|
325 | /*! | |
326 | Returns the type of the axis |
|
326 | Returns the type of the axis | |
327 | */ |
|
327 | */ | |
328 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const |
|
328 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const | |
329 | { |
|
329 | { | |
330 | return AxisTypeCategories; |
|
330 | return AxisTypeCategories; | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
333 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
334 |
|
334 | |||
335 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): |
|
335 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): | |
336 | QAbstractAxisPrivate(q) |
|
336 | QAbstractAxisPrivate(q) | |
337 | { |
|
337 | { | |
338 |
|
338 | |||
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
341 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() | |
342 | { |
|
342 | { | |
343 |
|
343 | |||
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
346 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) | |
347 | { |
|
347 | { | |
348 | setRange(min,m_maxCategory); |
|
348 | setRange(min,m_maxCategory); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
351 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) | |
352 | { |
|
352 | { | |
353 | setRange(m_minCategory,max); |
|
353 | setRange(m_minCategory,max); | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
356 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
357 | { |
|
357 | { | |
358 | Q_Q(QBarCategoriesAxis); |
|
358 | Q_Q(QBarCategoriesAxis); | |
359 | QString value1 = min.toString(); |
|
359 | QString value1 = min.toString(); | |
360 | QString value2 = max.toString(); |
|
360 | QString value2 = max.toString(); | |
361 | q->setRange(value1,value2); |
|
361 | q->setRange(value1,value2); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | int QBarCategoriesAxisPrivate::ticksCount() const |
|
364 | int QBarCategoriesAxisPrivate::ticksCount() const | |
365 | { |
|
365 | { | |
366 | return m_categories.count()+1; |
|
366 | return m_categories.count()+1; | |
367 | } |
|
367 | } | |
368 |
|
368 | |||
369 | void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
369 | void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
370 | { |
|
370 | { | |
|
371 | Q_Q(QBarCategoriesAxis); | |||
|
372 | Q_UNUSED(count); | |||
371 | m_min = min; |
|
373 | m_min = min; | |
372 | m_max = max; |
|
374 | m_max = max; | |
373 | m_ticksCount = count; |
|
375 | int minIndex = qFloor(min); | |
374 | //TODO: |
|
376 | int maxIndex = qFloor(max); | |
|
377 | ||||
|
378 | if (minIndex < 0) { | |||
|
379 | minIndex = 0; | |||
|
380 | } | |||
|
381 | if (maxIndex > m_categories.count()-1){ | |||
|
382 | maxIndex = m_categories.count()-1; | |||
|
383 | } | |||
|
384 | ||||
|
385 | bool changed = false; | |||
|
386 | if (m_minCategory != m_categories.at(minIndex)) { | |||
|
387 | m_minCategory = m_categories.at(minIndex); | |||
|
388 | emit q->minChanged(m_minCategory); | |||
|
389 | changed = true; | |||
|
390 | } | |||
|
391 | ||||
|
392 | if (m_maxCategory != m_categories.at(maxIndex)) { | |||
|
393 | m_maxCategory = m_categories.at(maxIndex); | |||
|
394 | emit q->maxChanged(m_maxCategory); | |||
|
395 | changed = true; | |||
|
396 | } | |||
|
397 | ||||
|
398 | if (changed) { | |||
|
399 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |||
|
400 | } | |||
375 | } |
|
401 | } | |
376 |
|
402 | |||
377 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
403 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) | |
378 | { |
|
404 | { | |
379 | Q_Q(QBarCategoriesAxis); |
|
405 | Q_Q(QBarCategoriesAxis); | |
380 | if(m_orientation == Qt::Vertical){ |
|
406 | if(m_orientation == Qt::Vertical){ | |
381 | return new ChartCategoriesAxisY(q,presenter); |
|
407 | return new ChartCategoriesAxisY(q,presenter); | |
382 | }else{ |
|
408 | }else{ | |
383 | return new ChartCategoriesAxisX(q,presenter); |
|
409 | return new ChartCategoriesAxisX(q,presenter); | |
384 | } |
|
410 | } | |
385 | } |
|
411 | } | |
386 |
|
412 | |||
387 | void QBarCategoriesAxisPrivate::emitRange() |
|
413 | void QBarCategoriesAxisPrivate::emitRange() | |
388 | { |
|
414 | { | |
389 |
|
|
415 | emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); | |
390 | } |
|
416 | } | |
391 |
|
417 | |||
392 | void QBarCategoriesAxisPrivate::initialize(Domain* domain) |
|
418 | void QBarCategoriesAxisPrivate::initialize(Domain* domain) | |
393 | { |
|
419 | { | |
394 | Q_UNUSED(domain); |
|
420 | if (qFuzzyCompare(m_max, m_min)) { | |
395 | //TODO: |
|
421 | if(m_orientation==Qt::Vertical){ | |
|
422 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); | |||
|
423 | }else{ | |||
|
424 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); | |||
|
425 | } | |||
|
426 | } | |||
396 | } |
|
427 | } | |
397 |
|
428 | |||
398 | #include "moc_qbarcategoriesaxis.cpp" |
|
429 | #include "moc_qbarcategoriesaxis.cpp" | |
399 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
430 | #include "moc_qbarcategoriesaxis_p.cpp" | |
400 |
|
431 | |||
401 | QTCOMMERCIALCHART_END_NAMESPACE |
|
432 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,323 +1,323 | |||||
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 "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 | /*! |
|
29 | /*! | |
30 | \class QValuesAxis |
|
30 | \class QValuesAxis | |
31 | \brief The QValuesAxis class is used for manipulating chart's axis. |
|
31 | \brief The QValuesAxis class is used for manipulating chart's axis. | |
32 | \mainclass |
|
32 | \mainclass | |
33 |
|
33 | |||
34 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
34 | ValuesAxis can be setup to show axis line with tick marks, grid lines and shades. | |
35 | Values of axis are drawn to position of ticks |
|
35 | Values of axis are drawn to position of ticks | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \qmlclass ValuesAxis QValuesAxis |
|
39 | \qmlclass ValuesAxis QValuesAxis | |
40 | \brief The ValuesAxis element is used for manipulating chart's axes |
|
40 | \brief The ValuesAxis element is used for manipulating chart's axes | |
41 |
|
41 | |||
42 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
42 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
43 | Values of axis are drawn to position of ticks |
|
43 | Values of axis are drawn to position of ticks | |
44 |
|
44 | |||
45 | To access Axes you can use ChartView API. For example: |
|
45 | To access Axes you can use ChartView API. For example: | |
46 | \code |
|
46 | \code | |
47 | ChartView { |
|
47 | ChartView { | |
48 | ValuesAxis { |
|
48 | ValuesAxis { | |
49 | id: xAxis |
|
49 | id: xAxis | |
50 | min: 0 |
|
50 | min: 0 | |
51 | max: 10 |
|
51 | max: 10 | |
52 | } |
|
52 | } | |
53 | // Add a few series... |
|
53 | // Add a few series... | |
54 | } |
|
54 | } | |
55 | \endcode |
|
55 | \endcode | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QValuesAxis::min |
|
59 | \property QValuesAxis::min | |
60 | Defines the minimum value on the axis. |
|
60 | Defines the minimum value on the axis. | |
61 | */ |
|
61 | */ | |
62 | /*! |
|
62 | /*! | |
63 | \qmlproperty real ValuesAxis::min |
|
63 | \qmlproperty real ValuesAxis::min | |
64 | Defines the minimum value on the axis. |
|
64 | Defines the minimum value on the axis. | |
65 | */ |
|
65 | */ | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | \property QValuesAxis::max |
|
68 | \property QValuesAxis::max | |
69 | Defines the maximum value on the axis. |
|
69 | Defines the maximum value on the axis. | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty real ValuesAxis::max |
|
72 | \qmlproperty real ValuesAxis::max | |
73 | Defines the maximum value on the axis. |
|
73 | Defines the maximum value on the axis. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \fn void QValuesAxis::minChanged(qreal min) |
|
77 | \fn void QValuesAxis::minChanged(qreal min) | |
78 | Axis emits signal when \a min of axis has changed. |
|
78 | Axis emits signal when \a min of axis has changed. | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlsignal ValuesAxis::onMinChanged(real min) |
|
81 | \qmlsignal ValuesAxis::onMinChanged(real min) | |
82 | Axis emits signal when \a min of axis has changed. |
|
82 | Axis emits signal when \a min of axis has changed. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \fn void QValuesAxis::maxChanged(qreal max) |
|
86 | \fn void QValuesAxis::maxChanged(qreal max) | |
87 | Axis emits signal when \a max of axis has changed. |
|
87 | Axis emits signal when \a max of axis has changed. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlsignal ValuesAxis::onMaxChanged(real max) |
|
90 | \qmlsignal ValuesAxis::onMaxChanged(real max) | |
91 | Axis emits signal when \a max of axis has changed. |
|
91 | Axis emits signal when \a max of axis has changed. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \fn void QValuesAxis::rangeChanged(qreal min, qreal max) |
|
95 | \fn void QValuesAxis::rangeChanged(qreal min, qreal max) | |
96 | Axis emits signal when \a min or \a max of axis has changed. |
|
96 | Axis emits signal when \a min or \a max of axis has changed. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QValuesAxis::ticksCount |
|
100 | \property QValuesAxis::ticksCount | |
101 | The number of tick marks for the axis. |
|
101 | The number of tick marks for the axis. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \qmlproperty int ValuesAxis::ticksCount |
|
105 | \qmlproperty int ValuesAxis::ticksCount | |
106 | The number of tick marks for the axis. |
|
106 | The number of tick marks for the axis. | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \property QValuesAxis::niceNumbersEnabled |
|
110 | \property QValuesAxis::niceNumbersEnabled | |
111 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
111 | Whether the nice numbers algorithm is enabled or not for the axis. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \qmlproperty bool ValuesAxis::niceNumbersEnabled |
|
115 | \qmlproperty bool ValuesAxis::niceNumbersEnabled | |
116 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
116 | Whether the nice numbers algorithm is enabled or not for the axis. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | Constructs an axis object which is a child of \a parent. |
|
120 | Constructs an axis object which is a child of \a parent. | |
121 | */ |
|
121 | */ | |
122 | QValuesAxis::QValuesAxis(QObject *parent) : |
|
122 | QValuesAxis::QValuesAxis(QObject *parent) : | |
123 | QAbstractAxis(*new QValuesAxisPrivate(this),parent) |
|
123 | QAbstractAxis(*new QValuesAxisPrivate(this),parent) | |
124 | { |
|
124 | { | |
125 |
|
125 | |||
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \internal |
|
129 | \internal | |
130 | */ |
|
130 | */ | |
131 | QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
131 | QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) | |
132 | { |
|
132 | { | |
133 |
|
133 | |||
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Destroys the object |
|
137 | Destroys the object | |
138 | */ |
|
138 | */ | |
139 | QValuesAxis::~QValuesAxis() |
|
139 | QValuesAxis::~QValuesAxis() | |
140 | { |
|
140 | { | |
141 |
|
141 | |||
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void QValuesAxis::setMin(qreal min) |
|
144 | void QValuesAxis::setMin(qreal min) | |
145 | { |
|
145 | { | |
146 | Q_D(QValuesAxis); |
|
146 | Q_D(QValuesAxis); | |
147 | setRange(min,d->m_max); |
|
147 | setRange(min,d->m_max); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | qreal QValuesAxis::min() const |
|
150 | qreal QValuesAxis::min() const | |
151 | { |
|
151 | { | |
152 | Q_D(const QValuesAxis); |
|
152 | Q_D(const QValuesAxis); | |
153 | return d->m_min; |
|
153 | return d->m_min; | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void QValuesAxis::setMax(qreal max) |
|
156 | void QValuesAxis::setMax(qreal max) | |
157 | { |
|
157 | { | |
158 | Q_D(QValuesAxis); |
|
158 | Q_D(QValuesAxis); | |
159 | setRange(d->m_min,max); |
|
159 | setRange(d->m_min,max); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | qreal QValuesAxis::max() const |
|
162 | qreal QValuesAxis::max() const | |
163 | { |
|
163 | { | |
164 | Q_D(const QValuesAxis); |
|
164 | Q_D(const QValuesAxis); | |
165 | return d->m_max; |
|
165 | return d->m_max; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | Sets range from \a min to \a max on the axis. |
|
169 | Sets range from \a min to \a max on the axis. | |
170 | */ |
|
170 | */ | |
171 | void QValuesAxis::setRange(qreal min, qreal max) |
|
171 | void QValuesAxis::setRange(qreal min, qreal max) | |
172 | { |
|
172 | { | |
173 | Q_D(QValuesAxis); |
|
173 | Q_D(QValuesAxis); | |
174 |
|
174 | |||
175 | bool changed = false; |
|
175 | bool changed = false; | |
176 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
176 | if (!qFuzzyIsNull(d->m_min - min)) { | |
177 | d->m_min = min; |
|
177 | d->m_min = min; | |
178 | changed = true; |
|
178 | changed = true; | |
179 | emit minChanged(min); |
|
179 | emit minChanged(min); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
182 | if (!qFuzzyIsNull(d->m_max - max)) { | |
183 | d->m_max = max; |
|
183 | d->m_max = max; | |
184 | changed = true; |
|
184 | changed = true; | |
185 | emit maxChanged(max); |
|
185 | emit maxChanged(max); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | if (changed) { |
|
188 | if (changed) { | |
189 | d->emitRange(); |
|
189 | d->emitRange(); | |
190 | emit rangeChanged(d->m_min,d->m_max); |
|
190 | emit rangeChanged(d->m_min,d->m_max); | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | Sets \a count for ticks on the axis. |
|
195 | Sets \a count for ticks on the axis. | |
196 | */ |
|
196 | */ | |
197 | void QValuesAxis::setTicksCount(int count) |
|
197 | void QValuesAxis::setTicksCount(int count) | |
198 | { |
|
198 | { | |
199 | Q_D(QValuesAxis); |
|
199 | Q_D(QValuesAxis); | |
200 | if (d->m_ticksCount != count) { |
|
200 | if (d->m_ticksCount != count) { | |
201 | d->m_ticksCount = count; |
|
201 | d->m_ticksCount = count; | |
202 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
202 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); | |
203 | } |
|
203 | } | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | \fn int QValuesAxis::ticksCount() const |
|
207 | \fn int QValuesAxis::ticksCount() const | |
208 | Return number of ticks on the axis |
|
208 | Return number of ticks on the axis | |
209 | */ |
|
209 | */ | |
210 | int QValuesAxis::ticksCount() const |
|
210 | int QValuesAxis::ticksCount() const | |
211 | { |
|
211 | { | |
212 | Q_D(const QValuesAxis); |
|
212 | Q_D(const QValuesAxis); | |
213 | return d->m_ticksCount; |
|
213 | return d->m_ticksCount; | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | void QValuesAxis::setNiceNumbersEnabled(bool enable) |
|
216 | void QValuesAxis::setNiceNumbersEnabled(bool enable) | |
217 | { |
|
217 | { | |
218 | Q_D(QValuesAxis); |
|
218 | Q_D(QValuesAxis); | |
219 | if (d->m_niceNumbers != enable){ |
|
219 | if (d->m_niceNumbers != enable){ | |
220 | d->m_niceNumbers = enable; |
|
220 | d->m_niceNumbers = enable; | |
221 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
221 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); | |
222 | } |
|
222 | } | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | bool QValuesAxis::niceNumbersEnabled() const |
|
225 | bool QValuesAxis::niceNumbersEnabled() const | |
226 | { |
|
226 | { | |
227 | Q_D(const QValuesAxis); |
|
227 | Q_D(const QValuesAxis); | |
228 | return d->m_niceNumbers; |
|
228 | return d->m_niceNumbers; | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Returns the type of the axis |
|
232 | Returns the type of the axis | |
233 | */ |
|
233 | */ | |
234 | QAbstractAxis::AxisType QValuesAxis::type() const |
|
234 | QAbstractAxis::AxisType QValuesAxis::type() const | |
235 | { |
|
235 | { | |
236 | return AxisTypeValues; |
|
236 | return AxisTypeValues; | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
239 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
240 |
|
240 | |||
241 | QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): |
|
241 | QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): | |
242 | QAbstractAxisPrivate(q), |
|
242 | QAbstractAxisPrivate(q), | |
243 | m_niceNumbers(false) |
|
243 | m_niceNumbers(false) | |
244 | { |
|
244 | { | |
245 |
|
245 | |||
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | QValuesAxisPrivate::~QValuesAxisPrivate() |
|
248 | QValuesAxisPrivate::~QValuesAxisPrivate() | |
249 | { |
|
249 | { | |
250 |
|
250 | |||
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
253 | void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) | |
254 | { |
|
254 | { | |
255 | Q_Q(QValuesAxis); |
|
255 | Q_Q(QValuesAxis); | |
256 | q->setRange(min,max); |
|
256 | q->setRange(min,max); | |
257 | q->setTicksCount(count); |
|
257 | q->setTicksCount(count); | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 |
|
260 | |||
261 | void QValuesAxisPrivate::setMin(const QVariant &min) |
|
261 | void QValuesAxisPrivate::setMin(const QVariant &min) | |
262 | { |
|
262 | { | |
263 | Q_Q(QValuesAxis); |
|
263 | Q_Q(QValuesAxis); | |
264 | bool ok; |
|
264 | bool ok; | |
265 | qreal value = min.toReal(&ok); |
|
265 | qreal value = min.toReal(&ok); | |
266 | if(ok) q->setMin(value); |
|
266 | if(ok) q->setMin(value); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void QValuesAxisPrivate::setMax(const QVariant &max) |
|
269 | void QValuesAxisPrivate::setMax(const QVariant &max) | |
270 | { |
|
270 | { | |
271 |
|
271 | |||
272 | Q_Q(QValuesAxis); |
|
272 | Q_Q(QValuesAxis); | |
273 | bool ok; |
|
273 | bool ok; | |
274 | qreal value = max.toReal(&ok); |
|
274 | qreal value = max.toReal(&ok); | |
275 | if(ok) q->setMax(value); |
|
275 | if(ok) q->setMax(value); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
278 | void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
279 | { |
|
279 | { | |
280 | Q_Q(QValuesAxis); |
|
280 | Q_Q(QValuesAxis); | |
281 | bool ok1; |
|
281 | bool ok1; | |
282 | bool ok2; |
|
282 | bool ok2; | |
283 | qreal value1 = min.toReal(&ok1); |
|
283 | qreal value1 = min.toReal(&ok1); | |
284 | qreal value2 = max.toReal(&ok2); |
|
284 | qreal value2 = max.toReal(&ok2); | |
285 | if(ok1&&ok2) q->setRange(value1,value2); |
|
285 | if(ok1&&ok2) q->setRange(value1,value2); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | int QValuesAxisPrivate::ticksCount() const |
|
288 | int QValuesAxisPrivate::ticksCount() const | |
289 | { |
|
289 | { | |
290 | return m_ticksCount; |
|
290 | return m_ticksCount; | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
293 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) | |
294 | { |
|
294 | { | |
295 | Q_Q(QValuesAxis); |
|
295 | Q_Q(QValuesAxis); | |
296 | if(m_orientation == Qt::Vertical){ |
|
296 | if(m_orientation == Qt::Vertical){ | |
297 | return new ChartValuesAxisY(q,presenter); |
|
297 | return new ChartValuesAxisY(q,presenter); | |
298 | }else{ |
|
298 | }else{ | |
299 | return new ChartValuesAxisX(q,presenter); |
|
299 | return new ChartValuesAxisX(q,presenter); | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void QValuesAxisPrivate::emitRange() |
|
304 | void QValuesAxisPrivate::emitRange() | |
305 | { |
|
305 | { | |
306 | emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); |
|
306 | emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void QValuesAxisPrivate::initialize(Domain* domain) |
|
309 | void QValuesAxisPrivate::initialize(Domain* domain) | |
310 | { |
|
310 | { | |
311 |
if(m_max |
|
311 | if(qFuzzyCompare(m_max,m_min)) { | |
312 | if(m_orientation==Qt::Vertical){ |
|
312 | if(m_orientation==Qt::Vertical){ | |
313 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); |
|
313 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); | |
314 | }else{ |
|
314 | }else{ | |
315 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); |
|
315 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); | |
316 | } |
|
316 | } | |
317 | } |
|
317 | } | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | #include "moc_qvaluesaxis.cpp" |
|
320 | #include "moc_qvaluesaxis.cpp" | |
321 | #include "moc_qvaluesaxis_p.cpp" |
|
321 | #include "moc_qvaluesaxis_p.cpp" | |
322 |
|
322 | |||
323 | QTCOMMERCIALCHART_END_NAMESPACE |
|
323 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now