##// END OF EJS Templates
QValueAxis: added posibility to specify label format
Marek Rosa -
r1854:4846aebc38ef
parent child
Show More
@@ -1,371 +1,376
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 "chartaxis_p.h"
21 #include "chartaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "qabstractaxis_p.h"
23 #include "qabstractaxis_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include <qmath.h>
26 #include <qmath.h>
27 #include <QDateTime>
27 #include <QDateTime>
28 #include <QValueAxis>
28
29
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31
31 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : ChartElement(presenter),
32 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : ChartElement(presenter),
32 m_chartAxis(axis),
33 m_chartAxis(axis),
33 m_labelsAngle(0),
34 m_labelsAngle(0),
34 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
35 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
35 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
36 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
36 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
37 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
37 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
38 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
38 m_min(0),
39 m_min(0),
39 m_max(0),
40 m_max(0),
40 m_animation(0),
41 m_animation(0),
41 m_minWidth(0),
42 m_minWidth(0),
42 m_minHeight(0)
43 m_minHeight(0)
43 {
44 {
44 //initial initialization
45 //initial initialization
45 m_arrow->setZValue(ChartPresenter::AxisZValue);
46 m_arrow->setZValue(ChartPresenter::AxisZValue);
46 m_arrow->setHandlesChildEvents(false);
47 m_arrow->setHandlesChildEvents(false);
47 m_labels->setZValue(ChartPresenter::AxisZValue);
48 m_labels->setZValue(ChartPresenter::AxisZValue);
48 m_shades->setZValue(ChartPresenter::ShadesZValue);
49 m_shades->setZValue(ChartPresenter::ShadesZValue);
49 m_grid->setZValue(ChartPresenter::GridZValue);
50 m_grid->setZValue(ChartPresenter::GridZValue);
50
51
51 QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
52 QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
52
53
53 QGraphicsSimpleTextItem item;
54 QGraphicsSimpleTextItem item;
54 m_font = item.font();
55 m_font = item.font();
55
56
56 }
57 }
57
58
58 ChartAxis::~ChartAxis()
59 ChartAxis::~ChartAxis()
59 {
60 {
60 }
61 }
61
62
62 void ChartAxis::setAnimation(AxisAnimation* animation)
63 void ChartAxis::setAnimation(AxisAnimation* animation)
63 {
64 {
64 m_animation=animation;
65 m_animation=animation;
65 }
66 }
66
67
67 void ChartAxis::setLayout(QVector<qreal> &layout)
68 void ChartAxis::setLayout(QVector<qreal> &layout)
68 {
69 {
69 m_layoutVector=layout;
70 m_layoutVector=layout;
70 }
71 }
71
72
72 void ChartAxis::createItems(int count)
73 void ChartAxis::createItems(int count)
73 {
74 {
74 if (m_arrow->children().size() == 0)
75 if (m_arrow->children().size() == 0)
75 m_arrow->addToGroup(new AxisItem(this,presenter()->rootItem()));
76 m_arrow->addToGroup(new AxisItem(this,presenter()->rootItem()));
76 for (int i = 0; i < count; ++i) {
77 for (int i = 0; i < count; ++i) {
77 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
78 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
78 m_labels->addToGroup(new QGraphicsSimpleTextItem(presenter()->rootItem()));
79 m_labels->addToGroup(new QGraphicsSimpleTextItem(presenter()->rootItem()));
79 m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
80 m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
80 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem()));
81 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem()));
81 }
82 }
82 }
83 }
83
84
84 void ChartAxis::deleteItems(int count)
85 void ChartAxis::deleteItems(int count)
85 {
86 {
86 QList<QGraphicsItem *> lines = m_grid->childItems();
87 QList<QGraphicsItem *> lines = m_grid->childItems();
87 QList<QGraphicsItem *> labels = m_labels->childItems();
88 QList<QGraphicsItem *> labels = m_labels->childItems();
88 QList<QGraphicsItem *> shades = m_shades->childItems();
89 QList<QGraphicsItem *> shades = m_shades->childItems();
89 QList<QGraphicsItem *> axis = m_arrow->childItems();
90 QList<QGraphicsItem *> axis = m_arrow->childItems();
90
91
91 for (int i = 0; i < count; ++i) {
92 for (int i = 0; i < count; ++i) {
92 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
93 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
93 delete(lines.takeLast());
94 delete(lines.takeLast());
94 delete(labels.takeLast());
95 delete(labels.takeLast());
95 delete(axis.takeLast());
96 delete(axis.takeLast());
96 }
97 }
97 }
98 }
98
99
99 void ChartAxis::updateLayout(QVector<qreal> &layout)
100 void ChartAxis::updateLayout(QVector<qreal> &layout)
100 {
101 {
101 int diff = m_layoutVector.size() - layout.size();
102 int diff = m_layoutVector.size() - layout.size();
102
103
103 if (diff>0) {
104 if (diff>0) {
104 deleteItems(diff);
105 deleteItems(diff);
105 }
106 }
106 else if (diff<0) {
107 else if (diff<0) {
107 createItems(-diff);
108 createItems(-diff);
108 }
109 }
109
110
110 if(diff<0) handleAxisUpdated();
111 if(diff<0) handleAxisUpdated();
111
112
112 if (m_animation) {
113 if (m_animation) {
113 switch(presenter()->state()){
114 switch(presenter()->state()){
114 case ChartPresenter::ZoomInState:
115 case ChartPresenter::ZoomInState:
115 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
116 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
116 m_animation->setAnimationPoint(presenter()->statePoint());
117 m_animation->setAnimationPoint(presenter()->statePoint());
117 break;
118 break;
118 case ChartPresenter::ZoomOutState:
119 case ChartPresenter::ZoomOutState:
119 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
120 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
120 m_animation->setAnimationPoint(presenter()->statePoint());
121 m_animation->setAnimationPoint(presenter()->statePoint());
121 break;
122 break;
122 case ChartPresenter::ScrollUpState:
123 case ChartPresenter::ScrollUpState:
123 case ChartPresenter::ScrollLeftState:
124 case ChartPresenter::ScrollLeftState:
124 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
125 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
125 break;
126 break;
126 case ChartPresenter::ScrollDownState:
127 case ChartPresenter::ScrollDownState:
127 case ChartPresenter::ScrollRightState:
128 case ChartPresenter::ScrollRightState:
128 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
129 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
129 break;
130 break;
130 case ChartPresenter::ShowState:
131 case ChartPresenter::ShowState:
131 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
132 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
132 break;
133 break;
133 }
134 }
134 m_animation->setValues(m_layoutVector,layout);
135 m_animation->setValues(m_layoutVector,layout);
135 presenter()->startAnimation(m_animation);
136 presenter()->startAnimation(m_animation);
136 }
137 }
137 else {
138 else {
138 setLayout(layout);
139 setLayout(layout);
139 updateGeometry();
140 updateGeometry();
140 }
141 }
141 }
142 }
142
143
143 void ChartAxis::setArrowOpacity(qreal opacity)
144 void ChartAxis::setArrowOpacity(qreal opacity)
144 {
145 {
145 m_arrow->setOpacity(opacity);
146 m_arrow->setOpacity(opacity);
146 }
147 }
147
148
148 qreal ChartAxis::arrowOpacity() const
149 qreal ChartAxis::arrowOpacity() const
149 {
150 {
150 return m_arrow->opacity();
151 return m_arrow->opacity();
151 }
152 }
152
153
153 void ChartAxis::setArrowVisibility(bool visible)
154 void ChartAxis::setArrowVisibility(bool visible)
154 {
155 {
155 m_arrow->setOpacity(visible);
156 m_arrow->setOpacity(visible);
156 }
157 }
157
158
158 void ChartAxis::setGridOpacity(qreal opacity)
159 void ChartAxis::setGridOpacity(qreal opacity)
159 {
160 {
160 m_grid->setOpacity(opacity);
161 m_grid->setOpacity(opacity);
161 }
162 }
162
163
163 qreal ChartAxis::gridOpacity() const
164 qreal ChartAxis::gridOpacity() const
164 {
165 {
165 return m_grid->opacity();
166 return m_grid->opacity();
166 }
167 }
167
168
168 void ChartAxis::setGridVisibility(bool visible)
169 void ChartAxis::setGridVisibility(bool visible)
169 {
170 {
170 m_grid->setOpacity(visible);
171 m_grid->setOpacity(visible);
171 }
172 }
172
173
173 void ChartAxis::setLabelsOpacity(qreal opacity)
174 void ChartAxis::setLabelsOpacity(qreal opacity)
174 {
175 {
175 m_labels->setOpacity(opacity);
176 m_labels->setOpacity(opacity);
176 }
177 }
177
178
178 qreal ChartAxis::labelsOpacity() const
179 qreal ChartAxis::labelsOpacity() const
179 {
180 {
180 return m_labels->opacity();
181 return m_labels->opacity();
181 }
182 }
182
183
183 void ChartAxis::setLabelsVisibility(bool visible)
184 void ChartAxis::setLabelsVisibility(bool visible)
184 {
185 {
185 m_labels->setOpacity(visible);
186 m_labels->setOpacity(visible);
186 }
187 }
187
188
188 void ChartAxis::setShadesOpacity(qreal opacity)
189 void ChartAxis::setShadesOpacity(qreal opacity)
189 {
190 {
190 m_shades->setOpacity(opacity);
191 m_shades->setOpacity(opacity);
191 }
192 }
192
193
193 qreal ChartAxis::shadesOpacity() const
194 qreal ChartAxis::shadesOpacity() const
194 {
195 {
195 return m_shades->opacity();
196 return m_shades->opacity();
196 }
197 }
197
198
198 void ChartAxis::setShadesVisibility(bool visible)
199 void ChartAxis::setShadesVisibility(bool visible)
199 {
200 {
200 m_shades->setVisible(visible);
201 m_shades->setVisible(visible);
201 }
202 }
202
203
203 void ChartAxis::setLabelsAngle(int angle)
204 void ChartAxis::setLabelsAngle(int angle)
204 {
205 {
205 foreach(QGraphicsItem* item , m_labels->childItems()) {
206 foreach(QGraphicsItem* item , m_labels->childItems()) {
206 item->setRotation(angle);
207 item->setRotation(angle);
207 }
208 }
208
209
209 m_labelsAngle=angle;
210 m_labelsAngle=angle;
210 }
211 }
211
212
212 void ChartAxis::setLabelsPen(const QPen &pen)
213 void ChartAxis::setLabelsPen(const QPen &pen)
213 {
214 {
214 foreach(QGraphicsItem* item , m_labels->childItems()) {
215 foreach(QGraphicsItem* item , m_labels->childItems()) {
215 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
216 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
216 }
217 }
217 }
218 }
218
219
219 void ChartAxis::setLabelsBrush(const QBrush &brush)
220 void ChartAxis::setLabelsBrush(const QBrush &brush)
220 {
221 {
221 foreach(QGraphicsItem* item , m_labels->childItems()) {
222 foreach(QGraphicsItem* item , m_labels->childItems()) {
222 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
223 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
223 }
224 }
224 }
225 }
225
226
226 void ChartAxis::setLabelsFont(const QFont &font)
227 void ChartAxis::setLabelsFont(const QFont &font)
227 {
228 {
228 foreach(QGraphicsItem* item , m_labels->childItems()) {
229 foreach(QGraphicsItem* item , m_labels->childItems()) {
229 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
230 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
230 }
231 }
231 m_font = font;
232 m_font = font;
232 }
233 }
233
234
234 void ChartAxis::setShadesBrush(const QBrush &brush)
235 void ChartAxis::setShadesBrush(const QBrush &brush)
235 {
236 {
236 foreach(QGraphicsItem* item , m_shades->childItems()) {
237 foreach(QGraphicsItem* item , m_shades->childItems()) {
237 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
238 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
238 }
239 }
239 }
240 }
240
241
241 void ChartAxis::setShadesPen(const QPen &pen)
242 void ChartAxis::setShadesPen(const QPen &pen)
242 {
243 {
243 foreach(QGraphicsItem* item , m_shades->childItems()) {
244 foreach(QGraphicsItem* item , m_shades->childItems()) {
244 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
245 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
245 }
246 }
246 }
247 }
247
248
248 void ChartAxis::setArrowPen(const QPen &pen)
249 void ChartAxis::setArrowPen(const QPen &pen)
249 {
250 {
250 foreach(QGraphicsItem* item , m_arrow->childItems()) {
251 foreach(QGraphicsItem* item , m_arrow->childItems()) {
251 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
252 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
252 }
253 }
253 }
254 }
254
255
255 void ChartAxis::setGridPen(const QPen &pen)
256 void ChartAxis::setGridPen(const QPen &pen)
256 {
257 {
257 foreach(QGraphicsItem* item , m_grid->childItems()) {
258 foreach(QGraphicsItem* item , m_grid->childItems()) {
258 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
259 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
259 }
260 }
260 }
261 }
261
262
262 bool ChartAxis::isEmpty()
263 bool ChartAxis::isEmpty()
263 {
264 {
264 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max);
265 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max);
265 }
266 }
266
267
267 void ChartAxis::handleDomainUpdated()
268 void ChartAxis::handleDomainUpdated()
268 {
269 {
269 Domain* domain = qobject_cast<Domain*>(sender());
270 Domain* domain = qobject_cast<Domain*>(sender());
270 qreal min(0);
271 qreal min(0);
271 qreal max(0);
272 qreal max(0);
272
273
273 if(m_chartAxis->orientation()==Qt::Horizontal) {
274 if(m_chartAxis->orientation()==Qt::Horizontal) {
274 min = domain->minX();
275 min = domain->minX();
275 max = domain->maxX();
276 max = domain->maxX();
276 }
277 }
277 else if (m_chartAxis->orientation()==Qt::Vertical)
278 else if (m_chartAxis->orientation()==Qt::Vertical)
278 {
279 {
279 min = domain->minY();
280 min = domain->minY();
280 max = domain->maxY();
281 max = domain->maxY();
281 }
282 }
282
283
283 if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max))
284 if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max))
284 {
285 {
285 m_min = min;
286 m_min = min;
286 m_max = max;
287 m_max = max;
287
288
288 if (!isEmpty()) {
289 if (!isEmpty()) {
289 QVector<qreal> layout = calculateLayout();
290 QVector<qreal> layout = calculateLayout();
290 updateLayout(layout);
291 updateLayout(layout);
291 }
292 }
292 }
293 }
293 }
294 }
294
295
295 void ChartAxis::handleAxisUpdated()
296 void ChartAxis::handleAxisUpdated()
296 {
297 {
297 if(isEmpty()) return;
298 if(isEmpty()) return;
298
299
299
300
300 bool visible = m_chartAxis->isVisible();
301 bool visible = m_chartAxis->isVisible();
301
302
302 setArrowVisibility(visible && m_chartAxis->isLineVisible());
303 setArrowVisibility(visible && m_chartAxis->isLineVisible());
303 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
304 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
304 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
305 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
305 setShadesVisibility(visible && m_chartAxis->shadesVisible());
306 setShadesVisibility(visible && m_chartAxis->shadesVisible());
306 setLabelsAngle(m_chartAxis->labelsAngle());
307 setLabelsAngle(m_chartAxis->labelsAngle());
307 setArrowPen(m_chartAxis->linePen());
308 setArrowPen(m_chartAxis->linePen());
308 setLabelsPen(m_chartAxis->labelsPen());
309 setLabelsPen(m_chartAxis->labelsPen());
309 setLabelsBrush(m_chartAxis->labelsBrush());
310 setLabelsBrush(m_chartAxis->labelsBrush());
310 setLabelsFont(m_chartAxis->labelsFont());
311 setLabelsFont(m_chartAxis->labelsFont());
311 setGridPen(m_chartAxis->gridLinePen());
312 setGridPen(m_chartAxis->gridLinePen());
312 setShadesPen(m_chartAxis->shadesPen());
313 setShadesPen(m_chartAxis->shadesPen());
313 setShadesBrush(m_chartAxis->shadesBrush());
314 setShadesBrush(m_chartAxis->shadesBrush());
314
315
315 }
316 }
316
317
317 void ChartAxis::hide()
318 void ChartAxis::hide()
318 {
319 {
319 setArrowVisibility(false);
320 setArrowVisibility(false);
320 setGridVisibility(false);
321 setGridVisibility(false);
321 setLabelsVisibility(false);
322 setLabelsVisibility(false);
322 setShadesVisibility(false);
323 setShadesVisibility(false);
323 }
324 }
324
325
325 void ChartAxis::handleGeometryChanged(const QRectF &rect)
326 void ChartAxis::handleGeometryChanged(const QRectF &rect)
326 {
327 {
327 if(m_rect != rect)
328 if(m_rect != rect)
328 {
329 {
329 m_rect = rect;
330 m_rect = rect;
330 if (isEmpty()) return;
331 if (isEmpty()) return;
331 QVector<qreal> layout = calculateLayout();
332 QVector<qreal> layout = calculateLayout();
332 updateLayout(layout);
333 updateLayout(layout);
333 }
334 }
334 }
335 }
335
336
336
337
337 qreal ChartAxis::minimumWidth()
338 qreal ChartAxis::minimumWidth()
338 {
339 {
339 if(m_minWidth == 0) updateGeometry();
340 if(m_minWidth == 0) updateGeometry();
340 return m_minWidth;
341 return m_minWidth;
341 }
342 }
342
343
343 qreal ChartAxis::minimumHeight()
344 qreal ChartAxis::minimumHeight()
344 {
345 {
345 if(m_minHeight == 0) updateGeometry();
346 if(m_minHeight == 0) updateGeometry();
346 return m_minHeight;
347 return m_minHeight;
347 }
348 }
348
349
349
350
350 void ChartAxis::axisSelected()
351 void ChartAxis::axisSelected()
351 {
352 {
352 qDebug()<<"TODO: axis clicked";
353 qDebug()<<"TODO: axis clicked";
353 }
354 }
354
355
355
356
356 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const
357 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const
357 {
358 {
358 Q_ASSERT(max>min);
359 Q_ASSERT(max>min);
359 Q_ASSERT(ticks>1);
360 Q_ASSERT(ticks>1);
360
361
361 int n = qMax(int(-qFloor(log10((max-min)/(ticks-1)))),0);
362 int n = qMax(int(-qFloor(log10((max-min)/(ticks-1)))),0);
362 n++;
363 n++;
364
365 QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis);
366 QByteArray array = axis->labelFormat().toAscii();
363 for (int i=0; i< ticks; i++) {
367 for (int i=0; i< ticks; i++) {
364 qreal value = min + (i * (max - min)/ (ticks-1));
368 qreal value = min + (i * (max - min)/ (ticks-1));
365 labels << QString::number(value,'f',n);
369 QString label;
370 labels << label.sprintf(array, value);;
366 }
371 }
367 }
372 }
368
373
369 #include "moc_chartaxis_p.cpp"
374 #include "moc_chartaxis_p.cpp"
370
375
371 QTCOMMERCIALCHART_END_NAMESPACE
376 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,384 +1,397
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 "qvalueaxis.h"
21 #include "qvalueaxis.h"
22 #include "qvalueaxis_p.h"
22 #include "qvalueaxis_p.h"
23 #include "chartvalueaxisx_p.h"
23 #include "chartvalueaxisx_p.h"
24 #include "chartvalueaxisy_p.h"
24 #include "chartvalueaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 /*!
31 /*!
32 \class QValueAxis
32 \class QValueAxis
33 \brief The QValueAxis class is used for manipulating chart's axis.
33 \brief The QValueAxis class is used for manipulating chart's axis.
34 \mainclass
34 \mainclass
35
35
36 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
36 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
37 Values of axis are drawn to position of ticks
37 Values of axis are drawn to position of ticks
38 */
38 */
39
39
40 /*!
40 /*!
41 \qmlclass ValueAxis QValueAxis
41 \qmlclass ValueAxis QValueAxis
42 \brief The ValueAxis element is used for manipulating chart's axes
42 \brief The ValueAxis element is used for manipulating chart's axes
43
43
44 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
44 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
45 Values of axis are drawn to position of ticks
45 Values of axis are drawn to position of ticks
46
46
47 To access Axes you can use ChartView API. For example:
47 To access Axes you can use ChartView API. For example:
48 \code
48 \code
49 ChartView {
49 ChartView {
50 ValueAxis {
50 ValueAxis {
51 id: xAxis
51 id: xAxis
52 min: 0
52 min: 0
53 max: 10
53 max: 10
54 }
54 }
55 // Add a few series...
55 // Add a few series...
56 }
56 }
57 \endcode
57 \endcode
58 */
58 */
59
59
60 /*!
60 /*!
61 \property QValueAxis::min
61 \property QValueAxis::min
62 Defines the minimum value on the axis.
62 Defines the minimum value on the axis.
63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
64 */
64 */
65 /*!
65 /*!
66 \qmlproperty real ValueAxis::min
66 \qmlproperty real ValueAxis::min
67 Defines the minimum value on the axis.
67 Defines the minimum value on the axis.
68 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
68 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QValueAxis::max
72 \property QValueAxis::max
73 Defines the maximum value on the axis.
73 Defines the maximum value on the axis.
74 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
74 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty real ValueAxis::max
77 \qmlproperty real ValueAxis::max
78 Defines the maximum value on the axis.
78 Defines the maximum value on the axis.
79 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
79 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
80 */
80 */
81
81
82 /*!
82 /*!
83 \fn void QValueAxis::minChanged(qreal min)
83 \fn void QValueAxis::minChanged(qreal min)
84 Axis emits signal when \a min of axis has changed.
84 Axis emits signal when \a min of axis has changed.
85 */
85 */
86 /*!
86 /*!
87 \qmlsignal ValueAxis::onMinChanged(real min)
87 \qmlsignal ValueAxis::onMinChanged(real min)
88 Axis emits signal when \a min of axis has changed.
88 Axis emits signal when \a min of axis has changed.
89 */
89 */
90
90
91 /*!
91 /*!
92 \fn void QValueAxis::maxChanged(qreal max)
92 \fn void QValueAxis::maxChanged(qreal max)
93 Axis emits signal when \a max of axis has changed.
93 Axis emits signal when \a max of axis has changed.
94 */
94 */
95 /*!
95 /*!
96 \qmlsignal ValueAxis::onMaxChanged(real max)
96 \qmlsignal ValueAxis::onMaxChanged(real max)
97 Axis emits signal when \a max of axis has changed.
97 Axis emits signal when \a max of axis has changed.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
101 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
102 Axis emits signal when \a min or \a max of axis has changed.
102 Axis emits signal when \a min or \a max of axis has changed.
103 */
103 */
104
104
105 /*!
105 /*!
106 \property QValueAxis::tickCount
106 \property QValueAxis::tickCount
107 The number of tick marks for the axis.
107 The number of tick marks for the axis.
108 */
108 */
109
109
110 /*!
110 /*!
111 \qmlproperty int ValueAxis::tickCount
111 \qmlproperty int ValueAxis::tickCount
112 The number of tick marks for the axis.
112 The number of tick marks for the axis.
113 */
113 */
114
114
115 /*!
115 /*!
116 \property QValueAxis::niceNumbersEnabled
116 \property QValueAxis::niceNumbersEnabled
117 Whether the nice numbers algorithm is enabled or not for the axis.
117 Whether the nice numbers algorithm is enabled or not for the axis.
118 */
118 */
119
119
120 /*!
120 /*!
121 \qmlproperty bool ValueAxis::niceNumbersEnabled
121 \qmlproperty bool ValueAxis::niceNumbersEnabled
122 Whether the nice numbers algorithm is enabled or not for the axis.
122 Whether the nice numbers algorithm is enabled or not for the axis.
123 */
123 */
124
124
125 /*!
125 /*!
126 Constructs an axis object which is a child of \a parent.
126 Constructs an axis object which is a child of \a parent.
127 */
127 */
128 QValueAxis::QValueAxis(QObject *parent) :
128 QValueAxis::QValueAxis(QObject *parent) :
129 QAbstractAxis(*new QValueAxisPrivate(this),parent)
129 QAbstractAxis(*new QValueAxisPrivate(this),parent)
130 {
130 {
131
131
132 }
132 }
133
133
134 /*!
134 /*!
135 \internal
135 \internal
136 */
136 */
137 QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
137 QValueAxis::QValueAxis(QValueAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
138 {
138 {
139
139
140 }
140 }
141
141
142 /*!
142 /*!
143 Destroys the object
143 Destroys the object
144 */
144 */
145 QValueAxis::~QValueAxis()
145 QValueAxis::~QValueAxis()
146 {
146 {
147 Q_D(QValueAxis);
147 Q_D(QValueAxis);
148 if(d->m_dataset) {
148 if(d->m_dataset) {
149 d->m_dataset->removeAxis(this);
149 d->m_dataset->removeAxis(this);
150 }
150 }
151 }
151 }
152
152
153 void QValueAxis::setMin(qreal min)
153 void QValueAxis::setMin(qreal min)
154 {
154 {
155 Q_D(QValueAxis);
155 Q_D(QValueAxis);
156 setRange(min, qMax(d->m_max, min));
156 setRange(min, qMax(d->m_max, min));
157 }
157 }
158
158
159 qreal QValueAxis::min() const
159 qreal QValueAxis::min() const
160 {
160 {
161 Q_D(const QValueAxis);
161 Q_D(const QValueAxis);
162 return d->m_min;
162 return d->m_min;
163 }
163 }
164
164
165 void QValueAxis::setMax(qreal max)
165 void QValueAxis::setMax(qreal max)
166 {
166 {
167 Q_D(QValueAxis);
167 Q_D(QValueAxis);
168 setRange(qMin(d->m_min, max), max);
168 setRange(qMin(d->m_min, max), max);
169 }
169 }
170
170
171 qreal QValueAxis::max() const
171 qreal QValueAxis::max() const
172 {
172 {
173 Q_D(const QValueAxis);
173 Q_D(const QValueAxis);
174 return d->m_max;
174 return d->m_max;
175 }
175 }
176
176
177 /*!
177 /*!
178 Sets range from \a min to \a max on the axis.
178 Sets range from \a min to \a max on the axis.
179 If min is greater than max then this function returns without making any changes.
179 If min is greater than max then this function returns without making any changes.
180 */
180 */
181 void QValueAxis::setRange(qreal min, qreal max)
181 void QValueAxis::setRange(qreal min, qreal max)
182 {
182 {
183 Q_D(QValueAxis);
183 Q_D(QValueAxis);
184 bool changed = false;
184 bool changed = false;
185
185
186 if (min > max) return;
186 if (min > max) return;
187
187
188 if(d->m_niceNumbers) {
188 if(d->m_niceNumbers) {
189 int ticks = d->m_tickCount;
189 int ticks = d->m_tickCount;
190 d->looseNiceNumbers(min, max, ticks);
190 d->looseNiceNumbers(min, max, ticks);
191 if(ticks!=d->m_tickCount) setTickCount(ticks);
191 if(ticks!=d->m_tickCount) setTickCount(ticks);
192 }
192 }
193
193
194 if (!qFuzzyIsNull(d->m_min - min)) {
194 if (!qFuzzyIsNull(d->m_min - min)) {
195 d->m_min = min;
195 d->m_min = min;
196 changed = true;
196 changed = true;
197 emit minChanged(min);
197 emit minChanged(min);
198 }
198 }
199
199
200 if (!qFuzzyIsNull(d->m_max - max)) {
200 if (!qFuzzyIsNull(d->m_max - max)) {
201 d->m_max = max;
201 d->m_max = max;
202 changed = true;
202 changed = true;
203 emit maxChanged(max);
203 emit maxChanged(max);
204 }
204 }
205
205
206 if (changed) {
206 if (changed) {
207 emit rangeChanged(min,max);
207 emit rangeChanged(min,max);
208 d->emitUpdated();
208 d->emitUpdated();
209 }
209 }
210 }
210 }
211
211
212 /*!
212 /*!
213 Sets \a count for ticks on the axis.
213 Sets \a count for ticks on the axis.
214 */
214 */
215 void QValueAxis::setTickCount(int count)
215 void QValueAxis::setTickCount(int count)
216 {
216 {
217 Q_D(QValueAxis);
217 Q_D(QValueAxis);
218 if (d->m_tickCount != count && count >=2) {
218 if (d->m_tickCount != count && count >=2) {
219 d->m_tickCount = count;
219 d->m_tickCount = count;
220 d->emitUpdated();
220 d->emitUpdated();
221 }
221 }
222 }
222 }
223
223
224 /*!
224 /*!
225 \fn int QValueAxis::tickCount() const
225 \fn int QValueAxis::tickCount() const
226 Return number of ticks on the axis
226 Return number of ticks on the axis
227 */
227 */
228 int QValueAxis::tickCount() const
228 int QValueAxis::tickCount() const
229 {
229 {
230 Q_D(const QValueAxis);
230 Q_D(const QValueAxis);
231 return d->m_tickCount;
231 return d->m_tickCount;
232 }
232 }
233
233
234 void QValueAxis::setNiceNumbersEnabled(bool enable)
234 void QValueAxis::setNiceNumbersEnabled(bool enable)
235 {
235 {
236 Q_D(QValueAxis);
236 Q_D(QValueAxis);
237 if (d->m_niceNumbers != enable){
237 if (d->m_niceNumbers != enable){
238 d->m_niceNumbers = enable;
238 d->m_niceNumbers = enable;
239 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) {
239 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) {
240 setRange(d->m_min,d->m_max);
240 setRange(d->m_min,d->m_max);
241 }
241 }
242 }
242 }
243 }
243 }
244
244
245 bool QValueAxis::niceNumbersEnabled() const
245 bool QValueAxis::niceNumbersEnabled() const
246 {
246 {
247 Q_D(const QValueAxis);
247 Q_D(const QValueAxis);
248 return d->m_niceNumbers;
248 return d->m_niceNumbers;
249 }
249 }
250
250
251 void QValueAxis::setLabelFormat(const QString &format)
252 {
253 Q_D(QValueAxis);
254 d->m_format = format;
255 }
256
257 QString QValueAxis::labelFormat() const
258 {
259 Q_D(const QValueAxis);
260 return d->m_format;
261 }
262
251 /*!
263 /*!
252 Returns the type of the axis
264 Returns the type of the axis
253 */
265 */
254 QAbstractAxis::AxisType QValueAxis::type() const
266 QAbstractAxis::AxisType QValueAxis::type() const
255 {
267 {
256 return AxisTypeValue;
268 return AxisTypeValue;
257 }
269 }
258
270
259 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
271 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
260
272
261 QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q):
273 QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q):
262 QAbstractAxisPrivate(q),
274 QAbstractAxisPrivate(q),
263 m_min(0),
275 m_min(0),
264 m_max(0),
276 m_max(0),
265 m_tickCount(5),
277 m_tickCount(5),
266 m_niceNumbers(false)
278 m_niceNumbers(false),
279 m_format("%g")
267 {
280 {
268
281
269 }
282 }
270
283
271 QValueAxisPrivate::~QValueAxisPrivate()
284 QValueAxisPrivate::~QValueAxisPrivate()
272 {
285 {
273
286
274 }
287 }
275
288
276 void QValueAxisPrivate::handleDomainUpdated()
289 void QValueAxisPrivate::handleDomainUpdated()
277 {
290 {
278 Q_Q(QValueAxis);
291 Q_Q(QValueAxis);
279 Domain* domain = qobject_cast<Domain*>(sender());
292 Domain* domain = qobject_cast<Domain*>(sender());
280 Q_ASSERT(domain);
293 Q_ASSERT(domain);
281
294
282 if(orientation()==Qt::Horizontal){
295 if(orientation()==Qt::Horizontal){
283 q->setRange(domain->minX(),domain->maxX());
296 q->setRange(domain->minX(),domain->maxX());
284 }else if(orientation()==Qt::Vertical){
297 }else if(orientation()==Qt::Vertical){
285 q->setRange(domain->minY(),domain->maxY());
298 q->setRange(domain->minY(),domain->maxY());
286 }
299 }
287 }
300 }
288
301
289
302
290 void QValueAxisPrivate::setMin(const QVariant &min)
303 void QValueAxisPrivate::setMin(const QVariant &min)
291 {
304 {
292 Q_Q(QValueAxis);
305 Q_Q(QValueAxis);
293 bool ok;
306 bool ok;
294 qreal value = min.toReal(&ok);
307 qreal value = min.toReal(&ok);
295 if(ok) q->setMin(value);
308 if(ok) q->setMin(value);
296 }
309 }
297
310
298 void QValueAxisPrivate::setMax(const QVariant &max)
311 void QValueAxisPrivate::setMax(const QVariant &max)
299 {
312 {
300
313
301 Q_Q(QValueAxis);
314 Q_Q(QValueAxis);
302 bool ok;
315 bool ok;
303 qreal value = max.toReal(&ok);
316 qreal value = max.toReal(&ok);
304 if(ok) q->setMax(value);
317 if(ok) q->setMax(value);
305 }
318 }
306
319
307 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
320 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
308 {
321 {
309 Q_Q(QValueAxis);
322 Q_Q(QValueAxis);
310 bool ok1;
323 bool ok1;
311 bool ok2;
324 bool ok2;
312 qreal value1 = min.toReal(&ok1);
325 qreal value1 = min.toReal(&ok1);
313 qreal value2 = max.toReal(&ok2);
326 qreal value2 = max.toReal(&ok2);
314 if(ok1&&ok2) q->setRange(value1,value2);
327 if(ok1&&ok2) q->setRange(value1,value2);
315 }
328 }
316
329
317 ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter)
330 ChartAxis* QValueAxisPrivate::createGraphics(ChartPresenter* presenter)
318 {
331 {
319 Q_Q(QValueAxis);
332 Q_Q(QValueAxis);
320 if(m_orientation == Qt::Vertical){
333 if(m_orientation == Qt::Vertical){
321 return new ChartValueAxisY(q,presenter);
334 return new ChartValueAxisY(q,presenter);
322 }else{
335 }else{
323 return new ChartValueAxisX(q,presenter);
336 return new ChartValueAxisX(q,presenter);
324 }
337 }
325
338
326 }
339 }
327
340
328 void QValueAxisPrivate::intializeDomain(Domain* domain)
341 void QValueAxisPrivate::intializeDomain(Domain* domain)
329 {
342 {
330 Q_Q(QValueAxis);
343 Q_Q(QValueAxis);
331 if(qFuzzyCompare(m_max,m_min)) {
344 if(qFuzzyCompare(m_max,m_min)) {
332 if(m_orientation==Qt::Vertical){
345 if(m_orientation==Qt::Vertical){
333 q->setRange(domain->minY(),domain->maxY());
346 q->setRange(domain->minY(),domain->maxY());
334 }else{
347 }else{
335 q->setRange(domain->minX(), domain->maxX());
348 q->setRange(domain->minX(), domain->maxX());
336 }
349 }
337 } else {
350 } else {
338 if(m_orientation==Qt::Vertical){
351 if(m_orientation==Qt::Vertical){
339 domain->setRangeY(m_min, m_max);
352 domain->setRangeY(m_min, m_max);
340 }else{
353 }else{
341 domain->setRangeX(m_min, m_max);
354 domain->setRangeX(m_min, m_max);
342 }
355 }
343 }
356 }
344 }
357 }
345
358
346 //algorithm defined by Paul S.Heckbert GraphicalGems I
359 //algorithm defined by Paul S.Heckbert GraphicalGems I
347
360
348 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
361 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
349 {
362 {
350 qreal range = niceNumber(max-min,true); //range with ceiling
363 qreal range = niceNumber(max-min,true); //range with ceiling
351 qreal step = niceNumber(range/(ticksCount-1),false);
364 qreal step = niceNumber(range/(ticksCount-1),false);
352 min = qFloor(min/step);
365 min = qFloor(min/step);
353 max = qCeil(max/step);
366 max = qCeil(max/step);
354 ticksCount = int(max-min) +1;
367 ticksCount = int(max-min) +1;
355 min*=step;
368 min*=step;
356 max*=step;
369 max*=step;
357 }
370 }
358
371
359 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
372 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
360
373
361 qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const
374 qreal QValueAxisPrivate::niceNumber(qreal x,bool ceiling) const
362 {
375 {
363 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
376 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
364 qreal q = x/z;//q<10 && q>=1;
377 qreal q = x/z;//q<10 && q>=1;
365
378
366 if(ceiling) {
379 if(ceiling) {
367 if(q <= 1.0) q=1;
380 if(q <= 1.0) q=1;
368 else if(q <= 2.0) q=2;
381 else if(q <= 2.0) q=2;
369 else if(q <= 5.0) q=5;
382 else if(q <= 5.0) q=5;
370 else q=10;
383 else q=10;
371 }
384 }
372 else {
385 else {
373 if(q < 1.5) q=1;
386 if(q < 1.5) q=1;
374 else if(q < 3.0) q=2;
387 else if(q < 3.0) q=2;
375 else if(q < 7.0) q=5;
388 else if(q < 7.0) q=5;
376 else q=10;
389 else q=10;
377 }
390 }
378 return q*z;
391 return q*z;
379 }
392 }
380
393
381 #include "moc_qvalueaxis.cpp"
394 #include "moc_qvalueaxis.cpp"
382 #include "moc_qvalueaxis_p.cpp"
395 #include "moc_qvalueaxis_p.cpp"
383
396
384 QTCOMMERCIALCHART_END_NAMESPACE
397 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,74 +1,77
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 #ifndef QVALUESAXIS_H
21 #ifndef QVALUESAXIS_H
22 #define QVALUESAXIS_H
22 #define QVALUESAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QValueAxisPrivate;
28 class QValueAxisPrivate;
29
29
30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount)
33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount)
34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
37
37
38 public:
38 public:
39 explicit QValueAxis(QObject *parent = 0);
39 explicit QValueAxis(QObject *parent = 0);
40 ~QValueAxis();
40 ~QValueAxis();
41
41
42 protected:
42 protected:
43 QValueAxis(QValueAxisPrivate &d,QObject *parent = 0);
43 QValueAxis(QValueAxisPrivate &d,QObject *parent = 0);
44
44
45 public:
45 public:
46 AxisType type() const;
46 AxisType type() const;
47
47
48 //range handling
48 //range handling
49 void setMin(qreal min);
49 void setMin(qreal min);
50 qreal min() const;
50 qreal min() const;
51 void setMax(qreal max);
51 void setMax(qreal max);
52 qreal max() const;
52 qreal max() const;
53 void setRange(qreal min, qreal max);
53 void setRange(qreal min, qreal max);
54
54
55 //ticks handling
55 //ticks handling
56 void setTickCount(int count);
56 void setTickCount(int count);
57 int tickCount() const;
57 int tickCount() const;
58
58
59 void setLabelFormat(const QString &format);
60 QString labelFormat() const;
61
59 void setNiceNumbersEnabled(bool enable = true);
62 void setNiceNumbersEnabled(bool enable = true);
60 bool niceNumbersEnabled() const;
63 bool niceNumbersEnabled() const;
61
64
62 Q_SIGNALS:
65 Q_SIGNALS:
63 void minChanged(qreal min);
66 void minChanged(qreal min);
64 void maxChanged(qreal max);
67 void maxChanged(qreal max);
65 void rangeChanged(qreal min, qreal max);
68 void rangeChanged(qreal min, qreal max);
66
69
67 private:
70 private:
68 Q_DECLARE_PRIVATE(QValueAxis)
71 Q_DECLARE_PRIVATE(QValueAxis)
69 Q_DISABLE_COPY(QValueAxis)
72 Q_DISABLE_COPY(QValueAxis)
70 };
73 };
71
74
72 QTCOMMERCIALCHART_END_NAMESPACE
75 QTCOMMERCIALCHART_END_NAMESPACE
73
76
74 #endif // QVALUESAXIS_H
77 #endif // QVALUESAXIS_H
@@ -1,72 +1,73
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QVALUESAXIS_P_H
30 #ifndef QVALUESAXIS_P_H
31 #define QVALUESAXIS_P_H
31 #define QVALUESAXIS_P_H
32
32
33 #include "qvalueaxis.h"
33 #include "qvalueaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QValueAxisPrivate : public QAbstractAxisPrivate
38 class QValueAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 QValueAxisPrivate(QValueAxis *q);
42 QValueAxisPrivate(QValueAxis *q);
43 ~QValueAxisPrivate();
43 ~QValueAxisPrivate();
44
44
45 public:
45 public:
46 ChartAxis* createGraphics(ChartPresenter* presenter);
46 ChartAxis* createGraphics(ChartPresenter* presenter);
47 void intializeDomain(Domain* domain);
47 void intializeDomain(Domain* domain);
48 void handleDomainUpdated();
48 void handleDomainUpdated();
49 qreal min(){ return m_min; };
49 qreal min(){ return m_min; };
50 qreal max(){ return m_max; };
50 qreal max(){ return m_max; };
51 int count() const { return m_tickCount;}
51 int count() const { return m_tickCount;}
52
52
53 protected:
53 protected:
54 void setMin(const QVariant &min);
54 void setMin(const QVariant &min);
55 void setMax(const QVariant &max);
55 void setMax(const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
57
57
58 private:
58 private:
59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
59 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
60 qreal niceNumber(qreal x,bool ceiling) const;
60 qreal niceNumber(qreal x,bool ceiling) const;
61
61
62 private:
62 private:
63 qreal m_min;
63 qreal m_min;
64 qreal m_max;
64 qreal m_max;
65 int m_tickCount;
65 int m_tickCount;
66 bool m_niceNumbers;
66 bool m_niceNumbers;
67 QString m_format;
67 Q_DECLARE_PUBLIC(QValueAxis)
68 Q_DECLARE_PUBLIC(QValueAxis)
68 };
69 };
69
70
70 QTCOMMERCIALCHART_END_NAMESPACE
71 QTCOMMERCIALCHART_END_NAMESPACE
71
72
72 #endif // QVALUESAXIS_P_H
73 #endif // QVALUESAXIS_P_H
General Comments 0
You need to be logged in to leave comments. Login now