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