@@ -1,222 +1,223 | |||||
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 "chartanimator_p.h" |
|
29 | #include "chartanimator_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 | { |
|
38 | { | |
39 | Q_ASSERT(series); |
|
39 | Q_ASSERT(series); | |
40 |
|
40 | |||
41 | QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series); |
|
41 | QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series); | |
42 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
42 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
43 | connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>))); |
|
43 | connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>))); | |
44 | connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>))); |
|
44 | connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>))); | |
45 | connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout())); |
|
45 | connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout())); | |
46 | connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout())); |
|
46 | connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout())); | |
47 | connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout())); |
|
47 | connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout())); | |
48 | connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout())); |
|
48 | connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout())); | |
49 |
|
49 | |||
50 | // Note: the following does not affect as long as the item does not have anything to paint |
|
50 | // Note: the following does not affect as long as the item does not have anything to paint | |
51 | setZValue(ChartPresenter::PieSeriesZValue); |
|
51 | setZValue(ChartPresenter::PieSeriesZValue); | |
52 |
|
52 | |||
53 | // Note: will not create slice items until we have a proper rectangle to draw on. |
|
53 | // Note: will not create slice items until we have a proper rectangle to draw on. | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | PieChartItem::~PieChartItem() |
|
56 | PieChartItem::~PieChartItem() | |
57 | { |
|
57 | { | |
58 | // slices deleted automatically through QGraphicsItem |
|
58 | // slices deleted automatically through QGraphicsItem | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void PieChartItem::handleGeometryChanged(const QRectF& rect) |
|
61 | void PieChartItem::handleGeometryChanged(const QRectF& rect) | |
62 | { |
|
62 | { | |
63 | prepareGeometryChange(); |
|
63 | prepareGeometryChange(); | |
64 | m_rect = rect; |
|
64 | m_rect = rect; | |
65 | updateLayout(); |
|
65 | updateLayout(); | |
66 |
|
66 | |||
67 | // This is for delayed initialization of the slice items during startup. |
|
67 | // This is for delayed initialization of the slice items during startup. | |
68 | // It ensures that startup animation originates from the correct position. |
|
68 | // It ensures that startup animation originates from the correct position. | |
69 | if (m_sliceItems.isEmpty()) |
|
69 | if (m_sliceItems.isEmpty()) | |
70 | handleSlicesAdded(m_series->slices()); |
|
70 | handleSlicesAdded(m_series->slices()); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
73 | void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
74 | { |
|
74 | { | |
75 | Q_UNUSED(minX); |
|
75 | Q_UNUSED(minX); | |
76 | Q_UNUSED(maxX); |
|
76 | Q_UNUSED(maxX); | |
77 | Q_UNUSED(minY); |
|
77 | Q_UNUSED(minY); | |
78 | Q_UNUSED(maxY); |
|
78 | Q_UNUSED(maxY); | |
79 | // does not apply to pie |
|
79 | // does not apply to pie | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount) |
|
82 | void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount) | |
83 | { |
|
83 | { | |
84 | Q_UNUSED(min); |
|
84 | Q_UNUSED(min); | |
85 | Q_UNUSED(max); |
|
85 | Q_UNUSED(max); | |
86 | Q_UNUSED(tickXCount); |
|
86 | Q_UNUSED(tickXCount); | |
87 | // does not apply to pie |
|
87 | // does not apply to pie | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount) |
|
90 | void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount) | |
91 | { |
|
91 | { | |
92 | Q_UNUSED(min); |
|
92 | Q_UNUSED(min); | |
93 | Q_UNUSED(max); |
|
93 | Q_UNUSED(max); | |
94 | Q_UNUSED(tickYCount); |
|
94 | Q_UNUSED(tickYCount); | |
95 | // does not apply to pie |
|
95 | // does not apply to pie | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void PieChartItem::updateLayout() |
|
98 | void PieChartItem::updateLayout() | |
99 | { |
|
99 | { | |
100 | // find pie center coordinates |
|
100 | // find pie center coordinates | |
101 | m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition())); |
|
101 | m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition())); | |
102 | m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition())); |
|
102 | m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition())); | |
103 |
|
103 | |||
104 | // find maximum radius for pie |
|
104 | // find maximum radius for pie | |
105 | m_pieRadius = m_rect.height() / 2; |
|
105 | m_pieRadius = m_rect.height() / 2; | |
106 | if (m_rect.width() < m_rect.height()) |
|
106 | if (m_rect.width() < m_rect.height()) | |
107 | m_pieRadius = m_rect.width() / 2; |
|
107 | m_pieRadius = m_rect.width() / 2; | |
108 |
|
108 | |||
109 | // apply size factor |
|
109 | // apply size factor | |
110 | m_pieRadius *= m_series->pieSize(); |
|
110 | m_pieRadius *= m_series->pieSize(); | |
111 |
|
111 | |||
112 | // set layouts for existing slice items |
|
112 | // set layouts for existing slice items | |
113 | foreach (QPieSlice* slice, m_series->slices()) { |
|
113 | foreach (QPieSlice* slice, m_series->slices()) { | |
114 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
114 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
115 | if (sliceItem) { |
|
115 | if (sliceItem) { | |
116 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
116 | PieSliceData sliceData = updateSliceGeometry(slice); | |
117 | if (animator()) |
|
117 | if (animator()) | |
118 | animator()->updateAnimation(this, sliceItem, sliceData); |
|
118 | animator()->updateAnimation(this, sliceItem, sliceData); | |
119 | else |
|
119 | else | |
120 | sliceItem->setLayout(sliceData); |
|
120 | sliceItem->setLayout(sliceData); | |
121 | } |
|
121 | } | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | update(); |
|
124 | update(); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) |
|
127 | void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |
128 | { |
|
128 | { | |
129 | // delay creating slice items until there is a proper rectangle |
|
129 | // delay creating slice items until there is a proper rectangle | |
130 | if (!m_rect.isValid() && m_sliceItems.isEmpty()) |
|
130 | if (!m_rect.isValid() && m_sliceItems.isEmpty()) | |
131 | return; |
|
131 | return; | |
132 |
|
132 | |||
133 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
133 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
134 |
|
134 | |||
135 | bool startupAnimation = m_sliceItems.isEmpty(); |
|
135 | bool startupAnimation = m_sliceItems.isEmpty(); | |
136 |
|
136 | |||
137 | foreach (QPieSlice *slice, slices) { |
|
137 | foreach (QPieSlice *slice, slices) { | |
138 | PieSliceItem* sliceItem = new PieSliceItem(this); |
|
138 | PieSliceItem* sliceItem = new PieSliceItem(this); | |
139 | m_sliceItems.insert(slice, sliceItem); |
|
139 | m_sliceItems.insert(slice, sliceItem); | |
140 |
|
140 | |||
141 | // Note: no need to connect to slice valueChanged() etc. |
|
141 | // Note: no need to connect to slice valueChanged() etc. | |
142 | // This is handled through calculatedDataChanged signal. |
|
142 | // This is handled through calculatedDataChanged signal. | |
143 | connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged())); |
|
143 | connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged())); | |
144 | connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged())); |
|
144 | connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged())); | |
145 | connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged())); |
|
145 | connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged())); | |
146 | connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged())); |
|
146 | connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged())); | |
147 | connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged())); |
|
147 | connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged())); | |
148 | connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged())); |
|
148 | connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged())); | |
149 |
|
149 | |||
150 | QPieSlicePrivate *p = QPieSlicePrivate::fromSlice(slice); |
|
150 | QPieSlicePrivate *p = QPieSlicePrivate::fromSlice(slice); | |
151 | connect(p, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged())); |
|
151 | connect(p, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged())); | |
152 | connect(p, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged())); |
|
152 | connect(p, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged())); | |
153 | connect(p, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged())); |
|
153 | connect(p, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged())); | |
154 | connect(p, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged())); |
|
154 | connect(p, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged())); | |
155 |
|
155 | |||
156 | connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked())); |
|
156 | connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked())); | |
157 | connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool))); |
|
157 | connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool))); | |
158 |
|
158 | |||
159 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
159 | PieSliceData sliceData = updateSliceGeometry(slice); | |
160 | if (animator()) |
|
160 | if (animator()) | |
161 | animator()->addAnimation(this, sliceItem, sliceData, startupAnimation); |
|
161 | animator()->addAnimation(this, sliceItem, sliceData, startupAnimation); | |
162 | else |
|
162 | else | |
163 | sliceItem->setLayout(sliceData); |
|
163 | sliceItem->setLayout(sliceData); | |
164 | } |
|
164 | } | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices) |
|
167 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices) | |
168 | { |
|
168 | { | |
169 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
169 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
170 |
|
170 | |||
171 | foreach (QPieSlice *slice, slices) { |
|
171 | foreach (QPieSlice *slice, slices) { | |
172 |
|
172 | |||
173 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
173 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
174 |
|
174 | |||
175 | // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created |
|
175 | // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created | |
176 | if (!sliceItem) |
|
176 | if (!sliceItem) | |
177 | continue; |
|
177 | continue; | |
178 |
|
178 | |||
179 | m_sliceItems.remove(slice); |
|
179 | m_sliceItems.remove(slice); | |
180 |
|
180 | |||
181 | if (animator()) |
|
181 | if (animator()) | |
182 | animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem |
|
182 | animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem | |
183 | else |
|
183 | else | |
184 | delete sliceItem; |
|
184 | delete sliceItem; | |
185 | } |
|
185 | } | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void PieChartItem::handleSliceChanged() |
|
188 | void PieChartItem::handleSliceChanged() | |
189 | { |
|
189 | { | |
190 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
190 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
191 | if (!slice) { |
|
191 | if (!slice) { | |
192 | QPieSlicePrivate* slicep = qobject_cast<QPieSlicePrivate *>(sender()); |
|
192 | QPieSlicePrivate* slicep = qobject_cast<QPieSlicePrivate *>(sender()); | |
193 | slice = slicep->q_ptr; |
|
193 | slice = slicep->q_ptr; | |
194 | } |
|
194 | } | |
195 | Q_ASSERT(m_sliceItems.contains(slice)); |
|
195 | Q_ASSERT(m_sliceItems.contains(slice)); | |
196 |
|
196 | |||
197 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
197 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
198 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
198 | PieSliceData sliceData = updateSliceGeometry(slice); | |
199 | if (animator()) |
|
199 | if (animator()) | |
200 | animator()->updateAnimation(this, sliceItem, sliceData); |
|
200 | animator()->updateAnimation(this, sliceItem, sliceData); | |
201 | else |
|
201 | else | |
202 | sliceItem->setLayout(sliceData); |
|
202 | sliceItem->setLayout(sliceData); | |
203 |
|
203 | |||
204 | update(); |
|
204 | update(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void PieChartItem::handleSeriesVisibleChanged() |
|
207 | void PieChartItem::handleSeriesVisibleChanged() | |
208 | { |
|
208 | { | |
209 | setVisible(m_series->isVisible()); |
|
209 | setVisible(m_series->isVisible()); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) |
|
212 | PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) | |
213 | { |
|
213 | { | |
214 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; |
|
214 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; | |
215 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
215 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); | |
216 | sliceData.m_radius = m_pieRadius; |
|
216 | sliceData.m_radius = m_pieRadius; | |
|
217 | sliceData.m_donut = m_series->donut(); | |||
217 | return sliceData; |
|
218 | return sliceData; | |
218 | } |
|
219 | } | |
219 |
|
220 | |||
220 | #include "moc_piechartitem_p.cpp" |
|
221 | #include "moc_piechartitem_p.cpp" | |
221 |
|
222 | |||
222 | QTCOMMERCIALCHART_END_NAMESPACE |
|
223 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,142 +1,144 | |||||
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 PIESLICEDATA_P_H |
|
30 | #ifndef PIESLICEDATA_P_H | |
31 | #define PIESLICEDATA_P_H |
|
31 | #define PIESLICEDATA_P_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "qpieslice.h" |
|
34 | #include "qpieslice.h" | |
35 | #include <QPen> |
|
35 | #include <QPen> | |
36 | #include <QBrush> |
|
36 | #include <QBrush> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | template <class T> |
|
40 | template <class T> | |
41 | class Themed : public T |
|
41 | class Themed : public T | |
42 | { |
|
42 | { | |
43 | public: |
|
43 | public: | |
44 | Themed():m_isThemed(true) {} |
|
44 | Themed():m_isThemed(true) {} | |
45 |
|
45 | |||
46 | inline T &operator=(const T &other) { return T::operator =(other); } |
|
46 | inline T &operator=(const T &other) { return T::operator =(other); } | |
47 |
|
47 | |||
48 | inline bool operator!=(const T &other) const { return T::operator !=(other); } |
|
48 | inline bool operator!=(const T &other) const { return T::operator !=(other); } | |
49 | inline bool operator!=(const Themed &other) const |
|
49 | inline bool operator!=(const Themed &other) const | |
50 | { |
|
50 | { | |
51 | if (T::operator !=(other)) |
|
51 | if (T::operator !=(other)) | |
52 | return true; |
|
52 | return true; | |
53 |
|
53 | |||
54 | if (m_isThemed != other.m_isThemed) |
|
54 | if (m_isThemed != other.m_isThemed) | |
55 | return true; |
|
55 | return true; | |
56 |
|
56 | |||
57 | return false; |
|
57 | return false; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | inline void setThemed(bool state) { m_isThemed = state; } |
|
60 | inline void setThemed(bool state) { m_isThemed = state; } | |
61 | inline bool isThemed() const { return m_isThemed; } |
|
61 | inline bool isThemed() const { return m_isThemed; } | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | bool m_isThemed; |
|
64 | bool m_isThemed; | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | class PieSliceData |
|
67 | class PieSliceData | |
68 | { |
|
68 | { | |
69 | public: |
|
69 | public: | |
70 | PieSliceData() |
|
70 | PieSliceData() | |
71 | { |
|
71 | { | |
72 | m_value = 0; |
|
72 | m_value = 0; | |
73 |
|
73 | |||
74 | m_isExploded = false; |
|
74 | m_isExploded = false; | |
75 | m_explodeDistanceFactor = 0.15; |
|
75 | m_explodeDistanceFactor = 0.15; | |
76 |
|
76 | |||
77 | m_isLabelVisible = false; |
|
77 | m_isLabelVisible = false; | |
78 | m_labelPosition = QPieSlice::LabelOutside; |
|
78 | m_labelPosition = QPieSlice::LabelOutside; | |
79 | m_labelArmLengthFactor = 0.15; |
|
79 | m_labelArmLengthFactor = 0.15; | |
80 |
|
80 | |||
81 | m_percentage = 0; |
|
81 | m_percentage = 0; | |
82 | m_radius = 0; |
|
82 | m_radius = 0; | |
83 | m_startAngle = 0; |
|
83 | m_startAngle = 0; | |
84 | m_angleSpan = 0; |
|
84 | m_angleSpan = 0; | |
|
85 | m_donut = false; | |||
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | bool operator!=(const PieSliceData &other) const |
|
88 | bool operator!=(const PieSliceData &other) const | |
88 | { |
|
89 | { | |
89 | if (!qFuzzyIsNull(m_value - other.m_value)) |
|
90 | if (!qFuzzyIsNull(m_value - other.m_value)) | |
90 | return true; |
|
91 | return true; | |
91 |
|
92 | |||
92 | if (m_slicePen != other.m_slicePen || |
|
93 | if (m_slicePen != other.m_slicePen || | |
93 | m_sliceBrush != other.m_sliceBrush) |
|
94 | m_sliceBrush != other.m_sliceBrush) | |
94 | return true; |
|
95 | return true; | |
95 |
|
96 | |||
96 | if (m_isExploded != other.m_isExploded || |
|
97 | if (m_isExploded != other.m_isExploded || | |
97 | !qFuzzyIsNull(m_explodeDistanceFactor - other.m_explodeDistanceFactor)) |
|
98 | !qFuzzyIsNull(m_explodeDistanceFactor - other.m_explodeDistanceFactor)) | |
98 | return true; |
|
99 | return true; | |
99 |
|
100 | |||
100 | if (m_isLabelVisible != other.m_isLabelVisible || |
|
101 | if (m_isLabelVisible != other.m_isLabelVisible || | |
101 | m_labelText != other.m_labelText || |
|
102 | m_labelText != other.m_labelText || | |
102 | m_labelFont != other.m_labelFont || |
|
103 | m_labelFont != other.m_labelFont || | |
103 | m_labelPosition != other.m_labelPosition || |
|
104 | m_labelPosition != other.m_labelPosition || | |
104 | !qFuzzyIsNull(m_labelArmLengthFactor - other.m_labelArmLengthFactor) || |
|
105 | !qFuzzyIsNull(m_labelArmLengthFactor - other.m_labelArmLengthFactor) || | |
105 | m_labelBrush != other.m_labelBrush) |
|
106 | m_labelBrush != other.m_labelBrush) | |
106 | return true; |
|
107 | return true; | |
107 |
|
108 | |||
108 | if (!qFuzzyIsNull(m_percentage - other.m_percentage) || |
|
109 | if (!qFuzzyIsNull(m_percentage - other.m_percentage) || | |
109 | m_center != other.m_center || |
|
110 | m_center != other.m_center || | |
110 | !qFuzzyIsNull(m_radius - other.m_radius) || |
|
111 | !qFuzzyIsNull(m_radius - other.m_radius) || | |
111 | !qFuzzyIsNull(m_startAngle - other.m_startAngle) || |
|
112 | !qFuzzyIsNull(m_startAngle - other.m_startAngle) || | |
112 | !qFuzzyIsNull(m_angleSpan - other.m_angleSpan)) |
|
113 | !qFuzzyIsNull(m_angleSpan - other.m_angleSpan)) | |
113 | return true; |
|
114 | return true; | |
114 |
|
115 | |||
115 | return false; |
|
116 | return false; | |
116 | } |
|
117 | } | |
117 |
|
118 | |||
118 | qreal m_value; |
|
119 | qreal m_value; | |
119 |
|
120 | |||
120 | Themed<QPen> m_slicePen; |
|
121 | Themed<QPen> m_slicePen; | |
121 | Themed<QBrush> m_sliceBrush; |
|
122 | Themed<QBrush> m_sliceBrush; | |
122 |
|
123 | |||
123 | bool m_isExploded; |
|
124 | bool m_isExploded; | |
124 | qreal m_explodeDistanceFactor; |
|
125 | qreal m_explodeDistanceFactor; | |
125 |
|
126 | |||
126 | bool m_isLabelVisible; |
|
127 | bool m_isLabelVisible; | |
127 | QString m_labelText; |
|
128 | QString m_labelText; | |
128 | Themed<QFont> m_labelFont; |
|
129 | Themed<QFont> m_labelFont; | |
129 | QPieSlice::LabelPosition m_labelPosition; |
|
130 | QPieSlice::LabelPosition m_labelPosition; | |
130 | qreal m_labelArmLengthFactor; |
|
131 | qreal m_labelArmLengthFactor; | |
131 | Themed<QBrush> m_labelBrush; |
|
132 | Themed<QBrush> m_labelBrush; | |
132 |
|
133 | |||
133 | qreal m_percentage; |
|
134 | qreal m_percentage; | |
134 | QPointF m_center; |
|
135 | QPointF m_center; | |
135 | qreal m_radius; |
|
136 | qreal m_radius; | |
136 | qreal m_startAngle; |
|
137 | qreal m_startAngle; | |
137 | qreal m_angleSpan; |
|
138 | qreal m_angleSpan; | |
|
139 | bool m_donut; | |||
138 | }; |
|
140 | }; | |
139 |
|
141 | |||
140 | QTCOMMERCIALCHART_END_NAMESPACE |
|
142 | QTCOMMERCIALCHART_END_NAMESPACE | |
141 |
|
143 | |||
142 | #endif // PIESLICEDATA_P_H |
|
144 | #endif // PIESLICEDATA_P_H |
@@ -1,234 +1,242 | |||||
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 "piesliceitem_p.h" |
|
21 | #include "piesliceitem_p.h" | |
22 | #include "piechartitem_p.h" |
|
22 | #include "piechartitem_p.h" | |
23 | #include "qpieseries.h" |
|
23 | #include "qpieseries.h" | |
24 | #include "qpieslice.h" |
|
24 | #include "qpieslice.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include <QPainter> |
|
26 | #include <QPainter> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QGraphicsSceneEvent> |
|
28 | #include <QGraphicsSceneEvent> | |
29 | #include <QTime> |
|
29 | #include <QTime> | |
30 | #include <QDebug> |
|
30 | #include <QDebug> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | QPointF offset(qreal angle, qreal length) |
|
34 | QPointF offset(qreal angle, qreal length) | |
35 | { |
|
35 | { | |
36 | qreal dx = qSin(angle*(M_PI/180)) * length; |
|
36 | qreal dx = qSin(angle*(M_PI/180)) * length; | |
37 | qreal dy = qCos(angle*(M_PI/180)) * length; |
|
37 | qreal dy = qCos(angle*(M_PI/180)) * length; | |
38 | return QPointF(dx, -dy); |
|
38 | return QPointF(dx, -dy); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | PieSliceItem::PieSliceItem(QGraphicsItem* parent) |
|
41 | PieSliceItem::PieSliceItem(QGraphicsItem* parent) | |
42 | :QGraphicsObject(parent), |
|
42 | :QGraphicsObject(parent), | |
43 | m_hovered(false) |
|
43 | m_hovered(false) | |
44 | { |
|
44 | { | |
45 | setAcceptHoverEvents(true); |
|
45 | setAcceptHoverEvents(true); | |
46 | setAcceptedMouseButtons(Qt::MouseButtonMask); |
|
46 | setAcceptedMouseButtons(Qt::MouseButtonMask); | |
47 | setZValue(ChartPresenter::PieSeriesZValue); |
|
47 | setZValue(ChartPresenter::PieSeriesZValue); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | PieSliceItem::~PieSliceItem() |
|
50 | PieSliceItem::~PieSliceItem() | |
51 | { |
|
51 | { | |
52 | // If user is hovering over the slice and it gets destroyed we do |
|
52 | // If user is hovering over the slice and it gets destroyed we do | |
53 | // not get a hover leave event. So we must emit the signal here. |
|
53 | // not get a hover leave event. So we must emit the signal here. | |
54 | if (m_hovered) |
|
54 | if (m_hovered) | |
55 | emit hovered(false); |
|
55 | emit hovered(false); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | QRectF PieSliceItem::boundingRect() const |
|
58 | QRectF PieSliceItem::boundingRect() const | |
59 | { |
|
59 | { | |
60 | return m_boundingRect; |
|
60 | return m_boundingRect; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | QPainterPath PieSliceItem::shape() const |
|
63 | QPainterPath PieSliceItem::shape() const | |
64 | { |
|
64 | { | |
65 | // Don't include the label and label arm. |
|
65 | // Don't include the label and label arm. | |
66 | // This is used to detect a mouse clicks. We do not want clicks from label. |
|
66 | // This is used to detect a mouse clicks. We do not want clicks from label. | |
67 | return m_slicePath; |
|
67 | return m_slicePath; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) |
|
70 | void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) | |
71 | { |
|
71 | { | |
72 | painter->save(); |
|
72 | painter->save(); | |
73 | painter->setClipRect(parentItem()->boundingRect()); |
|
73 | painter->setClipRect(parentItem()->boundingRect()); | |
74 | painter->setPen(m_data.m_slicePen); |
|
74 | painter->setPen(m_data.m_slicePen); | |
75 | painter->setBrush(m_data.m_sliceBrush); |
|
75 | painter->setBrush(m_data.m_sliceBrush); | |
76 | painter->drawPath(m_slicePath); |
|
76 | painter->drawPath(m_slicePath); | |
77 | painter->restore(); |
|
77 | painter->restore(); | |
78 |
|
78 | |||
79 | if (m_data.m_isLabelVisible) { |
|
79 | if (m_data.m_isLabelVisible) { | |
80 | painter->save(); |
|
80 | painter->save(); | |
81 |
|
81 | |||
82 | // Pen for label arm not defined in the QPieSeries api, let's use brush's color instead |
|
82 | // Pen for label arm not defined in the QPieSeries api, let's use brush's color instead | |
83 | // Also, the drawText actually uses the pen color for the text color (unlike QGraphicsSimpleTextItem) |
|
83 | // Also, the drawText actually uses the pen color for the text color (unlike QGraphicsSimpleTextItem) | |
84 | painter->setPen(m_data.m_labelBrush.color()); |
|
84 | painter->setPen(m_data.m_labelBrush.color()); | |
85 | painter->setBrush(m_data.m_labelBrush); |
|
85 | painter->setBrush(m_data.m_labelBrush); | |
86 | painter->setFont(m_data.m_labelFont); |
|
86 | painter->setFont(m_data.m_labelFont); | |
87 | if (m_data.m_labelPosition == QPieSlice::LabelOutside) { |
|
87 | if (m_data.m_labelPosition == QPieSlice::LabelOutside) { | |
88 | painter->setClipRect(parentItem()->boundingRect()); |
|
88 | painter->setClipRect(parentItem()->boundingRect()); | |
89 | painter->strokePath(m_labelArmPath, m_data.m_labelBrush.color()); |
|
89 | painter->strokePath(m_labelArmPath, m_data.m_labelBrush.color()); | |
90 | } else { // QPieSlice::LabelInside |
|
90 | } else { // QPieSlice::LabelInside | |
91 | painter->setClipPath(m_slicePath); |
|
91 | painter->setClipPath(m_slicePath); | |
92 | } |
|
92 | } | |
93 | painter->drawText(m_labelTextRect, Qt::AlignCenter, m_data.m_labelText); |
|
93 | painter->drawText(m_labelTextRect, Qt::AlignCenter, m_data.m_labelText); | |
94 |
|
94 | |||
95 | painter->restore(); |
|
95 | painter->restore(); | |
96 | } |
|
96 | } | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
99 | void PieSliceItem::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) | |
100 | { |
|
100 | { | |
101 | m_hovered = true; |
|
101 | m_hovered = true; | |
102 | emit hovered(true); |
|
102 | emit hovered(true); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
105 | void PieSliceItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) | |
106 | { |
|
106 | { | |
107 | m_hovered = false; |
|
107 | m_hovered = false; | |
108 | emit hovered(false); |
|
108 | emit hovered(false); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
111 | void PieSliceItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
112 | { |
|
112 | { | |
113 | emit clicked(event->buttons()); |
|
113 | emit clicked(event->buttons()); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void PieSliceItem::setLayout(const PieSliceData &sliceData) |
|
116 | void PieSliceItem::setLayout(const PieSliceData &sliceData) | |
117 | { |
|
117 | { | |
118 | m_data = sliceData; |
|
118 | m_data = sliceData; | |
119 | updateGeometry(); |
|
119 | updateGeometry(); | |
120 | update(); |
|
120 | update(); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void PieSliceItem::updateGeometry() |
|
123 | void PieSliceItem::updateGeometry() | |
124 | { |
|
124 | { | |
125 | if (m_data.m_radius <= 0) |
|
125 | if (m_data.m_radius <= 0) | |
126 | return; |
|
126 | return; | |
127 |
|
127 | |||
128 | prepareGeometryChange(); |
|
128 | prepareGeometryChange(); | |
129 |
|
129 | |||
130 | // slice path |
|
130 | // slice path | |
131 | qreal centerAngle; |
|
131 | qreal centerAngle; | |
132 | QPointF armStart; |
|
132 | QPointF armStart; | |
133 | m_slicePath = slicePath(m_data.m_center, m_data.m_radius, m_data.m_startAngle, m_data.m_angleSpan, ¢erAngle, &armStart); |
|
133 | m_slicePath = slicePath(m_data.m_center, m_data.m_radius, m_data.m_startAngle, m_data.m_angleSpan, ¢erAngle, &armStart); | |
134 |
|
134 | |||
135 | // text rect |
|
135 | // text rect | |
136 | QFontMetricsF fm(m_data.m_labelFont); |
|
136 | QFontMetricsF fm(m_data.m_labelFont); | |
137 | m_labelTextRect = QRectF(0, 0, fm.width(m_data.m_labelText), fm.height()); |
|
137 | m_labelTextRect = QRectF(0, 0, fm.width(m_data.m_labelText), fm.height()); | |
138 |
|
138 | |||
139 | // label arm path |
|
139 | // label arm path | |
140 | QPointF labelTextStart; |
|
140 | QPointF labelTextStart; | |
141 | m_labelArmPath = labelArmPath(armStart, centerAngle, m_data.m_radius * m_data.m_labelArmLengthFactor, m_labelTextRect.width(), &labelTextStart); |
|
141 | m_labelArmPath = labelArmPath(armStart, centerAngle, m_data.m_radius * m_data.m_labelArmLengthFactor, m_labelTextRect.width(), &labelTextStart); | |
142 |
|
142 | |||
143 | // text position |
|
143 | // text position | |
144 | if (m_data.m_labelPosition == QPieSlice::LabelOutside) |
|
144 | if (m_data.m_labelPosition == QPieSlice::LabelOutside) | |
145 | m_labelTextRect.moveBottomLeft(labelTextStart); |
|
145 | m_labelTextRect.moveBottomLeft(labelTextStart); | |
146 | else {// QPieSlice::LabelInside |
|
146 | else {// QPieSlice::LabelInside | |
147 | QPointF sliceCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2); |
|
147 | QPointF sliceCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2); | |
148 | m_labelTextRect.moveCenter(sliceCenter); |
|
148 | m_labelTextRect.moveCenter(sliceCenter); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | // bounding rect |
|
151 | // bounding rect | |
152 | if (m_data.m_isLabelVisible) |
|
152 | if (m_data.m_isLabelVisible) | |
153 | m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect); |
|
153 | m_boundingRect = m_slicePath.boundingRect().united(m_labelArmPath.boundingRect()).united(m_labelTextRect); | |
154 | else |
|
154 | else | |
155 | m_boundingRect = m_slicePath.boundingRect(); |
|
155 | m_boundingRect = m_slicePath.boundingRect(); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) |
|
158 | QPointF PieSliceItem::sliceCenter(QPointF point, qreal radius, QPieSlice *slice) | |
159 | { |
|
159 | { | |
160 | if (slice->isExploded()) { |
|
160 | if (slice->isExploded()) { | |
161 | qreal centerAngle = slice->startAngle() + (slice->angleSpan()/2); |
|
161 | qreal centerAngle = slice->startAngle() + (slice->angleSpan()/2); | |
162 | qreal len = radius * slice->explodeDistanceFactor(); |
|
162 | qreal len = radius * slice->explodeDistanceFactor(); | |
163 | point += offset(centerAngle, len); |
|
163 | point += offset(centerAngle, len); | |
164 | } |
|
164 | } | |
165 | return point; |
|
165 | return point; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF* armStart) |
|
168 | QPainterPath PieSliceItem::slicePath(QPointF center, qreal radius, qreal startAngle, qreal angleSpan, qreal *centerAngle, QPointF* armStart) | |
169 | { |
|
169 | { | |
170 | // calculate center angle |
|
170 | // calculate center angle | |
171 | *centerAngle = startAngle + (angleSpan/2); |
|
171 | *centerAngle = startAngle + (angleSpan/2); | |
172 |
|
172 | |||
173 | // calculate slice rectangle |
|
173 | // calculate slice rectangle | |
174 | QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2); |
|
174 | QRectF rect(center.x()-radius, center.y()-radius, radius*2, radius*2); | |
175 |
|
175 | |||
176 | // slice path |
|
176 | // slice path | |
177 | // TODO: draw the shape so that it might have a hole in the center |
|
|||
178 | QPainterPath path; |
|
177 | QPainterPath path; | |
179 | path.moveTo(rect.center()); |
|
178 | if (m_data.m_donut) { | |
180 | path.arcTo(rect, -startAngle + 90, -angleSpan); |
|
179 | qreal donutFraction = 5.0; | |
181 | path.closeSubpath(); |
|
180 | QRectF insideRect = rect.adjusted(rect.width() / donutFraction, rect.height() / donutFraction, -rect.width() / donutFraction, -rect.height() / donutFraction); | |
|
181 | path.arcMoveTo(rect, -startAngle + 90); | |||
|
182 | path.arcTo(rect, -startAngle + 90, -angleSpan); | |||
|
183 | path.arcTo(insideRect, -startAngle + 90 - angleSpan, angleSpan); | |||
|
184 | path.closeSubpath(); | |||
|
185 | } else { | |||
|
186 | path.moveTo(rect.center()); | |||
|
187 | path.arcTo(rect, -startAngle + 90, -angleSpan); | |||
|
188 | path.closeSubpath(); | |||
|
189 | } | |||
182 |
|
190 | |||
183 | // calculate label arm start point |
|
191 | // calculate label arm start point | |
184 | *armStart = center; |
|
192 | *armStart = center; | |
185 | *armStart += offset(*centerAngle, radius + PIESLICE_LABEL_GAP); |
|
193 | *armStart += offset(*centerAngle, radius + PIESLICE_LABEL_GAP); | |
186 |
|
194 | |||
187 | return path; |
|
195 | return path; | |
188 | } |
|
196 | } | |
189 |
|
197 | |||
190 | QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart) |
|
198 | QPainterPath PieSliceItem::labelArmPath(QPointF start, qreal angle, qreal length, qreal textWidth, QPointF *textStart) | |
191 | { |
|
199 | { | |
192 | // Normalize the angle to 0-360 range |
|
200 | // Normalize the angle to 0-360 range | |
193 | // NOTE: We are using int here on purpose. Depenging on platform and hardware |
|
201 | // NOTE: We are using int here on purpose. Depenging on platform and hardware | |
194 | // qreal can be a double, float or something the user gives to the Qt configure |
|
202 | // qreal can be a double, float or something the user gives to the Qt configure | |
195 | // (QT_COORD_TYPE). Compilers do not seem to support modulo for double or float |
|
203 | // (QT_COORD_TYPE). Compilers do not seem to support modulo for double or float | |
196 | // but there are fmod() and fmodf() functions for that. So instead of some #ifdef |
|
204 | // but there are fmod() and fmodf() functions for that. So instead of some #ifdef | |
197 | // that might break we just use int. Precision for this is just fine for our needs. |
|
205 | // that might break we just use int. Precision for this is just fine for our needs. | |
198 | int normalized = angle * 10.0; |
|
206 | int normalized = angle * 10.0; | |
199 | normalized = normalized % 3600; |
|
207 | normalized = normalized % 3600; | |
200 | if (normalized < 0) |
|
208 | if (normalized < 0) | |
201 | normalized += 3600; |
|
209 | normalized += 3600; | |
202 | angle = (qreal) normalized / 10.0; |
|
210 | angle = (qreal) normalized / 10.0; | |
203 |
|
211 | |||
204 | // prevent label arm pointing straight down because it will look bad |
|
212 | // prevent label arm pointing straight down because it will look bad | |
205 | if (angle < 180 && angle > 170) |
|
213 | if (angle < 180 && angle > 170) | |
206 | angle = 170; |
|
214 | angle = 170; | |
207 | if (angle > 180 && angle < 190) |
|
215 | if (angle > 180 && angle < 190) | |
208 | angle = 190; |
|
216 | angle = 190; | |
209 |
|
217 | |||
210 | // line from slice to label |
|
218 | // line from slice to label | |
211 | QPointF parm1 = start + offset(angle, length); |
|
219 | QPointF parm1 = start + offset(angle, length); | |
212 |
|
220 | |||
213 | // line to underline the label |
|
221 | // line to underline the label | |
214 | QPointF parm2 = parm1; |
|
222 | QPointF parm2 = parm1; | |
215 | if (angle < 180) { // arm swings the other way on the left side |
|
223 | if (angle < 180) { // arm swings the other way on the left side | |
216 |
|
|
224 | parm2 += QPointF(textWidth, 0); | |
217 |
|
|
225 | *textStart = parm1; | |
218 | } |
|
226 | } | |
219 | else { |
|
227 | else { | |
220 |
|
|
228 | parm2 += QPointF(-textWidth,0); | |
221 |
|
|
229 | *textStart = parm2; | |
222 | } |
|
230 | } | |
223 |
|
231 | |||
224 | QPainterPath path; |
|
232 | QPainterPath path; | |
225 | path.moveTo(start); |
|
233 | path.moveTo(start); | |
226 | path.lineTo(parm1); |
|
234 | path.lineTo(parm1); | |
227 | path.lineTo(parm2); |
|
235 | path.lineTo(parm2); | |
228 |
|
236 | |||
229 | return path; |
|
237 | return path; | |
230 | } |
|
238 | } | |
231 |
|
239 | |||
232 | #include "moc_piesliceitem_p.cpp" |
|
240 | #include "moc_piesliceitem_p.cpp" | |
233 |
|
241 | |||
234 | QTCOMMERCIALCHART_END_NAMESPACE |
|
242 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,781 +1,796 | |||||
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 "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseries_p.h" |
|
22 | #include "qpieseries_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "qpieslice_p.h" |
|
24 | #include "qpieslice_p.h" | |
25 | #include "pieslicedata_p.h" |
|
25 | #include "pieslicedata_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "chartanimator_p.h" |
|
28 | #include "chartanimator_p.h" | |
29 | #include "legendmarker_p.h" |
|
29 | #include "legendmarker_p.h" | |
30 | #include "qabstractaxis.h" |
|
30 | #include "qabstractaxis.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QPieSeries |
|
35 | \class QPieSeries | |
36 | \brief Pie series API for QtCommercial Charts |
|
36 | \brief Pie series API for QtCommercial Charts | |
37 |
|
37 | |||
38 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
38 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | |
39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
40 | The actual slice size is determined by that relative value. |
|
40 | The actual slice size is determined by that relative value. | |
41 |
|
41 | |||
42 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
42 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 | |
43 | These relate to the actual chart rectangle. |
|
43 | These relate to the actual chart rectangle. | |
44 |
|
44 | |||
45 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
45 | By default the pie is defined as a full pie but it can also be a partial pie. | |
46 | This can be done by setting a starting angle and angle span to the series. |
|
46 | This can be done by setting a starting angle and angle span to the series. | |
47 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
47 | Full pie is 360 degrees where 0 is at 12 a'clock. | |
48 |
|
48 | |||
49 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. |
|
49 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. | |
50 | \image examples_piechart.png |
|
50 | \image examples_piechart.png | |
51 | */ |
|
51 | */ | |
52 | /*! |
|
52 | /*! | |
53 | \qmlclass PieSeries QPieSeries |
|
53 | \qmlclass PieSeries QPieSeries | |
54 | \inherits AbstractSeries |
|
54 | \inherits AbstractSeries | |
55 |
|
55 | |||
56 | The following QML shows how to create a simple pie chart. |
|
56 | The following QML shows how to create a simple pie chart. | |
57 |
|
57 | |||
58 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
58 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
59 |
|
59 | |||
60 | \beginfloatleft |
|
60 | \beginfloatleft | |
61 | \image demos_qmlchart1.png |
|
61 | \image demos_qmlchart1.png | |
62 | \endfloat |
|
62 | \endfloat | |
63 | \clearfloat |
|
63 | \clearfloat | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | \property QPieSeries::horizontalPosition |
|
67 | \property QPieSeries::horizontalPosition | |
68 | \brief Defines the horizontal position of the pie. |
|
68 | \brief Defines the horizontal position of the pie. | |
69 |
|
69 | |||
70 | The value is a relative value to the chart rectangle where: |
|
70 | The value is a relative value to the chart rectangle where: | |
71 |
|
71 | |||
72 | \list |
|
72 | \list | |
73 | \o 0.0 is the absolute left. |
|
73 | \o 0.0 is the absolute left. | |
74 | \o 1.0 is the absolute right. |
|
74 | \o 1.0 is the absolute right. | |
75 | \endlist |
|
75 | \endlist | |
76 | Default value is 0.5 (center). |
|
76 | Default value is 0.5 (center). | |
77 | \sa verticalPosition |
|
77 | \sa verticalPosition | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty real PieSeries::horizontalPosition |
|
81 | \qmlproperty real PieSeries::horizontalPosition | |
82 |
|
82 | |||
83 | Defines the horizontal position of the pie. |
|
83 | Defines the horizontal position of the pie. | |
84 |
|
84 | |||
85 | The value is a relative value to the chart rectangle where: |
|
85 | The value is a relative value to the chart rectangle where: | |
86 |
|
86 | |||
87 | \list |
|
87 | \list | |
88 | \o 0.0 is the absolute left. |
|
88 | \o 0.0 is the absolute left. | |
89 | \o 1.0 is the absolute right. |
|
89 | \o 1.0 is the absolute right. | |
90 | \endlist |
|
90 | \endlist | |
91 | Default value is 0.5 (center). |
|
91 | Default value is 0.5 (center). | |
92 | \sa verticalPosition |
|
92 | \sa verticalPosition | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QPieSeries::verticalPosition |
|
96 | \property QPieSeries::verticalPosition | |
97 | \brief Defines the vertical position of the pie. |
|
97 | \brief Defines the vertical position of the pie. | |
98 |
|
98 | |||
99 | The value is a relative value to the chart rectangle where: |
|
99 | The value is a relative value to the chart rectangle where: | |
100 |
|
100 | |||
101 | \list |
|
101 | \list | |
102 | \o 0.0 is the absolute top. |
|
102 | \o 0.0 is the absolute top. | |
103 | \o 1.0 is the absolute bottom. |
|
103 | \o 1.0 is the absolute bottom. | |
104 | \endlist |
|
104 | \endlist | |
105 | Default value is 0.5 (center). |
|
105 | Default value is 0.5 (center). | |
106 | \sa horizontalPosition |
|
106 | \sa horizontalPosition | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty real PieSeries::verticalPosition |
|
110 | \qmlproperty real PieSeries::verticalPosition | |
111 |
|
111 | |||
112 | Defines the vertical position of the pie. |
|
112 | Defines the vertical position of the pie. | |
113 |
|
113 | |||
114 | The value is a relative value to the chart rectangle where: |
|
114 | The value is a relative value to the chart rectangle where: | |
115 |
|
115 | |||
116 | \list |
|
116 | \list | |
117 | \o 0.0 is the absolute top. |
|
117 | \o 0.0 is the absolute top. | |
118 | \o 1.0 is the absolute bottom. |
|
118 | \o 1.0 is the absolute bottom. | |
119 | \endlist |
|
119 | \endlist | |
120 | Default value is 0.5 (center). |
|
120 | Default value is 0.5 (center). | |
121 | \sa horizontalPosition |
|
121 | \sa horizontalPosition | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \property QPieSeries::size |
|
125 | \property QPieSeries::size | |
126 | \brief Defines the pie size. |
|
126 | \brief Defines the pie size. | |
127 |
|
127 | |||
128 | The value is a relative value to the chart rectangle where: |
|
128 | The value is a relative value to the chart rectangle where: | |
129 |
|
129 | |||
130 | \list |
|
130 | \list | |
131 | \o 0.0 is the minimum size (pie not drawn). |
|
131 | \o 0.0 is the minimum size (pie not drawn). | |
132 | \o 1.0 is the maximum size that can fit the chart. |
|
132 | \o 1.0 is the maximum size that can fit the chart. | |
133 | \endlist |
|
133 | \endlist | |
134 |
|
134 | |||
135 | Default value is 0.7. |
|
135 | Default value is 0.7. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \qmlproperty real PieSeries::size |
|
139 | \qmlproperty real PieSeries::size | |
140 |
|
140 | |||
141 | Defines the pie size. |
|
141 | Defines the pie size. | |
142 |
|
142 | |||
143 | The value is a relative value to the chart rectangle where: |
|
143 | The value is a relative value to the chart rectangle where: | |
144 |
|
144 | |||
145 | \list |
|
145 | \list | |
146 | \o 0.0 is the minimum size (pie not drawn). |
|
146 | \o 0.0 is the minimum size (pie not drawn). | |
147 | \o 1.0 is the maximum size that can fit the chart. |
|
147 | \o 1.0 is the maximum size that can fit the chart. | |
148 | \endlist |
|
148 | \endlist | |
149 |
|
149 | |||
150 | Default value is 0.7. |
|
150 | Default value is 0.7. | |
151 | */ |
|
151 | */ | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | \property QPieSeries::startAngle |
|
154 | \property QPieSeries::startAngle | |
155 | \brief Defines the starting angle of the pie. |
|
155 | \brief Defines the starting angle of the pie. | |
156 |
|
156 | |||
157 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
157 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
158 |
|
158 | |||
159 | Default is value is 0. |
|
159 | Default is value is 0. | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | \qmlproperty real PieSeries::startAngle |
|
163 | \qmlproperty real PieSeries::startAngle | |
164 |
|
164 | |||
165 | Defines the starting angle of the pie. |
|
165 | Defines the starting angle of the pie. | |
166 |
|
166 | |||
167 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
167 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
168 |
|
168 | |||
169 | Default is value is 0. |
|
169 | Default is value is 0. | |
170 | */ |
|
170 | */ | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \property QPieSeries::endAngle |
|
173 | \property QPieSeries::endAngle | |
174 | \brief Defines the ending angle of the pie. |
|
174 | \brief Defines the ending angle of the pie. | |
175 |
|
175 | |||
176 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
176 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
177 |
|
177 | |||
178 | Default is value is 360. |
|
178 | Default is value is 360. | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \qmlproperty real PieSeries::endAngle |
|
182 | \qmlproperty real PieSeries::endAngle | |
183 |
|
183 | |||
184 | Defines the ending angle of the pie. |
|
184 | Defines the ending angle of the pie. | |
185 |
|
185 | |||
186 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
186 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
187 |
|
187 | |||
188 | Default is value is 360. |
|
188 | Default is value is 360. | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | \property QPieSeries::count |
|
192 | \property QPieSeries::count | |
193 |
|
193 | |||
194 | Number of slices in the series. |
|
194 | Number of slices in the series. | |
195 | */ |
|
195 | */ | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | \qmlproperty int PieSeries::count |
|
198 | \qmlproperty int PieSeries::count | |
199 |
|
199 | |||
200 | Number of slices in the series. |
|
200 | Number of slices in the series. | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \fn void QPieSeries::countChanged() |
|
204 | \fn void QPieSeries::countChanged() | |
205 | Emitted when the slice count has changed. |
|
205 | Emitted when the slice count has changed. | |
206 | \sa count |
|
206 | \sa count | |
207 | */ |
|
207 | */ | |
208 | /*! |
|
208 | /*! | |
209 | \qmlsignal PieSeries::onCountChanged() |
|
209 | \qmlsignal PieSeries::onCountChanged() | |
210 | Emitted when the slice count has changed. |
|
210 | Emitted when the slice count has changed. | |
211 | */ |
|
211 | */ | |
212 |
|
212 | |||
213 | /*! |
|
213 | /*! | |
214 | \property QPieSeries::sum |
|
214 | \property QPieSeries::sum | |
215 |
|
215 | |||
216 | Sum of all slices. |
|
216 | Sum of all slices. | |
217 |
|
217 | |||
218 | The series keeps track of the sum of all slices it holds. |
|
218 | The series keeps track of the sum of all slices it holds. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \qmlproperty real PieSeries::sum |
|
222 | \qmlproperty real PieSeries::sum | |
223 |
|
223 | |||
224 | Sum of all slices. |
|
224 | Sum of all slices. | |
225 |
|
225 | |||
226 | The series keeps track of the sum of all slices it holds. |
|
226 | The series keeps track of the sum of all slices it holds. | |
227 | */ |
|
227 | */ | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | \fn void QPieSeries::sumChanged() |
|
230 | \fn void QPieSeries::sumChanged() | |
231 | Emitted when the sum of all slices has changed. |
|
231 | Emitted when the sum of all slices has changed. | |
232 | \sa sum |
|
232 | \sa sum | |
233 | */ |
|
233 | */ | |
234 | /*! |
|
234 | /*! | |
235 | \qmlsignal PieSeries::onSumChanged() |
|
235 | \qmlsignal PieSeries::onSumChanged() | |
236 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
236 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | |
237 | change value of a slice. |
|
237 | change value of a slice. | |
238 | */ |
|
238 | */ | |
239 |
|
239 | |||
240 | /*! |
|
240 | /*! | |
241 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
241 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
242 |
|
242 | |||
243 | This signal is emitted when \a slices have been added to the series. |
|
243 | This signal is emitted when \a slices have been added to the series. | |
244 |
|
244 | |||
245 | \sa append(), insert() |
|
245 | \sa append(), insert() | |
246 | */ |
|
246 | */ | |
247 | /*! |
|
247 | /*! | |
248 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
248 | \qmlsignal PieSeries::onAdded(PieSlice slice) | |
249 | Emitted when \a slice has been added to the series. |
|
249 | Emitted when \a slice has been added to the series. | |
250 | */ |
|
250 | */ | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
253 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
254 | This signal is emitted when \a slices have been removed from the series. |
|
254 | This signal is emitted when \a slices have been removed from the series. | |
255 | \sa remove() |
|
255 | \sa remove() | |
256 | */ |
|
256 | */ | |
257 | /*! |
|
257 | /*! | |
258 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
258 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | |
259 | Emitted when \a slice has been removed from the series. |
|
259 | Emitted when \a slice has been removed from the series. | |
260 | */ |
|
260 | */ | |
261 |
|
261 | |||
262 | /*! |
|
262 | /*! | |
263 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
263 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
264 | This signal is emitted when a \a slice has been clicked. |
|
264 | This signal is emitted when a \a slice has been clicked. | |
265 | \sa QPieSlice::clicked() |
|
265 | \sa QPieSlice::clicked() | |
266 | */ |
|
266 | */ | |
267 | /*! |
|
267 | /*! | |
268 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
268 | \qmlsignal PieSeries::onClicked(PieSlice slice) | |
269 | This signal is emitted when a \a slice has been clicked. |
|
269 | This signal is emitted when a \a slice has been clicked. | |
270 | */ |
|
270 | */ | |
271 |
|
271 | |||
272 | /*! |
|
272 | /*! | |
273 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
273 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
274 | This signal is emitted when user has hovered over or away from the \a slice. |
|
274 | This signal is emitted when user has hovered over or away from the \a slice. | |
275 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
275 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
276 | \sa QPieSlice::hovered() |
|
276 | \sa QPieSlice::hovered() | |
277 | */ |
|
277 | */ | |
278 | /*! |
|
278 | /*! | |
279 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
279 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | |
280 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
280 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | |
281 | over the slice and false when hover has moved away from the slice. |
|
281 | over the slice and false when hover has moved away from the slice. | |
282 | */ |
|
282 | */ | |
283 |
|
283 | |||
284 | /*! |
|
284 | /*! | |
285 | \qmlmethod PieSlice PieSeries::at(int index) |
|
285 | \qmlmethod PieSlice PieSeries::at(int index) | |
286 | Returns slice at \a index. Returns null if the index is not valid. |
|
286 | Returns slice at \a index. Returns null if the index is not valid. | |
287 | */ |
|
287 | */ | |
288 |
|
288 | |||
289 | /*! |
|
289 | /*! | |
290 | \qmlmethod PieSlice PieSeries::find(string label) |
|
290 | \qmlmethod PieSlice PieSeries::find(string label) | |
291 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
291 | Returns the first slice with \a label. Returns null if the index is not valid. | |
292 | */ |
|
292 | */ | |
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
295 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
296 | Adds a new slice with \a label and \a value to the pie. |
|
296 | Adds a new slice with \a label and \a value to the pie. | |
297 | */ |
|
297 | */ | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
300 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
301 | Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. |
|
301 | Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. | |
302 | */ |
|
302 | */ | |
303 |
|
303 | |||
304 | /*! |
|
304 | /*! | |
305 | \qmlmethod PieSeries::clear() |
|
305 | \qmlmethod PieSeries::clear() | |
306 | Removes all slices from the pie. |
|
306 | Removes all slices from the pie. | |
307 | */ |
|
307 | */ | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Constructs a series object which is a child of \a parent. |
|
310 | Constructs a series object which is a child of \a parent. | |
311 | */ |
|
311 | */ | |
312 | QPieSeries::QPieSeries(QObject *parent) : |
|
312 | QPieSeries::QPieSeries(QObject *parent) : | |
313 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) |
|
313 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) | |
314 | { |
|
314 | { | |
315 |
|
315 | |||
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | /*! |
|
318 | /*! | |
319 | Destroys the series and its slices. |
|
319 | Destroys the series and its slices. | |
320 | */ |
|
320 | */ | |
321 | QPieSeries::~QPieSeries() |
|
321 | QPieSeries::~QPieSeries() | |
322 | { |
|
322 | { | |
323 | // NOTE: d_prt destroyed by QObject |
|
323 | // NOTE: d_prt destroyed by QObject | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | /*! |
|
326 | /*! | |
327 | Returns QChartSeries::SeriesTypePie. |
|
327 | Returns QChartSeries::SeriesTypePie. | |
328 | */ |
|
328 | */ | |
329 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
329 | QAbstractSeries::SeriesType QPieSeries::type() const | |
330 | { |
|
330 | { | |
331 | return QAbstractSeries::SeriesTypePie; |
|
331 | return QAbstractSeries::SeriesTypePie; | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | /*! |
|
334 | /*! | |
335 | Appends a single \a slice to the series. |
|
335 | Appends a single \a slice to the series. | |
336 | Slice ownership is passed to the series. |
|
336 | Slice ownership is passed to the series. | |
337 |
|
337 | |||
338 | Returns true if append was succesfull. |
|
338 | Returns true if append was succesfull. | |
339 | */ |
|
339 | */ | |
340 | bool QPieSeries::append(QPieSlice* slice) |
|
340 | bool QPieSeries::append(QPieSlice* slice) | |
341 | { |
|
341 | { | |
342 | return append(QList<QPieSlice*>() << slice); |
|
342 | return append(QList<QPieSlice*>() << slice); | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | /*! |
|
345 | /*! | |
346 | Appends an array of \a slices to the series. |
|
346 | Appends an array of \a slices to the series. | |
347 | Slice ownership is passed to the series. |
|
347 | Slice ownership is passed to the series. | |
348 |
|
348 | |||
349 | Returns true if append was successfull. |
|
349 | Returns true if append was successfull. | |
350 | */ |
|
350 | */ | |
351 | bool QPieSeries::append(QList<QPieSlice*> slices) |
|
351 | bool QPieSeries::append(QList<QPieSlice*> slices) | |
352 | { |
|
352 | { | |
353 | Q_D(QPieSeries); |
|
353 | Q_D(QPieSeries); | |
354 |
|
354 | |||
355 | if (slices.count() == 0) |
|
355 | if (slices.count() == 0) | |
356 | return false; |
|
356 | return false; | |
357 |
|
357 | |||
358 | foreach (QPieSlice* s, slices) { |
|
358 | foreach (QPieSlice* s, slices) { | |
359 | if (!s || d->m_slices.contains(s)) |
|
359 | if (!s || d->m_slices.contains(s)) | |
360 | return false; |
|
360 | return false; | |
361 | if (s->series()) // already added to some series |
|
361 | if (s->series()) // already added to some series | |
362 | return false; |
|
362 | return false; | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | foreach (QPieSlice* s, slices) { |
|
365 | foreach (QPieSlice* s, slices) { | |
366 | s->setParent(this); |
|
366 | s->setParent(this); | |
367 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
367 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
368 | d->m_slices << s; |
|
368 | d->m_slices << s; | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | d->updateDerivativeData(); |
|
371 | d->updateDerivativeData(); | |
372 |
|
372 | |||
373 | foreach (QPieSlice* s, slices) { |
|
373 | foreach (QPieSlice* s, slices) { | |
374 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
374 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
375 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
375 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
376 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
376 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | emit added(slices); |
|
379 | emit added(slices); | |
380 | emit countChanged(); |
|
380 | emit countChanged(); | |
381 |
|
381 | |||
382 | return true; |
|
382 | return true; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | /*! |
|
385 | /*! | |
386 | Appends a single \a slice to the series and returns a reference to the series. |
|
386 | Appends a single \a slice to the series and returns a reference to the series. | |
387 | Slice ownership is passed to the series. |
|
387 | Slice ownership is passed to the series. | |
388 | */ |
|
388 | */ | |
389 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
389 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
390 | { |
|
390 | { | |
391 | append(slice); |
|
391 | append(slice); | |
392 | return *this; |
|
392 | return *this; | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 |
|
395 | |||
396 | /*! |
|
396 | /*! | |
397 | Appends a single slice to the series with give \a value and \a label. |
|
397 | Appends a single slice to the series with give \a value and \a label. | |
398 | Slice ownership is passed to the series. |
|
398 | Slice ownership is passed to the series. | |
399 | */ |
|
399 | */ | |
400 | QPieSlice* QPieSeries::append(QString label, qreal value) |
|
400 | QPieSlice* QPieSeries::append(QString label, qreal value) | |
401 | { |
|
401 | { | |
402 | QPieSlice* slice = new QPieSlice(label, value); |
|
402 | QPieSlice* slice = new QPieSlice(label, value); | |
403 | append(slice); |
|
403 | append(slice); | |
404 | return slice; |
|
404 | return slice; | |
405 | } |
|
405 | } | |
406 |
|
406 | |||
407 | /*! |
|
407 | /*! | |
408 | Inserts a single \a slice to the series before the slice at \a index position. |
|
408 | Inserts a single \a slice to the series before the slice at \a index position. | |
409 | Slice ownership is passed to the series. |
|
409 | Slice ownership is passed to the series. | |
410 |
|
410 | |||
411 | Returns true if insert was successfull. |
|
411 | Returns true if insert was successfull. | |
412 | */ |
|
412 | */ | |
413 | bool QPieSeries::insert(int index, QPieSlice* slice) |
|
413 | bool QPieSeries::insert(int index, QPieSlice* slice) | |
414 | { |
|
414 | { | |
415 | Q_D(QPieSeries); |
|
415 | Q_D(QPieSeries); | |
416 |
|
416 | |||
417 | if (index < 0 || index > d->m_slices.count()) |
|
417 | if (index < 0 || index > d->m_slices.count()) | |
418 | return false; |
|
418 | return false; | |
419 |
|
419 | |||
420 | if (!slice || d->m_slices.contains(slice)) |
|
420 | if (!slice || d->m_slices.contains(slice)) | |
421 | return false; |
|
421 | return false; | |
422 |
|
422 | |||
423 | if (slice->series()) // already added to some series |
|
423 | if (slice->series()) // already added to some series | |
424 | return false; |
|
424 | return false; | |
425 |
|
425 | |||
426 | slice->setParent(this); |
|
426 | slice->setParent(this); | |
427 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
427 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
428 | d->m_slices.insert(index, slice); |
|
428 | d->m_slices.insert(index, slice); | |
429 |
|
429 | |||
430 | d->updateDerivativeData(); |
|
430 | d->updateDerivativeData(); | |
431 |
|
431 | |||
432 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
432 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
433 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
433 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
434 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
434 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
435 |
|
435 | |||
436 | emit added(QList<QPieSlice*>() << slice); |
|
436 | emit added(QList<QPieSlice*>() << slice); | |
437 | emit countChanged(); |
|
437 | emit countChanged(); | |
438 |
|
438 | |||
439 | return true; |
|
439 | return true; | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | /*! |
|
442 | /*! | |
443 | Removes a single \a slice from the series and deletes the slice. |
|
443 | Removes a single \a slice from the series and deletes the slice. | |
444 |
|
444 | |||
445 | Do not reference the pointer after this call. |
|
445 | Do not reference the pointer after this call. | |
446 |
|
446 | |||
447 | Returns true if remove was successfull. |
|
447 | Returns true if remove was successfull. | |
448 | */ |
|
448 | */ | |
449 | bool QPieSeries::remove(QPieSlice* slice) |
|
449 | bool QPieSeries::remove(QPieSlice* slice) | |
450 | { |
|
450 | { | |
451 | Q_D(QPieSeries); |
|
451 | Q_D(QPieSeries); | |
452 |
|
452 | |||
453 | if (!d->m_slices.removeOne(slice)) |
|
453 | if (!d->m_slices.removeOne(slice)) | |
454 | return false; |
|
454 | return false; | |
455 |
|
455 | |||
456 | d->updateDerivativeData(); |
|
456 | d->updateDerivativeData(); | |
457 |
|
457 | |||
458 | emit removed(QList<QPieSlice*>() << slice); |
|
458 | emit removed(QList<QPieSlice*>() << slice); | |
459 | emit countChanged(); |
|
459 | emit countChanged(); | |
460 |
|
460 | |||
461 | delete slice; |
|
461 | delete slice; | |
462 | slice = 0; |
|
462 | slice = 0; | |
463 |
|
463 | |||
464 | return true; |
|
464 | return true; | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | /*! |
|
467 | /*! | |
468 | Clears all slices from the series. |
|
468 | Clears all slices from the series. | |
469 | */ |
|
469 | */ | |
470 | void QPieSeries::clear() |
|
470 | void QPieSeries::clear() | |
471 | { |
|
471 | { | |
472 | Q_D(QPieSeries); |
|
472 | Q_D(QPieSeries); | |
473 | if (d->m_slices.count() == 0) |
|
473 | if (d->m_slices.count() == 0) | |
474 | return; |
|
474 | return; | |
475 |
|
475 | |||
476 | QList<QPieSlice*> slices = d->m_slices; |
|
476 | QList<QPieSlice*> slices = d->m_slices; | |
477 | foreach (QPieSlice* s, d->m_slices) { |
|
477 | foreach (QPieSlice* s, d->m_slices) { | |
478 | d->m_slices.removeOne(s); |
|
478 | d->m_slices.removeOne(s); | |
479 | delete s; |
|
479 | delete s; | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
482 | d->updateDerivativeData(); |
|
482 | d->updateDerivativeData(); | |
483 |
|
483 | |||
484 | emit removed(slices); |
|
484 | emit removed(slices); | |
485 | emit countChanged(); |
|
485 | emit countChanged(); | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | /*! |
|
488 | /*! | |
489 | Returns a list of slices that belong to this series. |
|
489 | Returns a list of slices that belong to this series. | |
490 | */ |
|
490 | */ | |
491 | QList<QPieSlice*> QPieSeries::slices() const |
|
491 | QList<QPieSlice*> QPieSeries::slices() const | |
492 | { |
|
492 | { | |
493 | Q_D(const QPieSeries); |
|
493 | Q_D(const QPieSeries); | |
494 | return d->m_slices; |
|
494 | return d->m_slices; | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | /*! |
|
497 | /*! | |
498 | returns the number of the slices in this series. |
|
498 | returns the number of the slices in this series. | |
499 | */ |
|
499 | */ | |
500 | int QPieSeries::count() const |
|
500 | int QPieSeries::count() const | |
501 | { |
|
501 | { | |
502 | Q_D(const QPieSeries); |
|
502 | Q_D(const QPieSeries); | |
503 | return d->m_slices.count(); |
|
503 | return d->m_slices.count(); | |
504 | } |
|
504 | } | |
505 |
|
505 | |||
506 | /*! |
|
506 | /*! | |
507 | Returns true is the series is empty. |
|
507 | Returns true is the series is empty. | |
508 | */ |
|
508 | */ | |
509 | bool QPieSeries::isEmpty() const |
|
509 | bool QPieSeries::isEmpty() const | |
510 | { |
|
510 | { | |
511 | Q_D(const QPieSeries); |
|
511 | Q_D(const QPieSeries); | |
512 | return d->m_slices.isEmpty(); |
|
512 | return d->m_slices.isEmpty(); | |
513 | } |
|
513 | } | |
514 |
|
514 | |||
515 | /*! |
|
515 | /*! | |
516 | Returns the sum of all slice values in this series. |
|
516 | Returns the sum of all slice values in this series. | |
517 |
|
517 | |||
518 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
518 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
519 | */ |
|
519 | */ | |
520 | qreal QPieSeries::sum() const |
|
520 | qreal QPieSeries::sum() const | |
521 | { |
|
521 | { | |
522 | Q_D(const QPieSeries); |
|
522 | Q_D(const QPieSeries); | |
523 | return d->m_sum; |
|
523 | return d->m_sum; | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
|
526 | void QPieSeries::setDonut(bool donut) | |||
|
527 | { | |||
|
528 | Q_D(QPieSeries); | |||
|
529 | d->m_donutChart = donut; | |||
|
530 | d->updateDerivativeData(); | |||
|
531 | } | |||
|
532 | ||||
|
533 | bool QPieSeries::donut() const | |||
|
534 | { | |||
|
535 | Q_D(const QPieSeries); | |||
|
536 | return d->m_donutChart; | |||
|
537 | } | |||
|
538 | ||||
526 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
539 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
527 | { |
|
540 | { | |
528 | Q_D(QPieSeries); |
|
541 | Q_D(QPieSeries); | |
529 |
|
542 | |||
530 | if (relativePosition < 0.0) |
|
543 | if (relativePosition < 0.0) | |
531 | relativePosition = 0.0; |
|
544 | relativePosition = 0.0; | |
532 | if (relativePosition > 1.0) |
|
545 | if (relativePosition > 1.0) | |
533 | relativePosition = 1.0; |
|
546 | relativePosition = 1.0; | |
534 |
|
547 | |||
535 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
548 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { | |
536 | d->m_pieRelativeHorPos = relativePosition; |
|
549 | d->m_pieRelativeHorPos = relativePosition; | |
537 | emit d->horizontalPositionChanged(); |
|
550 | emit d->horizontalPositionChanged(); | |
538 | } |
|
551 | } | |
539 | } |
|
552 | } | |
540 |
|
553 | |||
541 | qreal QPieSeries::horizontalPosition() const |
|
554 | qreal QPieSeries::horizontalPosition() const | |
542 | { |
|
555 | { | |
543 | Q_D(const QPieSeries); |
|
556 | Q_D(const QPieSeries); | |
544 | return d->m_pieRelativeHorPos; |
|
557 | return d->m_pieRelativeHorPos; | |
545 | } |
|
558 | } | |
546 |
|
559 | |||
547 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
560 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
548 | { |
|
561 | { | |
549 | Q_D(QPieSeries); |
|
562 | Q_D(QPieSeries); | |
550 |
|
563 | |||
551 | if (relativePosition < 0.0) |
|
564 | if (relativePosition < 0.0) | |
552 | relativePosition = 0.0; |
|
565 | relativePosition = 0.0; | |
553 | if (relativePosition > 1.0) |
|
566 | if (relativePosition > 1.0) | |
554 | relativePosition = 1.0; |
|
567 | relativePosition = 1.0; | |
555 |
|
568 | |||
556 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
569 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { | |
557 | d->m_pieRelativeVerPos = relativePosition; |
|
570 | d->m_pieRelativeVerPos = relativePosition; | |
558 | emit d->verticalPositionChanged(); |
|
571 | emit d->verticalPositionChanged(); | |
559 | } |
|
572 | } | |
560 | } |
|
573 | } | |
561 |
|
574 | |||
562 | qreal QPieSeries::verticalPosition() const |
|
575 | qreal QPieSeries::verticalPosition() const | |
563 | { |
|
576 | { | |
564 | Q_D(const QPieSeries); |
|
577 | Q_D(const QPieSeries); | |
565 | return d->m_pieRelativeVerPos; |
|
578 | return d->m_pieRelativeVerPos; | |
566 | } |
|
579 | } | |
567 |
|
580 | |||
568 | void QPieSeries::setPieSize(qreal relativeSize) |
|
581 | void QPieSeries::setPieSize(qreal relativeSize) | |
569 | { |
|
582 | { | |
570 | Q_D(QPieSeries); |
|
583 | Q_D(QPieSeries); | |
571 |
|
584 | |||
572 | if (relativeSize < 0.0) |
|
585 | if (relativeSize < 0.0) | |
573 | relativeSize = 0.0; |
|
586 | relativeSize = 0.0; | |
574 | if (relativeSize > 1.0) |
|
587 | if (relativeSize > 1.0) | |
575 | relativeSize = 1.0; |
|
588 | relativeSize = 1.0; | |
576 |
|
589 | |||
577 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { |
|
590 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { | |
578 | d->m_pieRelativeSize = relativeSize; |
|
591 | d->m_pieRelativeSize = relativeSize; | |
579 | emit d->pieSizeChanged(); |
|
592 | emit d->pieSizeChanged(); | |
580 | } |
|
593 | } | |
581 | } |
|
594 | } | |
582 |
|
595 | |||
583 | qreal QPieSeries::pieSize() const |
|
596 | qreal QPieSeries::pieSize() const | |
584 | { |
|
597 | { | |
585 | Q_D(const QPieSeries); |
|
598 | Q_D(const QPieSeries); | |
586 | return d->m_pieRelativeSize; |
|
599 | return d->m_pieRelativeSize; | |
587 | } |
|
600 | } | |
588 |
|
601 | |||
589 |
|
602 | |||
590 | void QPieSeries::setPieStartAngle(qreal angle) |
|
603 | void QPieSeries::setPieStartAngle(qreal angle) | |
591 | { |
|
604 | { | |
592 | Q_D(QPieSeries); |
|
605 | Q_D(QPieSeries); | |
593 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
606 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | |
594 | return; |
|
607 | return; | |
595 | d->m_pieStartAngle = angle; |
|
608 | d->m_pieStartAngle = angle; | |
596 | d->updateDerivativeData(); |
|
609 | d->updateDerivativeData(); | |
597 | emit d->pieStartAngleChanged(); |
|
610 | emit d->pieStartAngleChanged(); | |
598 | } |
|
611 | } | |
599 |
|
612 | |||
600 | qreal QPieSeries::pieStartAngle() const |
|
613 | qreal QPieSeries::pieStartAngle() const | |
601 | { |
|
614 | { | |
602 | Q_D(const QPieSeries); |
|
615 | Q_D(const QPieSeries); | |
603 | return d->m_pieStartAngle; |
|
616 | return d->m_pieStartAngle; | |
604 | } |
|
617 | } | |
605 |
|
618 | |||
606 | /*! |
|
619 | /*! | |
607 | Sets the end angle of the pie. |
|
620 | Sets the end angle of the pie. | |
608 |
|
621 | |||
609 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
622 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
610 |
|
623 | |||
611 | \a angle must be greater than start angle. |
|
624 | \a angle must be greater than start angle. | |
612 |
|
625 | |||
613 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
626 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
614 | */ |
|
627 | */ | |
615 | void QPieSeries::setPieEndAngle(qreal angle) |
|
628 | void QPieSeries::setPieEndAngle(qreal angle) | |
616 | { |
|
629 | { | |
617 | Q_D(QPieSeries); |
|
630 | Q_D(QPieSeries); | |
618 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
631 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | |
619 | return; |
|
632 | return; | |
620 | d->m_pieEndAngle = angle; |
|
633 | d->m_pieEndAngle = angle; | |
621 | d->updateDerivativeData(); |
|
634 | d->updateDerivativeData(); | |
622 | emit d->pieEndAngleChanged(); |
|
635 | emit d->pieEndAngleChanged(); | |
623 | } |
|
636 | } | |
624 |
|
637 | |||
625 | /*! |
|
638 | /*! | |
626 | Returns the end angle of the pie. |
|
639 | Returns the end angle of the pie. | |
627 |
|
640 | |||
628 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
641 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
629 |
|
642 | |||
630 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
643 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
631 | */ |
|
644 | */ | |
632 | qreal QPieSeries::pieEndAngle() const |
|
645 | qreal QPieSeries::pieEndAngle() const | |
633 | { |
|
646 | { | |
634 | Q_D(const QPieSeries); |
|
647 | Q_D(const QPieSeries); | |
635 | return d->m_pieEndAngle; |
|
648 | return d->m_pieEndAngle; | |
636 | } |
|
649 | } | |
637 |
|
650 | |||
638 | /*! |
|
651 | /*! | |
639 | Sets the all the slice labels \a visible or invisible. |
|
652 | Sets the all the slice labels \a visible or invisible. | |
640 |
|
653 | |||
641 | Note that this affects only the current slices in the series. |
|
654 | Note that this affects only the current slices in the series. | |
642 | If user adds a new slice the default label visibility is false. |
|
655 | If user adds a new slice the default label visibility is false. | |
643 |
|
656 | |||
644 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
657 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
645 | */ |
|
658 | */ | |
646 | void QPieSeries::setLabelsVisible(bool visible) |
|
659 | void QPieSeries::setLabelsVisible(bool visible) | |
647 | { |
|
660 | { | |
648 | Q_D(QPieSeries); |
|
661 | Q_D(QPieSeries); | |
649 | foreach (QPieSlice* s, d->m_slices) |
|
662 | foreach (QPieSlice* s, d->m_slices) | |
650 | s->setLabelVisible(visible); |
|
663 | s->setLabelVisible(visible); | |
651 | } |
|
664 | } | |
652 |
|
665 | |||
653 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
666 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
654 |
|
667 | |||
655 |
|
668 | |||
656 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
669 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
657 | QAbstractSeriesPrivate(parent), |
|
670 | QAbstractSeriesPrivate(parent), | |
658 | m_pieRelativeHorPos(0.5), |
|
671 | m_pieRelativeHorPos(0.5), | |
659 | m_pieRelativeVerPos(0.5), |
|
672 | m_pieRelativeVerPos(0.5), | |
660 | m_pieRelativeSize(0.7), |
|
673 | m_pieRelativeSize(0.7), | |
661 | m_pieStartAngle(0), |
|
674 | m_pieStartAngle(0), | |
662 | m_pieEndAngle(360), |
|
675 | m_pieEndAngle(360), | |
663 | m_sum(0) |
|
676 | m_sum(0), | |
|
677 | m_donutChart(false) | |||
664 | { |
|
678 | { | |
665 | } |
|
679 | } | |
666 |
|
680 | |||
667 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
681 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
668 | { |
|
682 | { | |
669 | } |
|
683 | } | |
670 |
|
684 | |||
671 | void QPieSeriesPrivate::updateDerivativeData() |
|
685 | void QPieSeriesPrivate::updateDerivativeData() | |
672 | { |
|
686 | { | |
673 | // calculate sum of all slices |
|
687 | // calculate sum of all slices | |
674 | qreal sum = 0; |
|
688 | qreal sum = 0; | |
675 | foreach (QPieSlice* s, m_slices) |
|
689 | foreach (QPieSlice* s, m_slices) | |
676 | sum += s->value(); |
|
690 | sum += s->value(); | |
677 |
|
691 | |||
678 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
692 | if (!qFuzzyIsNull(m_sum - sum)) { | |
679 | m_sum = sum; |
|
693 | m_sum = sum; | |
680 | emit q_func()->sumChanged(); |
|
694 | emit q_func()->sumChanged(); | |
681 | } |
|
695 | } | |
682 |
|
696 | |||
683 | // nothing to show.. |
|
697 | // nothing to show.. | |
684 | if (qFuzzyIsNull(m_sum)) |
|
698 | if (qFuzzyIsNull(m_sum)) | |
685 | return; |
|
699 | return; | |
686 |
|
700 | |||
687 | // update slice attributes |
|
701 | // update slice attributes | |
688 | qreal sliceAngle = m_pieStartAngle; |
|
702 | qreal sliceAngle = m_pieStartAngle; | |
689 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
703 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
690 | QVector<QPieSlice*> changed; |
|
704 | QVector<QPieSlice*> changed; | |
691 | foreach (QPieSlice* s, m_slices) { |
|
705 | foreach (QPieSlice* s, m_slices) { | |
692 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
706 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
693 | d->setPercentage(s->value() / m_sum); |
|
707 | d->setPercentage(s->value() / m_sum); | |
694 | d->setStartAngle(sliceAngle); |
|
708 | d->setStartAngle(sliceAngle); | |
695 | d->setAngleSpan(pieSpan * s->percentage()); |
|
709 | d->setAngleSpan(pieSpan * s->percentage()); | |
|
710 | d->m_data.m_donut = m_donutChart; | |||
696 | sliceAngle += s->angleSpan(); |
|
711 | sliceAngle += s->angleSpan(); | |
697 | } |
|
712 | } | |
698 |
|
713 | |||
699 |
|
714 | |||
700 | emit calculatedDataChanged(); |
|
715 | emit calculatedDataChanged(); | |
701 | } |
|
716 | } | |
702 |
|
717 | |||
703 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
718 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
704 | { |
|
719 | { | |
705 | return series->d_func(); |
|
720 | return series->d_func(); | |
706 | } |
|
721 | } | |
707 |
|
722 | |||
708 | void QPieSeriesPrivate::sliceValueChanged() |
|
723 | void QPieSeriesPrivate::sliceValueChanged() | |
709 | { |
|
724 | { | |
710 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
725 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
711 | updateDerivativeData(); |
|
726 | updateDerivativeData(); | |
712 | } |
|
727 | } | |
713 |
|
728 | |||
714 | void QPieSeriesPrivate::sliceClicked() |
|
729 | void QPieSeriesPrivate::sliceClicked() | |
715 | { |
|
730 | { | |
716 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
731 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
717 | Q_ASSERT(m_slices.contains(slice)); |
|
732 | Q_ASSERT(m_slices.contains(slice)); | |
718 | Q_Q(QPieSeries); |
|
733 | Q_Q(QPieSeries); | |
719 | emit q->clicked(slice); |
|
734 | emit q->clicked(slice); | |
720 | } |
|
735 | } | |
721 |
|
736 | |||
722 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
737 | void QPieSeriesPrivate::sliceHovered(bool state) | |
723 | { |
|
738 | { | |
724 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
739 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
725 | Q_ASSERT(m_slices.contains(slice)); |
|
740 | Q_ASSERT(m_slices.contains(slice)); | |
726 | Q_Q(QPieSeries); |
|
741 | Q_Q(QPieSeries); | |
727 | emit q->hovered(slice, state); |
|
742 | emit q->hovered(slice, state); | |
728 | } |
|
743 | } | |
729 |
|
744 | |||
730 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
745 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | |
731 | { |
|
746 | { | |
732 | Q_UNUSED(domain); |
|
747 | Q_UNUSED(domain); | |
733 | // does not apply to pie |
|
748 | // does not apply to pie | |
734 | } |
|
749 | } | |
735 |
|
750 | |||
736 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
751 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
737 | { |
|
752 | { | |
738 | Q_Q(QPieSeries); |
|
753 | Q_Q(QPieSeries); | |
739 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
754 | PieChartItem* pie = new PieChartItem(q,presenter); | |
740 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
755 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
741 | presenter->animator()->addAnimation(pie); |
|
756 | presenter->animator()->addAnimation(pie); | |
742 | } |
|
757 | } | |
743 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
758 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
744 | return pie; |
|
759 | return pie; | |
745 | } |
|
760 | } | |
746 |
|
761 | |||
747 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) |
|
762 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |
748 | { |
|
763 | { | |
749 | Q_Q(QPieSeries); |
|
764 | Q_Q(QPieSeries); | |
750 | QList<LegendMarker*> markers; |
|
765 | QList<LegendMarker*> markers; | |
751 | foreach(QPieSlice* slice, q->slices()) { |
|
766 | foreach(QPieSlice* slice, q->slices()) { | |
752 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); |
|
767 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); | |
753 | markers << marker; |
|
768 | markers << marker; | |
754 | } |
|
769 | } | |
755 | return markers; |
|
770 | return markers; | |
756 | } |
|
771 | } | |
757 |
|
772 | |||
758 | void QPieSeriesPrivate::initializeAxisX(QAbstractAxis* axis) |
|
773 | void QPieSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
759 | { |
|
774 | { | |
760 | Q_UNUSED(axis); |
|
775 | Q_UNUSED(axis); | |
761 | } |
|
776 | } | |
762 |
|
777 | |||
763 | void QPieSeriesPrivate::initializeAxisY(QAbstractAxis* axis) |
|
778 | void QPieSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
764 | { |
|
779 | { | |
765 | Q_UNUSED(axis); |
|
780 | Q_UNUSED(axis); | |
766 | } |
|
781 | } | |
767 |
|
782 | |||
768 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisXType() const |
|
783 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisXType() const | |
769 | { |
|
784 | { | |
770 | return QAbstractAxis::AxisTypeNoAxis; |
|
785 | return QAbstractAxis::AxisTypeNoAxis; | |
771 | } |
|
786 | } | |
772 |
|
787 | |||
773 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisYType() const |
|
788 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisYType() const | |
774 | { |
|
789 | { | |
775 | return QAbstractAxis::AxisTypeNoAxis; |
|
790 | return QAbstractAxis::AxisTypeNoAxis; | |
776 | } |
|
791 | } | |
777 |
|
792 | |||
778 | #include "moc_qpieseries.cpp" |
|
793 | #include "moc_qpieseries.cpp" | |
779 | #include "moc_qpieseries_p.cpp" |
|
794 | #include "moc_qpieseries_p.cpp" | |
780 |
|
795 | |||
781 | QTCOMMERCIALCHART_END_NAMESPACE |
|
796 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,96 +1,99 | |||||
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 PIESERIES_H |
|
21 | #ifndef PIESERIES_H | |
22 | #define PIESERIES_H |
|
22 | #define PIESERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 | class QPieSeriesPrivate; |
|
27 | class QPieSeriesPrivate; | |
28 | class QPieSlice; |
|
28 | class QPieSlice; | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries |
|
30 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition) |
|
33 | Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition) | |
34 | Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition) |
|
34 | Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition) | |
35 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) |
|
35 | Q_PROPERTY(qreal size READ pieSize WRITE setPieSize) | |
36 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) |
|
36 | Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle) | |
37 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) |
|
37 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) | |
38 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
38 | Q_PROPERTY(int count READ count NOTIFY countChanged) | |
39 | Q_PROPERTY(qreal sum READ sum NOTIFY sumChanged) |
|
39 | Q_PROPERTY(qreal sum READ sum NOTIFY sumChanged) | |
40 |
|
40 | |||
41 | public: |
|
41 | public: | |
42 | explicit QPieSeries(QObject *parent = 0); |
|
42 | explicit QPieSeries(QObject *parent = 0); | |
43 | virtual ~QPieSeries(); |
|
43 | virtual ~QPieSeries(); | |
44 |
|
44 | |||
45 | QAbstractSeries::SeriesType type() const; |
|
45 | QAbstractSeries::SeriesType type() const; | |
46 |
|
46 | |||
47 | bool append(QPieSlice* slice); |
|
47 | bool append(QPieSlice* slice); | |
48 | bool append(QList<QPieSlice*> slices); |
|
48 | bool append(QList<QPieSlice*> slices); | |
49 | QPieSeries& operator << (QPieSlice* slice); |
|
49 | QPieSeries& operator << (QPieSlice* slice); | |
50 | QPieSlice* append(QString label, qreal value); |
|
50 | QPieSlice* append(QString label, qreal value); | |
51 |
|
51 | |||
52 | bool insert(int index, QPieSlice* slice); |
|
52 | bool insert(int index, QPieSlice* slice); | |
53 |
|
53 | |||
54 | bool remove(QPieSlice* slice); |
|
54 | bool remove(QPieSlice* slice); | |
55 | void clear(); |
|
55 | void clear(); | |
56 |
|
56 | |||
57 | QList<QPieSlice*> slices() const; |
|
57 | QList<QPieSlice*> slices() const; | |
58 | int count() const; |
|
58 | int count() const; | |
59 |
|
59 | |||
60 | bool isEmpty() const; |
|
60 | bool isEmpty() const; | |
61 |
|
61 | |||
62 | qreal sum() const; |
|
62 | qreal sum() const; | |
63 |
|
63 | |||
|
64 | void setDonut(bool donut = true); | |||
|
65 | bool donut() const; | |||
|
66 | ||||
64 | void setHorizontalPosition(qreal relativePosition); |
|
67 | void setHorizontalPosition(qreal relativePosition); | |
65 | qreal horizontalPosition() const; |
|
68 | qreal horizontalPosition() const; | |
66 |
|
69 | |||
67 | void setVerticalPosition(qreal relativePosition); |
|
70 | void setVerticalPosition(qreal relativePosition); | |
68 | qreal verticalPosition() const; |
|
71 | qreal verticalPosition() const; | |
69 |
|
72 | |||
70 | void setPieSize(qreal relativeSize); |
|
73 | void setPieSize(qreal relativeSize); | |
71 | qreal pieSize() const; |
|
74 | qreal pieSize() const; | |
72 |
|
75 | |||
73 | void setPieStartAngle(qreal startAngle); |
|
76 | void setPieStartAngle(qreal startAngle); | |
74 | qreal pieStartAngle() const; |
|
77 | qreal pieStartAngle() const; | |
75 |
|
78 | |||
76 | void setPieEndAngle(qreal endAngle); |
|
79 | void setPieEndAngle(qreal endAngle); | |
77 | qreal pieEndAngle() const; |
|
80 | qreal pieEndAngle() const; | |
78 |
|
81 | |||
79 | void setLabelsVisible(bool visible = true); |
|
82 | void setLabelsVisible(bool visible = true); | |
80 |
|
83 | |||
81 | Q_SIGNALS: |
|
84 | Q_SIGNALS: | |
82 | void added(QList<QPieSlice*> slices); |
|
85 | void added(QList<QPieSlice*> slices); | |
83 | void removed(QList<QPieSlice*> slices); |
|
86 | void removed(QList<QPieSlice*> slices); | |
84 | void clicked(QPieSlice* slice); |
|
87 | void clicked(QPieSlice* slice); | |
85 | void hovered(QPieSlice* slice, bool state); |
|
88 | void hovered(QPieSlice* slice, bool state); | |
86 | void countChanged(); |
|
89 | void countChanged(); | |
87 | void sumChanged(); |
|
90 | void sumChanged(); | |
88 |
|
91 | |||
89 | private: |
|
92 | private: | |
90 | Q_DECLARE_PRIVATE(QPieSeries) |
|
93 | Q_DECLARE_PRIVATE(QPieSeries) | |
91 | Q_DISABLE_COPY(QPieSeries) |
|
94 | Q_DISABLE_COPY(QPieSeries) | |
92 | }; |
|
95 | }; | |
93 |
|
96 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
95 |
|
98 | |||
96 | #endif // PIESERIES_H |
|
99 | #endif // PIESERIES_H |
@@ -1,88 +1,89 | |||||
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 QPIESERIES_P_H |
|
30 | #ifndef QPIESERIES_P_H | |
31 | #define QPIESERIES_P_H |
|
31 | #define QPIESERIES_P_H | |
32 |
|
32 | |||
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 | class QLegendPrivate; |
|
37 | class QLegendPrivate; | |
38 |
|
38 | |||
39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate |
|
39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QPieSeriesPrivate(QPieSeries *parent); |
|
44 | QPieSeriesPrivate(QPieSeries *parent); | |
45 | ~QPieSeriesPrivate(); |
|
45 | ~QPieSeriesPrivate(); | |
46 |
|
46 | |||
47 | void scaleDomain(Domain& domain); |
|
47 | void scaleDomain(Domain& domain); | |
48 | Chart* createGraphics(ChartPresenter *presenter); |
|
48 | Chart* createGraphics(ChartPresenter *presenter); | |
49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); |
|
49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); | |
50 | void initializeAxisX(QAbstractAxis* axis); |
|
50 | void initializeAxisX(QAbstractAxis* axis); | |
51 | void initializeAxisY(QAbstractAxis* axis); |
|
51 | void initializeAxisY(QAbstractAxis* axis); | |
52 | QAbstractAxis::AxisType defaultAxisXType() const; |
|
52 | QAbstractAxis::AxisType defaultAxisXType() const; | |
53 | QAbstractAxis::AxisType defaultAxisYType() const; |
|
53 | QAbstractAxis::AxisType defaultAxisYType() const; | |
54 |
|
54 | |||
55 | void updateDerivativeData(); |
|
55 | void updateDerivativeData(); | |
56 |
|
56 | |||
57 | static QPieSeriesPrivate* fromSeries(QPieSeries *series); |
|
57 | static QPieSeriesPrivate* fromSeries(QPieSeries *series); | |
58 |
|
58 | |||
59 | signals: |
|
59 | signals: | |
60 | void calculatedDataChanged(); |
|
60 | void calculatedDataChanged(); | |
61 | void pieSizeChanged(); |
|
61 | void pieSizeChanged(); | |
62 | void pieStartAngleChanged(); |
|
62 | void pieStartAngleChanged(); | |
63 | void pieEndAngleChanged(); |
|
63 | void pieEndAngleChanged(); | |
64 | void horizontalPositionChanged(); |
|
64 | void horizontalPositionChanged(); | |
65 | void verticalPositionChanged(); |
|
65 | void verticalPositionChanged(); | |
66 |
|
66 | |||
67 | public Q_SLOTS: |
|
67 | public Q_SLOTS: | |
68 | void sliceValueChanged(); |
|
68 | void sliceValueChanged(); | |
69 | void sliceClicked(); |
|
69 | void sliceClicked(); | |
70 | void sliceHovered(bool state); |
|
70 | void sliceHovered(bool state); | |
71 |
|
71 | |||
72 | private: |
|
72 | private: | |
73 | QList<QPieSlice*> m_slices; |
|
73 | QList<QPieSlice*> m_slices; | |
74 | qreal m_pieRelativeHorPos; |
|
74 | qreal m_pieRelativeHorPos; | |
75 | qreal m_pieRelativeVerPos; |
|
75 | qreal m_pieRelativeVerPos; | |
76 | qreal m_pieRelativeSize; |
|
76 | qreal m_pieRelativeSize; | |
77 | qreal m_pieStartAngle; |
|
77 | qreal m_pieStartAngle; | |
78 | qreal m_pieEndAngle; |
|
78 | qreal m_pieEndAngle; | |
79 | qreal m_sum; |
|
79 | qreal m_sum; | |
|
80 | bool m_donutChart; | |||
80 |
|
81 | |||
81 | private: |
|
82 | private: | |
82 | friend class QLegendPrivate; |
|
83 | friend class QLegendPrivate; | |
83 | Q_DECLARE_PUBLIC(QPieSeries) |
|
84 | Q_DECLARE_PUBLIC(QPieSeries) | |
84 | }; |
|
85 | }; | |
85 |
|
86 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
87 |
|
88 | |||
88 | #endif // QPIESERIES_P_H |
|
89 | #endif // QPIESERIES_P_H |
General Comments 0
You need to be logged in to leave comments.
Login now