##// END OF EJS Templates
Some interval axis docs updates
Marek Rosa -
r1800:0d55302d18fc
parent child
Show More
@@ -1,89 +1,90
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 chartView->chart()->createDefaultAxes();
16 chartView->chart()->createDefaultAxes();
17 \endcode
17 \endcode
18
18
19 \raw HTML
19 \raw HTML
20 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
20 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
21 <tr>
21 <tr>
22 <th class="titleheader" width="25%">
22 <th class="titleheader" width="25%">
23 Common and global
23 Common and global
24 </th>
24 </th>
25 <th class="titleheader" width="25%">
25 <th class="titleheader" width="25%">
26 XY chart
26 XY chart
27 </th>
27 </th>
28 </tr>
28 </tr>
29 <tr>
29 <tr>
30 <td valign="top">
30 <td valign="top">
31 <ul>
31 <ul>
32 <li><a href="qchart.html">QChart</a></li>
32 <li><a href="qchart.html">QChart</a></li>
33 <li><a href="qchartview.html">QChartView</a></li>
33 <li><a href="qchartview.html">QChartView</a></li>
34 <li><a href="qabstractaxis.html">QAbstractAxis</a></li>
34 <li><a href="qabstractaxis.html">QAbstractAxis</a></li>
35 <li><a href="qvaluesaxis.html">QValuesAxis</a></li>
35 <li><a href="qvaluesaxis.html">QValuesAxis</a></li>
36 <li><a href="qbarcategoriesaxis.html">QBarCategoriesAxis</a></li>
36 <li><a href="qbarcategoriesaxis.html">QBarCategoriesAxis</a></li>
37 <li><a href="qintervalsaxis.html">QIntervalsAxis</a></li>
37 <li><a href="qlegend.html">QLegend</a></li>
38 <li><a href="qlegend.html">QLegend</a></li>
38 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
39 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
39 <li><a href="qchartglobal.html">QChartGlobal</a></li>
40 <li><a href="qchartglobal.html">QChartGlobal</a></li>
40 </ul>
41 </ul>
41 </td>
42 </td>
42 <td valign="top">
43 <td valign="top">
43 <ul>
44 <ul>
44 <li><a href="qxyseries.html">QXYSeries</a></li>
45 <li><a href="qxyseries.html">QXYSeries</a></li>
45 <li><a href="qlineseries.html">QLineSeries</a></li>
46 <li><a href="qlineseries.html">QLineSeries</a></li>
46 <li><a href="qareaseries.html">QAreaSeries</a></li>
47 <li><a href="qareaseries.html">QAreaSeries</a></li>
47 <li><a href="qscatterseries.html">QScatterSeries</a></li>
48 <li><a href="qscatterseries.html">QScatterSeries</a></li>
48 <li><a href="qsplineseries.html">QSplineSeries</a></li>
49 <li><a href="qsplineseries.html">QSplineSeries</a></li>
49 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
50 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
50 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
51 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
51 </ul>
52 </ul>
52 </td>
53 </td>
53 </tr>
54 </tr>
54 </table>
55 </table>
55 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
56 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
56 <tr>
57 <tr>
57 <th class="titleheader" width="25%">
58 <th class="titleheader" width="25%">
58 Pie chart
59 Pie chart
59 </th>
60 </th>
60 <th class="titleheader" width="25%">
61 <th class="titleheader" width="25%">
61 Bar chart
62 Bar chart
62 </th>
63 </th>
63 <tr>
64 <tr>
64 <td valign="top">
65 <td valign="top">
65 <ul>
66 <ul>
66 <li><a href="qpieseries.html">QPieSeries</a></li>
67 <li><a href="qpieseries.html">QPieSeries</a></li>
67 <li><a href="qpieslice.html">QPieSlice</a></li>
68 <li><a href="qpieslice.html">QPieSlice</a></li>
68 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
69 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
69 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
70 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
70 </ul>
71 </ul>
71 </td>
72 </td>
72 <td valign="top">
73 <td valign="top">
73 <ul>
74 <ul>
74 <li><a href="qbarseries.html">QBarSeries</a></li>
75 <li><a href="qbarseries.html">QBarSeries</a></li>
75 <li><a href="qbarset.html">QBarSet</a></li>
76 <li><a href="qbarset.html">QBarSet</a></li>
76 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
77 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
77 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
78 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
78 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
79 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
79 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
80 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
80 <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li>
81 <li><a href="qhorizontalbarseries.html">QHorizontalBarSeries</a></li>
81 <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li>
82 <li><a href="qhorizontalstackedbarseries.html">QHorizontalStackedBarSeries</a></li>
82 <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li>
83 <li><a href="qhorizontalpercentbarseries.html">QHorizontalPercentBarSeries</a></li>
83 </ul>
84 </ul>
84 </td>
85 </td>
85 </tr>
86 </tr>
86 </table>
87 </table>
87 \endraw
88 \endraw
88
89
89 */
90 */
@@ -1,245 +1,249
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
31 \class QIntervalsAxis
30 \class QIntervalsAxis
32 \brief The QIntervalsAxis class is used for manipulating chart's axis.
31 \brief The QIntervalsAxis class is used for manipulating chart's axis.
33 \mainclass
32 \mainclass
34
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 */
33 */
37
34
38 /*!
35 /*!
39 \qmlclass Axis QIntervalsAxis
36 \qmlclass Axis QIntervalsAxis
40 \brief The Axis element is used for manipulating chart's axes.
37 \brief The Axis element is used for manipulating chart's axes.
41
38
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
39 Axis can be setup to show axis line with tick marks, grid lines and shades.
43
40
44 To access Axes you can use ChartView API. For example:
41 To access Axes you can use ChartView API. For example:
45 \code
42 \code
46 // TODO :)
43 // TODO :)
47 \endcode
44 \endcode
48 */
45 */
49
46
50 /*!
47 /*!
51 Constructs an axis object which is a child of \a parent.
48 Constructs an axis object which is a child of \a parent.
52 */
49 */
53 QIntervalsAxis::QIntervalsAxis(QObject *parent):
50 QIntervalsAxis::QIntervalsAxis(QObject *parent):
54 QValuesAxis(*new QIntervalsAxisPrivate(this),parent)
51 QValuesAxis(*new QIntervalsAxisPrivate(this),parent)
55 {
52 {
56 }
53 }
57
54
58 /*!
55 /*!
59 Destroys the object
56 Destroys the object
60 */
57 */
61 QIntervalsAxis::~QIntervalsAxis()
58 QIntervalsAxis::~QIntervalsAxis()
62 {
59 {
63 // Q_D(QValuesAxis);
60 // Q_D(QValuesAxis);
64 // if(d->m_dataset) {
61 // if(d->m_dataset) {
65 // d->m_dataset->removeAxis(this);
62 // d->m_dataset->removeAxis(this);
66 // }
63 // }
67 }
64 }
68
65
69 /*!
66 /*!
70 \internal
67 \internal
71 */
68 */
72 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
69 QIntervalsAxis::QIntervalsAxis(QIntervalsAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
73 {
70 {
74
71
75 }
72 }
76
73
77 /*!
74 /*!
78 Appends new interval to the axis with an \a intervalLabel.
75 Appends new interval to the axis with an \a intervalLabel.
79 Interval label has to be unique.
76 Interval label has to be unique.
80 Parameter \a interval specifies the high end limit of the interval.
77 Parameter \a intervalEnd specifies the high end limit of the interval.
81 It has to be greater than the high end limit of the previous interval.
78 It has to be greater than the high end limit of the previous interval.
82 Otherwise the method returns without adding a new interval.
79 Otherwise the method returns without adding a new interval.
83 */
80 */
84 void QIntervalsAxis::append(const QString& intervalLabel, qreal intervalEnd)
81 void QIntervalsAxis::append(const QString& intervalLabel, qreal intervalEnd)
85 {
82 {
86 Q_D(QIntervalsAxis);
83 Q_D(QIntervalsAxis);
87
84
88 if (!d->m_intervals.contains(intervalLabel))
85 if (!d->m_intervals.contains(intervalLabel))
89 {
86 {
90 if(d->m_intervals.isEmpty()){
87 if(d->m_intervals.isEmpty()){
91 Range range(d->m_categoryMinimum, intervalEnd);
88 Range range(d->m_categoryMinimum, intervalEnd);
92 d->m_intervalsMap.insert(intervalLabel, range);
89 d->m_intervalsMap.insert(intervalLabel, range);
93 d->m_intervals.append(intervalLabel);
90 d->m_intervals.append(intervalLabel);
94 }else if (intervalEnd > intervalMax(d->m_intervals.last())){
91 }else if (intervalEnd > intervalMax(d->m_intervals.last())){
95 Range range = d->m_intervalsMap.value(d->m_intervals.last());
92 Range range = d->m_intervalsMap.value(d->m_intervals.last());
96 d->m_intervalsMap.insert(intervalLabel, Range(range.second, intervalEnd));
93 d->m_intervalsMap.insert(intervalLabel, Range(range.second, intervalEnd));
97 d->m_intervals.append(intervalLabel);
94 d->m_intervals.append(intervalLabel);
98 }
95 }
99 }
96 }
100 }
97 }
101
98
102 /*!
99 /*!
103 Sets to \a min the low end limit of the first interval on the axis.
100 Sets to \a min the low end limit of the first interval on the axis.
104 */
101 */
105 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
102 void QIntervalsAxis::setFisrtIntervalMinimum(qreal min)
106 {
103 {
107 Q_D(QIntervalsAxis);
104 Q_D(QIntervalsAxis);
108 if(d->m_intervals.isEmpty()){
105 if(d->m_intervals.isEmpty()){
109 d->m_categoryMinimum = min;
106 d->m_categoryMinimum = min;
110 }else{
107 }else{
111 Range range = d->m_intervalsMap.value(d->m_intervals.first());
108 Range range = d->m_intervalsMap.value(d->m_intervals.first());
112 d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
109 d->m_intervalsMap.insert(d->m_intervals.first(), Range(min, range.second));
113 }
110 }
114 }
111 }
115
112
116 /*!
113 /*!
117 Returns the low end limit of the interval specified by an \a intervalLabel
114 Returns the low end limit of the interval specified by an \a intervalLabel
118 */
115 */
119 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
116 qreal QIntervalsAxis::intervalMin(const QString& intervalLabel) const
120 {
117 {
121 Q_D(const QIntervalsAxis);
118 Q_D(const QIntervalsAxis);
122 return d->m_intervalsMap.value(intervalLabel).first;
119 return d->m_intervalsMap.value(intervalLabel).first;
123 }
120 }
124
121
125 /*!
122 /*!
126 Returns the high end limit of the interval specified by an \a intervalLabel
123 Returns the high end limit of the interval specified by an \a intervalLabel
127 */
124 */
128 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
125 qreal QIntervalsAxis::intervalMax(const QString& intervalLabel) const
129 {
126 {
130 Q_D(const QIntervalsAxis);
127 Q_D(const QIntervalsAxis);
131 return d->m_intervalsMap.value(intervalLabel).second;
128 return d->m_intervalsMap.value(intervalLabel).second;
132 }
129 }
133
130
134 /*!
131 /*!
135 Removes \a interval from axis
132 Removes an interval specified by the \a intervalLabel from the axis
136 */
133 */
137 void QIntervalsAxis::remove(const QString &intervalLabel)
134 void QIntervalsAxis::remove(const QString &intervalLabel)
138 {
135 {
139 Q_D(QIntervalsAxis);
136 Q_D(QIntervalsAxis);
140 int labelIndex = d->m_intervals.indexOf(intervalLabel);
137 int labelIndex = d->m_intervals.indexOf(intervalLabel);
141
138
142 // check if such label exists
139 // check if such label exists
143 if (labelIndex != -1) {
140 if (labelIndex != -1) {
144 d->m_intervals.removeAt(labelIndex);
141 d->m_intervals.removeAt(labelIndex);
145 d->m_intervalsMap.remove(intervalLabel);
142 d->m_intervalsMap.remove(intervalLabel);
146
143
147 // the range of the interval that follows (if exists) needs to be updated
144 // the range of the interval that follows (if exists) needs to be updated
148 if (labelIndex < d->m_intervals.count()) {
145 if (labelIndex < d->m_intervals.count()) {
149 QString label = d->m_intervals.at(labelIndex);
146 QString label = d->m_intervals.at(labelIndex);
150 Range range = d->m_intervalsMap.value(label);
147 Range range = d->m_intervalsMap.value(label);
151
148
152 // set the range
149 // set the range
153 if (labelIndex == 0) {
150 if (labelIndex == 0) {
154 range.first = d->m_categoryMinimum;
151 range.first = d->m_categoryMinimum;
155 d->m_intervalsMap.insert(label, range);
152 d->m_intervalsMap.insert(label, range);
156 } else {
153 } else {
157 range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
154 range.first = d->m_intervalsMap.value(d->m_intervals.at(labelIndex - 1)).second;
158 d->m_intervalsMap.insert(label, range);
155 d->m_intervalsMap.insert(label, range);
159 }
156 }
160 }
157 }
161 d->emitUpdated();
158 d->emitUpdated();
162 }
159 }
163 }
160 }
164
161
162 /*!
163 Replaces \a oldLabel of an existing interval with a \a newLabel
164 If the old label does not exist the method returns without making any changes.
165 */
165 void QIntervalsAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
166 void QIntervalsAxis::replaceLabel(const QString& oldLabel, const QString& newLabel)
166 {
167 {
167 Q_D(QIntervalsAxis);
168 Q_D(QIntervalsAxis);
168 int labelIndex = d->m_intervals.indexOf(oldLabel);
169 int labelIndex = d->m_intervals.indexOf(oldLabel);
169
170
170 // check if such label exists
171 // check if such label exists
171 if (labelIndex != -1) {
172 if (labelIndex != -1) {
172 d->m_intervals.replace(labelIndex, newLabel);
173 d->m_intervals.replace(labelIndex, newLabel);
173 Range range = d->m_intervalsMap.value(oldLabel);
174 Range range = d->m_intervalsMap.value(oldLabel);
174 d->m_intervalsMap.remove(oldLabel);
175 d->m_intervalsMap.remove(oldLabel);
175 d->m_intervalsMap.insert(newLabel, range);
176 d->m_intervalsMap.insert(newLabel, range);
176 d->emitUpdated();
177 d->emitUpdated();
177 }
178 }
178
179
179 }
180 }
180
181
182 /*!
183 Returns the list of the intervals labels
184 */
181 QStringList QIntervalsAxis::intervalsLabels()
185 QStringList QIntervalsAxis::intervalsLabels()
182 {
186 {
183 Q_D(QIntervalsAxis);
187 Q_D(QIntervalsAxis);
184 return d->m_intervals;
188 return d->m_intervals;
185 }
189 }
186
190
187 /*!
191 /*!
188 Returns number of intervals.
192 Returns number of intervals.
189 */
193 */
190 int QIntervalsAxis::count() const
194 int QIntervalsAxis::count() const
191 {
195 {
192 Q_D(const QIntervalsAxis);
196 Q_D(const QIntervalsAxis);
193 return d->m_intervals.count();
197 return d->m_intervals.count();
194 }
198 }
195
199
196 /*!
200 /*!
197 Returns the type of the axis
201 Returns the type of the axis
198 */
202 */
199 QAbstractAxis::AxisType QIntervalsAxis::type() const
203 QAbstractAxis::AxisType QIntervalsAxis::type() const
200 {
204 {
201 return QAbstractAxis::AxisTypeIntervals;
205 return QAbstractAxis::AxisTypeIntervals;
202 }
206 }
203
207
204 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
208 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
205
209
206 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
210 QIntervalsAxisPrivate::QIntervalsAxisPrivate(QIntervalsAxis* q):
207 QValuesAxisPrivate(q),
211 QValuesAxisPrivate(q),
208 m_categoryMinimum(0)
212 m_categoryMinimum(0)
209 {
213 {
210
214
211 }
215 }
212
216
213 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
217 QIntervalsAxisPrivate::~QIntervalsAxisPrivate()
214 {
218 {
215
219
216 }
220 }
217
221
218 int QIntervalsAxisPrivate::ticksCount() const
222 int QIntervalsAxisPrivate::ticksCount() const
219 {
223 {
220 return m_intervals.count() + 1;
224 return m_intervals.count() + 1;
221 }
225 }
222
226
223 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
227 void QIntervalsAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
224 {
228 {
225 Q_UNUSED(count);
229 Q_UNUSED(count);
226 Q_UNUSED(min);
230 Q_UNUSED(min);
227 Q_UNUSED(max);
231 Q_UNUSED(max);
228 //m_min = min;
232 //m_min = min;
229 //m_max = max;
233 //m_max = max;
230 }
234 }
231
235
232 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
236 ChartAxis* QIntervalsAxisPrivate::createGraphics(ChartPresenter* presenter)
233 {
237 {
234 Q_Q(QIntervalsAxis);
238 Q_Q(QIntervalsAxis);
235 if(m_orientation == Qt::Vertical){
239 if(m_orientation == Qt::Vertical){
236 return new ChartIntervalAxisY(q,presenter);
240 return new ChartIntervalAxisY(q,presenter);
237 }else{
241 }else{
238 return new ChartIntervalAxisX(q,presenter);
242 return new ChartIntervalAxisX(q,presenter);
239 }
243 }
240 }
244 }
241
245
242 #include "moc_qintervalsaxis.cpp"
246 #include "moc_qintervalsaxis.cpp"
243 #include "moc_qintervalsaxis_p.cpp"
247 #include "moc_qintervalsaxis_p.cpp"
244
248
245 QTCOMMERCIALCHART_END_NAMESPACE
249 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,304 +1,304
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 "../qabstractaxis/tst_qabstractaxis.h"
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include "qintervalsaxis.h"
22 #include "qintervalsaxis.h"
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24
24
25 class tst_QIntervalsAxis: public tst_QAbstractAxis
25 class tst_QIntervalsAxis: public tst_QAbstractAxis
26 {
26 {
27 Q_OBJECT
27 Q_OBJECT
28
28
29 public slots:
29 public slots:
30 void initTestCase();
30 void initTestCase();
31 void cleanupTestCase();
31 void cleanupTestCase();
32 void init();
32 void init();
33 void cleanup();
33 void cleanup();
34
34
35 private slots:
35 private slots:
36 void qintervalsaxis_data();
36 void qintervalsaxis_data();
37 void qintervalsaxis();
37 void qintervalsaxis();
38
38
39 void max_raw_data();
39 void max_raw_data();
40 void max_raw();
40 void max_raw();
41 void max_data();
41 void max_data();
42 void max();
42 void max();
43 void max_animation_data();
43 void max_animation_data();
44 void max_animation();
44 void max_animation();
45 void min_raw_data();
45 void min_raw_data();
46 void min_raw();
46 void min_raw();
47 void min_data();
47 void min_data();
48 void min();
48 void min();
49 void min_animation_data();
49 void min_animation_data();
50 void min_animation();
50 void min_animation();
51 void range_raw_data();
51 void range_raw_data();
52 void range_raw();
52 void range_raw();
53 void range_data();
53 void range_data();
54 void range();
54 void range();
55 void range_animation_data();
55 void range_animation_data();
56 void range_animation();
56 void range_animation();
57
57
58 void interval_data();
58 void interval_data();
59 void interval();
59 void interval();
60
60
61 private:
61 private:
62 QIntervalsAxis* m_intervalsaxis;
62 QIntervalsAxis* m_intervalsaxis;
63 QLineSeries* m_series;
63 QLineSeries* m_series;
64 };
64 };
65
65
66 void tst_QIntervalsAxis::initTestCase()
66 void tst_QIntervalsAxis::initTestCase()
67 {
67 {
68 }
68 }
69
69
70 void tst_QIntervalsAxis::cleanupTestCase()
70 void tst_QIntervalsAxis::cleanupTestCase()
71 {
71 {
72 }
72 }
73
73
74 void tst_QIntervalsAxis::init()
74 void tst_QIntervalsAxis::init()
75 {
75 {
76 m_intervalsaxis = new QIntervalsAxis();
76 m_intervalsaxis = new QIntervalsAxis();
77 m_series = new QLineSeries();
77 m_series = new QLineSeries();
78 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
78 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
79 tst_QAbstractAxis::init(m_intervalsaxis, m_series);
79 tst_QAbstractAxis::init(m_intervalsaxis, m_series);
80 m_chart->addSeries(m_series);
80 m_chart->addSeries(m_series);
81 m_chart->createDefaultAxes();
81 m_chart->createDefaultAxes();
82 }
82 }
83
83
84 void tst_QIntervalsAxis::cleanup()
84 void tst_QIntervalsAxis::cleanup()
85 {
85 {
86 delete m_series;
86 delete m_series;
87 delete m_intervalsaxis;
87 delete m_intervalsaxis;
88 m_series = 0;
88 m_series = 0;
89 m_intervalsaxis = 0;
89 m_intervalsaxis = 0;
90 tst_QAbstractAxis::cleanup();
90 tst_QAbstractAxis::cleanup();
91 }
91 }
92
92
93 void tst_QIntervalsAxis::qintervalsaxis_data()
93 void tst_QIntervalsAxis::qintervalsaxis_data()
94 {
94 {
95 }
95 }
96
96
97 void tst_QIntervalsAxis::qintervalsaxis()
97 void tst_QIntervalsAxis::qintervalsaxis()
98 {
98 {
99 qabstractaxis();
99 qabstractaxis();
100
100
101 QVERIFY(qFuzzyIsNull(m_intervalsaxis->max()));
101 QVERIFY(qFuzzyIsNull(m_intervalsaxis->max()));
102 QVERIFY(qFuzzyIsNull(m_intervalsaxis->min()));
102 QVERIFY(qFuzzyIsNull(m_intervalsaxis->min()));
103 QCOMPARE(m_intervalsaxis->type(), QAbstractAxis::AxisTypeIntervals);
103 QCOMPARE(m_intervalsaxis->type(), QAbstractAxis::AxisTypeIntervals);
104
104
105 m_chart->setAxisX(m_intervalsaxis, m_series);
105 m_chart->setAxisX(m_intervalsaxis, m_series);
106 m_view->show();
106 m_view->show();
107 QTest::qWaitForWindowShown(m_view);
107 QTest::qWaitForWindowShown(m_view);
108
108
109 QVERIFY(!qFuzzyIsNull(m_intervalsaxis->max()));
109 QVERIFY(!qFuzzyIsNull(m_intervalsaxis->max()));
110 QVERIFY(!qFuzzyIsNull(m_intervalsaxis->min()));
110 QVERIFY(!qFuzzyIsNull(m_intervalsaxis->min()));
111 }
111 }
112
112
113 void tst_QIntervalsAxis::max_raw_data()
113 void tst_QIntervalsAxis::max_raw_data()
114 {
114 {
115 QTest::addColumn<qreal>("max");
115 QTest::addColumn<qreal>("max");
116 QTest::newRow("1.0") << 1.0;
116 QTest::newRow("1.0") << 1.0;
117 QTest::newRow("50.0") << 50.0;
117 QTest::newRow("50.0") << 50.0;
118 QTest::newRow("101.0") << 101.0;
118 QTest::newRow("101.0") << 101.0;
119 }
119 }
120
120
121 void tst_QIntervalsAxis::max_raw()
121 void tst_QIntervalsAxis::max_raw()
122 {
122 {
123 QFETCH(qreal, max);
123 QFETCH(qreal, max);
124
124
125 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
125 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
126 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
126 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
127 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
127 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
128
128
129 m_intervalsaxis->setMax(max);
129 m_intervalsaxis->setMax(max);
130 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Not equal");
130 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Not equal");
131
131
132 QCOMPARE(spy0.count(), 1);
132 QCOMPARE(spy0.count(), 1);
133 QCOMPARE(spy1.count(), 0);
133 QCOMPARE(spy1.count(), 0);
134 QCOMPARE(spy2.count(), 1);
134 QCOMPARE(spy2.count(), 1);
135 }
135 }
136
136
137 void tst_QIntervalsAxis::max_data()
137 void tst_QIntervalsAxis::max_data()
138 {
138 {
139 max_raw_data();
139 max_raw_data();
140 }
140 }
141
141
142 void tst_QIntervalsAxis::max()
142 void tst_QIntervalsAxis::max()
143 {
143 {
144 m_chart->setAxisX(m_intervalsaxis, m_series);
144 m_chart->setAxisX(m_intervalsaxis, m_series);
145 m_view->show();
145 m_view->show();
146 QTest::qWaitForWindowShown(m_view);
146 QTest::qWaitForWindowShown(m_view);
147 max_raw();
147 max_raw();
148 }
148 }
149
149
150 void tst_QIntervalsAxis::max_animation_data()
150 void tst_QIntervalsAxis::max_animation_data()
151 {
151 {
152 max_data();
152 max_data();
153 }
153 }
154
154
155 void tst_QIntervalsAxis::max_animation()
155 void tst_QIntervalsAxis::max_animation()
156 {
156 {
157 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
157 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
158 max();
158 max();
159 }
159 }
160
160
161 void tst_QIntervalsAxis::min_raw_data()
161 void tst_QIntervalsAxis::min_raw_data()
162 {
162 {
163 QTest::addColumn<qreal>("min");
163 QTest::addColumn<qreal>("min");
164 QTest::newRow("-1.0") << -1.0;
164 QTest::newRow("-1.0") << -1.0;
165 QTest::newRow("-50.0") << -50.0;
165 QTest::newRow("-50.0") << -50.0;
166 QTest::newRow("-101.0") << -101.0;
166 QTest::newRow("-101.0") << -101.0;
167 }
167 }
168
168
169 void tst_QIntervalsAxis::min_raw()
169 void tst_QIntervalsAxis::min_raw()
170 {
170 {
171 QFETCH(qreal, min);
171 QFETCH(qreal, min);
172
172
173 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
173 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
174 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
174 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
175 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
175 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
176
176
177 m_intervalsaxis->setMin(min);
177 m_intervalsaxis->setMin(min);
178 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Not equal");
178 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Not equal");
179
179
180 QCOMPARE(spy0.count(), 0);
180 QCOMPARE(spy0.count(), 0);
181 QCOMPARE(spy1.count(), 1);
181 QCOMPARE(spy1.count(), 1);
182 QCOMPARE(spy2.count(), 1);
182 QCOMPARE(spy2.count(), 1);
183 }
183 }
184
184
185 void tst_QIntervalsAxis::min_data()
185 void tst_QIntervalsAxis::min_data()
186 {
186 {
187 min_raw_data();
187 min_raw_data();
188 }
188 }
189
189
190 void tst_QIntervalsAxis::min()
190 void tst_QIntervalsAxis::min()
191 {
191 {
192 m_chart->setAxisX(m_intervalsaxis, m_series);
192 m_chart->setAxisX(m_intervalsaxis, m_series);
193 m_view->show();
193 m_view->show();
194 QTest::qWaitForWindowShown(m_view);
194 QTest::qWaitForWindowShown(m_view);
195 min_raw();
195 min_raw();
196 }
196 }
197
197
198 void tst_QIntervalsAxis::min_animation_data()
198 void tst_QIntervalsAxis::min_animation_data()
199 {
199 {
200 min_data();
200 min_data();
201 }
201 }
202
202
203 void tst_QIntervalsAxis::min_animation()
203 void tst_QIntervalsAxis::min_animation()
204 {
204 {
205 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
205 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
206 min();
206 min();
207 }
207 }
208
208
209 void tst_QIntervalsAxis::range_raw_data()
209 void tst_QIntervalsAxis::range_raw_data()
210 {
210 {
211 QTest::addColumn<qreal>("min");
211 QTest::addColumn<qreal>("min");
212 QTest::addColumn<qreal>("max");
212 QTest::addColumn<qreal>("max");
213 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
213 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
214 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
214 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
215 QTest::newRow("101.0") << 40.0 << 60.0;
215 QTest::newRow("101.0") << 40.0 << 60.0;
216 }
216 }
217
217
218 void tst_QIntervalsAxis::range_raw()
218 void tst_QIntervalsAxis::range_raw()
219 {
219 {
220 QFETCH(qreal, min);
220 QFETCH(qreal, min);
221 QFETCH(qreal, max);
221 QFETCH(qreal, max);
222
222
223 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
223 QSignalSpy spy0(m_intervalsaxis, SIGNAL(maxChanged(qreal)));
224 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
224 QSignalSpy spy1(m_intervalsaxis, SIGNAL(minChanged(qreal)));
225 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
225 QSignalSpy spy2(m_intervalsaxis, SIGNAL(rangeChanged(qreal, qreal)));
226
226
227 m_intervalsaxis->setRange(min, max);
227 m_intervalsaxis->setRange(min, max);
228 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Min not equal");
228 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->min() - min), "Min not equal");
229 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Max not equal");
229 QVERIFY2(qFuzzyIsNull(m_intervalsaxis->max() - max), "Max not equal");
230
230
231 QCOMPARE(spy0.count(), 1);
231 QCOMPARE(spy0.count(), 1);
232 QCOMPARE(spy1.count(), 1);
232 QCOMPARE(spy1.count(), 1);
233 QCOMPARE(spy2.count(), 1);
233 QCOMPARE(spy2.count(), 1);
234 }
234 }
235
235
236 void tst_QIntervalsAxis::range_data()
236 void tst_QIntervalsAxis::range_data()
237 {
237 {
238 range_raw_data();
238 range_raw_data();
239 }
239 }
240
240
241 void tst_QIntervalsAxis::range()
241 void tst_QIntervalsAxis::range()
242 {
242 {
243 m_chart->setAxisX(m_intervalsaxis, m_series);
243 m_chart->setAxisX(m_intervalsaxis, m_series);
244 m_view->show();
244 m_view->show();
245 QTest::qWaitForWindowShown(m_view);
245 QTest::qWaitForWindowShown(m_view);
246 range_raw();
246 range_raw();
247 }
247 }
248
248
249 void tst_QIntervalsAxis::range_animation_data()
249 void tst_QIntervalsAxis::range_animation_data()
250 {
250 {
251 range_data();
251 range_data();
252 }
252 }
253
253
254 void tst_QIntervalsAxis::range_animation()
254 void tst_QIntervalsAxis::range_animation()
255 {
255 {
256 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
256 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
257 range();
257 range();
258 }
258 }
259
259
260 void tst_QIntervalsAxis::interval_data()
260 void tst_QIntervalsAxis::interval_data()
261 {
261 {
262 //
262 //
263 }
263 }
264
264
265 void tst_QIntervalsAxis::interval()
265 void tst_QIntervalsAxis::interval()
266 {
266 {
267 // append one correct interval
267 // append one correct interval
268 m_intervalsaxis->append("first", (qreal)45);
268 m_intervalsaxis->append("first", (qreal)45);
269 QCOMPARE(m_intervalsaxis->intervalMin("first"), (qreal)0);
269 QCOMPARE(m_intervalsaxis->intervalMin("first"), (qreal)0);
270 QCOMPARE(m_intervalsaxis->intervalMax("first"), (qreal)45);
270 QCOMPARE(m_intervalsaxis->intervalMax("first"), (qreal)45);
271
271
272 // append one more correct interval
272 // append one more correct interval
273 m_intervalsaxis->append("second", (qreal)75);
273 m_intervalsaxis->append("second", (qreal)75);
274 QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)45);
274 QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)45);
275 QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75);
275 QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75);
276
276
277 // append one incorrect interval
277 // append one incorrect interval
278 m_intervalsaxis->append("third", (qreal)15);
278 m_intervalsaxis->append("third", (qreal)15);
279 QCOMPARE(m_intervalsaxis->count(), 2);
279 QCOMPARE(m_intervalsaxis->count(), 2);
280 QCOMPARE(m_intervalsaxis->intervalMax(m_intervalsaxis->intervalsLabels().last()), (qreal)75);
280 QCOMPARE(m_intervalsaxis->intervalMax(m_intervalsaxis->intervalsLabels().last()), (qreal)75);
281 // QCOMPARE(intervalMax("first"), (qreal)75);
281 // QCOMPARE(intervalMax("first"), (qreal)75);
282
282
283 // append one more correct interval
283 // append one more correct interval
284 m_intervalsaxis->append("third", (qreal)100);
284 m_intervalsaxis->append("third", (qreal)100);
285 QCOMPARE(m_intervalsaxis->count(), 3);
285 QCOMPARE(m_intervalsaxis->count(), 3);
286 QCOMPARE(m_intervalsaxis->intervalMin("third"), (qreal)75);
286 QCOMPARE(m_intervalsaxis->intervalMin("third"), (qreal)75);
287 QCOMPARE(m_intervalsaxis->intervalMax("third"), (qreal)100);
287 QCOMPARE(m_intervalsaxis->intervalMax("third"), (qreal)100);
288
288
289 // remove one interval
289 // remove one interval
290 m_intervalsaxis->remove("first");
290 m_intervalsaxis->remove("first");
291 QCOMPARE(m_intervalsaxis->count(), 2);
291 QCOMPARE(m_intervalsaxis->count(), 2);
292 QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)0); // second interval should extend to firstInterval minimum
292 QCOMPARE(m_intervalsaxis->intervalMin("second"), (qreal)0); // second interval should extend to firstInterval minimum
293 QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75);
293 QCOMPARE(m_intervalsaxis->intervalMax("second"), (qreal)75);
294
294
295 // remove one interval
295 // remove one interval
296 m_intervalsaxis->replace("second", "replaced");
296 m_intervalsaxis->replaceLabel("second", "replaced");
297 QCOMPARE(m_intervalsaxis->count(), 2);
297 QCOMPARE(m_intervalsaxis->count(), 2);
298 QCOMPARE(m_intervalsaxis->intervalMin("replaced"), (qreal)0); // second interval should extend to firstInterval minimum
298 QCOMPARE(m_intervalsaxis->intervalMin("replaced"), (qreal)0); // second interval should extend to firstInterval minimum
299 QCOMPARE(m_intervalsaxis->intervalMax("replaced"), (qreal)75);
299 QCOMPARE(m_intervalsaxis->intervalMax("replaced"), (qreal)75);
300 }
300 }
301
301
302 QTEST_MAIN(tst_QIntervalsAxis)
302 QTEST_MAIN(tst_QIntervalsAxis)
303 #include "tst_qintervalsaxis.moc"
303 #include "tst_qintervalsaxis.moc"
304
304
General Comments 0
You need to be logged in to leave comments. Login now