@@ -1,238 +1,243 | |||||
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 "piechartitem_p.h" |
|
21 | #include "piechartitem_p.h" | |
22 | #include "piesliceitem_p.h" |
|
22 | #include "piesliceitem_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "qpieslice_p.h" |
|
24 | #include "qpieslice_p.h" | |
25 | #include "qpieseries.h" |
|
25 | #include "qpieseries.h" | |
26 | #include "qpieseries_p.h" |
|
26 | #include "qpieseries_p.h" | |
27 | #include "chartpresenter_p.h" |
|
27 | #include "chartpresenter_p.h" | |
28 | #include "chartdataset_p.h" |
|
28 | #include "chartdataset_p.h" | |
29 | #include "pieanimation_p.h" |
|
29 | #include "pieanimation_p.h" | |
30 | #include <QPainter> |
|
30 | #include <QPainter> | |
31 | #include <QTimer> |
|
31 | #include <QTimer> | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter) |
|
35 | PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter) | |
36 | :ChartItem(presenter), |
|
36 | :ChartItem(presenter), | |
37 | m_series(series), |
|
37 | m_series(series), | |
38 | m_animation(0) |
|
38 | m_animation(0) | |
39 | { |
|
39 | { | |
40 | Q_ASSERT(series); |
|
40 | Q_ASSERT(series); | |
41 |
|
41 | |||
42 | QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series); |
|
42 | QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series); | |
43 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
43 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
44 | connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>))); |
|
44 | connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>))); | |
45 | connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>))); |
|
45 | connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>))); | |
46 | connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout())); |
|
46 | connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout())); | |
47 | connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout())); |
|
47 | connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout())); | |
48 | connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout())); |
|
48 | connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout())); | |
49 | connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout())); |
|
49 | connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout())); | |
50 |
|
50 | |||
51 | // Note: the following does not affect as long as the item does not have anything to paint |
|
51 | // Note: the following does not affect as long as the item does not have anything to paint | |
52 | setZValue(ChartPresenter::PieSeriesZValue); |
|
52 | setZValue(ChartPresenter::PieSeriesZValue); | |
53 |
|
53 | |||
54 | // Note: will not create slice items until we have a proper rectangle to draw on. |
|
54 | // Note: will not create slice items until we have a proper rectangle to draw on. | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | PieChartItem::~PieChartItem() |
|
57 | PieChartItem::~PieChartItem() | |
58 | { |
|
58 | { | |
59 | // slices deleted automatically through QGraphicsItem |
|
59 | // slices deleted automatically through QGraphicsItem | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void PieChartItem::setAnimation(PieAnimation* animation) |
|
62 | void PieChartItem::setAnimation(PieAnimation* animation) | |
63 | { |
|
63 | { | |
64 | m_animation=animation; |
|
64 | m_animation=animation; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | ChartAnimation* PieChartItem::animation() const |
|
67 | ChartAnimation* PieChartItem::animation() const | |
68 | { |
|
68 | { | |
69 | return m_animation; |
|
69 | return m_animation; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void PieChartItem::handleGeometryChanged(const QRectF& rect) |
|
72 | void PieChartItem::handleGeometryChanged(const QRectF& rect) | |
73 | { |
|
73 | { | |
74 | prepareGeometryChange(); |
|
74 | prepareGeometryChange(); | |
75 | m_rect = rect; |
|
75 | m_rect = rect; | |
76 | updateLayout(); |
|
76 | updateLayout(); | |
77 |
|
77 | |||
78 | // This is for delayed initialization of the slice items during startup. |
|
78 | // This is for delayed initialization of the slice items during startup. | |
79 | // It ensures that startup animation originates from the correct position. |
|
79 | // It ensures that startup animation originates from the correct position. | |
80 | if (m_sliceItems.isEmpty()) |
|
80 | if (m_sliceItems.isEmpty()) | |
81 | handleSlicesAdded(m_series->slices()); |
|
81 | handleSlicesAdded(m_series->slices()); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
84 | void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
85 | { |
|
85 | { | |
86 | Q_UNUSED(minX); |
|
86 | Q_UNUSED(minX); | |
87 | Q_UNUSED(maxX); |
|
87 | Q_UNUSED(maxX); | |
88 | Q_UNUSED(minY); |
|
88 | Q_UNUSED(minY); | |
89 | Q_UNUSED(maxY); |
|
89 | Q_UNUSED(maxY); | |
90 | // does not apply to pie |
|
90 | // does not apply to pie | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
|
93 | void PieChartItem::handleDomainUpdated() | |||
|
94 | { | |||
|
95 | // does not apply to pie | |||
|
96 | } | |||
|
97 | ||||
93 | void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount) |
|
98 | void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount) | |
94 | { |
|
99 | { | |
95 | Q_UNUSED(min); |
|
100 | Q_UNUSED(min); | |
96 | Q_UNUSED(max); |
|
101 | Q_UNUSED(max); | |
97 | Q_UNUSED(tickXCount); |
|
102 | Q_UNUSED(tickXCount); | |
98 | // does not apply to pie |
|
103 | // does not apply to pie | |
99 | } |
|
104 | } | |
100 |
|
105 | |||
101 | void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount) |
|
106 | void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount) | |
102 | { |
|
107 | { | |
103 | Q_UNUSED(min); |
|
108 | Q_UNUSED(min); | |
104 | Q_UNUSED(max); |
|
109 | Q_UNUSED(max); | |
105 | Q_UNUSED(tickYCount); |
|
110 | Q_UNUSED(tickYCount); | |
106 | // does not apply to pie |
|
111 | // does not apply to pie | |
107 | } |
|
112 | } | |
108 |
|
113 | |||
109 | void PieChartItem::updateLayout() |
|
114 | void PieChartItem::updateLayout() | |
110 | { |
|
115 | { | |
111 | // find pie center coordinates |
|
116 | // find pie center coordinates | |
112 | m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition())); |
|
117 | m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition())); | |
113 | m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition())); |
|
118 | m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition())); | |
114 |
|
119 | |||
115 | // find maximum radius for pie |
|
120 | // find maximum radius for pie | |
116 | m_pieRadius = m_rect.height() / 2; |
|
121 | m_pieRadius = m_rect.height() / 2; | |
117 | if (m_rect.width() < m_rect.height()) |
|
122 | if (m_rect.width() < m_rect.height()) | |
118 | m_pieRadius = m_rect.width() / 2; |
|
123 | m_pieRadius = m_rect.width() / 2; | |
119 |
|
124 | |||
120 | m_donutInnerRadius = m_pieRadius; |
|
125 | m_donutInnerRadius = m_pieRadius; | |
121 | // apply size factor |
|
126 | // apply size factor | |
122 | m_pieRadius *= m_series->pieSize(); |
|
127 | m_pieRadius *= m_series->pieSize(); | |
123 | m_donutInnerRadius *= m_series->donutInnerSize(); |
|
128 | m_donutInnerRadius *= m_series->donutInnerSize(); | |
124 |
|
129 | |||
125 | // set layouts for existing slice items |
|
130 | // set layouts for existing slice items | |
126 | foreach (QPieSlice* slice, m_series->slices()) { |
|
131 | foreach (QPieSlice* slice, m_series->slices()) { | |
127 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
132 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
128 | if (sliceItem) { |
|
133 | if (sliceItem) { | |
129 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
134 | PieSliceData sliceData = updateSliceGeometry(slice); | |
130 | if (m_animation){ |
|
135 | if (m_animation){ | |
131 | presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); |
|
136 | presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); | |
132 | } |
|
137 | } | |
133 | else |
|
138 | else | |
134 | sliceItem->setLayout(sliceData); |
|
139 | sliceItem->setLayout(sliceData); | |
135 | } |
|
140 | } | |
136 | } |
|
141 | } | |
137 |
|
142 | |||
138 | update(); |
|
143 | update(); | |
139 | } |
|
144 | } | |
140 |
|
145 | |||
141 | void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) |
|
146 | void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |
142 | { |
|
147 | { | |
143 | // delay creating slice items until there is a proper rectangle |
|
148 | // delay creating slice items until there is a proper rectangle | |
144 | if (!m_rect.isValid() && m_sliceItems.isEmpty()) |
|
149 | if (!m_rect.isValid() && m_sliceItems.isEmpty()) | |
145 | return; |
|
150 | return; | |
146 |
|
151 | |||
147 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
152 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
148 |
|
153 | |||
149 | bool startupAnimation = m_sliceItems.isEmpty(); |
|
154 | bool startupAnimation = m_sliceItems.isEmpty(); | |
150 |
|
155 | |||
151 | foreach (QPieSlice *slice, slices) { |
|
156 | foreach (QPieSlice *slice, slices) { | |
152 | PieSliceItem* sliceItem = new PieSliceItem(this); |
|
157 | PieSliceItem* sliceItem = new PieSliceItem(this); | |
153 | m_sliceItems.insert(slice, sliceItem); |
|
158 | m_sliceItems.insert(slice, sliceItem); | |
154 |
|
159 | |||
155 | // Note: no need to connect to slice valueChanged() etc. |
|
160 | // Note: no need to connect to slice valueChanged() etc. | |
156 | // This is handled through calculatedDataChanged signal. |
|
161 | // This is handled through calculatedDataChanged signal. | |
157 | connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged())); |
|
162 | connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged())); | |
158 | connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged())); |
|
163 | connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged())); | |
159 | connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged())); |
|
164 | connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged())); | |
160 | connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged())); |
|
165 | connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged())); | |
161 | connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged())); |
|
166 | connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged())); | |
162 | connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged())); |
|
167 | connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged())); | |
163 |
|
168 | |||
164 | QPieSlicePrivate *p = QPieSlicePrivate::fromSlice(slice); |
|
169 | QPieSlicePrivate *p = QPieSlicePrivate::fromSlice(slice); | |
165 | connect(p, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged())); |
|
170 | connect(p, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged())); | |
166 | connect(p, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged())); |
|
171 | connect(p, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged())); | |
167 | connect(p, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged())); |
|
172 | connect(p, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged())); | |
168 | connect(p, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged())); |
|
173 | connect(p, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged())); | |
169 |
|
174 | |||
170 | connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked())); |
|
175 | connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked())); | |
171 | connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool))); |
|
176 | connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool))); | |
172 |
|
177 | |||
173 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
178 | PieSliceData sliceData = updateSliceGeometry(slice); | |
174 | if (m_animation) |
|
179 | if (m_animation) | |
175 | presenter()->startAnimation(m_animation->addSlice(sliceItem, sliceData, startupAnimation)); |
|
180 | presenter()->startAnimation(m_animation->addSlice(sliceItem, sliceData, startupAnimation)); | |
176 | else |
|
181 | else | |
177 | sliceItem->setLayout(sliceData); |
|
182 | sliceItem->setLayout(sliceData); | |
178 | } |
|
183 | } | |
179 | } |
|
184 | } | |
180 |
|
185 | |||
181 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices) |
|
186 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices) | |
182 | { |
|
187 | { | |
183 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
188 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
184 |
|
189 | |||
185 | foreach (QPieSlice *slice, slices) { |
|
190 | foreach (QPieSlice *slice, slices) { | |
186 |
|
191 | |||
187 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
192 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
188 |
|
193 | |||
189 | // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created |
|
194 | // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created | |
190 | if (!sliceItem) |
|
195 | if (!sliceItem) | |
191 | continue; |
|
196 | continue; | |
192 |
|
197 | |||
193 | m_sliceItems.remove(slice); |
|
198 | m_sliceItems.remove(slice); | |
194 |
|
199 | |||
195 | if (m_animation) |
|
200 | if (m_animation) | |
196 | presenter()->startAnimation(m_animation->removeSlice(sliceItem)); // animator deletes the PieSliceItem |
|
201 | presenter()->startAnimation(m_animation->removeSlice(sliceItem)); // animator deletes the PieSliceItem | |
197 | else |
|
202 | else | |
198 | delete sliceItem; |
|
203 | delete sliceItem; | |
199 | } |
|
204 | } | |
200 | } |
|
205 | } | |
201 |
|
206 | |||
202 | void PieChartItem::handleSliceChanged() |
|
207 | void PieChartItem::handleSliceChanged() | |
203 | { |
|
208 | { | |
204 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
209 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
205 | if (!slice) { |
|
210 | if (!slice) { | |
206 | QPieSlicePrivate* slicep = qobject_cast<QPieSlicePrivate *>(sender()); |
|
211 | QPieSlicePrivate* slicep = qobject_cast<QPieSlicePrivate *>(sender()); | |
207 | slice = slicep->q_ptr; |
|
212 | slice = slicep->q_ptr; | |
208 | } |
|
213 | } | |
209 | Q_ASSERT(m_sliceItems.contains(slice)); |
|
214 | Q_ASSERT(m_sliceItems.contains(slice)); | |
210 |
|
215 | |||
211 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
216 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
212 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
217 | PieSliceData sliceData = updateSliceGeometry(slice); | |
213 | if (m_animation) |
|
218 | if (m_animation) | |
214 | presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); |
|
219 | presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); | |
215 | else |
|
220 | else | |
216 | sliceItem->setLayout(sliceData); |
|
221 | sliceItem->setLayout(sliceData); | |
217 |
|
222 | |||
218 | update(); |
|
223 | update(); | |
219 | } |
|
224 | } | |
220 |
|
225 | |||
221 | void PieChartItem::handleSeriesVisibleChanged() |
|
226 | void PieChartItem::handleSeriesVisibleChanged() | |
222 | { |
|
227 | { | |
223 | setVisible(m_series->isVisible()); |
|
228 | setVisible(m_series->isVisible()); | |
224 | } |
|
229 | } | |
225 |
|
230 | |||
226 | PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) |
|
231 | PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) | |
227 | { |
|
232 | { | |
228 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; |
|
233 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; | |
229 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
234 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); | |
230 | sliceData.m_radius = m_pieRadius; |
|
235 | sliceData.m_radius = m_pieRadius; | |
231 | sliceData.m_donut = m_series->donut(); |
|
236 | sliceData.m_donut = m_series->donut(); | |
232 | sliceData.m_innerRadius = m_donutInnerRadius; |
|
237 | sliceData.m_innerRadius = m_donutInnerRadius; | |
233 | return sliceData; |
|
238 | return sliceData; | |
234 | } |
|
239 | } | |
235 |
|
240 | |||
236 | #include "moc_piechartitem_p.cpp" |
|
241 | #include "moc_piechartitem_p.cpp" | |
237 |
|
242 | |||
238 | QTCOMMERCIALCHART_END_NAMESPACE |
|
243 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,87 +1,88 | |||||
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 PIECHARTITEM_H |
|
30 | #ifndef PIECHARTITEM_H | |
31 | #define PIECHARTITEM_H |
|
31 | #define PIECHARTITEM_H | |
32 |
|
32 | |||
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "piesliceitem_p.h" |
|
35 | #include "piesliceitem_p.h" | |
36 |
|
36 | |||
37 | class QGraphicsItem; |
|
37 | class QGraphicsItem; | |
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 | class QPieSlice; |
|
39 | class QPieSlice; | |
40 | class ChartPresenter; |
|
40 | class ChartPresenter; | |
41 | class PieAnimation; |
|
41 | class PieAnimation; | |
42 |
|
42 | |||
43 | class PieChartItem : public ChartItem |
|
43 | class PieChartItem : public ChartItem | |
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 | explicit PieChartItem(QPieSeries *series, ChartPresenter *presenter); |
|
48 | explicit PieChartItem(QPieSeries *series, ChartPresenter *presenter); | |
49 | ~PieChartItem(); |
|
49 | ~PieChartItem(); | |
50 |
|
50 | |||
51 | // from QGraphicsItem |
|
51 | // from QGraphicsItem | |
52 | QRectF boundingRect() const { return m_rect; } |
|
52 | QRectF boundingRect() const { return m_rect; } | |
53 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} |
|
53 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} | |
54 |
|
54 | |||
55 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
56 | // from Chart |
|
56 | // from Chart | |
57 | virtual void handleGeometryChanged(const QRectF &rect); |
|
57 | virtual void handleGeometryChanged(const QRectF &rect); | |
58 | virtual void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
58 | virtual void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
|
59 | virtual void handleDomainUpdated(); | |||
59 | virtual void rangeXChanged(qreal min, qreal max, int tickXCount); |
|
60 | virtual void rangeXChanged(qreal min, qreal max, int tickXCount); | |
60 | virtual void rangeYChanged(qreal min, qreal max, int tickYCount); |
|
61 | virtual void rangeYChanged(qreal min, qreal max, int tickYCount); | |
61 |
|
62 | |||
62 | void updateLayout(); |
|
63 | void updateLayout(); | |
63 | void handleSlicesAdded(QList<QPieSlice*> slices); |
|
64 | void handleSlicesAdded(QList<QPieSlice*> slices); | |
64 | void handleSlicesRemoved(QList<QPieSlice*> slices); |
|
65 | void handleSlicesRemoved(QList<QPieSlice*> slices); | |
65 | void handleSliceChanged(); |
|
66 | void handleSliceChanged(); | |
66 | void handleSeriesVisibleChanged(); |
|
67 | void handleSeriesVisibleChanged(); | |
67 |
|
68 | |||
68 | void setAnimation(PieAnimation* animation); |
|
69 | void setAnimation(PieAnimation* animation); | |
69 | ChartAnimation* animation() const; |
|
70 | ChartAnimation* animation() const; | |
70 |
|
71 | |||
71 | private: |
|
72 | private: | |
72 | PieSliceData updateSliceGeometry(QPieSlice *slice); |
|
73 | PieSliceData updateSliceGeometry(QPieSlice *slice); | |
73 |
|
74 | |||
74 | private: |
|
75 | private: | |
75 | QHash<QPieSlice*, PieSliceItem*> m_sliceItems; |
|
76 | QHash<QPieSlice*, PieSliceItem*> m_sliceItems; | |
76 | QPieSeries *m_series; |
|
77 | QPieSeries *m_series; | |
77 | QRectF m_rect; |
|
78 | QRectF m_rect; | |
78 | QPointF m_pieCenter; |
|
79 | QPointF m_pieCenter; | |
79 | qreal m_pieRadius; |
|
80 | qreal m_pieRadius; | |
80 | qreal m_donutInnerRadius; |
|
81 | qreal m_donutInnerRadius; | |
81 | PieAnimation* m_animation; |
|
82 | PieAnimation* m_animation; | |
82 |
|
83 | |||
83 | }; |
|
84 | }; | |
84 |
|
85 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE | |
86 |
|
87 | |||
87 | #endif // PIECHARTITEM_H |
|
88 | #endif // PIECHARTITEM_H |
General Comments 0
You need to be logged in to leave comments.
Login now