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