##// END OF EJS Templates
Some docs to QValuesAxis
Marek Rosa -
r1547:968e8f414e70
parent child
Show More
@@ -1,192 +1,251
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 "qvaluesaxis.h"
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
22 #include "qvaluesaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 /*!
26 \class QValuesAxis
27 \brief The QValuesAxis class is used for manipulating chart's axis.
28 \mainclass
29
30 Axis can be setup to show axis line with tick marks, grid lines and shades.
31 */
32
33 /*!
34 \qmlclass Axis QValuesAxis
35 \brief The Axis element is used for manipulating chart's axes
36
37 Axis can be setup to show axis line with tick marks, grid lines and shades.
38
39 To access Axes you can use ChartView API. For example:
40 \code
41 ChartView {
42 axisX.min: 0
43 axisX.max: 3
44 axisX.ticksCount: 4
45 axisY.min: 0
46 axisY.max: 4
47 // Add a few series...
48 }
49 \endcode
50 */
51
52 /*!
53 \property QValuesAxis::min
54 Defines the minimum value on the axis.
55 */
56 /*!
57 \qmlproperty real Axis::min
58 Defines the minimum value on the axis.
59 */
60
61 /*!
62 \property QValuesAxis::max
63 Defines the maximum value on the axis.
64 */
65 /*!
66 \qmlproperty real Axis::max
67 Defines the maximum value on the axis.
68 */
69
70 /*!
71 \fn void QValuesAxis::minChanged(qreal min)
72 Axis emits signal when \a min of axis has changed.
73 */
74
75 /*!
76 \fn void QValuesAxis::maxChanged(qreal max)
77 Axis emits signal when \a max of axis has changed.
78 */
79
80 /*!
81 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
82 Axis emits signal when \a min or \a max of axis has changed.
83 */
25
84
26 QValuesAxis::QValuesAxis(QObject *parent) :
85 QValuesAxis::QValuesAxis(QObject *parent) :
27 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
86 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
28 {
87 {
29
88
30 }
89 }
31
90
32 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
91 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
33 {
92 {
34
93
35 }
94 }
36
95
37 QValuesAxis::~QValuesAxis()
96 QValuesAxis::~QValuesAxis()
38 {
97 {
39
98
40 }
99 }
41
100
42 void QValuesAxis::setMin(qreal min)
101 void QValuesAxis::setMin(qreal min)
43 {
102 {
44 Q_D(QValuesAxis);
103 Q_D(QValuesAxis);
45 setRange(min,d->m_max);
104 setRange(min,d->m_max);
46 }
105 }
47
106
48 qreal QValuesAxis::min() const
107 qreal QValuesAxis::min() const
49 {
108 {
50 Q_D(const QValuesAxis);
109 Q_D(const QValuesAxis);
51 return d->m_min;
110 return d->m_min;
52 }
111 }
53
112
54 void QValuesAxis::setMax(qreal max)
113 void QValuesAxis::setMax(qreal max)
55 {
114 {
56 Q_D(QValuesAxis);
115 Q_D(QValuesAxis);
57 setRange(d->m_min,max);
116 setRange(d->m_min,max);
58 }
117 }
59
118
60 qreal QValuesAxis::max() const
119 qreal QValuesAxis::max() const
61 {
120 {
62 Q_D(const QValuesAxis);
121 Q_D(const QValuesAxis);
63 return d->m_max;
122 return d->m_max;
64 }
123 }
65
124
66 /*!
125 /*!
67 Sets range from \a min to \a max on the axis.
126 Sets range from \a min to \a max on the axis.
68 */
127 */
69 void QValuesAxis::setRange(qreal min, qreal max)
128 void QValuesAxis::setRange(qreal min, qreal max)
70 {
129 {
71 Q_D(QValuesAxis);
130 Q_D(QValuesAxis);
72 bool changed = false;
131 bool changed = false;
73 if (!qFuzzyIsNull(d->m_min - min)) {
132 if (!qFuzzyIsNull(d->m_min - min)) {
74 d->m_min = min;
133 d->m_min = min;
75 changed = true;
134 changed = true;
76 emit minChanged(min);
135 emit minChanged(min);
77 }
136 }
78
137
79 if (!qFuzzyIsNull(d->m_max - max)) {
138 if (!qFuzzyIsNull(d->m_max - max)) {
80 d->m_max = max;
139 d->m_max = max;
81 changed = true;
140 changed = true;
82 emit maxChanged(max);
141 emit maxChanged(max);
83 }
142 }
84
143
85 if (changed) {
144 if (changed) {
86 emit rangeChanged(d->m_min,d->m_max);
145 emit rangeChanged(d->m_min,d->m_max);
87 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
146 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
88 }
147 }
89 }
148 }
90
149
91 /*!
150 /*!
92 Sets \a count for ticks on the axis.
151 Sets \a count for ticks on the axis.
93 */
152 */
94 void QValuesAxis::setTicksCount(int count)
153 void QValuesAxis::setTicksCount(int count)
95 {
154 {
96 Q_D(QValuesAxis);
155 Q_D(QValuesAxis);
97 if (d->m_ticksCount != count) {
156 if (d->m_ticksCount != count) {
98 d->m_ticksCount = count;
157 d->m_ticksCount = count;
99 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
158 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
100 }
159 }
101 }
160 }
102
161
103 /*!
162 /*!
104 \fn int QAbstractAxis::ticksCount() const
163 \fn int QAbstractAxis::ticksCount() const
105 Return number of ticks on the axis
164 Return number of ticks on the axis
106 */
165 */
107 int QValuesAxis::ticksCount() const
166 int QValuesAxis::ticksCount() const
108 {
167 {
109 Q_D(const QValuesAxis);
168 Q_D(const QValuesAxis);
110 return d->m_ticksCount;
169 return d->m_ticksCount;
111 }
170 }
112
171
113 void QValuesAxis::setNiceNumbersEnabled(bool enable)
172 void QValuesAxis::setNiceNumbersEnabled(bool enable)
114 {
173 {
115 Q_D(QValuesAxis);
174 Q_D(QValuesAxis);
116 if (d->m_niceNumbers != enable){
175 if (d->m_niceNumbers != enable){
117 d->m_niceNumbers = enable;
176 d->m_niceNumbers = enable;
118 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
177 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
119 }
178 }
120 }
179 }
121
180
122 bool QValuesAxis::niceNumbersEnabled() const
181 bool QValuesAxis::niceNumbersEnabled() const
123 {
182 {
124 Q_D(const QValuesAxis);
183 Q_D(const QValuesAxis);
125 return d->m_niceNumbers;
184 return d->m_niceNumbers;
126 }
185 }
127
186
128 QAbstractAxis::AxisType QValuesAxis::type() const
187 QAbstractAxis::AxisType QValuesAxis::type() const
129 {
188 {
130 return AxisTypeValues;
189 return AxisTypeValues;
131 }
190 }
132
191
133 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
192 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
134
193
135 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
194 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
136 QAbstractAxisPrivate(q),
195 QAbstractAxisPrivate(q),
137 m_min(0),
196 m_min(0),
138 m_max(0),
197 m_max(0),
139 m_niceNumbers(false),
198 m_niceNumbers(false),
140 m_ticksCount(5)
199 m_ticksCount(5)
141 {
200 {
142
201
143 }
202 }
144
203
145 QValuesAxisPrivate::~QValuesAxisPrivate()
204 QValuesAxisPrivate::~QValuesAxisPrivate()
146 {
205 {
147
206
148 }
207 }
149
208
150 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
209 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
151 {
210 {
152 Q_Q(QValuesAxis);
211 Q_Q(QValuesAxis);
153 q->setRange(min,max);
212 q->setRange(min,max);
154 q->setTicksCount(count);
213 q->setTicksCount(count);
155 }
214 }
156
215
157
216
158 void QValuesAxisPrivate::setMin(const QVariant& min)
217 void QValuesAxisPrivate::setMin(const QVariant& min)
159 {
218 {
160 Q_Q(QValuesAxis);
219 Q_Q(QValuesAxis);
161 bool ok;
220 bool ok;
162 qreal value = min.toReal(&ok);
221 qreal value = min.toReal(&ok);
163 if(ok) q->setMin(value);
222 if(ok) q->setMin(value);
164 }
223 }
165
224
166 void QValuesAxisPrivate::setMax(const QVariant& max)
225 void QValuesAxisPrivate::setMax(const QVariant& max)
167 {
226 {
168 Q_Q(QValuesAxis);
227 Q_Q(QValuesAxis);
169 bool ok;
228 bool ok;
170 qreal value = max.toReal(&ok);
229 qreal value = max.toReal(&ok);
171 if(ok) q->setMax(value);
230 if(ok) q->setMax(value);
172 }
231 }
173
232
174 void QValuesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
233 void QValuesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
175 {
234 {
176 Q_Q(QValuesAxis);
235 Q_Q(QValuesAxis);
177 bool ok1;
236 bool ok1;
178 bool ok2;
237 bool ok2;
179 qreal value1 = min.toReal(&ok1);
238 qreal value1 = min.toReal(&ok1);
180 qreal value2 = max.toReal(&ok2);
239 qreal value2 = max.toReal(&ok2);
181 if(ok1&&ok2) q->setRange(value1,value2);
240 if(ok1&&ok2) q->setRange(value1,value2);
182 }
241 }
183
242
184 int QValuesAxisPrivate::ticksCount() const
243 int QValuesAxisPrivate::ticksCount() const
185 {
244 {
186 return m_ticksCount;
245 return m_ticksCount;
187 }
246 }
188
247
189 #include "moc_qvaluesaxis.cpp"
248 #include "moc_qvaluesaxis.cpp"
190 #include "moc_qvaluesaxis_p.cpp"
249 #include "moc_qvaluesaxis_p.cpp"
191
250
192 QTCOMMERCIALCHART_END_NAMESPACE
251 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now