@@ -1,364 +1,367 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarcategoriesaxis.h" |
|
22 | 22 | #include "qbarcategoriesaxis_p.h" |
|
23 | 23 | #include "chartcategoriesaxisx_p.h" |
|
24 | 24 | #include "chartcategoriesaxisy_p.h" |
|
25 | 25 | #include <qmath.h> |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | /*! |
|
30 | 30 | \class QBarCategoriesAxis |
|
31 | 31 | \brief The QBarCategoriesAxis class is used for manipulating chart's axis. |
|
32 | 32 | \mainclass |
|
33 | 33 | |
|
34 | 34 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | 35 | */ |
|
36 | 36 | |
|
37 | 37 | /*! |
|
38 | 38 | \qmlclass Axis QBarCategoriesAxis |
|
39 | 39 | \brief The Axis element is used for manipulating chart's axes. |
|
40 | 40 | |
|
41 | 41 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
42 | 42 | |
|
43 | 43 | To access Axes you can use ChartView API. For example: |
|
44 | 44 | \code |
|
45 | 45 | ChartView { |
|
46 | 46 | axisX.min: "Feb" |
|
47 | 47 | axisX.max: "Jun" |
|
48 | 48 | // Add a few series... |
|
49 | 49 | } |
|
50 | 50 | \endcode |
|
51 | 51 | */ |
|
52 | 52 | |
|
53 | 53 | /*! |
|
54 | 54 | \property QBarCategoriesAxis::categories |
|
55 | 55 | Defines the categories of axis |
|
56 | 56 | */ |
|
57 | 57 | /*! |
|
58 | 58 | \qmlproperty QStringList Axis::categories |
|
59 | 59 | Defines the categories of axis |
|
60 | 60 | */ |
|
61 | 61 | |
|
62 | 62 | /*! |
|
63 | 63 | \property QBarCategoriesAxis::min |
|
64 | 64 | Defines the minimum value on the axis. |
|
65 | 65 | */ |
|
66 | 66 | /*! |
|
67 | 67 | \qmlproperty real Axis::min |
|
68 | 68 | Defines the minimum value on the axis. |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \property QBarCategoriesAxis::max |
|
73 | 73 | Defines the maximum value on the axis. |
|
74 | 74 | */ |
|
75 | 75 | /*! |
|
76 | 76 | \qmlproperty real Axis::max |
|
77 | 77 | Defines the maximum value on the axis. |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \fn void QBarCategoriesAxis::minChanged(const QString &min) |
|
82 | 82 | Axis emits signal when \a min of axis has changed. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \fn void QBarCategoriesAxis::maxChanged(const QString &max) |
|
87 | 87 | Axis emits signal when \a max of axis has changed. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max) |
|
92 | 92 | Axis emits signal when \a min or \a max of axis has changed. |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | /*! | |
|
96 | Constructs an axis object which is a child of \a parent. | |
|
97 | */ | |
|
95 | 98 | QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent): |
|
96 | 99 | QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent) |
|
97 | 100 | { |
|
98 | 101 | } |
|
99 | 102 | |
|
100 | 103 | QBarCategoriesAxis::~QBarCategoriesAxis() |
|
101 | 104 | { |
|
102 | 105 | } |
|
103 | 106 | |
|
104 | 107 | QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent) |
|
105 | 108 | { |
|
106 | 109 | |
|
107 | 110 | } |
|
108 | 111 | |
|
109 | 112 | /*! |
|
110 | 113 | Appends \a categories to axis |
|
111 | 114 | */ |
|
112 | 115 | void QBarCategoriesAxis::append(const QStringList &categories) |
|
113 | 116 | { |
|
114 | 117 | Q_D(QBarCategoriesAxis); |
|
115 | 118 | if (d->m_categories.isEmpty()) { |
|
116 | 119 | d->m_categories.append(categories); |
|
117 | 120 | setRange(categories.first(),categories.last()); |
|
118 | 121 | }else{ |
|
119 | 122 | d->m_categories.append(categories); |
|
120 | 123 | } |
|
121 | 124 | |
|
122 | 125 | emit categoriesChanged(); |
|
123 | 126 | } |
|
124 | 127 | |
|
125 | 128 | /*! |
|
126 | 129 | Appends \a category to axis |
|
127 | 130 | */ |
|
128 | 131 | void QBarCategoriesAxis::append(const QString &category) |
|
129 | 132 | { |
|
130 | 133 | Q_D(QBarCategoriesAxis); |
|
131 | 134 | if (d->m_categories.isEmpty()) { |
|
132 | 135 | d->m_categories.append(category); |
|
133 | 136 | setRange(category,category); |
|
134 | 137 | }else{ |
|
135 | 138 | d->m_categories.append(category); |
|
136 | 139 | } |
|
137 | 140 | emit categoriesChanged(); |
|
138 | 141 | } |
|
139 | 142 | |
|
140 | 143 | /*! |
|
141 | 144 | Removes \a category from axis |
|
142 | 145 | */ |
|
143 | 146 | void QBarCategoriesAxis::remove(const QString &category) |
|
144 | 147 | { |
|
145 | 148 | Q_D(QBarCategoriesAxis); |
|
146 | 149 | if (d->m_categories.contains(category)) { |
|
147 | 150 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
148 | 151 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
149 | 152 | emit categoriesChanged(); |
|
150 | 153 | } |
|
151 | 154 | } |
|
152 | 155 | |
|
153 | 156 | /*! |
|
154 | 157 | Inserts \a category to axis at \a index |
|
155 | 158 | */ |
|
156 | 159 | void QBarCategoriesAxis::insert(int index, const QString &category) |
|
157 | 160 | { |
|
158 | 161 | Q_D(QBarCategoriesAxis); |
|
159 | 162 | if (d->m_categories.isEmpty()) { |
|
160 | 163 | d->m_categories.insert(index,category); |
|
161 | 164 | setRange(category,category); |
|
162 | 165 | }else{ |
|
163 | 166 | |
|
164 | 167 | } |
|
165 | 168 | emit categoriesChanged(); |
|
166 | 169 | } |
|
167 | 170 | |
|
168 | 171 | /*! |
|
169 | 172 | Removes all categories. |
|
170 | 173 | */ |
|
171 | 174 | void QBarCategoriesAxis::clear() |
|
172 | 175 | { |
|
173 | 176 | Q_D(QBarCategoriesAxis); |
|
174 | 177 | d->m_categories.clear(); |
|
175 | 178 | setRange(QString::null,QString::null); |
|
176 | 179 | emit categoriesChanged(); |
|
177 | 180 | } |
|
178 | 181 | |
|
179 | 182 | void QBarCategoriesAxis::setCategories(const QStringList &categories) |
|
180 | 183 | { |
|
181 | 184 | Q_D(QBarCategoriesAxis); |
|
182 | 185 | if(d->m_categories!=categories){ |
|
183 | 186 | d->m_categories = categories; |
|
184 | 187 | setRange(categories.first(),categories.last()); |
|
185 | 188 | emit categoriesChanged(); |
|
186 | 189 | } |
|
187 | 190 | } |
|
188 | 191 | |
|
189 | 192 | QStringList QBarCategoriesAxis::categories() |
|
190 | 193 | { |
|
191 | 194 | Q_D(QBarCategoriesAxis); |
|
192 | 195 | return d->m_categories; |
|
193 | 196 | } |
|
194 | 197 | |
|
195 | 198 | /*! |
|
196 | 199 | Returns number of categories. |
|
197 | 200 | */ |
|
198 | 201 | int QBarCategoriesAxis::count() const |
|
199 | 202 | { |
|
200 | 203 | Q_D(const QBarCategoriesAxis); |
|
201 | 204 | return d->m_categories.count(); |
|
202 | 205 | } |
|
203 | 206 | |
|
204 | 207 | /*! |
|
205 | 208 | Returns category at \a index. Index must be valid. |
|
206 | 209 | */ |
|
207 | 210 | QString QBarCategoriesAxis::at(int index) const |
|
208 | 211 | { |
|
209 | 212 | Q_D(const QBarCategoriesAxis); |
|
210 | 213 | return d->m_categories.at(index); |
|
211 | 214 | } |
|
212 | 215 | |
|
213 | 216 | /*! |
|
214 | 217 | Sets minimum category to \a min. |
|
215 | 218 | */ |
|
216 | 219 | void QBarCategoriesAxis::setMin(const QString& min) |
|
217 | 220 | { |
|
218 | 221 | Q_D(QBarCategoriesAxis); |
|
219 | 222 | setRange(min,d->m_maxCategory); |
|
220 | 223 | } |
|
221 | 224 | |
|
222 | 225 | /*! |
|
223 | 226 | Returns minimum category. |
|
224 | 227 | */ |
|
225 | 228 | QString QBarCategoriesAxis::min() const |
|
226 | 229 | { |
|
227 | 230 | Q_D(const QBarCategoriesAxis); |
|
228 | 231 | return d->m_minCategory; |
|
229 | 232 | } |
|
230 | 233 | |
|
231 | 234 | /*! |
|
232 | 235 | Sets maximum category to \a max. |
|
233 | 236 | */ |
|
234 | 237 | void QBarCategoriesAxis::setMax(const QString& max) |
|
235 | 238 | { |
|
236 | 239 | Q_D(QBarCategoriesAxis); |
|
237 | 240 | setRange(d->m_minCategory,max); |
|
238 | 241 | } |
|
239 | 242 | |
|
240 | 243 | /*! |
|
241 | 244 | Returns maximum category |
|
242 | 245 | */ |
|
243 | 246 | QString QBarCategoriesAxis::max() const |
|
244 | 247 | { |
|
245 | 248 | Q_D(const QBarCategoriesAxis); |
|
246 | 249 | return d->m_maxCategory; |
|
247 | 250 | } |
|
248 | 251 | |
|
249 | 252 | /*! |
|
250 | 253 | Sets range from \a minCategory to \a maxCategory |
|
251 | 254 | */ |
|
252 | 255 | void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory) |
|
253 | 256 | { |
|
254 | 257 | Q_D(QBarCategoriesAxis); |
|
255 | 258 | |
|
256 | 259 | int minIndex = d->m_categories.indexOf(minCategory); |
|
257 | 260 | if (minIndex == -1) { |
|
258 | 261 | return; |
|
259 | 262 | } |
|
260 | 263 | int maxIndex = d->m_categories.indexOf(maxCategory); |
|
261 | 264 | if (maxIndex == -1) { |
|
262 | 265 | return; |
|
263 | 266 | } |
|
264 | 267 | |
|
265 | 268 | if (maxIndex <= minIndex) { |
|
266 | 269 | // max must be greater than min |
|
267 | 270 | return; |
|
268 | 271 | } |
|
269 | 272 | |
|
270 | 273 | bool changed = false; |
|
271 | 274 | if (!qFuzzyIsNull(d->m_min - (minIndex))) { |
|
272 | 275 | d->m_minCategory = minCategory; |
|
273 | 276 | d->m_min = minIndex; |
|
274 | 277 | emit minChanged(minCategory); |
|
275 | 278 | changed = true; |
|
276 | 279 | } |
|
277 | 280 | |
|
278 | 281 | if (!qFuzzyIsNull(d->m_max - (maxIndex))) { |
|
279 | 282 | d->m_max = maxIndex; |
|
280 | 283 | d->m_maxCategory = maxCategory; |
|
281 | 284 | emit maxChanged(maxCategory); |
|
282 | 285 | changed = true; |
|
283 | 286 | } |
|
284 | 287 | |
|
285 | 288 | if ((changed)) { |
|
286 | 289 | d->emitRange(); |
|
287 | 290 | emit categoriesChanged(); |
|
288 | 291 | } |
|
289 | 292 | } |
|
290 | 293 | |
|
291 | 294 | /*! |
|
292 | 295 | Returns the type of axis. |
|
293 | 296 | */ |
|
294 | 297 | QAbstractAxis::AxisType QBarCategoriesAxis::type() const |
|
295 | 298 | { |
|
296 | 299 | return AxisTypeCategories; |
|
297 | 300 | } |
|
298 | 301 | |
|
299 | 302 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
300 | 303 | |
|
301 | 304 | QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q): |
|
302 | 305 | QAbstractAxisPrivate(q) |
|
303 | 306 | { |
|
304 | 307 | |
|
305 | 308 | } |
|
306 | 309 | |
|
307 | 310 | QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate() |
|
308 | 311 | { |
|
309 | 312 | |
|
310 | 313 | } |
|
311 | 314 | |
|
312 | 315 | void QBarCategoriesAxisPrivate::setMin(const QVariant &min) |
|
313 | 316 | { |
|
314 | 317 | setRange(min,m_maxCategory); |
|
315 | 318 | } |
|
316 | 319 | |
|
317 | 320 | void QBarCategoriesAxisPrivate::setMax(const QVariant &max) |
|
318 | 321 | { |
|
319 | 322 | setRange(m_minCategory,max); |
|
320 | 323 | } |
|
321 | 324 | |
|
322 | 325 | void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
323 | 326 | { |
|
324 | 327 | Q_Q(QBarCategoriesAxis); |
|
325 | 328 | QString value1 = min.toString(); |
|
326 | 329 | QString value2 = max.toString(); |
|
327 | 330 | q->setRange(value1,value2); |
|
328 | 331 | } |
|
329 | 332 | |
|
330 | 333 | int QBarCategoriesAxisPrivate::ticksCount() const |
|
331 | 334 | { |
|
332 | 335 | return m_categories.count()+1; |
|
333 | 336 | } |
|
334 | 337 | |
|
335 | 338 | void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
336 | 339 | { |
|
337 | 340 | m_min = min; |
|
338 | 341 | m_max = max; |
|
339 | 342 | m_ticksCount = count; |
|
340 | 343 | } |
|
341 | 344 | |
|
342 | 345 | ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
343 | 346 | { |
|
344 | 347 | Q_Q( QBarCategoriesAxis); |
|
345 | 348 | if(m_orientation == Qt::Vertical){ |
|
346 | 349 | return new ChartCategoriesAxisY(q,presenter); |
|
347 | 350 | }else{ |
|
348 | 351 | return new ChartCategoriesAxisX(q,presenter); |
|
349 | 352 | } |
|
350 | 353 | } |
|
351 | 354 | |
|
352 | 355 | void QBarCategoriesAxisPrivate::emitRange() |
|
353 | 356 | { |
|
354 | 357 | Q_Q( QBarCategoriesAxis); |
|
355 | 358 | if(!q->signalsBlocked()) { |
|
356 | 359 | emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false); |
|
357 | 360 | } |
|
358 | 361 | } |
|
359 | 362 | |
|
360 | 363 | |
|
361 | 364 | #include "moc_qbarcategoriesaxis.cpp" |
|
362 | 365 | #include "moc_qbarcategoriesaxis_p.cpp" |
|
363 | 366 | |
|
364 | 367 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,169 +1,171 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qintervalaxis.h" |
|
22 | 22 | #include "qintervalaxis_p.h" |
|
23 | 23 | #include "chartcategoriesaxisx_p.h" |
|
24 | 24 | #include "chartcategoriesaxisy_p.h" |
|
25 | 25 | #include <qmath.h> |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | /*! |
|
30 | 30 | \class QIntervalAxis |
|
31 | 31 | \brief The QIntervalAxis class is used for manipulating chart's axis. |
|
32 | 32 | \mainclass |
|
33 | 33 | |
|
34 | 34 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | 35 | */ |
|
36 | 36 | |
|
37 | 37 | /*! |
|
38 | 38 | \qmlclass Axis QIntervalAxis |
|
39 | 39 | \brief The Axis element is used for manipulating chart's axes. |
|
40 | 40 | |
|
41 | 41 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
42 | 42 | |
|
43 | 43 | To access Axes you can use ChartView API. For example: |
|
44 | 44 | \code |
|
45 | 45 | // TODO :) |
|
46 | 46 | \endcode |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | ||
|
49 | /*! | |
|
50 | Constructs an axis object which is a child of \a parent. | |
|
51 | */ | |
|
50 | 52 | QIntervalAxis::QIntervalAxis(QObject *parent): |
|
51 | 53 | QValuesAxis(*new QIntervalAxisPrivate(this),parent) |
|
52 | 54 | { |
|
53 | 55 | } |
|
54 | 56 | |
|
55 | 57 | QIntervalAxis::~QIntervalAxis() |
|
56 | 58 | { |
|
57 | 59 | } |
|
58 | 60 | |
|
59 | 61 | QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent) |
|
60 | 62 | { |
|
61 | 63 | |
|
62 | 64 | } |
|
63 | 65 | |
|
64 | 66 | /*! |
|
65 | 67 | Appends \a categories to axis |
|
66 | 68 | */ |
|
67 | 69 | void QIntervalAxis::append(const QString& category, qreal x) |
|
68 | 70 | { |
|
69 | 71 | Q_D(QIntervalAxis); |
|
70 | 72 | if (!d->m_categories.contains(category)) |
|
71 | 73 | { |
|
72 | 74 | if(d->m_categories.isEmpty()){ |
|
73 | 75 | Range range(d->m_categoryMinimum,x); |
|
74 | 76 | d->m_categoriesMap.insert(category,range); |
|
75 | 77 | d->m_categories.append(category); |
|
76 | 78 | }else{ |
|
77 | 79 | Range range = d->m_categoriesMap.value(d->m_categories.last()); |
|
78 | 80 | d->m_categoriesMap.insert(category,Range(range.first,x)); |
|
79 | 81 | d->m_categories.append(category); |
|
80 | 82 | } |
|
81 | 83 | setRange(d->m_min,x); |
|
82 | 84 | } |
|
83 | 85 | } |
|
84 | 86 | |
|
85 | 87 | void QIntervalAxis::setFisrtCategoryMinimum(qreal x) |
|
86 | 88 | { |
|
87 | 89 | Q_D(QIntervalAxis); |
|
88 | 90 | if(d->m_categories.isEmpty()){ |
|
89 | 91 | d->m_categoryMinimum=x; |
|
90 | 92 | }else{ |
|
91 | 93 | Range range = d->m_categoriesMap.value(d->m_categories.first()); |
|
92 | 94 | d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second)); |
|
93 | 95 | setRange(x,d->m_min); |
|
94 | 96 | } |
|
95 | 97 | } |
|
96 | 98 | |
|
97 | 99 | /*! |
|
98 | 100 | Removes \a category from axis |
|
99 | 101 | */ |
|
100 | 102 | void QIntervalAxis::remove(const QString &category) |
|
101 | 103 | { |
|
102 | 104 | Q_UNUSED(category); |
|
103 | 105 | //TODO |
|
104 | 106 | } |
|
105 | 107 | |
|
106 | 108 | QStringList QIntervalAxis::categories() |
|
107 | 109 | { |
|
108 | 110 | Q_D(QIntervalAxis); |
|
109 | 111 | return d->m_categories; |
|
110 | 112 | } |
|
111 | 113 | |
|
112 | 114 | /*! |
|
113 | 115 | Returns number of categories. |
|
114 | 116 | */ |
|
115 | 117 | int QIntervalAxis::count() const |
|
116 | 118 | { |
|
117 | 119 | Q_D(const QIntervalAxis); |
|
118 | 120 | return d->m_categories.count(); |
|
119 | 121 | } |
|
120 | 122 | |
|
121 | 123 | /*! |
|
122 | 124 | Returns the type of axis. |
|
123 | 125 | */ |
|
124 | 126 | QAbstractAxis::AxisType QIntervalAxis::type() const |
|
125 | 127 | { |
|
126 | 128 | return AxisTypeCategories; |
|
127 | 129 | } |
|
128 | 130 | |
|
129 | 131 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
130 | 132 | |
|
131 | 133 | QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q): |
|
132 | 134 | QValuesAxisPrivate(q), |
|
133 | 135 | m_categoryMinimum(0) |
|
134 | 136 | { |
|
135 | 137 | |
|
136 | 138 | } |
|
137 | 139 | |
|
138 | 140 | QIntervalAxisPrivate::~QIntervalAxisPrivate() |
|
139 | 141 | { |
|
140 | 142 | |
|
141 | 143 | } |
|
142 | 144 | |
|
143 | 145 | int QIntervalAxisPrivate::ticksCount() const |
|
144 | 146 | { |
|
145 | 147 | return m_categories.count()+1; |
|
146 | 148 | } |
|
147 | 149 | |
|
148 | 150 | void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
149 | 151 | { |
|
150 | 152 | m_min = min; |
|
151 | 153 | m_max = max; |
|
152 | 154 | m_ticksCount = count; |
|
153 | 155 | } |
|
154 | 156 | |
|
155 | 157 | ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
156 | 158 | { |
|
157 | 159 | Q_UNUSED(presenter); |
|
158 | 160 | // Q_Q( QCategoriesAxis); |
|
159 | 161 | if(m_orientation == Qt::Vertical){ |
|
160 | 162 | return 0; |
|
161 | 163 | }else{ |
|
162 | 164 | return 0; |
|
163 | 165 | } |
|
164 | 166 | } |
|
165 | 167 | |
|
166 | 168 | #include "moc_qintervalaxis.cpp" |
|
167 | 169 | #include "moc_qintervalaxis_p.cpp" |
|
168 | 170 | |
|
169 | 171 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,290 +1,293 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qvaluesaxis.h" |
|
22 | 22 | #include "qvaluesaxis_p.h" |
|
23 | 23 | #include "chartvaluesaxisx_p.h" |
|
24 | 24 | #include "chartvaluesaxisy_p.h" |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | /*! |
|
29 | 29 | \class QValuesAxis |
|
30 | 30 | \brief The QValuesAxis class is used for manipulating chart's axis. |
|
31 | 31 | \mainclass |
|
32 | 32 | |
|
33 | 33 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
34 | 34 | */ |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \qmlclass Axis QValuesAxis |
|
38 | 38 | \brief The Axis element is used for manipulating chart's axes |
|
39 | 39 | |
|
40 | 40 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
41 | 41 | |
|
42 | 42 | To access Axes you can use ChartView API. For example: |
|
43 | 43 | \code |
|
44 | 44 | ChartView { |
|
45 | 45 | axisX.min: 0 |
|
46 | 46 | axisX.max: 3 |
|
47 | 47 | axisX.ticksCount: 4 |
|
48 | 48 | axisY.min: 0 |
|
49 | 49 | axisY.max: 4 |
|
50 | 50 | // Add a few series... |
|
51 | 51 | } |
|
52 | 52 | \endcode |
|
53 | 53 | */ |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | \property QValuesAxis::min |
|
57 | 57 | Defines the minimum value on the axis. |
|
58 | 58 | */ |
|
59 | 59 | /*! |
|
60 | 60 | \qmlproperty real Axis::min |
|
61 | 61 | Defines the minimum value on the axis. |
|
62 | 62 | */ |
|
63 | 63 | |
|
64 | 64 | /*! |
|
65 | 65 | \property QValuesAxis::max |
|
66 | 66 | Defines the maximum value on the axis. |
|
67 | 67 | */ |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty real Axis::max |
|
70 | 70 | Defines the maximum value on the axis. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \fn void QValuesAxis::minChanged(qreal min) |
|
75 | 75 | Axis emits signal when \a min of axis has changed. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \fn void QValuesAxis::maxChanged(qreal max) |
|
80 | 80 | Axis emits signal when \a max of axis has changed. |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \fn void QValuesAxis::rangeChanged(qreal min, qreal max) |
|
85 | 85 | Axis emits signal when \a min or \a max of axis has changed. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QValuesAxis::ticksCount |
|
90 | 90 | The number of tick marks for the axis. |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \qmlproperty int Axis::ticksCount |
|
95 | 95 | The number of tick marks for the axis. |
|
96 | 96 | */ |
|
97 | 97 | |
|
98 | 98 | /*! |
|
99 | 99 | \property QValuesAxis::niceNumbersEnabled |
|
100 | 100 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \qmlproperty bool Axis::niceNumbersEnabled |
|
105 | 105 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | /*! | |
|
109 | Constructs an axis object which is a child of \a parent. | |
|
110 | */ | |
|
108 | 111 | QValuesAxis::QValuesAxis(QObject *parent) : |
|
109 | 112 | QAbstractAxis(*new QValuesAxisPrivate(this),parent) |
|
110 | 113 | { |
|
111 | 114 | |
|
112 | 115 | } |
|
113 | 116 | |
|
114 | 117 | QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
115 | 118 | { |
|
116 | 119 | |
|
117 | 120 | } |
|
118 | 121 | |
|
119 | 122 | QValuesAxis::~QValuesAxis() |
|
120 | 123 | { |
|
121 | 124 | |
|
122 | 125 | } |
|
123 | 126 | |
|
124 | 127 | void QValuesAxis::setMin(qreal min) |
|
125 | 128 | { |
|
126 | 129 | Q_D(QValuesAxis); |
|
127 | 130 | setRange(min,d->m_max); |
|
128 | 131 | } |
|
129 | 132 | |
|
130 | 133 | qreal QValuesAxis::min() const |
|
131 | 134 | { |
|
132 | 135 | Q_D(const QValuesAxis); |
|
133 | 136 | return d->m_min; |
|
134 | 137 | } |
|
135 | 138 | |
|
136 | 139 | void QValuesAxis::setMax(qreal max) |
|
137 | 140 | { |
|
138 | 141 | Q_D(QValuesAxis); |
|
139 | 142 | setRange(d->m_min,max); |
|
140 | 143 | } |
|
141 | 144 | |
|
142 | 145 | qreal QValuesAxis::max() const |
|
143 | 146 | { |
|
144 | 147 | Q_D(const QValuesAxis); |
|
145 | 148 | return d->m_max; |
|
146 | 149 | } |
|
147 | 150 | |
|
148 | 151 | /*! |
|
149 | 152 | Sets range from \a min to \a max on the axis. |
|
150 | 153 | */ |
|
151 | 154 | void QValuesAxis::setRange(qreal min, qreal max) |
|
152 | 155 | { |
|
153 | 156 | Q_D(QValuesAxis); |
|
154 | 157 | bool changed = false; |
|
155 | 158 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
156 | 159 | d->m_min = min; |
|
157 | 160 | changed = true; |
|
158 | 161 | emit minChanged(min); |
|
159 | 162 | } |
|
160 | 163 | |
|
161 | 164 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
162 | 165 | d->m_max = max; |
|
163 | 166 | changed = true; |
|
164 | 167 | emit maxChanged(max); |
|
165 | 168 | } |
|
166 | 169 | |
|
167 | 170 | if (changed) { |
|
168 | 171 | d->emitRange(); |
|
169 | 172 | emit rangeChanged(d->m_min,d->m_max); |
|
170 | 173 | } |
|
171 | 174 | } |
|
172 | 175 | |
|
173 | 176 | /*! |
|
174 | 177 | Sets \a count for ticks on the axis. |
|
175 | 178 | */ |
|
176 | 179 | void QValuesAxis::setTicksCount(int count) |
|
177 | 180 | { |
|
178 | 181 | Q_D(QValuesAxis); |
|
179 | 182 | if (d->m_ticksCount != count) { |
|
180 | 183 | d->m_ticksCount = count; |
|
181 | 184 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
182 | 185 | } |
|
183 | 186 | } |
|
184 | 187 | |
|
185 | 188 | /*! |
|
186 | 189 | \fn int QValuesAxis::ticksCount() const |
|
187 | 190 | Return number of ticks on the axis |
|
188 | 191 | */ |
|
189 | 192 | int QValuesAxis::ticksCount() const |
|
190 | 193 | { |
|
191 | 194 | Q_D(const QValuesAxis); |
|
192 | 195 | return d->m_ticksCount; |
|
193 | 196 | } |
|
194 | 197 | |
|
195 | 198 | void QValuesAxis::setNiceNumbersEnabled(bool enable) |
|
196 | 199 | { |
|
197 | 200 | Q_D(QValuesAxis); |
|
198 | 201 | if (d->m_niceNumbers != enable){ |
|
199 | 202 | d->m_niceNumbers = enable; |
|
200 | 203 | emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers); |
|
201 | 204 | } |
|
202 | 205 | } |
|
203 | 206 | |
|
204 | 207 | bool QValuesAxis::niceNumbersEnabled() const |
|
205 | 208 | { |
|
206 | 209 | Q_D(const QValuesAxis); |
|
207 | 210 | return d->m_niceNumbers; |
|
208 | 211 | } |
|
209 | 212 | |
|
210 | 213 | QAbstractAxis::AxisType QValuesAxis::type() const |
|
211 | 214 | { |
|
212 | 215 | return AxisTypeValues; |
|
213 | 216 | } |
|
214 | 217 | |
|
215 | 218 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
216 | 219 | |
|
217 | 220 | QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q): |
|
218 | 221 | QAbstractAxisPrivate(q), |
|
219 | 222 | m_niceNumbers(false) |
|
220 | 223 | { |
|
221 | 224 | |
|
222 | 225 | } |
|
223 | 226 | |
|
224 | 227 | QValuesAxisPrivate::~QValuesAxisPrivate() |
|
225 | 228 | { |
|
226 | 229 | |
|
227 | 230 | } |
|
228 | 231 | |
|
229 | 232 | void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
230 | 233 | { |
|
231 | 234 | Q_Q(QValuesAxis); |
|
232 | 235 | q->setRange(min,max); |
|
233 | 236 | q->setTicksCount(count); |
|
234 | 237 | } |
|
235 | 238 | |
|
236 | 239 | |
|
237 | 240 | void QValuesAxisPrivate::setMin(const QVariant &min) |
|
238 | 241 | { |
|
239 | 242 | Q_Q(QValuesAxis); |
|
240 | 243 | bool ok; |
|
241 | 244 | qreal value = min.toReal(&ok); |
|
242 | 245 | if(ok) q->setMin(value); |
|
243 | 246 | } |
|
244 | 247 | |
|
245 | 248 | void QValuesAxisPrivate::setMax(const QVariant &max) |
|
246 | 249 | { |
|
247 | 250 | Q_Q(QValuesAxis); |
|
248 | 251 | bool ok; |
|
249 | 252 | qreal value = max.toReal(&ok); |
|
250 | 253 | if(ok) q->setMax(value); |
|
251 | 254 | } |
|
252 | 255 | |
|
253 | 256 | void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
254 | 257 | { |
|
255 | 258 | Q_Q(QValuesAxis); |
|
256 | 259 | bool ok1; |
|
257 | 260 | bool ok2; |
|
258 | 261 | qreal value1 = min.toReal(&ok1); |
|
259 | 262 | qreal value2 = max.toReal(&ok2); |
|
260 | 263 | if(ok1&&ok2) q->setRange(value1,value2); |
|
261 | 264 | } |
|
262 | 265 | |
|
263 | 266 | int QValuesAxisPrivate::ticksCount() const |
|
264 | 267 | { |
|
265 | 268 | return m_ticksCount; |
|
266 | 269 | } |
|
267 | 270 | |
|
268 | 271 | ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
269 | 272 | { |
|
270 | 273 | Q_Q(QValuesAxis); |
|
271 | 274 | if(m_orientation == Qt::Vertical){ |
|
272 | 275 | return new ChartValuesAxisY(q,presenter); |
|
273 | 276 | }else{ |
|
274 | 277 | return new ChartValuesAxisX(q,presenter); |
|
275 | 278 | } |
|
276 | 279 | |
|
277 | 280 | } |
|
278 | 281 | |
|
279 | 282 | void QValuesAxisPrivate::emitRange() |
|
280 | 283 | { |
|
281 | 284 | Q_Q(QValuesAxis); |
|
282 | 285 | if(!q->signalsBlocked()) { |
|
283 | 286 | emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); |
|
284 | 287 | } |
|
285 | 288 | } |
|
286 | 289 | |
|
287 | 290 | #include "moc_qvaluesaxis.cpp" |
|
288 | 291 | #include "moc_qvaluesaxis_p.cpp" |
|
289 | 292 | |
|
290 | 293 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now