@@ -224,11 +224,11 void ChartAnimator::updateLayout(XYChartItem* item, QVector<QPointF>& oldPoints | |||||
224 | QTimer::singleShot(0,animation,SLOT(start())); |
|
224 | QTimer::singleShot(0,animation,SLOT(start())); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 |
void ChartAnimator::addAnimation(PieChartItem* item, QPieSlice *slice, const PieSlice |
|
227 | void ChartAnimator::addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) | |
228 | { |
|
228 | { | |
229 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); |
|
229 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); | |
230 | Q_ASSERT(animation); |
|
230 | Q_ASSERT(animation); | |
231 |
animation->addSlice(slice, la |
|
231 | animation->addSlice(slice, sliceData, isEmpty); | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | void ChartAnimator::removeAnimation(PieChartItem* item, QPieSlice *slice) |
|
234 | void ChartAnimator::removeAnimation(PieChartItem* item, QPieSlice *slice) | |
@@ -245,11 +245,11 void ChartAnimator::updateLayout(PieChartItem* item, const PieLayout &layout) | |||||
245 | animation->updateValues(layout); |
|
245 | animation->updateValues(layout); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 |
void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const PieSlice |
|
248 | void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData) | |
249 | { |
|
249 | { | |
250 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); |
|
250 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); | |
251 | Q_ASSERT(animation); |
|
251 | Q_ASSERT(animation); | |
252 |
animation->updateValue(slice, la |
|
252 | animation->updateValue(slice, sliceData); | |
253 | } |
|
253 | } | |
254 |
|
254 | |||
255 | void ChartAnimator::setState(State state,const QPointF& point) |
|
255 | void ChartAnimator::setState(State state,const QPointF& point) |
@@ -35,10 +35,10 public: | |||||
35 | void updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newContorlPoints,int index); |
|
35 | void updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newContorlPoints,int index); | |
36 | void updateLayout(AxisItem* item, QVector<qreal>& layout); |
|
36 | void updateLayout(AxisItem* item, QVector<qreal>& layout); | |
37 |
|
37 | |||
38 |
void addAnimation(PieChartItem* item, QPieSlice *slice, const PieSlice |
|
38 | void addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty); | |
39 | void removeAnimation(PieChartItem* item, QPieSlice *slice); |
|
39 | void removeAnimation(PieChartItem* item, QPieSlice *slice); | |
40 | void updateLayout(PieChartItem* item, const PieLayout &layout); |
|
40 | void updateLayout(PieChartItem* item, const PieLayout &layout); | |
41 |
void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSlice |
|
41 | void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData); | |
42 |
|
42 | |||
43 | void setState(State state,const QPointF& point = QPointF()); |
|
43 | void setState(State state,const QPointF& point = QPointF()); | |
44 |
|
44 |
@@ -22,32 +22,32 void PieAnimation::updateValues(const PieLayout &newValues) | |||||
22 | updateValue(s, newValues.value(s)); |
|
22 | updateValue(s, newValues.value(s)); | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 |
void PieAnimation::updateValue(QPieSlice *slice, const PieSlice |
|
25 | void PieAnimation::updateValue(QPieSlice *slice, const PieSliceData &sliceData) | |
26 | { |
|
26 | { | |
27 | PieSliceAnimation *animation = m_animations.value(slice); |
|
27 | PieSliceAnimation *animation = m_animations.value(slice); | |
28 | Q_ASSERT(animation); |
|
28 | Q_ASSERT(animation); | |
29 | animation->stop(); |
|
29 | animation->stop(); | |
30 |
|
30 | |||
31 |
animation->updateValue( |
|
31 | animation->updateValue(sliceData); | |
32 | animation->setDuration(1000); |
|
32 | animation->setDuration(1000); | |
33 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
33 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
34 |
|
34 | |||
35 | QTimer::singleShot(0, animation, SLOT(start())); |
|
35 | QTimer::singleShot(0, animation, SLOT(start())); | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 |
void PieAnimation::addSlice(QPieSlice *slice, const PieSlice |
|
38 | void PieAnimation::addSlice(QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) | |
39 | { |
|
39 | { | |
40 | PieSliceAnimation *animation = new PieSliceAnimation(m_item, slice); |
|
40 | PieSliceAnimation *animation = new PieSliceAnimation(m_item, slice); | |
41 | m_animations.insert(slice, animation); |
|
41 | m_animations.insert(slice, animation); | |
42 |
|
42 | |||
43 |
PieSlice |
|
43 | PieSliceData startValue = sliceData; | |
44 |
start |
|
44 | startValue.m_radius = 0; | |
45 | if (isEmpty) |
|
45 | if (isEmpty) | |
46 |
start |
|
46 | startValue.m_startAngle = 0; | |
47 | else |
|
47 | else | |
48 |
start |
|
48 | startValue.m_startAngle = sliceData.m_startAngle + (sliceData.m_angleSpan/2); | |
49 |
start |
|
49 | startValue.m_angleSpan = 0; | |
50 |
animation->setValue(start |
|
50 | animation->setValue(startValue, sliceData); | |
51 |
|
51 | |||
52 | animation->setDuration(1000); |
|
52 | animation->setDuration(1000); | |
53 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
53 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
@@ -60,13 +60,13 void PieAnimation::removeSlice(QPieSlice *slice) | |||||
60 | Q_ASSERT(animation); |
|
60 | Q_ASSERT(animation); | |
61 | animation->stop(); |
|
61 | animation->stop(); | |
62 |
|
62 | |||
63 |
PieSlice |
|
63 | PieSliceData endValue = animation->currentSliceValue(); | |
64 |
end |
|
64 | endValue.m_radius = 0; | |
65 | // TODO: find the actual angle where this slice disappears |
|
65 | // TODO: find the actual angle where this slice disappears | |
66 |
end |
|
66 | endValue.m_startAngle = endValue.m_startAngle + endValue.m_angleSpan; | |
67 |
end |
|
67 | endValue.m_angleSpan = 0; | |
68 |
|
68 | |||
69 |
animation->updateValue(end |
|
69 | animation->updateValue(endValue); | |
70 | animation->setDuration(1000); |
|
70 | animation->setDuration(1000); | |
71 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
71 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
72 |
|
72 |
@@ -17,8 +17,8 public: | |||||
17 | PieAnimation(PieChartItem *item); |
|
17 | PieAnimation(PieChartItem *item); | |
18 | ~PieAnimation(); |
|
18 | ~PieAnimation(); | |
19 | void updateValues(const PieLayout &newValues); |
|
19 | void updateValues(const PieLayout &newValues); | |
20 |
void updateValue(QPieSlice *slice, const PieSlice |
|
20 | void updateValue(QPieSlice *slice, const PieSliceData &newValue); | |
21 |
void addSlice(QPieSlice *slice, const PieSlice |
|
21 | void addSlice(QPieSlice *slice, const PieSliceData &endValue, bool isEmpty); | |
22 | void removeSlice(QPieSlice *slice); |
|
22 | void removeSlice(QPieSlice *slice); | |
23 |
|
23 | |||
24 | public: // from QVariantAnimation |
|
24 | public: // from QVariantAnimation |
@@ -2,7 +2,7 | |||||
2 | #include "piechartitem_p.h" |
|
2 | #include "piechartitem_p.h" | |
3 | #include "qpieslice.h" |
|
3 | #include "qpieslice.h" | |
4 |
|
4 | |||
5 |
Q_DECLARE_METATYPE(QtCommercialChart::PieSlice |
|
5 | Q_DECLARE_METATYPE(QtCommercialChart::PieSliceData) | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
@@ -49,7 +49,7 PieSliceAnimation::~PieSliceAnimation() | |||||
49 | { |
|
49 | { | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 |
void PieSliceAnimation::setValue(const PieSlice |
|
52 | void PieSliceAnimation::setValue(const PieSliceData &startValue, const PieSliceData &endValue) | |
53 | { |
|
53 | { | |
54 | if (state() != QAbstractAnimation::Stopped) |
|
54 | if (state() != QAbstractAnimation::Stopped) | |
55 | stop(); |
|
55 | stop(); | |
@@ -60,7 +60,7 void PieSliceAnimation::setValue(const PieSliceLayout &startValue, const PieSlic | |||||
60 | setKeyValueAt(1.0, qVariantFromValue(endValue)); |
|
60 | setKeyValueAt(1.0, qVariantFromValue(endValue)); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 |
void PieSliceAnimation::updateValue(const PieSlice |
|
63 | void PieSliceAnimation::updateValue(const PieSliceData &endValue) | |
64 | { |
|
64 | { | |
65 | if (state() != QAbstractAnimation::Stopped) |
|
65 | if (state() != QAbstractAnimation::Stopped) | |
66 | stop(); |
|
66 | stop(); | |
@@ -69,7 +69,7 void PieSliceAnimation::updateValue(const PieSliceLayout &endValue) | |||||
69 | setKeyValueAt(1.0, qVariantFromValue(endValue)); |
|
69 | setKeyValueAt(1.0, qVariantFromValue(endValue)); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 |
PieSlice |
|
72 | PieSliceData PieSliceAnimation::currentSliceValue() | |
73 | { |
|
73 | { | |
74 | // NOTE: |
|
74 | // NOTE: | |
75 | // We must use an internal current value because QVariantAnimation::currentValue() is updated |
|
75 | // We must use an internal current value because QVariantAnimation::currentValue() is updated | |
@@ -81,10 +81,10 PieSliceLayout PieSliceAnimation::currentSliceValue() | |||||
81 |
|
81 | |||
82 | QVariant PieSliceAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const |
|
82 | QVariant PieSliceAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const | |
83 | { |
|
83 | { | |
84 |
PieSlice |
|
84 | PieSliceData startValue = qVariantValue<PieSliceData>(start); | |
85 |
PieSlice |
|
85 | PieSliceData endValue = qVariantValue<PieSliceData>(end); | |
86 |
|
86 | |||
87 |
PieSlice |
|
87 | PieSliceData result; | |
88 | result = endValue; |
|
88 | result = endValue; | |
89 | result.m_center = linearPos(startValue.m_center, endValue.m_center, progress); |
|
89 | result.m_center = linearPos(startValue.m_center, endValue.m_center, progress); | |
90 | result.m_radius = linearPos(startValue.m_radius, endValue.m_radius, progress); |
|
90 | result.m_radius = linearPos(startValue.m_radius, endValue.m_radius, progress); | |
@@ -99,7 +99,7 QVariant PieSliceAnimation::interpolated(const QVariant &start, const QVariant & | |||||
99 | void PieSliceAnimation::updateCurrentValue(const QVariant &value) |
|
99 | void PieSliceAnimation::updateCurrentValue(const QVariant &value) | |
100 | { |
|
100 | { | |
101 | if (state() != QAbstractAnimation::Stopped) { //workaround |
|
101 | if (state() != QAbstractAnimation::Stopped) { //workaround | |
102 |
m_currentValue = qVariantValue<PieSlice |
|
102 | m_currentValue = qVariantValue<PieSliceData>(value); | |
103 | m_item->setLayout(m_slice, m_currentValue); |
|
103 | m_item->setLayout(m_slice, m_currentValue); | |
104 | } |
|
104 | } | |
105 | } |
|
105 | } |
@@ -14,9 +14,9 class PieSliceAnimation : public QVariantAnimation | |||||
14 | public: |
|
14 | public: | |
15 | PieSliceAnimation(PieChartItem *item, QPieSlice *slice); |
|
15 | PieSliceAnimation(PieChartItem *item, QPieSlice *slice); | |
16 | ~PieSliceAnimation(); |
|
16 | ~PieSliceAnimation(); | |
17 |
void setValue(const PieSlice |
|
17 | void setValue(const PieSliceData &startValue, const PieSliceData &endValue); | |
18 |
void updateValue(const PieSlice |
|
18 | void updateValue(const PieSliceData &endValue); | |
19 |
PieSlice |
|
19 | PieSliceData currentSliceValue(); | |
20 |
|
20 | |||
21 | protected: |
|
21 | protected: | |
22 | QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const; |
|
22 | QVariant interpolated(const QVariant &start, const QVariant &end, qreal progress) const; | |
@@ -25,7 +25,7 protected: | |||||
25 | private: |
|
25 | private: | |
26 | PieChartItem *m_item; |
|
26 | PieChartItem *m_item; | |
27 | QPieSlice *m_slice; |
|
27 | QPieSlice *m_slice; | |
28 |
PieSlice |
|
28 | PieSliceData m_currentValue; | |
29 | }; |
|
29 | }; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -61,12 +61,12 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |||||
61 | connect(slice, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter())); |
|
61 | connect(slice, SIGNAL(hoverEnter()), s, SIGNAL(hoverEnter())); | |
62 | connect(slice, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave())); |
|
62 | connect(slice, SIGNAL(hoverLeave()), s, SIGNAL(hoverLeave())); | |
63 |
|
63 | |||
64 |
PieSlice |
|
64 | PieSliceData data = sliceData(s); | |
65 |
|
65 | |||
66 | if (m_animator) |
|
66 | if (m_animator) | |
67 |
m_animator->addAnimation(this, s, |
|
67 | m_animator->addAnimation(this, s, data, isEmpty); | |
68 | else |
|
68 | else | |
69 |
setLayout(s, |
|
69 | setLayout(s, data); | |
70 | } |
|
70 | } | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
@@ -93,8 +93,8 void PieChartItem::handleSliceChanged() | |||||
93 | { |
|
93 | { | |
94 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
94 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
95 | Q_ASSERT(m_slices.contains(slice)); |
|
95 | Q_ASSERT(m_slices.contains(slice)); | |
96 |
PieSlice |
|
96 | PieSliceData data = sliceData(slice); | |
97 |
updateLayout(slice, |
|
97 | updateLayout(slice, data); | |
98 | update(); |
|
98 | update(); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
@@ -125,16 +125,31 void PieChartItem::calculatePieLayout() | |||||
125 | m_pieRadius *= m_series->pieSize(); |
|
125 | m_pieRadius *= m_series->pieSize(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 |
PieSlice |
|
128 | PieSliceData PieChartItem::sliceData(QPieSlice *slice) | |
129 | { |
|
129 | { | |
130 |
PieSlice |
|
130 | PieSliceData sliceData; | |
131 | sliceLayout.m_center = PieSlice::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
131 | ||
132 | sliceLayout.m_radius = m_pieRadius; |
|
132 | // TODO: | |
133 | sliceLayout.m_startAngle = slice->startAngle(); |
|
133 | // sliceData = slice->m_data; | |
134 | sliceLayout.m_angleSpan = slice->m_angleSpan; |
|
134 | ||
135 | sliceLayout.m_pen = slice->m_slicePen; |
|
135 | sliceData.m_center = PieSlice::sliceCenter(m_pieCenter, m_pieRadius, slice); | |
136 |
slice |
|
136 | sliceData.m_radius = m_pieRadius; | |
137 | return sliceLayout; |
|
137 | sliceData.m_startAngle = slice->startAngle(); | |
|
138 | sliceData.m_angleSpan = slice->m_angleSpan; | |||
|
139 | ||||
|
140 | sliceData.m_pen = slice->m_slicePen; | |||
|
141 | sliceData.m_brush = slice->m_sliceBrush; | |||
|
142 | ||||
|
143 | sliceData.m_isExploded = slice->isExploded(); | |||
|
144 | sliceData.m_explodeDistanceFactor = slice->explodeDistanceFactor(); | |||
|
145 | ||||
|
146 | sliceData.m_labelVisible = slice->isLabelVisible(); | |||
|
147 | sliceData.m_labelText = slice->label(); | |||
|
148 | sliceData.m_labelFont = slice->labelFont(); | |||
|
149 | sliceData.m_labelArmLengthFactor = slice->labelArmLengthFactor(); | |||
|
150 | sliceData.m_labelArmPen = slice->labelArmPen(); | |||
|
151 | ||||
|
152 | return sliceData; | |||
138 | } |
|
153 | } | |
139 |
|
154 | |||
140 | PieLayout PieChartItem::calculateLayout() |
|
155 | PieLayout PieChartItem::calculateLayout() | |
@@ -143,7 +158,7 PieLayout PieChartItem::calculateLayout() | |||||
143 |
PieLayout |
|
158 | PieLayout layout; | |
144 | foreach (QPieSlice* s, m_series->slices()) { |
|
159 | foreach (QPieSlice* s, m_series->slices()) { | |
145 | if (m_slices.contains(s)) // calculate layout only for those slices that are already visible |
|
160 | if (m_slices.contains(s)) // calculate layout only for those slices that are already visible | |
146 |
layout.insert(s, |
|
161 | layout.insert(s, sliceData(s)); | |
147 | } |
|
162 | } | |
148 | return layout; |
|
163 | return layout; | |
149 | } |
|
164 | } | |
@@ -156,12 +171,12 void PieChartItem::applyLayout(const PieLayout &layout) | |||||
156 | setLayout(layout); |
|
171 | setLayout(layout); | |
157 | } |
|
172 | } | |
158 |
|
173 | |||
159 |
void PieChartItem::updateLayout(QPieSlice *slice, const PieSlice |
|
174 | void PieChartItem::updateLayout(QPieSlice *slice, const PieSliceData &sliceData) | |
160 | { |
|
175 | { | |
161 | if (m_animator) |
|
176 | if (m_animator) | |
162 |
m_animator->updateLayout(this, slice, la |
|
177 | m_animator->updateLayout(this, slice, sliceData); | |
163 | else |
|
178 | else | |
164 |
setLayout(slice, la |
|
179 | setLayout(slice, sliceData); | |
165 | } |
|
180 | } | |
166 |
|
181 | |||
167 | void PieChartItem::setLayout(const PieLayout &layout) |
|
182 | void PieChartItem::setLayout(const PieLayout &layout) | |
@@ -169,21 +184,18 void PieChartItem::setLayout(const PieLayout &layout) | |||||
169 | foreach (QPieSlice *slice, layout.keys()) { |
|
184 | foreach (QPieSlice *slice, layout.keys()) { | |
170 | PieSlice *s = m_slices.value(slice); |
|
185 | PieSlice *s = m_slices.value(slice); | |
171 | Q_ASSERT(s); |
|
186 | Q_ASSERT(s); | |
172 |
s->set |
|
187 | s->setSliceData(layout.value(slice)); | |
173 | s->updateData(slice); |
|
|||
174 | s->updateGeometry(); |
|
188 | s->updateGeometry(); | |
175 | s->update(); |
|
189 | s->update(); | |
176 | } |
|
190 | } | |
177 | } |
|
191 | } | |
178 |
|
192 | |||
179 |
void PieChartItem::setLayout(QPieSlice *slice, const PieSlice |
|
193 | void PieChartItem::setLayout(QPieSlice *slice, const PieSliceData &sliceData) | |
180 | { |
|
194 | { | |
181 | // find slice |
|
195 | // find slice | |
182 | PieSlice *s = m_slices.value(slice); |
|
196 | PieSlice *s = m_slices.value(slice); | |
183 | Q_ASSERT(s); |
|
197 | Q_ASSERT(s); | |
184 |
s->set |
|
198 | s->setSliceData(sliceData); | |
185 | if (m_series->m_slices.contains(slice)) // Slice has been deleted if not found. Animations ongoing... |
|
|||
186 | s->updateData(slice); |
|
|||
187 | s->updateGeometry(); |
|
199 | s->updateGeometry(); | |
188 | s->update(); |
|
200 | s->update(); | |
189 | } |
|
201 | } |
@@ -10,7 +10,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
10 | class QPieSlice; |
|
10 | class QPieSlice; | |
11 | class ChartPresenter; |
|
11 | class ChartPresenter; | |
12 |
|
12 | |||
13 |
typedef QHash<QPieSlice*, PieSlice |
|
13 | typedef QHash<QPieSlice*, PieSliceData> PieLayout; | |
14 |
|
14 | |||
15 | class PieChartItem : public QObject, public ChartItem |
|
15 | class PieChartItem : public QObject, public ChartItem | |
16 | { |
|
16 | { | |
@@ -36,12 +36,12 public Q_SLOTS: | |||||
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | void calculatePieLayout(); |
|
38 | void calculatePieLayout(); | |
39 |
PieSlice |
|
39 | PieSliceData sliceData(QPieSlice *slice); | |
40 | PieLayout calculateLayout(); |
|
40 | PieLayout calculateLayout(); | |
41 | void applyLayout(const PieLayout &layout); |
|
41 | void applyLayout(const PieLayout &layout); | |
42 |
void updateLayout(QPieSlice *slice, const PieSlice |
|
42 | void updateLayout(QPieSlice *slice, const PieSliceData &sliceData); | |
43 | void setLayout(const PieLayout &layout); |
|
43 | void setLayout(const PieLayout &layout); | |
44 |
void setLayout(QPieSlice *slice, const PieSlice |
|
44 | void setLayout(QPieSlice *slice, const PieSliceData &sliceData); | |
45 | void destroySlice(QPieSlice *slice); |
|
45 | void destroySlice(QPieSlice *slice); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: |
@@ -21,11 +21,7 QPointF offset(qreal angle, qreal length) | |||||
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | PieSlice::PieSlice(QGraphicsItem* parent) |
|
23 | PieSlice::PieSlice(QGraphicsItem* parent) | |
24 |
:QGraphicsObject(parent) |
|
24 | :QGraphicsObject(parent) | |
25 | m_isExploded(false), |
|
|||
26 | m_explodeDistanceFactor(0), |
|
|||
27 | m_labelVisible(false), |
|
|||
28 | m_labelArmLengthFactor(0) |
|
|||
29 | { |
|
25 | { | |
30 | setAcceptHoverEvents(true); |
|
26 | setAcceptHoverEvents(true); | |
31 | setAcceptedMouseButtons(Qt::LeftButton); |
|
27 | setAcceptedMouseButtons(Qt::LeftButton); | |
@@ -54,19 +50,19 void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option | |||||
54 | painter->setClipRect(parentItem()->boundingRect()); |
|
50 | painter->setClipRect(parentItem()->boundingRect()); | |
55 |
|
51 | |||
56 | painter->save(); |
|
52 | painter->save(); | |
57 |
painter->setPen(m_ |
|
53 | painter->setPen(m_data.m_pen); | |
58 |
painter->setBrush(m_ |
|
54 | painter->setBrush(m_data.m_brush); | |
59 | painter->drawPath(m_slicePath); |
|
55 | painter->drawPath(m_slicePath); | |
60 | painter->restore(); |
|
56 | painter->restore(); | |
61 |
|
57 | |||
62 | if (m_labelVisible) { |
|
58 | if (m_data.m_labelVisible) { | |
63 | painter->save(); |
|
59 | painter->save(); | |
64 | painter->setPen(m_labelArmPen); |
|
60 | painter->setPen(m_data.m_labelArmPen); | |
65 | painter->drawPath(m_labelArmPath); |
|
61 | painter->drawPath(m_labelArmPath); | |
66 | painter->restore(); |
|
62 | painter->restore(); | |
67 |
|
63 | |||
68 | painter->setFont(m_labelFont); |
|
64 | painter->setFont(m_data.m_labelFont); | |
69 | painter->drawText(m_labelTextRect.bottomLeft(), m_labelText); |
|
65 | painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText); | |
70 | } |
|
66 | } | |
71 | } |
|
67 | } | |
72 |
|
68 | |||
@@ -85,14 +81,14 void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) | |||||
85 | emit clicked(); |
|
81 | emit clicked(); | |
86 | } |
|
82 | } | |
87 |
|
83 | |||
88 |
void PieSlice::set |
|
84 | void PieSlice::setSliceData(PieSliceData sliceData) | |
89 | { |
|
85 | { | |
90 |
m_ |
|
86 | m_data = sliceData; | |
91 | } |
|
87 | } | |
92 |
|
88 | |||
93 | void PieSlice::updateGeometry() |
|
89 | void PieSlice::updateGeometry() | |
94 | { |
|
90 | { | |
95 |
if (m_ |
|
91 | if (m_data.m_radius <= 0) | |
96 | return; |
|
92 | return; | |
97 |
|
93 | |||
98 | prepareGeometryChange(); |
|
94 | prepareGeometryChange(); | |
@@ -100,14 +96,14 void PieSlice::updateGeometry() | |||||
100 | // update slice path |
|
96 | // update slice path | |
101 | qreal centerAngle; |
|
97 | qreal centerAngle; | |
102 | QPointF armStart; |
|
98 | QPointF armStart; | |
103 |
m_slicePath = slicePath(m_ |
|
99 | m_slicePath = slicePath(m_data.m_center, m_data.m_radius, m_data.m_startAngle, m_data.m_angleSpan, ¢erAngle, &armStart); | |
104 |
|
100 | |||
105 | // update text rect |
|
101 | // update text rect | |
106 | m_labelTextRect = labelTextRect(m_labelFont, m_labelText); |
|
102 | m_labelTextRect = labelTextRect(m_data.m_labelFont, m_data.m_labelText); | |
107 |
|
103 | |||
108 | // update label arm path |
|
104 | // update label arm path | |
109 | QPointF labelTextStart; |
|
105 | QPointF labelTextStart; | |
110 |
m_labelArmPath = labelArmPath(armStart, centerAngle, m_ |
|
106 | m_labelArmPath = labelArmPath(armStart, centerAngle, m_data.m_radius * m_data.m_labelArmLengthFactor, m_labelTextRect.width(), &labelTextStart); | |
111 |
|
107 | |||
112 | // update text position |
|
108 | // update text position | |
113 | m_labelTextRect.moveBottomLeft(labelTextStart); |
|
109 | m_labelTextRect.moveBottomLeft(labelTextStart); | |
@@ -116,20 +112,6 void PieSlice::updateGeometry() | |||||
116 | m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect); |
|
112 | m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect); | |
117 | } |
|
113 | } | |
118 |
|
114 | |||
119 | void PieSlice::updateData(const QPieSlice* sliceData) |
|
|||
120 | { |
|
|||
121 | // TODO: compare what has changes to avoid unneccesary geometry updates |
|
|||
122 |
|
||||
123 | m_isExploded = sliceData->isExploded(); |
|
|||
124 | m_explodeDistanceFactor = sliceData->explodeDistanceFactor(); |
|
|||
125 |
|
||||
126 | m_labelVisible = sliceData->isLabelVisible(); |
|
|||
127 | m_labelText = sliceData->label(); |
|
|||
128 | m_labelFont = sliceData->labelFont(); |
|
|||
129 | m_labelArmLengthFactor = sliceData->labelArmLengthFactor(); |
|
|||
130 | m_labelArmPen = sliceData->labelArmPen(); |
|
|||
131 | } |
|
|||
132 |
|
||||
133 | QPointF PieSlice::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) |
|
115 | QPointF PieSlice::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) | |
134 | { |
|
116 | { | |
135 | if (slice->isExploded()) { |
|
117 | if (slice->isExploded()) { |
@@ -16,15 +16,25 class PieChartItem; | |||||
16 | class PieSliceLabel; |
|
16 | class PieSliceLabel; | |
17 | class QPieSlice; |
|
17 | class QPieSlice; | |
18 |
|
18 | |||
19 |
class PieSlice |
|
19 | class PieSliceData | |
20 | { |
|
20 | { | |
21 | public: |
|
21 | public: | |
22 | QPointF m_center; |
|
22 | QPointF m_center; | |
23 | qreal m_radius; |
|
23 | qreal m_radius; | |
24 | qreal m_startAngle; |
|
24 | qreal m_startAngle; | |
25 | qreal m_angleSpan; |
|
25 | qreal m_angleSpan; | |
|
26 | ||||
26 | QPen m_pen; |
|
27 | QPen m_pen; | |
27 | QBrush m_brush; |
|
28 | QBrush m_brush; | |
|
29 | ||||
|
30 | bool m_isExploded; | |||
|
31 | qreal m_explodeDistanceFactor; | |||
|
32 | ||||
|
33 | bool m_labelVisible; | |||
|
34 | QString m_labelText; | |||
|
35 | QFont m_labelFont; | |||
|
36 | qreal m_labelArmLengthFactor; | |||
|
37 | QPen m_labelArmPen; | |||
28 | }; |
|
38 | }; | |
29 |
|
39 | |||
30 | class PieSlice : public QGraphicsObject |
|
40 | class PieSlice : public QGraphicsObject | |
@@ -49,30 +59,19 Q_SIGNALS: | |||||
49 | void hoverLeave(); |
|
59 | void hoverLeave(); | |
50 |
|
60 | |||
51 | public: |
|
61 | public: | |
52 |
void set |
|
62 | void setSliceData(PieSliceData sliceData); | |
53 | void updateGeometry(); |
|
63 | void updateGeometry(); | |
54 | void updateData(const QPieSlice *sliceData); |
|
|||
55 | static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice); |
|
64 | static QPointF sliceCenter(QPointF point, qreal radius, QPieSlice *slice); | |
56 | static QPainterPath slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal* centerAngle, QPointF* armStart); |
|
65 | static QPainterPath slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal* centerAngle, QPointF* armStart); | |
57 | static QPainterPath labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF* textStart); |
|
66 | static QPainterPath labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF* textStart); | |
58 | static QRectF labelTextRect(QFont font, QString text); |
|
67 | static QRectF labelTextRect(QFont font, QString text); | |
59 |
|
68 | |||
60 | private: |
|
69 | private: | |
61 |
PieSlice |
|
70 | PieSliceData m_data; | |
62 | QRectF m_boundingRect; |
|
71 | QRectF m_boundingRect; | |
63 |
|
||||
64 | QPainterPath m_slicePath; |
|
72 | QPainterPath m_slicePath; | |
65 | bool m_isExploded; |
|
|||
66 | qreal m_explodeDistanceFactor; |
|
|||
67 | bool m_labelVisible; |
|
|||
68 |
|
||||
69 | QPainterPath m_labelArmPath; |
|
73 | QPainterPath m_labelArmPath; | |
70 | qreal m_labelArmLengthFactor; |
|
|||
71 | QPen m_labelArmPen; |
|
|||
72 |
|
||||
73 | QRectF m_labelTextRect; |
|
74 | QRectF m_labelTextRect; | |
74 | QFont m_labelFont; |
|
|||
75 | QString m_labelText; |
|
|||
76 | }; |
|
75 | }; | |
77 |
|
76 | |||
78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now