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