##// 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 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qcategoryaxis.h"
22 22 #include "qcategoryaxis_p.h"
23 23 #include "chartcategoryaxisx_p.h"
24 24 #include "chartcategoryaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 /*!
30 30 \class QCategoryAxis
31 31 \brief The QCategoryAxis class allows putting a named ranges on the axis.
32 32 \mainclass
33 33
34 34 This class can be used when the underlying data needs to be given extra meaning.
35 35 Unlike with the QBarCategoryAxis the QCategoryAxis allows the categories ranges widths to be specified freely.
36 36 */
37 37
38 38 /*!
39 39 \qmlclass CategoryAxis QCategoryAxis
40 40 \brief The QCategoryAxis class allows putting a named ranges on the axis.
41 41 */
42 42
43 43 /*!
44 44 \property QCategoryAxis::startValue
45 45 Defines the low end of the first category on the axis.
46 46 */
47 47
48 48 /*!
49 49 \qmlproperty int CategoryAxis::startValue
50 50 Defines the low end of the first category on the axis.
51 51 */
52 52
53 53 /*!
54 54 Constructs an axis object which is a child of \a parent.
55 55 */
56 56 QCategoryAxis::QCategoryAxis(QObject *parent):
57 57 QValueAxis(*new QCategoryAxisPrivate(this),parent)
58 58 {
59 59 }
60 60
61 61 /*!
62 62 Destroys the object
63 63 */
64 64 QCategoryAxis::~QCategoryAxis()
65 65 {
66 66 // Q_D(QValueAxis);
67 67 // if(d->m_dataset) {
68 68 // d->m_dataset->removeAxis(this);
69 69 // }
70 70 }
71 71
72 72 /*!
73 73 \internal
74 74 */
75 75 QCategoryAxis::QCategoryAxis(QCategoryAxisPrivate &d,QObject *parent):QValueAxis(d,parent)
76 76 {
77 77
78 78 }
79 79
80 80 /*!
81 81 Appends new category to the axis with an \a categoryLabel.
82 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 84 It has to be greater than the high end limit of the previous category.
85 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 89 Q_D(QCategoryAxis);
90 90
91 91 if (!d->m_categories.contains(categoryLabel))
92 92 {
93 93 if(d->m_categories.isEmpty()){
94 Range range(d->m_categoryMinimum, categoryHighEnd);
94 Range range(d->m_categoryMinimum, categoryEndValue);
95 95 d->m_categoriesMap.insert(categoryLabel, range);
96 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 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 100 d->m_categories.append(categoryLabel);
101 101 }
102 102 }
103 103 }
104 104
105 105 /*!
106 106 Sets \a min to be the low end limit of the first category on the axis.
107 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 108 Otherwise nothing is done.
109 109 */
110 110 void QCategoryAxis::setStartValue(qreal min)
111 111 {
112 112 Q_D(QCategoryAxis);
113 113 if(d->m_categories.isEmpty()){
114 114 d->m_categoryMinimum = min;
115 115 }else{
116 116 Range range = d->m_categoriesMap.value(d->m_categories.first());
117 117 if (min < range.second)
118 118 d->m_categoriesMap.insert(d->m_categories.first(), Range(min, range.second));
119 119 }
120 120 }
121 121
122 122 /*!
123 123 Returns the low end limit of the category specified by an \a categoryLabel
124 124 */
125 125 qreal QCategoryAxis::startValue(const QString& categoryLabel) const
126 126 {
127 127 Q_D(const QCategoryAxis);
128 128 if (categoryLabel == QString())
129 129 return d->m_categoryMinimum;
130 130 else
131 131 return d->m_categoriesMap.value(categoryLabel).first;
132 132 }
133 133
134 134 /*!
135 135 Returns the high end limit of the interval specified by an \a categoryLabel
136 136 */
137 137 qreal QCategoryAxis::endValue(const QString& categoryLabel) const
138 138 {
139 139 Q_D(const QCategoryAxis);
140 140 return d->m_categoriesMap.value(categoryLabel).second;
141 141 }
142 142
143 143 /*!
144 144 Removes an interval specified by the \a categoryLabel from the axis
145 145 */
146 146 void QCategoryAxis::remove(const QString &categoryLabel)
147 147 {
148 148 Q_D(QCategoryAxis);
149 149 int labelIndex = d->m_categories.indexOf(categoryLabel);
150 150
151 151 // check if such label exists
152 152 if (labelIndex != -1) {
153 153 d->m_categories.removeAt(labelIndex);
154 154 d->m_categoriesMap.remove(categoryLabel);
155 155
156 156 // the range of the interval that follows (if exists) needs to be updated
157 157 if (labelIndex < d->m_categories.count()) {
158 158 QString label = d->m_categories.at(labelIndex);
159 159 Range range = d->m_categoriesMap.value(label);
160 160
161 161 // set the range
162 162 if (labelIndex == 0) {
163 163 range.first = d->m_categoryMinimum;
164 164 d->m_categoriesMap.insert(label, range);
165 165 } else {
166 166 range.first = d->m_categoriesMap.value(d->m_categories.at(labelIndex - 1)).second;
167 167 d->m_categoriesMap.insert(label, range);
168 168 }
169 169 }
170 170 d->emitUpdated();
171 171 }
172 172 }
173 173
174 174 /*!
175 175 Replaces \a oldLabel of an existing category with a \a newLabel
176 176 If the old label does not exist the method returns without making any changes.
177 177 */
178 178 void QCategoryAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
179 179 {
180 180 Q_D(QCategoryAxis);
181 181 int labelIndex = d->m_categories.indexOf(oldLabel);
182 182
183 183 // check if such label exists
184 184 if (labelIndex != -1) {
185 185 d->m_categories.replace(labelIndex, newLabel);
186 186 Range range = d->m_categoriesMap.value(oldLabel);
187 187 d->m_categoriesMap.remove(oldLabel);
188 188 d->m_categoriesMap.insert(newLabel, range);
189 189 d->emitUpdated();
190 190 }
191 191
192 192 }
193 193
194 194 /*!
195 195 Returns the list of the intervals labels
196 196 */
197 197 QStringList QCategoryAxis::categoriesLabels()
198 198 {
199 199 Q_D(QCategoryAxis);
200 200 return d->m_categories;
201 201 }
202 202
203 203 /*!
204 204 Returns number of intervals.
205 205 */
206 206 int QCategoryAxis::count() const
207 207 {
208 208 Q_D(const QCategoryAxis);
209 209 return d->m_categories.count();
210 210 }
211 211
212 212 /*!
213 213 Returns the type of the axis
214 214 */
215 215 QAbstractAxis::AxisType QCategoryAxis::type() const
216 216 {
217 217 return QAbstractAxis::AxisTypeCategory;
218 218 }
219 219
220 220 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
221 221
222 222 QCategoryAxisPrivate::QCategoryAxisPrivate(QCategoryAxis* q):
223 223 QValueAxisPrivate(q),
224 224 m_categoryMinimum(0)
225 225 {
226 226
227 227 }
228 228
229 229 QCategoryAxisPrivate::~QCategoryAxisPrivate()
230 230 {
231 231
232 232 }
233 233
234 234 int QCategoryAxisPrivate::ticksCount() const
235 235 {
236 236 return m_categories.count() + 1;
237 237 }
238 238
239 239 void QCategoryAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
240 240 {
241 241 Q_UNUSED(count);
242 242 Q_UNUSED(min);
243 243 Q_UNUSED(max);
244 244 //m_min = min;
245 245 //m_max = max;
246 246 }
247 247
248 248 ChartAxis* QCategoryAxisPrivate::createGraphics(ChartPresenter* presenter)
249 249 {
250 250 Q_Q(QCategoryAxis);
251 251 if(m_orientation == Qt::Vertical){
252 252 return new ChartCategoryAxisY(q,presenter);
253 253 }else{
254 254 return new ChartCategoryAxisX(q,presenter);
255 255 }
256 256 }
257 257
258 258 #include "moc_qcategoryaxis.cpp"
259 259 #include "moc_qcategoryaxis_p.cpp"
260 260
261 261 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now