@@ -1,90 +1,90 | |||
|
1 | 1 | /*! |
|
2 | 2 | \page classes.html |
|
3 | 3 | \title QtCommercial Charts API |
|
4 | 4 | \keyword All Classes |
|
5 | 5 | |
|
6 | 6 | Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However |
|
7 | 7 | there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget. |
|
8 | 8 | |
|
9 | 9 | Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance. |
|
10 | 10 | \code |
|
11 | 11 | QLineSeries* series = new QLineSeries(); |
|
12 | 12 | series->add(0, 6); |
|
13 | 13 | series->add(2, 4); |
|
14 | 14 | ... |
|
15 | 15 | chartView->chart()->addSeries(series); |
|
16 | 16 | chartView->chart()->createDefaultAxes(); |
|
17 | 17 | \endcode |
|
18 | 18 | |
|
19 | 19 | \raw HTML |
|
20 | 20 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
21 | 21 | <tr> |
|
22 | 22 | <th class="titleheader" width="25%"> |
|
23 | 23 | Common and global |
|
24 | 24 | </th> |
|
25 | 25 | <th class="titleheader" width="25%"> |
|
26 | 26 | XY chart |
|
27 | 27 | </th> |
|
28 | 28 | </tr> |
|
29 | 29 | <tr> |
|
30 | 30 | <td valign="top"> |
|
31 | 31 | <ul> |
|
32 | 32 | <li><a href="qchart.html">QChart</a></li> |
|
33 | 33 | <li><a href="qchartview.html">QChartView</a></li> |
|
34 | 34 | <li><a href="qabstractaxis.html">QAbstractAxis</a></li> |
|
35 |
<li><a href="qvalue |
|
|
36 |
<li><a href="qbarcategor |
|
|
35 | <li><a href="qvalueaxis.html">QValueAxis</a></li> | |
|
36 | <li><a href="qbarcategoryaxis.html">QBarCategoryAxis</a></li> | |
|
37 | 37 | <li><a href="qintervalsaxis.html">QIntervalsAxis</a></li> |
|
38 | 38 | <li><a href="qlegend.html">QLegend</a></li> |
|
39 | 39 | <li><a href="qabstractseries.html">QAbstractSeries</a></li> |
|
40 | 40 | <li><a href="qchartglobal.html">QChartGlobal</a></li> |
|
41 | 41 | </ul> |
|
42 | 42 | </td> |
|
43 | 43 | <td valign="top"> |
|
44 | 44 | <ul> |
|
45 | 45 | <li><a href="qxyseries.html">QXYSeries</a></li> |
|
46 | 46 | <li><a href="qlineseries.html">QLineSeries</a></li> |
|
47 | 47 | <li><a href="qareaseries.html">QAreaSeries</a></li> |
|
48 | 48 | <li><a href="qscatterseries.html">QScatterSeries</a></li> |
|
49 | 49 | <li><a href="qsplineseries.html">QSplineSeries</a></li> |
|
50 | 50 | <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li> |
|
51 | 51 | <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li> |
|
52 | 52 | </ul> |
|
53 | 53 | </td> |
|
54 | 54 | </tr> |
|
55 | 55 | </table> |
|
56 | 56 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
57 | 57 | <tr> |
|
58 | 58 | <th class="titleheader" width="25%"> |
|
59 | 59 | Pie chart |
|
60 | 60 | </th> |
|
61 | 61 | <th class="titleheader" width="25%"> |
|
62 | 62 | Bar chart |
|
63 | 63 | </th> |
|
64 | 64 | <tr> |
|
65 | 65 | <td valign="top"> |
|
66 | 66 | <ul> |
|
67 | 67 | <li><a href="qpieseries.html">QPieSeries</a></li> |
|
68 | 68 | <li><a href="qpieslice.html">QPieSlice</a></li> |
|
69 | 69 | <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li> |
|
70 | 70 | <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li> |
|
71 | 71 | </ul> |
|
72 | 72 | </td> |
|
73 | 73 | <td valign="top"> |
|
74 | 74 | <ul> |
|
75 | 75 | <li><a href="qbarseries.html">QBarSeries</a></li> |
|
76 | 76 | <li><a href="qbarset.html">QBarSet</a></li> |
|
77 | 77 | <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li> |
|
78 | 78 | <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li> |
|
79 | 79 | <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li> |
|
80 | 80 | <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li> |
|
81 | 81 | <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li> |
|
82 | 82 | <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li> |
|
83 | 83 | <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li> |
|
84 | 84 | </ul> |
|
85 | 85 | </td> |
|
86 | 86 | </tr> |
|
87 | 87 | </table> |
|
88 | 88 | \endraw |
|
89 | 89 | |
|
90 | 90 | */ |
@@ -1,322 +1,322 | |||
|
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 "domain_p.h" |
|
26 | 26 | #include <cmath> |
|
27 | 27 | #include <QDebug> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | /*! |
|
31 | 31 | \class QDateTimeAxis |
|
32 | 32 | \brief The QDateTimeAxis class is used for manipulating chart's axis. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | The labels can be configured by setting an appropriate DateTime format. |
|
36 | 36 | Note that any date before 4800 BCE or after about 1.4 million CE may not be accurately stored. |
|
37 | 37 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
38 | 38 | */ |
|
39 | 39 | |
|
40 | 40 | /*! |
|
41 | 41 | \qmlclass DateTimeAxis QDateTimeAxis |
|
42 | 42 | \brief The DateTimeAxis element is used for manipulating chart's axes |
|
43 | 43 | |
|
44 | 44 | The labels can be configured by setting an appropriate DateTime format. |
|
45 | 45 | Note that any date before 4800 BCE or after about 1.4 million CE may not be accurately stored. |
|
46 | 46 | DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \property QDateTimeAxis::min |
|
51 | 51 | Defines the minimum value on the axis. |
|
52 | 52 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
53 | 53 | */ |
|
54 | 54 | /*! |
|
55 | 55 | \qmlproperty real ValuesAxis::min |
|
56 | 56 | Defines the minimum value on the axis. |
|
57 | 57 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \property QDateTimeAxis::max |
|
62 | 62 | Defines the maximum value on the axis. |
|
63 | 63 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
64 | 64 | */ |
|
65 | 65 | /*! |
|
66 | 66 | \qmlproperty real ValuesAxis::max |
|
67 | 67 | Defines the maximum value on the axis. |
|
68 | 68 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \fn void QDateTimeAxis::minChanged(QDateTime min) |
|
73 | 73 | Axis emits signal when \a min of axis has changed. |
|
74 | 74 | */ |
|
75 | 75 | /*! |
|
76 | 76 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) |
|
77 | 77 | Axis emits signal when \a min of axis has changed. |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \fn void QDateTimeAxis::maxChanged(QDateTime max) |
|
82 | 82 | Axis emits signal when \a max of axis has changed. |
|
83 | 83 | */ |
|
84 | 84 | /*! |
|
85 | 85 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) |
|
86 | 86 | Axis emits signal when \a max of axis has changed. |
|
87 | 87 | */ |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) |
|
91 | 91 | Axis emits signal when \a min or \a max of axis has changed. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 |
\property QDateTimeAxis::tick |
|
|
95 | \property QDateTimeAxis::tickCount | |
|
96 | 96 | The number of tick marks for the axis. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 |
\qmlproperty int ValuesAxis::tick |
|
|
100 | \qmlproperty int ValuesAxis::tickCount | |
|
101 | 101 | The number of tick marks for the axis. |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | Constructs an axis object which is a child of \a parent. |
|
106 | 106 | */ |
|
107 | 107 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : |
|
108 | 108 | QAbstractAxis(*new QDateTimeAxisPrivate(this),parent) |
|
109 | 109 | { |
|
110 | 110 | |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | /*! |
|
114 | 114 | \internal |
|
115 | 115 | */ |
|
116 | 116 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
117 | 117 | { |
|
118 | 118 | |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | /*! |
|
122 | 122 | Destroys the object |
|
123 | 123 | */ |
|
124 | 124 | QDateTimeAxis::~QDateTimeAxis() |
|
125 | 125 | { |
|
126 | 126 | |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | void QDateTimeAxis::setMin(QDateTime min) |
|
130 | 130 | { |
|
131 | 131 | Q_D(QDateTimeAxis); |
|
132 | 132 | if (min.isValid()) |
|
133 | 133 | setRange(min, qMax(d->m_max, min)); |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | QDateTime QDateTimeAxis::min() const |
|
137 | 137 | { |
|
138 | 138 | Q_D(const QDateTimeAxis); |
|
139 | 139 | return d->m_min; |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | void QDateTimeAxis::setMax(QDateTime max) |
|
143 | 143 | { |
|
144 | 144 | Q_D(QDateTimeAxis); |
|
145 | 145 | if (max.isValid()) |
|
146 | 146 | setRange(qMin(d->m_min, max), max); |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | 149 | QDateTime QDateTimeAxis::max() const |
|
150 | 150 | { |
|
151 | 151 | Q_D(const QDateTimeAxis); |
|
152 | 152 | return d->m_max; |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | Sets range from \a min to \a max on the axis. |
|
157 | 157 | If min is greater than max then this function returns without making any changes. |
|
158 | 158 | */ |
|
159 | 159 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) |
|
160 | 160 | { |
|
161 | 161 | Q_D(QDateTimeAxis); |
|
162 | 162 | if (!min.isValid() || !max.isValid() || min > max) |
|
163 | 163 | return; |
|
164 | 164 | |
|
165 | 165 | bool changed = false; |
|
166 | 166 | if (d->m_min != min) { |
|
167 | 167 | d->m_min = min; |
|
168 | 168 | changed = true; |
|
169 | 169 | emit minChanged(min); |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | if (d->m_max != max) { |
|
173 | 173 | d->m_max = max; |
|
174 | 174 | changed = true; |
|
175 | 175 | emit maxChanged(max); |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | // if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount); |
|
179 | 179 | |
|
180 | 180 | if (changed) { |
|
181 | 181 | emit rangeChanged(d->m_min,d->m_max); |
|
182 | 182 | d->emitUpdated(); |
|
183 | 183 | } |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | 187 | Sets \a format string that is used when creating label for the axis out of the QDateTime object. |
|
188 | 188 | Check QDateTime documentation for information on how the string should be defined. |
|
189 |
\sa format |
|
|
189 | \sa format() | |
|
190 | 190 | */ |
|
191 | 191 | void QDateTimeAxis::setFormat(QString format) |
|
192 | 192 | { |
|
193 | 193 | Q_D(QDateTimeAxis); |
|
194 | 194 | d->m_format = format; |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | /*! |
|
198 | 198 | Returns the format string that is used when creating label for the axis out of the QDateTime object. |
|
199 | 199 | Check QDateTime documentation for information on how the string should be defined. |
|
200 |
\sa setFormat |
|
|
200 | \sa setFormat() | |
|
201 | 201 | */ |
|
202 | 202 | QString QDateTimeAxis::format() const |
|
203 | 203 | { |
|
204 | 204 | Q_D(const QDateTimeAxis); |
|
205 | 205 | return d->m_format; |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | /*! |
|
209 | 209 | Sets \a count for ticks on the axis. |
|
210 | 210 | */ |
|
211 | 211 | void QDateTimeAxis::setTickCount(int count) |
|
212 | 212 | { |
|
213 | 213 | Q_D(QDateTimeAxis); |
|
214 | 214 | if (d->m_tickCount != count && count >=2) { |
|
215 | 215 | d->m_tickCount = count; |
|
216 | 216 | d->emitUpdated(); |
|
217 | 217 | } |
|
218 | 218 | } |
|
219 | 219 | |
|
220 | 220 | /*! |
|
221 |
\fn int QDateTimeAxis::tick |
|
|
221 | \fn int QDateTimeAxis::tickCount() const | |
|
222 | 222 | Return number of ticks on the axis |
|
223 | 223 | */ |
|
224 | 224 | int QDateTimeAxis::tickCount() const |
|
225 | 225 | { |
|
226 | 226 | Q_D(const QDateTimeAxis); |
|
227 | 227 | return d->m_tickCount; |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | /*! |
|
231 | 231 | Returns the type of the axis |
|
232 | 232 | */ |
|
233 | 233 | QAbstractAxis::AxisType QDateTimeAxis::type() const |
|
234 | 234 | { |
|
235 | 235 | return AxisTypeDateTime; |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
239 | 239 | |
|
240 | 240 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q): |
|
241 | 241 | QAbstractAxisPrivate(q), |
|
242 | 242 | m_tickCount(5) |
|
243 | 243 | { |
|
244 | 244 | m_min = QDateTime::fromMSecsSinceEpoch(0); |
|
245 | 245 | m_max = QDateTime::fromMSecsSinceEpoch(0); |
|
246 | 246 | m_format = "dd-MMM-yy\nh:mm"; |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
|
250 | 250 | { |
|
251 | 251 | |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | void QDateTimeAxisPrivate::handleDomainUpdated() |
|
255 | 255 | { |
|
256 | 256 | Q_Q(QDateTimeAxis); |
|
257 | 257 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
258 | 258 | Q_ASSERT(domain); |
|
259 | 259 | |
|
260 | 260 | if(orientation()==Qt::Horizontal){ |
|
261 | 261 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
262 | 262 | }else if(orientation()==Qt::Vertical){ |
|
263 | 263 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
264 | 264 | } |
|
265 | 265 | } |
|
266 | 266 | |
|
267 | 267 | |
|
268 | 268 | void QDateTimeAxisPrivate::setMin(const QVariant &min) |
|
269 | 269 | { |
|
270 | 270 | Q_Q(QDateTimeAxis); |
|
271 | 271 | if (min.canConvert(QVariant::DateTime)) |
|
272 | 272 | q->setMin(min.toDateTime()); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | void QDateTimeAxisPrivate::setMax(const QVariant &max) |
|
276 | 276 | { |
|
277 | 277 | |
|
278 | 278 | Q_Q(QDateTimeAxis); |
|
279 | 279 | if (max.canConvert(QVariant::DateTime)) |
|
280 | 280 | q->setMax(max.toDateTime()); |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
284 | 284 | { |
|
285 | 285 | Q_Q(QDateTimeAxis); |
|
286 | 286 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) |
|
287 | 287 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
288 | 288 | } |
|
289 | 289 | |
|
290 | 290 | ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
291 | 291 | { |
|
292 | 292 | Q_Q(QDateTimeAxis); |
|
293 | 293 | if(m_orientation == Qt::Vertical){ |
|
294 | 294 | return new ChartDateTimeAxisY(q,presenter); |
|
295 | 295 | }else{ |
|
296 | 296 | return new ChartDateTimeAxisX(q,presenter); |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | void QDateTimeAxisPrivate::intializeDomain(Domain* domain) |
|
302 | 302 | { |
|
303 | 303 | Q_Q(QDateTimeAxis); |
|
304 | 304 | if(m_max == m_min) { |
|
305 | 305 | if(m_orientation==Qt::Vertical){ |
|
306 | 306 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY())); |
|
307 | 307 | }else{ |
|
308 | 308 | q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX())); |
|
309 | 309 | } |
|
310 | 310 | } else { |
|
311 | 311 | if(m_orientation==Qt::Vertical){ |
|
312 | 312 | domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); |
|
313 | 313 | }else{ |
|
314 | 314 | domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch()); |
|
315 | 315 | } |
|
316 | 316 | } |
|
317 | 317 | } |
|
318 | 318 | |
|
319 | 319 | #include "moc_qdatetimeaxis.cpp" |
|
320 | 320 | #include "moc_qdatetimeaxis_p.cpp" |
|
321 | 321 | |
|
322 | 322 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,384 +1,384 | |||
|
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 "domain_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include <qmath.h> |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | /*! |
|
32 | 32 | \class QValueAxis |
|
33 | 33 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 |
Value |
|
|
36 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
|
37 | 37 | Values of axis are drawn to position of ticks |
|
38 | 38 | */ |
|
39 | 39 | |
|
40 | 40 | /*! |
|
41 |
\qmlclass Value |
|
|
42 |
\brief The Value |
|
|
41 | \qmlclass ValueAxis QValueAxis | |
|
42 | \brief The ValueAxis element is used for manipulating chart's axes | |
|
43 | 43 | |
|
44 | 44 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
45 | 45 | Values of axis are drawn to position of ticks |
|
46 | 46 | |
|
47 | 47 | To access Axes you can use ChartView API. For example: |
|
48 | 48 | \code |
|
49 | 49 | ChartView { |
|
50 |
Value |
|
|
50 | ValueAxis { | |
|
51 | 51 | id: xAxis |
|
52 | 52 | min: 0 |
|
53 | 53 | max: 10 |
|
54 | 54 | } |
|
55 | 55 | // Add a few series... |
|
56 | 56 | } |
|
57 | 57 | \endcode |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \property QValueAxis::min |
|
62 | 62 | Defines the minimum value on the axis. |
|
63 | 63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
64 | 64 | */ |
|
65 | 65 | /*! |
|
66 |
\qmlproperty real Value |
|
|
66 | \qmlproperty real ValueAxis::min | |
|
67 | 67 | Defines the minimum value on the axis. |
|
68 | 68 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \property QValueAxis::max |
|
73 | 73 | Defines the maximum value on the axis. |
|
74 | 74 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
75 | 75 | */ |
|
76 | 76 | /*! |
|
77 |
\qmlproperty real Value |
|
|
77 | \qmlproperty real ValueAxis::max | |
|
78 | 78 | Defines the maximum value on the axis. |
|
79 | 79 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
80 | 80 | */ |
|
81 | 81 | |
|
82 | 82 | /*! |
|
83 | 83 | \fn void QValueAxis::minChanged(qreal min) |
|
84 | 84 | Axis emits signal when \a min of axis has changed. |
|
85 | 85 | */ |
|
86 | 86 | /*! |
|
87 |
\qmlsignal Value |
|
|
87 | \qmlsignal ValueAxis::onMinChanged(real min) | |
|
88 | 88 | Axis emits signal when \a min of axis has changed. |
|
89 | 89 | */ |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | \fn void QValueAxis::maxChanged(qreal max) |
|
93 | 93 | Axis emits signal when \a max of axis has changed. |
|
94 | 94 | */ |
|
95 | 95 | /*! |
|
96 |
\qmlsignal Value |
|
|
96 | \qmlsignal ValueAxis::onMaxChanged(real max) | |
|
97 | 97 | Axis emits signal when \a max of axis has changed. |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
102 | 102 | Axis emits signal when \a min or \a max of axis has changed. |
|
103 | 103 | */ |
|
104 | 104 | |
|
105 | 105 | /*! |
|
106 |
\property QValueAxis::tick |
|
|
106 | \property QValueAxis::tickCount | |
|
107 | 107 | The number of tick marks for the axis. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 |
\qmlproperty int Value |
|
|
111 | \qmlproperty int ValueAxis::tickCount | |
|
112 | 112 | The number of tick marks for the axis. |
|
113 | 113 | */ |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | \property QValueAxis::niceNumbersEnabled |
|
117 | 117 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
118 | 118 | */ |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 |
\qmlproperty bool Value |
|
|
121 | \qmlproperty bool ValueAxis::niceNumbersEnabled | |
|
122 | 122 | Whether the nice numbers algorithm is enabled or not for the axis. |
|
123 | 123 | */ |
|
124 | 124 | |
|
125 | 125 | /*! |
|
126 | 126 | Constructs an axis object which is a child of \a parent. |
|
127 | 127 | */ |
|
128 | 128 | QValueAxis::QValueAxis(QObject *parent) : |
|
129 | 129 | QAbstractAxis(*new QValueAxisPrivate(this),parent) |
|
130 | 130 | { |
|
131 | 131 | |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \internal |
|
136 | 136 | */ |
|
137 | 137 | QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent) |
|
138 | 138 | { |
|
139 | 139 | |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | Destroys the object |
|
144 | 144 | */ |
|
145 | 145 | QValueAxis::~QValueAxis() |
|
146 | 146 | { |
|
147 | 147 | Q_D(QValueAxis); |
|
148 | 148 | if(d->m_dataset) { |
|
149 | 149 | d->m_dataset->removeAxis(this); |
|
150 | 150 | } |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | void QValueAxis::setMin(qreal min) |
|
154 | 154 | { |
|
155 | 155 | Q_D(QValueAxis); |
|
156 | 156 | setRange(min, qMax(d->m_max, min)); |
|
157 | 157 | } |
|
158 | 158 | |
|
159 | 159 | qreal QValueAxis::min() const |
|
160 | 160 | { |
|
161 | 161 | Q_D(const QValueAxis); |
|
162 | 162 | return d->m_min; |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | void QValueAxis::setMax(qreal max) |
|
166 | 166 | { |
|
167 | 167 | Q_D(QValueAxis); |
|
168 | 168 | setRange(qMin(d->m_min, max), max); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | qreal QValueAxis::max() const |
|
172 | 172 | { |
|
173 | 173 | Q_D(const QValueAxis); |
|
174 | 174 | return d->m_max; |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | Sets range from \a min to \a max on the axis. |
|
179 | 179 | If min is greater than max then this function returns without making any changes. |
|
180 | 180 | */ |
|
181 | 181 | void QValueAxis::setRange(qreal min, qreal max) |
|
182 | 182 | { |
|
183 | 183 | Q_D(QValueAxis); |
|
184 | 184 | bool changed = false; |
|
185 | 185 | |
|
186 | 186 | if (min > max) return; |
|
187 | 187 | |
|
188 | 188 | if(d->m_niceNumbers) { |
|
189 | 189 | int ticks = d->m_tickCount; |
|
190 | 190 | d->looseNiceNumbers(min, max, ticks); |
|
191 | 191 | if(ticks!=d->m_tickCount) setTickCount(ticks); |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | if (!qFuzzyIsNull(d->m_min - min)) { |
|
195 | 195 | d->m_min = min; |
|
196 | 196 | changed = true; |
|
197 | 197 | emit minChanged(min); |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | if (!qFuzzyIsNull(d->m_max - max)) { |
|
201 | 201 | d->m_max = max; |
|
202 | 202 | changed = true; |
|
203 | 203 | emit maxChanged(max); |
|
204 | 204 | } |
|
205 | 205 | |
|
206 | 206 | if (changed) { |
|
207 | 207 | emit rangeChanged(min,max); |
|
208 | 208 | d->emitUpdated(); |
|
209 | 209 | } |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | /*! |
|
213 | 213 | Sets \a count for ticks on the axis. |
|
214 | 214 | */ |
|
215 | 215 | void QValueAxis::setTickCount(int count) |
|
216 | 216 | { |
|
217 | 217 | Q_D(QValueAxis); |
|
218 | 218 | if (d->m_tickCount != count && count >=2) { |
|
219 | 219 | d->m_tickCount = count; |
|
220 | 220 | d->emitUpdated(); |
|
221 | 221 | } |
|
222 | 222 | } |
|
223 | 223 | |
|
224 | 224 | /*! |
|
225 |
\fn int QValueAxis::tick |
|
|
225 | \fn int QValueAxis::tickCount() const | |
|
226 | 226 | Return number of ticks on the axis |
|
227 | 227 | */ |
|
228 | 228 | int QValueAxis::tickCount() const |
|
229 | 229 | { |
|
230 | 230 | Q_D(const QValueAxis); |
|
231 | 231 | return d->m_tickCount; |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
235 | 235 | { |
|
236 | 236 | Q_D(QValueAxis); |
|
237 | 237 | if (d->m_niceNumbers != enable){ |
|
238 | 238 | d->m_niceNumbers = enable; |
|
239 | 239 | if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) { |
|
240 | 240 | setRange(d->m_min,d->m_max); |
|
241 | 241 | } |
|
242 | 242 | } |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | bool QValueAxis::niceNumbersEnabled() const |
|
246 | 246 | { |
|
247 | 247 | Q_D(const QValueAxis); |
|
248 | 248 | return d->m_niceNumbers; |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | /*! |
|
252 | 252 | Returns the type of the axis |
|
253 | 253 | */ |
|
254 | 254 | QAbstractAxis::AxisType QValueAxis::type() const |
|
255 | 255 | { |
|
256 | 256 | return AxisTypeValues; |
|
257 | 257 | } |
|
258 | 258 | |
|
259 | 259 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
260 | 260 | |
|
261 | 261 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q): |
|
262 | 262 | QAbstractAxisPrivate(q), |
|
263 | 263 | m_min(0), |
|
264 | 264 | m_max(0), |
|
265 | 265 | m_tickCount(5), |
|
266 | 266 | m_niceNumbers(false) |
|
267 | 267 | { |
|
268 | 268 | |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | QValueAxisPrivate::~QValueAxisPrivate() |
|
272 | 272 | { |
|
273 | 273 | |
|
274 | 274 | } |
|
275 | 275 | |
|
276 | 276 | void QValueAxisPrivate::handleDomainUpdated() |
|
277 | 277 | { |
|
278 | 278 | Q_Q(QValueAxis); |
|
279 | 279 | Domain* domain = qobject_cast<Domain*>(sender()); |
|
280 | 280 | Q_ASSERT(domain); |
|
281 | 281 | |
|
282 | 282 | if(orientation()==Qt::Horizontal){ |
|
283 | 283 | q->setRange(domain->minX(),domain->maxX()); |
|
284 | 284 | }else if(orientation()==Qt::Vertical){ |
|
285 | 285 | q->setRange(domain->minY(),domain->maxY()); |
|
286 | 286 | } |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | |
|
290 | 290 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
291 | 291 | { |
|
292 | 292 | Q_Q(QValueAxis); |
|
293 | 293 | bool ok; |
|
294 | 294 | qreal value = min.toReal(&ok); |
|
295 | 295 | if(ok) q->setMin(value); |
|
296 | 296 | } |
|
297 | 297 | |
|
298 | 298 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
299 | 299 | { |
|
300 | 300 | |
|
301 | 301 | Q_Q(QValueAxis); |
|
302 | 302 | bool ok; |
|
303 | 303 | qreal value = max.toReal(&ok); |
|
304 | 304 | if(ok) q->setMax(value); |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
308 | 308 | { |
|
309 | 309 | Q_Q(QValueAxis); |
|
310 | 310 | bool ok1; |
|
311 | 311 | bool ok2; |
|
312 | 312 | qreal value1 = min.toReal(&ok1); |
|
313 | 313 | qreal value2 = max.toReal(&ok2); |
|
314 | 314 | if(ok1&&ok2) q->setRange(value1,value2); |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter) |
|
318 | 318 | { |
|
319 | 319 | Q_Q(QValueAxis); |
|
320 | 320 | if(m_orientation == Qt::Vertical){ |
|
321 | 321 | return new ChartValueAxisY(q,presenter); |
|
322 | 322 | }else{ |
|
323 | 323 | return new ChartValueAxisX(q,presenter); |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | void QValueAxisPrivate::intializeDomain(Domain* domain) |
|
329 | 329 | { |
|
330 | 330 | Q_Q(QValueAxis); |
|
331 | 331 | if(qFuzzyCompare(m_max,m_min)) { |
|
332 | 332 | if(m_orientation==Qt::Vertical){ |
|
333 | 333 | q->setRange(domain->minY(),domain->maxY()); |
|
334 | 334 | }else{ |
|
335 | 335 | q->setRange(domain->minX(), domain->maxX()); |
|
336 | 336 | } |
|
337 | 337 | } else { |
|
338 | 338 | if(m_orientation==Qt::Vertical){ |
|
339 | 339 | domain->setRangeY(m_min, m_max); |
|
340 | 340 | }else{ |
|
341 | 341 | domain->setRangeX(m_min, m_max); |
|
342 | 342 | } |
|
343 | 343 | } |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
347 | 347 | |
|
348 | 348 | void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const |
|
349 | 349 | { |
|
350 | 350 | qreal range = niceNumber(max-min,true); //range with ceiling |
|
351 | 351 | qreal step = niceNumber(range/(ticksCount-1),false); |
|
352 | 352 | min = qFloor(min/step); |
|
353 | 353 | max = qCeil(max/step); |
|
354 | 354 | ticksCount = int(max-min) +1; |
|
355 | 355 | min*=step; |
|
356 | 356 | max*=step; |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
360 | 360 | |
|
361 | 361 | qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const |
|
362 | 362 | { |
|
363 | 363 | qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
364 | 364 | qreal q = x/z;//q<10 && q>=1; |
|
365 | 365 | |
|
366 | 366 | if(ceiling) { |
|
367 | 367 | if(q <= 1.0) q=1; |
|
368 | 368 | else if(q <= 2.0) q=2; |
|
369 | 369 | else if(q <= 5.0) q=5; |
|
370 | 370 | else q=10; |
|
371 | 371 | } |
|
372 | 372 | else { |
|
373 | 373 | if(q < 1.5) q=1; |
|
374 | 374 | else if(q < 3.0) q=2; |
|
375 | 375 | else if(q < 7.0) q=5; |
|
376 | 376 | else q=10; |
|
377 | 377 | } |
|
378 | 378 | return q*z; |
|
379 | 379 | } |
|
380 | 380 | |
|
381 | 381 | #include "moc_qvalueaxis.cpp" |
|
382 | 382 | #include "moc_qvalueaxis_p.cpp" |
|
383 | 383 | |
|
384 | 384 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now