@@ -1,364 +1,373 | |||
|
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 "qdatetimeaxis.h" |
|
22 | 22 | #include "qdatetimeaxis_p.h" |
|
23 | 23 | #include "chartdatetimeaxisx_p.h" |
|
24 | 24 | #include "chartdatetimeaxisy_p.h" |
|
25 | 25 | #include "abstractdomain_p.h" |
|
26 | 26 | #include "qchart.h" |
|
27 | 27 | #include <float.h> |
|
28 | 28 | #include <cmath> |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | /*! |
|
32 | 32 | \class QDateTimeAxis |
|
33 | 33 | \brief The QDateTimeAxis class is used for manipulating chart's axis. |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 | 36 | The labels can be configured by setting an appropriate DateTime format. |
|
37 | 37 | QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE |
|
38 | 38 | There are also other limitiation related to QDateTime . Please refer to QDateTime documentation. |
|
39 | 39 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
40 | 40 | |
|
41 | 41 | NOTE: QDateTimeAxis is disabled on ARM architecture. |
|
42 | 42 | |
|
43 | 43 | \image api_datatime_axis.png |
|
44 | 44 | |
|
45 | 45 | QDateTimeAxis can be used with QLineSeries, QSplineSeries or QScatterSeries. |
|
46 | 46 | To add a data point to the series QDateTime::toMSecsSinceEpoch() is used. |
|
47 | 47 | \code |
|
48 | 48 | QLineSeries *series = new QLineSeries; |
|
49 | 49 | |
|
50 | 50 | QDateTime xValue; |
|
51 | 51 | xValue.setDate(QDate(2012, 1 , 18)); |
|
52 | 52 | xValue.setTime(QTime(9, 34)); |
|
53 | 53 | qreal yValue = 12; |
|
54 | 54 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
55 | 55 | |
|
56 | 56 | xValue.setDate(QDate(2013, 5 , 11)); |
|
57 | 57 | xValue.setTime(QTime(11, 14)); |
|
58 | 58 | qreal yValue = 22; |
|
59 | 59 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
60 | 60 | \endcode |
|
61 | 61 | |
|
62 | 62 | Adding the series to the chart and setting up the QDateTimeAxis. |
|
63 | 63 | \code |
|
64 | 64 | QChartView *chartView = new QChartView; |
|
65 | 65 | chartView->chart()->addSeries(series); |
|
66 | 66 | |
|
67 | 67 | // ... |
|
68 | 68 | QDateTimeAxis *axisX = new QDateTimeAxis; |
|
69 | 69 | axisX->setFormat("dd-MM-yyyy h:mm"); |
|
70 | 70 | chartView->chart()->setAxisX(axisX, series); |
|
71 | 71 | \endcode |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \qmlclass DateTimeAxis QDateTimeAxis |
|
76 | 76 | \brief The DateTimeAxis element is used for manipulating chart's axes |
|
77 | 77 | \inherits AbstractAxis |
|
78 | 78 | |
|
79 | 79 | The labels can be configured by setting an appropriate DateTime format. |
|
80 | 80 | Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored. |
|
81 | 81 | DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
82 | 82 | */ |
|
83 | 83 | |
|
84 | 84 | /*! |
|
85 | 85 | \property QDateTimeAxis::min |
|
86 | 86 | Defines the minimum value on the axis. |
|
87 | 87 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty real ValuesAxis::min |
|
91 | 91 | Defines the minimum value on the axis. |
|
92 | 92 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | \property QDateTimeAxis::max |
|
97 | 97 | Defines the maximum value on the axis. |
|
98 | 98 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
99 | 99 | */ |
|
100 | 100 | /*! |
|
101 | 101 | \qmlproperty real ValuesAxis::max |
|
102 | 102 | Defines the maximum value on the axis. |
|
103 | 103 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
104 | 104 | */ |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | \fn void QDateTimeAxis::minChanged(QDateTime min) |
|
108 | 108 | Axis emits signal when \a min of axis has changed. |
|
109 | 109 | */ |
|
110 | 110 | /*! |
|
111 | 111 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) |
|
112 | 112 | Axis emits signal when \a min of axis has changed. |
|
113 | 113 | */ |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | \fn void QDateTimeAxis::maxChanged(QDateTime max) |
|
117 | 117 | Axis emits signal when \a max of axis has changed. |
|
118 | 118 | */ |
|
119 | 119 | /*! |
|
120 | 120 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) |
|
121 | 121 | Axis emits signal when \a max of axis has changed. |
|
122 | 122 | */ |
|
123 | 123 | |
|
124 | 124 | /*! |
|
125 | 125 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) |
|
126 | 126 | Axis emits signal when \a min or \a max of axis has changed. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \property QDateTimeAxis::tickCount |
|
131 | 131 | The number of tick marks for the axis. |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \qmlproperty int DateTimeAxis::tickCount |
|
136 | 136 | The number of tick marks for the axis. |
|
137 | 137 | */ |
|
138 | 138 | |
|
139 | 139 | /*! |
|
140 | 140 | \property QDateTimeAxis::format |
|
141 | 141 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
142 | 142 | Check QDateTime documentation for information on how the string should be defined. |
|
143 | 143 | */ |
|
144 | 144 | /*! |
|
145 | 145 | \qmlproperty string DateTimeAxis::format |
|
146 | 146 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
147 | 147 | Check QDateTime documentation for information on how the string should be defined. |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | \fn void QDateTimeAxis::tickCountChanged(int tickCount) | |
|
152 | Axis emits signal when \a tickCount number on axis have changed. | |
|
153 | */ | |
|
154 | /*! | |
|
155 | \qmlsignal DateTimeAxis::tickCountChanged(int tickCount) | |
|
156 | Axis emits signal when \a tickCount number on axis have changed. | |
|
157 | */ | |
|
158 | ||
|
159 | /*! | |
|
151 | 160 | \fn void QDateTimeAxis::formatChanged(QString format) |
|
152 | 161 | Axis emits signal when \a format of the axis has changed. |
|
153 | 162 | */ |
|
154 | 163 | /*! |
|
155 | 164 | \qmlsignal DateTimeAxis::onFormatChanged(string format) |
|
156 | 165 | Axis emits signal when \a format of the axis has changed. |
|
157 | 166 | */ |
|
158 | 167 | |
|
159 | 168 | /*! |
|
160 | 169 | Constructs an axis object which is a child of \a parent. |
|
161 | 170 | */ |
|
162 | 171 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : |
|
163 | 172 | QAbstractAxis(*new QDateTimeAxisPrivate(this), parent) |
|
164 | 173 | { |
|
165 | 174 | |
|
166 | 175 | } |
|
167 | 176 | |
|
168 | 177 | /*! |
|
169 | 178 | \internal |
|
170 | 179 | */ |
|
171 | 180 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
172 | 181 | { |
|
173 | 182 | |
|
174 | 183 | } |
|
175 | 184 | |
|
176 | 185 | /*! |
|
177 | 186 | Destroys the object |
|
178 | 187 | */ |
|
179 | 188 | QDateTimeAxis::~QDateTimeAxis() |
|
180 | 189 | { |
|
181 | 190 | Q_D(QDateTimeAxis); |
|
182 | 191 | if (d->m_chart) |
|
183 | 192 | d->m_chart->removeAxis(this); |
|
184 | 193 | } |
|
185 | 194 | |
|
186 | 195 | void QDateTimeAxis::setMin(QDateTime min) |
|
187 | 196 | { |
|
188 | 197 | Q_D(QDateTimeAxis); |
|
189 | 198 | if (min.isValid()) |
|
190 | 199 | d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch()))); |
|
191 | 200 | } |
|
192 | 201 | |
|
193 | 202 | QDateTime QDateTimeAxis::min() const |
|
194 | 203 | { |
|
195 | 204 | Q_D(const QDateTimeAxis); |
|
196 | 205 | return QDateTime::fromMSecsSinceEpoch(d->m_min); |
|
197 | 206 | } |
|
198 | 207 | |
|
199 | 208 | void QDateTimeAxis::setMax(QDateTime max) |
|
200 | 209 | { |
|
201 | 210 | Q_D(QDateTimeAxis); |
|
202 | 211 | if (max.isValid()) |
|
203 | 212 | d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch()); |
|
204 | 213 | } |
|
205 | 214 | |
|
206 | 215 | QDateTime QDateTimeAxis::max() const |
|
207 | 216 | { |
|
208 | 217 | Q_D(const QDateTimeAxis); |
|
209 | 218 | return QDateTime::fromMSecsSinceEpoch(d->m_max); |
|
210 | 219 | } |
|
211 | 220 | |
|
212 | 221 | /*! |
|
213 | 222 | Sets range from \a min to \a max on the axis. |
|
214 | 223 | If min is greater than max then this function returns without making any changes. |
|
215 | 224 | */ |
|
216 | 225 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) |
|
217 | 226 | { |
|
218 | 227 | Q_D(QDateTimeAxis); |
|
219 | 228 | if (!min.isValid() || !max.isValid() || min > max) |
|
220 | 229 | return; |
|
221 | 230 | |
|
222 | 231 | d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch()); |
|
223 | 232 | } |
|
224 | 233 | |
|
225 | 234 | void QDateTimeAxis::setFormat(QString format) |
|
226 | 235 | { |
|
227 | 236 | Q_D(QDateTimeAxis); |
|
228 | 237 | if (d->m_format != format) { |
|
229 | 238 | d->m_format = format; |
|
230 | 239 | emit formatChanged(format); |
|
231 | 240 | } |
|
232 | 241 | } |
|
233 | 242 | |
|
234 | 243 | QString QDateTimeAxis::format() const |
|
235 | 244 | { |
|
236 | 245 | Q_D(const QDateTimeAxis); |
|
237 | 246 | return d->m_format; |
|
238 | 247 | } |
|
239 | 248 | |
|
240 | 249 | /*! |
|
241 | 250 | Sets \a count for ticks on the axis. |
|
242 | 251 | */ |
|
243 | 252 | void QDateTimeAxis::setTickCount(int count) |
|
244 | 253 | { |
|
245 | 254 | Q_D(QDateTimeAxis); |
|
246 | 255 | if (d->m_tickCount != count && count >= 2) { |
|
247 | 256 | d->m_tickCount = count; |
|
248 | 257 | emit tickCountChanged(count); |
|
249 | 258 | } |
|
250 | 259 | } |
|
251 | 260 | |
|
252 | 261 | /*! |
|
253 | 262 | \fn int QDateTimeAxis::tickCount() const |
|
254 | 263 | Return number of ticks on the axis |
|
255 | 264 | */ |
|
256 | 265 | int QDateTimeAxis::tickCount() const |
|
257 | 266 | { |
|
258 | 267 | Q_D(const QDateTimeAxis); |
|
259 | 268 | return d->m_tickCount; |
|
260 | 269 | } |
|
261 | 270 | |
|
262 | 271 | /*! |
|
263 | 272 | Returns the type of the axis |
|
264 | 273 | */ |
|
265 | 274 | QAbstractAxis::AxisType QDateTimeAxis::type() const |
|
266 | 275 | { |
|
267 | 276 | return AxisTypeDateTime; |
|
268 | 277 | } |
|
269 | 278 | |
|
270 | 279 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
271 | 280 | |
|
272 | 281 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) |
|
273 | 282 | : QAbstractAxisPrivate(q), |
|
274 | 283 | m_min(0), |
|
275 | 284 | m_max(0), |
|
276 | 285 | m_tickCount(5) |
|
277 | 286 | { |
|
278 | 287 | m_format = "dd-MM-yyyy\nh:mm"; |
|
279 | 288 | } |
|
280 | 289 | |
|
281 | 290 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
|
282 | 291 | { |
|
283 | 292 | |
|
284 | 293 | } |
|
285 | 294 | |
|
286 | 295 | void QDateTimeAxisPrivate::setRange(qreal min,qreal max) |
|
287 | 296 | { |
|
288 | 297 | Q_Q(QDateTimeAxis); |
|
289 | 298 | |
|
290 | 299 | bool changed = false; |
|
291 | 300 | |
|
292 | 301 | if (m_min != min) { |
|
293 | 302 | m_min = min; |
|
294 | 303 | changed = true; |
|
295 | 304 | emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min)); |
|
296 | 305 | } |
|
297 | 306 | |
|
298 | 307 | if (m_max != max) { |
|
299 | 308 | m_max = max; |
|
300 | 309 | changed = true; |
|
301 | 310 | emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max)); |
|
302 | 311 | } |
|
303 | 312 | |
|
304 | 313 | if (changed) { |
|
305 | 314 | emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max)); |
|
306 | 315 | emit rangeChanged(m_min,m_max); |
|
307 | 316 | } |
|
308 | 317 | } |
|
309 | 318 | |
|
310 | 319 | |
|
311 | 320 | void QDateTimeAxisPrivate::setMin(const QVariant &min) |
|
312 | 321 | { |
|
313 | 322 | Q_Q(QDateTimeAxis); |
|
314 | 323 | if (min.canConvert(QVariant::DateTime)) |
|
315 | 324 | q->setMin(min.toDateTime()); |
|
316 | 325 | } |
|
317 | 326 | |
|
318 | 327 | void QDateTimeAxisPrivate::setMax(const QVariant &max) |
|
319 | 328 | { |
|
320 | 329 | |
|
321 | 330 | Q_Q(QDateTimeAxis); |
|
322 | 331 | if (max.canConvert(QVariant::DateTime)) |
|
323 | 332 | q->setMax(max.toDateTime()); |
|
324 | 333 | } |
|
325 | 334 | |
|
326 | 335 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
327 | 336 | { |
|
328 | 337 | Q_Q(QDateTimeAxis); |
|
329 | 338 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) |
|
330 | 339 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
331 | 340 | } |
|
332 | 341 | |
|
333 | 342 | void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
334 | 343 | { |
|
335 | 344 | Q_Q(QDateTimeAxis); |
|
336 | 345 | ChartAxis* axis(0); |
|
337 | 346 | if (orientation() == Qt::Vertical) |
|
338 | 347 | axis = new ChartDateTimeAxisY(q,parent); |
|
339 | 348 | if (orientation() == Qt::Horizontal) |
|
340 | 349 | axis = new ChartDateTimeAxisX(q,parent); |
|
341 | 350 | |
|
342 | 351 | m_item.reset(axis); |
|
343 | 352 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
344 | 353 | } |
|
345 | 354 | |
|
346 | 355 | void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
347 | 356 | { |
|
348 | 357 | if (m_max == m_min) { |
|
349 | 358 | if (orientation() == Qt::Vertical) |
|
350 | 359 | setRange(domain->minY(), domain->maxY()); |
|
351 | 360 | else |
|
352 | 361 | setRange(domain->minX(), domain->maxX()); |
|
353 | 362 | } else { |
|
354 | 363 | if (orientation() == Qt::Vertical) |
|
355 | 364 | domain->setRangeY(m_min, m_max); |
|
356 | 365 | else |
|
357 | 366 | domain->setRangeX(m_min, m_max); |
|
358 | 367 | } |
|
359 | 368 | } |
|
360 | 369 | |
|
361 | 370 | #include "moc_qdatetimeaxis.cpp" |
|
362 | 371 | #include "moc_qdatetimeaxis_p.cpp" |
|
363 | 372 | |
|
364 | 373 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,869 +1,870 | |||
|
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 "qabstractaxis.h" |
|
22 | 22 | #include "qabstractaxis_p.h" |
|
23 | 23 | #include "chartdataset_p.h" |
|
24 | 24 | #include "charttheme_p.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | /*! |
|
29 | 29 | \class QAbstractAxis |
|
30 | 30 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
31 | 31 | \mainclass |
|
32 | 32 | |
|
33 | 33 | There is only one x Axis visible at the time, however there can be multiple y axes. |
|
34 | 34 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
35 | 35 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
36 | 36 | */ |
|
37 | 37 | |
|
38 | 38 | /*! |
|
39 | 39 | \qmlclass AbstractAxis QAbstractAxis |
|
40 | 40 | \brief The Axis element is used for manipulating chart's axes |
|
41 | 41 | |
|
42 | 42 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. |
|
43 | 43 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
44 | 44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
45 | 45 | |
|
46 | 46 | To access Axes you can use ChartView API. For example: |
|
47 | 47 | \code |
|
48 | 48 | ChartView { |
|
49 | 49 | axisX.min: 0 |
|
50 | 50 | axisX.max: 3 |
|
51 | 51 | axisX.ticksCount: 4 |
|
52 | 52 | axisY.min: 0 |
|
53 | 53 | axisY.max: 4 |
|
54 | 54 | // Add a few series... |
|
55 | 55 | } |
|
56 | 56 | \endcode |
|
57 | 57 | */ |
|
58 | 58 | |
|
59 | 59 | /*! |
|
60 | 60 | \enum QAbstractAxis::AxisType |
|
61 | 61 | |
|
62 | 62 | The type of the series object. |
|
63 | 63 | |
|
64 | 64 | \value AxisTypeNoAxis |
|
65 | 65 | \value AxisTypeValue |
|
66 | 66 | \value AxisTypeBarCategory |
|
67 | 67 | \value AxisTypeCategory |
|
68 | 68 | \value AxisTypeDateTime |
|
69 | \value AxisTypeLogValue | |
|
69 | 70 | */ |
|
70 | 71 | |
|
71 | 72 | /*! |
|
72 | 73 | *\fn void QAbstractAxis::type() const |
|
73 | 74 | Returns the type of the axis |
|
74 | 75 | */ |
|
75 | 76 | |
|
76 | 77 | /*! |
|
77 | 78 | \property QAbstractAxis::lineVisible |
|
78 | 79 | The visibility of the axis line |
|
79 | 80 | */ |
|
80 | 81 | /*! |
|
81 | 82 | \qmlproperty bool AbstractAxis::lineVisible |
|
82 | 83 | The visibility of the axis line |
|
83 | 84 | */ |
|
84 | 85 | |
|
85 | 86 | /*! |
|
86 | 87 | \property QAbstractAxis::labelsVisible |
|
87 | 88 | Defines if axis labels are visible. |
|
88 | 89 | */ |
|
89 | 90 | /*! |
|
90 | 91 | \qmlproperty bool AbstractAxis::labelsVisible |
|
91 | 92 | Defines if axis labels are visible. |
|
92 | 93 | */ |
|
93 | 94 | |
|
94 | 95 | /*! |
|
95 | 96 | \property QAbstractAxis::visible |
|
96 | 97 | The visibility of the axis. |
|
97 | 98 | */ |
|
98 | 99 | /*! |
|
99 | 100 | \qmlproperty bool AbstractAxis::visible |
|
100 | 101 | The visibility of the axis. |
|
101 | 102 | */ |
|
102 | 103 | |
|
103 | 104 | /*! |
|
104 | 105 | \property QAbstractAxis::gridVisible |
|
105 | 106 | The visibility of the grid lines. |
|
106 | 107 | */ |
|
107 | 108 | /*! |
|
108 | 109 | \qmlproperty bool AbstractAxis::gridVisible |
|
109 | 110 | The visibility of the grid lines. |
|
110 | 111 | */ |
|
111 | 112 | |
|
112 | 113 | /*! |
|
113 | 114 | \property QAbstractAxis::color |
|
114 | 115 | The color of the axis and ticks. |
|
115 | 116 | */ |
|
116 | 117 | /*! |
|
117 | 118 | \qmlproperty color AbstractAxis::color |
|
118 | 119 | The color of the axis and ticks. |
|
119 | 120 | */ |
|
120 | 121 | |
|
121 | 122 | /*! |
|
122 | 123 | \property QAbstractAxis::labelsFont |
|
123 | 124 | The font of the axis labels. |
|
124 | 125 | */ |
|
125 | 126 | |
|
126 | 127 | /*! |
|
127 | 128 | \qmlproperty Font AbstractAxis::labelsFont |
|
128 | 129 | The font of the axis labels. |
|
129 | 130 | |
|
130 | 131 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
131 | 132 | */ |
|
132 | 133 | |
|
133 | 134 | /*! |
|
134 | 135 | \property QAbstractAxis::labelsColor |
|
135 | 136 | The color of the axis labels. |
|
136 | 137 | */ |
|
137 | 138 | /*! |
|
138 | 139 | \qmlproperty color AbstractAxis::labelsColor |
|
139 | 140 | The color of the axis labels. |
|
140 | 141 | */ |
|
141 | 142 | |
|
142 | 143 | /*! |
|
143 | 144 | \property QAbstractAxis::labelsAngle |
|
144 | 145 | The angle of the axis labels in degrees. |
|
145 | 146 | */ |
|
146 | 147 | /*! |
|
147 | 148 | \qmlproperty int AbstractAxis::labelsAngle |
|
148 | 149 | The angle of the axis labels in degrees. |
|
149 | 150 | */ |
|
150 | 151 | |
|
151 | 152 | /*! |
|
152 | 153 | \property QAbstractAxis::shadesVisible |
|
153 | 154 | The visibility of the axis shades. |
|
154 | 155 | */ |
|
155 | 156 | /*! |
|
156 | 157 | \qmlproperty bool AbstractAxis::shadesVisible |
|
157 | 158 | The visibility of the axis shades. |
|
158 | 159 | */ |
|
159 | 160 | |
|
160 | 161 | /*! |
|
161 | 162 | \property QAbstractAxis::shadesColor |
|
162 | 163 | The fill (brush) color of the axis shades. |
|
163 | 164 | */ |
|
164 | 165 | /*! |
|
165 | 166 | \qmlproperty color AbstractAxis::shadesColor |
|
166 | 167 | The fill (brush) color of the axis shades. |
|
167 | 168 | */ |
|
168 | 169 | |
|
169 | 170 | /*! |
|
170 | 171 | \property QAbstractAxis::shadesBorderColor |
|
171 | 172 | The border (pen) color of the axis shades. |
|
172 | 173 | */ |
|
173 | 174 | /*! |
|
174 | 175 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
175 | 176 | The border (pen) color of the axis shades. |
|
176 | 177 | */ |
|
177 | 178 | |
|
178 | 179 | /*! |
|
179 | 180 | \property QAbstractAxis::titleVisible |
|
180 | 181 | The visibility of the axis title. By default the value is true. |
|
181 | 182 | */ |
|
182 | 183 | /*! |
|
183 | 184 | \qmlproperty bool AbstractAxis::titleVisible |
|
184 | 185 | The visibility of the axis title. By default the value is true. |
|
185 | 186 | */ |
|
186 | 187 | |
|
187 | 188 | /*! |
|
188 | 189 | \property QAbstractAxis::titleFont |
|
189 | 190 | The font of the title of the axis. |
|
190 | 191 | */ |
|
191 | 192 | /*! |
|
192 | 193 | \qmlproperty Font AbstractAxis::title |
|
193 | 194 | The font of the title of the axis. |
|
194 | 195 | */ |
|
195 | 196 | |
|
196 | 197 | /*! |
|
197 | 198 | \property QAbstractAxis::title |
|
198 | 199 | The title of the axis. Empty by default. |
|
199 | 200 | */ |
|
200 | 201 | /*! |
|
201 | 202 | \qmlproperty string AbstractAxis::title |
|
202 | 203 | The title of the axis. Empty string by default. |
|
203 | 204 | */ |
|
204 | 205 | |
|
205 | 206 | /*! |
|
206 | 207 | \property QAbstractAxis::alignment |
|
207 | 208 | The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom. |
|
208 | 209 | */ |
|
209 | 210 | /*! |
|
210 | 211 | \qmlproperty alignment AbstractAxis::alignment |
|
211 | 212 | The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom. |
|
212 | 213 | */ |
|
213 | 214 | |
|
214 | 215 | /*! |
|
215 | 216 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
216 | 217 | Visibility of the axis has changed to \a visible. |
|
217 | 218 | */ |
|
218 | 219 | /*! |
|
219 | 220 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
220 | 221 | Visibility of the axis has changed to \a visible. |
|
221 | 222 | */ |
|
222 | 223 | |
|
223 | 224 | /*! |
|
224 | 225 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
225 | 226 | Visibility of the axis line has changed to \a visible. |
|
226 | 227 | */ |
|
227 | 228 | /*! |
|
228 | 229 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
229 | 230 | Visibility of the axis line has changed to \a visible. |
|
230 | 231 | */ |
|
231 | 232 | |
|
232 | 233 | /*! |
|
233 | 234 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
234 | 235 | Visibility of the labels of the axis has changed to \a visible. |
|
235 | 236 | */ |
|
236 | 237 | /*! |
|
237 | 238 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
238 | 239 | Visibility of the labels of the axis has changed to \a visible. |
|
239 | 240 | */ |
|
240 | 241 | |
|
241 | 242 | /*! |
|
242 | 243 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
243 | 244 | Visibility of the grid lines of the axis has changed to \a visible. |
|
244 | 245 | */ |
|
245 | 246 | /*! |
|
246 | 247 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
247 | 248 | Visibility of the grid lines of the axis has changed to \a visible. |
|
248 | 249 | */ |
|
249 | 250 | |
|
250 | 251 | /*! |
|
251 | 252 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
252 | 253 | Emitted if the \a color of the axis is changed. |
|
253 | 254 | */ |
|
254 | 255 | /*! |
|
255 | 256 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
256 | 257 | Emitted if the \a color of the axis is changed. |
|
257 | 258 | */ |
|
258 | 259 | |
|
259 | 260 | /*! |
|
260 | 261 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
261 | 262 | Emitted if the \a color of the axis labels is changed. |
|
262 | 263 | */ |
|
263 | 264 | /*! |
|
264 | 265 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
265 | 266 | Emitted if the \a color of the axis labels is changed. |
|
266 | 267 | */ |
|
267 | 268 | |
|
268 | 269 | /*! |
|
269 | 270 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
270 | 271 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
271 | 272 | */ |
|
272 | 273 | /*! |
|
273 | 274 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
274 | 275 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
275 | 276 | */ |
|
276 | 277 | |
|
277 | 278 | /*! |
|
278 | 279 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
279 | 280 | Emitted if the \a color of the axis shades is changed. |
|
280 | 281 | */ |
|
281 | 282 | /*! |
|
282 | 283 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
283 | 284 | Emitted if the \a color of the axis shades is changed. |
|
284 | 285 | */ |
|
285 | 286 | |
|
286 | 287 | /*! |
|
287 | 288 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
288 | 289 | Emitted if the border \a color of the axis shades is changed. |
|
289 | 290 | */ |
|
290 | 291 | /*! |
|
291 | 292 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
292 | 293 | Emitted if the border \a color of the axis shades is changed. |
|
293 | 294 | */ |
|
294 | 295 | |
|
295 | 296 | /*! |
|
296 | 297 | \internal |
|
297 | 298 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
298 | 299 | QChart when axis added. |
|
299 | 300 | */ |
|
300 | 301 | |
|
301 | 302 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
302 | 303 | : QObject(parent), |
|
303 | 304 | d_ptr(&d) |
|
304 | 305 | { |
|
305 | 306 | } |
|
306 | 307 | |
|
307 | 308 | /*! |
|
308 | 309 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
309 | 310 | */ |
|
310 | 311 | |
|
311 | 312 | QAbstractAxis::~QAbstractAxis() |
|
312 | 313 | { |
|
313 | 314 | if (d_ptr->m_chart) |
|
314 | 315 | qFatal("Still binded axis detected !"); |
|
315 | 316 | } |
|
316 | 317 | |
|
317 | 318 | /*! |
|
318 | 319 | Sets \a pen used to draw axis line and ticks. |
|
319 | 320 | */ |
|
320 | 321 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
321 | 322 | { |
|
322 | 323 | if (d_ptr->m_axisPen != pen) { |
|
323 | 324 | d_ptr->m_axisPen = pen; |
|
324 | 325 | emit linePenChanged(pen); |
|
325 | 326 | } |
|
326 | 327 | } |
|
327 | 328 | |
|
328 | 329 | /*! |
|
329 | 330 | Returns pen used to draw axis and ticks. |
|
330 | 331 | */ |
|
331 | 332 | QPen QAbstractAxis::linePen() const |
|
332 | 333 | { |
|
333 | 334 | return d_ptr->m_axisPen; |
|
334 | 335 | } |
|
335 | 336 | |
|
336 | 337 | //TODO: remove me |
|
337 | 338 | void QAbstractAxis::setLinePenColor(QColor color) |
|
338 | 339 | { |
|
339 | 340 | QPen p = d_ptr->m_axisPen; |
|
340 | 341 | if (p.color() != color) { |
|
341 | 342 | p.setColor(color); |
|
342 | 343 | setLinePen(p); |
|
343 | 344 | emit colorChanged(color); |
|
344 | 345 | } |
|
345 | 346 | } |
|
346 | 347 | |
|
347 | 348 | QColor QAbstractAxis::linePenColor() const |
|
348 | 349 | { |
|
349 | 350 | return d_ptr->m_axisPen.color(); |
|
350 | 351 | } |
|
351 | 352 | |
|
352 | 353 | /*! |
|
353 | 354 | Sets if axis and ticks are \a visible. |
|
354 | 355 | */ |
|
355 | 356 | void QAbstractAxis::setLineVisible(bool visible) |
|
356 | 357 | { |
|
357 | 358 | if (d_ptr->m_arrowVisible != visible) { |
|
358 | 359 | d_ptr->m_arrowVisible = visible; |
|
359 | 360 | emit lineVisibleChanged(visible); |
|
360 | 361 | } |
|
361 | 362 | } |
|
362 | 363 | |
|
363 | 364 | bool QAbstractAxis::isLineVisible() const |
|
364 | 365 | { |
|
365 | 366 | return d_ptr->m_arrowVisible; |
|
366 | 367 | } |
|
367 | 368 | |
|
368 | 369 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
369 | 370 | { |
|
370 | 371 | if (d_ptr->m_gridLineVisible != visible) { |
|
371 | 372 | d_ptr->m_gridLineVisible = visible; |
|
372 | 373 | emit gridVisibleChanged(visible); |
|
373 | 374 | } |
|
374 | 375 | } |
|
375 | 376 | |
|
376 | 377 | bool QAbstractAxis::isGridLineVisible() const |
|
377 | 378 | { |
|
378 | 379 | return d_ptr->m_gridLineVisible; |
|
379 | 380 | } |
|
380 | 381 | |
|
381 | 382 | /*! |
|
382 | 383 | Sets \a pen used to draw grid line. |
|
383 | 384 | */ |
|
384 | 385 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
385 | 386 | { |
|
386 | 387 | if (d_ptr->m_gridLinePen != pen) { |
|
387 | 388 | d_ptr->m_gridLinePen = pen; |
|
388 | 389 | emit gridLinePenChanged(pen); |
|
389 | 390 | } |
|
390 | 391 | } |
|
391 | 392 | |
|
392 | 393 | /*! |
|
393 | 394 | Returns pen used to draw grid. |
|
394 | 395 | */ |
|
395 | 396 | QPen QAbstractAxis::gridLinePen() const |
|
396 | 397 | { |
|
397 | 398 | return d_ptr->m_gridLinePen; |
|
398 | 399 | } |
|
399 | 400 | |
|
400 | 401 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
401 | 402 | { |
|
402 | 403 | if (d_ptr->m_labelsVisible != visible) { |
|
403 | 404 | d_ptr->m_labelsVisible = visible; |
|
404 | 405 | emit labelsVisibleChanged(visible); |
|
405 | 406 | } |
|
406 | 407 | } |
|
407 | 408 | |
|
408 | 409 | bool QAbstractAxis::labelsVisible() const |
|
409 | 410 | { |
|
410 | 411 | return d_ptr->m_labelsVisible; |
|
411 | 412 | } |
|
412 | 413 | |
|
413 | 414 | /*! |
|
414 | 415 | Sets \a pen used to draw labels. |
|
415 | 416 | */ |
|
416 | 417 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
417 | 418 | { |
|
418 | 419 | if (d_ptr->m_labelsPen != pen) { |
|
419 | 420 | d_ptr->m_labelsPen = pen; |
|
420 | 421 | emit labelsPenChanged(pen); |
|
421 | 422 | } |
|
422 | 423 | } |
|
423 | 424 | |
|
424 | 425 | /*! |
|
425 | 426 | Returns the pen used to labels. |
|
426 | 427 | */ |
|
427 | 428 | QPen QAbstractAxis::labelsPen() const |
|
428 | 429 | { |
|
429 | 430 | return d_ptr->m_labelsPen; |
|
430 | 431 | } |
|
431 | 432 | |
|
432 | 433 | /*! |
|
433 | 434 | Sets \a brush used to draw labels. |
|
434 | 435 | */ |
|
435 | 436 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
436 | 437 | { |
|
437 | 438 | if (d_ptr->m_labelsBrush != brush) { |
|
438 | 439 | d_ptr->m_labelsBrush = brush; |
|
439 | 440 | emit labelsBrushChanged(brush); |
|
440 | 441 | } |
|
441 | 442 | } |
|
442 | 443 | |
|
443 | 444 | /*! |
|
444 | 445 | Returns brush used to draw labels. |
|
445 | 446 | */ |
|
446 | 447 | QBrush QAbstractAxis::labelsBrush() const |
|
447 | 448 | { |
|
448 | 449 | return d_ptr->m_labelsBrush; |
|
449 | 450 | } |
|
450 | 451 | |
|
451 | 452 | /*! |
|
452 | 453 | Sets \a font used to draw labels. |
|
453 | 454 | */ |
|
454 | 455 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
455 | 456 | { |
|
456 | 457 | if (d_ptr->m_labelsFont != font) { |
|
457 | 458 | d_ptr->m_labelsFont = font; |
|
458 | 459 | emit labelsFontChanged(font); |
|
459 | 460 | } |
|
460 | 461 | } |
|
461 | 462 | |
|
462 | 463 | /*! |
|
463 | 464 | Returns font used to draw labels. |
|
464 | 465 | */ |
|
465 | 466 | QFont QAbstractAxis::labelsFont() const |
|
466 | 467 | { |
|
467 | 468 | return d_ptr->m_labelsFont; |
|
468 | 469 | } |
|
469 | 470 | |
|
470 | 471 | void QAbstractAxis::setLabelsAngle(int angle) |
|
471 | 472 | { |
|
472 | 473 | if (d_ptr->m_labelsAngle != angle) { |
|
473 | 474 | d_ptr->m_labelsAngle = angle; |
|
474 | 475 | emit labelsAngleChanged(angle); |
|
475 | 476 | } |
|
476 | 477 | } |
|
477 | 478 | |
|
478 | 479 | int QAbstractAxis::labelsAngle() const |
|
479 | 480 | { |
|
480 | 481 | return d_ptr->m_labelsAngle; |
|
481 | 482 | } |
|
482 | 483 | //TODO: remove me |
|
483 | 484 | void QAbstractAxis::setLabelsColor(QColor color) |
|
484 | 485 | { |
|
485 | 486 | QBrush b = d_ptr->m_labelsBrush; |
|
486 | 487 | if (b.color() != color) { |
|
487 | 488 | b.setColor(color); |
|
488 | 489 | setLabelsBrush(b); |
|
489 | 490 | emit labelsColorChanged(color); |
|
490 | 491 | } |
|
491 | 492 | } |
|
492 | 493 | |
|
493 | 494 | QColor QAbstractAxis::labelsColor() const |
|
494 | 495 | { |
|
495 | 496 | return d_ptr->m_labelsBrush.color(); |
|
496 | 497 | } |
|
497 | 498 | |
|
498 | 499 | void QAbstractAxis::setTitleVisible(bool visible) |
|
499 | 500 | { |
|
500 | 501 | if (d_ptr->m_titleVisible != visible) { |
|
501 | 502 | d_ptr->m_titleVisible = visible; |
|
502 | 503 | emit titleVisibleChanged(visible); |
|
503 | 504 | } |
|
504 | 505 | } |
|
505 | 506 | |
|
506 | 507 | bool QAbstractAxis::isTitleVisible() const |
|
507 | 508 | { |
|
508 | 509 | return d_ptr->m_titleVisible; |
|
509 | 510 | } |
|
510 | 511 | |
|
511 | 512 | /*! |
|
512 | 513 | Sets \a pen used to draw title. |
|
513 | 514 | */ |
|
514 | 515 | void QAbstractAxis::setTitlePen(const QPen &pen) |
|
515 | 516 | { |
|
516 | 517 | if (d_ptr->m_titlePen != pen) { |
|
517 | 518 | d_ptr->m_titlePen = pen; |
|
518 | 519 | emit titlePenChanged(pen); |
|
519 | 520 | } |
|
520 | 521 | } |
|
521 | 522 | |
|
522 | 523 | /*! |
|
523 | 524 | Returns the pen used to title. |
|
524 | 525 | */ |
|
525 | 526 | QPen QAbstractAxis::titlePen() const |
|
526 | 527 | { |
|
527 | 528 | return d_ptr->m_titlePen; |
|
528 | 529 | } |
|
529 | 530 | |
|
530 | 531 | /*! |
|
531 | 532 | Sets \a brush used to draw title. |
|
532 | 533 | */ |
|
533 | 534 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
|
534 | 535 | { |
|
535 | 536 | if (d_ptr->m_titleBrush != brush) { |
|
536 | 537 | d_ptr->m_titleBrush = brush; |
|
537 | 538 | emit titleBrushChanged(brush); |
|
538 | 539 | } |
|
539 | 540 | } |
|
540 | 541 | |
|
541 | 542 | /*! |
|
542 | 543 | Returns brush used to draw title. |
|
543 | 544 | */ |
|
544 | 545 | QBrush QAbstractAxis::titleBrush() const |
|
545 | 546 | { |
|
546 | 547 | return d_ptr->m_titleBrush; |
|
547 | 548 | } |
|
548 | 549 | |
|
549 | 550 | /*! |
|
550 | 551 | Sets \a font used to draw title. |
|
551 | 552 | */ |
|
552 | 553 | void QAbstractAxis::setTitleFont(const QFont &font) |
|
553 | 554 | { |
|
554 | 555 | if (d_ptr->m_titleFont != font) { |
|
555 | 556 | d_ptr->m_titleFont = font; |
|
556 | 557 | emit titleFontChanged(font); |
|
557 | 558 | } |
|
558 | 559 | } |
|
559 | 560 | |
|
560 | 561 | /*! |
|
561 | 562 | Returns font used to draw title. |
|
562 | 563 | */ |
|
563 | 564 | QFont QAbstractAxis::titleFont() const |
|
564 | 565 | { |
|
565 | 566 | return d_ptr->m_titleFont; |
|
566 | 567 | } |
|
567 | 568 | |
|
568 | 569 | void QAbstractAxis::setTitleText(const QString &title) |
|
569 | 570 | { |
|
570 | 571 | if (d_ptr->m_title != title) { |
|
571 | 572 | d_ptr->m_title = title; |
|
572 | 573 | emit titleTextChanged(title); |
|
573 | 574 | } |
|
574 | 575 | } |
|
575 | 576 | |
|
576 | 577 | QString QAbstractAxis::titleText() const |
|
577 | 578 | { |
|
578 | 579 | return d_ptr->m_title; |
|
579 | 580 | } |
|
580 | 581 | |
|
581 | 582 | |
|
582 | 583 | void QAbstractAxis::setShadesVisible(bool visible) |
|
583 | 584 | { |
|
584 | 585 | if (d_ptr->m_shadesVisible != visible) { |
|
585 | 586 | d_ptr->m_shadesVisible = visible; |
|
586 | 587 | emit shadesVisibleChanged(visible); |
|
587 | 588 | } |
|
588 | 589 | } |
|
589 | 590 | |
|
590 | 591 | bool QAbstractAxis::shadesVisible() const |
|
591 | 592 | { |
|
592 | 593 | return d_ptr->m_shadesVisible; |
|
593 | 594 | } |
|
594 | 595 | |
|
595 | 596 | /*! |
|
596 | 597 | Sets \a pen used to draw shades. |
|
597 | 598 | */ |
|
598 | 599 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
599 | 600 | { |
|
600 | 601 | if (d_ptr->m_shadesPen != pen) { |
|
601 | 602 | d_ptr->m_shadesPen = pen; |
|
602 | 603 | emit shadesPenChanged(pen); |
|
603 | 604 | } |
|
604 | 605 | } |
|
605 | 606 | |
|
606 | 607 | /*! |
|
607 | 608 | Returns pen used to draw shades. |
|
608 | 609 | */ |
|
609 | 610 | QPen QAbstractAxis::shadesPen() const |
|
610 | 611 | { |
|
611 | 612 | return d_ptr->m_shadesPen; |
|
612 | 613 | } |
|
613 | 614 | |
|
614 | 615 | /*! |
|
615 | 616 | Sets \a brush used to draw shades. |
|
616 | 617 | */ |
|
617 | 618 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
618 | 619 | { |
|
619 | 620 | if (d_ptr->m_shadesBrush != brush) { |
|
620 | 621 | d_ptr->m_shadesBrush = brush; |
|
621 | 622 | emit shadesBrushChanged(brush); |
|
622 | 623 | } |
|
623 | 624 | } |
|
624 | 625 | |
|
625 | 626 | /*! |
|
626 | 627 | Returns brush used to draw shades. |
|
627 | 628 | */ |
|
628 | 629 | QBrush QAbstractAxis::shadesBrush() const |
|
629 | 630 | { |
|
630 | 631 | return d_ptr->m_shadesBrush; |
|
631 | 632 | } |
|
632 | 633 | |
|
633 | 634 | void QAbstractAxis::setShadesColor(QColor color) |
|
634 | 635 | { |
|
635 | 636 | QBrush b = d_ptr->m_shadesBrush; |
|
636 | 637 | if (b.color() != color) { |
|
637 | 638 | b.setColor(color); |
|
638 | 639 | setShadesBrush(b); |
|
639 | 640 | emit shadesColorChanged(color); |
|
640 | 641 | } |
|
641 | 642 | } |
|
642 | 643 | |
|
643 | 644 | QColor QAbstractAxis::shadesColor() const |
|
644 | 645 | { |
|
645 | 646 | return d_ptr->m_shadesBrush.color(); |
|
646 | 647 | } |
|
647 | 648 | |
|
648 | 649 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
649 | 650 | { |
|
650 | 651 | QPen p = d_ptr->m_shadesPen; |
|
651 | 652 | if (p.color() != color) { |
|
652 | 653 | p.setColor(color); |
|
653 | 654 | setShadesPen(p); |
|
654 | 655 | emit shadesColorChanged(color); |
|
655 | 656 | } |
|
656 | 657 | } |
|
657 | 658 | |
|
658 | 659 | QColor QAbstractAxis::shadesBorderColor() const |
|
659 | 660 | { |
|
660 | 661 | return d_ptr->m_shadesPen.color(); |
|
661 | 662 | } |
|
662 | 663 | |
|
663 | 664 | |
|
664 | 665 | bool QAbstractAxis::isVisible() const |
|
665 | 666 | { |
|
666 | 667 | return d_ptr->m_visible; |
|
667 | 668 | } |
|
668 | 669 | |
|
669 | 670 | /*! |
|
670 | 671 | Sets axis, shades, labels and grid lines to be visible. |
|
671 | 672 | */ |
|
672 | 673 | void QAbstractAxis::setVisible(bool visible) |
|
673 | 674 | { |
|
674 | 675 | if (d_ptr->m_visible != visible) { |
|
675 | 676 | d_ptr->m_visible = visible; |
|
676 | 677 | emit visibleChanged(visible); |
|
677 | 678 | } |
|
678 | 679 | } |
|
679 | 680 | |
|
680 | 681 | |
|
681 | 682 | /*! |
|
682 | 683 | Sets axis, shades, labels and grid lines to be visible. |
|
683 | 684 | */ |
|
684 | 685 | void QAbstractAxis::show() |
|
685 | 686 | { |
|
686 | 687 | setVisible(true); |
|
687 | 688 | } |
|
688 | 689 | |
|
689 | 690 | /*! |
|
690 | 691 | Sets axis, shades, labels and grid lines to not be visible. |
|
691 | 692 | */ |
|
692 | 693 | void QAbstractAxis::hide() |
|
693 | 694 | { |
|
694 | 695 | setVisible(false); |
|
695 | 696 | } |
|
696 | 697 | |
|
697 | 698 | /*! |
|
698 | 699 | Sets the minimum value shown on the axis. |
|
699 | 700 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
700 | 701 | If the conversion is impossible then the function call does nothing |
|
701 | 702 | */ |
|
702 | 703 | void QAbstractAxis::setMin(const QVariant &min) |
|
703 | 704 | { |
|
704 | 705 | d_ptr->setMin(min); |
|
705 | 706 | } |
|
706 | 707 | |
|
707 | 708 | /*! |
|
708 | 709 | Sets the maximum value shown on the axis. |
|
709 | 710 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
710 | 711 | If the conversion is impossible then the function call does nothing |
|
711 | 712 | */ |
|
712 | 713 | void QAbstractAxis::setMax(const QVariant &max) |
|
713 | 714 | { |
|
714 | 715 | d_ptr->setMax(max); |
|
715 | 716 | } |
|
716 | 717 | |
|
717 | 718 | /*! |
|
718 | 719 | Sets the range shown on the axis. |
|
719 | 720 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
720 | 721 | If the conversion is impossible then the function call does nothing. |
|
721 | 722 | */ |
|
722 | 723 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
723 | 724 | { |
|
724 | 725 | d_ptr->setRange(min, max); |
|
725 | 726 | } |
|
726 | 727 | |
|
727 | 728 | |
|
728 | 729 | /*! |
|
729 | 730 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
730 | 731 | */ |
|
731 | 732 | // NOTE: should have const but it breaks BC: |
|
732 | 733 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function |
|
733 | 734 | Qt::Orientation QAbstractAxis::orientation() |
|
734 | 735 | { |
|
735 | 736 | return d_ptr->orientation(); |
|
736 | 737 | } |
|
737 | 738 | |
|
738 | 739 | Qt::Alignment QAbstractAxis::alignment() const |
|
739 | 740 | { |
|
740 | 741 | return d_ptr->alignment(); |
|
741 | 742 | } |
|
742 | 743 | |
|
743 | 744 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
744 | 745 | |
|
745 | 746 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
746 | 747 | : q_ptr(q), |
|
747 | 748 | m_chart(0), |
|
748 | 749 | m_alignment(0), |
|
749 | 750 | m_orientation(Qt::Orientation(0)), |
|
750 | 751 | m_visible(true), |
|
751 | 752 | m_arrowVisible(true), |
|
752 | 753 | m_gridLineVisible(true), |
|
753 | 754 | m_labelsVisible(true), |
|
754 | 755 | m_labelsAngle(0), |
|
755 | 756 | m_shadesVisible(false), |
|
756 | 757 | m_shadesBrush(Qt::SolidPattern), |
|
757 | 758 | m_shadesOpacity(1.0), |
|
758 | 759 | m_dirty(false) |
|
759 | 760 | { |
|
760 | 761 | |
|
761 | 762 | } |
|
762 | 763 | |
|
763 | 764 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
764 | 765 | { |
|
765 | 766 | } |
|
766 | 767 | |
|
767 | 768 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
|
768 | 769 | { |
|
769 | 770 | switch(alignment) { |
|
770 | 771 | case Qt::AlignTop: |
|
771 | 772 | case Qt::AlignBottom: |
|
772 | 773 | m_orientation = Qt::Horizontal; |
|
773 | 774 | break; |
|
774 | 775 | case Qt::AlignLeft: |
|
775 | 776 | case Qt::AlignRight: |
|
776 | 777 | m_orientation = Qt::Vertical; |
|
777 | 778 | break; |
|
778 | 779 | default: |
|
779 | 780 | qWarning()<<"No alignment specified !"; |
|
780 | 781 | break; |
|
781 | 782 | }; |
|
782 | 783 | m_alignment=alignment; |
|
783 | 784 | } |
|
784 | 785 | |
|
785 | 786 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
|
786 | 787 | { |
|
787 | 788 | QPen pen; |
|
788 | 789 | QBrush brush; |
|
789 | 790 | QFont font; |
|
790 | 791 | |
|
791 | 792 | bool axisX = m_orientation == Qt::Horizontal; |
|
792 | 793 | |
|
793 | 794 | if (m_arrowVisible) { |
|
794 | 795 | |
|
795 | 796 | if (forced || brush == m_labelsBrush){ |
|
796 | 797 | q_ptr->setLabelsBrush(theme->labelBrush()); |
|
797 | 798 | } |
|
798 | 799 | //TODO: introduce axis brush |
|
799 | 800 | if (forced || brush == m_titleBrush){ |
|
800 | 801 | q_ptr->setTitleBrush(theme->labelBrush()); |
|
801 | 802 | } |
|
802 | 803 | if (forced || pen == m_labelsPen){ |
|
803 | 804 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons |
|
804 | 805 | } |
|
805 | 806 | if (forced || pen == m_titlePen){ |
|
806 | 807 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons |
|
807 | 808 | } |
|
808 | 809 | if (forced || m_shadesVisible) { |
|
809 | 810 | |
|
810 | 811 | if (forced || brush == m_shadesBrush){ |
|
811 | 812 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
|
812 | 813 | } |
|
813 | 814 | if (forced || pen == m_shadesPen){ |
|
814 | 815 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
|
815 | 816 | } |
|
816 | 817 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
|
817 | 818 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
|
818 | 819 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
|
819 | 820 | q_ptr->setShadesVisible(true); |
|
820 | 821 | } |
|
821 | 822 | } |
|
822 | 823 | |
|
823 | 824 | if (forced || pen == m_axisPen) { |
|
824 | 825 | q_ptr->setLinePen(theme->axisLinePen()); |
|
825 | 826 | } |
|
826 | 827 | |
|
827 | 828 | if (forced || pen == m_gridLinePen) { |
|
828 | 829 | q_ptr->setGridLinePen(theme->girdLinePen()); |
|
829 | 830 | } |
|
830 | 831 | |
|
831 | 832 | if (forced || font == m_labelsFont){ |
|
832 | 833 | q_ptr->setLabelsFont(theme->labelFont()); |
|
833 | 834 | } |
|
834 | 835 | //TODO: discuss with Tero |
|
835 | 836 | if (forced || font == m_titleFont){ |
|
836 | 837 | QFont font(m_labelsFont); |
|
837 | 838 | font.setBold(true); |
|
838 | 839 | q_ptr->setTitleFont(font); |
|
839 | 840 | } |
|
840 | 841 | } |
|
841 | 842 | } |
|
842 | 843 | |
|
843 | 844 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
|
844 | 845 | { |
|
845 | 846 | setRange(min,max); |
|
846 | 847 | } |
|
847 | 848 | |
|
848 | 849 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
849 | 850 | { |
|
850 | 851 | Q_UNUSED(parent); |
|
851 | 852 | } |
|
852 | 853 | |
|
853 | 854 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
854 | 855 | { |
|
855 | 856 | ChartAxis* axis = m_item.data(); |
|
856 | 857 | Q_ASSERT(axis); |
|
857 | 858 | if(options.testFlag(QChart::GridAxisAnimations)) { |
|
858 | 859 | axis->setAnimation(new AxisAnimation(axis)); |
|
859 | 860 | }else{ |
|
860 | 861 | axis->setAnimation(0); |
|
861 | 862 | } |
|
862 | 863 | } |
|
863 | 864 | |
|
864 | 865 | |
|
865 | 866 | |
|
866 | 867 | #include "moc_qabstractaxis.cpp" |
|
867 | 868 | #include "moc_qabstractaxis_p.cpp" |
|
868 | 869 | |
|
869 | 870 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,418 +1,427 | |||
|
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 "qvalueaxis.h" |
|
22 | 22 | #include "qvalueaxis_p.h" |
|
23 | 23 | #include "chartvalueaxisx_p.h" |
|
24 | 24 | #include "chartvalueaxisy_p.h" |
|
25 | 25 | #include "abstractdomain_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "chartpresenter_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | /*! |
|
33 | 33 | \class QValueAxis |
|
34 | 34 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
38 | 38 | Values of axis are drawn to position of ticks. |
|
39 | 39 | |
|
40 | 40 | Example code on how to use QValueAxis. |
|
41 | 41 | \code |
|
42 | 42 | QChartView *chartView = new QChartView; |
|
43 | 43 | QLineSeries *series = new QLineSeries; |
|
44 | 44 | // ... |
|
45 | 45 | chartView->chart()->addSeries(series); |
|
46 | 46 | |
|
47 | 47 | QValueAxis *axisX = new QValueAxis; |
|
48 | 48 | axisX->setRange(10, 20.5); |
|
49 | 49 | axisX->setTickCount(10); |
|
50 | 50 | axisX->setLabelFormat("%.2f"); |
|
51 | 51 | chartView->chart()->setAxisX(axisX, series); |
|
52 | 52 | \endcode |
|
53 | 53 | */ |
|
54 | 54 | |
|
55 | 55 | /*! |
|
56 | 56 | \qmlclass ValueAxis QValueAxis |
|
57 | 57 | \inherits AbstractAxis |
|
58 | 58 | \brief The ValueAxis element is used for manipulating chart's axes |
|
59 | 59 | |
|
60 | 60 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
61 | 61 | Values of axis are drawn to position of ticks |
|
62 | 62 | |
|
63 | 63 | To access Axes you can use ChartView API. For example: |
|
64 | 64 | \code |
|
65 | 65 | ChartView { |
|
66 | 66 | ValueAxis { |
|
67 | 67 | id: xAxis |
|
68 | 68 | min: 0 |
|
69 | 69 | max: 10 |
|
70 | 70 | } |
|
71 | 71 | // Add a few series... |
|
72 | 72 | } |
|
73 | 73 | \endcode |
|
74 | 74 | */ |
|
75 | 75 | |
|
76 | 76 | /*! |
|
77 | 77 | \property QValueAxis::min |
|
78 | 78 | Defines the minimum value on the axis. |
|
79 | 79 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
80 | 80 | */ |
|
81 | 81 | /*! |
|
82 | 82 | \qmlproperty real ValueAxis::min |
|
83 | 83 | Defines the minimum value on the axis. |
|
84 | 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 | 88 | \property QValueAxis::max |
|
89 | 89 | Defines the maximum value on the axis. |
|
90 | 90 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
91 | 91 | */ |
|
92 | 92 | /*! |
|
93 | 93 | \qmlproperty real ValueAxis::max |
|
94 | 94 | Defines the maximum value on the axis. |
|
95 | 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 | 99 | \property QValueAxis::tickCount |
|
100 | 100 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. |
|
101 | 101 | The default value is 5, and it can not be below 2. |
|
102 | 102 | */ |
|
103 | 103 | /*! |
|
104 | 104 | \qmlproperty real ValueAxis::tickCount |
|
105 | 105 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. |
|
106 | 106 | The default value is 5, and it can not be below 2. |
|
107 | 107 | */ |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | 110 | \property QValueAxis::labelFormat |
|
111 |
Defines the label format |
|
|
111 | Defines the label format of the axis. | |
|
112 | 112 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
113 | 113 | See QString::sprintf() for additional details. |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | 116 | \qmlproperty real ValueAxis::labelFormat |
|
117 |
Defines the label format |
|
|
117 | Defines the label format of the axis. | |
|
118 | 118 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
119 | 119 | See QString::sprintf() for additional details. |
|
120 | 120 | */ |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | \fn void QValueAxis::minChanged(qreal min) |
|
124 | 124 | Axis emits signal when \a min of axis has changed. |
|
125 | 125 | */ |
|
126 | 126 | /*! |
|
127 | 127 | \qmlsignal ValueAxis::onMinChanged(real min) |
|
128 | 128 | Axis emits signal when \a min of axis has changed. |
|
129 | 129 | */ |
|
130 | 130 | |
|
131 | 131 | /*! |
|
132 | 132 | \fn void QValueAxis::maxChanged(qreal max) |
|
133 | 133 | Axis emits signal when \a max of axis has changed. |
|
134 | 134 | */ |
|
135 | 135 | /*! |
|
136 | 136 | \qmlsignal ValueAxis::onMaxChanged(real max) |
|
137 | 137 | Axis emits signal when \a max of axis has changed. |
|
138 | 138 | */ |
|
139 | 139 | |
|
140 | 140 | /*! |
|
141 | 141 | \fn void QValueAxis::tickCountChanged(int tickCount) |
|
142 |
Axis emits signal when number |
|
|
142 | Axis emits signal when \a tickCount number on axis have changed. | |
|
143 | 143 | */ |
|
144 | 144 | /*! |
|
145 | 145 | \qmlsignal ValueAxis::tickCountChanged(int tickCount) |
|
146 |
Axis emits signal when number |
|
|
146 | Axis emits signal when \a tickCount number on axis have changed. | |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
151 | 151 | Axis emits signal when \a min or \a max of axis has changed. |
|
152 | 152 | */ |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | \fn void QValueAxis::labelFormatChanged(const QString &format) | |
|
156 | Axis emits signal when \a format of axis labels has changed. | |
|
157 | */ | |
|
158 | /*! | |
|
159 | \qmlsignal ValueAxis::labelFormatChanged(const QString &format) | |
|
160 | Axis emits signal when \a format of axis labels has changed. | |
|
161 | */ | |
|
162 | ||
|
163 | /*! | |
|
155 | 164 | \property QValueAxis::niceNumbersEnabled |
|
156 | 165 | \obsolete |
|
157 | 166 | Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead. |
|
158 | 167 | */ |
|
159 | 168 | |
|
160 | 169 | /*! |
|
161 | 170 | \qmlproperty bool ValueAxis::niceNumbersEnabled |
|
162 | 171 | \obsolete |
|
163 | 172 | Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead. |
|
164 | 173 | */ |
|
165 | 174 | |
|
166 | 175 | /*! |
|
167 | 176 | Constructs an axis object which is a child of \a parent. |
|
168 | 177 | */ |
|
169 | 178 | QValueAxis::QValueAxis(QObject *parent) : |
|
170 | 179 | QAbstractAxis(*new QValueAxisPrivate(this), parent) |
|
171 | 180 | { |
|
172 | 181 | |
|
173 | 182 | } |
|
174 | 183 | |
|
175 | 184 | /*! |
|
176 | 185 | \internal |
|
177 | 186 | */ |
|
178 | 187 | QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent) |
|
179 | 188 | : QAbstractAxis(d, parent) |
|
180 | 189 | { |
|
181 | 190 | |
|
182 | 191 | } |
|
183 | 192 | |
|
184 | 193 | /*! |
|
185 | 194 | Destroys the object |
|
186 | 195 | */ |
|
187 | 196 | QValueAxis::~QValueAxis() |
|
188 | 197 | { |
|
189 | 198 | Q_D(QValueAxis); |
|
190 | 199 | if (d->m_chart) |
|
191 | 200 | d->m_chart->removeAxis(this); |
|
192 | 201 | } |
|
193 | 202 | |
|
194 | 203 | void QValueAxis::setMin(qreal min) |
|
195 | 204 | { |
|
196 | 205 | Q_D(QValueAxis); |
|
197 | 206 | setRange(min, qMax(d->m_max, min)); |
|
198 | 207 | } |
|
199 | 208 | |
|
200 | 209 | qreal QValueAxis::min() const |
|
201 | 210 | { |
|
202 | 211 | Q_D(const QValueAxis); |
|
203 | 212 | return d->m_min; |
|
204 | 213 | } |
|
205 | 214 | |
|
206 | 215 | void QValueAxis::setMax(qreal max) |
|
207 | 216 | { |
|
208 | 217 | Q_D(QValueAxis); |
|
209 | 218 | setRange(qMin(d->m_min, max), max); |
|
210 | 219 | } |
|
211 | 220 | |
|
212 | 221 | qreal QValueAxis::max() const |
|
213 | 222 | { |
|
214 | 223 | Q_D(const QValueAxis); |
|
215 | 224 | return d->m_max; |
|
216 | 225 | } |
|
217 | 226 | |
|
218 | 227 | /*! |
|
219 | 228 | Sets range from \a min to \a max on the axis. |
|
220 | 229 | If min is greater than max then this function returns without making any changes. |
|
221 | 230 | */ |
|
222 | 231 | void QValueAxis::setRange(qreal min, qreal max) |
|
223 | 232 | { |
|
224 | 233 | Q_D(QValueAxis); |
|
225 | 234 | d->setRange(min,max); |
|
226 | 235 | } |
|
227 | 236 | |
|
228 | 237 | void QValueAxis::setTickCount(int count) |
|
229 | 238 | { |
|
230 | 239 | Q_D(QValueAxis); |
|
231 | 240 | if (d->m_tickCount != count && count >= 2) { |
|
232 | 241 | d->m_tickCount = count; |
|
233 | 242 | emit tickCountChanged(count); |
|
234 | 243 | } |
|
235 | 244 | } |
|
236 | 245 | |
|
237 | 246 | int QValueAxis::tickCount() const |
|
238 | 247 | { |
|
239 | 248 | Q_D(const QValueAxis); |
|
240 | 249 | return d->m_tickCount; |
|
241 | 250 | } |
|
242 | 251 | |
|
243 | 252 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
244 | 253 | { |
|
245 | 254 | Q_D(QValueAxis); |
|
246 | 255 | qWarning()<<"This function is depreciated, it can lead to unexpected behavior.Use applyNiceNumbers(). "; |
|
247 | 256 | if(enable) { |
|
248 | 257 | QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); |
|
249 | 258 | QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); |
|
250 | 259 | applyNiceNumbers(); |
|
251 | 260 | } |
|
252 | 261 | else { |
|
253 | 262 | QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); |
|
254 | 263 | QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); |
|
255 | 264 | } |
|
256 | 265 | d->m_niceNumbersEnabled=enable; |
|
257 | 266 | } |
|
258 | 267 | |
|
259 | 268 | bool QValueAxis::niceNumbersEnabled() const |
|
260 | 269 | { |
|
261 | 270 | Q_D(const QValueAxis); |
|
262 | 271 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; |
|
263 | 272 | return d->m_niceNumbersEnabled; |
|
264 | 273 | } |
|
265 | 274 | |
|
266 | 275 | void QValueAxis::setLabelFormat(const QString &format) |
|
267 | 276 | { |
|
268 | 277 | Q_D(QValueAxis); |
|
269 | 278 | d->m_format = format; |
|
270 | 279 | emit labelFormatChanged(format); |
|
271 | 280 | } |
|
272 | 281 | |
|
273 | 282 | QString QValueAxis::labelFormat() const |
|
274 | 283 | { |
|
275 | 284 | Q_D(const QValueAxis); |
|
276 | 285 | return d->m_format; |
|
277 | 286 | } |
|
278 | 287 | |
|
279 | 288 | /*! |
|
280 | 289 | Returns the type of the axis |
|
281 | 290 | */ |
|
282 | 291 | QAbstractAxis::AxisType QValueAxis::type() const |
|
283 | 292 | { |
|
284 | 293 | return AxisTypeValue; |
|
285 | 294 | } |
|
286 | 295 | |
|
287 | 296 | /*! |
|
288 | 297 | This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that |
|
289 | 298 | 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. |
|
290 | 299 | This method will modify the current range and number of ticks. |
|
291 |
\sa setRange(), setTick |
|
|
300 | \sa setRange(), setTickCount() | |
|
292 | 301 | */ |
|
293 | 302 | void QValueAxis::applyNiceNumbers() |
|
294 | 303 | { |
|
295 | 304 | Q_D(QValueAxis); |
|
296 | 305 | if(d->m_applying) return; |
|
297 | 306 | qreal min = d->m_min; |
|
298 | 307 | qreal max = d->m_max; |
|
299 | 308 | int ticks = d->m_tickCount; |
|
300 | 309 | AbstractDomain::looseNiceNumbers(min,max,ticks); |
|
301 | 310 | d->m_applying=true; |
|
302 | 311 | d->setRange(min,max); |
|
303 | 312 | setTickCount(ticks); |
|
304 | 313 | d->m_applying=false; |
|
305 | 314 | } |
|
306 | 315 | |
|
307 | 316 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
308 | 317 | |
|
309 | 318 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) |
|
310 | 319 | : QAbstractAxisPrivate(q), |
|
311 | 320 | m_min(0), |
|
312 | 321 | m_max(0), |
|
313 | 322 | m_tickCount(5), |
|
314 | 323 | m_format(QString::null), |
|
315 | 324 | m_applying(false), |
|
316 | 325 | m_niceNumbersEnabled(false) |
|
317 | 326 | { |
|
318 | 327 | |
|
319 | 328 | } |
|
320 | 329 | |
|
321 | 330 | QValueAxisPrivate::~QValueAxisPrivate() |
|
322 | 331 | { |
|
323 | 332 | |
|
324 | 333 | } |
|
325 | 334 | |
|
326 | 335 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
327 | 336 | { |
|
328 | 337 | Q_Q(QValueAxis); |
|
329 | 338 | bool ok; |
|
330 | 339 | qreal value = min.toReal(&ok); |
|
331 | 340 | if (ok) |
|
332 | 341 | q->setMin(value); |
|
333 | 342 | } |
|
334 | 343 | |
|
335 | 344 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
336 | 345 | { |
|
337 | 346 | Q_Q(QValueAxis); |
|
338 | 347 | bool ok; |
|
339 | 348 | qreal value = max.toReal(&ok); |
|
340 | 349 | if (ok) |
|
341 | 350 | q->setMax(value); |
|
342 | 351 | } |
|
343 | 352 | |
|
344 | 353 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
345 | 354 | { |
|
346 | 355 | Q_Q(QValueAxis); |
|
347 | 356 | bool ok1; |
|
348 | 357 | bool ok2; |
|
349 | 358 | qreal value1 = min.toReal(&ok1); |
|
350 | 359 | qreal value2 = max.toReal(&ok2); |
|
351 | 360 | if (ok1 && ok2) |
|
352 | 361 | q->setRange(value1, value2); |
|
353 | 362 | } |
|
354 | 363 | |
|
355 | 364 | void QValueAxisPrivate::setRange(qreal min, qreal max) |
|
356 | 365 | { |
|
357 | 366 | Q_Q(QValueAxis); |
|
358 | 367 | bool changed = false; |
|
359 | 368 | |
|
360 | 369 | if (min > max) |
|
361 | 370 | return; |
|
362 | 371 | |
|
363 | 372 | if (!qFuzzyCompare(m_min,min)) { |
|
364 | 373 | m_min = min; |
|
365 | 374 | changed = true; |
|
366 | 375 | emit q->minChanged(min); |
|
367 | 376 | } |
|
368 | 377 | |
|
369 | 378 | if (!qFuzzyCompare(m_max,max)) { |
|
370 | 379 | m_max = max; |
|
371 | 380 | changed = true; |
|
372 | 381 | emit q->maxChanged(max); |
|
373 | 382 | } |
|
374 | 383 | |
|
375 | 384 | if (changed) { |
|
376 | 385 | emit rangeChanged(min,max); |
|
377 | 386 | emit q->rangeChanged(min, max); |
|
378 | 387 | } |
|
379 | 388 | } |
|
380 | 389 | |
|
381 | 390 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
382 | 391 | { |
|
383 | 392 | Q_Q(QValueAxis); |
|
384 | 393 | ChartAxis* axis(0); |
|
385 | 394 | if (orientation() == Qt::Vertical) |
|
386 | 395 | axis = new ChartValueAxisY(q,parent); |
|
387 | 396 | if (orientation() == Qt::Horizontal) |
|
388 | 397 | axis = new ChartValueAxisX(q,parent); |
|
389 | 398 | |
|
390 | 399 | m_item.reset(axis); |
|
391 | 400 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
392 | 401 | } |
|
393 | 402 | |
|
394 | 403 | |
|
395 | 404 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
396 | 405 | { |
|
397 | 406 | if (orientation() == Qt::Vertical) { |
|
398 | 407 | if(!qFuzzyIsNull(m_max - m_min)) { |
|
399 | 408 | domain->setRangeY(m_min, m_max); |
|
400 | 409 | } |
|
401 | 410 | else { |
|
402 | 411 | setRange(domain->minY(), domain->maxY()); |
|
403 | 412 | } |
|
404 | 413 | } |
|
405 | 414 | if (orientation() == Qt::Horizontal) { |
|
406 | 415 | if(!qFuzzyIsNull(m_max - m_min)) { |
|
407 | 416 | domain->setRangeX(m_min, m_max); |
|
408 | 417 | } |
|
409 | 418 | else { |
|
410 | 419 | setRange(domain->minX(), domain->maxX()); |
|
411 | 420 | } |
|
412 | 421 | } |
|
413 | 422 | } |
|
414 | 423 | |
|
415 | 424 | #include "moc_qvalueaxis.cpp" |
|
416 | 425 | #include "moc_qvalueaxis_p.cpp" |
|
417 | 426 | |
|
418 | 427 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now