##// END OF EJS Templates
Axis docs updated
Marek Rosa -
r1887:e0460f4395dd
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -1,286 +1,301
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qcategoryaxis.h"
21 #include "qcategoryaxis.h"
22 #include "qcategoryaxis_p.h"
22 #include "qcategoryaxis_p.h"
23 #include "chartcategoryaxisx_p.h"
23 #include "chartcategoryaxisx_p.h"
24 #include "chartcategoryaxisy_p.h"
24 #include "chartcategoryaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
29 /*!
30 \class QCategoryAxis
30 \class QCategoryAxis
31 \brief The QCategoryAxis class allows putting a named ranges on the axis.
31 \brief The QCategoryAxis class allows putting a named ranges on the axis.
32 \mainclass
32 \mainclass
33
33
34 This class can be used when the underlying data needs to be given extra meaning.
34 This class can be used when the underlying data needs to be given extra meaning.
35 Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely.
35 Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely.
36
37 Example code on how to use QCategoryAxis.
38 \code
39 QChartView *chartView = new QChartView;
40 QLineSeries *series = new QLineSeries;
41 // ...
42 chartView->chart()->addSeries(series);
43
44 QCategoryAxis *axisX = new QCategoryAxis;
45 axisX->setStartValue(15);
46 axisX->append("First", 20);
47 axisX->append("Second", 37);
48 axisX->append("Third", 52);
49 chartView->chart()->setAxisX(series, axisX);
50 \endcode
36 */
51 */
37 /*!
52 /*!
38 \qmlclass CategoryAxis QCategoryAxis
53 \qmlclass CategoryAxis QCategoryAxis
39 \inherits AbstractAxis
54 \inherits AbstractAxis
40 \brief CategoryAxis allows putting a named ranges on the axis.
55 \brief CategoryAxis allows putting a named ranges on the axis.
41
56
42 For example:
57 For example:
43 \code
58 \code
44 CategoryAxis {
59 CategoryAxis {
45 startValue: 0.0
60 startValue: 0.0
46 CategoryRange { endValue: 1.0; label: "min (0-1)" }
61 CategoryRange { endValue: 1.0; label: "min (0-1)" }
47 CategoryRange { endValue: 3.0; label: "standard (1-3)" }
62 CategoryRange { endValue: 3.0; label: "standard (1-3)" }
48 CategoryRange { endValue: 4.0; label: "high (3-4)" }
63 CategoryRange { endValue: 4.0; label: "high (3-4)" }
49 }
64 }
50 \endcode
65 \endcode
51 */
66 */
52
67
53 /*!
68 /*!
54 \property QCategoryAxis::startValue
69 \property QCategoryAxis::startValue
55 Defines the low end of the first category on the axis.
70 Defines the low end of the first category on the axis.
56 */
71 */
57 /*!
72 /*!
58 \qmlproperty int CategoryAxis::startValue
73 \qmlproperty int CategoryAxis::startValue
59 Defines the low end of the first category on the axis.
74 Defines the low end of the first category on the axis.
60 */
75 */
61
76
62 /*!
77 /*!
63 Constructs an axis object which is a child of \a parent.
78 Constructs an axis object which is a child of \a parent.
64 */
79 */
65 QCategoryAxis::QCategoryAxis(QObject *parent):
80 QCategoryAxis::QCategoryAxis(QObject *parent):
66 QValueAxis(*new QCategoryAxisPrivate(this),parent)
81 QValueAxis(*new QCategoryAxisPrivate(this),parent)
67 {
82 {
68 }
83 }
69
84
70 /*!
85 /*!
71 Destroys the object
86 Destroys the object
72 */
87 */
73 QCategoryAxis::~QCategoryAxis()
88 QCategoryAxis::~QCategoryAxis()
74 {
89 {
75 // Q_D(QValueAxis);
90 // Q_D(QValueAxis);
76 // if(d->m_dataset) {
91 // if(d->m_dataset) {
77 // d->m_dataset->removeAxis(this);
92 // d->m_dataset->removeAxis(this);
78 // }
93 // }
79 }
94 }
80
95
81 /*!
96 /*!
82 \internal
97 \internal
83 */
98 */
84 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
99 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
85 {
100 {
86
101
87 }
102 }
88
103
89 /*!
104 /*!
90 \qmlmethod CategoryAxis::append(string label, real endValue)
105 \qmlmethod CategoryAxis::append(string label, real endValue)
91 Appends new category to the axis with an \a label. Category label has to be unique.
106 Appends new category to the axis with an \a label. Category label has to be unique.
92 Parameter \a endValue specifies the high end limit of the category.
107 Parameter \a endValue specifies the high end limit of the category.
93 It has to be greater than the high end limit of the previous category.
108 It has to be greater than the high end limit of the previous category.
94 Otherwise the method returns without adding a new category.
109 Otherwise the method returns without adding a new category.
95 */
110 */
96 /*!
111 /*!
97 Appends new category to the axis with an \a categoryLabel.
112 Appends new category to the axis with an \a categoryLabel.
98 Category label has to be unique.
113 Category label has to be unique.
99 Parameter \a categoryEndValue specifies the high end limit of the category.
114 Parameter \a categoryEndValue specifies the high end limit of the category.
100 It has to be greater than the high end limit of the previous category.
115 It has to be greater than the high end limit of the previous category.
101 Otherwise the method returns without adding a new category.
116 Otherwise the method returns without adding a new category.
102 */
117 */
103 void QCategoryAxis::append(const QString& categoryLabel, qreal categoryEndValue)
118 void QCategoryAxis::append(const QString& categoryLabel, qreal categoryEndValue)
104 {
119 {
105 Q_D(QCategoryAxis);
120 Q_D(QCategoryAxis);
106
121
107 if (!d->m_categories.contains(categoryLabel))
122 if (!d->m_categories.contains(categoryLabel))
108 {
123 {
109 if(d->m_categories.isEmpty()){
124 if(d->m_categories.isEmpty()){
110 Range range(d->m_categoryMinimum, categoryEndValue);
125 Range range(d->m_categoryMinimum, categoryEndValue);
111 d->m_categoriesMap.insert(categoryLabel, range);
126 d->m_categoriesMap.insert(categoryLabel, range);
112 d->m_categories.append(categoryLabel);
127 d->m_categories.append(categoryLabel);
113 }else if (categoryEndValue > endValue(d->m_categories.last())){
128 }else if (categoryEndValue > endValue(d->m_categories.last())){
114 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
129 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
115 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
130 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
116 d->m_categories.append(categoryLabel);
131 d->m_categories.append(categoryLabel);
117 }
132 }
118 }
133 }
119 }
134 }
120
135
121 /*!
136 /*!
122 Sets \a min to be the low end limit of the first category on the axis.
137 Sets \a min to be the low end limit of the first category on the axis.
123 If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range.
138 If there is already some categories added to the axis then passed value must be lower than the high end value of the already defined first category range.
124 Otherwise nothing is done.
139 Otherwise nothing is done.
125 */
140 */
126 void QCategoryAxis::setStartValue(qreal min)
141 void QCategoryAxis::setStartValue(qreal min)
127 {
142 {
128 Q_D(QCategoryAxis);
143 Q_D(QCategoryAxis);
129 if(d->m_categories.isEmpty()){
144 if(d->m_categories.isEmpty()){
130 d->m_categoryMinimum = min;
145 d->m_categoryMinimum = min;
131 }else{
146 }else{
132 Range range = d->m_categoriesMap.value(d->m_categories.first());
147 Range range = d->m_categoriesMap.value(d->m_categories.first());
133 if (min < range.second)
148 if (min < range.second)
134 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
149 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
135 }
150 }
136 }
151 }
137
152
138 /*!
153 /*!
139 Returns the low end limit of the category specified by an \a categoryLabel
154 Returns the low end limit of the category specified by an \a categoryLabel
140 */
155 */
141 qreal QCategoryAxis::startValue(const QString& categoryLabel) const
156 qreal QCategoryAxis::startValue(const QString& categoryLabel) const
142 {
157 {
143 Q_D(const QCategoryAxis);
158 Q_D(const QCategoryAxis);
144 if (categoryLabel == QString())
159 if (categoryLabel == QString())
145 return d->m_categoryMinimum;
160 return d->m_categoryMinimum;
146 else
161 else
147 return d->m_categoriesMap.value(categoryLabel).first;
162 return d->m_categoriesMap.value(categoryLabel).first;
148 }
163 }
149
164
150 /*!
165 /*!
151 Returns the high end limit of the interval specified by an \a categoryLabel
166 Returns the high end limit of the interval specified by an \a categoryLabel
152 */
167 */
153 qreal QCategoryAxis::endValue(const QString& categoryLabel) const
168 qreal QCategoryAxis::endValue(const QString& categoryLabel) const
154 {
169 {
155 Q_D(const QCategoryAxis);
170 Q_D(const QCategoryAxis);
156 return d->m_categoriesMap.value(categoryLabel).second;
171 return d->m_categoriesMap.value(categoryLabel).second;
157 }
172 }
158
173
159 /*!
174 /*!
160 \qmlmethod CategoryAxis::remove(string label)
175 \qmlmethod CategoryAxis::remove(string label)
161 Removes a category specified by the \a label from the axis
176 Removes a category specified by the \a label from the axis
162 */
177 */
163 /*!
178 /*!
164 Removes an interval specified by the \a categoryLabel from the axis
179 Removes an interval specified by the \a categoryLabel from the axis
165 */
180 */
166 void QCategoryAxis::remove(const QString &categoryLabel)
181 void QCategoryAxis::remove(const QString &categoryLabel)
167 {
182 {
168 Q_D(QCategoryAxis);
183 Q_D(QCategoryAxis);
169 int labelIndex = d->m_categories.indexOf(categoryLabel);
184 int labelIndex = d->m_categories.indexOf(categoryLabel);
170
185
171 // check if such label exists
186 // check if such label exists
172 if (labelIndex != -1) {
187 if (labelIndex != -1) {
173 d->m_categories.removeAt(labelIndex);
188 d->m_categories.removeAt(labelIndex);
174 d->m_categoriesMap.remove(categoryLabel);
189 d->m_categoriesMap.remove(categoryLabel);
175
190
176 // the range of the interval that follows (if exists) needs to be updated
191 // the range of the interval that follows (if exists) needs to be updated
177 if (labelIndex < d->m_categories.count()) {
192 if (labelIndex < d->m_categories.count()) {
178 QString label = d->m_categories.at(labelIndex);
193 QString label = d->m_categories.at(labelIndex);
179 Range range = d->m_categoriesMap.value(label);
194 Range range = d->m_categoriesMap.value(label);
180
195
181 // set the range
196 // set the range
182 if (labelIndex == 0) {
197 if (labelIndex == 0) {
183 range.first = d->m_categoryMinimum;
198 range.first = d->m_categoryMinimum;
184 d->m_categoriesMap.insert(label, range);
199 d->m_categoriesMap.insert(label, range);
185 } else {
200 } else {
186 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
201 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
187 d->m_categoriesMap.insert(label, range);
202 d->m_categoriesMap.insert(label, range);
188 }
203 }
189 }
204 }
190 d->emitUpdated();
205 d->emitUpdated();
191 }
206 }
192 }
207 }
193
208
194 /*!
209 /*!
195 \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel)
210 \qmlmethod CategoryAxis::replace(string oldLabel, string newLabel)
196 Replaces \a oldLabel of an existing category with a \a newLabel.
211 Replaces \a oldLabel of an existing category with a \a newLabel.
197 If the old label does not exist the method returns without making any changes.
212 If the old label does not exist the method returns without making any changes.
198 */
213 */
199 /*!
214 /*!
200 Replaces \a oldLabel of an existing category with a \a newLabel
215 Replaces \a oldLabel of an existing category with a \a newLabel
201 If the old label does not exist the method returns without making any changes.
216 If the old label does not exist the method returns without making any changes.
202 */
217 */
203 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
218 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
204 {
219 {
205 Q_D(QCategoryAxis);
220 Q_D(QCategoryAxis);
206 int labelIndex = d->m_categories.indexOf(oldLabel);
221 int labelIndex = d->m_categories.indexOf(oldLabel);
207
222
208 // check if such label exists
223 // check if such label exists
209 if (labelIndex != -1) {
224 if (labelIndex != -1) {
210 d->m_categories.replace(labelIndex, newLabel);
225 d->m_categories.replace(labelIndex, newLabel);
211 Range range = d->m_categoriesMap.value(oldLabel);
226 Range range = d->m_categoriesMap.value(oldLabel);
212 d->m_categoriesMap.remove(oldLabel);
227 d->m_categoriesMap.remove(oldLabel);
213 d->m_categoriesMap.insert(newLabel, range);
228 d->m_categoriesMap.insert(newLabel, range);
214 d->emitUpdated();
229 d->emitUpdated();
215 }
230 }
216
231
217 }
232 }
218
233
219 /*!
234 /*!
220 Returns the list of the intervals labels
235 Returns the list of the intervals labels
221 */
236 */
222 QStringList QCategoryAxis::categoriesLabels()
237 QStringList QCategoryAxis::categoriesLabels()
223 {
238 {
224 Q_D(QCategoryAxis);
239 Q_D(QCategoryAxis);
225 return d->m_categories;
240 return d->m_categories;
226 }
241 }
227
242
228 /*!
243 /*!
229 Returns number of intervals.
244 Returns number of intervals.
230 */
245 */
231 int QCategoryAxis::count() const
246 int QCategoryAxis::count() const
232 {
247 {
233 Q_D(const QCategoryAxis);
248 Q_D(const QCategoryAxis);
234 return d->m_categories.count();
249 return d->m_categories.count();
235 }
250 }
236
251
237 /*!
252 /*!
238 Returns the type of the axis
253 Returns the type of the axis
239 */
254 */
240 QAbstractAxis::AxisType QCategoryAxis::type() const
255 QAbstractAxis::AxisType QCategoryAxis::type() const
241 {
256 {
242 return QAbstractAxis::AxisTypeCategory;
257 return QAbstractAxis::AxisTypeCategory;
243 }
258 }
244
259
245 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
260 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
246
261
247 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q):
262 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q):
248 QValueAxisPrivate(q),
263 QValueAxisPrivate(q),
249 m_categoryMinimum(0)
264 m_categoryMinimum(0)
250 {
265 {
251
266
252 }
267 }
253
268
254 QCategoryAxisPrivate::~QCategoryAxisPrivate()
269 QCategoryAxisPrivate::~QCategoryAxisPrivate()
255 {
270 {
256
271
257 }
272 }
258
273
259 int QCategoryAxisPrivate::ticksCount() const
274 int QCategoryAxisPrivate::ticksCount() const
260 {
275 {
261 return m_categories.count() + 1;
276 return m_categories.count() + 1;
262 }
277 }
263
278
264 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
279 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
265 {
280 {
266 Q_UNUSED(count);
281 Q_UNUSED(count);
267 Q_UNUSED(min);
282 Q_UNUSED(min);
268 Q_UNUSED(max);
283 Q_UNUSED(max);
269 //m_min = min;
284 //m_min = min;
270 //m_max = max;
285 //m_max = max;
271 }
286 }
272
287
273 ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
288 ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
274 {
289 {
275 Q_Q(QCategoryAxis);
290 Q_Q(QCategoryAxis);
276 if(m_orientation == Qt::Vertical){
291 if(m_orientation == Qt::Vertical){
277 return new ChartCategoryAxisY(q,presenter);
292 return new ChartCategoryAxisY(q,presenter);
278 }else{
293 }else{
279 return new ChartCategoryAxisX(q,presenter);
294 return new ChartCategoryAxisX(q,presenter);
280 }
295 }
281 }
296 }
282
297
283 #include "moc_qcategoryaxis.cpp"
298 #include "moc_qcategoryaxis.cpp"
284 #include "moc_qcategoryaxis_p.cpp"
299 #include "moc_qcategoryaxis_p.cpp"
285
300
286 QTCOMMERCIALCHART_END_NAMESPACE
301 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,341 +1,343
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qdatetimeaxis.h"
21 #include "qdatetimeaxis.h"
22 #include "qdatetimeaxis_p.h"
22 #include "qdatetimeaxis_p.h"
23 #include "chartdatetimeaxisx_p.h"
23 #include "chartdatetimeaxisx_p.h"
24 #include "chartdatetimeaxisy_p.h"
24 #include "chartdatetimeaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include <cmath>
26 #include <cmath>
27 #include <QDebug>
27 #include <QDebug>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 /*!
30 /*!
31 \class QDateTimeAxis
31 \class QDateTimeAxis
32 \brief The QDateTimeAxis class is used for manipulating chart's axis.
32 \brief The QDateTimeAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 The labels can be configured by setting an appropriate DateTime format.
35 The labels can be configured by setting an appropriate DateTime format.
36 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
36 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
37 QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
37 QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
38
38
39 \image api_datatime_axis.png
40
39 Example code on how to use QDateTimeAxis.
41 Example code on how to use QDateTimeAxis.
40 \code
42 \code
41 QChartView *chartView = new QChartView;
43 QChartView *chartView = new QChartView;
42 QLineSeries *series = new QLineSeries;
44 QLineSeries *series = new QLineSeries;
43
45
44 QDateTime xValue;
46 QDateTime xValue;
45 xValue.setDate(QDate(2012, 1 , 18));
47 xValue.setDate(QDate(2012, 1 , 18));
46 xValue.setTime(QTime(9, 34));
48 xValue.setTime(QTime(9, 34));
47 series->append(xValue.toMSecsSinceEpoch(), 12);
49 series->append(xValue.toMSecsSinceEpoch(), 12);
48
50
49 xValue.setDate(QDate(2013, 5 , 11));
51 xValue.setDate(QDate(2013, 5 , 11));
50 xValue.setTime(QTime(11, 14));
52 xValue.setTime(QTime(11, 14));
51 series->append(xValue.toMSecsSinceEpoch(), 22);
53 series->append(xValue.toMSecsSinceEpoch(), 22);
52 chartView->chart()->addSeries(series);
54 chartView->chart()->addSeries(series);
53
55
54 // ...
56 // ...
55 QDateTimeAxis *axisX = new QDateTimeAxis;
57 QDateTimeAxis *axisX = new QDateTimeAxis;
56 axisX->setFormat("dd-MM-yyyy h:mm");
58 axisX->setFormat("dd-MM-yyyy h:mm");
57 chartView->chart()->setAxisX(series, axisX);
59 chartView->chart()->setAxisX(series, axisX);
58 \endcode
60 \endcode
59 */
61 */
60
62
61 /*!
63 /*!
62 \qmlclass DateTimeAxis QDateTimeAxis
64 \qmlclass DateTimeAxis QDateTimeAxis
63 \brief The DateTimeAxis element is used for manipulating chart's axes
65 \brief The DateTimeAxis element is used for manipulating chart's axes
64
66
65 The labels can be configured by setting an appropriate DateTime format.
67 The labels can be configured by setting an appropriate DateTime format.
66 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
68 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
67 DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
69 DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
68 */
70 */
69
71
70 /*!
72 /*!
71 \property QDateTimeAxis::min
73 \property QDateTimeAxis::min
72 Defines the minimum value on the axis.
74 Defines the minimum value on the axis.
73 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
75 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
74 */
76 */
75 /*!
77 /*!
76 \qmlproperty real ValuesAxis::min
78 \qmlproperty real ValuesAxis::min
77 Defines the minimum value on the axis.
79 Defines the minimum value on the axis.
78 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
80 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
79 */
81 */
80
82
81 /*!
83 /*!
82 \property QDateTimeAxis::max
84 \property QDateTimeAxis::max
83 Defines the maximum value on the axis.
85 Defines the maximum value on the axis.
84 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
86 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
85 */
87 */
86 /*!
88 /*!
87 \qmlproperty real ValuesAxis::max
89 \qmlproperty real ValuesAxis::max
88 Defines the maximum value on the axis.
90 Defines the maximum value on the axis.
89 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
91 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
90 */
92 */
91
93
92 /*!
94 /*!
93 \fn void QDateTimeAxis::minChanged(QDateTime min)
95 \fn void QDateTimeAxis::minChanged(QDateTime min)
94 Axis emits signal when \a min of axis has changed.
96 Axis emits signal when \a min of axis has changed.
95 */
97 */
96 /*!
98 /*!
97 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
99 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
98 Axis emits signal when \a min of axis has changed.
100 Axis emits signal when \a min of axis has changed.
99 */
101 */
100
102
101 /*!
103 /*!
102 \fn void QDateTimeAxis::maxChanged(QDateTime max)
104 \fn void QDateTimeAxis::maxChanged(QDateTime max)
103 Axis emits signal when \a max of axis has changed.
105 Axis emits signal when \a max of axis has changed.
104 */
106 */
105 /*!
107 /*!
106 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
108 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
107 Axis emits signal when \a max of axis has changed.
109 Axis emits signal when \a max of axis has changed.
108 */
110 */
109
111
110 /*!
112 /*!
111 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
113 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
112 Axis emits signal when \a min or \a max of axis has changed.
114 Axis emits signal when \a min or \a max of axis has changed.
113 */
115 */
114
116
115 /*!
117 /*!
116 \property QDateTimeAxis::tickCount
118 \property QDateTimeAxis::tickCount
117 The number of tick marks for the axis.
119 The number of tick marks for the axis.
118 */
120 */
119
121
120 /*!
122 /*!
121 \qmlproperty int ValuesAxis::tickCount
123 \qmlproperty int ValuesAxis::tickCount
122 The number of tick marks for the axis.
124 The number of tick marks for the axis.
123 */
125 */
124
126
125 /*!
127 /*!
126 Constructs an axis object which is a child of \a parent.
128 Constructs an axis object which is a child of \a parent.
127 */
129 */
128 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
130 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
129 QAbstractAxis(*new QDateTimeAxisPrivate(this),parent)
131 QAbstractAxis(*new QDateTimeAxisPrivate(this),parent)
130 {
132 {
131
133
132 }
134 }
133
135
134 /*!
136 /*!
135 \internal
137 \internal
136 */
138 */
137 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
139 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
138 {
140 {
139
141
140 }
142 }
141
143
142 /*!
144 /*!
143 Destroys the object
145 Destroys the object
144 */
146 */
145 QDateTimeAxis::~QDateTimeAxis()
147 QDateTimeAxis::~QDateTimeAxis()
146 {
148 {
147
149
148 }
150 }
149
151
150 void QDateTimeAxis::setMin(QDateTime min)
152 void QDateTimeAxis::setMin(QDateTime min)
151 {
153 {
152 Q_D(QDateTimeAxis);
154 Q_D(QDateTimeAxis);
153 if (min.isValid())
155 if (min.isValid())
154 setRange(min, qMax(d->m_max, min));
156 setRange(min, qMax(d->m_max, min));
155 }
157 }
156
158
157 QDateTime QDateTimeAxis::min() const
159 QDateTime QDateTimeAxis::min() const
158 {
160 {
159 Q_D(const QDateTimeAxis);
161 Q_D(const QDateTimeAxis);
160 return d->m_min;
162 return d->m_min;
161 }
163 }
162
164
163 void QDateTimeAxis::setMax(QDateTime max)
165 void QDateTimeAxis::setMax(QDateTime max)
164 {
166 {
165 Q_D(QDateTimeAxis);
167 Q_D(QDateTimeAxis);
166 if (max.isValid())
168 if (max.isValid())
167 setRange(qMin(d->m_min, max), max);
169 setRange(qMin(d->m_min, max), max);
168 }
170 }
169
171
170 QDateTime QDateTimeAxis::max() const
172 QDateTime QDateTimeAxis::max() const
171 {
173 {
172 Q_D(const QDateTimeAxis);
174 Q_D(const QDateTimeAxis);
173 return d->m_max;
175 return d->m_max;
174 }
176 }
175
177
176 /*!
178 /*!
177 Sets range from \a min to \a max on the axis.
179 Sets range from \a min to \a max on the axis.
178 If min is greater than max then this function returns without making any changes.
180 If min is greater than max then this function returns without making any changes.
179 */
181 */
180 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
182 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
181 {
183 {
182 Q_D(QDateTimeAxis);
184 Q_D(QDateTimeAxis);
183 if (!min.isValid() || !max.isValid() || min > max)
185 if (!min.isValid() || !max.isValid() || min > max)
184 return;
186 return;
185
187
186 bool changed = false;
188 bool changed = false;
187 if (d->m_min != min) {
189 if (d->m_min != min) {
188 d->m_min = min;
190 d->m_min = min;
189 changed = true;
191 changed = true;
190 emit minChanged(min);
192 emit minChanged(min);
191 }
193 }
192
194
193 if (d->m_max != max) {
195 if (d->m_max != max) {
194 d->m_max = max;
196 d->m_max = max;
195 changed = true;
197 changed = true;
196 emit maxChanged(max);
198 emit maxChanged(max);
197 }
199 }
198
200
199 if (changed) {
201 if (changed) {
200 emit rangeChanged(d->m_min,d->m_max);
202 emit rangeChanged(d->m_min,d->m_max);
201 d->emitUpdated();
203 d->emitUpdated();
202 }
204 }
203 }
205 }
204
206
205 /*!
207 /*!
206 Sets \a format string that is used when creating label for the axis out of the QDateTime object.
208 Sets \a format string that is used when creating label for the axis out of the QDateTime object.
207 Check QDateTime documentation for information on how the string should be defined.
209 Check QDateTime documentation for information on how the string should be defined.
208 \sa format()
210 \sa format()
209 */
211 */
210 void QDateTimeAxis::setFormat(QString format)
212 void QDateTimeAxis::setFormat(QString format)
211 {
213 {
212 Q_D(QDateTimeAxis);
214 Q_D(QDateTimeAxis);
213 d->m_format = format;
215 d->m_format = format;
214 }
216 }
215
217
216 /*!
218 /*!
217 Returns the format string that is used when creating label for the axis out of the QDateTime object.
219 Returns the format string that is used when creating label for the axis out of the QDateTime object.
218 Check QDateTime documentation for information on how the string should be defined.
220 Check QDateTime documentation for information on how the string should be defined.
219 \sa setFormat()
221 \sa setFormat()
220 */
222 */
221 QString QDateTimeAxis::format() const
223 QString QDateTimeAxis::format() const
222 {
224 {
223 Q_D(const QDateTimeAxis);
225 Q_D(const QDateTimeAxis);
224 return d->m_format;
226 return d->m_format;
225 }
227 }
226
228
227 /*!
229 /*!
228 Sets \a count for ticks on the axis.
230 Sets \a count for ticks on the axis.
229 */
231 */
230 void QDateTimeAxis::setTickCount(int count)
232 void QDateTimeAxis::setTickCount(int count)
231 {
233 {
232 Q_D(QDateTimeAxis);
234 Q_D(QDateTimeAxis);
233 if (d->m_tickCount != count && count >=2) {
235 if (d->m_tickCount != count && count >=2) {
234 d->m_tickCount = count;
236 d->m_tickCount = count;
235 d->emitUpdated();
237 d->emitUpdated();
236 }
238 }
237 }
239 }
238
240
239 /*!
241 /*!
240 \fn int QDateTimeAxis::tickCount() const
242 \fn int QDateTimeAxis::tickCount() const
241 Return number of ticks on the axis
243 Return number of ticks on the axis
242 */
244 */
243 int QDateTimeAxis::tickCount() const
245 int QDateTimeAxis::tickCount() const
244 {
246 {
245 Q_D(const QDateTimeAxis);
247 Q_D(const QDateTimeAxis);
246 return d->m_tickCount;
248 return d->m_tickCount;
247 }
249 }
248
250
249 /*!
251 /*!
250 Returns the type of the axis
252 Returns the type of the axis
251 */
253 */
252 QAbstractAxis::AxisType QDateTimeAxis::type() const
254 QAbstractAxis::AxisType QDateTimeAxis::type() const
253 {
255 {
254 return AxisTypeDateTime;
256 return AxisTypeDateTime;
255 }
257 }
256
258
257 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
259 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
258
260
259 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q):
261 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis* q):
260 QAbstractAxisPrivate(q),
262 QAbstractAxisPrivate(q),
261 m_tickCount(5)
263 m_tickCount(5)
262 {
264 {
263 m_min = QDateTime::fromMSecsSinceEpoch(0);
265 m_min = QDateTime::fromMSecsSinceEpoch(0);
264 m_max = QDateTime::fromMSecsSinceEpoch(0);
266 m_max = QDateTime::fromMSecsSinceEpoch(0);
265 m_format = "dd-MMM-yyyy\nh:mm";
267 m_format = "dd-MM-yyyy\nh:mm";
266 }
268 }
267
269
268 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
270 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
269 {
271 {
270
272
271 }
273 }
272
274
273 void QDateTimeAxisPrivate::handleDomainUpdated()
275 void QDateTimeAxisPrivate::handleDomainUpdated()
274 {
276 {
275 Q_Q(QDateTimeAxis);
277 Q_Q(QDateTimeAxis);
276 Domain* domain = qobject_cast<Domain*>(sender());
278 Domain* domain = qobject_cast<Domain*>(sender());
277 Q_ASSERT(domain);
279 Q_ASSERT(domain);
278
280
279 if(orientation()==Qt::Horizontal){
281 if(orientation()==Qt::Horizontal){
280 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
282 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
281 }else if(orientation()==Qt::Vertical){
283 }else if(orientation()==Qt::Vertical){
282 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
284 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
283 }
285 }
284 }
286 }
285
287
286
288
287 void QDateTimeAxisPrivate::setMin(const QVariant &min)
289 void QDateTimeAxisPrivate::setMin(const QVariant &min)
288 {
290 {
289 Q_Q(QDateTimeAxis);
291 Q_Q(QDateTimeAxis);
290 if (min.canConvert(QVariant::DateTime))
292 if (min.canConvert(QVariant::DateTime))
291 q->setMin(min.toDateTime());
293 q->setMin(min.toDateTime());
292 }
294 }
293
295
294 void QDateTimeAxisPrivate::setMax(const QVariant &max)
296 void QDateTimeAxisPrivate::setMax(const QVariant &max)
295 {
297 {
296
298
297 Q_Q(QDateTimeAxis);
299 Q_Q(QDateTimeAxis);
298 if (max.canConvert(QVariant::DateTime))
300 if (max.canConvert(QVariant::DateTime))
299 q->setMax(max.toDateTime());
301 q->setMax(max.toDateTime());
300 }
302 }
301
303
302 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
304 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
303 {
305 {
304 Q_Q(QDateTimeAxis);
306 Q_Q(QDateTimeAxis);
305 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
307 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
306 q->setRange(min.toDateTime(), max.toDateTime());
308 q->setRange(min.toDateTime(), max.toDateTime());
307 }
309 }
308
310
309 ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter)
311 ChartAxis* QDateTimeAxisPrivate::createGraphics(ChartPresenter* presenter)
310 {
312 {
311 Q_Q(QDateTimeAxis);
313 Q_Q(QDateTimeAxis);
312 if(m_orientation == Qt::Vertical){
314 if(m_orientation == Qt::Vertical){
313 return new ChartDateTimeAxisY(q,presenter);
315 return new ChartDateTimeAxisY(q,presenter);
314 }else{
316 }else{
315 return new ChartDateTimeAxisX(q,presenter);
317 return new ChartDateTimeAxisX(q,presenter);
316 }
318 }
317
319
318 }
320 }
319
321
320 void QDateTimeAxisPrivate::intializeDomain(Domain* domain)
322 void QDateTimeAxisPrivate::intializeDomain(Domain* domain)
321 {
323 {
322 Q_Q(QDateTimeAxis);
324 Q_Q(QDateTimeAxis);
323 if(m_max == m_min) {
325 if(m_max == m_min) {
324 if(m_orientation==Qt::Vertical){
326 if(m_orientation==Qt::Vertical){
325 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
327 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minY()), QDateTime::fromMSecsSinceEpoch(domain->maxY()));
326 }else{
328 }else{
327 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
329 q->setRange(QDateTime::fromMSecsSinceEpoch(domain->minX()), QDateTime::fromMSecsSinceEpoch(domain->maxX()));
328 }
330 }
329 } else {
331 } else {
330 if(m_orientation==Qt::Vertical){
332 if(m_orientation==Qt::Vertical){
331 domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
333 domain->setRangeY(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
332 }else{
334 }else{
333 domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
335 domain->setRangeX(m_min.toMSecsSinceEpoch(), m_max.toMSecsSinceEpoch());
334 }
336 }
335 }
337 }
336 }
338 }
337
339
338 #include "moc_qdatetimeaxis.cpp"
340 #include "moc_qdatetimeaxis.cpp"
339 #include "moc_qdatetimeaxis_p.cpp"
341 #include "moc_qdatetimeaxis_p.cpp"
340
342
341 QTCOMMERCIALCHART_END_NAMESPACE
343 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now