##// END OF EJS Templates
Fix wrong interpolation call in bar*series, unit tests fixed
Michal Klocek -
r1734:ee6ddf4cebac
parent child
Show More
@@ -1,66 +1,68
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 "abstractbaranimation_p.h"
21 #include "abstractbaranimation_p.h"
22 #include "abstractbarchartitem_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24 #include <QDebug>
24 #include <QDebug>
25
25
26 Q_DECLARE_METATYPE(QVector<QRectF>)
26 Q_DECLARE_METATYPE(QVector<QRectF>)
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 AbstractBarAnimation::AbstractBarAnimation(AbstractBarChartItem *item)
30 AbstractBarAnimation::AbstractBarAnimation(AbstractBarChartItem *item)
31 :ChartAnimation(item),
31 :ChartAnimation(item),
32 m_item(item)
32 m_item(item)
33 {
33 {
34 setDuration(ChartAnimationDuration);
34 setDuration(ChartAnimationDuration);
35 setEasingCurve(QEasingCurve::OutQuart);
35 setEasingCurve(QEasingCurve::OutQuart);
36 }
36 }
37
37
38 AbstractBarAnimation::~AbstractBarAnimation()
38 AbstractBarAnimation::~AbstractBarAnimation()
39 {
39 {
40 }
40 }
41
41
42 QVariant AbstractBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
42 QVariant AbstractBarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
43 {
43 {
44 Q_UNUSED(from);
44 Q_UNUSED(from);
45 Q_UNUSED(to);
45 Q_UNUSED(to);
46 Q_UNUSED(progress);
46 Q_UNUSED(progress);
47 qWarning() << "AbstractBarAnimation::interpolated called";
47 qWarning() << "AbstractBarAnimation::interpolated called";
48 return to;
48 return to;
49 }
49 }
50
50
51 void AbstractBarAnimation::updateCurrentValue(const QVariant &value)
51 void AbstractBarAnimation::updateCurrentValue(const QVariant &value)
52 {
52 {
53 QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value);
53 QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value);
54 m_item->setLayout(layout);
54 m_item->setLayout(layout);
55 }
55 }
56
56
57 void AbstractBarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout)
57 void AbstractBarAnimation::setup(const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout)
58 {
58 {
59 QVariantAnimation::KeyValues value;
60 setKeyValues(value); //workaround for wrong interpolation call
59 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
61 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
60 setKeyValueAt(1.0, qVariantFromValue(newLayout));
62 setKeyValueAt(1.0, qVariantFromValue(newLayout));
61 }
63 }
62
64
63 #include "moc_abstractbaranimation_p.cpp"
65 #include "moc_abstractbaranimation_p.cpp"
64
66
65 QTCOMMERCIALCHART_END_NAMESPACE
67 QTCOMMERCIALCHART_END_NAMESPACE
66
68
@@ -1,62 +1,61
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 "baranimation_p.h"
21 #include "baranimation_p.h"
22 #include "abstractbarchartitem_p.h"
22 #include "abstractbarchartitem_p.h"
23 #include <QTimer>
23 #include <QTimer>
24
24
25 Q_DECLARE_METATYPE(QVector<QRectF>)
25 Q_DECLARE_METATYPE(QVector<QRectF>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 BarAnimation::BarAnimation(AbstractBarChartItem *item)
29 BarAnimation::BarAnimation(AbstractBarChartItem *item)
30 :AbstractBarAnimation(item)
30 :AbstractBarAnimation(item)
31 {
31 {
32 setDuration(ChartAnimationDuration);
32
33 setEasingCurve(QEasingCurve::OutQuart);
34 }
33 }
35
34
36 BarAnimation::~BarAnimation()
35 BarAnimation::~BarAnimation()
37 {
36 {
38 }
37 }
39
38
40 QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
39 QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const
41 {
40 {
42 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
41 QVector<QRectF> startVector = qVariantValue<QVector<QRectF> >(from);
43 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
42 QVector<QRectF> endVector = qVariantValue<QVector<QRectF> >(to);
44 QVector<QRectF> result;
43 QVector<QRectF> result;
45
44
46 Q_ASSERT(startVector.count() == endVector.count());
45 Q_ASSERT(startVector.count() == endVector.count());
47
46
48 for(int i = 0; i < startVector.count(); i++) {
47 for(int i = 0; i < startVector.count(); i++) {
49 qreal w = endVector[i].width();
48 qreal w = endVector[i].width();
50 qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
49 qreal h = startVector[i].height() + ((endVector[i].height() - startVector[i].height()) * progress);
51 qreal x = endVector[i].topLeft().x();
50 qreal x = endVector[i].topLeft().x();
52 qreal y = endVector[i].topLeft().y() + endVector[i].height() - h;
51 qreal y = endVector[i].topLeft().y() + endVector[i].height() - h;
53
52
54 QRectF value(x,y,w,h);
53 QRectF value(x,y,w,h);
55 result << value;
54 result << value;
56 }
55 }
57 return qVariantFromValue(result);
56 return qVariantFromValue(result);
58 }
57 }
59
58
60 #include "moc_baranimation_p.cpp"
59 #include "moc_baranimation_p.cpp"
61
60
62 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,372 +1,371
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 "domain_p.h"
26 #include "domain_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28 #include <QDateTime>
28 #include <QDateTime>
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_arrow(new QGraphicsItemGroup(presenter->rootItem())),
38 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
39 m_min(0),
39 m_min(0),
40 m_max(0),
40 m_max(0),
41 m_animation(0),
41 m_animation(0),
42 m_minWidth(0),
42 m_minWidth(0),
43 m_minHeight(0)
43 m_minHeight(0)
44 {
44 {
45 //initial initialization
45 //initial initialization
46 m_arrow->setZValue(ChartPresenter::AxisZValue);
46 m_arrow->setZValue(ChartPresenter::AxisZValue);
47 m_arrow->setHandlesChildEvents(false);
47 m_arrow->setHandlesChildEvents(false);
48
48
49 m_shades->setZValue(ChartPresenter::ShadesZValue);
49 m_shades->setZValue(ChartPresenter::ShadesZValue);
50 m_grid->setZValue(ChartPresenter::GridZValue);
50 m_grid->setZValue(ChartPresenter::GridZValue);
51
51
52 QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
52 QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
53
53
54 QGraphicsSimpleTextItem item;
54 QGraphicsSimpleTextItem item;
55 m_font = item.font();
55 m_font = item.font();
56 }
56 }
57
57
58 ChartAxis::~ChartAxis()
58 ChartAxis::~ChartAxis()
59 {
59 {
60 }
60 }
61
61
62 void ChartAxis::setAnimation(AxisAnimation* animation)
62 void ChartAxis::setAnimation(AxisAnimation* animation)
63 {
63 {
64 m_animation=animation;
64 m_animation=animation;
65 }
65 }
66
66
67 void ChartAxis::setLayout(QVector<qreal> &layout)
67 void ChartAxis::setLayout(QVector<qreal> &layout)
68 {
68 {
69 m_layoutVector=layout;
69 m_layoutVector=layout;
70 }
70 }
71
71
72 void ChartAxis::createItems(int count)
72 void ChartAxis::createItems(int count)
73 {
73 {
74 if (m_arrow->children().size() == 0)
74 if (m_arrow->children().size() == 0)
75 m_arrow->addToGroup(new AxisItem(this));
75 m_arrow->addToGroup(new AxisItem(this));
76 for (int i = 0; i < count; ++i) {
76 for (int i = 0; i < count; ++i) {
77 m_grid->addToGroup(new QGraphicsLineItem());
77 m_grid->addToGroup(new QGraphicsLineItem());
78 m_labels->addToGroup(new QGraphicsSimpleTextItem());
78 m_labels->addToGroup(new QGraphicsSimpleTextItem());
79 m_arrow->addToGroup(new QGraphicsLineItem());
79 m_arrow->addToGroup(new QGraphicsLineItem());
80 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
80 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
81 }
81 }
82 }
82 }
83
83
84 void ChartAxis::deleteItems(int count)
84 void ChartAxis::deleteItems(int count)
85 {
85 {
86 QList<QGraphicsItem *> lines = m_grid->childItems();
86 QList<QGraphicsItem *> lines = m_grid->childItems();
87 QList<QGraphicsItem *> labels = m_labels->childItems();
87 QList<QGraphicsItem *> labels = m_labels->childItems();
88 QList<QGraphicsItem *> shades = m_shades->childItems();
88 QList<QGraphicsItem *> shades = m_shades->childItems();
89 QList<QGraphicsItem *> axis = m_arrow->childItems();
89 QList<QGraphicsItem *> axis = m_arrow->childItems();
90
90
91 for (int i = 0; i < count; ++i) {
91 for (int i = 0; i < count; ++i) {
92 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
92 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
93 delete(lines.takeLast());
93 delete(lines.takeLast());
94 delete(labels.takeLast());
94 delete(labels.takeLast());
95 delete(axis.takeLast());
95 delete(axis.takeLast());
96 }
96 }
97 }
97 }
98
98
99 void ChartAxis::updateLayout(QVector<qreal> &layout)
99 void ChartAxis::updateLayout(QVector<qreal> &layout)
100 {
100 {
101 int diff = m_layoutVector.size() - layout.size();
101 int diff = m_layoutVector.size() - layout.size();
102
102
103 if (diff>0) {
103 if (diff>0) {
104 deleteItems(diff);
104 deleteItems(diff);
105 }
105 }
106 else if (diff<0) {
106 else if (diff<0) {
107 createItems(-diff);
107 createItems(-diff);
108 }
108 }
109
109
110 if(diff<0) handleAxisUpdated();
110 if(diff<0) handleAxisUpdated();
111
111
112 if (m_animation) {
112 if (m_animation) {
113 switch(presenter()->state()){
113 switch(presenter()->state()){
114 case ChartPresenter::ZoomInState:
114 case ChartPresenter::ZoomInState:
115 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
115 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
116 m_animation->setAnimationPoint(presenter()->statePoint());
116 m_animation->setAnimationPoint(presenter()->statePoint());
117 break;
117 break;
118 case ChartPresenter::ZoomOutState:
118 case ChartPresenter::ZoomOutState:
119 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
119 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
120 m_animation->setAnimationPoint(presenter()->statePoint());
120 m_animation->setAnimationPoint(presenter()->statePoint());
121 break;
121 break;
122 case ChartPresenter::ScrollUpState:
122 case ChartPresenter::ScrollUpState:
123 case ChartPresenter::ScrollLeftState:
123 case ChartPresenter::ScrollLeftState:
124 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
124 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
125 break;
125 break;
126 case ChartPresenter::ScrollDownState:
126 case ChartPresenter::ScrollDownState:
127 case ChartPresenter::ScrollRightState:
127 case ChartPresenter::ScrollRightState:
128 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
128 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
129 break;
129 break;
130 case ChartPresenter::ShowState:
130 case ChartPresenter::ShowState:
131 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
131 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
132 break;
132 break;
133 }
133 }
134 m_animation->setValues(m_layoutVector,layout);
134 m_animation->setValues(m_layoutVector,layout);
135 presenter()->startAnimation(m_animation);
135 presenter()->startAnimation(m_animation);
136 }
136 }
137 else {
137 else {
138 setLayout(layout);
138 setLayout(layout);
139 updateGeometry();
139 updateGeometry();
140 }
140 }
141 }
141 }
142
142
143 void ChartAxis::setArrowOpacity(qreal opacity)
143 void ChartAxis::setArrowOpacity(qreal opacity)
144 {
144 {
145 m_arrow->setOpacity(opacity);
145 m_arrow->setOpacity(opacity);
146 }
146 }
147
147
148 qreal ChartAxis::arrowOpacity() const
148 qreal ChartAxis::arrowOpacity() const
149 {
149 {
150 return m_arrow->opacity();
150 return m_arrow->opacity();
151 }
151 }
152
152
153 void ChartAxis::setArrowVisibility(bool visible)
153 void ChartAxis::setArrowVisibility(bool visible)
154 {
154 {
155 m_arrow->setOpacity(visible);
155 m_arrow->setOpacity(visible);
156 }
156 }
157
157
158 void ChartAxis::setGridOpacity(qreal opacity)
158 void ChartAxis::setGridOpacity(qreal opacity)
159 {
159 {
160 m_grid->setOpacity(opacity);
160 m_grid->setOpacity(opacity);
161 }
161 }
162
162
163 qreal ChartAxis::gridOpacity() const
163 qreal ChartAxis::gridOpacity() const
164 {
164 {
165 return m_grid->opacity();
165 return m_grid->opacity();
166 }
166 }
167
167
168 void ChartAxis::setGridVisibility(bool visible)
168 void ChartAxis::setGridVisibility(bool visible)
169 {
169 {
170 m_grid->setOpacity(visible);
170 m_grid->setOpacity(visible);
171 }
171 }
172
172
173 void ChartAxis::setLabelsOpacity(qreal opacity)
173 void ChartAxis::setLabelsOpacity(qreal opacity)
174 {
174 {
175 m_labels->setOpacity(opacity);
175 m_labels->setOpacity(opacity);
176 }
176 }
177
177
178 qreal ChartAxis::labelsOpacity() const
178 qreal ChartAxis::labelsOpacity() const
179 {
179 {
180 return m_labels->opacity();
180 return m_labels->opacity();
181 }
181 }
182
182
183 void ChartAxis::setLabelsVisibility(bool visible)
183 void ChartAxis::setLabelsVisibility(bool visible)
184 {
184 {
185 m_labels->setOpacity(visible);
185 m_labels->setOpacity(visible);
186 }
186 }
187
187
188 void ChartAxis::setShadesOpacity(qreal opacity)
188 void ChartAxis::setShadesOpacity(qreal opacity)
189 {
189 {
190 m_shades->setOpacity(opacity);
190 m_shades->setOpacity(opacity);
191 }
191 }
192
192
193 qreal ChartAxis::shadesOpacity() const
193 qreal ChartAxis::shadesOpacity() const
194 {
194 {
195 return m_shades->opacity();
195 return m_shades->opacity();
196 }
196 }
197
197
198 void ChartAxis::setShadesVisibility(bool visible)
198 void ChartAxis::setShadesVisibility(bool visible)
199 {
199 {
200 m_shades->setVisible(visible);
200 m_shades->setVisible(visible);
201 }
201 }
202
202
203 void ChartAxis::setLabelsAngle(int angle)
203 void ChartAxis::setLabelsAngle(int angle)
204 {
204 {
205 foreach(QGraphicsItem* item , m_labels->childItems()) {
205 foreach(QGraphicsItem* item , m_labels->childItems()) {
206 item->setRotation(angle);
206 item->setRotation(angle);
207 }
207 }
208
208
209 m_labelsAngle=angle;
209 m_labelsAngle=angle;
210 }
210 }
211
211
212 void ChartAxis::setLabelsPen(const QPen &pen)
212 void ChartAxis::setLabelsPen(const QPen &pen)
213 {
213 {
214 foreach(QGraphicsItem* item , m_labels->childItems()) {
214 foreach(QGraphicsItem* item , m_labels->childItems()) {
215 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
215 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
216 }
216 }
217 }
217 }
218
218
219 void ChartAxis::setLabelsBrush(const QBrush &brush)
219 void ChartAxis::setLabelsBrush(const QBrush &brush)
220 {
220 {
221 foreach(QGraphicsItem* item , m_labels->childItems()) {
221 foreach(QGraphicsItem* item , m_labels->childItems()) {
222 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
222 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
223 }
223 }
224 }
224 }
225
225
226 void ChartAxis::setLabelsFont(const QFont &font)
226 void ChartAxis::setLabelsFont(const QFont &font)
227 {
227 {
228 foreach(QGraphicsItem* item , m_labels->childItems()) {
228 foreach(QGraphicsItem* item , m_labels->childItems()) {
229 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
229 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
230 }
230 }
231 m_font = font;
231 m_font = font;
232 }
232 }
233
233
234 void ChartAxis::setShadesBrush(const QBrush &brush)
234 void ChartAxis::setShadesBrush(const QBrush &brush)
235 {
235 {
236 foreach(QGraphicsItem* item , m_shades->childItems()) {
236 foreach(QGraphicsItem* item , m_shades->childItems()) {
237 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
237 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
238 }
238 }
239 }
239 }
240
240
241 void ChartAxis::setShadesPen(const QPen &pen)
241 void ChartAxis::setShadesPen(const QPen &pen)
242 {
242 {
243 foreach(QGraphicsItem* item , m_shades->childItems()) {
243 foreach(QGraphicsItem* item , m_shades->childItems()) {
244 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
244 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
245 }
245 }
246 }
246 }
247
247
248 void ChartAxis::setArrowPen(const QPen &pen)
248 void ChartAxis::setArrowPen(const QPen &pen)
249 {
249 {
250 foreach(QGraphicsItem* item , m_arrow->childItems()) {
250 foreach(QGraphicsItem* item , m_arrow->childItems()) {
251 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
251 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
252 }
252 }
253 }
253 }
254
254
255 void ChartAxis::setGridPen(const QPen &pen)
255 void ChartAxis::setGridPen(const QPen &pen)
256 {
256 {
257 foreach(QGraphicsItem* item , m_grid->childItems()) {
257 foreach(QGraphicsItem* item , m_grid->childItems()) {
258 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
258 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
259 }
259 }
260 }
260 }
261
261
262 bool ChartAxis::isEmpty()
262 bool ChartAxis::isEmpty()
263 {
263 {
264 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max);
264 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max);
265 }
265 }
266
266
267 void ChartAxis::handleDomainUpdated()
267 void ChartAxis::handleDomainUpdated()
268 {
268 {
269 Domain* domain = qobject_cast<Domain*>(sender());
269 Domain* domain = qobject_cast<Domain*>(sender());
270 qreal min(0);
270 qreal min(0);
271 qreal max(0);
271 qreal max(0);
272
272
273 if(m_chartAxis->orientation()==Qt::Horizontal) {
273 if(m_chartAxis->orientation()==Qt::Horizontal) {
274 min = domain->minX();
274 min = domain->minX();
275 max = domain->maxX();
275 max = domain->maxX();
276 }
276 }
277 else if (m_chartAxis->orientation()==Qt::Vertical)
277 else if (m_chartAxis->orientation()==Qt::Vertical)
278 {
278 {
279 min = domain->minY();
279 min = domain->minY();
280 max = domain->maxY();
280 max = domain->maxY();
281 }
281 }
282
282
283 if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max))
283 if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max))
284 {
284 {
285 m_min = min;
285 m_min = min;
286 m_max = max;
286 m_max = max;
287
287
288 if (!isEmpty()) {
288 if (!isEmpty()) {
289 QVector<qreal> layout = calculateLayout();
289 QVector<qreal> layout = calculateLayout();
290 updateLayout(layout);
290 updateLayout(layout);
291 }
291 }
292 }
292 }
293 }
293 }
294
294
295 void ChartAxis::handleAxisUpdated()
295 void ChartAxis::handleAxisUpdated()
296 {
296 {
297 if(isEmpty()) return;
297 if(isEmpty()) return;
298
298
299
299
300 bool visible = m_chartAxis->isVisible();
300 bool visible = m_chartAxis->isVisible();
301
301
302 setArrowVisibility(visible && m_chartAxis->isArrowVisible());
302 setArrowVisibility(visible && m_chartAxis->isArrowVisible());
303 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
303 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
304 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
304 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
305 setShadesVisibility(visible && m_chartAxis->shadesVisible());
305 setShadesVisibility(visible && m_chartAxis->shadesVisible());
306
307 setLabelsAngle(m_chartAxis->labelsAngle());
306 setLabelsAngle(m_chartAxis->labelsAngle());
308 setArrowPen(m_chartAxis->axisPen());
307 setArrowPen(m_chartAxis->axisPen());
309 setLabelsPen(m_chartAxis->labelsPen());
308 setLabelsPen(m_chartAxis->labelsPen());
310 setLabelsBrush(m_chartAxis->labelsBrush());
309 setLabelsBrush(m_chartAxis->labelsBrush());
311 setLabelsFont(m_chartAxis->labelsFont());
310 setLabelsFont(m_chartAxis->labelsFont());
312 setGridPen(m_chartAxis->gridLinePen());
311 setGridPen(m_chartAxis->gridLinePen());
313 setShadesPen(m_chartAxis->shadesPen());
312 setShadesPen(m_chartAxis->shadesPen());
314 setShadesBrush(m_chartAxis->shadesBrush());
313 setShadesBrush(m_chartAxis->shadesBrush());
315
314
316 }
315 }
317
316
318 void ChartAxis::hide()
317 void ChartAxis::hide()
319 {
318 {
320 setArrowVisibility(false);
319 setArrowVisibility(false);
321 setGridVisibility(false);
320 setGridVisibility(false);
322 setLabelsVisibility(false);
321 setLabelsVisibility(false);
323 setShadesVisibility(false);
322 setShadesVisibility(false);
324 }
323 }
325
324
326 void ChartAxis::handleGeometryChanged(const QRectF &rect)
325 void ChartAxis::handleGeometryChanged(const QRectF &rect)
327 {
326 {
328 if(m_rect != rect)
327 if(m_rect != rect)
329 {
328 {
330 m_rect = rect;
329 m_rect = rect;
331 if (isEmpty()) return;
330 if (isEmpty()) return;
332 QVector<qreal> layout = calculateLayout();
331 QVector<qreal> layout = calculateLayout();
333 updateLayout(layout);
332 updateLayout(layout);
334 }
333 }
335 }
334 }
336
335
337
336
338 qreal ChartAxis::minimumWidth()
337 qreal ChartAxis::minimumWidth()
339 {
338 {
340 if(m_minWidth == 0) updateGeometry();
339 if(m_minWidth == 0) updateGeometry();
341 return m_minWidth;
340 return m_minWidth;
342 }
341 }
343
342
344 qreal ChartAxis::minimumHeight()
343 qreal ChartAxis::minimumHeight()
345 {
344 {
346 if(m_minHeight == 0) updateGeometry();
345 if(m_minHeight == 0) updateGeometry();
347 return m_minHeight;
346 return m_minHeight;
348 }
347 }
349
348
350
349
351 void ChartAxis::axisSelected()
350 void ChartAxis::axisSelected()
352 {
351 {
353 qDebug()<<"TODO: axis clicked";
352 qDebug()<<"TODO: axis clicked";
354 }
353 }
355
354
356
355
357 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const
356 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const
358 {
357 {
359 Q_ASSERT(max>min);
358 Q_ASSERT(max>min);
360 Q_ASSERT(ticks>1);
359 Q_ASSERT(ticks>1);
361
360
362 int n = qMax(int(-qFloor(log10((max-min)/(ticks-1)))),0);
361 int n = qMax(int(-qFloor(log10((max-min)/(ticks-1)))),0);
363 n++;
362 n++;
364 for (int i=0; i< ticks; i++) {
363 for (int i=0; i< ticks; i++) {
365 qreal value = min + (i * (max - min)/ (ticks-1));
364 qreal value = min + (i * (max - min)/ (ticks-1));
366 labels << QString::number(value,'f',n);
365 labels << QString::number(value,'f',n);
367 }
366 }
368 }
367 }
369
368
370 #include "moc_chartaxis_p.cpp"
369 #include "moc_chartaxis_p.cpp"
371
370
372 QTCOMMERCIALCHART_END_NAMESPACE
371 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now