##// END OF EJS Templates
QIntervalsAxis some names updates
Marek Rosa -
r1799:82d343f35d2d
parent child
Show More
@@ -1,242 +1,245
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 "qintervalsaxis.h"
21 #include "qintervalsaxis.h"
22 #include "qintervalsaxis_p.h"
22 #include "qintervalsaxis_p.h"
23 #include "chartintervalsaxisx_p.h"
23 #include "chartintervalsaxisx_p.h"
24 #include "chartintervalsaxisy_p.h"
24 #include "chartintervalsaxisy_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 \internal
30 \internal
31 \class QIntervalsAxis
31 \class QIntervalsAxis
32 \brief The QIntervalsAxis class is used for manipulating chart's axis.
32 \brief The QIntervalsAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 */
36 */
37
37
38 /*!
38 /*!
39 \qmlclass Axis QIntervalsAxis
39 \qmlclass Axis QIntervalsAxis
40 \brief The Axis element is used for manipulating chart's axes.
40 \brief The Axis element is used for manipulating chart's axes.
41
41
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43
43
44 To access Axes you can use ChartView API. For example:
44 To access Axes you can use ChartView API. For example:
45 \code
45 \code
46 // TODO :)
46 // TODO :)
47 \endcode
47 \endcode
48 */
48 */
49
49
50 /*!
50 /*!
51 Constructs an axis object which is a child of \a parent.
51 Constructs an axis object which is a child of \a parent.
52 */
52 */
53 QIntervalsAxis::QIntervalsAxis(QObject *parent):
53 QIntervalsAxis::QIntervalsAxis(QObject *parent):
54 QValuesAxis(*new QIntervalsAxisPrivate(this),parent)
54 QValuesAxis(*new QIntervalsAxisPrivate(this),parent)
55 {
55 {
56 }
56 }
57
57
58 /*!
58 /*!
59 Destroys the object
59 Destroys the object
60 */
60 */
61 QIntervalsAxis::~QIntervalsAxis()
61 QIntervalsAxis::~QIntervalsAxis()
62 {
62 {
63 // Q_D(QValuesAxis);
63 // Q_D(QValuesAxis);
64 // if(d->m_dataset) {
64 // if(d->m_dataset) {
65 // d->m_dataset->removeAxis(this);
65 // d->m_dataset->removeAxis(this);
66 // }
66 // }
67 }
67 }
68
68
69 /*!
69 /*!
70 \internal
70 \internal
71 */
71 */
72 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
72 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
73 {
73 {
74
74
75 }
75 }
76
76
77 /*!
77 /*!
78 Appends new interval to the axis with an \a intervalLabel.
78 Appends new interval to the axis with an \a intervalLabel.
79 Interval label has to be unique.
79 Parameter \a interval specifies the high end limit of the interval.
80 Parameter \a interval specifies the high end limit of the interval.
81 It has to be greater than the high end limit of the previous interval.
82 Otherwise the method returns without adding a new interval.
80 */
83 */
81 void QIntervalsAxis::append(const QString& intervalLabel, qreal interval)
84 void QIntervalsAxis::append(const QString& intervalLabel, qreal intervalEnd)
82 {
85 {
83 Q_D(QIntervalsAxis);
86 Q_D(QIntervalsAxis);
84
87
85 if (!d->m_intervals.contains(intervalLabel))
88 if (!d->m_intervals.contains(intervalLabel))
86 {
89 {
87 if(d->m_intervals.isEmpty()){
90 if(d->m_intervals.isEmpty()){
88 Range range(d->m_categoryMinimum,interval);
91 Range range(d->m_categoryMinimum, intervalEnd);
89 d->m_intervalsMap.insert(intervalLabel, range);
92 d->m_intervalsMap.insert(intervalLabel, range);
90 d->m_intervals.append(intervalLabel);
93 d->m_intervals.append(intervalLabel);
91 }else if (interval > intervalMax(d->m_intervals.last())){
94 }else if (intervalEnd > intervalMax(d->m_intervals.last())){
92 Range range = d->m_intervalsMap.value(d->m_intervals.last());
95 Range range = d->m_intervalsMap.value(d->m_intervals.last());
93 d->m_intervalsMap.insert(intervalLabel, Range(range.second,interval));
96 d->m_intervalsMap.insert(intervalLabel, Range(range.second, intervalEnd));
94 d->m_intervals.append(intervalLabel);
97 d->m_intervals.append(intervalLabel);
95 }
98 }
96 }
99 }
97 }
100 }
98
101
99 /*!
102 /*!
100 Sets to \a min the low end limit of the first interval on the axis.
103 Sets to \a min the low end limit of the first interval on the axis.
101 */
104 */
102 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
105 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
103 {
106 {
104 Q_D(QIntervalsAxis);
107 Q_D(QIntervalsAxis);
105 if(d->m_intervals.isEmpty()){
108 if(d->m_intervals.isEmpty()){
106 d->m_categoryMinimum = min;
109 d->m_categoryMinimum = min;
107 }else{
110 }else{
108 Range range = d->m_intervalsMap.value(d->m_intervals.first());
111 Range range = d->m_intervalsMap.value(d->m_intervals.first());
109 d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
112 d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
110 }
113 }
111 }
114 }
112
115
113 /*!
116 /*!
114 Returns the low end limit of the interval specified by an \a intervalLabel
117 Returns the low end limit of the interval specified by an \a intervalLabel
115 */
118 */
116 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
119 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
117 {
120 {
118 Q_D(const QIntervalsAxis);
121 Q_D(const QIntervalsAxis);
119 return d->m_intervalsMap.value(intervalLabel).first;
122 return d->m_intervalsMap.value(intervalLabel).first;
120 }
123 }
121
124
122 /*!
125 /*!
123 Returns the high end limit of the interval specified by an \a intervalLabel
126 Returns the high end limit of the interval specified by an \a intervalLabel
124 */
127 */
125 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
128 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
126 {
129 {
127 Q_D(const QIntervalsAxis);
130 Q_D(const QIntervalsAxis);
128 return d->m_intervalsMap.value(intervalLabel).second;
131 return d->m_intervalsMap.value(intervalLabel).second;
129 }
132 }
130
133
131 /*!
134 /*!
132 Removes \a interval from axis
135 Removes \a interval from axis
133 */
136 */
134 void QIntervalsAxis::remove(const QString &intervalLabel)
137 void QIntervalsAxis::remove(const QString &intervalLabel)
135 {
138 {
136 Q_D(QIntervalsAxis);
139 Q_D(QIntervalsAxis);
137 int labelIndex = d->m_intervals.indexOf(intervalLabel);
140 int labelIndex = d->m_intervals.indexOf(intervalLabel);
138
141
139 // check if such label exists
142 // check if such label exists
140 if (labelIndex != -1) {
143 if (labelIndex != -1) {
141 d->m_intervals.removeAt(labelIndex);
144 d->m_intervals.removeAt(labelIndex);
142 d->m_intervalsMap.remove(intervalLabel);
145 d->m_intervalsMap.remove(intervalLabel);
143
146
144 // the range of the interval that follows (if exists) needs to be updated
147 // the range of the interval that follows (if exists) needs to be updated
145 if (labelIndex < d->m_intervals.count()) {
148 if (labelIndex < d->m_intervals.count()) {
146 QString label = d->m_intervals.at(labelIndex);
149 QString label = d->m_intervals.at(labelIndex);
147 Range range = d->m_intervalsMap.value(label);
150 Range range = d->m_intervalsMap.value(label);
148
151
149 // set the range
152 // set the range
150 if (labelIndex == 0) {
153 if (labelIndex == 0) {
151 range.first = d->m_categoryMinimum;
154 range.first = d->m_categoryMinimum;
152 d->m_intervalsMap.insert(label, range);
155 d->m_intervalsMap.insert(label, range);
153 } else {
156 } else {
154 range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
157 range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
155 d->m_intervalsMap.insert(label, range);
158 d->m_intervalsMap.insert(label, range);
156 }
159 }
157 }
160 }
158 d->emitUpdated();
161 d->emitUpdated();
159 }
162 }
160 }
163 }
161
164
162 void QIntervalsAxis::replace(const QString& oldLabel, const QString& newLabel)
165 void QIntervalsAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
163 {
166 {
164 Q_D(QIntervalsAxis);
167 Q_D(QIntervalsAxis);
165 int labelIndex = d->m_intervals.indexOf(oldLabel);
168 int labelIndex = d->m_intervals.indexOf(oldLabel);
166
169
167 // check if such label exists
170 // check if such label exists
168 if (labelIndex != -1) {
171 if (labelIndex != -1) {
169 d->m_intervals.replace(labelIndex, newLabel);
172 d->m_intervals.replace(labelIndex, newLabel);
170 Range range = d->m_intervalsMap.value(oldLabel);
173 Range range = d->m_intervalsMap.value(oldLabel);
171 d->m_intervalsMap.remove(oldLabel);
174 d->m_intervalsMap.remove(oldLabel);
172 d->m_intervalsMap.insert(newLabel, range);
175 d->m_intervalsMap.insert(newLabel, range);
173 d->emitUpdated();
176 d->emitUpdated();
174 }
177 }
175
178
176 }
179 }
177
180
178 QStringList QIntervalsAxis::intervalsLabels()
181 QStringList QIntervalsAxis::intervalsLabels()
179 {
182 {
180 Q_D(QIntervalsAxis);
183 Q_D(QIntervalsAxis);
181 return d->m_intervals;
184 return d->m_intervals;
182 }
185 }
183
186
184 /*!
187 /*!
185 Returns number of categories.
188 Returns number of intervals.
186 */
189 */
187 int QIntervalsAxis::count() const
190 int QIntervalsAxis::count() const
188 {
191 {
189 Q_D(const QIntervalsAxis);
192 Q_D(const QIntervalsAxis);
190 return d->m_intervals.count();
193 return d->m_intervals.count();
191 }
194 }
192
195
193 /*!
196 /*!
194 Returns the type of the axis
197 Returns the type of the axis
195 */
198 */
196 QAbstractAxis::AxisType QIntervalsAxis::type() const
199 QAbstractAxis::AxisType QIntervalsAxis::type() const
197 {
200 {
198 return QAbstractAxis::AxisTypeIntervals;
201 return QAbstractAxis::AxisTypeIntervals;
199 }
202 }
200
203
201 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
204 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
202
205
203 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
206 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
204 QValuesAxisPrivate(q),
207 QValuesAxisPrivate(q),
205 m_categoryMinimum(0)
208 m_categoryMinimum(0)
206 {
209 {
207
210
208 }
211 }
209
212
210 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
213 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
211 {
214 {
212
215
213 }
216 }
214
217
215 int QIntervalsAxisPrivate::ticksCount() const
218 int QIntervalsAxisPrivate::ticksCount() const
216 {
219 {
217 return m_intervals.count() + 1;
220 return m_intervals.count() + 1;
218 }
221 }
219
222
220 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
223 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
221 {
224 {
222 Q_UNUSED(count);
225 Q_UNUSED(count);
223 Q_UNUSED(min);
226 Q_UNUSED(min);
224 Q_UNUSED(max);
227 Q_UNUSED(max);
225 //m_min = min;
228 //m_min = min;
226 //m_max = max;
229 //m_max = max;
227 }
230 }
228
231
229 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
232 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
230 {
233 {
231 Q_Q(QIntervalsAxis);
234 Q_Q(QIntervalsAxis);
232 if(m_orientation == Qt::Vertical){
235 if(m_orientation == Qt::Vertical){
233 return new ChartIntervalAxisY(q,presenter);
236 return new ChartIntervalAxisY(q,presenter);
234 }else{
237 }else{
235 return new ChartIntervalAxisX(q,presenter);
238 return new ChartIntervalAxisX(q,presenter);
236 }
239 }
237 }
240 }
238
241
239 #include "moc_qintervalsaxis.cpp"
242 #include "moc_qintervalsaxis.cpp"
240 #include "moc_qintervalsaxis_p.cpp"
243 #include "moc_qintervalsaxis_p.cpp"
241
244
242 QTCOMMERCIALCHART_END_NAMESPACE
245 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,65 +1,65
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 "qvaluesaxis.h"
25 #include "qvaluesaxis.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QIntervalsAxisPrivate;
29 class QIntervalsAxisPrivate;
30
30
31 class QTCOMMERCIALCHART_EXPORT QIntervalsAxis : public QValuesAxis
31 class QTCOMMERCIALCHART_EXPORT QIntervalsAxis : public QValuesAxis
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34
34
35 public:
35 public:
36 explicit QIntervalsAxis(QObject *parent = 0);
36 explicit QIntervalsAxis(QObject *parent = 0);
37 ~QIntervalsAxis();
37 ~QIntervalsAxis();
38
38
39 protected:
39 protected:
40 QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent = 0);
40 QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent = 0);
41
41
42 public:
42 public:
43 AxisType type() const;
43 AxisType type() const;
44
44
45 void append(const QString& label, qreal interval = 1);
45 void append(const QString& label, qreal intervalEnd);
46 void remove(const QString& label);
46 void remove(const QString& label);
47 void replace(const QString& oldLabel, const QString& newLabel);
47 void replaceLabel(const QString& oldLabel, const QString& newLabel);
48
48
49 void setFisrtIntervalMinimum(qreal min);
49 void setFisrtIntervalMinimum(qreal min);
50
50
51 qreal intervalMin(const QString& intervalLabel) const;
51 qreal intervalMin(const QString& intervalLabel) const;
52 qreal intervalMax(const QString& intervalLabel) const;
52 qreal intervalMax(const QString& intervalLabel) const;
53
53
54 QStringList intervalsLabels();
54 QStringList intervalsLabels();
55 int count() const;
55 int count() const;
56
56
57
57
58 private:
58 private:
59 Q_DECLARE_PRIVATE(QIntervalsAxis)
59 Q_DECLARE_PRIVATE(QIntervalsAxis)
60 Q_DISABLE_COPY(QIntervalsAxis)
60 Q_DISABLE_COPY(QIntervalsAxis)
61 };
61 };
62
62
63 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
64
64
65 #endif // QCATEGORIESAXIS_H
65 #endif // QCATEGORIESAXIS_H
1 NO CONTENT: modified file
NO CONTENT: modified file
General Comments 0
You need to be logged in to leave comments. Login now