##// END OF EJS Templates
QCategoryAxis: method parameter name updated
Marek Rosa -
r1849:36af7b811b66
parent child
Show More
@@ -1,261 +1,261
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 */
36 */
37
37
38 /*!
38 /*!
39 \qmlclass CategoryAxis QCategoryAxis
39 \qmlclass CategoryAxis QCategoryAxis
40 \brief The QCategoryAxis class allows putting a named ranges on the axis.
40 \brief The QCategoryAxis class allows putting a named ranges on the axis.
41 */
41 */
42
42
43 /*!
43 /*!
44 \property QCategoryAxis::startValue
44 \property QCategoryAxis::startValue
45 Defines the low end of the first category on the axis.
45 Defines the low end of the first category on the axis.
46 */
46 */
47
47
48 /*!
48 /*!
49 \qmlproperty int CategoryAxis::startValue
49 \qmlproperty int CategoryAxis::startValue
50 Defines the low end of the first category on the axis.
50 Defines the low end of the first category on the axis.
51 */
51 */
52
52
53 /*!
53 /*!
54 Constructs an axis object which is a child of \a parent.
54 Constructs an axis object which is a child of \a parent.
55 */
55 */
56 QCategoryAxis::QCategoryAxis(QObject *parent):
56 QCategoryAxis::QCategoryAxis(QObject *parent):
57 QValueAxis(*new QCategoryAxisPrivate(this),parent)
57 QValueAxis(*new QCategoryAxisPrivate(this),parent)
58 {
58 {
59 }
59 }
60
60
61 /*!
61 /*!
62 Destroys the object
62 Destroys the object
63 */
63 */
64 QCategoryAxis::~QCategoryAxis()
64 QCategoryAxis::~QCategoryAxis()
65 {
65 {
66 // Q_D(QValueAxis);
66 // Q_D(QValueAxis);
67 // if(d->m_dataset) {
67 // if(d->m_dataset) {
68 // d->m_dataset->removeAxis(this);
68 // d->m_dataset->removeAxis(this);
69 // }
69 // }
70 }
70 }
71
71
72 /*!
72 /*!
73 \internal
73 \internal
74 */
74 */
75 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
75 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
76 {
76 {
77
77
78 }
78 }
79
79
80 /*!
80 /*!
81 Appends new category to the axis with an \a categoryLabel.
81 Appends new category to the axis with an \a categoryLabel.
82 Category label has to be unique.
82 Category label has to be unique.
83 Parameter \a categoryHighEnd specifies the high end limit of the category.
83 Parameter \a categoryEndValue specifies the high end limit of the category.
84 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.
85 Otherwise the method returns without adding a new category.
85 Otherwise the method returns without adding a new category.
86 */
86 */
87 void QCategoryAxis::append(const QString& categoryLabel, qreal categoryHighEnd)
87 void QCategoryAxis::append(const QString& categoryLabel, qreal categoryEndValue)
88 {
88 {
89 Q_D(QCategoryAxis);
89 Q_D(QCategoryAxis);
90
90
91 if (!d->m_categories.contains(categoryLabel))
91 if (!d->m_categories.contains(categoryLabel))
92 {
92 {
93 if(d->m_categories.isEmpty()){
93 if(d->m_categories.isEmpty()){
94 Range range(d->m_categoryMinimum, categoryHighEnd);
94 Range range(d->m_categoryMinimum, categoryEndValue);
95 d->m_categoriesMap.insert(categoryLabel, range);
95 d->m_categoriesMap.insert(categoryLabel, range);
96 d->m_categories.append(categoryLabel);
96 d->m_categories.append(categoryLabel);
97 }else if (categoryHighEnd > endValue(d->m_categories.last())){
97 }else if (categoryEndValue > endValue(d->m_categories.last())){
98 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
98 Range previousRange = d->m_categoriesMap.value(d->m_categories.last());
99 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryHighEnd));
99 d->m_categoriesMap.insert(categoryLabel, Range(previousRange.second, categoryEndValue));
100 d->m_categories.append(categoryLabel);
100 d->m_categories.append(categoryLabel);
101 }
101 }
102 }
102 }
103 }
103 }
104
104
105 /*!
105 /*!
106 Sets \a min to be the low end limit of the first category on the axis.
106 Sets \a min to be the low end limit of the first category on the axis.
107 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.
107 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.
108 Otherwise nothing is done.
108 Otherwise nothing is done.
109 */
109 */
110 void QCategoryAxis::setStartValue(qreal min)
110 void QCategoryAxis::setStartValue(qreal min)
111 {
111 {
112 Q_D(QCategoryAxis);
112 Q_D(QCategoryAxis);
113 if(d->m_categories.isEmpty()){
113 if(d->m_categories.isEmpty()){
114 d->m_categoryMinimum = min;
114 d->m_categoryMinimum = min;
115 }else{
115 }else{
116 Range range = d->m_categoriesMap.value(d->m_categories.first());
116 Range range = d->m_categoriesMap.value(d->m_categories.first());
117 if (min < range.second)
117 if (min < range.second)
118 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
118 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
119 }
119 }
120 }
120 }
121
121
122 /*!
122 /*!
123 Returns the low end limit of the category specified by an \a categoryLabel
123 Returns the low end limit of the category specified by an \a categoryLabel
124 */
124 */
125 qreal QCategoryAxis::startValue(const QString& categoryLabel) const
125 qreal QCategoryAxis::startValue(const QString& categoryLabel) const
126 {
126 {
127 Q_D(const QCategoryAxis);
127 Q_D(const QCategoryAxis);
128 if (categoryLabel == QString())
128 if (categoryLabel == QString())
129 return d->m_categoryMinimum;
129 return d->m_categoryMinimum;
130 else
130 else
131 return d->m_categoriesMap.value(categoryLabel).first;
131 return d->m_categoriesMap.value(categoryLabel).first;
132 }
132 }
133
133
134 /*!
134 /*!
135 Returns the high end limit of the interval specified by an \a categoryLabel
135 Returns the high end limit of the interval specified by an \a categoryLabel
136 */
136 */
137 qreal QCategoryAxis::endValue(const QString& categoryLabel) const
137 qreal QCategoryAxis::endValue(const QString& categoryLabel) const
138 {
138 {
139 Q_D(const QCategoryAxis);
139 Q_D(const QCategoryAxis);
140 return d->m_categoriesMap.value(categoryLabel).second;
140 return d->m_categoriesMap.value(categoryLabel).second;
141 }
141 }
142
142
143 /*!
143 /*!
144 Removes an interval specified by the \a categoryLabel from the axis
144 Removes an interval specified by the \a categoryLabel from the axis
145 */
145 */
146 void QCategoryAxis::remove(const QString &categoryLabel)
146 void QCategoryAxis::remove(const QString &categoryLabel)
147 {
147 {
148 Q_D(QCategoryAxis);
148 Q_D(QCategoryAxis);
149 int labelIndex = d->m_categories.indexOf(categoryLabel);
149 int labelIndex = d->m_categories.indexOf(categoryLabel);
150
150
151 // check if such label exists
151 // check if such label exists
152 if (labelIndex != -1) {
152 if (labelIndex != -1) {
153 d->m_categories.removeAt(labelIndex);
153 d->m_categories.removeAt(labelIndex);
154 d->m_categoriesMap.remove(categoryLabel);
154 d->m_categoriesMap.remove(categoryLabel);
155
155
156 // the range of the interval that follows (if exists) needs to be updated
156 // the range of the interval that follows (if exists) needs to be updated
157 if (labelIndex < d->m_categories.count()) {
157 if (labelIndex < d->m_categories.count()) {
158 QString label = d->m_categories.at(labelIndex);
158 QString label = d->m_categories.at(labelIndex);
159 Range range = d->m_categoriesMap.value(label);
159 Range range = d->m_categoriesMap.value(label);
160
160
161 // set the range
161 // set the range
162 if (labelIndex == 0) {
162 if (labelIndex == 0) {
163 range.first = d->m_categoryMinimum;
163 range.first = d->m_categoryMinimum;
164 d->m_categoriesMap.insert(label, range);
164 d->m_categoriesMap.insert(label, range);
165 } else {
165 } else {
166 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
166 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
167 d->m_categoriesMap.insert(label, range);
167 d->m_categoriesMap.insert(label, range);
168 }
168 }
169 }
169 }
170 d->emitUpdated();
170 d->emitUpdated();
171 }
171 }
172 }
172 }
173
173
174 /*!
174 /*!
175 Replaces \a oldLabel of an existing category with a \a newLabel
175 Replaces \a oldLabel of an existing category with a \a newLabel
176 If the old label does not exist the method returns without making any changes.
176 If the old label does not exist the method returns without making any changes.
177 */
177 */
178 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
178 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
179 {
179 {
180 Q_D(QCategoryAxis);
180 Q_D(QCategoryAxis);
181 int labelIndex = d->m_categories.indexOf(oldLabel);
181 int labelIndex = d->m_categories.indexOf(oldLabel);
182
182
183 // check if such label exists
183 // check if such label exists
184 if (labelIndex != -1) {
184 if (labelIndex != -1) {
185 d->m_categories.replace(labelIndex, newLabel);
185 d->m_categories.replace(labelIndex, newLabel);
186 Range range = d->m_categoriesMap.value(oldLabel);
186 Range range = d->m_categoriesMap.value(oldLabel);
187 d->m_categoriesMap.remove(oldLabel);
187 d->m_categoriesMap.remove(oldLabel);
188 d->m_categoriesMap.insert(newLabel, range);
188 d->m_categoriesMap.insert(newLabel, range);
189 d->emitUpdated();
189 d->emitUpdated();
190 }
190 }
191
191
192 }
192 }
193
193
194 /*!
194 /*!
195 Returns the list of the intervals labels
195 Returns the list of the intervals labels
196 */
196 */
197 QStringList QCategoryAxis::categoriesLabels()
197 QStringList QCategoryAxis::categoriesLabels()
198 {
198 {
199 Q_D(QCategoryAxis);
199 Q_D(QCategoryAxis);
200 return d->m_categories;
200 return d->m_categories;
201 }
201 }
202
202
203 /*!
203 /*!
204 Returns number of intervals.
204 Returns number of intervals.
205 */
205 */
206 int QCategoryAxis::count() const
206 int QCategoryAxis::count() const
207 {
207 {
208 Q_D(const QCategoryAxis);
208 Q_D(const QCategoryAxis);
209 return d->m_categories.count();
209 return d->m_categories.count();
210 }
210 }
211
211
212 /*!
212 /*!
213 Returns the type of the axis
213 Returns the type of the axis
214 */
214 */
215 QAbstractAxis::AxisType QCategoryAxis::type() const
215 QAbstractAxis::AxisType QCategoryAxis::type() const
216 {
216 {
217 return QAbstractAxis::AxisTypeCategory;
217 return QAbstractAxis::AxisTypeCategory;
218 }
218 }
219
219
220 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
220 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
221
221
222 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q):
222 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q):
223 QValueAxisPrivate(q),
223 QValueAxisPrivate(q),
224 m_categoryMinimum(0)
224 m_categoryMinimum(0)
225 {
225 {
226
226
227 }
227 }
228
228
229 QCategoryAxisPrivate::~QCategoryAxisPrivate()
229 QCategoryAxisPrivate::~QCategoryAxisPrivate()
230 {
230 {
231
231
232 }
232 }
233
233
234 int QCategoryAxisPrivate::ticksCount() const
234 int QCategoryAxisPrivate::ticksCount() const
235 {
235 {
236 return m_categories.count() + 1;
236 return m_categories.count() + 1;
237 }
237 }
238
238
239 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
239 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
240 {
240 {
241 Q_UNUSED(count);
241 Q_UNUSED(count);
242 Q_UNUSED(min);
242 Q_UNUSED(min);
243 Q_UNUSED(max);
243 Q_UNUSED(max);
244 //m_min = min;
244 //m_min = min;
245 //m_max = max;
245 //m_max = max;
246 }
246 }
247
247
248 ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
248 ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
249 {
249 {
250 Q_Q(QCategoryAxis);
250 Q_Q(QCategoryAxis);
251 if(m_orientation == Qt::Vertical){
251 if(m_orientation == Qt::Vertical){
252 return new ChartCategoryAxisY(q,presenter);
252 return new ChartCategoryAxisY(q,presenter);
253 }else{
253 }else{
254 return new ChartCategoryAxisX(q,presenter);
254 return new ChartCategoryAxisX(q,presenter);
255 }
255 }
256 }
256 }
257
257
258 #include "moc_qcategoryaxis.cpp"
258 #include "moc_qcategoryaxis.cpp"
259 #include "moc_qcategoryaxis_p.cpp"
259 #include "moc_qcategoryaxis_p.cpp"
260
260
261 QTCOMMERCIALCHART_END_NAMESPACE
261 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now