##// END OF EJS Templates
barcategoriesaxis documentation. Doc stub to intervalaxis
sauimone -
r1624:aa412a1538c7
parent child
Show More
@@ -1,84 +1,87
1 1 /*!
2 2 \page classes.html
3 3 \title QtCommercial Charts API
4 4 \keyword All Classes
5 5
6 6 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
7 7 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
8 8
9 9 Each chart type is represented by QAbstractSeries derived class. To create given chart type users have to use instance of related series class and add it to QChart instance.
10 10 \code
11 11 QLineSeries* series = new QLineSeries();
12 12 series->add(0, 6);
13 13 series->add(2, 4);
14 14 ...
15 15 chartView->chart()->addSeries(series);
16 16 \endcode
17 17
18 18 \raw HTML
19 19 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
20 20 <tr>
21 21 <th class="titleheader" width="25%">
22 22 Common and global
23 23 </th>
24 24 <th class="titleheader" width="25%">
25 25 XY chart
26 26 </th>
27 27 </tr>
28 28 <tr>
29 29 <td valign="top">
30 30 <ul>
31 31 <li><a href="qchart.html">QChart</a></li>
32 <li><a href="qaxis.html">QAxis</a></li>
32 <li><a href="qabstractaxis.html">QAbstractAxis</a></li>
33 <li><a href="qvaluesaxis.html">QValuesAxis</a></li>
34 <li><a href="qbarcategoriesaxis.html">QBarCategoriesAxis</a></li>
35 <li><a href="qintervalaxis.html">QIntervalAxis</a></li>
33 36 <li><a href="qaxiscategories.html">QAxisCategories</a></li>
34 37 <li><a href="qchartview.html">QChartView</a></li>
35 38 <li><a href="qlegend.html">QLegend</a></li>
36 39 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
37 40 <li><a href="qchartglobal.html">QChartGlobal</a></li>
38 41 </ul>
39 42 </td>
40 43 <td valign="top">
41 44 <ul>
42 45 <li><a href="qxyseries.html">QXYSeries</a></li>
43 46 <li><a href="qlineseries.html">QLineSeries</a></li>
44 47 <li><a href="qareaseries.html">QAreaSeries</a></li>
45 48 <li><a href="qscatterseries.html">QScatterSeries</a></li>
46 49 <li><a href="qsplineseries.html">QSplineSeries</a></li>
47 50 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
48 51 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
49 52 </ul>
50 53 </td>
51 54 </tr>
52 55 </table>
53 56 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
54 57 <tr>
55 58 <th class="titleheader" width="25%">
56 59 Pie chart
57 60 </th>
58 61 <th class="titleheader" width="25%">
59 62 Bar chart
60 63 </th>
61 64 <tr>
62 65 <td valign="top">
63 66 <ul>
64 67 <li><a href="qpieseries.html">QPieSeries</a></li>
65 68 <li><a href="qpieslice.html">QPieSlice</a></li>
66 69 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
67 70 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
68 71 </ul>
69 72 </td>
70 73 <td valign="top">
71 74 <ul>
72 75 <li><a href="qbarseries.html">QBarSeries</a></li>
73 76 <li><a href="qbarset.html">QBarSet</a></li>
74 77 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
75 78 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
76 79 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
77 80 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
78 81 </ul>
79 82 </td>
80 83 </tr>
81 84 </table>
82 85 \endraw
83 86
84 87 */
@@ -1,299 +1,364
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 "qbarcategoriesaxis.h"
22 22 #include "qbarcategoriesaxis_p.h"
23 23 #include "chartcategoriesaxisx_p.h"
24 24 #include "chartcategoriesaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
30 \class QBarCategoriesAxis
31 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
32 \mainclass
33
34 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 */
36
37 /*!
38 \qmlclass Axis QBarCategoriesAxis
39 \brief The Axis element is used for manipulating chart's axes.
40
41 Axis can be setup to show axis line with tick marks, grid lines and shades.
42
43 To access Axes you can use ChartView API. For example:
44 \code
45 ChartView {
46 axisX.min: "Feb"
47 axisX.max: "Jun"
48 // Add a few series...
49 }
50 \endcode
51 */
52
53 /*!
54 \property QBarCategoriesAxis::categories
55 Defines the categories of axis
56 */
57 /*!
58 \qmlproperty QStringList Axis::categories
59 Defines the categories of axis
60 */
61
62 /*!
63 \property QBarCategoriesAxis::min
64 Defines the minimum value on the axis.
65 */
66 /*!
67 \qmlproperty real Axis::min
68 Defines the minimum value on the axis.
69 */
70
71 /*!
72 \property QBarCategoriesAxis::max
73 Defines the maximum value on the axis.
74 */
75 /*!
76 \qmlproperty real Axis::max
77 Defines the maximum value on the axis.
78 */
79
80 /*!
81 \fn void QBarCategoriesAxis::minChanged(const QString &min)
82 Axis emits signal when \a min of axis has changed.
83 */
84
85 /*!
86 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
87 Axis emits signal when \a max of axis has changed.
88 */
89
90 /*!
91 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
92 Axis emits signal when \a min or \a max of axis has changed.
93 */
29 94
30 95 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
31 96 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
32 97 {
33 98 }
34 99
35 100 QBarCategoriesAxis::~QBarCategoriesAxis()
36 101 {
37 102 }
38 103
39 104 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
40 105 {
41 106
42 107 }
43 108
44 109 /*!
45 110 Appends \a categories to axis
46 111 */
47 112 void QBarCategoriesAxis::append(const QStringList &categories)
48 113 {
49 114 Q_D(QBarCategoriesAxis);
50 115 if (d->m_categories.isEmpty()) {
51 116 d->m_categories.append(categories);
52 117 setRange(categories.first(),categories.last());
53 118 }else{
54 119 d->m_categories.append(categories);
55 120 }
56 121
57 122 emit categoriesChanged();
58 123 }
59 124
60 125 /*!
61 126 Appends \a category to axis
62 127 */
63 128 void QBarCategoriesAxis::append(const QString &category)
64 129 {
65 130 Q_D(QBarCategoriesAxis);
66 131 if (d->m_categories.isEmpty()) {
67 132 d->m_categories.append(category);
68 133 setRange(category,category);
69 134 }else{
70 135 d->m_categories.append(category);
71 136 }
72 137 emit categoriesChanged();
73 138 }
74 139
75 140 /*!
76 141 Removes \a category from axis
77 142 */
78 143 void QBarCategoriesAxis::remove(const QString &category)
79 144 {
80 145 Q_D(QBarCategoriesAxis);
81 146 if (d->m_categories.contains(category)) {
82 147 d->m_categories.removeAt(d->m_categories.indexOf(category));
83 148 setRange(d->m_categories.first(),d->m_categories.last());
84 149 emit categoriesChanged();
85 150 }
86 151 }
87 152
88 153 /*!
89 154 Inserts \a category to axis at \a index
90 155 */
91 156 void QBarCategoriesAxis::insert(int index, const QString &category)
92 157 {
93 158 Q_D(QBarCategoriesAxis);
94 159 if (d->m_categories.isEmpty()) {
95 160 d->m_categories.insert(index,category);
96 161 setRange(category,category);
97 162 }else{
98 163
99 164 }
100 165 emit categoriesChanged();
101 166 }
102 167
103 168 /*!
104 169 Removes all categories.
105 170 */
106 171 void QBarCategoriesAxis::clear()
107 172 {
108 173 Q_D(QBarCategoriesAxis);
109 174 d->m_categories.clear();
110 175 setRange(QString::null,QString::null);
111 176 emit categoriesChanged();
112 177 }
113 178
114 179 void QBarCategoriesAxis::setCategories(const QStringList &categories)
115 180 {
116 181 Q_D(QBarCategoriesAxis);
117 182 if(d->m_categories!=categories){
118 183 d->m_categories = categories;
119 184 setRange(categories.first(),categories.last());
120 185 emit categoriesChanged();
121 186 }
122 187 }
123 188
124 189 QStringList QBarCategoriesAxis::categories()
125 190 {
126 191 Q_D(QBarCategoriesAxis);
127 192 return d->m_categories;
128 193 }
129 194
130 195 /*!
131 196 Returns number of categories.
132 197 */
133 198 int QBarCategoriesAxis::count() const
134 199 {
135 200 Q_D(const QBarCategoriesAxis);
136 201 return d->m_categories.count();
137 202 }
138 203
139 204 /*!
140 205 Returns category at \a index. Index must be valid.
141 206 */
142 207 QString QBarCategoriesAxis::at(int index) const
143 208 {
144 209 Q_D(const QBarCategoriesAxis);
145 210 return d->m_categories.at(index);
146 211 }
147 212
148 213 /*!
149 214 Sets minimum category to \a min.
150 215 */
151 216 void QBarCategoriesAxis::setMin(const QString& min)
152 217 {
153 218 Q_D(QBarCategoriesAxis);
154 219 setRange(min,d->m_maxCategory);
155 220 }
156 221
157 222 /*!
158 223 Returns minimum category.
159 224 */
160 225 QString QBarCategoriesAxis::min() const
161 226 {
162 227 Q_D(const QBarCategoriesAxis);
163 228 return d->m_minCategory;
164 229 }
165 230
166 231 /*!
167 232 Sets maximum category to \a max.
168 233 */
169 234 void QBarCategoriesAxis::setMax(const QString& max)
170 235 {
171 236 Q_D(QBarCategoriesAxis);
172 237 setRange(d->m_minCategory,max);
173 238 }
174 239
175 240 /*!
176 241 Returns maximum category
177 242 */
178 243 QString QBarCategoriesAxis::max() const
179 244 {
180 245 Q_D(const QBarCategoriesAxis);
181 246 return d->m_maxCategory;
182 247 }
183 248
184 249 /*!
185 250 Sets range from \a minCategory to \a maxCategory
186 251 */
187 252 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
188 253 {
189 254 Q_D(QBarCategoriesAxis);
190 255
191 256 int minIndex = d->m_categories.indexOf(minCategory);
192 257 if (minIndex == -1) {
193 258 return;
194 259 }
195 260 int maxIndex = d->m_categories.indexOf(maxCategory);
196 261 if (maxIndex == -1) {
197 262 return;
198 263 }
199 264
200 265 if (maxIndex <= minIndex) {
201 266 // max must be greater than min
202 267 return;
203 268 }
204 269
205 270 bool changed = false;
206 271 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
207 272 d->m_minCategory = minCategory;
208 273 d->m_min = minIndex;
209 274 emit minChanged(minCategory);
210 275 changed = true;
211 276 }
212 277
213 278 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
214 279 d->m_max = maxIndex;
215 280 d->m_maxCategory = maxCategory;
216 281 emit maxChanged(maxCategory);
217 282 changed = true;
218 283 }
219 284
220 285 if ((changed)) {
221 286 d->emitRange();
222 287 emit categoriesChanged();
223 288 }
224 289 }
225 290
226 291 /*!
227 292 Returns the type of axis.
228 293 */
229 294 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
230 295 {
231 296 return AxisTypeCategories;
232 297 }
233 298
234 299 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
235 300
236 301 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
237 302 QAbstractAxisPrivate(q)
238 303 {
239 304
240 305 }
241 306
242 307 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
243 308 {
244 309
245 310 }
246 311
247 312 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
248 313 {
249 314 setRange(min,m_maxCategory);
250 315 }
251 316
252 317 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
253 318 {
254 319 setRange(m_minCategory,max);
255 320 }
256 321
257 322 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
258 323 {
259 324 Q_Q(QBarCategoriesAxis);
260 325 QString value1 = min.toString();
261 326 QString value2 = max.toString();
262 327 q->setRange(value1,value2);
263 328 }
264 329
265 330 int QBarCategoriesAxisPrivate::ticksCount() const
266 331 {
267 332 return m_categories.count()+1;
268 333 }
269 334
270 335 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
271 336 {
272 337 m_min = min;
273 338 m_max = max;
274 339 m_ticksCount = count;
275 340 }
276 341
277 342 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
278 343 {
279 344 Q_Q( QBarCategoriesAxis);
280 345 if(m_orientation == Qt::Vertical){
281 346 return new ChartCategoriesAxisY(q,presenter);
282 347 }else{
283 348 return new ChartCategoriesAxisX(q,presenter);
284 349 }
285 350 }
286 351
287 352 void QBarCategoriesAxisPrivate::emitRange()
288 353 {
289 354 Q_Q( QBarCategoriesAxis);
290 355 if(!q->signalsBlocked()) {
291 356 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
292 357 }
293 358 }
294 359
295 360
296 361 #include "moc_qbarcategoriesaxis.cpp"
297 362 #include "moc_qbarcategoriesaxis_p.cpp"
298 363
299 364 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,149 +1,169
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 "qintervalaxis.h"
22 22 #include "qintervalaxis_p.h"
23 23 #include "chartcategoriesaxisx_p.h"
24 24 #include "chartcategoriesaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
30 \class QIntervalAxis
31 \brief The QIntervalAxis class is used for manipulating chart's axis.
32 \mainclass
33
34 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 */
36
37 /*!
38 \qmlclass Axis QIntervalAxis
39 \brief The Axis element is used for manipulating chart's axes.
40
41 Axis can be setup to show axis line with tick marks, grid lines and shades.
42
43 To access Axes you can use ChartView API. For example:
44 \code
45 // TODO :)
46 \endcode
47 */
48
29 49
30 50 QIntervalAxis::QIntervalAxis(QObject *parent):
31 51 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
32 52 {
33 53 }
34 54
35 55 QIntervalAxis::~QIntervalAxis()
36 56 {
37 57 }
38 58
39 59 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
40 60 {
41 61
42 62 }
43 63
44 64 /*!
45 65 Appends \a categories to axis
46 66 */
47 67 void QIntervalAxis::append(const QString& category, qreal x)
48 68 {
49 69 Q_D(QIntervalAxis);
50 70 if (!d->m_categories.contains(category))
51 71 {
52 72 if(d->m_categories.isEmpty()){
53 73 Range range(d->m_categoryMinimum,x);
54 74 d->m_categoriesMap.insert(category,range);
55 75 d->m_categories.append(category);
56 76 }else{
57 77 Range range = d->m_categoriesMap.value(d->m_categories.last());
58 78 d->m_categoriesMap.insert(category,Range(range.first,x));
59 79 d->m_categories.append(category);
60 80 }
61 81 setRange(d->m_min,x);
62 82 }
63 83 }
64 84
65 85 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
66 86 {
67 87 Q_D(QIntervalAxis);
68 88 if(d->m_categories.isEmpty()){
69 89 d->m_categoryMinimum=x;
70 90 }else{
71 91 Range range = d->m_categoriesMap.value(d->m_categories.first());
72 92 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
73 93 setRange(x,d->m_min);
74 94 }
75 95 }
76 96
77 97 /*!
78 98 Removes \a category from axis
79 99 */
80 100 void QIntervalAxis::remove(const QString &category)
81 101 {
82 102 Q_UNUSED(category);
83 103 //TODO
84 104 }
85 105
86 106 QStringList QIntervalAxis::categories()
87 107 {
88 108 Q_D(QIntervalAxis);
89 109 return d->m_categories;
90 110 }
91 111
92 112 /*!
93 113 Returns number of categories.
94 114 */
95 115 int QIntervalAxis::count() const
96 116 {
97 117 Q_D(const QIntervalAxis);
98 118 return d->m_categories.count();
99 119 }
100 120
101 121 /*!
102 122 Returns the type of axis.
103 123 */
104 124 QAbstractAxis::AxisType QIntervalAxis::type() const
105 125 {
106 126 return AxisTypeCategories;
107 127 }
108 128
109 129 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110 130
111 131 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
112 132 QValuesAxisPrivate(q),
113 133 m_categoryMinimum(0)
114 134 {
115 135
116 136 }
117 137
118 138 QIntervalAxisPrivate::~QIntervalAxisPrivate()
119 139 {
120 140
121 141 }
122 142
123 143 int QIntervalAxisPrivate::ticksCount() const
124 144 {
125 145 return m_categories.count()+1;
126 146 }
127 147
128 148 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
129 149 {
130 150 m_min = min;
131 151 m_max = max;
132 152 m_ticksCount = count;
133 153 }
134 154
135 155 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
136 156 {
137 157 Q_UNUSED(presenter);
138 158 // Q_Q( QCategoriesAxis);
139 159 if(m_orientation == Qt::Vertical){
140 160 return 0;
141 161 }else{
142 162 return 0;
143 163 }
144 164 }
145 165
146 166 #include "moc_qintervalaxis.cpp"
147 167 #include "moc_qintervalaxis_p.cpp"
148 168
149 169 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now