##// END OF EJS Templates
abstract axis qml documentation. bug fix to setArrowVisible
sauimone -
r1654:746d930ea165
parent child
Show More
@@ -1,391 +1,391
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 "chartanimator_p.h"
25 #include "chartanimator_p.h"
26 #include <QPainter>
26 #include <QPainter>
27 #include <QDebug>
27 #include <QDebug>
28 #include <qmath.h>
28 #include <qmath.h>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter),
32 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter),
33 m_chartAxis(axis),
33 m_chartAxis(axis),
34 m_labelsAngle(0),
34 m_labelsAngle(0),
35 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
35 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
36 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
36 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
37 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
37 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
38 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
38 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
39 m_min(0),
39 m_min(0),
40 m_max(0),
40 m_max(0),
41 m_ticksCount(0),
41 m_ticksCount(0),
42 m_animation(0),
42 m_animation(0),
43 m_minWidth(0),
43 m_minWidth(0),
44 m_minHeight(0)
44 m_minHeight(0)
45 {
45 {
46 //initial initialization
46 //initial initialization
47 m_axis->setZValue(ChartPresenter::AxisZValue);
47 m_axis->setZValue(ChartPresenter::AxisZValue);
48 m_axis->setHandlesChildEvents(false);
48 m_axis->setHandlesChildEvents(false);
49
49
50 m_shades->setZValue(ChartPresenter::ShadesZValue);
50 m_shades->setZValue(ChartPresenter::ShadesZValue);
51 m_grid->setZValue(ChartPresenter::GridZValue);
51 m_grid->setZValue(ChartPresenter::GridZValue);
52
52
53 QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
53 QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
54
54
55 QGraphicsSimpleTextItem item;
55 QGraphicsSimpleTextItem item;
56 m_font = item.font();
56 m_font = item.font();
57
57
58 handleAxisUpdated();
58 handleAxisUpdated();
59 }
59 }
60
60
61 ChartAxis::~ChartAxis()
61 ChartAxis::~ChartAxis()
62 {
62 {
63 }
63 }
64
64
65 void ChartAxis::setAnimation(AxisAnimation* animation)
65 void ChartAxis::setAnimation(AxisAnimation* animation)
66 {
66 {
67 m_animation=animation;
67 m_animation=animation;
68 }
68 }
69
69
70 void ChartAxis::setLayout(QVector<qreal> &layout)
70 void ChartAxis::setLayout(QVector<qreal> &layout)
71 {
71 {
72 m_layoutVector=layout;
72 m_layoutVector=layout;
73 }
73 }
74
74
75 void ChartAxis::createItems(int count)
75 void ChartAxis::createItems(int count)
76 {
76 {
77 if (m_axis->children().size() == 0)
77 if (m_axis->children().size() == 0)
78 m_axis->addToGroup(new AxisItem(this));
78 m_axis->addToGroup(new AxisItem(this));
79 for (int i = 0; i < count; ++i) {
79 for (int i = 0; i < count; ++i) {
80 m_grid->addToGroup(new QGraphicsLineItem());
80 m_grid->addToGroup(new QGraphicsLineItem());
81 m_labels->addToGroup(new QGraphicsSimpleTextItem());
81 m_labels->addToGroup(new QGraphicsSimpleTextItem());
82 m_axis->addToGroup(new QGraphicsLineItem());
82 m_axis->addToGroup(new QGraphicsLineItem());
83 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
83 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
84 }
84 }
85 }
85 }
86
86
87 void ChartAxis::deleteItems(int count)
87 void ChartAxis::deleteItems(int count)
88 {
88 {
89 QList<QGraphicsItem *> lines = m_grid->childItems();
89 QList<QGraphicsItem *> lines = m_grid->childItems();
90 QList<QGraphicsItem *> labels = m_labels->childItems();
90 QList<QGraphicsItem *> labels = m_labels->childItems();
91 QList<QGraphicsItem *> shades = m_shades->childItems();
91 QList<QGraphicsItem *> shades = m_shades->childItems();
92 QList<QGraphicsItem *> axis = m_axis->childItems();
92 QList<QGraphicsItem *> axis = m_axis->childItems();
93
93
94 for (int i = 0; i < count; ++i) {
94 for (int i = 0; i < count; ++i) {
95 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
95 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
96 delete(lines.takeLast());
96 delete(lines.takeLast());
97 delete(labels.takeLast());
97 delete(labels.takeLast());
98 delete(axis.takeLast());
98 delete(axis.takeLast());
99 }
99 }
100 }
100 }
101
101
102 void ChartAxis::updateLayout(QVector<qreal> &layout)
102 void ChartAxis::updateLayout(QVector<qreal> &layout)
103 {
103 {
104 int diff = m_layoutVector.size() - layout.size();
104 int diff = m_layoutVector.size() - layout.size();
105
105
106 if (diff>0) {
106 if (diff>0) {
107 deleteItems(diff);
107 deleteItems(diff);
108 }
108 }
109 else if (diff<0) {
109 else if (diff<0) {
110 createItems(-diff);
110 createItems(-diff);
111 }
111 }
112
112
113 if( diff!=0) handleAxisUpdated();
113 if( diff!=0) handleAxisUpdated();
114
114
115 if (m_animation) {
115 if (m_animation) {
116 switch(presenter()->state()){
116 switch(presenter()->state()){
117 case ChartPresenter::ZoomInState:
117 case ChartPresenter::ZoomInState:
118 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
118 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
119 m_animation->setAnimationPoint(presenter()->statePoint());
119 m_animation->setAnimationPoint(presenter()->statePoint());
120 break;
120 break;
121 case ChartPresenter::ZoomOutState:
121 case ChartPresenter::ZoomOutState:
122 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
122 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
123 m_animation->setAnimationPoint(presenter()->statePoint());
123 m_animation->setAnimationPoint(presenter()->statePoint());
124 break;
124 break;
125 case ChartPresenter::ScrollUpState:
125 case ChartPresenter::ScrollUpState:
126 case ChartPresenter::ScrollLeftState:
126 case ChartPresenter::ScrollLeftState:
127 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
127 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
128 break;
128 break;
129 case ChartPresenter::ScrollDownState:
129 case ChartPresenter::ScrollDownState:
130 case ChartPresenter::ScrollRightState:
130 case ChartPresenter::ScrollRightState:
131 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
131 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
132 break;
132 break;
133 case ChartPresenter::ShowState:
133 case ChartPresenter::ShowState:
134 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
134 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
135 break;
135 break;
136 }
136 }
137 m_animation->setValues(m_layoutVector,layout);
137 m_animation->setValues(m_layoutVector,layout);
138 presenter()->startAnimation(m_animation);
138 presenter()->startAnimation(m_animation);
139 }
139 }
140 else {
140 else {
141 setLayout(layout);
141 setLayout(layout);
142 updateGeometry();
142 updateGeometry();
143 }
143 }
144 }
144 }
145
145
146 void ChartAxis::setAxisOpacity(qreal opacity)
146 void ChartAxis::setAxisOpacity(qreal opacity)
147 {
147 {
148 m_axis->setOpacity(opacity);
148 m_axis->setOpacity(opacity);
149 }
149 }
150
150
151 qreal ChartAxis::axisOpacity() const
151 qreal ChartAxis::axisOpacity() const
152 {
152 {
153 return m_axis->opacity();
153 return m_axis->opacity();
154 }
154 }
155
155
156 void ChartAxis::setGridOpacity(qreal opacity)
156 void ChartAxis::setGridOpacity(qreal opacity)
157 {
157 {
158 m_grid->setOpacity(opacity);
158 m_grid->setOpacity(opacity);
159 }
159 }
160
160
161 qreal ChartAxis::gridOpacity() const
161 qreal ChartAxis::gridOpacity() const
162 {
162 {
163 return m_grid->opacity();
163 return m_grid->opacity();
164 }
164 }
165
165
166 void ChartAxis::setLabelsOpacity(qreal opacity)
166 void ChartAxis::setLabelsOpacity(qreal opacity)
167 {
167 {
168 m_labels->setOpacity(opacity);
168 m_labels->setOpacity(opacity);
169 }
169 }
170
170
171 qreal ChartAxis::labelsOpacity() const
171 qreal ChartAxis::labelsOpacity() const
172 {
172 {
173 return m_labels->opacity();
173 return m_labels->opacity();
174 }
174 }
175
175
176 void ChartAxis::setShadesOpacity(qreal opacity)
176 void ChartAxis::setShadesOpacity(qreal opacity)
177 {
177 {
178 m_shades->setOpacity(opacity);
178 m_shades->setOpacity(opacity);
179 }
179 }
180
180
181 qreal ChartAxis::shadesOpacity() const
181 qreal ChartAxis::shadesOpacity() const
182 {
182 {
183 return m_shades->opacity();
183 return m_shades->opacity();
184 }
184 }
185
185
186 void ChartAxis::setLabelsAngle(int angle)
186 void ChartAxis::setLabelsAngle(int angle)
187 {
187 {
188 foreach(QGraphicsItem* item , m_labels->childItems()) {
188 foreach(QGraphicsItem* item , m_labels->childItems()) {
189 item->setRotation(angle);
189 item->setRotation(angle);
190 }
190 }
191
191
192 m_labelsAngle=angle;
192 m_labelsAngle=angle;
193 }
193 }
194
194
195 void ChartAxis::setLabelsPen(const QPen &pen)
195 void ChartAxis::setLabelsPen(const QPen &pen)
196 {
196 {
197 foreach(QGraphicsItem* item , m_labels->childItems()) {
197 foreach(QGraphicsItem* item , m_labels->childItems()) {
198 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
198 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
199 }
199 }
200 }
200 }
201
201
202 void ChartAxis::setLabelsBrush(const QBrush &brush)
202 void ChartAxis::setLabelsBrush(const QBrush &brush)
203 {
203 {
204 foreach(QGraphicsItem* item , m_labels->childItems()) {
204 foreach(QGraphicsItem* item , m_labels->childItems()) {
205 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
205 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
206 }
206 }
207 }
207 }
208
208
209 void ChartAxis::setLabelsFont(const QFont &font)
209 void ChartAxis::setLabelsFont(const QFont &font)
210 {
210 {
211 foreach(QGraphicsItem* item , m_labels->childItems()) {
211 foreach(QGraphicsItem* item , m_labels->childItems()) {
212 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
212 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
213 }
213 }
214 m_font = font;
214 m_font = font;
215 }
215 }
216
216
217 void ChartAxis::setShadesBrush(const QBrush &brush)
217 void ChartAxis::setShadesBrush(const QBrush &brush)
218 {
218 {
219 foreach(QGraphicsItem* item , m_shades->childItems()) {
219 foreach(QGraphicsItem* item , m_shades->childItems()) {
220 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
220 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
221 }
221 }
222 }
222 }
223
223
224 void ChartAxis::setShadesPen(const QPen &pen)
224 void ChartAxis::setShadesPen(const QPen &pen)
225 {
225 {
226 foreach(QGraphicsItem* item , m_shades->childItems()) {
226 foreach(QGraphicsItem* item , m_shades->childItems()) {
227 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
227 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
228 }
228 }
229 }
229 }
230
230
231 void ChartAxis::setAxisPen(const QPen &pen)
231 void ChartAxis::setAxisPen(const QPen &pen)
232 {
232 {
233 foreach(QGraphicsItem* item , m_axis->childItems()) {
233 foreach(QGraphicsItem* item , m_axis->childItems()) {
234 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
234 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
235 }
235 }
236 }
236 }
237
237
238 void ChartAxis::setGridPen(const QPen &pen)
238 void ChartAxis::setGridPen(const QPen &pen)
239 {
239 {
240 foreach(QGraphicsItem* item , m_grid->childItems()) {
240 foreach(QGraphicsItem* item , m_grid->childItems()) {
241 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
241 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
242 }
242 }
243 }
243 }
244
244
245 bool ChartAxis::isEmpty()
245 bool ChartAxis::isEmpty()
246 {
246 {
247 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0;
247 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0;
248 }
248 }
249
249
250 //handlers
250 //handlers
251
251
252 void ChartAxis::handleAxisCategoriesUpdated()
252 void ChartAxis::handleAxisCategoriesUpdated()
253 {
253 {
254 if (isEmpty()) return;
254 if (isEmpty()) return;
255 updateLayout(m_layoutVector);
255 updateLayout(m_layoutVector);
256 }
256 }
257
257
258 void ChartAxis::handleAxisUpdated()
258 void ChartAxis::handleAxisUpdated()
259 {
259 {
260
260
261 if (isEmpty()) return;
261 if (isEmpty()) return;
262
262
263 if (!m_chartAxis->isVisible()) {
263 if (!m_chartAxis->isVisible()) {
264 setAxisOpacity(0);
264 setAxisOpacity(0);
265 setGridOpacity(0);
265 setGridOpacity(0);
266 setLabelsOpacity(0);
266 setLabelsOpacity(0);
267 setShadesOpacity(0);
267 setShadesOpacity(0);
268 }
268 }
269 else {
269 else {
270
270
271 if (m_chartAxis->isAxisVisible()) {
271 if (m_chartAxis->isArrowVisible()) {
272 setAxisOpacity(100);
272 setAxisOpacity(100);
273 }
273 }
274 else {
274 else {
275 setAxisOpacity(0);
275 setAxisOpacity(0);
276 }
276 }
277
277
278 if (m_chartAxis->isGridLineVisible()) {
278 if (m_chartAxis->isGridLineVisible()) {
279 setGridOpacity(100);
279 setGridOpacity(100);
280 }
280 }
281 else {
281 else {
282 setGridOpacity(0);
282 setGridOpacity(0);
283 }
283 }
284
284
285 if (m_chartAxis->labelsVisible()) {
285 if (m_chartAxis->labelsVisible()) {
286 setLabelsOpacity(100);
286 setLabelsOpacity(100);
287 }
287 }
288 else {
288 else {
289 setLabelsOpacity(0);
289 setLabelsOpacity(0);
290 }
290 }
291
291
292 if (m_chartAxis->shadesVisible()) {
292 if (m_chartAxis->shadesVisible()) {
293 setShadesOpacity(100);
293 setShadesOpacity(100);
294 }
294 }
295 else {
295 else {
296 setShadesOpacity(0);
296 setShadesOpacity(0);
297 }
297 }
298 }
298 }
299 setLabelsAngle(m_chartAxis->labelsAngle());
299 setLabelsAngle(m_chartAxis->labelsAngle());
300 setAxisPen(m_chartAxis->axisPen());
300 setAxisPen(m_chartAxis->axisPen());
301 setLabelsPen(m_chartAxis->labelsPen());
301 setLabelsPen(m_chartAxis->labelsPen());
302 setLabelsBrush(m_chartAxis->labelsBrush());
302 setLabelsBrush(m_chartAxis->labelsBrush());
303 setLabelsFont(m_chartAxis->labelsFont());
303 setLabelsFont(m_chartAxis->labelsFont());
304 setGridPen(m_chartAxis->gridLinePen());
304 setGridPen(m_chartAxis->gridLinePen());
305 setShadesPen(m_chartAxis->shadesPen());
305 setShadesPen(m_chartAxis->shadesPen());
306 setShadesBrush(m_chartAxis->shadesBrush());
306 setShadesBrush(m_chartAxis->shadesBrush());
307
307
308 }
308 }
309
309
310 void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount)
310 void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount)
311 {
311 {
312 if (qFuzzyIsNull(min - max) || tickCount < 2)
312 if (qFuzzyIsNull(min - max) || tickCount < 2)
313 return;
313 return;
314
314
315 m_min = min;
315 m_min = min;
316 m_max = max;
316 m_max = max;
317 m_ticksCount= tickCount;
317 m_ticksCount= tickCount;
318
318
319 if (isEmpty()) return;
319 if (isEmpty()) return;
320 QVector<qreal> layout = calculateLayout();
320 QVector<qreal> layout = calculateLayout();
321 updateLayout(layout);
321 updateLayout(layout);
322 }
322 }
323
323
324 void ChartAxis::handleGeometryChanged(const QRectF &rect)
324 void ChartAxis::handleGeometryChanged(const QRectF &rect)
325 {
325 {
326 if(m_rect != rect)
326 if(m_rect != rect)
327 {
327 {
328 m_rect = rect;
328 m_rect = rect;
329 if (isEmpty()) return;
329 if (isEmpty()) return;
330 QVector<qreal> layout = calculateLayout();
330 QVector<qreal> layout = calculateLayout();
331 updateLayout(layout);
331 updateLayout(layout);
332 }
332 }
333 }
333 }
334
334
335
335
336 qreal ChartAxis::minimumWidth()
336 qreal ChartAxis::minimumWidth()
337 {
337 {
338 if(m_minWidth == 0) updateGeometry();
338 if(m_minWidth == 0) updateGeometry();
339 return m_minWidth;
339 return m_minWidth;
340 }
340 }
341
341
342 qreal ChartAxis::minimumHeight()
342 qreal ChartAxis::minimumHeight()
343 {
343 {
344 if(m_minHeight == 0) updateGeometry();
344 if(m_minHeight == 0) updateGeometry();
345 return m_minHeight;
345 return m_minHeight;
346 }
346 }
347
347
348
348
349 void ChartAxis::axisSelected()
349 void ChartAxis::axisSelected()
350 {
350 {
351 qDebug()<<"TODO: axis clicked";
351 qDebug()<<"TODO: axis clicked";
352 }
352 }
353
353
354
354
355 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const
355 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const
356 {
356 {
357 Q_ASSERT(max>min);
357 Q_ASSERT(max>min);
358 Q_ASSERT(ticks>1);
358 Q_ASSERT(ticks>1);
359
359
360 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
360 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
361 n++;
361 n++;
362 for (int i=0; i< ticks; i++) {
362 for (int i=0; i< ticks; i++) {
363 qreal value = min + (i * (max - min)/ (ticks-1));
363 qreal value = min + (i * (max - min)/ (ticks-1));
364 labels << QString::number(value,'f',n);
364 labels << QString::number(value,'f',n);
365 }
365 }
366 }
366 }
367
367
368 void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const
368 void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const
369 {
369 {
370 Q_ASSERT(max>min);
370 Q_ASSERT(max>min);
371 Q_UNUSED(max);
371 Q_UNUSED(max);
372
372
373 int x = qCeil(min);
373 int x = qCeil(min);
374 int count = 0;
374 int count = 0;
375
375
376 // Try to find category for x coordinate
376 // Try to find category for x coordinate
377 while (count < m_ticksCount) {
377 while (count < m_ticksCount) {
378 if ((x < categories.count()) && (x >= 0)) {
378 if ((x < categories.count()) && (x >= 0)) {
379 labels << categories.at(x);
379 labels << categories.at(x);
380 } else {
380 } else {
381 // No label for x coordinate
381 // No label for x coordinate
382 labels << "";
382 labels << "";
383 }
383 }
384 x++;
384 x++;
385 count++;
385 count++;
386 }
386 }
387 }
387 }
388
388
389 #include "moc_chartaxis_p.cpp"
389 #include "moc_chartaxis_p.cpp"
390
390
391 QTCOMMERCIALCHART_END_NAMESPACE
391 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,606 +1,627
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.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QAbstractAxis
27 \class QAbstractAxis
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
28 \brief The QAbstractAxis class is used for manipulating chart's axis.
29 \mainclass
29 \mainclass
30
30
31 There is only one x Axis visible at the time, however there can be multiple y axes.
31 There is only one x Axis visible at the time, however there can be multiple y axes.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass AbstractAxis QAbstractAxis
37 \qmlclass AbstractAxis QAbstractAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43
43
44 To access Axes you can use ChartView API. For example:
44 To access Axes you can use ChartView API. For example:
45 \code
45 \code
46 ChartView {
46 ChartView {
47 axisX.min: 0
47 axisX.min: 0
48 axisX.max: 3
48 axisX.max: 3
49 axisX.ticksCount: 4
49 axisX.ticksCount: 4
50 axisY.min: 0
50 axisY.min: 0
51 axisY.max: 4
51 axisY.max: 4
52 // Add a few series...
52 // Add a few series...
53 }
53 }
54 \endcode
54 \endcode
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QAbstractAxis::AxisType
58 \enum QAbstractAxis::AxisType
59
59
60 The type of the series object.
60 The type of the series object.
61
61
62 \value AxisTypeNoAxis
62 \value AxisTypeNoAxis
63 \value AxisTypeValues
63 \value AxisTypeValues
64 \value AxisTypeCategories
64 \value AxisTypeCategories
65 */
65 */
66
66
67 /*!
67 /*!
68 *\fn void QAbstractAxis::type() const
68 *\fn void QAbstractAxis::type() const
69 Returns the type of the axis
69 Returns the type of the axis
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QAbstractAxis::arrowVisible
73 \property QAbstractAxis::arrowVisible
74 The visibility of the axis arrow
74 The visibility of the axis arrow
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty bool AbstractAxis::arrrowVisible
77 \qmlproperty bool AbstractAxis::arrrowVisible
78 The visibility of the axis arrow
78 The visibility of the axis arrow
79 */
79 */
80
80
81 /*!
81 /*!
82 \property QAbstractAxis::labelsVisible
82 \property QAbstractAxis::labelsVisible
83 Defines if axis labels are visible.
83 Defines if axis labels are visible.
84 */
84 */
85 /*!
85 /*!
86 \qmlproperty bool AbstractAxis::labelsVisible
86 \qmlproperty bool AbstractAxis::labelsVisible
87 Defines if axis labels are visible.
87 Defines if axis labels are visible.
88 */
88 */
89
89
90 /*!
90 /*!
91 \property QAbstractAxis::visible
91 \property QAbstractAxis::visible
92 The visibility of the axis.
92 The visibility of the axis.
93 */
93 */
94 /*!
94 /*!
95 \qmlproperty bool AbstractAxis::visible
95 \qmlproperty bool AbstractAxis::visible
96 The visibility of the axis.
96 The visibility of the axis.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QAbstractAxis::gridVisible
100 \property QAbstractAxis::gridVisible
101 The visibility of the grid lines.
101 The visibility of the grid lines.
102 */
102 */
103 /*!
103 /*!
104 \qmlproperty bool AbstractAxis::gridVisible
104 \qmlproperty bool AbstractAxis::gridVisible
105 The visibility of the grid lines.
105 The visibility of the grid lines.
106 */
106 */
107
107
108 /*!
108 /*!
109 \property QAbstractAxis::color
109 \property QAbstractAxis::color
110 The color of the axis and ticks.
110 The color of the axis and ticks.
111 */
111 */
112 /*!
112 /*!
113 \qmlproperty color AbstractAxis::color
113 \qmlproperty color AbstractAxis::color
114 The color of the axis and ticks.
114 The color of the axis and ticks.
115 */
115 */
116
116
117 /*!
117 /*!
118 \property QAbstractAxis::labelsFont
118 \property QAbstractAxis::labelsFont
119 The font of the axis labels.
119 The font of the axis labels.
120 */
120 */
121
121
122 /*!
122 /*!
123 \qmlproperty Font AbstractAxis::labelsFont
123 \qmlproperty Font AbstractAxis::labelsFont
124 The font of the axis labels.
124 The font of the axis labels.
125
125
126 See the \l {Font} {QML Font Element} for detailed documentation.
126 See the \l {Font} {QML Font Element} for detailed documentation.
127 */
127 */
128
128
129 /*!
129 /*!
130 \property QAbstractAxis::labelsColor
130 \property QAbstractAxis::labelsColor
131 The color of the axis labels.
131 The color of the axis labels.
132 */
132 */
133 /*!
133 /*!
134 \qmlproperty color AbstractAxis::labelsColor
134 \qmlproperty color AbstractAxis::labelsColor
135 The color of the axis labels.
135 The color of the axis labels.
136 */
136 */
137
137
138 /*!
138 /*!
139 \property QAbstractAxis::labelsAngle
139 \property QAbstractAxis::labelsAngle
140 The angle of the axis labels in degrees.
140 The angle of the axis labels in degrees.
141 */
141 */
142 /*!
142 /*!
143 \qmlproperty int AbstractAxis::labelsAngle
143 \qmlproperty int AbstractAxis::labelsAngle
144 The angle of the axis labels in degrees.
144 The angle of the axis labels in degrees.
145 */
145 */
146
146
147 /*!
147 /*!
148 \property QAbstractAxis::shadesVisible
148 \property QAbstractAxis::shadesVisible
149 The visibility of the axis shades.
149 The visibility of the axis shades.
150 */
150 */
151 /*!
151 /*!
152 \qmlproperty bool AbstractAxis::shadesVisible
152 \qmlproperty bool AbstractAxis::shadesVisible
153 The visibility of the axis shades.
153 The visibility of the axis shades.
154 */
154 */
155
155
156 /*!
156 /*!
157 \property QAbstractAxis::shadesColor
157 \property QAbstractAxis::shadesColor
158 The fill (brush) color of the axis shades.
158 The fill (brush) color of the axis shades.
159 */
159 */
160 /*!
160 /*!
161 \qmlproperty color AbstractAxis::shadesColor
161 \qmlproperty color AbstractAxis::shadesColor
162 The fill (brush) color of the axis shades.
162 The fill (brush) color of the axis shades.
163 */
163 */
164
164
165 /*!
165 /*!
166 \property QAbstractAxis::shadesBorderColor
166 \property QAbstractAxis::shadesBorderColor
167 The border (pen) color of the axis shades.
167 The border (pen) color of the axis shades.
168 */
168 */
169 /*!
169 /*!
170 \qmlproperty color AbstractAxis::shadesBorderColor
170 \qmlproperty color AbstractAxis::shadesBorderColor
171 The border (pen) color of the axis shades.
171 The border (pen) color of the axis shades.
172 */
172 */
173
173
174 /*!
174 /*!
175 \fn void QAbstractAxis::visibleChanged(bool)
175 \fn void QAbstractAxis::visibleChanged(bool visible)
176 Visiblity of the axis has changed to \a visible.
176 Visiblity of the axis has changed to \a visible.
177 */
177 */
178
179 /*!
178 /*!
180 \fn void QAbstractAxis::labelsVisibleChanged(bool)
179 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
181 Visiblity of the labels of the axis has changed to \a visible.
180 Visiblity of the axis has changed to \a visible.
182 */
181 */
183
182
184 /*!
183 /*!
185 \fn void QAbstractAxis::gridVisibleChanged(bool)
184 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
186 Visiblity of the grid lines of the axis has changed to \a visible.
185 Visiblity of the axis arrow has changed to \a visible.
187 */
186 */
188
187 /*!
189 /*
188 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
190 \fn void QAbstractAxis::minChanged(qreal min)
189 Visiblity of the axis arrow has changed to \a visible.
191 Axis emits signal when \a min of axis has changed.
192 */
190 */
193
191
194 /*
192 /*!
195 \fn void QAbstractAxis::maxChanged(qreal max)
193 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
196 Axis emits signal when \a max of axis has changed.
194 Visiblity of the labels of the axis has changed to \a visible.
197 */
195 */
198
196 /*!
199 /*
197 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
200 \fn void QAbstractAxis::rangeChanged(qreal min, qreal max)
198 Visiblity of the labels of the axis has changed to \a visible.
201 Axis emits signal when \a min or \a max of axis has changed.
202 */
199 */
203
200
204 /*
201 /*!
205 \fn QChartAxisCategories* QAbstractAxis::categories()
202 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
206 Returns pointer to the list of categories which correspond to the values on the axis.
203 Visiblity of the grid lines of the axis has changed to \a visible.
204 */
205 /*!
206 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
207 Visiblity of the grid lines of the axis has changed to \a visible.
207 */
208 */
208
209
209 /*!
210 /*!
210 \fn void QAbstractAxis::colorChanged(QColor)
211 \fn void QAbstractAxis::colorChanged(QColor color)
212 Emitted if the \a color of the axis is changed.
213 */
214 /*!
215 \qmlsignal AbstractAxis::onColorChanged(QColor color)
211 Emitted if the \a color of the axis is changed.
216 Emitted if the \a color of the axis is changed.
212 */
217 */
213
218
214 /*!
219 /*!
215 \fn void QAbstractAxis::labelsColorChanged(QColor)
220 \fn void QAbstractAxis::labelsColorChanged(QColor color)
221 Emitted if the \a color of the axis labels is changed.
222 */
223 /*!
224 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
216 Emitted if the \a color of the axis labels is changed.
225 Emitted if the \a color of the axis labels is changed.
217 */
226 */
218
227
219 /*!
228 /*!
220 \fn void QAbstractAxis::shadesVisibleChanged(bool)
229 \fn void QAbstractAxis::shadesVisibleChanged(bool)
221 Emitted if the visibility of the axis shades is changed to \a visible.
230 Emitted if the visibility of the axis shades is changed to \a visible.
222 */
231 */
232 /*!
233 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
234 Emitted if the visibility of the axis shades is changed to \a visible.
235 */
223
236
224 /*!
237 /*!
225 \fn void QAbstractAxis::shadesColorChanged(QColor)
238 \fn void QAbstractAxis::shadesColorChanged(QColor color)
239 Emitted if the \a color of the axis shades is changed.
240 */
241 /*!
242 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
226 Emitted if the \a color of the axis shades is changed.
243 Emitted if the \a color of the axis shades is changed.
227 */
244 */
228
245
229 /*!
246 /*!
230 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
247 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
231 Emitted if the border \a color of the axis shades is changed.
248 Emitted if the border \a color of the axis shades is changed.
232 */
249 */
250 /*!
251 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
252 Emitted if the border \a color of the axis shades is changed.
253 */
233
254
234 /*!
255 /*!
235 Constructs new axis object which is a child of \a parent. Ownership is taken by
256 Constructs new axis object which is a child of \a parent. Ownership is taken by
236 QChart when axis added.
257 QChart when axis added.
237 */
258 */
238
259
239 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
260 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
240 QObject(parent),
261 QObject(parent),
241 d_ptr(&d)
262 d_ptr(&d)
242 {
263 {
243 }
264 }
244
265
245 /*!
266 /*!
246 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
267 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
247 */
268 */
248
269
249 QAbstractAxis::~QAbstractAxis()
270 QAbstractAxis::~QAbstractAxis()
250 {
271 {
251 }
272 }
252
273
253 /*!
274 /*!
254 Sets \a pen used to draw axis line and ticks.
275 Sets \a pen used to draw axis line and ticks.
255 */
276 */
256 void QAbstractAxis::setAxisPen(const QPen &pen)
277 void QAbstractAxis::setAxisPen(const QPen &pen)
257 {
278 {
258 if (d_ptr->m_axisPen!=pen) {
279 if (d_ptr->m_axisPen!=pen) {
259 d_ptr->m_axisPen = pen;
280 d_ptr->m_axisPen = pen;
260 emit d_ptr->updated();
281 emit d_ptr->updated();
261 }
282 }
262 }
283 }
263
284
264 /*!
285 /*!
265 Returns pen used to draw axis and ticks.
286 Returns pen used to draw axis and ticks.
266 */
287 */
267 QPen QAbstractAxis::axisPen() const
288 QPen QAbstractAxis::axisPen() const
268 {
289 {
269 return d_ptr->m_axisPen;
290 return d_ptr->m_axisPen;
270 }
291 }
271
292
272 void QAbstractAxis::setAxisPenColor(QColor color)
293 void QAbstractAxis::setAxisPenColor(QColor color)
273 {
294 {
274 QPen p = d_ptr->m_axisPen;
295 QPen p = d_ptr->m_axisPen;
275 if (p.color() != color) {
296 if (p.color() != color) {
276 p.setColor(color);
297 p.setColor(color);
277 setAxisPen(p);
298 setAxisPen(p);
278 emit colorChanged(color);
299 emit colorChanged(color);
279 }
300 }
280 }
301 }
281
302
282 QColor QAbstractAxis::axisPenColor() const
303 QColor QAbstractAxis::axisPenColor() const
283 {
304 {
284 return d_ptr->m_axisPen.color();
305 return d_ptr->m_axisPen.color();
285 }
306 }
286
307
287 /*!
308 /*!
288 Sets if axis and ticks are \a visible.
309 Sets if axis and ticks are \a visible.
289 */
310 */
290 void QAbstractAxis::setAxisVisible(bool visible)
311 void QAbstractAxis::setArrowVisible(bool visible)
291 {
312 {
292 if (d_ptr->m_axisVisible != visible) {
313 if (d_ptr->m_arrowVisible != visible) {
293 d_ptr->m_axisVisible = visible;
314 d_ptr->m_arrowVisible = visible;
294 emit d_ptr->updated();
315 emit d_ptr->updated();
295 emit visibleChanged(visible);
316 emit arrowVisibleChanged(visible);
296 }
317 }
297 }
318 }
298
319
299 bool QAbstractAxis::isAxisVisible() const
320 bool QAbstractAxis::isArrowVisible() const
300 {
321 {
301 return d_ptr->m_axisVisible;
322 return d_ptr->m_arrowVisible;
302 }
323 }
303
324
304 void QAbstractAxis::setGridLineVisible(bool visible)
325 void QAbstractAxis::setGridLineVisible(bool visible)
305 {
326 {
306 if (d_ptr->m_gridLineVisible != visible) {
327 if (d_ptr->m_gridLineVisible != visible) {
307 d_ptr->m_gridLineVisible = visible;
328 d_ptr->m_gridLineVisible = visible;
308 emit d_ptr->updated();
329 emit d_ptr->updated();
309 emit gridVisibleChanged(visible);
330 emit gridVisibleChanged(visible);
310 }
331 }
311 }
332 }
312
333
313 bool QAbstractAxis::isGridLineVisible() const
334 bool QAbstractAxis::isGridLineVisible() const
314 {
335 {
315 return d_ptr->m_gridLineVisible;
336 return d_ptr->m_gridLineVisible;
316 }
337 }
317
338
318 /*!
339 /*!
319 Sets \a pen used to draw grid line.
340 Sets \a pen used to draw grid line.
320 */
341 */
321 void QAbstractAxis::setGridLinePen(const QPen &pen)
342 void QAbstractAxis::setGridLinePen(const QPen &pen)
322 {
343 {
323 if (d_ptr->m_gridLinePen != pen) {
344 if (d_ptr->m_gridLinePen != pen) {
324 d_ptr->m_gridLinePen = pen;
345 d_ptr->m_gridLinePen = pen;
325 emit d_ptr->updated();
346 emit d_ptr->updated();
326 }
347 }
327 }
348 }
328
349
329 /*!
350 /*!
330 Returns pen used to draw grid.
351 Returns pen used to draw grid.
331 */
352 */
332 QPen QAbstractAxis::gridLinePen() const
353 QPen QAbstractAxis::gridLinePen() const
333 {
354 {
334 return d_ptr->m_gridLinePen;
355 return d_ptr->m_gridLinePen;
335 }
356 }
336
357
337 void QAbstractAxis::setLabelsVisible(bool visible)
358 void QAbstractAxis::setLabelsVisible(bool visible)
338 {
359 {
339 if (d_ptr->m_labelsVisible != visible) {
360 if (d_ptr->m_labelsVisible != visible) {
340 d_ptr->m_labelsVisible = visible;
361 d_ptr->m_labelsVisible = visible;
341 emit d_ptr->updated();
362 emit d_ptr->updated();
342 emit labelsVisibleChanged(visible);
363 emit labelsVisibleChanged(visible);
343 }
364 }
344 }
365 }
345
366
346 bool QAbstractAxis::labelsVisible() const
367 bool QAbstractAxis::labelsVisible() const
347 {
368 {
348 return d_ptr->m_labelsVisible;
369 return d_ptr->m_labelsVisible;
349 }
370 }
350
371
351 /*!
372 /*!
352 Sets \a pen used to draw labels.
373 Sets \a pen used to draw labels.
353 */
374 */
354 void QAbstractAxis::setLabelsPen(const QPen &pen)
375 void QAbstractAxis::setLabelsPen(const QPen &pen)
355 {
376 {
356 if (d_ptr->m_labelsPen != pen) {
377 if (d_ptr->m_labelsPen != pen) {
357 d_ptr->m_labelsPen = pen;
378 d_ptr->m_labelsPen = pen;
358 emit d_ptr->updated();
379 emit d_ptr->updated();
359 }
380 }
360 }
381 }
361
382
362 /*!
383 /*!
363 Returns the pen used to labels.
384 Returns the pen used to labels.
364 */
385 */
365 QPen QAbstractAxis::labelsPen() const
386 QPen QAbstractAxis::labelsPen() const
366 {
387 {
367 return d_ptr->m_labelsPen;
388 return d_ptr->m_labelsPen;
368 }
389 }
369
390
370 /*!
391 /*!
371 Sets \a brush used to draw labels.
392 Sets \a brush used to draw labels.
372 */
393 */
373 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
394 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
374 {
395 {
375 if (d_ptr->m_labelsBrush != brush) {
396 if (d_ptr->m_labelsBrush != brush) {
376 d_ptr->m_labelsBrush = brush;
397 d_ptr->m_labelsBrush = brush;
377 emit d_ptr->updated();
398 emit d_ptr->updated();
378 }
399 }
379 }
400 }
380
401
381 /*!
402 /*!
382 Returns brush used to draw labels.
403 Returns brush used to draw labels.
383 */
404 */
384 QBrush QAbstractAxis::labelsBrush() const
405 QBrush QAbstractAxis::labelsBrush() const
385 {
406 {
386 return d_ptr->m_labelsBrush;
407 return d_ptr->m_labelsBrush;
387 }
408 }
388
409
389 /*!
410 /*!
390 Sets \a font used to draw labels.
411 Sets \a font used to draw labels.
391 */
412 */
392 void QAbstractAxis::setLabelsFont(const QFont &font)
413 void QAbstractAxis::setLabelsFont(const QFont &font)
393 {
414 {
394 if (d_ptr->m_labelsFont != font) {
415 if (d_ptr->m_labelsFont != font) {
395 d_ptr->m_labelsFont = font;
416 d_ptr->m_labelsFont = font;
396 emit d_ptr->updated();
417 emit d_ptr->updated();
397 }
418 }
398 }
419 }
399
420
400 /*!
421 /*!
401 Returns font used to draw labels.
422 Returns font used to draw labels.
402 */
423 */
403 QFont QAbstractAxis::labelsFont() const
424 QFont QAbstractAxis::labelsFont() const
404 {
425 {
405 return d_ptr->m_labelsFont;
426 return d_ptr->m_labelsFont;
406 }
427 }
407
428
408 void QAbstractAxis::setLabelsAngle(int angle)
429 void QAbstractAxis::setLabelsAngle(int angle)
409 {
430 {
410 if (d_ptr->m_labelsAngle != angle) {
431 if (d_ptr->m_labelsAngle != angle) {
411 d_ptr->m_labelsAngle = angle;
432 d_ptr->m_labelsAngle = angle;
412 emit d_ptr->updated();
433 emit d_ptr->updated();
413 }
434 }
414 }
435 }
415
436
416 int QAbstractAxis::labelsAngle() const
437 int QAbstractAxis::labelsAngle() const
417 {
438 {
418 return d_ptr->m_labelsAngle;
439 return d_ptr->m_labelsAngle;
419 }
440 }
420
441
421 void QAbstractAxis::setLabelsColor(QColor color)
442 void QAbstractAxis::setLabelsColor(QColor color)
422 {
443 {
423 QBrush b = d_ptr->m_labelsBrush;
444 QBrush b = d_ptr->m_labelsBrush;
424 if (b.color() != color) {
445 if (b.color() != color) {
425 b.setColor(color);
446 b.setColor(color);
426 setLabelsBrush(b);
447 setLabelsBrush(b);
427 emit labelsColorChanged(color);
448 emit labelsColorChanged(color);
428 }
449 }
429 }
450 }
430
451
431 QColor QAbstractAxis::labelsColor() const
452 QColor QAbstractAxis::labelsColor() const
432 {
453 {
433 return d_ptr->m_labelsBrush.color();
454 return d_ptr->m_labelsBrush.color();
434 }
455 }
435
456
436 void QAbstractAxis::setShadesVisible(bool visible)
457 void QAbstractAxis::setShadesVisible(bool visible)
437 {
458 {
438 if (d_ptr->m_shadesVisible != visible) {
459 if (d_ptr->m_shadesVisible != visible) {
439 d_ptr->m_shadesVisible = visible;
460 d_ptr->m_shadesVisible = visible;
440 emit d_ptr->updated();
461 emit d_ptr->updated();
441 emit shadesVisibleChanged(visible);
462 emit shadesVisibleChanged(visible);
442 }
463 }
443 }
464 }
444
465
445 bool QAbstractAxis::shadesVisible() const
466 bool QAbstractAxis::shadesVisible() const
446 {
467 {
447 return d_ptr->m_shadesVisible;
468 return d_ptr->m_shadesVisible;
448 }
469 }
449
470
450 /*!
471 /*!
451 Sets \a pen used to draw shades.
472 Sets \a pen used to draw shades.
452 */
473 */
453 void QAbstractAxis::setShadesPen(const QPen &pen)
474 void QAbstractAxis::setShadesPen(const QPen &pen)
454 {
475 {
455 if (d_ptr->m_shadesPen != pen) {
476 if (d_ptr->m_shadesPen != pen) {
456 d_ptr->m_shadesPen = pen;
477 d_ptr->m_shadesPen = pen;
457 emit d_ptr->updated();
478 emit d_ptr->updated();
458 }
479 }
459 }
480 }
460
481
461 /*!
482 /*!
462 Returns pen used to draw shades.
483 Returns pen used to draw shades.
463 */
484 */
464 QPen QAbstractAxis::shadesPen() const
485 QPen QAbstractAxis::shadesPen() const
465 {
486 {
466 return d_ptr->m_shadesPen;
487 return d_ptr->m_shadesPen;
467 }
488 }
468
489
469 /*!
490 /*!
470 Sets \a brush used to draw shades.
491 Sets \a brush used to draw shades.
471 */
492 */
472 void QAbstractAxis::setShadesBrush(const QBrush &brush)
493 void QAbstractAxis::setShadesBrush(const QBrush &brush)
473 {
494 {
474 if (d_ptr->m_shadesBrush != brush) {
495 if (d_ptr->m_shadesBrush != brush) {
475 d_ptr->m_shadesBrush = brush;
496 d_ptr->m_shadesBrush = brush;
476 emit d_ptr->updated();
497 emit d_ptr->updated();
477 emit shadesColorChanged(brush.color());
498 emit shadesColorChanged(brush.color());
478 }
499 }
479 }
500 }
480
501
481 /*!
502 /*!
482 Returns brush used to draw shades.
503 Returns brush used to draw shades.
483 */
504 */
484 QBrush QAbstractAxis::shadesBrush() const
505 QBrush QAbstractAxis::shadesBrush() const
485 {
506 {
486 return d_ptr->m_shadesBrush;
507 return d_ptr->m_shadesBrush;
487 }
508 }
488
509
489 void QAbstractAxis::setShadesColor(QColor color)
510 void QAbstractAxis::setShadesColor(QColor color)
490 {
511 {
491 QBrush b = d_ptr->m_shadesBrush;
512 QBrush b = d_ptr->m_shadesBrush;
492 b.setColor(color);
513 b.setColor(color);
493 setShadesBrush(b);
514 setShadesBrush(b);
494 }
515 }
495
516
496 QColor QAbstractAxis::shadesColor() const
517 QColor QAbstractAxis::shadesColor() const
497 {
518 {
498 return d_ptr->m_shadesBrush.color();
519 return d_ptr->m_shadesBrush.color();
499 }
520 }
500
521
501 void QAbstractAxis::setShadesBorderColor(QColor color)
522 void QAbstractAxis::setShadesBorderColor(QColor color)
502 {
523 {
503 QPen p = d_ptr->m_shadesPen;
524 QPen p = d_ptr->m_shadesPen;
504 p.setColor(color);
525 p.setColor(color);
505 setShadesPen(p);
526 setShadesPen(p);
506 }
527 }
507
528
508 QColor QAbstractAxis::shadesBorderColor() const
529 QColor QAbstractAxis::shadesBorderColor() const
509 {
530 {
510 return d_ptr->m_shadesPen.color();
531 return d_ptr->m_shadesPen.color();
511 }
532 }
512
533
513
534
514 bool QAbstractAxis::isVisible() const
535 bool QAbstractAxis::isVisible() const
515 {
536 {
516 return d_ptr->m_visible;
537 return d_ptr->m_visible;
517 }
538 }
518
539
519 /*!
540 /*!
520 Sets axis, shades, labels and grid lines to be visible.
541 Sets axis, shades, labels and grid lines to be visible.
521 */
542 */
522 void QAbstractAxis::setVisible(bool visible)
543 void QAbstractAxis::setVisible(bool visible)
523 {
544 {
524 if(d_ptr->m_visible!=visible){
545 if(d_ptr->m_visible!=visible){
525 d_ptr->m_visible=visible;
546 d_ptr->m_visible=visible;
526 emit visibleChanged(visible);
547 emit visibleChanged(visible);
527 emit d_ptr->updated();
548 emit d_ptr->updated();
528 }
549 }
529 }
550 }
530
551
531
552
532 /*!
553 /*!
533 Sets axis, shades, labels and grid lines to be visible.
554 Sets axis, shades, labels and grid lines to be visible.
534 */
555 */
535 void QAbstractAxis::show()
556 void QAbstractAxis::show()
536 {
557 {
537 setVisible(true);
558 setVisible(true);
538 }
559 }
539
560
540 /*!
561 /*!
541 Sets axis, shades, labels and grid lines to not be visible.
562 Sets axis, shades, labels and grid lines to not be visible.
542 */
563 */
543 void QAbstractAxis::hide()
564 void QAbstractAxis::hide()
544 {
565 {
545 setVisible(false);
566 setVisible(false);
546 }
567 }
547
568
548 /*!
569 /*!
549 Sets the minimum value shown on the axis.
570 Sets the minimum value shown on the axis.
550 Depending on the actual axis type the \a min paramter is converted to appropriate type.
571 Depending on the actual axis type the \a min paramter is converted to appropriate type.
551 If the conversion is impossible then the function call does nothing
572 If the conversion is impossible then the function call does nothing
552 */
573 */
553 void QAbstractAxis::setMin(const QVariant &min)
574 void QAbstractAxis::setMin(const QVariant &min)
554 {
575 {
555 d_ptr->setMin(min);
576 d_ptr->setMin(min);
556 }
577 }
557
578
558 /*!
579 /*!
559 Sets the maximum value shown on the axis.
580 Sets the maximum value shown on the axis.
560 Depending on the actual axis type the \a max paramter is converted to appropriate type.
581 Depending on the actual axis type the \a max paramter is converted to appropriate type.
561 If the conversion is impossible then the function call does nothing
582 If the conversion is impossible then the function call does nothing
562 */
583 */
563 void QAbstractAxis::setMax(const QVariant &max)
584 void QAbstractAxis::setMax(const QVariant &max)
564 {
585 {
565 d_ptr->setMax(max);
586 d_ptr->setMax(max);
566 }
587 }
567
588
568 /*!
589 /*!
569 Sets the range shown on the axis.
590 Sets the range shown on the axis.
570 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
591 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
571 If the conversion is impossible then the function call does nothing.
592 If the conversion is impossible then the function call does nothing.
572 */
593 */
573 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
594 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
574 {
595 {
575 d_ptr->setRange(min,max);
596 d_ptr->setRange(min,max);
576 }
597 }
577
598
578 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
599 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
579
600
580 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
601 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
581 q_ptr(q),
602 q_ptr(q),
582 m_visible(false),
603 m_visible(false),
583 m_axisVisible(true),
604 m_arrowVisible(true),
584 m_gridLineVisible(true),
605 m_gridLineVisible(true),
585 m_labelsVisible(true),
606 m_labelsVisible(true),
586 m_labelsAngle(0),
607 m_labelsAngle(0),
587 m_shadesVisible(false),
608 m_shadesVisible(false),
588 m_shadesBrush(Qt::SolidPattern),
609 m_shadesBrush(Qt::SolidPattern),
589 m_shadesOpacity(1.0),
610 m_shadesOpacity(1.0),
590 m_orientation(Qt::Orientation(0)),
611 m_orientation(Qt::Orientation(0)),
591 m_min(0),
612 m_min(0),
592 m_max(0),
613 m_max(0),
593 m_ticksCount(5)
614 m_ticksCount(5)
594 {
615 {
595
616
596 }
617 }
597
618
598 QAbstractAxisPrivate::~QAbstractAxisPrivate()
619 QAbstractAxisPrivate::~QAbstractAxisPrivate()
599 {
620 {
600
621
601 }
622 }
602
623
603 #include "moc_qabstractaxis.cpp"
624 #include "moc_qabstractaxis.cpp"
604 #include "moc_qabstractaxis_p.cpp"
625 #include "moc_qabstractaxis_p.cpp"
605
626
606 QTCOMMERCIALCHART_END_NAMESPACE
627 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,139 +1,139
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 QABSTRACTAXIS_H
21 #ifndef QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QFont>
26 #include <QFont>
27 #include <QVariant>
27 #include <QVariant>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAbstractAxisPrivate;
31 class QAbstractAxisPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
47
47
48 public:
48 public:
49
49
50 enum AxisType {
50 enum AxisType {
51 AxisTypeNoAxis = 0x0,
51 AxisTypeNoAxis = 0x0,
52 AxisTypeValues = 0x1,
52 AxisTypeValues = 0x1,
53 AxisTypeCategories = 0x2
53 AxisTypeCategories = 0x2
54 };
54 };
55
55
56 Q_DECLARE_FLAGS(AxisTypes, AxisType)
56 Q_DECLARE_FLAGS(AxisTypes, AxisType)
57
57
58 protected:
58 protected:
59 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
59 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
60
60
61 public:
61 public:
62 ~QAbstractAxis();
62 ~QAbstractAxis();
63
63
64 virtual AxisType type() const = 0;
64 virtual AxisType type() const = 0;
65
65
66 //visibilty hadnling
66 //visibilty hadnling
67 bool isVisible() const;
67 bool isVisible() const;
68 void setVisible(bool visible = true);
68 void setVisible(bool visible = true);
69
69
70
70
71 //axis handling
71 //axis handling
72 bool isAxisVisible() const;
72 bool isArrowVisible() const;
73 void setAxisVisible(bool visible = true);
73 void setArrowVisible(bool visible = true);
74 void setAxisPen(const QPen &pen);
74 void setAxisPen(const QPen &pen);
75 QPen axisPen() const;
75 QPen axisPen() const;
76 void setAxisPenColor(QColor color);
76 void setAxisPenColor(QColor color);
77 QColor axisPenColor() const;
77 QColor axisPenColor() const;
78
78
79 //grid handling
79 //grid handling
80 bool isGridLineVisible() const;
80 bool isGridLineVisible() const;
81 void setGridLineVisible(bool visible = true);
81 void setGridLineVisible(bool visible = true);
82 void setGridLinePen(const QPen &pen);
82 void setGridLinePen(const QPen &pen);
83 QPen gridLinePen() const;
83 QPen gridLinePen() const;
84
84
85 //labels handling
85 //labels handling
86 bool labelsVisible() const;
86 bool labelsVisible() const;
87 void setLabelsVisible(bool visible = true);
87 void setLabelsVisible(bool visible = true);
88 void setLabelsPen(const QPen &pen);
88 void setLabelsPen(const QPen &pen);
89 QPen labelsPen() const;
89 QPen labelsPen() const;
90 void setLabelsBrush(const QBrush &brush);
90 void setLabelsBrush(const QBrush &brush);
91 QBrush labelsBrush() const;
91 QBrush labelsBrush() const;
92 void setLabelsFont(const QFont &font);
92 void setLabelsFont(const QFont &font);
93 QFont labelsFont() const;
93 QFont labelsFont() const;
94 void setLabelsAngle(int angle);
94 void setLabelsAngle(int angle);
95 int labelsAngle() const;
95 int labelsAngle() const;
96 void setLabelsColor(QColor color);
96 void setLabelsColor(QColor color);
97 QColor labelsColor() const;
97 QColor labelsColor() const;
98
98
99 //shades handling
99 //shades handling
100 bool shadesVisible() const;
100 bool shadesVisible() const;
101 void setShadesVisible(bool visible = true);
101 void setShadesVisible(bool visible = true);
102 void setShadesPen(const QPen &pen);
102 void setShadesPen(const QPen &pen);
103 QPen shadesPen() const;
103 QPen shadesPen() const;
104 void setShadesBrush(const QBrush &brush);
104 void setShadesBrush(const QBrush &brush);
105 QBrush shadesBrush() const;
105 QBrush shadesBrush() const;
106 void setShadesColor(QColor color);
106 void setShadesColor(QColor color);
107 QColor shadesColor() const;
107 QColor shadesColor() const;
108 void setShadesBorderColor(QColor color);
108 void setShadesBorderColor(QColor color);
109 QColor shadesBorderColor() const;
109 QColor shadesBorderColor() const;
110
110
111 //range handling
111 //range handling
112 void setMin(const QVariant &min);
112 void setMin(const QVariant &min);
113 void setMax(const QVariant &max);
113 void setMax(const QVariant &max);
114 void setRange(const QVariant &min, const QVariant &max);
114 void setRange(const QVariant &min, const QVariant &max);
115
115
116 void show();
116 void show();
117 void hide();
117 void hide();
118
118
119 Q_SIGNALS:
119 Q_SIGNALS:
120 void visibleChanged(bool visible);
120 void visibleChanged(bool visible);
121 void axisVisibleChanged(bool visible);
121 void arrowVisibleChanged(bool visible);
122 void labelsVisibleChanged(bool visible);
122 void labelsVisibleChanged(bool visible);
123 void gridVisibleChanged(bool visible);
123 void gridVisibleChanged(bool visible);
124 void colorChanged(QColor color);
124 void colorChanged(QColor color);
125 void labelsColorChanged(QColor color);
125 void labelsColorChanged(QColor color);
126 void shadesVisibleChanged(bool visible);
126 void shadesVisibleChanged(bool visible);
127 void shadesColorChanged(QColor color);
127 void shadesColorChanged(QColor color);
128 void shadesBorderColorChanged(QColor color);
128 void shadesBorderColorChanged(QColor color);
129
129
130 protected:
130 protected:
131 QScopedPointer<QAbstractAxisPrivate> d_ptr;
131 QScopedPointer<QAbstractAxisPrivate> d_ptr;
132 Q_DISABLE_COPY(QAbstractAxis);
132 Q_DISABLE_COPY(QAbstractAxis);
133 friend class ChartDataSet;
133 friend class ChartDataSet;
134 friend class ChartAxis;
134 friend class ChartAxis;
135 friend class ChartPresenter;
135 friend class ChartPresenter;
136 };
136 };
137
137
138 QTCOMMERCIALCHART_END_NAMESPACE
138 QTCOMMERCIALCHART_END_NAMESPACE
139 #endif
139 #endif
@@ -1,94 +1,94
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 QABSTRACTAXIS_P_H
30 #ifndef QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
32
32
33 #include "qabstractaxis.h"
33 #include "qabstractaxis.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class ChartPresenter;
37 class ChartPresenter;
38 class ChartAxis;
38 class ChartAxis;
39
39
40 class QAbstractAxisPrivate : public QObject
40 class QAbstractAxisPrivate : public QObject
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 QAbstractAxisPrivate(QAbstractAxis *q);
44 QAbstractAxisPrivate(QAbstractAxis *q);
45 ~QAbstractAxisPrivate();
45 ~QAbstractAxisPrivate();
46
46
47 Q_SIGNALS:
47 Q_SIGNALS:
48 void updated();
48 void updated();
49
49
50 public:
50 public:
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
52 virtual void emitRange() = 0;
52 virtual void emitRange() = 0;
53
53
54 protected:
54 protected:
55 virtual void setMin(const QVariant &min) = 0;
55 virtual void setMin(const QVariant &min) = 0;
56 virtual void setMax(const QVariant &max) = 0;
56 virtual void setMax(const QVariant &max) = 0;
57 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
57 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
58 virtual int ticksCount() const = 0;
58 virtual int ticksCount() const = 0;
59
59
60 public:
60 public:
61 QAbstractAxis *q_ptr;
61 QAbstractAxis *q_ptr;
62 bool m_visible;
62 bool m_visible;
63
63
64 bool m_axisVisible;
64 bool m_arrowVisible;
65 QPen m_axisPen;
65 QPen m_axisPen;
66 QBrush m_axisBrush;
66 QBrush m_axisBrush;
67
67
68 bool m_gridLineVisible;
68 bool m_gridLineVisible;
69 QPen m_gridLinePen;
69 QPen m_gridLinePen;
70
70
71 bool m_labelsVisible;
71 bool m_labelsVisible;
72 QPen m_labelsPen;
72 QPen m_labelsPen;
73 QBrush m_labelsBrush;
73 QBrush m_labelsBrush;
74 QFont m_labelsFont;
74 QFont m_labelsFont;
75 int m_labelsAngle;
75 int m_labelsAngle;
76
76
77 bool m_shadesVisible;
77 bool m_shadesVisible;
78 QPen m_shadesPen;
78 QPen m_shadesPen;
79 QBrush m_shadesBrush;
79 QBrush m_shadesBrush;
80 qreal m_shadesOpacity;
80 qreal m_shadesOpacity;
81
81
82 Qt::Orientation m_orientation;
82 Qt::Orientation m_orientation;
83
83
84 // range
84 // range
85 qreal m_min;
85 qreal m_min;
86 qreal m_max;
86 qreal m_max;
87 int m_ticksCount;
87 int m_ticksCount;
88
88
89 friend class QAbstractAxis;
89 friend class QAbstractAxis;
90 };
90 };
91
91
92 QTCOMMERCIALCHART_END_NAMESPACE
92 QTCOMMERCIALCHART_END_NAMESPACE
93
93
94 #endif
94 #endif
@@ -1,381 +1,389
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarcategoriesaxis.h"
21 #include "qbarcategoriesaxis.h"
22 #include "qbarcategoriesaxis_p.h"
22 #include "qbarcategoriesaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
29 /*!
30 \class QBarCategoriesAxis
30 \class QBarCategoriesAxis
31 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
31 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
32 \mainclass
32 \mainclass
33
33
34 BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades.
34 BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades.
35 Categories are drawn between ticks. Note that you can use this also with lineseries too.
35 Categories are drawn between ticks. Note that you can use this also with lineseries too.
36 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
36 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
37 */
37 */
38
38
39 /*!
39 /*!
40 \qmlclass BarCategoriesAxis QBarCategoriesAxis
40 \qmlclass BarCategoriesAxis QBarCategoriesAxis
41 \brief The Axis element is used for manipulating chart's axes.
41 \brief The Axis element is used for manipulating chart's axes.
42
42
43 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 Axis can be setup to show axis line with tick marks, grid lines and shades.
44 Categories are drawn between ticks. Note that you can use this also with lineseries too.
44 Categories are drawn between ticks. Note that you can use this also with lineseries too.
45
45
46 To access BarCategoriesAxis you can use ChartView API. For example:
46 To access BarCategoriesAxis you can use ChartView API. For example:
47 \code
47 \code
48 ChartView {
48 ChartView {
49 BarCategoriesAxis {
49 BarCategoriesAxis {
50 id: categoryAxis
50 id: categoryAxis
51 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
51 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
52 }
52 }
53 // Add a few series...
53 // Add a few series...
54 }
54 }
55 \endcode
55 \endcode
56 */
56 */
57
57
58 /*!
58 /*!
59 \property QBarCategoriesAxis::categories
59 \property QBarCategoriesAxis::categories
60 Defines the categories of axis
60 Defines the categories of axis
61 */
61 */
62 /*!
62 /*!
63 \qmlproperty QStringList BarCategoriesAxis::categories
63 \qmlproperty QStringList BarCategoriesAxis::categories
64 Defines the categories of axis
64 Defines the categories of axis
65 */
65 */
66
66
67 /*!
67 /*!
68 \property QBarCategoriesAxis::min
68 \property QBarCategoriesAxis::min
69 Defines the minimum value on the axis.
69 Defines the minimum value on the axis.
70 */
70 */
71 /*!
71 /*!
72 \qmlproperty real BarCategoriesAxis::min
72 \qmlproperty QString BarCategoriesAxis::min
73 Defines the minimum value on the axis.
73 Defines the minimum value on the axis.
74 */
74 */
75
75
76 /*!
76 /*!
77 \property QBarCategoriesAxis::max
77 \property QBarCategoriesAxis::max
78 Defines the maximum value on the axis.
78 Defines the maximum value on the axis.
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty real BarCategoriesAxis::max
81 \qmlproperty QString BarCategoriesAxis::max
82 Defines the maximum value on the axis.
82 Defines the maximum value on the axis.
83 */
83 */
84
84
85 /*!
85 /*!
86 \fn void QBarCategoriesAxis::minChanged(const QString &min)
86 \fn void QBarCategoriesAxis::minChanged(const QString &min)
87 Axis emits signal when \a min of axis has changed.
87 Axis emits signal when \a min of axis has changed.
88 */
88 */
89 /*!
90 \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min)
91 Axis emits signal when \a min of axis has changed.
92 */
89
93
90 /*!
94 /*!
91 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
95 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
92 Axis emits signal when \a max of axis has changed.
96 Axis emits signal when \a max of axis has changed.
93 */
97 */
98 /*!
99 \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max)
100 Axis emits signal when \a max of axis has changed.
101 */
94
102
95 /*!
103 /*!
96 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
104 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
97 Axis emits signal when \a min or \a max of axis has changed.
105 Axis emits signal when \a min or \a max of axis has changed.
98 */
106 */
99
107
100 /*!
108 /*!
101 Constructs an axis object which is a child of \a parent.
109 Constructs an axis object which is a child of \a parent.
102 */
110 */
103 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
111 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
104 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
112 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
105 {
113 {
106 }
114 }
107
115
108 /*!
116 /*!
109 Destroys the object
117 Destroys the object
110 */
118 */
111 QBarCategoriesAxis::~QBarCategoriesAxis()
119 QBarCategoriesAxis::~QBarCategoriesAxis()
112 {
120 {
113 }
121 }
114
122
115 /*!
123 /*!
116 \internal
124 \internal
117 */
125 */
118 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
126 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
119 {
127 {
120
128
121 }
129 }
122
130
123 /*!
131 /*!
124 Appends \a categories to axis
132 Appends \a categories to axis
125 */
133 */
126 void QBarCategoriesAxis::append(const QStringList &categories)
134 void QBarCategoriesAxis::append(const QStringList &categories)
127 {
135 {
128 if(categories.isEmpty()) return;
136 if(categories.isEmpty()) return;
129
137
130 Q_D(QBarCategoriesAxis);
138 Q_D(QBarCategoriesAxis);
131 if (d->m_categories.isEmpty()) {
139 if (d->m_categories.isEmpty()) {
132 d->m_categories.append(categories);
140 d->m_categories.append(categories);
133 setRange(categories.first(),categories.last());
141 setRange(categories.first(),categories.last());
134 }else{
142 }else{
135 d->m_categories.append(categories);
143 d->m_categories.append(categories);
136 }
144 }
137 emit d->updated();
145 emit d->updated();
138 emit categoriesChanged();
146 emit categoriesChanged();
139 }
147 }
140
148
141 /*!
149 /*!
142 Appends \a category to axis
150 Appends \a category to axis
143 */
151 */
144 void QBarCategoriesAxis::append(const QString &category)
152 void QBarCategoriesAxis::append(const QString &category)
145 {
153 {
146 Q_D(QBarCategoriesAxis);
154 Q_D(QBarCategoriesAxis);
147 if (d->m_categories.isEmpty()) {
155 if (d->m_categories.isEmpty()) {
148 d->m_categories.append(category);
156 d->m_categories.append(category);
149 setRange(category,category);
157 setRange(category,category);
150 }else{
158 }else{
151 d->m_categories.append(category);
159 d->m_categories.append(category);
152 }
160 }
153 emit d->updated();
161 emit d->updated();
154 emit categoriesChanged();
162 emit categoriesChanged();
155 }
163 }
156
164
157 /*!
165 /*!
158 Removes \a category from axis
166 Removes \a category from axis
159 */
167 */
160 void QBarCategoriesAxis::remove(const QString &category)
168 void QBarCategoriesAxis::remove(const QString &category)
161 {
169 {
162 Q_D(QBarCategoriesAxis);
170 Q_D(QBarCategoriesAxis);
163 if (d->m_categories.contains(category)) {
171 if (d->m_categories.contains(category)) {
164 d->m_categories.removeAt(d->m_categories.indexOf(category));
172 d->m_categories.removeAt(d->m_categories.indexOf(category));
165 setRange(d->m_categories.first(),d->m_categories.last());
173 setRange(d->m_categories.first(),d->m_categories.last());
166 emit d->updated();
174 emit d->updated();
167 emit categoriesChanged();
175 emit categoriesChanged();
168 }
176 }
169 }
177 }
170
178
171 /*!
179 /*!
172 Inserts \a category to axis at \a index
180 Inserts \a category to axis at \a index
173 */
181 */
174 void QBarCategoriesAxis::insert(int index, const QString &category)
182 void QBarCategoriesAxis::insert(int index, const QString &category)
175 {
183 {
176 Q_D(QBarCategoriesAxis);
184 Q_D(QBarCategoriesAxis);
177 if (d->m_categories.isEmpty()) {
185 if (d->m_categories.isEmpty()) {
178 d->m_categories.insert(index,category);
186 d->m_categories.insert(index,category);
179 setRange(category,category);
187 setRange(category,category);
180 }else{
188 }else{
181 d->m_categories.insert(index,category);
189 d->m_categories.insert(index,category);
182 }
190 }
183 emit d->updated();
191 emit d->updated();
184 emit categoriesChanged();
192 emit categoriesChanged();
185 }
193 }
186
194
187 /*!
195 /*!
188 Removes all categories.
196 Removes all categories.
189 */
197 */
190 void QBarCategoriesAxis::clear()
198 void QBarCategoriesAxis::clear()
191 {
199 {
192 Q_D(QBarCategoriesAxis);
200 Q_D(QBarCategoriesAxis);
193 d->m_categories.clear();
201 d->m_categories.clear();
194 setRange(QString::null,QString::null);
202 setRange(QString::null,QString::null);
195 emit d->updated();
203 emit d->updated();
196 emit categoriesChanged();
204 emit categoriesChanged();
197 }
205 }
198
206
199 void QBarCategoriesAxis::setCategories(const QStringList &categories)
207 void QBarCategoriesAxis::setCategories(const QStringList &categories)
200 {
208 {
201 Q_D(QBarCategoriesAxis);
209 Q_D(QBarCategoriesAxis);
202 if(d->m_categories!=categories){
210 if(d->m_categories!=categories){
203 d->m_categories = categories;
211 d->m_categories = categories;
204 setRange(categories.first(),categories.last());
212 setRange(categories.first(),categories.last());
205 emit d->updated();
213 emit d->updated();
206 emit categoriesChanged();
214 emit categoriesChanged();
207 }
215 }
208 }
216 }
209
217
210 QStringList QBarCategoriesAxis::categories()
218 QStringList QBarCategoriesAxis::categories()
211 {
219 {
212 Q_D(QBarCategoriesAxis);
220 Q_D(QBarCategoriesAxis);
213 return d->m_categories;
221 return d->m_categories;
214 }
222 }
215
223
216 /*!
224 /*!
217 Returns number of categories.
225 Returns number of categories.
218 */
226 */
219 int QBarCategoriesAxis::count() const
227 int QBarCategoriesAxis::count() const
220 {
228 {
221 Q_D(const QBarCategoriesAxis);
229 Q_D(const QBarCategoriesAxis);
222 return d->m_categories.count();
230 return d->m_categories.count();
223 }
231 }
224
232
225 /*!
233 /*!
226 Returns category at \a index. Index must be valid.
234 Returns category at \a index. Index must be valid.
227 */
235 */
228 QString QBarCategoriesAxis::at(int index) const
236 QString QBarCategoriesAxis::at(int index) const
229 {
237 {
230 Q_D(const QBarCategoriesAxis);
238 Q_D(const QBarCategoriesAxis);
231 return d->m_categories.at(index);
239 return d->m_categories.at(index);
232 }
240 }
233
241
234 /*!
242 /*!
235 Sets minimum category to \a min.
243 Sets minimum category to \a min.
236 */
244 */
237 void QBarCategoriesAxis::setMin(const QString& min)
245 void QBarCategoriesAxis::setMin(const QString& min)
238 {
246 {
239 Q_D(QBarCategoriesAxis);
247 Q_D(QBarCategoriesAxis);
240 setRange(min,d->m_maxCategory);
248 setRange(min,d->m_maxCategory);
241 }
249 }
242
250
243 /*!
251 /*!
244 Returns minimum category.
252 Returns minimum category.
245 */
253 */
246 QString QBarCategoriesAxis::min() const
254 QString QBarCategoriesAxis::min() const
247 {
255 {
248 Q_D(const QBarCategoriesAxis);
256 Q_D(const QBarCategoriesAxis);
249 return d->m_minCategory;
257 return d->m_minCategory;
250 }
258 }
251
259
252 /*!
260 /*!
253 Sets maximum category to \a max.
261 Sets maximum category to \a max.
254 */
262 */
255 void QBarCategoriesAxis::setMax(const QString& max)
263 void QBarCategoriesAxis::setMax(const QString& max)
256 {
264 {
257 Q_D(QBarCategoriesAxis);
265 Q_D(QBarCategoriesAxis);
258 setRange(d->m_minCategory,max);
266 setRange(d->m_minCategory,max);
259 }
267 }
260
268
261 /*!
269 /*!
262 Returns maximum category
270 Returns maximum category
263 */
271 */
264 QString QBarCategoriesAxis::max() const
272 QString QBarCategoriesAxis::max() const
265 {
273 {
266 Q_D(const QBarCategoriesAxis);
274 Q_D(const QBarCategoriesAxis);
267 return d->m_maxCategory;
275 return d->m_maxCategory;
268 }
276 }
269
277
270 /*!
278 /*!
271 Sets range from \a minCategory to \a maxCategory
279 Sets range from \a minCategory to \a maxCategory
272 */
280 */
273 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
281 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
274 {
282 {
275 Q_D(QBarCategoriesAxis);
283 Q_D(QBarCategoriesAxis);
276
284
277 int minIndex = d->m_categories.indexOf(minCategory);
285 int minIndex = d->m_categories.indexOf(minCategory);
278 if (minIndex == -1) {
286 if (minIndex == -1) {
279 return;
287 return;
280 }
288 }
281 int maxIndex = d->m_categories.indexOf(maxCategory);
289 int maxIndex = d->m_categories.indexOf(maxCategory);
282 if (maxIndex == -1) {
290 if (maxIndex == -1) {
283 return;
291 return;
284 }
292 }
285
293
286 if (maxIndex <= minIndex) {
294 if (maxIndex <= minIndex) {
287 // max must be greater than min
295 // max must be greater than min
288 return;
296 return;
289 }
297 }
290
298
291 bool changed = false;
299 bool changed = false;
292 if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) {
300 if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) {
293 d->m_minCategory = minCategory;
301 d->m_minCategory = minCategory;
294 d->m_min = minIndex;
302 d->m_min = minIndex;
295 emit minChanged(minCategory);
303 emit minChanged(minCategory);
296 changed = true;
304 changed = true;
297 }
305 }
298
306
299 if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) {
307 if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) {
300 d->m_max = maxIndex;
308 d->m_max = maxIndex;
301 d->m_maxCategory = maxCategory;
309 d->m_maxCategory = maxCategory;
302 emit maxChanged(maxCategory);
310 emit maxChanged(maxCategory);
303 changed = true;
311 changed = true;
304 }
312 }
305
313
306 if (changed) {
314 if (changed) {
307 d->emitRange();
315 d->emitRange();
308 }
316 }
309 }
317 }
310
318
311 /*!
319 /*!
312 Returns the type of the axis
320 Returns the type of the axis
313 */
321 */
314 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
322 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
315 {
323 {
316 return AxisTypeCategories;
324 return AxisTypeCategories;
317 }
325 }
318
326
319 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
327 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
320
328
321 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
329 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
322 QAbstractAxisPrivate(q)
330 QAbstractAxisPrivate(q)
323 {
331 {
324
332
325 }
333 }
326
334
327 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
335 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
328 {
336 {
329
337
330 }
338 }
331
339
332 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
340 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
333 {
341 {
334 setRange(min,m_maxCategory);
342 setRange(min,m_maxCategory);
335 }
343 }
336
344
337 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
345 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
338 {
346 {
339 setRange(m_minCategory,max);
347 setRange(m_minCategory,max);
340 }
348 }
341
349
342 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
350 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
343 {
351 {
344 Q_Q(QBarCategoriesAxis);
352 Q_Q(QBarCategoriesAxis);
345 QString value1 = min.toString();
353 QString value1 = min.toString();
346 QString value2 = max.toString();
354 QString value2 = max.toString();
347 q->setRange(value1,value2);
355 q->setRange(value1,value2);
348 }
356 }
349
357
350 int QBarCategoriesAxisPrivate::ticksCount() const
358 int QBarCategoriesAxisPrivate::ticksCount() const
351 {
359 {
352 return m_categories.count()+1;
360 return m_categories.count()+1;
353 }
361 }
354
362
355 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
363 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
356 {
364 {
357 m_min = min;
365 m_min = min;
358 m_max = max;
366 m_max = max;
359 m_ticksCount = count;
367 m_ticksCount = count;
360 }
368 }
361
369
362 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
370 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
363 {
371 {
364 Q_Q( QBarCategoriesAxis);
372 Q_Q( QBarCategoriesAxis);
365 if(m_orientation == Qt::Vertical){
373 if(m_orientation == Qt::Vertical){
366 return new ChartCategoriesAxisY(q,presenter);
374 return new ChartCategoriesAxisY(q,presenter);
367 }else{
375 }else{
368 return new ChartCategoriesAxisX(q,presenter);
376 return new ChartCategoriesAxisX(q,presenter);
369 }
377 }
370 }
378 }
371
379
372 void QBarCategoriesAxisPrivate::emitRange()
380 void QBarCategoriesAxisPrivate::emitRange()
373 {
381 {
374 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
382 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
375 }
383 }
376
384
377
385
378 #include "moc_qbarcategoriesaxis.cpp"
386 #include "moc_qbarcategoriesaxis.cpp"
379 #include "moc_qbarcategoriesaxis_p.cpp"
387 #include "moc_qbarcategoriesaxis_p.cpp"
380
388
381 QTCOMMERCIALCHART_END_NAMESPACE
389 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,178 +1,178
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qintervalaxis.h"
21 #include "qintervalaxis.h"
22 #include "qintervalaxis_p.h"
22 #include "qintervalaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*!
29 /*!
30 \internal
30 \internal
31 \class QIntervalAxis
31 \class QIntervalAxis
32 \brief The QIntervalAxis class is used for manipulating chart's axis.
32 \brief The QIntervalAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 */
36 */
37
37
38 /*!
38 /*!
39 \qmlclass Axis QIntervalAxis
39 \qmlclass Axis QIntervalAxis
40 \brief The Axis element is used for manipulating chart's axes.
40 \brief The Axis element is used for manipulating chart's axes.
41
41
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43
43
44 To access Axes you can use ChartView API. For example:
44 To access Axes you can use ChartView API. For example:
45 \code
45 \code
46 // TODO :)
46 // TODO :)
47 \endcode
47 \endcode
48 */
48 */
49
49
50 /*!
50 /*!
51 Constructs an axis object which is a child of \a parent.
51 Constructs an axis object which is a child of \a parent.
52 */
52 */
53 QIntervalAxis::QIntervalAxis(QObject *parent):
53 QIntervalAxis::QIntervalAxis(QObject *parent):
54 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
54 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
55 {
55 {
56 }
56 }
57
57
58 /*!
58 /*!
59 Destroys the object
59 Destroys the object
60 */
60 */
61 QIntervalAxis::~QIntervalAxis()
61 QIntervalAxis::~QIntervalAxis()
62 {
62 {
63 }
63 }
64
64
65 /*!
65 /*!
66 \internal
66 \internal
67 */
67 */
68 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
68 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
69 {
69 {
70
70
71 }
71 }
72
72
73 /*!
73 /*!
74 Appends \a categories to axis
74 Appends \a category to axis
75 */
75 */
76 void QIntervalAxis::append(const QString& category, qreal x)
76 void QIntervalAxis::append(const QString& category, qreal x)
77 {
77 {
78 Q_D(QIntervalAxis);
78 Q_D(QIntervalAxis);
79 if (!d->m_categories.contains(category))
79 if (!d->m_categories.contains(category))
80 {
80 {
81 if(d->m_categories.isEmpty()){
81 if(d->m_categories.isEmpty()){
82 Range range(d->m_categoryMinimum,x);
82 Range range(d->m_categoryMinimum,x);
83 d->m_categoriesMap.insert(category,range);
83 d->m_categoriesMap.insert(category,range);
84 d->m_categories.append(category);
84 d->m_categories.append(category);
85 }else{
85 }else{
86 Range range = d->m_categoriesMap.value(d->m_categories.last());
86 Range range = d->m_categoriesMap.value(d->m_categories.last());
87 d->m_categoriesMap.insert(category,Range(range.first,x));
87 d->m_categoriesMap.insert(category,Range(range.first,x));
88 d->m_categories.append(category);
88 d->m_categories.append(category);
89 }
89 }
90 setRange(d->m_min,x);
90 setRange(d->m_min,x);
91 }
91 }
92 }
92 }
93
93
94 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
94 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
95 {
95 {
96 Q_D(QIntervalAxis);
96 Q_D(QIntervalAxis);
97 if(d->m_categories.isEmpty()){
97 if(d->m_categories.isEmpty()){
98 d->m_categoryMinimum=x;
98 d->m_categoryMinimum=x;
99 }else{
99 }else{
100 Range range = d->m_categoriesMap.value(d->m_categories.first());
100 Range range = d->m_categoriesMap.value(d->m_categories.first());
101 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
101 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
102 setRange(x,d->m_min);
102 setRange(x,d->m_min);
103 }
103 }
104 }
104 }
105
105
106 /*!
106 /*!
107 Removes \a category from axis
107 Removes \a category from axis
108 */
108 */
109 void QIntervalAxis::remove(const QString &category)
109 void QIntervalAxis::remove(const QString &category)
110 {
110 {
111 Q_UNUSED(category);
111 Q_UNUSED(category);
112 //TODO
112 //TODO
113 }
113 }
114
114
115 QStringList QIntervalAxis::categories()
115 QStringList QIntervalAxis::categories()
116 {
116 {
117 Q_D(QIntervalAxis);
117 Q_D(QIntervalAxis);
118 return d->m_categories;
118 return d->m_categories;
119 }
119 }
120
120
121 /*!
121 /*!
122 Returns number of categories.
122 Returns number of categories.
123 */
123 */
124 int QIntervalAxis::count() const
124 int QIntervalAxis::count() const
125 {
125 {
126 Q_D(const QIntervalAxis);
126 Q_D(const QIntervalAxis);
127 return d->m_categories.count();
127 return d->m_categories.count();
128 }
128 }
129
129
130 /*!
130 /*!
131 Returns the type of the axis
131 Returns the type of the axis
132 */
132 */
133 QAbstractAxis::AxisType QIntervalAxis::type() const
133 QAbstractAxis::AxisType QIntervalAxis::type() const
134 {
134 {
135 return AxisTypeCategories;
135 return AxisTypeCategories;
136 }
136 }
137
137
138 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
138 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139
139
140 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
140 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
141 QValuesAxisPrivate(q),
141 QValuesAxisPrivate(q),
142 m_categoryMinimum(0)
142 m_categoryMinimum(0)
143 {
143 {
144
144
145 }
145 }
146
146
147 QIntervalAxisPrivate::~QIntervalAxisPrivate()
147 QIntervalAxisPrivate::~QIntervalAxisPrivate()
148 {
148 {
149
149
150 }
150 }
151
151
152 int QIntervalAxisPrivate::ticksCount() const
152 int QIntervalAxisPrivate::ticksCount() const
153 {
153 {
154 return m_categories.count()+1;
154 return m_categories.count()+1;
155 }
155 }
156
156
157 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
157 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
158 {
158 {
159 m_min = min;
159 m_min = min;
160 m_max = max;
160 m_max = max;
161 m_ticksCount = count;
161 m_ticksCount = count;
162 }
162 }
163
163
164 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
164 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
165 {
165 {
166 Q_UNUSED(presenter);
166 Q_UNUSED(presenter);
167 // Q_Q( QCategoriesAxis);
167 // Q_Q( QCategoriesAxis);
168 if(m_orientation == Qt::Vertical){
168 if(m_orientation == Qt::Vertical){
169 return 0;
169 return 0;
170 }else{
170 }else{
171 return 0;
171 return 0;
172 }
172 }
173 }
173 }
174
174
175 #include "moc_qintervalaxis.cpp"
175 #include "moc_qintervalaxis.cpp"
176 #include "moc_qintervalaxis_p.cpp"
176 #include "moc_qintervalaxis_p.cpp"
177
177
178 QTCOMMERCIALCHART_END_NAMESPACE
178 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,303 +1,311
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 #include "chartvaluesaxisx_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
24 #include "chartvaluesaxisy_p.h"
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 /*!
28 /*!
29 \class QValuesAxis
29 \class QValuesAxis
30 \brief The QValuesAxis class is used for manipulating chart's axis.
30 \brief The QValuesAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
33 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
33 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
34 Values of axis are drawn to position of ticks
34 Values of axis are drawn to position of ticks
35 */
35 */
36
36
37 /*!
37 /*!
38 \qmlclass ValuesAxis QValuesAxis
38 \qmlclass ValuesAxis QValuesAxis
39 \brief The ValuesAxis element is used for manipulating chart's axes
39 \brief The ValuesAxis element is used for manipulating chart's axes
40
40
41 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
41 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
42 Values of axis are drawn to position of ticks
42 Values of axis are drawn to position of ticks
43
43
44 To access Axes you can use ChartView API. For example:
44 To access Axes you can use ChartView API. For example:
45 \code
45 \code
46 ChartView {
46 ChartView {
47 ValuesAxis {
47 ValuesAxis {
48 id: xAxis
48 id: xAxis
49 min: 0
49 min: 0
50 max: 10
50 max: 10
51 }
51 }
52 // Add a few series...
52 // Add a few series...
53 }
53 }
54 \endcode
54 \endcode
55 */
55 */
56
56
57 /*!
57 /*!
58 \property QValuesAxis::min
58 \property QValuesAxis::min
59 Defines the minimum value on the axis.
59 Defines the minimum value on the axis.
60 */
60 */
61 /*!
61 /*!
62 \qmlproperty real ValuesAxis::min
62 \qmlproperty real ValuesAxis::min
63 Defines the minimum value on the axis.
63 Defines the minimum value on the axis.
64 */
64 */
65
65
66 /*!
66 /*!
67 \property QValuesAxis::max
67 \property QValuesAxis::max
68 Defines the maximum value on the axis.
68 Defines the maximum value on the axis.
69 */
69 */
70 /*!
70 /*!
71 \qmlproperty real ValuesAxis::max
71 \qmlproperty real ValuesAxis::max
72 Defines the maximum value on the axis.
72 Defines the maximum value on the axis.
73 */
73 */
74
74
75 /*!
75 /*!
76 \fn void QValuesAxis::minChanged(qreal min)
76 \fn void QValuesAxis::minChanged(qreal min)
77 Axis emits signal when \a min of axis has changed.
77 Axis emits signal when \a min of axis has changed.
78 */
78 */
79 /*!
80 \qmlsignal ValuesAxis::onMinChanged(real min)
81 Axis emits signal when \a min of axis has changed.
82 */
79
83
80 /*!
84 /*!
81 \fn void QValuesAxis::maxChanged(qreal max)
85 \fn void QValuesAxis::maxChanged(qreal max)
82 Axis emits signal when \a max of axis has changed.
86 Axis emits signal when \a max of axis has changed.
83 */
87 */
88 /*!
89 \qmlsignal ValuesAxis::onMaxChanged(real max)
90 Axis emits signal when \a max of axis has changed.
91 */
84
92
85 /*!
93 /*!
86 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
94 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
87 Axis emits signal when \a min or \a max of axis has changed.
95 Axis emits signal when \a min or \a max of axis has changed.
88 */
96 */
89
97
90 /*!
98 /*!
91 \property QValuesAxis::ticksCount
99 \property QValuesAxis::ticksCount
92 The number of tick marks for the axis.
100 The number of tick marks for the axis.
93 */
101 */
94
102
95 /*!
103 /*!
96 \qmlproperty int ValuesAxis::ticksCount
104 \qmlproperty int ValuesAxis::ticksCount
97 The number of tick marks for the axis.
105 The number of tick marks for the axis.
98 */
106 */
99
107
100 /*!
108 /*!
101 \property QValuesAxis::niceNumbersEnabled
109 \property QValuesAxis::niceNumbersEnabled
102 Whether the nice numbers algorithm is enabled or not for the axis.
110 Whether the nice numbers algorithm is enabled or not for the axis.
103 */
111 */
104
112
105 /*!
113 /*!
106 \qmlproperty bool ValuesAxis::niceNumbersEnabled
114 \qmlproperty bool ValuesAxis::niceNumbersEnabled
107 Whether the nice numbers algorithm is enabled or not for the axis.
115 Whether the nice numbers algorithm is enabled or not for the axis.
108 */
116 */
109
117
110 /*!
118 /*!
111 Constructs an axis object which is a child of \a parent.
119 Constructs an axis object which is a child of \a parent.
112 */
120 */
113 QValuesAxis::QValuesAxis(QObject *parent) :
121 QValuesAxis::QValuesAxis(QObject *parent) :
114 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
122 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
115 {
123 {
116
124
117 }
125 }
118
126
119 /*!
127 /*!
120 \internal
128 \internal
121 */
129 */
122 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
130 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
123 {
131 {
124
132
125 }
133 }
126
134
127 /*!
135 /*!
128 Destroys the object
136 Destroys the object
129 */
137 */
130 QValuesAxis::~QValuesAxis()
138 QValuesAxis::~QValuesAxis()
131 {
139 {
132
140
133 }
141 }
134
142
135 void QValuesAxis::setMin(qreal min)
143 void QValuesAxis::setMin(qreal min)
136 {
144 {
137 Q_D(QValuesAxis);
145 Q_D(QValuesAxis);
138 setRange(min,d->m_max);
146 setRange(min,d->m_max);
139 }
147 }
140
148
141 qreal QValuesAxis::min() const
149 qreal QValuesAxis::min() const
142 {
150 {
143 Q_D(const QValuesAxis);
151 Q_D(const QValuesAxis);
144 return d->m_min;
152 return d->m_min;
145 }
153 }
146
154
147 void QValuesAxis::setMax(qreal max)
155 void QValuesAxis::setMax(qreal max)
148 {
156 {
149 Q_D(QValuesAxis);
157 Q_D(QValuesAxis);
150 setRange(d->m_min,max);
158 setRange(d->m_min,max);
151 }
159 }
152
160
153 qreal QValuesAxis::max() const
161 qreal QValuesAxis::max() const
154 {
162 {
155 Q_D(const QValuesAxis);
163 Q_D(const QValuesAxis);
156 return d->m_max;
164 return d->m_max;
157 }
165 }
158
166
159 /*!
167 /*!
160 Sets range from \a min to \a max on the axis.
168 Sets range from \a min to \a max on the axis.
161 */
169 */
162 void QValuesAxis::setRange(qreal min, qreal max)
170 void QValuesAxis::setRange(qreal min, qreal max)
163 {
171 {
164 Q_D(QValuesAxis);
172 Q_D(QValuesAxis);
165
173
166 bool changed = false;
174 bool changed = false;
167 if (!qFuzzyIsNull(d->m_min - min)) {
175 if (!qFuzzyIsNull(d->m_min - min)) {
168 d->m_min = min;
176 d->m_min = min;
169 changed = true;
177 changed = true;
170 emit minChanged(min);
178 emit minChanged(min);
171 }
179 }
172
180
173 if (!qFuzzyIsNull(d->m_max - max)) {
181 if (!qFuzzyIsNull(d->m_max - max)) {
174 d->m_max = max;
182 d->m_max = max;
175 changed = true;
183 changed = true;
176 emit maxChanged(max);
184 emit maxChanged(max);
177 }
185 }
178
186
179 if (changed) {
187 if (changed) {
180 d->emitRange();
188 d->emitRange();
181 emit rangeChanged(d->m_min,d->m_max);
189 emit rangeChanged(d->m_min,d->m_max);
182 }
190 }
183 }
191 }
184
192
185 /*!
193 /*!
186 Sets \a count for ticks on the axis.
194 Sets \a count for ticks on the axis.
187 */
195 */
188 void QValuesAxis::setTicksCount(int count)
196 void QValuesAxis::setTicksCount(int count)
189 {
197 {
190 Q_D(QValuesAxis);
198 Q_D(QValuesAxis);
191 if (d->m_ticksCount != count) {
199 if (d->m_ticksCount != count) {
192 d->m_ticksCount = count;
200 d->m_ticksCount = count;
193 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
201 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
194 }
202 }
195 }
203 }
196
204
197 /*!
205 /*!
198 \fn int QValuesAxis::ticksCount() const
206 \fn int QValuesAxis::ticksCount() const
199 Return number of ticks on the axis
207 Return number of ticks on the axis
200 */
208 */
201 int QValuesAxis::ticksCount() const
209 int QValuesAxis::ticksCount() const
202 {
210 {
203 Q_D(const QValuesAxis);
211 Q_D(const QValuesAxis);
204 return d->m_ticksCount;
212 return d->m_ticksCount;
205 }
213 }
206
214
207 void QValuesAxis::setNiceNumbersEnabled(bool enable)
215 void QValuesAxis::setNiceNumbersEnabled(bool enable)
208 {
216 {
209 Q_D(QValuesAxis);
217 Q_D(QValuesAxis);
210 if (d->m_niceNumbers != enable){
218 if (d->m_niceNumbers != enable){
211 d->m_niceNumbers = enable;
219 d->m_niceNumbers = enable;
212 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
220 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
213 }
221 }
214 }
222 }
215
223
216 bool QValuesAxis::niceNumbersEnabled() const
224 bool QValuesAxis::niceNumbersEnabled() const
217 {
225 {
218 Q_D(const QValuesAxis);
226 Q_D(const QValuesAxis);
219 return d->m_niceNumbers;
227 return d->m_niceNumbers;
220 }
228 }
221
229
222 /*!
230 /*!
223 Returns the type of the axis
231 Returns the type of the axis
224 */
232 */
225 QAbstractAxis::AxisType QValuesAxis::type() const
233 QAbstractAxis::AxisType QValuesAxis::type() const
226 {
234 {
227 return AxisTypeValues;
235 return AxisTypeValues;
228 }
236 }
229
237
230 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
238 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231
239
232 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
240 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
233 QAbstractAxisPrivate(q),
241 QAbstractAxisPrivate(q),
234 m_niceNumbers(false)
242 m_niceNumbers(false)
235 {
243 {
236
244
237 }
245 }
238
246
239 QValuesAxisPrivate::~QValuesAxisPrivate()
247 QValuesAxisPrivate::~QValuesAxisPrivate()
240 {
248 {
241
249
242 }
250 }
243
251
244 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
252 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
245 {
253 {
246 Q_Q(QValuesAxis);
254 Q_Q(QValuesAxis);
247 q->setRange(min,max);
255 q->setRange(min,max);
248 q->setTicksCount(count);
256 q->setTicksCount(count);
249 }
257 }
250
258
251
259
252 void QValuesAxisPrivate::setMin(const QVariant &min)
260 void QValuesAxisPrivate::setMin(const QVariant &min)
253 {
261 {
254 Q_Q(QValuesAxis);
262 Q_Q(QValuesAxis);
255 bool ok;
263 bool ok;
256 qreal value = min.toReal(&ok);
264 qreal value = min.toReal(&ok);
257 if(ok) q->setMin(value);
265 if(ok) q->setMin(value);
258 }
266 }
259
267
260 void QValuesAxisPrivate::setMax(const QVariant &max)
268 void QValuesAxisPrivate::setMax(const QVariant &max)
261 {
269 {
262
270
263 Q_Q(QValuesAxis);
271 Q_Q(QValuesAxis);
264 bool ok;
272 bool ok;
265 qreal value = max.toReal(&ok);
273 qreal value = max.toReal(&ok);
266 if(ok) q->setMax(value);
274 if(ok) q->setMax(value);
267 }
275 }
268
276
269 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
277 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
270 {
278 {
271 Q_Q(QValuesAxis);
279 Q_Q(QValuesAxis);
272 bool ok1;
280 bool ok1;
273 bool ok2;
281 bool ok2;
274 qreal value1 = min.toReal(&ok1);
282 qreal value1 = min.toReal(&ok1);
275 qreal value2 = max.toReal(&ok2);
283 qreal value2 = max.toReal(&ok2);
276 if(ok1&&ok2) q->setRange(value1,value2);
284 if(ok1&&ok2) q->setRange(value1,value2);
277 }
285 }
278
286
279 int QValuesAxisPrivate::ticksCount() const
287 int QValuesAxisPrivate::ticksCount() const
280 {
288 {
281 return m_ticksCount;
289 return m_ticksCount;
282 }
290 }
283
291
284 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
292 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
285 {
293 {
286 Q_Q(QValuesAxis);
294 Q_Q(QValuesAxis);
287 if(m_orientation == Qt::Vertical){
295 if(m_orientation == Qt::Vertical){
288 return new ChartValuesAxisY(q,presenter);
296 return new ChartValuesAxisY(q,presenter);
289 }else{
297 }else{
290 return new ChartValuesAxisX(q,presenter);
298 return new ChartValuesAxisX(q,presenter);
291 }
299 }
292
300
293 }
301 }
294
302
295 void QValuesAxisPrivate::emitRange()
303 void QValuesAxisPrivate::emitRange()
296 {
304 {
297 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
305 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
298 }
306 }
299
307
300 #include "moc_qvaluesaxis.cpp"
308 #include "moc_qvaluesaxis.cpp"
301 #include "moc_qvaluesaxis_p.cpp"
309 #include "moc_qvaluesaxis_p.cpp"
302
310
303 QTCOMMERCIALCHART_END_NAMESPACE
311 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,389 +1,389
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 "charttheme_p.h"
21 #include "charttheme_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qchart_p.h"
23 #include "qchart_p.h"
24 #include "qchartview.h"
24 #include "qchartview.h"
25 #include "qlegend.h"
25 #include "qlegend.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include <QTime>
27 #include <QTime>
28
28
29 //series
29 //series
30 #include "qbarset.h"
30 #include "qbarset.h"
31 #include "qabstractbarseries.h"
31 #include "qabstractbarseries.h"
32 #include "qstackedbarseries.h"
32 #include "qstackedbarseries.h"
33 #include "qpercentbarseries.h"
33 #include "qpercentbarseries.h"
34 #include "qlineseries.h"
34 #include "qlineseries.h"
35 #include "qareaseries.h"
35 #include "qareaseries.h"
36 #include "qscatterseries.h"
36 #include "qscatterseries.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieslice.h"
38 #include "qpieslice.h"
39 #include "qpieslice_p.h"
39 #include "qpieslice_p.h"
40 #include "qsplineseries.h"
40 #include "qsplineseries.h"
41
41
42 //items
42 //items
43 #include "chartaxis_p.h"
43 #include "chartaxis_p.h"
44 #include "barchartitem_p.h"
44 #include "barchartitem_p.h"
45 #include "stackedbarchartitem_p.h"
45 #include "stackedbarchartitem_p.h"
46 #include "percentbarchartitem_p.h"
46 #include "percentbarchartitem_p.h"
47 #include "linechartitem_p.h"
47 #include "linechartitem_p.h"
48 #include "areachartitem_p.h"
48 #include "areachartitem_p.h"
49 #include "scatterchartitem_p.h"
49 #include "scatterchartitem_p.h"
50 #include "piechartitem_p.h"
50 #include "piechartitem_p.h"
51 #include "splinechartitem_p.h"
51 #include "splinechartitem_p.h"
52
52
53 //themes
53 //themes
54 #include "chartthemesystem_p.h"
54 #include "chartthemesystem_p.h"
55 #include "chartthemelight_p.h"
55 #include "chartthemelight_p.h"
56 #include "chartthemebluecerulean_p.h"
56 #include "chartthemebluecerulean_p.h"
57 #include "chartthemedark_p.h"
57 #include "chartthemedark_p.h"
58 #include "chartthemebrownsand_p.h"
58 #include "chartthemebrownsand_p.h"
59 #include "chartthemebluencs_p.h"
59 #include "chartthemebluencs_p.h"
60 #include "chartthemehighcontrast_p.h"
60 #include "chartthemehighcontrast_p.h"
61 #include "chartthemeblueicy_p.h"
61 #include "chartthemeblueicy_p.h"
62
62
63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
64
64
65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
66 m_masterFont(QFont("arial", 14)),
66 m_masterFont(QFont("arial", 14)),
67 m_labelFont(QFont("arial", 10)),
67 m_labelFont(QFont("arial", 10)),
68 m_labelBrush(QColor(QRgb(0x000000))),
68 m_labelBrush(QColor(QRgb(0x000000))),
69 m_axisLinePen(QPen(QRgb(0x000000))),
69 m_axisLinePen(QPen(QRgb(0x000000))),
70 m_backgroundShadesPen(Qt::NoPen),
70 m_backgroundShadesPen(Qt::NoPen),
71 m_backgroundShadesBrush(Qt::NoBrush),
71 m_backgroundShadesBrush(Qt::NoBrush),
72 m_backgroundShades(BackgroundShadesNone),
72 m_backgroundShades(BackgroundShadesNone),
73 m_backgroundDropShadowEnabled(false),
73 m_backgroundDropShadowEnabled(false),
74 m_gridLinePen(QPen(QRgb(0x000000))),
74 m_gridLinePen(QPen(QRgb(0x000000))),
75 m_force(false)
75 m_force(false)
76 {
76 {
77 m_id = id;
77 m_id = id;
78 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
78 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
79 }
79 }
80
80
81
81
82 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
82 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
83 {
83 {
84 switch(theme) {
84 switch(theme) {
85 case QChart::ChartThemeLight:
85 case QChart::ChartThemeLight:
86 return new ChartThemeLight();
86 return new ChartThemeLight();
87 case QChart::ChartThemeBlueCerulean:
87 case QChart::ChartThemeBlueCerulean:
88 return new ChartThemeBlueCerulean();
88 return new ChartThemeBlueCerulean();
89 case QChart::ChartThemeDark:
89 case QChart::ChartThemeDark:
90 return new ChartThemeDark();
90 return new ChartThemeDark();
91 case QChart::ChartThemeBrownSand:
91 case QChart::ChartThemeBrownSand:
92 return new ChartThemeBrownSand();
92 return new ChartThemeBrownSand();
93 case QChart::ChartThemeBlueNcs:
93 case QChart::ChartThemeBlueNcs:
94 return new ChartThemeBlueNcs();
94 return new ChartThemeBlueNcs();
95 case QChart::ChartThemeHighContrast:
95 case QChart::ChartThemeHighContrast:
96 return new ChartThemeHighContrast();
96 return new ChartThemeHighContrast();
97 case QChart::ChartThemeBlueIcy:
97 case QChart::ChartThemeBlueIcy:
98 return new ChartThemeBlueIcy();
98 return new ChartThemeBlueIcy();
99 default:
99 default:
100 return new ChartThemeSystem();
100 return new ChartThemeSystem();
101 }
101 }
102 }
102 }
103
103
104 void ChartTheme::decorate(QChart *chart)
104 void ChartTheme::decorate(QChart *chart)
105 {
105 {
106 QBrush brush;
106 QBrush brush;
107
107
108 if(brush == chart->backgroundBrush() || m_force)
108 if(brush == chart->backgroundBrush() || m_force)
109 chart->setBackgroundBrush(m_chartBackgroundGradient);
109 chart->setBackgroundBrush(m_chartBackgroundGradient);
110 chart->setTitleFont(m_masterFont);
110 chart->setTitleFont(m_masterFont);
111 chart->setTitleBrush(m_labelBrush);
111 chart->setTitleBrush(m_labelBrush);
112 chart->setDropShadowEnabled(m_backgroundDropShadowEnabled);
112 chart->setDropShadowEnabled(m_backgroundDropShadowEnabled);
113 }
113 }
114
114
115 void ChartTheme::decorate(QLegend *legend)
115 void ChartTheme::decorate(QLegend *legend)
116 {
116 {
117 QPen pen;
117 QPen pen;
118 QBrush brush;
118 QBrush brush;
119 QFont font;
119 QFont font;
120
120
121 if (pen == legend->pen() || m_force)
121 if (pen == legend->pen() || m_force)
122 legend->setPen(m_axisLinePen);
122 legend->setPen(m_axisLinePen);
123
123
124 if (brush == legend->brush() || m_force)
124 if (brush == legend->brush() || m_force)
125 legend->setBrush(m_chartBackgroundGradient);
125 legend->setBrush(m_chartBackgroundGradient);
126
126
127 if (font == legend->font() || m_force)
127 if (font == legend->font() || m_force)
128 legend->setFont(m_labelFont);
128 legend->setFont(m_labelFont);
129
129
130 if (brush == legend->labelBrush() || m_force)
130 if (brush == legend->labelBrush() || m_force)
131 legend->setLabelBrush(m_labelBrush);
131 legend->setLabelBrush(m_labelBrush);
132 }
132 }
133
133
134 void ChartTheme::decorate(QAreaSeries *series, int index)
134 void ChartTheme::decorate(QAreaSeries *series, int index)
135 {
135 {
136 QPen pen;
136 QPen pen;
137 QBrush brush;
137 QBrush brush;
138
138
139 if (pen == series->pen() || m_force){
139 if (pen == series->pen() || m_force){
140 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
140 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
141 pen.setWidthF(2);
141 pen.setWidthF(2);
142 series->setPen(pen);
142 series->setPen(pen);
143 }
143 }
144
144
145 if (brush == series->brush() || m_force) {
145 if (brush == series->brush() || m_force) {
146 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
146 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
147 series->setBrush(brush);
147 series->setBrush(brush);
148 }
148 }
149 }
149 }
150
150
151
151
152 void ChartTheme::decorate(QLineSeries *series,int index)
152 void ChartTheme::decorate(QLineSeries *series,int index)
153 {
153 {
154 QPen pen;
154 QPen pen;
155 if(pen == series->pen() || m_force ){
155 if(pen == series->pen() || m_force ){
156 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
156 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
157 pen.setWidthF(2);
157 pen.setWidthF(2);
158 series->setPen(pen);
158 series->setPen(pen);
159 }
159 }
160 }
160 }
161
161
162 void ChartTheme::decorate(QAbstractBarSeries *series, int index)
162 void ChartTheme::decorate(QAbstractBarSeries *series, int index)
163 {
163 {
164 QBrush brush;
164 QBrush brush;
165 QPen pen;
165 QPen pen;
166 QList<QBarSet *> sets = series->barSets();
166 QList<QBarSet *> sets = series->barSets();
167
167
168 qreal takeAtPos = 0.5;
168 qreal takeAtPos = 0.5;
169 qreal step = 0.2;
169 qreal step = 0.2;
170 if (sets.count() > 1 ) {
170 if (sets.count() > 1 ) {
171 step = 1.0 / (qreal) sets.count();
171 step = 1.0 / (qreal) sets.count();
172 if (sets.count() % m_seriesGradients.count())
172 if (sets.count() % m_seriesGradients.count())
173 step *= m_seriesGradients.count();
173 step *= m_seriesGradients.count();
174 else
174 else
175 step *= (m_seriesGradients.count() - 1);
175 step *= (m_seriesGradients.count() - 1);
176 }
176 }
177
177
178 for (int i(0); i < sets.count(); i++) {
178 for (int i(0); i < sets.count(); i++) {
179 int colorIndex = (index + i) % m_seriesGradients.count();
179 int colorIndex = (index + i) % m_seriesGradients.count();
180 if (i > 0 && i % m_seriesGradients.count() == 0) {
180 if (i > 0 && i % m_seriesGradients.count() == 0) {
181 // There is no dedicated base color for each sets, generate more colors
181 // There is no dedicated base color for each sets, generate more colors
182 takeAtPos += step;
182 takeAtPos += step;
183 if (takeAtPos == 1.0)
183 if (takeAtPos == 1.0)
184 takeAtPos += step;
184 takeAtPos += step;
185 takeAtPos -= (int) takeAtPos;
185 takeAtPos -= (int) takeAtPos;
186 }
186 }
187 if (brush == sets.at(i)->brush() || m_force )
187 if (brush == sets.at(i)->brush() || m_force )
188 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
188 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
189
189
190 // Pick label color from the opposite end of the gradient.
190 // Pick label color from the opposite end of the gradient.
191 // 0.3 as a boundary seems to work well.
191 // 0.3 as a boundary seems to work well.
192 if (takeAtPos < 0.3)
192 if (takeAtPos < 0.3)
193 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
193 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
194 else
194 else
195 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
195 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
196
196
197 if (pen == sets.at(i)->pen() || m_force) {
197 if (pen == sets.at(i)->pen() || m_force) {
198 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
198 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
199 sets.at(i)->setPen(c);
199 sets.at(i)->setPen(c);
200 }
200 }
201 }
201 }
202 }
202 }
203
203
204 void ChartTheme::decorate(QScatterSeries *series, int index)
204 void ChartTheme::decorate(QScatterSeries *series, int index)
205 {
205 {
206 QPen pen;
206 QPen pen;
207 QBrush brush;
207 QBrush brush;
208
208
209 if (pen == series->pen() || m_force) {
209 if (pen == series->pen() || m_force) {
210 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
210 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
211 pen.setWidthF(2);
211 pen.setWidthF(2);
212 series->setPen(pen);
212 series->setPen(pen);
213 }
213 }
214
214
215 if (brush == series->brush() || m_force) {
215 if (brush == series->brush() || m_force) {
216 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
216 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
217 series->setBrush(brush);
217 series->setBrush(brush);
218 }
218 }
219 }
219 }
220
220
221 void ChartTheme::decorate(QPieSeries *series, int index)
221 void ChartTheme::decorate(QPieSeries *series, int index)
222 {
222 {
223
223
224 for (int i(0); i < series->slices().count(); i++) {
224 for (int i(0); i < series->slices().count(); i++) {
225
225
226 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
226 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
227
227
228 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
228 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
229 qreal pos = (qreal) (i + 1) / (qreal) series->count();
229 qreal pos = (qreal) (i + 1) / (qreal) series->count();
230 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
230 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
231
231
232 QPieSlice *s = series->slices().at(i);
232 QPieSlice *s = series->slices().at(i);
233 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
233 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
234
234
235 if (d->m_data.m_slicePen.isThemed() || m_force)
235 if (d->m_data.m_slicePen.isThemed() || m_force)
236 d->setPen(penColor, true);
236 d->setPen(penColor, true);
237
237
238 if (d->m_data.m_sliceBrush.isThemed() || m_force)
238 if (d->m_data.m_sliceBrush.isThemed() || m_force)
239 d->setBrush(brushColor, true);
239 d->setBrush(brushColor, true);
240
240
241 if (d->m_data.m_labelBrush.isThemed() || m_force)
241 if (d->m_data.m_labelBrush.isThemed() || m_force)
242 d->setLabelBrush(m_labelBrush.color(), true);
242 d->setLabelBrush(m_labelBrush.color(), true);
243
243
244 if (d->m_data.m_labelFont.isThemed() || m_force)
244 if (d->m_data.m_labelFont.isThemed() || m_force)
245 d->setLabelFont(m_labelFont, true);
245 d->setLabelFont(m_labelFont, true);
246 }
246 }
247 }
247 }
248
248
249 void ChartTheme::decorate(QSplineSeries *series, int index)
249 void ChartTheme::decorate(QSplineSeries *series, int index)
250 {
250 {
251 QPen pen;
251 QPen pen;
252 if(pen == series->pen() || m_force){
252 if(pen == series->pen() || m_force){
253 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
253 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
254 pen.setWidthF(2);
254 pen.setWidthF(2);
255 series->setPen(pen);
255 series->setPen(pen);
256 }
256 }
257 }
257 }
258
258
259 void ChartTheme::decorate(QAbstractAxis *axis,bool axisX)
259 void ChartTheme::decorate(QAbstractAxis *axis,bool axisX)
260 {
260 {
261 QPen pen;
261 QPen pen;
262 QBrush brush;
262 QBrush brush;
263 QFont font;
263 QFont font;
264
264
265 if (axis->isAxisVisible()) {
265 if (axis->isArrowVisible()) {
266
266
267 if(brush == axis->labelsBrush() || m_force){
267 if(brush == axis->labelsBrush() || m_force){
268 axis->setLabelsBrush(m_labelBrush);
268 axis->setLabelsBrush(m_labelBrush);
269 }
269 }
270 if(pen == axis->labelsPen() || m_force){
270 if(pen == axis->labelsPen() || m_force){
271 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
271 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
272 }
272 }
273
273
274
274
275 if (axis->shadesVisible() || m_force) {
275 if (axis->shadesVisible() || m_force) {
276
276
277 if(brush == axis->shadesBrush() || m_force){
277 if(brush == axis->shadesBrush() || m_force){
278 axis->setShadesBrush(m_backgroundShadesBrush);
278 axis->setShadesBrush(m_backgroundShadesBrush);
279 }
279 }
280
280
281 if(pen == axis->shadesPen() || m_force){
281 if(pen == axis->shadesPen() || m_force){
282 axis->setShadesPen(m_backgroundShadesPen);
282 axis->setShadesPen(m_backgroundShadesPen);
283 }
283 }
284
284
285 if( m_force && (m_backgroundShades == BackgroundShadesBoth
285 if( m_force && (m_backgroundShades == BackgroundShadesBoth
286 || (m_backgroundShades == BackgroundShadesVertical && axisX)
286 || (m_backgroundShades == BackgroundShadesVertical && axisX)
287 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
287 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
288 axis->setShadesVisible(true);
288 axis->setShadesVisible(true);
289
289
290 }
290 }
291 }
291 }
292
292
293 if(pen == axis->axisPen() || m_force){
293 if(pen == axis->axisPen() || m_force){
294 axis->setAxisPen(m_axisLinePen);
294 axis->setAxisPen(m_axisLinePen);
295 }
295 }
296
296
297 if(pen == axis->gridLinePen() || m_force){
297 if(pen == axis->gridLinePen() || m_force){
298 axis->setGridLinePen(m_gridLinePen);
298 axis->setGridLinePen(m_gridLinePen);
299 }
299 }
300
300
301 if(font == axis->labelsFont() || m_force){
301 if(font == axis->labelsFont() || m_force){
302 axis->setLabelsFont(m_labelFont);
302 axis->setLabelsFont(m_labelFont);
303 }
303 }
304 }
304 }
305 }
305 }
306
306
307 void ChartTheme::generateSeriesGradients()
307 void ChartTheme::generateSeriesGradients()
308 {
308 {
309 // Generate gradients in HSV color space
309 // Generate gradients in HSV color space
310 foreach (const QColor& color, m_seriesColors) {
310 foreach (const QColor& color, m_seriesColors) {
311 QLinearGradient g;
311 QLinearGradient g;
312 qreal h = color.hsvHueF();
312 qreal h = color.hsvHueF();
313 qreal s = color.hsvSaturationF();
313 qreal s = color.hsvSaturationF();
314
314
315 // TODO: tune the algorithm to give nice results with most base colors defined in
315 // TODO: tune the algorithm to give nice results with most base colors defined in
316 // most themes. The rest of the gradients we can define manually in theme specific
316 // most themes. The rest of the gradients we can define manually in theme specific
317 // implementation.
317 // implementation.
318 QColor start = color;
318 QColor start = color;
319 start.setHsvF(h, 0.0, 1.0);
319 start.setHsvF(h, 0.0, 1.0);
320 g.setColorAt(0.0, start);
320 g.setColorAt(0.0, start);
321
321
322 g.setColorAt(0.5, color);
322 g.setColorAt(0.5, color);
323
323
324 QColor end = color;
324 QColor end = color;
325 end.setHsvF(h, s, 0.25);
325 end.setHsvF(h, s, 0.25);
326 g.setColorAt(1.0, end);
326 g.setColorAt(1.0, end);
327
327
328 m_seriesGradients << g;
328 m_seriesGradients << g;
329 }
329 }
330 }
330 }
331
331
332
332
333 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
333 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
334 {
334 {
335 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
335 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
336 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
336 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
337 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
337 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
338 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
338 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
339 QColor c;
339 QColor c;
340 c.setRgbF(r, g, b);
340 c.setRgbF(r, g, b);
341 return c;
341 return c;
342 }
342 }
343
343
344 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
344 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
345 {
345 {
346 Q_ASSERT(pos >= 0 && pos <= 1.0);
346 Q_ASSERT(pos >= 0 && pos <= 1.0);
347
347
348 QGradientStops stops = gradient.stops();
348 QGradientStops stops = gradient.stops();
349 int count = stops.count();
349 int count = stops.count();
350
350
351 // find previous stop relative to position
351 // find previous stop relative to position
352 QGradientStop prev = stops.first();
352 QGradientStop prev = stops.first();
353 for (int i = 0; i < count; i++) {
353 for (int i = 0; i < count; i++) {
354 QGradientStop stop = stops.at(i);
354 QGradientStop stop = stops.at(i);
355 if (pos > stop.first)
355 if (pos > stop.first)
356 prev = stop;
356 prev = stop;
357
357
358 // given position is actually a stop position?
358 // given position is actually a stop position?
359 if (pos == stop.first) {
359 if (pos == stop.first) {
360 //qDebug() << "stop color" << pos;
360 //qDebug() << "stop color" << pos;
361 return stop.second;
361 return stop.second;
362 }
362 }
363 }
363 }
364
364
365 // find next stop relative to position
365 // find next stop relative to position
366 QGradientStop next = stops.last();
366 QGradientStop next = stops.last();
367 for (int i = count - 1; i >= 0; i--) {
367 for (int i = count - 1; i >= 0; i--) {
368 QGradientStop stop = stops.at(i);
368 QGradientStop stop = stops.at(i);
369 if (pos < stop.first)
369 if (pos < stop.first)
370 next = stop;
370 next = stop;
371 }
371 }
372
372
373 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
373 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
374
374
375 qreal range = next.first - prev.first;
375 qreal range = next.first - prev.first;
376 qreal posDelta = pos - prev.first;
376 qreal posDelta = pos - prev.first;
377 qreal relativePos = posDelta / range;
377 qreal relativePos = posDelta / range;
378
378
379 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
379 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
380
380
381 return colorAt(prev.second, next.second, relativePos);
381 return colorAt(prev.second, next.second, relativePos);
382 }
382 }
383
383
384 void ChartTheme::setForced(bool enabled)
384 void ChartTheme::setForced(bool enabled)
385 {
385 {
386 m_force=enabled;
386 m_force=enabled;
387 }
387 }
388
388
389 QTCOMMERCIALCHART_END_NAMESPACE
389 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now