@@ -1,442 +1,456 | |||||
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 | Removes all categories. |
|
208 | Removes all categories. | |
209 | */ |
|
209 | */ | |
210 | void QBarCategoriesAxis::clear() |
|
210 | void QBarCategoriesAxis::clear() | |
211 | { |
|
211 | { | |
212 | Q_D(QBarCategoriesAxis); |
|
212 | Q_D(QBarCategoriesAxis); | |
213 | d->m_categories.clear(); |
|
213 | d->m_categories.clear(); | |
214 | setRange(QString::null,QString::null); |
|
214 | setRange(QString::null,QString::null); | |
215 | emit categoriesChanged(); |
|
215 | emit categoriesChanged(); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | void QBarCategoriesAxis::setCategories(const QStringList &categories) |
|
218 | void QBarCategoriesAxis::setCategories(const QStringList &categories) | |
219 | { |
|
219 | { | |
220 | Q_D(QBarCategoriesAxis); |
|
220 | Q_D(QBarCategoriesAxis); | |
221 | if(d->m_categories!=categories) { |
|
221 | if(d->m_categories!=categories) { | |
222 | d->m_categories = categories; |
|
222 | d->m_categories = categories; | |
223 | setRange(categories.first(),categories.last()); |
|
223 | setRange(categories.first(),categories.last()); | |
224 | emit categoriesChanged(); |
|
224 | emit categoriesChanged(); | |
225 | } |
|
225 | } | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | QStringList QBarCategoriesAxis::categories() |
|
228 | QStringList QBarCategoriesAxis::categories() | |
229 | { |
|
229 | { | |
230 | Q_D(QBarCategoriesAxis); |
|
230 | Q_D(QBarCategoriesAxis); | |
231 | return d->m_categories; |
|
231 | return d->m_categories; | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | Returns number of categories. |
|
235 | Returns number of categories. | |
236 | */ |
|
236 | */ | |
237 | int QBarCategoriesAxis::count() const |
|
237 | int QBarCategoriesAxis::count() const | |
238 | { |
|
238 | { | |
239 | Q_D(const QBarCategoriesAxis); |
|
239 | Q_D(const QBarCategoriesAxis); | |
240 | return d->m_categories.count(); |
|
240 | return d->m_categories.count(); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Returns category at \a index. Index must be valid. |
|
244 | Returns category at \a index. Index must be valid. | |
245 | */ |
|
245 | */ | |
246 | QString QBarCategoriesAxis::at(int index) const |
|
246 | QString QBarCategoriesAxis::at(int index) const | |
247 | { |
|
247 | { | |
248 | Q_D(const QBarCategoriesAxis); |
|
248 | Q_D(const QBarCategoriesAxis); | |
249 | return d->m_categories.at(index); |
|
249 | return d->m_categories.at(index); | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | Sets minimum category to \a min. |
|
253 | Sets minimum category to \a min. | |
254 | */ |
|
254 | */ | |
255 | void QBarCategoriesAxis::setMin(const QString& min) |
|
255 | void QBarCategoriesAxis::setMin(const QString& min) | |
256 | { |
|
256 | { | |
257 | Q_D(QBarCategoriesAxis); |
|
257 | Q_D(QBarCategoriesAxis); | |
258 | setRange(min,d->m_maxCategory); |
|
258 | setRange(min,d->m_maxCategory); | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Returns minimum category. |
|
262 | Returns minimum category. | |
263 | */ |
|
263 | */ | |
264 | QString QBarCategoriesAxis::min() const |
|
264 | QString QBarCategoriesAxis::min() const | |
265 | { |
|
265 | { | |
266 | Q_D(const QBarCategoriesAxis); |
|
266 | Q_D(const QBarCategoriesAxis); | |
267 | return d->m_minCategory; |
|
267 | return d->m_minCategory; | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /*! |
|
270 | /*! | |
271 | Sets maximum category to \a max. |
|
271 | Sets maximum category to \a max. | |
272 | */ |
|
272 | */ | |
273 | void QBarCategoriesAxis::setMax(const QString& max) |
|
273 | void QBarCategoriesAxis::setMax(const QString& max) | |
274 | { |
|
274 | { | |
275 | Q_D(QBarCategoriesAxis); |
|
275 | Q_D(QBarCategoriesAxis); | |
276 | setRange(d->m_minCategory,max); |
|
276 | setRange(d->m_minCategory,max); | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | /*! |
|
279 | /*! | |
280 | Returns maximum category |
|
280 | Returns maximum category | |
281 | */ |
|
281 | */ | |
282 | QString QBarCategoriesAxis::max() const |
|
282 | QString QBarCategoriesAxis::max() const | |
283 | { |
|
283 | { | |
284 | Q_D(const QBarCategoriesAxis); |
|
284 | Q_D(const QBarCategoriesAxis); | |
285 | return d->m_maxCategory; |
|
285 | return d->m_maxCategory; | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | /*! |
|
288 | /*! | |
289 | Sets range from \a minCategory to \a maxCategory |
|
289 | Sets range from \a minCategory to \a maxCategory | |
290 | */ |
|
290 | */ | |
291 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
291 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) | |
292 | { |
|
292 | { | |
293 | Q_D(QBarCategoriesAxis); |
|
293 | Q_D(QBarCategoriesAxis); | |
294 |
|
294 | |||
295 | bool changed = false; |
|
295 | bool changed = false; | |
296 |
|
296 | |||
297 | //special case |
|
297 | //special case | |
298 | if(minCategory.isNull() && maxCategory.isNull()){ |
|
298 | if(minCategory.isNull() && maxCategory.isNull()){ | |
299 | d->m_minCategory = minCategory; |
|
299 | d->m_minCategory = minCategory; | |
300 | d->m_maxCategory = maxCategory; |
|
300 | d->m_maxCategory = maxCategory; | |
301 | d->m_min = 0; |
|
301 | d->m_min = 0; | |
302 | d->m_max = 0; |
|
302 | d->m_max = 0; | |
303 | emit minChanged(minCategory); |
|
303 | emit minChanged(minCategory); | |
304 | emit maxChanged(maxCategory); |
|
304 | emit maxChanged(maxCategory); | |
305 | d->m_count=0; |
|
305 | d->m_count=0; | |
306 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
306 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); | |
307 | d->emitUpdated(); |
|
307 | d->emitUpdated(); | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; |
|
310 | if(d->m_categories.indexOf(d->m_maxCategory)<d->m_categories.indexOf(d->m_minCategory)) return; | |
311 |
|
311 | |||
312 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { |
|
312 | if (!minCategory.isEmpty() && d->m_minCategory!=minCategory && d->m_categories.contains(minCategory)) { | |
313 | d->m_minCategory = minCategory; |
|
313 | d->m_minCategory = minCategory; | |
314 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; |
|
314 | d->m_min = d->m_categories.indexOf(d->m_minCategory) - 0.5; | |
315 | changed = true; |
|
315 | changed = true; | |
316 | emit minChanged(minCategory); |
|
316 | emit minChanged(minCategory); | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { |
|
319 | if (!maxCategory.isEmpty() && d->m_maxCategory!=maxCategory && d->m_categories.contains(maxCategory)) { | |
320 | d->m_maxCategory = maxCategory; |
|
320 | d->m_maxCategory = maxCategory; | |
321 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; |
|
321 | d->m_max = d->m_categories.indexOf(d->m_maxCategory) + 0.5; | |
322 | changed = true; |
|
322 | changed = true; | |
323 | emit maxChanged(maxCategory); |
|
323 | emit maxChanged(maxCategory); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | if (changed) { |
|
326 | if (changed) { | |
327 | d->m_count=d->m_max - d->m_min; |
|
327 | d->m_count=d->m_max - d->m_min; | |
328 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); |
|
328 | emit rangeChanged(d->m_minCategory,d->m_maxCategory); | |
329 | d->emitUpdated(); |
|
329 | d->emitUpdated(); | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | /*! |
|
333 | /*! | |
334 | Returns the type of the axis |
|
334 | Returns the type of the axis | |
335 | */ |
|
335 | */ | |
336 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const |
|
336 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const | |
337 | { |
|
337 | { | |
338 | return AxisTypeCategories; |
|
338 | return AxisTypeCategories; | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
341 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
342 |
|
342 | |||
343 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): |
|
343 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): | |
344 | QAbstractAxisPrivate(q), |
|
344 | QAbstractAxisPrivate(q), | |
345 | m_min(0.0), |
|
345 | m_min(0.0), | |
346 | m_max(0.0), |
|
346 | m_max(0.0), | |
347 | m_count(0) |
|
347 | m_count(0) | |
348 | { |
|
348 | { | |
349 |
|
349 | |||
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
352 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() | |
353 | { |
|
353 | { | |
354 |
|
354 | |||
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
357 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) | |
358 | { |
|
358 | { | |
359 | setRange(min,m_maxCategory); |
|
359 | setRange(min,m_maxCategory); | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
362 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) | |
363 | { |
|
363 | { | |
364 | setRange(m_minCategory,max); |
|
364 | setRange(m_minCategory,max); | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
367 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
368 | { |
|
368 | { | |
369 | Q_Q(QBarCategoriesAxis); |
|
369 | Q_Q(QBarCategoriesAxis); | |
370 | QString value1 = min.toString(); |
|
370 | QString value1 = min.toString(); | |
371 | QString value2 = max.toString(); |
|
371 | QString value2 = max.toString(); | |
372 | q->setRange(value1,value2); |
|
372 | q->setRange(value1,value2); | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | void QBarCategoriesAxisPrivate::handleDomainUpdated() |
|
375 | void QBarCategoriesAxisPrivate::handleDomainUpdated() | |
376 | { |
|
376 | { | |
377 | Q_Q(QBarCategoriesAxis); |
|
377 | Q_Q(QBarCategoriesAxis); | |
378 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
378 | Domain* domain = qobject_cast<Domain*>(sender()); | |
379 |
|
379 | |||
380 | if(m_orientation==Qt::Horizontal) { |
|
380 | if(m_orientation==Qt::Horizontal) { | |
381 | m_min = domain->minX(); |
|
381 | m_min = domain->minX(); | |
382 | m_max = domain->maxX(); |
|
382 | m_max = domain->maxX(); | |
383 | } |
|
383 | } | |
384 | else if(m_orientation==Qt::Vertical) { |
|
384 | else if(m_orientation==Qt::Vertical) { | |
385 | m_min = domain->minY(); |
|
385 | m_min = domain->minY(); | |
386 | m_max = domain->maxY(); |
|
386 | m_max = domain->maxY(); | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | bool changed = false; |
|
389 | bool changed = false; | |
390 |
|
390 | |||
391 | int min = m_min + 0.5; |
|
391 | int min = m_min + 0.5; | |
392 | if(min>=0 && min<m_categories.count()) { |
|
392 | if(min>=0 && min<m_categories.count()) { | |
393 | QString minCategory = m_categories.at(min); |
|
393 | QString minCategory = m_categories.at(min); | |
394 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { |
|
394 | if(m_minCategory!=minCategory && !minCategory.isEmpty()) { | |
395 | m_minCategory=minCategory; |
|
395 | m_minCategory=minCategory; | |
396 | changed=true; |
|
396 | changed=true; | |
397 | emit q->minChanged(minCategory); |
|
397 | emit q->minChanged(minCategory); | |
398 | } |
|
398 | } | |
399 | } |
|
399 | } | |
400 | int max = m_max - 0.5; |
|
400 | int max = m_max - 0.5; | |
401 | if(max>=0 && max<m_categories.count()) { |
|
401 | if(max>=0 && max<m_categories.count()) { | |
402 | QString maxCategory = m_categories.at(max); |
|
402 | QString maxCategory = m_categories.at(max); | |
403 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { |
|
403 | if(m_maxCategory!=maxCategory && !maxCategory.isEmpty()) { | |
404 | m_maxCategory=maxCategory; |
|
404 | m_maxCategory=maxCategory; | |
405 | emit q->maxChanged(maxCategory); |
|
405 | emit q->maxChanged(maxCategory); | |
406 | } |
|
406 | } | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | if (changed) { |
|
409 | if (changed) { | |
410 | emit q->rangeChanged(m_minCategory,m_maxCategory); |
|
410 | emit q->rangeChanged(m_minCategory,m_maxCategory); | |
411 | } |
|
411 | } | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
414 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) | |
415 | { |
|
415 | { | |
416 | Q_Q(QBarCategoriesAxis); |
|
416 | Q_Q(QBarCategoriesAxis); | |
417 | if(m_orientation == Qt::Vertical){ |
|
417 | if(m_orientation == Qt::Vertical){ | |
418 | return new ChartCategoriesAxisY(q,presenter); |
|
418 | return new ChartCategoriesAxisY(q,presenter); | |
419 | }else{ |
|
419 | }else{ | |
420 | return new ChartCategoriesAxisX(q,presenter); |
|
420 | return new ChartCategoriesAxisX(q,presenter); | |
421 | } |
|
421 | } | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) |
|
424 | void QBarCategoriesAxisPrivate::intializeDomain(Domain* domain) | |
425 | { |
|
425 | { | |
426 | Q_UNUSED(domain); |
|
426 | ||
427 | // TODO: this causes crash now. added to known issues. |
|
427 | Q_Q(QBarCategoriesAxis); | |
428 | /* |
|
428 | if(m_max==m_min) { | |
429 | if (qFuzzyCompare(m_max, m_min)) { |
|
429 | int min; | |
430 | if(m_orientation==Qt::Vertical){ |
|
430 | int max; | |
431 | handleAxisRangeChanged(domain->minY(),domain->maxY(),domain->tickXCount()); |
|
431 | if(m_orientation==Qt::Vertical) { | |
432 | }else{ |
|
432 | min = domain->minY() + 0.5; | |
433 | handleAxisRangeChanged(domain->minX(),domain->maxX(),domain->tickYCount()); |
|
433 | max = domain->maxY() - 0.5; | |
|
434 | } | |||
|
435 | else { | |||
|
436 | min = domain->minX() + 0.5; | |||
|
437 | max = domain->maxX() - 0.5; | |||
|
438 | } | |||
|
439 | ||||
|
440 | if(min>0 && min<m_categories.count() && max>0 && max<m_categories.count()) | |||
|
441 | q->setRange(m_categories.at(min),m_categories.at(max)); | |||
|
442 | } | |||
|
443 | else { | |||
|
444 | if(m_orientation==Qt::Vertical) { | |||
|
445 | domain->setRangeY(m_min, m_max); | |||
|
446 | } | |||
|
447 | else { | |||
|
448 | domain->setRangeX(m_min, m_max); | |||
434 | } |
|
449 | } | |
435 | } |
|
450 | } | |
436 | */ |
|
|||
437 | } |
|
451 | } | |
438 |
|
452 | |||
439 | #include "moc_qbarcategoriesaxis.cpp" |
|
453 | #include "moc_qbarcategoriesaxis.cpp" | |
440 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
454 | #include "moc_qbarcategoriesaxis_p.cpp" | |
441 |
|
455 | |||
442 | QTCOMMERCIALCHART_END_NAMESPACE |
|
456 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,484 +1,484 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qvaluesaxis.h" |
|
23 | #include "qvaluesaxis.h" | |
24 | #include "qbarcategoriesaxis.h" |
|
24 | #include "qbarcategoriesaxis.h" | |
25 | #include "qvaluesaxis_p.h" |
|
25 | #include "qvaluesaxis_p.h" | |
26 | #include "qintervalsaxis.h" |
|
26 | #include "qintervalsaxis.h" | |
27 | #include "qdatetimeaxis.h" |
|
27 | #include "qdatetimeaxis.h" | |
28 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
29 | #include "qabstractbarseries.h" |
|
29 | #include "qabstractbarseries.h" | |
30 | #include "qstackedbarseries.h" |
|
30 | #include "qstackedbarseries.h" | |
31 | #include "qpercentbarseries.h" |
|
31 | #include "qpercentbarseries.h" | |
32 | #include "qpieseries.h" |
|
32 | #include "qpieseries.h" | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) |
|
36 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent) | |
37 | { |
|
37 | { | |
38 |
|
38 | |||
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | ChartDataSet::~ChartDataSet() |
|
41 | ChartDataSet::~ChartDataSet() | |
42 | { |
|
42 | { | |
43 | removeAllSeries(); |
|
43 | removeAllSeries(); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
46 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
47 | { |
|
47 | { | |
48 | Domain* domain = m_seriesDomainMap.value(series); |
|
48 | Domain* domain = m_seriesDomainMap.value(series); | |
49 |
|
49 | |||
50 | if(domain) { |
|
50 | if(domain) { | |
51 | qWarning() << "Can not add series. Series already on the chart"; |
|
51 | qWarning() << "Can not add series. Series already on the chart"; | |
52 | return; |
|
52 | return; | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | domain = new Domain(series); |
|
55 | domain = new Domain(series); | |
56 | m_seriesDomainMap.insert(series,domain); |
|
56 | m_seriesDomainMap.insert(series,domain); | |
57 | series->d_ptr->scaleDomain(*domain); |
|
57 | series->d_ptr->scaleDomain(*domain); | |
58 |
|
58 | |||
59 | createSeriesIndex(series); |
|
59 | createSeriesIndex(series); | |
60 |
|
60 | |||
61 | series->setParent(this); // take ownership |
|
61 | series->setParent(this); // take ownership | |
62 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
62 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
63 | series->d_ptr->m_dataset = this; |
|
63 | series->d_ptr->m_dataset = this; | |
64 |
|
64 | |||
65 | emit seriesAdded(series,domain); |
|
65 | emit seriesAdded(series,domain); | |
66 |
|
66 | |||
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
69 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
70 | { |
|
70 | { | |
71 |
|
71 | |||
72 | if(!m_seriesDomainMap.contains(series)) { |
|
72 | if(!m_seriesDomainMap.contains(series)) { | |
73 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
73 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
74 | return; |
|
74 | return; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | emit seriesRemoved(series); |
|
77 | emit seriesRemoved(series); | |
78 |
|
78 | |||
79 | Domain* domain = m_seriesDomainMap.take(series); |
|
79 | Domain* domain = m_seriesDomainMap.take(series); | |
80 | delete domain; |
|
80 | delete domain; | |
81 | domain = 0; |
|
81 | domain = 0; | |
82 |
|
82 | |||
83 | removeSeriesIndex(series); |
|
83 | removeSeriesIndex(series); | |
84 |
|
84 | |||
85 | series->setParent(0); |
|
85 | series->setParent(0); | |
86 | series->d_ptr->m_chart = 0; |
|
86 | series->d_ptr->m_chart = 0; | |
87 | series->d_ptr->m_dataset = 0; |
|
87 | series->d_ptr->m_dataset = 0; | |
88 |
|
88 | |||
89 | removeAxes(series); |
|
89 | removeAxes(series); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 |
|
92 | |||
93 |
|
93 | |||
94 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) |
|
94 | void ChartDataSet::createSeriesIndex(QAbstractSeries* series) | |
95 | { |
|
95 | { | |
96 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
96 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
97 |
|
97 | |||
98 | int key=0; |
|
98 | int key=0; | |
99 | while (i.hasNext()) { |
|
99 | while (i.hasNext()) { | |
100 | i.next(); |
|
100 | i.next(); | |
101 | if(i.key()!=key) { |
|
101 | if(i.key()!=key) { | |
102 | break; |
|
102 | break; | |
103 | } |
|
103 | } | |
104 | key++; |
|
104 | key++; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | m_indexSeriesMap.insert(key,series); |
|
107 | m_indexSeriesMap.insert(key,series); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) |
|
110 | void ChartDataSet::removeSeriesIndex(QAbstractSeries* series) | |
111 | { |
|
111 | { | |
112 | int key = seriesIndex(series); |
|
112 | int key = seriesIndex(series); | |
113 | Q_ASSERT(key!=-1); |
|
113 | Q_ASSERT(key!=-1); | |
114 | m_indexSeriesMap.remove(key); |
|
114 | m_indexSeriesMap.remove(key); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void ChartDataSet::createDefaultAxes() |
|
117 | void ChartDataSet::createDefaultAxes() | |
118 | { |
|
118 | { | |
119 |
|
119 | |||
120 | if(m_seriesDomainMap.isEmpty()) return; |
|
120 | if(m_seriesDomainMap.isEmpty()) return; | |
121 |
|
121 | |||
122 | QAbstractAxis::AxisTypes typeX(0); |
|
122 | QAbstractAxis::AxisTypes typeX(0); | |
123 | QAbstractAxis::AxisTypes typeY(0); |
|
123 | QAbstractAxis::AxisTypes typeY(0); | |
124 |
|
124 | |||
125 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
125 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
126 | while (i.hasNext()) { |
|
126 | while (i.hasNext()) { | |
127 | i.next(); |
|
127 | i.next(); | |
128 | removeAxes(i.key()); |
|
128 | removeAxes(i.key()); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | i.toFront(); |
|
131 | i.toFront(); | |
132 |
|
132 | |||
133 | while (i.hasNext()) { |
|
133 | while (i.hasNext()) { | |
134 | i.next(); |
|
134 | i.next(); | |
135 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
135 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
136 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
136 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
137 | if(axisX) typeX&=axisX->type(); |
|
137 | if(axisX) typeX&=axisX->type(); | |
138 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); |
|
138 | else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal); | |
139 | if(axisY) typeY&=axisY->type(); |
|
139 | if(axisY) typeY&=axisY->type(); | |
140 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); |
|
140 | else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | createAxes(typeX,Qt::Horizontal); |
|
143 | createAxes(typeX,Qt::Horizontal); | |
144 | createAxes(typeY,Qt::Vertical); |
|
144 | createAxes(typeY,Qt::Vertical); | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation) |
|
147 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation) | |
148 | { |
|
148 | { | |
149 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
149 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
150 |
|
150 | |||
151 | if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) |
|
151 | if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories)) | |
152 | { |
|
152 | { | |
153 | while (i.hasNext()) { |
|
153 | while (i.hasNext()) { | |
154 | i.next(); |
|
154 | i.next(); | |
155 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation); |
|
155 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation); | |
156 | if(!axis) continue; |
|
156 | if(!axis) continue; | |
157 | initializeAxis(axis,i.key()); |
|
157 | initializeAxis(axis,i.key()); | |
158 | emit axisAdded(axis,i.value()); |
|
158 | emit axisAdded(axis,i.value()); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | } |
|
161 | } | |
162 | else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
162 | else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { | |
163 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation); |
|
163 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation); | |
164 | i.toFront(); |
|
164 | i.toFront(); | |
165 | while (i.hasNext()) { |
|
165 | while (i.hasNext()) { | |
166 | i.next(); |
|
166 | i.next(); | |
167 | initializeAxis(axis,i.key()); |
|
167 | initializeAxis(axis,i.key()); | |
168 | } |
|
168 | } | |
169 | emit axisAdded(axis,i.value()); |
|
169 | emit axisAdded(axis,i.value()); | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 |
|
173 | |||
174 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation) |
|
174 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation) | |
175 | { |
|
175 | { | |
176 | QAbstractAxis* axis =0; |
|
176 | QAbstractAxis* axis =0; | |
177 |
|
177 | |||
178 | switch(type) { |
|
178 | switch(type) { | |
179 | case QAbstractAxis::AxisTypeValues: |
|
179 | case QAbstractAxis::AxisTypeValues: | |
180 | axis = new QValuesAxis(this); |
|
180 | axis = new QValuesAxis(this); | |
181 | break; |
|
181 | break; | |
182 | case QAbstractAxis::AxisTypeCategories: |
|
182 | case QAbstractAxis::AxisTypeCategories: | |
183 | axis = new QBarCategoriesAxis(this); |
|
183 | axis = new QBarCategoriesAxis(this); | |
184 | break; |
|
184 | break; | |
185 | case QAbstractAxis::AxisTypeIntervals: |
|
185 | case QAbstractAxis::AxisTypeIntervals: | |
186 | axis = new QIntervalsAxis(this); |
|
186 | axis = new QIntervalsAxis(this); | |
187 | break; |
|
187 | break; | |
188 | case QAbstractAxis::AxisTypeDateTime: |
|
188 | case QAbstractAxis::AxisTypeDateTime: | |
189 | axis = new QDateTimeAxis(this); |
|
189 | axis = new QDateTimeAxis(this); | |
190 | break; |
|
190 | break; | |
191 | default: |
|
191 | default: | |
192 | axis = 0; |
|
192 | axis = 0; | |
193 | break; |
|
193 | break; | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | if(axis) |
|
196 | if(axis) | |
197 | axis->d_ptr->setOrientation(orientation); |
|
197 | axis->d_ptr->setOrientation(orientation); | |
198 |
|
198 | |||
199 | return axis; |
|
199 | return axis; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) |
|
202 | void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series) | |
203 | { |
|
203 | { | |
204 | Domain* domain = m_seriesDomainMap.value(series); |
|
204 | Domain* domain = m_seriesDomainMap.value(series); | |
205 | axis->d_ptr->m_dataset = this; |
|
205 | axis->d_ptr->m_dataset = this; | |
206 | axis->d_ptr->intializeDomain(domain); |
|
|||
207 | series->d_ptr->initializeAxis(axis); |
|
206 | series->d_ptr->initializeAxis(axis); | |
|
207 | axis->d_ptr->intializeDomain(domain); | |||
208 | if(axis->orientation()==Qt::Horizontal) { |
|
208 | if(axis->orientation()==Qt::Horizontal) { | |
209 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
209 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); | |
210 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
210 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); | |
211 | m_seriesAxisXMap.insert(series,axis); |
|
211 | m_seriesAxisXMap.insert(series,axis); | |
212 | } |
|
212 | } | |
213 | else { |
|
213 | else { | |
214 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); |
|
214 | QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated())); | |
215 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); |
|
215 | QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated())); | |
216 | m_seriesAxisYMap.insert(series,axis); |
|
216 | m_seriesAxisYMap.insert(series,axis); | |
217 | } |
|
217 | } | |
218 | axis->d_ptr->emitUpdated(); |
|
218 | axis->d_ptr->emitUpdated(); | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | void ChartDataSet::removeAxes(QAbstractSeries* series) |
|
221 | void ChartDataSet::removeAxes(QAbstractSeries* series) | |
222 | { |
|
222 | { | |
223 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
223 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
224 |
|
224 | |||
225 | if(axisX) { |
|
225 | if(axisX) { | |
226 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
226 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
227 | int x = axesX.indexOf(axisX); |
|
227 | int x = axesX.indexOf(axisX); | |
228 |
|
228 | |||
229 | if(x==-1) { |
|
229 | if(x==-1) { | |
230 | emit axisRemoved(axisX); |
|
230 | emit axisRemoved(axisX); | |
231 | axisX->d_ptr->m_dataset=0; |
|
231 | axisX->d_ptr->m_dataset=0; | |
232 | axisX->deleteLater(); |
|
232 | axisX->deleteLater(); | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
236 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
237 |
|
237 | |||
238 | if(axisY) { |
|
238 | if(axisY) { | |
239 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
239 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
240 |
|
240 | |||
241 | int y = axesY.indexOf(axisY); |
|
241 | int y = axesY.indexOf(axisY); | |
242 |
|
242 | |||
243 | if(y==-1) { |
|
243 | if(y==-1) { | |
244 | emit axisRemoved(axisY); |
|
244 | emit axisRemoved(axisY); | |
245 | axisY->d_ptr->m_dataset=0; |
|
245 | axisY->d_ptr->m_dataset=0; | |
246 | axisY->deleteLater(); |
|
246 | axisY->deleteLater(); | |
247 | } |
|
247 | } | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void ChartDataSet::removeAxis(QAbstractAxis* axis) |
|
251 | void ChartDataSet::removeAxis(QAbstractAxis* axis) | |
252 | { |
|
252 | { | |
253 | if(!axis->d_ptr->m_dataset) { |
|
253 | if(!axis->d_ptr->m_dataset) { | |
254 | qWarning()<<"UnBound axis found !"; |
|
254 | qWarning()<<"UnBound axis found !"; | |
255 | return; |
|
255 | return; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
258 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; | |
259 |
|
259 | |||
260 | if(axis->orientation()==Qt::Vertical) { |
|
260 | if(axis->orientation()==Qt::Vertical) { | |
261 | seriesAxisMap= &m_seriesAxisYMap; |
|
261 | seriesAxisMap= &m_seriesAxisYMap; | |
262 | } |
|
262 | } | |
263 | else { |
|
263 | else { | |
264 | seriesAxisMap= &m_seriesAxisXMap; |
|
264 | seriesAxisMap= &m_seriesAxisXMap; | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap); |
|
267 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap); | |
268 |
|
268 | |||
269 | while (i.hasNext()) { |
|
269 | while (i.hasNext()) { | |
270 | i.next(); |
|
270 | i.next(); | |
271 | if(i.value()==axis) { |
|
271 | if(i.value()==axis) { | |
272 | removeSeries(i.key()); |
|
272 | removeSeries(i.key()); | |
273 | } |
|
273 | } | |
274 | } |
|
274 | } | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void ChartDataSet::removeAllSeries() |
|
277 | void ChartDataSet::removeAllSeries() | |
278 | { |
|
278 | { | |
279 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
279 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
280 | foreach(QAbstractSeries *s , series) { |
|
280 | foreach(QAbstractSeries *s , series) { | |
281 | removeSeries(s); |
|
281 | removeSeries(s); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
284 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
285 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
285 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
286 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
286 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
287 |
|
287 | |||
288 | qDeleteAll(series); |
|
288 | qDeleteAll(series); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
291 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
292 | { |
|
292 | { | |
293 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
293 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
294 |
|
294 | |||
295 |
|
295 | |||
296 | blockAxisSignals(true); |
|
296 | blockAxisSignals(true); | |
297 |
|
297 | |||
298 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
298 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
299 |
|
299 | |||
300 | while (i.hasNext()) { |
|
300 | while (i.hasNext()) { | |
301 | i.next(); |
|
301 | i.next(); | |
302 | i.value()->zoomIn(rect,size); |
|
302 | i.value()->zoomIn(rect,size); | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | blockAxisSignals(false); |
|
305 | blockAxisSignals(false); | |
306 |
|
306 | |||
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
309 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
310 | { |
|
310 | { | |
311 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
311 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
312 |
|
312 | |||
313 | blockAxisSignals(true); |
|
313 | blockAxisSignals(true); | |
314 |
|
314 | |||
315 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
315 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
316 |
|
316 | |||
317 | while (i.hasNext()) { |
|
317 | while (i.hasNext()) { | |
318 | i.next(); |
|
318 | i.next(); | |
319 | i.value()->zoomOut(rect,size); |
|
319 | i.value()->zoomOut(rect,size); | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | blockAxisSignals(false); |
|
322 | blockAxisSignals(false); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | void ChartDataSet::blockAxisSignals(bool enabled) |
|
325 | void ChartDataSet::blockAxisSignals(bool enabled) | |
326 | { |
|
326 | { | |
327 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
327 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
328 | while (i.hasNext()) { |
|
328 | while (i.hasNext()) { | |
329 | i.next(); |
|
329 | i.next(); | |
330 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
330 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
331 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
331 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
332 | if(axisX) { |
|
332 | if(axisX) { | |
333 | axisX->d_ptr->blockSignals(enabled); |
|
333 | axisX->d_ptr->blockSignals(enabled); | |
334 | if(!enabled) { |
|
334 | if(!enabled) { | |
335 | axisX->d_ptr->setDirty(false); |
|
335 | axisX->d_ptr->setDirty(false); | |
336 | axisX->d_ptr->emitUpdated(); |
|
336 | axisX->d_ptr->emitUpdated(); | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 | if(axisY) { |
|
339 | if(axisY) { | |
340 | axisY->d_ptr->blockSignals(enabled); |
|
340 | axisY->d_ptr->blockSignals(enabled); | |
341 | if(!enabled) { |
|
341 | if(!enabled) { | |
342 | axisY->d_ptr->setDirty(false); |
|
342 | axisY->d_ptr->setDirty(false); | |
343 | axisY->d_ptr->emitUpdated(); |
|
343 | axisY->d_ptr->emitUpdated(); | |
344 | } |
|
344 | } | |
345 | } |
|
345 | } | |
346 | } |
|
346 | } | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
349 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
350 | { |
|
350 | { | |
351 | int count=0; |
|
351 | int count=0; | |
352 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
352 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
353 | while (i.hasNext()) { |
|
353 | while (i.hasNext()) { | |
354 | i.next(); |
|
354 | i.next(); | |
355 | if(i.key()->type()==type) count++; |
|
355 | if(i.key()->type()==type) count++; | |
356 | } |
|
356 | } | |
357 | return count; |
|
357 | return count; | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
360 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
361 | { |
|
361 | { | |
362 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
362 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
363 | while (i.hasNext()) { |
|
363 | while (i.hasNext()) { | |
364 | i.next(); |
|
364 | i.next(); | |
365 | if (i.value() == series) |
|
365 | if (i.value() == series) | |
366 | return i.key(); |
|
366 | return i.key(); | |
367 | } |
|
367 | } | |
368 | return -1; |
|
368 | return -1; | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
371 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
372 | { |
|
372 | { | |
373 | if(series == 0) { |
|
373 | if(series == 0) { | |
374 |
|
374 | |||
375 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); |
|
375 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); | |
376 |
|
376 | |||
377 | while (i.hasNext()) { |
|
377 | while (i.hasNext()) { | |
378 | i.next(); |
|
378 | i.next(); | |
379 | if(i.value()->isVisible()) return i.value(); |
|
379 | if(i.value()->isVisible()) return i.value(); | |
380 | } |
|
380 | } | |
381 | return 0; |
|
381 | return 0; | |
382 | } |
|
382 | } | |
383 | return m_seriesAxisXMap.value(series); |
|
383 | return m_seriesAxisXMap.value(series); | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
386 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
387 | { |
|
387 | { | |
388 | if(series == 0) { |
|
388 | if(series == 0) { | |
389 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); |
|
389 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); | |
390 |
|
390 | |||
391 | while (i.hasNext()) { |
|
391 | while (i.hasNext()) { | |
392 | i.next(); |
|
392 | i.next(); | |
393 | if(i.value()->isVisible()) return i.value(); |
|
393 | if(i.value()->isVisible()) return i.value(); | |
394 | } |
|
394 | } | |
395 | return 0; |
|
395 | return 0; | |
396 | } |
|
396 | } | |
397 | return m_seriesAxisYMap.value(series); |
|
397 | return m_seriesAxisYMap.value(series); | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) |
|
400 | void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation) | |
401 | { |
|
401 | { | |
402 | Q_ASSERT(axis); |
|
402 | Q_ASSERT(axis); | |
403 |
|
403 | |||
404 | if(!series) { |
|
404 | if(!series) { | |
405 | qWarning() << "Series not found on the chart."; |
|
405 | qWarning() << "Series not found on the chart."; | |
406 | return; |
|
406 | return; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | Domain* domain = m_seriesDomainMap.value(series); |
|
409 | Domain* domain = m_seriesDomainMap.value(series); | |
410 |
|
410 | |||
411 | if(!domain) { |
|
411 | if(!domain) { | |
412 | qWarning() << "Series not found on the chart."; |
|
412 | qWarning() << "Series not found on the chart."; | |
413 | return; |
|
413 | return; | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { |
|
416 | if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) { | |
417 | qWarning()<<"Axis already defined as axis Y"; |
|
417 | qWarning()<<"Axis already defined as axis Y"; | |
418 | return; |
|
418 | return; | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { |
|
421 | if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) { | |
422 | qWarning()<<"Axis already defined as axis X"; |
|
422 | qWarning()<<"Axis already defined as axis X"; | |
423 | return; |
|
423 | return; | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | axis->d_ptr->setOrientation(orientation); |
|
426 | axis->d_ptr->setOrientation(orientation); | |
427 |
|
427 | |||
428 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; |
|
428 | QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap; | |
429 |
|
429 | |||
430 | if(orientation==Qt::Vertical) { |
|
430 | if(orientation==Qt::Vertical) { | |
431 | seriesAxisMap= &m_seriesAxisYMap; |
|
431 | seriesAxisMap= &m_seriesAxisYMap; | |
432 | }else{ |
|
432 | }else{ | |
433 | seriesAxisMap= &m_seriesAxisXMap; |
|
433 | seriesAxisMap= &m_seriesAxisXMap; | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); |
|
436 | QAbstractAxis *oldAxis = seriesAxisMap->take(series); | |
437 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); |
|
437 | QList<QAbstractAxis*> axes = seriesAxisMap->values(); | |
438 | if(oldAxis) { |
|
438 | if(oldAxis) { | |
439 | if(axes.indexOf(oldAxis)==-1) { |
|
439 | if(axes.indexOf(oldAxis)==-1) { | |
440 | emit axisRemoved(oldAxis); |
|
440 | emit axisRemoved(oldAxis); | |
441 | oldAxis->disconnect(); |
|
441 | oldAxis->disconnect(); | |
442 | QObject::disconnect(domain,0,oldAxis,0); |
|
442 | QObject::disconnect(domain,0,oldAxis,0); | |
443 | oldAxis->d_ptr->m_dataset=0; |
|
443 | oldAxis->d_ptr->m_dataset=0; | |
444 | oldAxis->deleteLater(); |
|
444 | oldAxis->deleteLater(); | |
445 | } |
|
445 | } | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | if(axes.indexOf(axis)==-1) { |
|
448 | if(axes.indexOf(axis)==-1) { | |
449 | initializeAxis(axis,series); |
|
449 | initializeAxis(axis,series); | |
450 | emit axisAdded(axis,domain); |
|
450 | emit axisAdded(axis,domain); | |
451 | }else{ |
|
451 | }else{ | |
452 | initializeAxis(axis,series); |
|
452 | initializeAxis(axis,series); | |
453 | } |
|
453 | } | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
456 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
457 | { |
|
457 | { | |
458 | return m_seriesDomainMap.value(series); |
|
458 | return m_seriesDomainMap.value(series); | |
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
461 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
462 | { |
|
462 | { | |
463 | blockAxisSignals(true); |
|
463 | blockAxisSignals(true); | |
464 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
464 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
465 | while (i.hasNext()) { |
|
465 | while (i.hasNext()) { | |
466 | i.next(); |
|
466 | i.next(); | |
467 | i.value()->move(dx,dy,size); |
|
467 | i.value()->move(dx,dy,size); | |
468 | } |
|
468 | } | |
469 | blockAxisSignals(false); |
|
469 | blockAxisSignals(false); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
472 | QList<QAbstractSeries*> ChartDataSet::series() const | |
473 | { |
|
473 | { | |
474 | return m_seriesDomainMap.keys(); |
|
474 | return m_seriesDomainMap.keys(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
477 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
478 | { |
|
478 | { | |
479 | emit seriesUpdated(series); |
|
479 | emit seriesUpdated(series); | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
482 | #include "moc_chartdataset_p.cpp" |
|
482 | #include "moc_chartdataset_p.cpp" | |
483 |
|
483 | |||
484 | QTCOMMERCIALCHART_END_NAMESPACE |
|
484 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,582 +1,649 | |||||
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 "../qabstractaxis/tst_qabstractaxis.h" |
|
21 | #include "../qabstractaxis/tst_qabstractaxis.h" | |
22 | #include <qbarseries.h> |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qbarcategoriesaxis.h> |
|
24 | #include <qbarcategoriesaxis.h> | |
25 |
|
25 | |||
26 | class tst_QBarCategoriesAxis: public tst_QAbstractAxis |
|
26 | class tst_QBarCategoriesAxis: public tst_QAbstractAxis | |
27 | { |
|
27 | { | |
28 | Q_OBJECT |
|
28 | Q_OBJECT | |
29 |
|
29 | |||
30 | public slots: |
|
30 | public slots: | |
31 | void initTestCase(); |
|
31 | void initTestCase(); | |
32 | void cleanupTestCase(); |
|
32 | void cleanupTestCase(); | |
33 | void init(); |
|
33 | void init(); | |
34 | void cleanup(); |
|
34 | void cleanup(); | |
35 |
|
35 | |||
36 | private slots: |
|
36 | private slots: | |
37 | void qbarcategoriesaxis_data(); |
|
37 | void qbarcategoriesaxis_data(); | |
38 | void qbarcategoriesaxis(); |
|
38 | void qbarcategoriesaxis(); | |
39 |
|
39 | |||
40 | void append_data(); |
|
40 | void append_data(); | |
41 | void append(); |
|
41 | void append(); | |
42 | void at_data(); |
|
42 | void at_data(); | |
43 | void at(); |
|
43 | void at(); | |
44 | void categories_data(); |
|
44 | void categories_data(); | |
45 | void categories(); |
|
45 | void categories(); | |
46 | void clear_data(); |
|
46 | void clear_data(); | |
47 | void clear(); |
|
47 | void clear(); | |
48 | void count_data(); |
|
48 | void count_data(); | |
49 | void count(); |
|
49 | void count(); | |
50 | void insert_data(); |
|
50 | void insert_data(); | |
51 | void insert(); |
|
51 | void insert(); | |
52 | void remove_data(); |
|
52 | void remove_data(); | |
53 | void remove(); |
|
53 | void remove(); | |
54 | void max_raw_data(); |
|
54 | void max_raw_data(); | |
55 | void max_raw(); |
|
55 | void max_raw(); | |
56 | void max_data(); |
|
56 | void max_data(); | |
57 | void max(); |
|
57 | void max(); | |
58 | void max_animation_data(); |
|
58 | void max_animation_data(); | |
59 | void max_animation(); |
|
59 | void max_animation(); | |
60 | void min_raw_data(); |
|
60 | void min_raw_data(); | |
61 | void min_raw(); |
|
61 | void min_raw(); | |
62 | void min_data(); |
|
62 | void min_data(); | |
63 | void min(); |
|
63 | void min(); | |
64 | void min_animation_data(); |
|
64 | void min_animation_data(); | |
65 | void min_animation(); |
|
65 | void min_animation(); | |
66 | void range_raw_data(); |
|
66 | void range_raw_data(); | |
67 | void range_raw(); |
|
67 | void range_raw(); | |
68 | void range_data(); |
|
68 | void range_data(); | |
69 | void range(); |
|
69 | void range(); | |
70 | void range_animation_data(); |
|
70 | void range_animation_data(); | |
71 | void range_animation(); |
|
71 | void range_animation(); | |
|
72 | void noautoscale_data(); | |||
|
73 | void noautoscale(); | |||
|
74 | void autoscale_data(); | |||
|
75 | void autoscale(); | |||
72 |
|
76 | |||
73 | private: |
|
77 | private: | |
74 | QBarCategoriesAxis* m_baraxis; |
|
78 | QBarCategoriesAxis* m_baraxis; | |
75 | QBarSeries* m_series; |
|
79 | QBarSeries* m_series; | |
76 | }; |
|
80 | }; | |
77 |
|
81 | |||
78 | void tst_QBarCategoriesAxis::initTestCase() |
|
82 | void tst_QBarCategoriesAxis::initTestCase() | |
79 | { |
|
83 | { | |
80 | } |
|
84 | } | |
81 |
|
85 | |||
82 | void tst_QBarCategoriesAxis::cleanupTestCase() |
|
86 | void tst_QBarCategoriesAxis::cleanupTestCase() | |
83 | { |
|
87 | { | |
84 | } |
|
88 | } | |
85 |
|
89 | |||
86 | void tst_QBarCategoriesAxis::init() |
|
90 | void tst_QBarCategoriesAxis::init() | |
87 | { |
|
91 | { | |
88 | m_baraxis = new QBarCategoriesAxis(); |
|
92 | m_baraxis = new QBarCategoriesAxis(); | |
89 | m_series = new QBarSeries(); |
|
93 | m_series = new QBarSeries(); | |
90 |
|
94 | |||
91 | QBarSet *set0 = new QBarSet("Jane"); |
|
95 | QBarSet *set0 = new QBarSet("Jane"); | |
92 | QBarSet *set1 = new QBarSet("John"); |
|
96 | QBarSet *set1 = new QBarSet("John"); | |
93 | QBarSet *set2 = new QBarSet("Axel"); |
|
97 | QBarSet *set2 = new QBarSet("Axel"); | |
94 | QBarSet *set3 = new QBarSet("Mary"); |
|
98 | QBarSet *set3 = new QBarSet("Mary"); | |
95 | QBarSet *set4 = new QBarSet("Samantha"); |
|
99 | QBarSet *set4 = new QBarSet("Samantha"); | |
96 |
|
100 | |||
97 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
101 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
98 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
102 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
99 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
103 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
100 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
104 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
101 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
105 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
102 |
|
106 | |||
103 | m_series->append(set0); |
|
107 | m_series->append(set0); | |
104 | m_series->append(set1); |
|
108 | m_series->append(set1); | |
105 | m_series->append(set2); |
|
109 | m_series->append(set2); | |
106 | m_series->append(set3); |
|
110 | m_series->append(set3); | |
107 | m_series->append(set4); |
|
111 | m_series->append(set4); | |
108 |
|
112 | |||
109 | QStringList categories; |
|
113 | QStringList categories; | |
110 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
114 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
111 |
|
115 | |||
112 | m_baraxis->append(categories); |
|
116 | m_baraxis->append(categories); | |
113 |
|
117 | |||
114 | tst_QAbstractAxis::init(m_baraxis, m_series); |
|
118 | tst_QAbstractAxis::init(m_baraxis, m_series); | |
115 | m_chart->addSeries(m_series); |
|
119 | m_chart->addSeries(m_series); | |
116 | m_chart->createDefaultAxes(); |
|
120 | m_chart->createDefaultAxes(); | |
117 | } |
|
121 | } | |
118 |
|
122 | |||
119 | void tst_QBarCategoriesAxis::cleanup() |
|
123 | void tst_QBarCategoriesAxis::cleanup() | |
120 | { |
|
124 | { | |
121 | delete m_series; |
|
125 | delete m_series; | |
122 | delete m_baraxis; |
|
126 | delete m_baraxis; | |
123 | m_series = 0; |
|
127 | m_series = 0; | |
124 | m_baraxis = 0; |
|
128 | m_baraxis = 0; | |
125 | tst_QAbstractAxis::cleanup(); |
|
129 | tst_QAbstractAxis::cleanup(); | |
126 | } |
|
130 | } | |
127 |
|
131 | |||
128 | void tst_QBarCategoriesAxis::qbarcategoriesaxis_data() |
|
132 | void tst_QBarCategoriesAxis::qbarcategoriesaxis_data() | |
129 | { |
|
133 | { | |
130 | } |
|
134 | } | |
131 |
|
135 | |||
132 | void tst_QBarCategoriesAxis::qbarcategoriesaxis() |
|
136 | void tst_QBarCategoriesAxis::qbarcategoriesaxis() | |
133 | { |
|
137 | { | |
134 | qabstractaxis(); |
|
138 | qabstractaxis(); | |
135 | QBarCategoriesAxis axis; |
|
139 | QBarCategoriesAxis axis; | |
136 | axis.append(QStringList()); |
|
140 | axis.append(QStringList()); | |
137 | axis.append(QString()); |
|
141 | axis.append(QString()); | |
138 | QCOMPARE(axis.at(0), QString()); |
|
142 | QCOMPARE(axis.at(0), QString()); | |
139 | QStringList test; |
|
143 | QStringList test; | |
140 | test.append(QString()); |
|
144 | test.append(QString()); | |
141 | QCOMPARE(axis.categories(),test); |
|
145 | QCOMPARE(axis.categories(),test); | |
142 | axis.clear(); |
|
146 | axis.clear(); | |
143 | QCOMPARE(axis.count(), 0); |
|
147 | QCOMPARE(axis.count(), 0); | |
144 | axis.insert(-1, QString()); |
|
148 | axis.insert(-1, QString()); | |
145 | QCOMPARE(axis.max(), QString()); |
|
149 | QCOMPARE(axis.max(), QString()); | |
146 | QCOMPARE(axis.min(), QString()); |
|
150 | QCOMPARE(axis.min(), QString()); | |
147 | axis.remove(QString()); |
|
151 | axis.remove(QString()); | |
148 | axis.setCategories(QStringList()); |
|
152 | axis.setCategories(QStringList()); | |
149 | axis.setMax(QString()); |
|
153 | axis.setMax(QString()); | |
150 | axis.setMin(QString()); |
|
154 | axis.setMin(QString()); | |
151 | axis.setRange(QString(), QString()); |
|
155 | axis.setRange(QString(), QString()); | |
152 | QCOMPARE(axis.type(), QAbstractAxis::AxisTypeCategories); |
|
156 | QCOMPARE(axis.type(), QAbstractAxis::AxisTypeCategories); | |
153 | } |
|
157 | } | |
154 |
|
158 | |||
155 | void tst_QBarCategoriesAxis::append_data() |
|
159 | void tst_QBarCategoriesAxis::append_data() | |
156 | { |
|
160 | { | |
157 | QTest::addColumn<QStringList>("categories"); |
|
161 | QTest::addColumn<QStringList>("categories"); | |
158 | QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr"); |
|
162 | QTest::newRow("Jan Feb Mar Apr") << (QStringList() << "Jan" << "Feb" << "Mar" << "Apr"); | |
159 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
163 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); | |
160 | } |
|
164 | } | |
161 |
|
165 | |||
162 | void tst_QBarCategoriesAxis::append() |
|
166 | void tst_QBarCategoriesAxis::append() | |
163 | { |
|
167 | { | |
164 | QFETCH(QStringList, categories); |
|
168 | QFETCH(QStringList, categories); | |
165 |
|
169 | |||
166 | QBarCategoriesAxis axis; |
|
170 | QBarCategoriesAxis axis; | |
167 |
|
171 | |||
168 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
172 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); | |
169 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
173 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); | |
170 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
174 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); | |
171 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
175 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
172 |
|
176 | |||
173 | axis.append(categories); |
|
177 | axis.append(categories); | |
174 |
|
178 | |||
175 | QCOMPARE(spy0.count(), 1); |
|
179 | QCOMPARE(spy0.count(), 1); | |
176 | QCOMPARE(spy1.count(), 1); |
|
180 | QCOMPARE(spy1.count(), 1); | |
177 | QCOMPARE(spy2.count(), 1); |
|
181 | QCOMPARE(spy2.count(), 1); | |
178 | QCOMPARE(spy3.count(), 1); |
|
182 | QCOMPARE(spy3.count(), 1); | |
179 |
|
183 | |||
180 | m_chart->setAxisX(&axis, m_series); |
|
184 | m_chart->setAxisX(&axis, m_series); | |
181 | m_view->show(); |
|
185 | m_view->show(); | |
182 | QTest::qWaitForWindowShown(m_view); |
|
186 | QTest::qWaitForWindowShown(m_view); | |
183 | QCOMPARE(axis.categories(), categories); |
|
187 | QCOMPARE(axis.categories(), categories); | |
184 |
|
188 | |||
185 | QCOMPARE(spy0.count(), 1); |
|
189 | QCOMPARE(spy0.count(), 1); | |
186 | QCOMPARE(spy1.count(), 1); |
|
190 | QCOMPARE(spy1.count(), 1); | |
187 | QCOMPARE(spy2.count(), 1); |
|
191 | QCOMPARE(spy2.count(), 1); | |
188 | QCOMPARE(spy3.count(), 1); |
|
192 | QCOMPARE(spy3.count(), 1); | |
189 | } |
|
193 | } | |
190 |
|
194 | |||
191 | void tst_QBarCategoriesAxis::at_data() |
|
195 | void tst_QBarCategoriesAxis::at_data() | |
192 | { |
|
196 | { | |
193 | QTest::addColumn<QStringList>("categories"); |
|
197 | QTest::addColumn<QStringList>("categories"); | |
194 | QTest::addColumn<int>("index"); |
|
198 | QTest::addColumn<int>("index"); | |
195 | QTest::addColumn<QString>("string"); |
|
199 | QTest::addColumn<QString>("string"); | |
196 | QTest::newRow("Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul"; |
|
200 | QTest::newRow("Jul Aug Sep 0 Jul") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jul"; | |
197 | QTest::newRow("Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep"; |
|
201 | QTest::newRow("Jul Aug Sep 2 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Sep"; | |
198 | QTest::newRow("Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug"; |
|
202 | QTest::newRow("Jul Aug Sep 1 Aug") << (QStringList() << "Jul" << "Aug" << "Sep") << 1 << "Aug"; | |
199 | } |
|
203 | } | |
200 |
|
204 | |||
201 | void tst_QBarCategoriesAxis::at() |
|
205 | void tst_QBarCategoriesAxis::at() | |
202 | { |
|
206 | { | |
203 | QFETCH(int, index); |
|
207 | QFETCH(int, index); | |
204 | QFETCH(QString, string); |
|
208 | QFETCH(QString, string); | |
205 | QFETCH(QStringList, categories); |
|
209 | QFETCH(QStringList, categories); | |
206 |
|
210 | |||
207 | QBarCategoriesAxis axis; |
|
211 | QBarCategoriesAxis axis; | |
208 | axis.append(categories); |
|
212 | axis.append(categories); | |
209 |
|
213 | |||
210 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
214 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); | |
211 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
215 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); | |
212 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
216 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); | |
213 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
217 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
214 |
|
218 | |||
215 | QCOMPARE(axis.at(index), string); |
|
219 | QCOMPARE(axis.at(index), string); | |
216 |
|
220 | |||
217 | QCOMPARE(spy0.count(), 0); |
|
221 | QCOMPARE(spy0.count(), 0); | |
218 | QCOMPARE(spy1.count(), 0); |
|
222 | QCOMPARE(spy1.count(), 0); | |
219 | QCOMPARE(spy2.count(), 0); |
|
223 | QCOMPARE(spy2.count(), 0); | |
220 | QCOMPARE(spy3.count(), 0); |
|
224 | QCOMPARE(spy3.count(), 0); | |
221 |
|
225 | |||
222 | m_chart->setAxisX(&axis, m_series); |
|
226 | m_chart->setAxisX(&axis, m_series); | |
223 | m_view->show(); |
|
227 | m_view->show(); | |
224 | QTest::qWaitForWindowShown(m_view); |
|
228 | QTest::qWaitForWindowShown(m_view); | |
225 | QCOMPARE(axis.at(index), string); |
|
229 | QCOMPARE(axis.at(index), string); | |
226 |
|
230 | |||
227 | QCOMPARE(spy0.count(), 0); |
|
231 | QCOMPARE(spy0.count(), 0); | |
228 | QCOMPARE(spy1.count(), 0); |
|
232 | QCOMPARE(spy1.count(), 0); | |
229 | QCOMPARE(spy2.count(), 0); |
|
233 | QCOMPARE(spy2.count(), 0); | |
230 | QCOMPARE(spy3.count(), 0); |
|
234 | QCOMPARE(spy3.count(), 0); | |
231 | } |
|
235 | } | |
232 |
|
236 | |||
233 | void tst_QBarCategoriesAxis::categories_data() |
|
237 | void tst_QBarCategoriesAxis::categories_data() | |
234 | { |
|
238 | { | |
235 | QTest::addColumn<QStringList>("categories"); |
|
239 | QTest::addColumn<QStringList>("categories"); | |
236 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
240 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); | |
237 | } |
|
241 | } | |
238 |
|
242 | |||
239 | void tst_QBarCategoriesAxis::categories() |
|
243 | void tst_QBarCategoriesAxis::categories() | |
240 | { |
|
244 | { | |
241 | QFETCH(QStringList, categories); |
|
245 | QFETCH(QStringList, categories); | |
242 |
|
246 | |||
243 | QBarCategoriesAxis axis; |
|
247 | QBarCategoriesAxis axis; | |
244 |
|
248 | |||
245 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
249 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); | |
246 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
250 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); | |
247 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
251 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); | |
248 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
252 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
249 |
|
253 | |||
250 | axis.setCategories(categories); |
|
254 | axis.setCategories(categories); | |
251 | QCOMPARE(axis.categories(), categories); |
|
255 | QCOMPARE(axis.categories(), categories); | |
252 |
|
256 | |||
253 | QCOMPARE(spy0.count(), 1); |
|
257 | QCOMPARE(spy0.count(), 1); | |
254 | QCOMPARE(spy1.count(), 1); |
|
258 | QCOMPARE(spy1.count(), 1); | |
255 | QCOMPARE(spy2.count(), 1); |
|
259 | QCOMPARE(spy2.count(), 1); | |
256 | QCOMPARE(spy3.count(), 1); |
|
260 | QCOMPARE(spy3.count(), 1); | |
257 |
|
261 | |||
258 | m_chart->setAxisX(&axis, m_series); |
|
262 | m_chart->setAxisX(&axis, m_series); | |
259 | m_view->show(); |
|
263 | m_view->show(); | |
260 | QTest::qWaitForWindowShown(m_view); |
|
264 | QTest::qWaitForWindowShown(m_view); | |
261 | QCOMPARE(axis.categories(), categories); |
|
265 | QCOMPARE(axis.categories(), categories); | |
262 |
|
266 | |||
263 | QCOMPARE(spy0.count(), 1); |
|
267 | QCOMPARE(spy0.count(), 1); | |
264 | QCOMPARE(spy1.count(), 1); |
|
268 | QCOMPARE(spy1.count(), 1); | |
265 | QCOMPARE(spy2.count(), 1); |
|
269 | QCOMPARE(spy2.count(), 1); | |
266 | QCOMPARE(spy3.count(), 1); |
|
270 | QCOMPARE(spy3.count(), 1); | |
267 |
|
271 | |||
268 | } |
|
272 | } | |
269 |
|
273 | |||
270 | void tst_QBarCategoriesAxis::clear_data() |
|
274 | void tst_QBarCategoriesAxis::clear_data() | |
271 | { |
|
275 | { | |
272 | QTest::addColumn<QStringList>("categories"); |
|
276 | QTest::addColumn<QStringList>("categories"); | |
273 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); |
|
277 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep"); | |
274 | } |
|
278 | } | |
275 |
|
279 | |||
276 | void tst_QBarCategoriesAxis::clear() |
|
280 | void tst_QBarCategoriesAxis::clear() | |
277 | { |
|
281 | { | |
278 | QFETCH(QStringList, categories); |
|
282 | QFETCH(QStringList, categories); | |
279 |
|
283 | |||
280 | QBarCategoriesAxis axis; |
|
284 | QBarCategoriesAxis axis; | |
281 |
|
285 | |||
282 | axis.setCategories(categories); |
|
286 | axis.setCategories(categories); | |
283 | QCOMPARE(axis.categories(), categories); |
|
287 | QCOMPARE(axis.categories(), categories); | |
284 |
|
288 | |||
285 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
289 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); | |
286 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
290 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); | |
287 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
291 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); | |
288 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
292 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
289 |
|
293 | |||
290 | axis.clear(); |
|
294 | axis.clear(); | |
291 | QCOMPARE(axis.categories(), QStringList()); |
|
295 | QCOMPARE(axis.categories(), QStringList()); | |
292 |
|
296 | |||
293 | QCOMPARE(spy0.count(), 1); |
|
297 | QCOMPARE(spy0.count(), 1); | |
294 | QCOMPARE(spy1.count(), 1); |
|
298 | QCOMPARE(spy1.count(), 1); | |
295 | QCOMPARE(spy2.count(), 1); |
|
299 | QCOMPARE(spy2.count(), 1); | |
296 | QCOMPARE(spy3.count(), 1); |
|
300 | QCOMPARE(spy3.count(), 1); | |
297 |
|
301 | |||
298 | m_chart->setAxisX(&axis, m_series); |
|
302 | m_chart->setAxisX(&axis, m_series); | |
299 | m_view->show(); |
|
303 | m_view->show(); | |
300 | QTest::qWaitForWindowShown(m_view); |
|
304 | QTest::qWaitForWindowShown(m_view); | |
301 |
|
305 | |||
302 | QCOMPARE(spy0.count(), 2); |
|
306 | QCOMPARE(spy0.count(), 2); | |
303 | QCOMPARE(spy1.count(), 2); |
|
307 | QCOMPARE(spy1.count(), 2); | |
304 | QCOMPARE(spy2.count(), 2); |
|
308 | QCOMPARE(spy2.count(), 2); | |
305 | QCOMPARE(spy3.count(), 2); |
|
309 | QCOMPARE(spy3.count(), 2); | |
306 |
|
310 | |||
307 | axis.clear(); |
|
311 | axis.clear(); | |
308 | QCOMPARE(axis.categories().count(),0); |
|
312 | QCOMPARE(axis.categories().count(),0); | |
309 | QCOMPARE(spy0.count(), 3); |
|
313 | QCOMPARE(spy0.count(), 3); | |
310 | QCOMPARE(spy1.count(), 3); |
|
314 | QCOMPARE(spy1.count(), 3); | |
311 | QCOMPARE(spy2.count(), 3); |
|
315 | QCOMPARE(spy2.count(), 3); | |
312 | QCOMPARE(spy3.count(), 3); |
|
316 | QCOMPARE(spy3.count(), 3); | |
313 | } |
|
317 | } | |
314 |
|
318 | |||
315 | void tst_QBarCategoriesAxis::count_data() |
|
319 | void tst_QBarCategoriesAxis::count_data() | |
316 | { |
|
320 | { | |
317 | QTest::addColumn<QStringList>("categories"); |
|
321 | QTest::addColumn<QStringList>("categories"); | |
318 | QTest::addColumn<int>("count"); |
|
322 | QTest::addColumn<int>("count"); | |
319 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3; |
|
323 | QTest::newRow("Jul Aug Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3; | |
320 | QTest::newRow("Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2; |
|
324 | QTest::newRow("Jul Aug ") << (QStringList() << "Jul" << "Aug") << 2; | |
321 | } |
|
325 | } | |
322 |
|
326 | |||
323 | void tst_QBarCategoriesAxis::count() |
|
327 | void tst_QBarCategoriesAxis::count() | |
324 | { |
|
328 | { | |
325 | QFETCH(QStringList, categories); |
|
329 | QFETCH(QStringList, categories); | |
326 | QFETCH(int, count); |
|
330 | QFETCH(int, count); | |
327 |
|
331 | |||
328 | QBarCategoriesAxis axis; |
|
332 | QBarCategoriesAxis axis; | |
329 | axis.setCategories(categories); |
|
333 | axis.setCategories(categories); | |
330 |
|
334 | |||
331 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
335 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); | |
332 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
336 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); | |
333 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
337 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); | |
334 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
338 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
335 |
|
339 | |||
336 | QCOMPARE(axis.count(), count); |
|
340 | QCOMPARE(axis.count(), count); | |
337 |
|
341 | |||
338 | QCOMPARE(spy0.count(), 0); |
|
342 | QCOMPARE(spy0.count(), 0); | |
339 | QCOMPARE(spy1.count(), 0); |
|
343 | QCOMPARE(spy1.count(), 0); | |
340 | QCOMPARE(spy2.count(), 0); |
|
344 | QCOMPARE(spy2.count(), 0); | |
341 | QCOMPARE(spy3.count(), 0); |
|
345 | QCOMPARE(spy3.count(), 0); | |
342 |
|
346 | |||
343 | m_chart->setAxisX(&axis, m_series); |
|
347 | m_chart->setAxisX(&axis, m_series); | |
344 | m_view->show(); |
|
348 | m_view->show(); | |
345 | QTest::qWaitForWindowShown(m_view); |
|
349 | QTest::qWaitForWindowShown(m_view); | |
346 | QCOMPARE(axis.count(), count); |
|
350 | QCOMPARE(axis.count(), count); | |
347 | } |
|
351 | } | |
348 |
|
352 | |||
349 | void tst_QBarCategoriesAxis::insert_data() |
|
353 | void tst_QBarCategoriesAxis::insert_data() | |
350 | { |
|
354 | { | |
351 | QTest::addColumn<QStringList>("categories"); |
|
355 | QTest::addColumn<QStringList>("categories"); | |
352 | QTest::addColumn<int>("index"); |
|
356 | QTest::addColumn<int>("index"); | |
353 | QTest::addColumn<QString>("category"); |
|
357 | QTest::addColumn<QString>("category"); | |
354 | QTest::newRow("Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jun"; |
|
358 | QTest::newRow("Jul Aug Sep 0 Jun") << (QStringList() << "Jul" << "Aug" << "Sep") << 0 << "Jun"; | |
355 | QTest::newRow("Jul Aug Sep 3 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3 << "Sep"; |
|
359 | QTest::newRow("Jul Aug Sep 3 Sep") << (QStringList() << "Jul" << "Aug" << "Sep") << 3 << "Sep"; | |
356 | QTest::newRow("Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer"; |
|
360 | QTest::newRow("Jul Aug Sep 2 Summer") << (QStringList() << "Jul" << "Aug" << "Sep") << 2 << "Summer"; | |
357 | } |
|
361 | } | |
358 |
|
362 | |||
359 | void tst_QBarCategoriesAxis::insert() |
|
363 | void tst_QBarCategoriesAxis::insert() | |
360 | { |
|
364 | { | |
361 | QFETCH(QStringList, categories); |
|
365 | QFETCH(QStringList, categories); | |
362 | QFETCH(int, index); |
|
366 | QFETCH(int, index); | |
363 | QFETCH(QString, category); |
|
367 | QFETCH(QString, category); | |
364 |
|
368 | |||
365 | QBarCategoriesAxis axis; |
|
369 | QBarCategoriesAxis axis; | |
366 | axis.append(categories); |
|
370 | axis.append(categories); | |
367 |
|
371 | |||
368 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
372 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); | |
369 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
373 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); | |
370 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
374 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); | |
371 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
375 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
372 |
|
376 | |||
373 | axis.insert(index, category); |
|
377 | axis.insert(index, category); | |
374 | QCOMPARE(axis.at(index),category); |
|
378 | QCOMPARE(axis.at(index),category); | |
375 |
|
379 | |||
376 | QCOMPARE(spy0.count(), 1); |
|
380 | QCOMPARE(spy0.count(), 1); | |
377 | QCOMPARE(spy1.count(), 0); |
|
381 | QCOMPARE(spy1.count(), 0); | |
378 | QCOMPARE(spy2.count(), 0); |
|
382 | QCOMPARE(spy2.count(), 0); | |
379 | QCOMPARE(spy3.count(), 0); |
|
383 | QCOMPARE(spy3.count(), 0); | |
380 |
|
384 | |||
381 | m_chart->setAxisX(&axis, m_series); |
|
385 | m_chart->setAxisX(&axis, m_series); | |
382 | m_view->show(); |
|
386 | m_view->show(); | |
383 | QTest::qWaitForWindowShown(m_view); |
|
387 | QTest::qWaitForWindowShown(m_view); | |
384 | } |
|
388 | } | |
385 |
|
389 | |||
386 | void tst_QBarCategoriesAxis::remove_data() |
|
390 | void tst_QBarCategoriesAxis::remove_data() | |
387 | { |
|
391 | { | |
388 | QTest::addColumn<QStringList>("categories"); |
|
392 | QTest::addColumn<QStringList>("categories"); | |
389 | QTest::addColumn<QString>("category"); |
|
393 | QTest::addColumn<QString>("category"); | |
390 | QTest::addColumn<QStringList>("result"); |
|
394 | QTest::addColumn<QStringList>("result"); | |
391 | QTest::newRow("Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep"); |
|
395 | QTest::newRow("Jul Aug Sep 0") << (QStringList() << "Jul" << "Aug" << "Sep") << "Jul" << (QStringList() << "Aug" << "Sep"); | |
392 | QTest::newRow("Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep"); |
|
396 | QTest::newRow("Jul Aug Sep 1") << (QStringList() << "Jul" << "Aug" << "Sep") << "Aug"<< (QStringList() << "Jul" << "Sep"); | |
393 | } |
|
397 | } | |
394 |
|
398 | |||
395 | void tst_QBarCategoriesAxis::remove() |
|
399 | void tst_QBarCategoriesAxis::remove() | |
396 | { |
|
400 | { | |
397 | QFETCH(QStringList, categories); |
|
401 | QFETCH(QStringList, categories); | |
398 | QFETCH(QString, category); |
|
402 | QFETCH(QString, category); | |
399 | QFETCH(QStringList, result); |
|
403 | QFETCH(QStringList, result); | |
400 |
|
404 | |||
401 | QBarCategoriesAxis axis; |
|
405 | QBarCategoriesAxis axis; | |
402 | axis.append(categories); |
|
406 | axis.append(categories); | |
403 |
|
407 | |||
404 | int maxCount = axis.max() == category; |
|
408 | int maxCount = axis.max() == category; | |
405 | int minCount = axis.min() == category; |
|
409 | int minCount = axis.min() == category; | |
406 | int rangeCount = maxCount + minCount; |
|
410 | int rangeCount = maxCount + minCount; | |
407 |
|
411 | |||
408 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); |
|
412 | QSignalSpy spy0(&axis, SIGNAL(categoriesChanged())); | |
409 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); |
|
413 | QSignalSpy spy1(&axis, SIGNAL(maxChanged(QString const&))); | |
410 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); |
|
414 | QSignalSpy spy2(&axis, SIGNAL(minChanged(QString const&))); | |
411 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
415 | QSignalSpy spy3(&axis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
412 |
|
416 | |||
413 | axis.remove(category); |
|
417 | axis.remove(category); | |
414 | QCOMPARE(axis.categories(),result); |
|
418 | QCOMPARE(axis.categories(),result); | |
415 |
|
419 | |||
416 | QCOMPARE(spy0.count(), 1); |
|
420 | QCOMPARE(spy0.count(), 1); | |
417 | QCOMPARE(spy1.count(), maxCount); |
|
421 | QCOMPARE(spy1.count(), maxCount); | |
418 | QCOMPARE(spy2.count(), minCount); |
|
422 | QCOMPARE(spy2.count(), minCount); | |
419 | QCOMPARE(spy3.count(), rangeCount); |
|
423 | QCOMPARE(spy3.count(), rangeCount); | |
420 | } |
|
424 | } | |
421 |
|
425 | |||
422 | void tst_QBarCategoriesAxis::max_raw_data() |
|
426 | void tst_QBarCategoriesAxis::max_raw_data() | |
423 | { |
|
427 | { | |
424 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
428 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
425 | QTest::addColumn<QString>("max"); |
|
429 | QTest::addColumn<QString>("max"); | |
426 | QTest::newRow("Feb") << "Feb"; |
|
430 | QTest::newRow("Feb") << "Feb"; | |
427 | QTest::newRow("Apr") << "Apr"; |
|
431 | QTest::newRow("Apr") << "Apr"; | |
428 | QTest::newRow("May") << "May"; |
|
432 | QTest::newRow("May") << "May"; | |
429 | } |
|
433 | } | |
430 |
|
434 | |||
431 | void tst_QBarCategoriesAxis::max_raw() |
|
435 | void tst_QBarCategoriesAxis::max_raw() | |
432 | { |
|
436 | { | |
433 | QFETCH(QString, max); |
|
437 | QFETCH(QString, max); | |
434 |
|
438 | |||
435 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
439 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); | |
436 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); |
|
440 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); | |
437 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); |
|
441 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); | |
438 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
442 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
439 |
|
443 | |||
440 | m_baraxis->setMax(max); |
|
444 | m_baraxis->setMax(max); | |
441 | QCOMPARE(m_baraxis->max(), max); |
|
445 | QCOMPARE(m_baraxis->max(), max); | |
442 |
|
446 | |||
443 | QCOMPARE(spy0.count(), 0); |
|
447 | QCOMPARE(spy0.count(), 0); | |
444 | QCOMPARE(spy1.count(), 1); |
|
448 | QCOMPARE(spy1.count(), 1); | |
445 | QCOMPARE(spy2.count(), 0); |
|
449 | QCOMPARE(spy2.count(), 0); | |
446 | QCOMPARE(spy3.count(), 1); |
|
450 | QCOMPARE(spy3.count(), 1); | |
447 | } |
|
451 | } | |
448 |
|
452 | |||
449 | void tst_QBarCategoriesAxis::max_data() |
|
453 | void tst_QBarCategoriesAxis::max_data() | |
450 | { |
|
454 | { | |
451 | max_raw_data(); |
|
455 | max_raw_data(); | |
452 | } |
|
456 | } | |
453 |
|
457 | |||
454 | void tst_QBarCategoriesAxis::max() |
|
458 | void tst_QBarCategoriesAxis::max() | |
455 | { |
|
459 | { | |
456 | m_chart->setAxisX(m_baraxis, m_series); |
|
460 | m_chart->setAxisX(m_baraxis, m_series); | |
457 | m_view->show(); |
|
461 | m_view->show(); | |
458 | QTest::qWaitForWindowShown(m_view); |
|
462 | QTest::qWaitForWindowShown(m_view); | |
459 | max_raw(); |
|
463 | max_raw(); | |
460 | } |
|
464 | } | |
461 |
|
465 | |||
462 | void tst_QBarCategoriesAxis::max_animation_data() |
|
466 | void tst_QBarCategoriesAxis::max_animation_data() | |
463 | { |
|
467 | { | |
464 | max_data(); |
|
468 | max_data(); | |
465 | } |
|
469 | } | |
466 |
|
470 | |||
467 | void tst_QBarCategoriesAxis::max_animation() |
|
471 | void tst_QBarCategoriesAxis::max_animation() | |
468 | { |
|
472 | { | |
469 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
473 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
470 | max(); |
|
474 | max(); | |
471 | } |
|
475 | } | |
472 |
|
476 | |||
473 | void tst_QBarCategoriesAxis::min_raw_data() |
|
477 | void tst_QBarCategoriesAxis::min_raw_data() | |
474 | { |
|
478 | { | |
475 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
479 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
476 | QTest::addColumn<QString>("min"); |
|
480 | QTest::addColumn<QString>("min"); | |
477 | QTest::newRow("Feb") << "Feb"; |
|
481 | QTest::newRow("Feb") << "Feb"; | |
478 | QTest::newRow("Apr") << "Apr"; |
|
482 | QTest::newRow("Apr") << "Apr"; | |
479 | QTest::newRow("May") << "May"; |
|
483 | QTest::newRow("May") << "May"; | |
480 | } |
|
484 | } | |
481 |
|
485 | |||
482 | void tst_QBarCategoriesAxis::min_raw() |
|
486 | void tst_QBarCategoriesAxis::min_raw() | |
483 | { |
|
487 | { | |
484 | QFETCH(QString, min); |
|
488 | QFETCH(QString, min); | |
485 |
|
489 | |||
486 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
490 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); | |
487 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); |
|
491 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); | |
488 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); |
|
492 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); | |
489 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
493 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
490 |
|
494 | |||
491 | m_baraxis->setMin(min); |
|
495 | m_baraxis->setMin(min); | |
492 | QCOMPARE(m_baraxis->min(), min); |
|
496 | QCOMPARE(m_baraxis->min(), min); | |
493 |
|
497 | |||
494 | QCOMPARE(spy0.count(), 0); |
|
498 | QCOMPARE(spy0.count(), 0); | |
495 | QCOMPARE(spy1.count(), 0); |
|
499 | QCOMPARE(spy1.count(), 0); | |
496 | QCOMPARE(spy2.count(), 1); |
|
500 | QCOMPARE(spy2.count(), 1); | |
497 | QCOMPARE(spy3.count(), 1); |
|
501 | QCOMPARE(spy3.count(), 1); | |
498 |
|
502 | |||
499 | } |
|
503 | } | |
500 |
|
504 | |||
501 | void tst_QBarCategoriesAxis::min_data() |
|
505 | void tst_QBarCategoriesAxis::min_data() | |
502 | { |
|
506 | { | |
503 | min_raw_data(); |
|
507 | min_raw_data(); | |
504 | } |
|
508 | } | |
505 |
|
509 | |||
506 | void tst_QBarCategoriesAxis::min() |
|
510 | void tst_QBarCategoriesAxis::min() | |
507 | { |
|
511 | { | |
508 | m_chart->setAxisX(m_baraxis, m_series); |
|
512 | m_chart->setAxisX(m_baraxis, m_series); | |
509 | m_view->show(); |
|
513 | m_view->show(); | |
510 | QTest::qWaitForWindowShown(m_view); |
|
514 | QTest::qWaitForWindowShown(m_view); | |
511 | min_raw(); |
|
515 | min_raw(); | |
512 | } |
|
516 | } | |
513 |
|
517 | |||
514 | void tst_QBarCategoriesAxis::min_animation_data() |
|
518 | void tst_QBarCategoriesAxis::min_animation_data() | |
515 | { |
|
519 | { | |
516 | min_data(); |
|
520 | min_data(); | |
517 | } |
|
521 | } | |
518 |
|
522 | |||
519 | void tst_QBarCategoriesAxis::min_animation() |
|
523 | void tst_QBarCategoriesAxis::min_animation() | |
520 | { |
|
524 | { | |
521 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
525 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
522 | min(); |
|
526 | min(); | |
523 | } |
|
527 | } | |
524 |
|
528 | |||
525 |
|
529 | |||
526 | void tst_QBarCategoriesAxis::range_raw_data() |
|
530 | void tst_QBarCategoriesAxis::range_raw_data() | |
527 | { |
|
531 | { | |
528 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
532 | //"Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
529 | QTest::addColumn<QString>("min"); |
|
533 | QTest::addColumn<QString>("min"); | |
530 | QTest::addColumn<QString>("max"); |
|
534 | QTest::addColumn<QString>("max"); | |
531 | QTest::newRow("Feb - Apr") << "Feb" << "Apr"; |
|
535 | QTest::newRow("Feb - Apr") << "Feb" << "Apr"; | |
532 | QTest::newRow("Feb - May") << "Feb" << "May"; |
|
536 | QTest::newRow("Feb - May") << "Feb" << "May"; | |
533 | QTest::newRow("Mar - Apr") << "Mar" << "Apr"; |
|
537 | QTest::newRow("Mar - Apr") << "Mar" << "Apr"; | |
534 | } |
|
538 | } | |
535 |
|
539 | |||
536 | void tst_QBarCategoriesAxis::range_raw() |
|
540 | void tst_QBarCategoriesAxis::range_raw() | |
537 | { |
|
541 | { | |
538 | QFETCH(QString, min); |
|
542 | QFETCH(QString, min); | |
539 | QFETCH(QString, max); |
|
543 | QFETCH(QString, max); | |
540 |
|
544 | |||
541 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); |
|
545 | QSignalSpy spy0(m_baraxis, SIGNAL(categoriesChanged())); | |
542 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); |
|
546 | QSignalSpy spy1(m_baraxis, SIGNAL(maxChanged(QString const&))); | |
543 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); |
|
547 | QSignalSpy spy2(m_baraxis, SIGNAL(minChanged(QString const&))); | |
544 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); |
|
548 | QSignalSpy spy3(m_baraxis, SIGNAL(rangeChanged(QString const&, QString const&))); | |
545 |
|
549 | |||
546 | m_baraxis->setRange(min, max); |
|
550 | m_baraxis->setRange(min, max); | |
547 | QCOMPARE(m_baraxis->min(), min); |
|
551 | QCOMPARE(m_baraxis->min(), min); | |
548 | QCOMPARE(m_baraxis->max(), max); |
|
552 | QCOMPARE(m_baraxis->max(), max); | |
549 |
|
553 | |||
550 | QCOMPARE(spy0.count(), 0); |
|
554 | QCOMPARE(spy0.count(), 0); | |
551 | QCOMPARE(spy1.count(), 1); |
|
555 | QCOMPARE(spy1.count(), 1); | |
552 | QCOMPARE(spy2.count(), 1); |
|
556 | QCOMPARE(spy2.count(), 1); | |
553 | QCOMPARE(spy3.count(), 1); |
|
557 | QCOMPARE(spy3.count(), 1); | |
554 | } |
|
558 | } | |
555 |
|
559 | |||
556 | void tst_QBarCategoriesAxis::range_data() |
|
560 | void tst_QBarCategoriesAxis::range_data() | |
557 | { |
|
561 | { | |
558 | range_raw_data(); |
|
562 | range_raw_data(); | |
559 | } |
|
563 | } | |
560 |
|
564 | |||
561 | void tst_QBarCategoriesAxis::range() |
|
565 | void tst_QBarCategoriesAxis::range() | |
562 | { |
|
566 | { | |
563 | m_chart->setAxisX(m_baraxis, m_series); |
|
567 | m_chart->setAxisX(m_baraxis, m_series); | |
564 | m_view->show(); |
|
568 | m_view->show(); | |
565 | QTest::qWaitForWindowShown(m_view); |
|
569 | QTest::qWaitForWindowShown(m_view); | |
566 | range_raw(); |
|
570 | range_raw(); | |
567 | } |
|
571 | } | |
568 |
|
572 | |||
569 | void tst_QBarCategoriesAxis::range_animation_data() |
|
573 | void tst_QBarCategoriesAxis::range_animation_data() | |
570 | { |
|
574 | { | |
571 | range_data(); |
|
575 | range_data(); | |
572 | } |
|
576 | } | |
573 |
|
577 | |||
574 | void tst_QBarCategoriesAxis::range_animation() |
|
578 | void tst_QBarCategoriesAxis::range_animation() | |
575 | { |
|
579 | { | |
576 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); |
|
580 | m_chart->setAnimationOptions(QChart::GridAxisAnimations); | |
577 | range(); |
|
581 | range(); | |
578 | } |
|
582 | } | |
579 |
|
583 | |||
|
584 | ||||
|
585 | void tst_QBarCategoriesAxis::noautoscale_data() | |||
|
586 | { | |||
|
587 | QTest::addColumn<QString>("min"); | |||
|
588 | QTest::addColumn<QString>("max"); | |||
|
589 | QTest::newRow("Feb - Mar") << "Feb" << "Mar"; | |||
|
590 | QTest::newRow("Feb - May") << "Feb" << "May"; | |||
|
591 | QTest::newRow("Apr - May") << "Apr" << "May"; | |||
|
592 | } | |||
|
593 | ||||
|
594 | void tst_QBarCategoriesAxis::noautoscale() | |||
|
595 | { | |||
|
596 | QFETCH(QString, min); | |||
|
597 | QFETCH(QString, max); | |||
|
598 | ||||
|
599 | QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString))); | |||
|
600 | QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString))); | |||
|
601 | QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString))); | |||
|
602 | ||||
|
603 | m_baraxis->setRange(min, max); | |||
|
604 | QCOMPARE(m_baraxis->min(),min); | |||
|
605 | QCOMPARE(m_baraxis->max(),max); | |||
|
606 | ||||
|
607 | QCOMPARE(spy0.count(), 1); | |||
|
608 | QCOMPARE(spy1.count(), 1); | |||
|
609 | QCOMPARE(spy2.count(), 1); | |||
|
610 | ||||
|
611 | m_chart->setAxisX(m_baraxis, m_series); | |||
|
612 | m_view->show(); | |||
|
613 | QTest::qWaitForWindowShown(m_view); | |||
|
614 | QCOMPARE(m_baraxis->min(),min); | |||
|
615 | QCOMPARE(m_baraxis->max(),max); | |||
|
616 | } | |||
|
617 | ||||
|
618 | void tst_QBarCategoriesAxis::autoscale_data() | |||
|
619 | { | |||
|
620 | ||||
|
621 | } | |||
|
622 | ||||
|
623 | void tst_QBarCategoriesAxis::autoscale() | |||
|
624 | { | |||
|
625 | delete m_baraxis; | |||
|
626 | m_baraxis = new QBarCategoriesAxis(); | |||
|
627 | ||||
|
628 | QSignalSpy spy0(m_baraxis, SIGNAL(maxChanged(QString))); | |||
|
629 | QSignalSpy spy1(m_baraxis, SIGNAL(minChanged(QString))); | |||
|
630 | QSignalSpy spy2(m_baraxis, SIGNAL(rangeChanged(QString, QString))); | |||
|
631 | ||||
|
632 | QCOMPARE(m_baraxis->min(),QString()); | |||
|
633 | QCOMPARE(m_baraxis->max(),QString()); | |||
|
634 | m_chart->setAxisX(m_baraxis, m_series); | |||
|
635 | ||||
|
636 | QCOMPARE(spy0.count(), 1); | |||
|
637 | QCOMPARE(spy1.count(), 1); | |||
|
638 | QCOMPARE(spy2.count(), 1); | |||
|
639 | ||||
|
640 | m_view->show(); | |||
|
641 | QTest::qWaitForWindowShown(m_view); | |||
|
642 | QCOMPARE(m_baraxis->min(),QString("1")); | |||
|
643 | QCOMPARE(m_baraxis->max(),QString("6")); | |||
|
644 | } | |||
|
645 | ||||
|
646 | ||||
580 | QTEST_MAIN(tst_QBarCategoriesAxis) |
|
647 | QTEST_MAIN(tst_QBarCategoriesAxis) | |
581 | #include "tst_qbarcategoriesaxis.moc" |
|
648 | #include "tst_qbarcategoriesaxis.moc" | |
582 |
|
649 |
General Comments 0
You need to be logged in to leave comments.
Login now