@@ -1,391 +1,394 | |||||
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 "qvalueaxis.h" |
|
21 | #include "qvalueaxis.h" | |
22 | #include "qvalueaxis_p.h" |
|
22 | #include "qvalueaxis_p.h" | |
23 | #include "chartvalueaxisx_p.h" |
|
23 | #include "chartvalueaxisx_p.h" | |
24 | #include "chartvalueaxisy_p.h" |
|
24 | #include "chartvalueaxisy_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "chartpresenter_p.h" |
|
27 | #include "chartpresenter_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 | /*! |
|
32 | /*! | |
33 | \class QValueAxis |
|
33 | \class QValueAxis | |
34 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
34 | \brief The QValueAxis class is used for manipulating chart's axis. | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
37 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
38 | Values of axis are drawn to position of ticks. |
|
38 | Values of axis are drawn to position of ticks. | |
39 |
|
39 | |||
40 | Example code on how to use QValueAxis. |
|
40 | Example code on how to use QValueAxis. | |
41 | \code |
|
41 | \code | |
42 | QChartView *chartView = new QChartView; |
|
42 | QChartView *chartView = new QChartView; | |
43 | QLineSeries *series = new QLineSeries; |
|
43 | QLineSeries *series = new QLineSeries; | |
44 | // ... |
|
44 | // ... | |
45 | chartView->chart()->addSeries(series); |
|
45 | chartView->chart()->addSeries(series); | |
46 |
|
46 | |||
47 | QValueAxis *axisX = new QValueAxis; |
|
47 | QValueAxis *axisX = new QValueAxis; | |
48 | axisX->setRange(10, 20.5); |
|
48 | axisX->setRange(10, 20.5); | |
49 | axisX->setTickCount(10); |
|
49 | axisX->setTickCount(10); | |
50 | axisX->setLabelFormat("%.2f"); |
|
50 | axisX->setLabelFormat("%.2f"); | |
51 | chartView->chart()->setAxisX(axisX, series); |
|
51 | chartView->chart()->setAxisX(axisX, series); | |
52 | \endcode |
|
52 | \endcode | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \qmlclass ValueAxis QValueAxis |
|
56 | \qmlclass ValueAxis QValueAxis | |
57 | \inherits AbstractAxis |
|
57 | \inherits AbstractAxis | |
58 | \brief The ValueAxis element is used for manipulating chart's axes |
|
58 | \brief The ValueAxis element is used for manipulating chart's axes | |
59 |
|
59 | |||
60 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
60 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
61 | Values of axis are drawn to position of ticks |
|
61 | Values of axis are drawn to position of ticks | |
62 |
|
62 | |||
63 | To access Axes you can use ChartView API. For example: |
|
63 | To access Axes you can use ChartView API. For example: | |
64 | \code |
|
64 | \code | |
65 | ChartView { |
|
65 | ChartView { | |
66 | ValueAxis { |
|
66 | ValueAxis { | |
67 | id: xAxis |
|
67 | id: xAxis | |
68 | min: 0 |
|
68 | min: 0 | |
69 | max: 10 |
|
69 | max: 10 | |
70 | } |
|
70 | } | |
71 | // Add a few series... |
|
71 | // Add a few series... | |
72 | } |
|
72 | } | |
73 | \endcode |
|
73 | \endcode | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QValueAxis::min |
|
77 | \property QValueAxis::min | |
78 | Defines the minimum value on the axis. |
|
78 | Defines the minimum value on the axis. | |
79 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
79 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty real ValueAxis::min |
|
82 | \qmlproperty real ValueAxis::min | |
83 | Defines the minimum value on the axis. |
|
83 | Defines the minimum value on the axis. | |
84 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
84 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QValueAxis::max |
|
88 | \property QValueAxis::max | |
89 | Defines the maximum value on the axis. |
|
89 | Defines the maximum value on the axis. | |
90 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
90 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
91 | */ |
|
91 | */ | |
92 | /*! |
|
92 | /*! | |
93 | \qmlproperty real ValueAxis::max |
|
93 | \qmlproperty real ValueAxis::max | |
94 | Defines the maximum value on the axis. |
|
94 | Defines the maximum value on the axis. | |
95 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
95 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
|
99 | \property QValueAxis::tickCount | |||
|
100 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. | |||
|
101 | The default value is 5, and it can not be below 2. | |||
|
102 | */ | |||
|
103 | /*! | |||
|
104 | \qmlproperty real ValueAxis::tickCount | |||
|
105 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. | |||
|
106 | The default value is 5, and it can not be below 2. | |||
|
107 | */ | |||
|
108 | ||||
|
109 | /*! | |||
99 | \property QValueAxis::labelFormat |
|
110 | \property QValueAxis::labelFormat | |
100 | Defines the label format for the axis. |
|
111 | Defines the label format for the axis. | |
101 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
112 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c | |
102 | See QString::sprintf() for additional details. |
|
113 | See QString::sprintf() for additional details. | |
103 | */ |
|
114 | */ | |
104 | /*! |
|
115 | /*! | |
105 | \qmlproperty real ValueAxis::labelFormat |
|
116 | \qmlproperty real ValueAxis::labelFormat | |
106 | Defines the label format for the axis. |
|
117 | Defines the label format for the axis. | |
107 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
118 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c | |
108 | See QString::sprintf() for additional details. |
|
119 | See QString::sprintf() for additional details. | |
109 | */ |
|
120 | */ | |
110 |
|
121 | |||
111 | /*! |
|
122 | /*! | |
112 | \fn void QValueAxis::minChanged(qreal min) |
|
123 | \fn void QValueAxis::minChanged(qreal min) | |
113 | Axis emits signal when \a min of axis has changed. |
|
124 | Axis emits signal when \a min of axis has changed. | |
114 | */ |
|
125 | */ | |
115 | /*! |
|
126 | /*! | |
116 | \qmlsignal ValueAxis::onMinChanged(real min) |
|
127 | \qmlsignal ValueAxis::onMinChanged(real min) | |
117 | Axis emits signal when \a min of axis has changed. |
|
128 | Axis emits signal when \a min of axis has changed. | |
118 | */ |
|
129 | */ | |
119 |
|
130 | |||
120 | /*! |
|
131 | /*! | |
121 | \fn void QValueAxis::maxChanged(qreal max) |
|
132 | \fn void QValueAxis::maxChanged(qreal max) | |
122 | Axis emits signal when \a max of axis has changed. |
|
133 | Axis emits signal when \a max of axis has changed. | |
123 | */ |
|
134 | */ | |
124 | /*! |
|
135 | /*! | |
125 | \qmlsignal ValueAxis::onMaxChanged(real max) |
|
136 | \qmlsignal ValueAxis::onMaxChanged(real max) | |
126 | Axis emits signal when \a max of axis has changed. |
|
137 | Axis emits signal when \a max of axis has changed. | |
127 | */ |
|
138 | */ | |
128 |
|
139 | |||
129 | /*! |
|
140 | /*! | |
130 |
\fn void QValueAxis:: |
|
141 | \fn void QValueAxis::tickCountChanged(int tickCount) | |
131 |
Axis emits signal when |
|
142 | Axis emits signal when number of ticks on axis have changed. | |
132 | */ |
|
143 | */ | |
133 |
|
||||
134 | /*! |
|
144 | /*! | |
135 | \property QValueAxis::tickCount |
|
145 | \qmlsignal ValueAxis::tickCountChanged(int tickCount) | |
136 | The number of tick marks for the axis. |
|
146 | Axis emits signal when number of ticks on axis have changed. | |
137 | */ |
|
147 | */ | |
138 |
|
148 | |||
139 | /*! |
|
149 | /*! | |
140 | \qmlproperty int ValueAxis::tickCount |
|
150 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) | |
141 | The number of tick marks for the axis. |
|
151 | Axis emits signal when \a min or \a max of axis has changed. | |
142 | */ |
|
152 | */ | |
143 |
|
153 | |||
144 | /*! |
|
154 | /*! | |
145 | \property QValueAxis::niceNumbersEnabled |
|
155 | \property QValueAxis::niceNumbersEnabled | |
146 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
156 | Whether the nice numbers algorithm is enabled or not for the axis. | |
147 | */ |
|
157 | */ | |
148 |
|
158 | |||
149 | /*! |
|
159 | /*! | |
150 | \qmlproperty bool ValueAxis::niceNumbersEnabled |
|
160 | \qmlproperty bool ValueAxis::niceNumbersEnabled | |
151 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
161 | Whether the nice numbers algorithm is enabled or not for the axis. | |
152 | */ |
|
162 | */ | |
153 |
|
163 | |||
154 | /*! |
|
164 | /*! | |
155 | Constructs an axis object which is a child of \a parent. |
|
165 | Constructs an axis object which is a child of \a parent. | |
156 | */ |
|
166 | */ | |
157 | QValueAxis::QValueAxis(QObject *parent) : |
|
167 | QValueAxis::QValueAxis(QObject *parent) : | |
158 | QAbstractAxis(*new QValueAxisPrivate(this), parent) |
|
168 | QAbstractAxis(*new QValueAxisPrivate(this), parent) | |
159 | { |
|
169 | { | |
160 |
|
170 | |||
161 | } |
|
171 | } | |
162 |
|
172 | |||
163 | /*! |
|
173 | /*! | |
164 | \internal |
|
174 | \internal | |
165 | */ |
|
175 | */ | |
166 | QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent) |
|
176 | QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent) | |
167 | : QAbstractAxis(d, parent) |
|
177 | : QAbstractAxis(d, parent) | |
168 | { |
|
178 | { | |
169 |
|
179 | |||
170 | } |
|
180 | } | |
171 |
|
181 | |||
172 | /*! |
|
182 | /*! | |
173 | Destroys the object |
|
183 | Destroys the object | |
174 | */ |
|
184 | */ | |
175 | QValueAxis::~QValueAxis() |
|
185 | QValueAxis::~QValueAxis() | |
176 | { |
|
186 | { | |
177 | Q_D(QValueAxis); |
|
187 | Q_D(QValueAxis); | |
178 | if (d->m_chart) |
|
188 | if (d->m_chart) | |
179 | d->m_chart->removeAxis(this); |
|
189 | d->m_chart->removeAxis(this); | |
180 | } |
|
190 | } | |
181 |
|
191 | |||
182 | void QValueAxis::setMin(qreal min) |
|
192 | void QValueAxis::setMin(qreal min) | |
183 | { |
|
193 | { | |
184 | Q_D(QValueAxis); |
|
194 | Q_D(QValueAxis); | |
185 | setRange(min, qMax(d->m_max, min)); |
|
195 | setRange(min, qMax(d->m_max, min)); | |
186 | } |
|
196 | } | |
187 |
|
197 | |||
188 | qreal QValueAxis::min() const |
|
198 | qreal QValueAxis::min() const | |
189 | { |
|
199 | { | |
190 | Q_D(const QValueAxis); |
|
200 | Q_D(const QValueAxis); | |
191 | return d->m_min; |
|
201 | return d->m_min; | |
192 | } |
|
202 | } | |
193 |
|
203 | |||
194 | void QValueAxis::setMax(qreal max) |
|
204 | void QValueAxis::setMax(qreal max) | |
195 | { |
|
205 | { | |
196 | Q_D(QValueAxis); |
|
206 | Q_D(QValueAxis); | |
197 | setRange(qMin(d->m_min, max), max); |
|
207 | setRange(qMin(d->m_min, max), max); | |
198 | } |
|
208 | } | |
199 |
|
209 | |||
200 | qreal QValueAxis::max() const |
|
210 | qreal QValueAxis::max() const | |
201 | { |
|
211 | { | |
202 | Q_D(const QValueAxis); |
|
212 | Q_D(const QValueAxis); | |
203 | return d->m_max; |
|
213 | return d->m_max; | |
204 | } |
|
214 | } | |
205 |
|
215 | |||
206 | /*! |
|
216 | /*! | |
207 | Sets range from \a min to \a max on the axis. |
|
217 | Sets range from \a min to \a max on the axis. | |
208 | If min is greater than max then this function returns without making any changes. |
|
218 | If min is greater than max then this function returns without making any changes. | |
209 | */ |
|
219 | */ | |
210 | void QValueAxis::setRange(qreal min, qreal max) |
|
220 | void QValueAxis::setRange(qreal min, qreal max) | |
211 | { |
|
221 | { | |
212 | Q_D(QValueAxis); |
|
222 | Q_D(QValueAxis); | |
213 | d->setRange(min,max); |
|
223 | d->setRange(min,max); | |
214 | } |
|
224 | } | |
215 |
|
225 | |||
216 | /*! |
|
|||
217 | Sets \a count for ticks on the axis. |
|
|||
218 | */ |
|
|||
219 | void QValueAxis::setTickCount(int count) |
|
226 | void QValueAxis::setTickCount(int count) | |
220 | { |
|
227 | { | |
221 | Q_D(QValueAxis); |
|
228 | Q_D(QValueAxis); | |
222 | if (d->m_tickCount != count && count >= 2) { |
|
229 | if (d->m_tickCount != count && count >= 2) { | |
223 | d->m_tickCount = count; |
|
230 | d->m_tickCount = count; | |
224 | emit tickCountChanged(count); |
|
231 | emit tickCountChanged(count); | |
225 | } |
|
232 | } | |
226 | } |
|
233 | } | |
227 |
|
234 | |||
228 | /*! |
|
|||
229 | \fn int QValueAxis::tickCount() const |
|
|||
230 | Return number of ticks on the axis |
|
|||
231 | */ |
|
|||
232 | int QValueAxis::tickCount() const |
|
235 | int QValueAxis::tickCount() const | |
233 | { |
|
236 | { | |
234 | Q_D(const QValueAxis); |
|
237 | Q_D(const QValueAxis); | |
235 | return d->m_tickCount; |
|
238 | return d->m_tickCount; | |
236 | } |
|
239 | } | |
237 |
|
240 | |||
238 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
241 | void QValueAxis::setNiceNumbersEnabled(bool enable) | |
239 | { |
|
242 | { | |
240 | Q_UNUSED(enable); |
|
243 | Q_UNUSED(enable); | |
241 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; |
|
244 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; | |
242 | } |
|
245 | } | |
243 |
|
246 | |||
244 | bool QValueAxis::niceNumbersEnabled() const |
|
247 | bool QValueAxis::niceNumbersEnabled() const | |
245 | { |
|
248 | { | |
246 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; |
|
249 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; | |
247 | return false; |
|
250 | return false; | |
248 | } |
|
251 | } | |
249 |
|
252 | |||
250 | void QValueAxis::setLabelFormat(const QString &format) |
|
253 | void QValueAxis::setLabelFormat(const QString &format) | |
251 | { |
|
254 | { | |
252 | Q_D(QValueAxis); |
|
255 | Q_D(QValueAxis); | |
253 | d->m_format = format; |
|
256 | d->m_format = format; | |
254 | } |
|
257 | } | |
255 |
|
258 | |||
256 | QString QValueAxis::labelFormat() const |
|
259 | QString QValueAxis::labelFormat() const | |
257 | { |
|
260 | { | |
258 | Q_D(const QValueAxis); |
|
261 | Q_D(const QValueAxis); | |
259 | return d->m_format; |
|
262 | return d->m_format; | |
260 | } |
|
263 | } | |
261 |
|
264 | |||
262 | /*! |
|
265 | /*! | |
263 | Returns the type of the axis |
|
266 | Returns the type of the axis | |
264 | */ |
|
267 | */ | |
265 | QAbstractAxis::AxisType QValueAxis::type() const |
|
268 | QAbstractAxis::AxisType QValueAxis::type() const | |
266 | { |
|
269 | { | |
267 | return AxisTypeValue; |
|
270 | return AxisTypeValue; | |
268 | } |
|
271 | } | |
269 |
|
272 | |||
270 | void QValueAxis::applyNiceNumbers() |
|
273 | void QValueAxis::applyNiceNumbers() | |
271 | { |
|
274 | { | |
272 | Q_D(QValueAxis); |
|
275 | Q_D(QValueAxis); | |
273 | qreal min = d->m_min; |
|
276 | qreal min = d->m_min; | |
274 | qreal max = d->m_max; |
|
277 | qreal max = d->m_max; | |
275 | int ticks = d->m_tickCount; |
|
278 | int ticks = d->m_tickCount; | |
276 | AbstractDomain::looseNiceNumbers(min,max,ticks); |
|
279 | AbstractDomain::looseNiceNumbers(min,max,ticks); | |
277 | d->setRange(min,max); |
|
280 | d->setRange(min,max); | |
278 | setTickCount(ticks); |
|
281 | setTickCount(ticks); | |
279 | } |
|
282 | } | |
280 |
|
283 | |||
281 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
284 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
282 |
|
285 | |||
283 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) |
|
286 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) | |
284 | : QAbstractAxisPrivate(q), |
|
287 | : QAbstractAxisPrivate(q), | |
285 | m_min(0), |
|
288 | m_min(0), | |
286 | m_max(0), |
|
289 | m_max(0), | |
287 | m_tickCount(5), |
|
290 | m_tickCount(5), | |
288 | m_format(QString::null) |
|
291 | m_format(QString::null) | |
289 | { |
|
292 | { | |
290 |
|
293 | |||
291 | } |
|
294 | } | |
292 |
|
295 | |||
293 | QValueAxisPrivate::~QValueAxisPrivate() |
|
296 | QValueAxisPrivate::~QValueAxisPrivate() | |
294 | { |
|
297 | { | |
295 |
|
298 | |||
296 | } |
|
299 | } | |
297 |
|
300 | |||
298 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
301 | void QValueAxisPrivate::setMin(const QVariant &min) | |
299 | { |
|
302 | { | |
300 | Q_Q(QValueAxis); |
|
303 | Q_Q(QValueAxis); | |
301 | bool ok; |
|
304 | bool ok; | |
302 | qreal value = min.toReal(&ok); |
|
305 | qreal value = min.toReal(&ok); | |
303 | if (ok) |
|
306 | if (ok) | |
304 | q->setMin(value); |
|
307 | q->setMin(value); | |
305 | } |
|
308 | } | |
306 |
|
309 | |||
307 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
310 | void QValueAxisPrivate::setMax(const QVariant &max) | |
308 | { |
|
311 | { | |
309 |
|
312 | |||
310 | Q_Q(QValueAxis); |
|
313 | Q_Q(QValueAxis); | |
311 | bool ok; |
|
314 | bool ok; | |
312 | qreal value = max.toReal(&ok); |
|
315 | qreal value = max.toReal(&ok); | |
313 | if (ok) |
|
316 | if (ok) | |
314 | q->setMax(value); |
|
317 | q->setMax(value); | |
315 | } |
|
318 | } | |
316 |
|
319 | |||
317 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
320 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
318 | { |
|
321 | { | |
319 | Q_Q(QValueAxis); |
|
322 | Q_Q(QValueAxis); | |
320 | bool ok1; |
|
323 | bool ok1; | |
321 | bool ok2; |
|
324 | bool ok2; | |
322 | qreal value1 = min.toReal(&ok1); |
|
325 | qreal value1 = min.toReal(&ok1); | |
323 | qreal value2 = max.toReal(&ok2); |
|
326 | qreal value2 = max.toReal(&ok2); | |
324 | if (ok1 && ok2) |
|
327 | if (ok1 && ok2) | |
325 | q->setRange(value1, value2); |
|
328 | q->setRange(value1, value2); | |
326 | } |
|
329 | } | |
327 |
|
330 | |||
328 | void QValueAxisPrivate::setRange(qreal min, qreal max) |
|
331 | void QValueAxisPrivate::setRange(qreal min, qreal max) | |
329 | { |
|
332 | { | |
330 | Q_Q(QValueAxis); |
|
333 | Q_Q(QValueAxis); | |
331 | bool changed = false; |
|
334 | bool changed = false; | |
332 |
|
335 | |||
333 | if (min > max) |
|
336 | if (min > max) | |
334 | return; |
|
337 | return; | |
335 |
|
338 | |||
336 | if (!qFuzzyCompare(m_min,min)) { |
|
339 | if (!qFuzzyCompare(m_min,min)) { | |
337 | m_min = min; |
|
340 | m_min = min; | |
338 | changed = true; |
|
341 | changed = true; | |
339 | emit q->minChanged(min); |
|
342 | emit q->minChanged(min); | |
340 | } |
|
343 | } | |
341 |
|
344 | |||
342 | if (!qFuzzyCompare(m_max,max)) { |
|
345 | if (!qFuzzyCompare(m_max,max)) { | |
343 | m_max = max; |
|
346 | m_max = max; | |
344 | changed = true; |
|
347 | changed = true; | |
345 | emit q->maxChanged(max); |
|
348 | emit q->maxChanged(max); | |
346 | } |
|
349 | } | |
347 |
|
350 | |||
348 | if (changed) { |
|
351 | if (changed) { | |
349 | emit q->rangeChanged(min, max); |
|
352 | emit q->rangeChanged(min, max); | |
350 | emit rangeChanged(min,max); |
|
353 | emit rangeChanged(min,max); | |
351 | } |
|
354 | } | |
352 | } |
|
355 | } | |
353 |
|
356 | |||
354 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
357 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
355 | { |
|
358 | { | |
356 | Q_Q(QValueAxis); |
|
359 | Q_Q(QValueAxis); | |
357 | ChartAxis* axis(0); |
|
360 | ChartAxis* axis(0); | |
358 | if (orientation() == Qt::Vertical) |
|
361 | if (orientation() == Qt::Vertical) | |
359 | axis = new ChartValueAxisY(q,parent); |
|
362 | axis = new ChartValueAxisY(q,parent); | |
360 | if (orientation() == Qt::Horizontal) |
|
363 | if (orientation() == Qt::Horizontal) | |
361 | axis = new ChartValueAxisX(q,parent); |
|
364 | axis = new ChartValueAxisX(q,parent); | |
362 |
|
365 | |||
363 | m_item.reset(axis); |
|
366 | m_item.reset(axis); | |
364 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
367 | QAbstractAxisPrivate::initializeGraphics(parent); | |
365 | } |
|
368 | } | |
366 |
|
369 | |||
367 |
|
370 | |||
368 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
371 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) | |
369 | { |
|
372 | { | |
370 | if (orientation() == Qt::Vertical) { |
|
373 | if (orientation() == Qt::Vertical) { | |
371 | if(!qFuzzyIsNull(m_max - m_min)) { |
|
374 | if(!qFuzzyIsNull(m_max - m_min)) { | |
372 | domain->setRangeY(m_min, m_max); |
|
375 | domain->setRangeY(m_min, m_max); | |
373 | } |
|
376 | } | |
374 | else { |
|
377 | else { | |
375 | setRange(domain->minY(), domain->maxY()); |
|
378 | setRange(domain->minY(), domain->maxY()); | |
376 | } |
|
379 | } | |
377 | } |
|
380 | } | |
378 | if (orientation() == Qt::Horizontal) { |
|
381 | if (orientation() == Qt::Horizontal) { | |
379 | if(!qFuzzyIsNull(m_max - m_min)) { |
|
382 | if(!qFuzzyIsNull(m_max - m_min)) { | |
380 | domain->setRangeX(m_min, m_max); |
|
383 | domain->setRangeX(m_min, m_max); | |
381 | } |
|
384 | } | |
382 | else { |
|
385 | else { | |
383 | setRange(domain->minX(), domain->maxX()); |
|
386 | setRange(domain->minX(), domain->maxX()); | |
384 | } |
|
387 | } | |
385 | } |
|
388 | } | |
386 | } |
|
389 | } | |
387 |
|
390 | |||
388 | #include "moc_qvalueaxis.cpp" |
|
391 | #include "moc_qvalueaxis.cpp" | |
389 | #include "moc_qvalueaxis_p.cpp" |
|
392 | #include "moc_qvalueaxis_p.cpp" | |
390 |
|
393 | |||
391 | QTCOMMERCIALCHART_END_NAMESPACE |
|
394 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,83 +1,83 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QVALUEAXIS_H |
|
21 | #ifndef QVALUEAXIS_H | |
22 | #define QVALUEAXIS_H |
|
22 | #define QVALUEAXIS_H | |
23 |
|
23 | |||
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QValueAxisPrivate; |
|
28 | class QValueAxisPrivate; | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis |
|
30 | class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) |
|
33 | Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged) | |
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) |
|
34 | Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled) | |
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) |
|
35 | Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged) | |
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) |
|
36 | Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged) | |
37 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat) |
|
37 | Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat) | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | explicit QValueAxis(QObject *parent = 0); |
|
40 | explicit QValueAxis(QObject *parent = 0); | |
41 | ~QValueAxis(); |
|
41 | ~QValueAxis(); | |
42 |
|
42 | |||
43 | protected: |
|
43 | protected: | |
44 | QValueAxis(QValueAxisPrivate &d, QObject *parent = 0); |
|
44 | QValueAxis(QValueAxisPrivate &d, QObject *parent = 0); | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | AxisType type() const; |
|
47 | AxisType type() const; | |
48 |
|
48 | |||
49 | //range handling |
|
49 | //range handling | |
50 | void setMin(qreal min); |
|
50 | void setMin(qreal min); | |
51 | qreal min() const; |
|
51 | qreal min() const; | |
52 | void setMax(qreal max); |
|
52 | void setMax(qreal max); | |
53 | qreal max() const; |
|
53 | qreal max() const; | |
54 | void setRange(qreal min, qreal max); |
|
54 | void setRange(qreal min, qreal max); | |
55 |
|
55 | |||
56 | //ticks handling |
|
56 | //ticks handling | |
57 | void setTickCount(int count); |
|
57 | void setTickCount(int count); | |
58 | int tickCount() const; |
|
58 | int tickCount() const; | |
59 |
|
59 | |||
60 | void setLabelFormat(const QString &format); |
|
60 | void setLabelFormat(const QString &format); | |
61 | QString labelFormat() const; |
|
61 | QString labelFormat() const; | |
62 |
|
62 | |||
63 | //TODO: depreciated ! |
|
63 | //TODO: depreciated ! | |
64 | void setNiceNumbersEnabled(bool enable = true); |
|
64 | void setNiceNumbersEnabled(bool enable = true); | |
65 | bool niceNumbersEnabled() const; |
|
65 | bool niceNumbersEnabled() const; | |
66 |
|
66 | |||
67 | public Q_SLOTS: |
|
67 | public Q_SLOTS: | |
68 | void applyNiceNumbers(); |
|
68 | void applyNiceNumbers(); | |
69 |
|
69 | |||
70 | Q_SIGNALS: |
|
70 | Q_SIGNALS: | |
71 | void minChanged(qreal min); |
|
71 | void minChanged(qreal min); | |
72 | void maxChanged(qreal max); |
|
72 | void maxChanged(qreal max); | |
73 | void rangeChanged(qreal min, qreal max); |
|
73 | void rangeChanged(qreal min, qreal max); | |
74 |
void tickCountChanged(int tick |
|
74 | void tickCountChanged(int tickCount); | |
75 |
|
75 | |||
76 | private: |
|
76 | private: | |
77 | Q_DECLARE_PRIVATE(QValueAxis) |
|
77 | Q_DECLARE_PRIVATE(QValueAxis) | |
78 | Q_DISABLE_COPY(QValueAxis) |
|
78 | Q_DISABLE_COPY(QValueAxis) | |
79 | }; |
|
79 | }; | |
80 |
|
80 | |||
81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
81 | QTCOMMERCIALCHART_END_NAMESPACE | |
82 |
|
82 | |||
83 | #endif // QVALUEAXIS_H |
|
83 | #endif // QVALUEAXIS_H |
General Comments 0
You need to be logged in to leave comments.
Login now