##// END OF EJS Templates
Removed a few signals from QPieSeries API
Tero Ahola -
r1482:57681a863659
parent child
Show More
@@ -1,215 +1,216
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 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
42 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
42 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
43 connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>)));
43 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
44 connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>)));
44 connect(series, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
45 connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout()));
45 connect(series, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
46 connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout()));
46 connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
47 connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout()));
47 connect(QPieSeriesPrivate::fromSeries(series), SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
48 connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout()));
48
49
49 // 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
50 setZValue(ChartPresenter::PieSeriesZValue);
51 setZValue(ChartPresenter::PieSeriesZValue);
51
52
52 // 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.
53 }
54 }
54
55
55 PieChartItem::~PieChartItem()
56 PieChartItem::~PieChartItem()
56 {
57 {
57 // slices deleted automatically through QGraphicsItem
58 // slices deleted automatically through QGraphicsItem
58 }
59 }
59
60
60 void PieChartItem::handleGeometryChanged(const QRectF& rect)
61 void PieChartItem::handleGeometryChanged(const QRectF& rect)
61 {
62 {
62 prepareGeometryChange();
63 prepareGeometryChange();
63 m_rect = rect;
64 m_rect = rect;
64 updateLayout();
65 updateLayout();
65
66
66 // This is for delayed initialization of the slice items during startup.
67 // This is for delayed initialization of the slice items during startup.
67 // It ensures that startup animation originates from the correct position.
68 // It ensures that startup animation originates from the correct position.
68 if (m_sliceItems.isEmpty())
69 if (m_sliceItems.isEmpty())
69 handleSlicesAdded(m_series->slices());
70 handleSlicesAdded(m_series->slices());
70 }
71 }
71
72
72 void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
73 void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
73 {
74 {
74 Q_UNUSED(minX);
75 Q_UNUSED(minX);
75 Q_UNUSED(maxX);
76 Q_UNUSED(maxX);
76 Q_UNUSED(minY);
77 Q_UNUSED(minY);
77 Q_UNUSED(maxY);
78 Q_UNUSED(maxY);
78 // does not apply to pie
79 // does not apply to pie
79 }
80 }
80
81
81 void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount)
82 void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount)
82 {
83 {
83 Q_UNUSED(min);
84 Q_UNUSED(min);
84 Q_UNUSED(max);
85 Q_UNUSED(max);
85 Q_UNUSED(tickXCount);
86 Q_UNUSED(tickXCount);
86 // does not apply to pie
87 // does not apply to pie
87 }
88 }
88
89
89 void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount)
90 void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount)
90 {
91 {
91 Q_UNUSED(min);
92 Q_UNUSED(min);
92 Q_UNUSED(max);
93 Q_UNUSED(max);
93 Q_UNUSED(tickYCount);
94 Q_UNUSED(tickYCount);
94 // does not apply to pie
95 // does not apply to pie
95 }
96 }
96
97
97 void PieChartItem::updateLayout()
98 void PieChartItem::updateLayout()
98 {
99 {
99 // find pie center coordinates
100 // find pie center coordinates
100 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()));
101 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()));
102
103
103 // find maximum radius for pie
104 // find maximum radius for pie
104 m_pieRadius = m_rect.height() / 2;
105 m_pieRadius = m_rect.height() / 2;
105 if (m_rect.width() < m_rect.height())
106 if (m_rect.width() < m_rect.height())
106 m_pieRadius = m_rect.width() / 2;
107 m_pieRadius = m_rect.width() / 2;
107
108
108 // apply size factor
109 // apply size factor
109 m_pieRadius *= m_series->pieSize();
110 m_pieRadius *= m_series->pieSize();
110
111
111 // set layouts for existing slice items
112 // set layouts for existing slice items
112 foreach (QPieSlice* slice, m_series->slices()) {
113 foreach (QPieSlice* slice, m_series->slices()) {
113 PieSliceItem *sliceItem = m_sliceItems.value(slice);
114 PieSliceItem *sliceItem = m_sliceItems.value(slice);
114 if (sliceItem) {
115 if (sliceItem) {
115 PieSliceData sliceData = updateSliceGeometry(slice);
116 PieSliceData sliceData = updateSliceGeometry(slice);
116 if (animator())
117 if (animator())
117 animator()->updateAnimation(this, sliceItem, sliceData);
118 animator()->updateAnimation(this, sliceItem, sliceData);
118 else
119 else
119 sliceItem->setLayout(sliceData);
120 sliceItem->setLayout(sliceData);
120 }
121 }
121 }
122 }
122
123
123 update();
124 update();
124 }
125 }
125
126
126 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
127 void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices)
127 {
128 {
128 // delay creating slice items until there is a proper rectangle
129 // delay creating slice items until there is a proper rectangle
129 if (!m_rect.isValid() && m_sliceItems.isEmpty())
130 if (!m_rect.isValid() && m_sliceItems.isEmpty())
130 return;
131 return;
131
132
132 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
133 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
133
134
134 bool startupAnimation = m_sliceItems.isEmpty();
135 bool startupAnimation = m_sliceItems.isEmpty();
135
136
136 foreach (QPieSlice *slice, slices) {
137 foreach (QPieSlice *slice, slices) {
137 PieSliceItem* sliceItem = new PieSliceItem(this);
138 PieSliceItem* sliceItem = new PieSliceItem(this);
138 m_sliceItems.insert(slice, sliceItem);
139 m_sliceItems.insert(slice, sliceItem);
139
140
140 // Note: do need to connect to slice valueChanged() etc.
141 // Note: do need to connect to slice valueChanged() etc.
141 // This is handled through calculatedDataChanged signal.
142 // This is handled through calculatedDataChanged signal.
142 connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged()));
143 connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged()));
143 connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged()));
144 connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged()));
144 connect(slice, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged()));
145 connect(slice, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged()));
145 connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged()));
146 connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged()));
146 connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged()));
147 connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged()));
147 connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged()));
148 connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged()));
148 connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged()));
149 connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged()));
149 connect(slice, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged()));
150 connect(slice, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged()));
150 connect(slice, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged()));
151 connect(slice, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged()));
151 connect(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
152 connect(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged()));
152
153
153 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
154 connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked()));
154 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
155 connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool)));
155
156
156 PieSliceData sliceData = updateSliceGeometry(slice);
157 PieSliceData sliceData = updateSliceGeometry(slice);
157 if (animator())
158 if (animator())
158 animator()->addAnimation(this, sliceItem, sliceData, startupAnimation);
159 animator()->addAnimation(this, sliceItem, sliceData, startupAnimation);
159 else
160 else
160 sliceItem->setLayout(sliceData);
161 sliceItem->setLayout(sliceData);
161 }
162 }
162 }
163 }
163
164
164 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
165 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
165 {
166 {
166 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
167 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
167
168
168 foreach (QPieSlice *slice, slices) {
169 foreach (QPieSlice *slice, slices) {
169
170
170 PieSliceItem *sliceItem = m_sliceItems.value(slice);
171 PieSliceItem *sliceItem = m_sliceItems.value(slice);
171
172
172 // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
173 // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
173 if (!sliceItem)
174 if (!sliceItem)
174 continue;
175 continue;
175
176
176 m_sliceItems.remove(slice);
177 m_sliceItems.remove(slice);
177
178
178 if (animator())
179 if (animator())
179 animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem
180 animator()->removeAnimation(this, sliceItem); // animator deletes the PieSliceItem
180 else
181 else
181 delete sliceItem;
182 delete sliceItem;
182 }
183 }
183 }
184 }
184
185
185 void PieChartItem::handleSliceChanged()
186 void PieChartItem::handleSliceChanged()
186 {
187 {
187 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
188 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
188 Q_ASSERT(m_sliceItems.contains(slice));
189 Q_ASSERT(m_sliceItems.contains(slice));
189
190
190 PieSliceItem *sliceItem = m_sliceItems.value(slice);
191 PieSliceItem *sliceItem = m_sliceItems.value(slice);
191 PieSliceData sliceData = updateSliceGeometry(slice);
192 PieSliceData sliceData = updateSliceGeometry(slice);
192 if (animator())
193 if (animator())
193 animator()->updateAnimation(this, sliceItem, sliceData);
194 animator()->updateAnimation(this, sliceItem, sliceData);
194 else
195 else
195 sliceItem->setLayout(sliceData);
196 sliceItem->setLayout(sliceData);
196
197
197 update();
198 update();
198 }
199 }
199
200
200 void PieChartItem::handleSeriesVisibleChanged()
201 void PieChartItem::handleSeriesVisibleChanged()
201 {
202 {
202 setVisible(m_series->isVisible());
203 setVisible(m_series->isVisible());
203 }
204 }
204
205
205 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice)
206 PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice)
206 {
207 {
207 PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data;
208 PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data;
208 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
209 sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice);
209 sliceData.m_radius = m_pieRadius;
210 sliceData.m_radius = m_pieRadius;
210 return sliceData;
211 return sliceData;
211 }
212 }
212
213
213 #include "moc_piechartitem_p.cpp"
214 #include "moc_piechartitem_p.cpp"
214
215
215 QTCOMMERCIALCHART_END_NAMESPACE
216 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,672 +1,632
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
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QPieSeries
34 \class QPieSeries
35 \brief Pie series API for QtCommercial Charts
35 \brief Pie series API for QtCommercial Charts
36
36
37 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
37 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
38 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
38 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
39 The actual slice size is determined by that relative value.
39 The actual slice size is determined by that relative value.
40
40
41 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
41 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
42 These relate to the actual chart rectangle.
42 These relate to the actual chart rectangle.
43
43
44 By default the pie is defined as a full pie but it can also be a partial pie.
44 By default the pie is defined as a full pie but it can also be a partial pie.
45 This can be done by setting a starting angle and angle span to the series.
45 This can be done by setting a starting angle and angle span to the series.
46 Full pie is 360 degrees where 0 is at 12 a'clock.
46 Full pie is 360 degrees where 0 is at 12 a'clock.
47
47
48 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
48 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
49 \image examples_piechart.png
49 \image examples_piechart.png
50 */
50 */
51
51
52 /*!
52 /*!
53 \property QPieSeries::horizontalPosition
53 \property QPieSeries::horizontalPosition
54 \brief Defines the horizontal position of the pie.
54 \brief Defines the horizontal position of the pie.
55
55
56 The value is a relative value to the chart rectangle where:
56 The value is a relative value to the chart rectangle where:
57
57
58 \list
58 \list
59 \o 0.0 is the absolute left.
59 \o 0.0 is the absolute left.
60 \o 1.0 is the absolute right.
60 \o 1.0 is the absolute right.
61 \endlist
61 \endlist
62
62
63 Default value is 0.5 (center).
63 Default value is 0.5 (center).
64
64
65 \sa verticalPosition
65 \sa verticalPosition
66 */
66 */
67
67
68 /*!
68 /*!
69 \fn void QPieSeries::horizontalPositionChanged()
70
71 Emitted then the horizontal position of the pie has changed.
72
73 \sa horizontalPosition
74 */
75
76 /*!
77 \property QPieSeries::verticalPosition
69 \property QPieSeries::verticalPosition
78 \brief Defines the vertical position of the pie.
70 \brief Defines the vertical position of the pie.
79
71
80 The value is a relative value to the chart rectangle where:
72 The value is a relative value to the chart rectangle where:
81
73
82 \list
74 \list
83 \o 0.0 is the absolute top.
75 \o 0.0 is the absolute top.
84 \o 1.0 is the absolute bottom.
76 \o 1.0 is the absolute bottom.
85 \endlist
77 \endlist
86
78
87 Default value is 0.5 (center).
79 Default value is 0.5 (center).
88
80
89 \sa horizontalPosition
81 \sa horizontalPosition
90 */
82 */
91
83
92 /*!
84 /*!
93 \fn void QPieSeries::verticalPositionChanged()
94
95 Emitted then the vertical position of the pie has changed.
96
97 \sa verticalPosition
98 */
99
100 /*!
101 \property QPieSeries::size
85 \property QPieSeries::size
102 \brief Defines the pie size.
86 \brief Defines the pie size.
103
87
104 The value is a relative value to the chart rectangle where:
88 The value is a relative value to the chart rectangle where:
105
89
106 \list
90 \list
107 \o 0.0 is the minimum size (pie not drawn).
91 \o 0.0 is the minimum size (pie not drawn).
108 \o 1.0 is the maximum size that can fit the chart.
92 \o 1.0 is the maximum size that can fit the chart.
109 \endlist
93 \endlist
110
94
111 Default value is 0.7.
95 Default value is 0.7.
112 */
96 */
113
97
114 /*!
98 /*!
115 \fn void QPieSeries::pieSizeChanged()
116
117 Emitted when the pie size has changed.
118
119 \sa size
120 */
121
122 /*!
123 \property QPieSeries::startAngle
99 \property QPieSeries::startAngle
124 \brief Defines the starting angle of the pie.
100 \brief Defines the starting angle of the pie.
125
101
126 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
102 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
127
103
128 Default is value is 0.
104 Default is value is 0.
129 */
105 */
130
106
131 /*!
107 /*!
132 \fn void QPieSeries::pieStartAngleChanged()
133
134 Emitted when the starting angle of the pie has changed.
135
136 \sa startAngle
137 */
138
139 /*!
140 \property QPieSeries::endAngle
108 \property QPieSeries::endAngle
141 \brief Defines the ending angle of the pie.
109 \brief Defines the ending angle of the pie.
142
110
143 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
111 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
144
112
145 Default is value is 360.
113 Default is value is 360.
146 */
114 */
147
115
148 /*!
116 /*!
149 \fn void QPieSeries::pieEndAngleChanged()
150
151 Emitted when the ending angle of the pie has changed.
152
153 \sa endAngle
154 */
155
156 /*!
157 \property QPieSeries::count
117 \property QPieSeries::count
158
118
159 Number of slices in the series.
119 Number of slices in the series.
160 */
120 */
161
121
162 /*!
122 /*!
163 \fn void QPieSeries::countChanged()
123 \fn void QPieSeries::countChanged()
164
124
165 Emitted when the slice count has changed.
125 Emitted when the slice count has changed.
166
126
167 \sa count
127 \sa count
168 */
128 */
169
129
170 /*!
130 /*!
171 \property QPieSeries::sum
131 \property QPieSeries::sum
172
132
173 Sum of all slices.
133 Sum of all slices.
174
134
175 The series keeps track of the sum of all slices it holds.
135 The series keeps track of the sum of all slices it holds.
176 */
136 */
177
137
178 /*!
138 /*!
179 \fn void QPieSeries::sumChanged()
139 \fn void QPieSeries::sumChanged()
180
140
181 Emitted when the sum of all slices has changed.
141 Emitted when the sum of all slices has changed.
182
142
183 \sa sum
143 \sa sum
184 */
144 */
185
145
186 /*!
146 /*!
187 \fn void QPieSeries::added(QList<QPieSlice*> slices)
147 \fn void QPieSeries::added(QList<QPieSlice*> slices)
188
148
189 This signal is emitted when \a slices have been added to the series.
149 This signal is emitted when \a slices have been added to the series.
190
150
191 \sa append(), insert()
151 \sa append(), insert()
192 */
152 */
193
153
194 /*!
154 /*!
195 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
155 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
196
156
197 This signal is emitted when \a slices have been removed from the series.
157 This signal is emitted when \a slices have been removed from the series.
198
158
199 \sa remove()
159 \sa remove()
200 */
160 */
201
161
202 /*!
162 /*!
203 \fn void QPieSeries::clicked(QPieSlice* slice)
163 \fn void QPieSeries::clicked(QPieSlice* slice)
204
164
205 This signal is emitted when a \a slice has been clicked.
165 This signal is emitted when a \a slice has been clicked.
206
166
207 \sa QPieSlice::clicked()
167 \sa QPieSlice::clicked()
208 */
168 */
209
169
210 /*!
170 /*!
211 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
171 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
212
172
213 This signal is emitted when user has hovered over or away from the \a slice.
173 This signal is emitted when user has hovered over or away from the \a slice.
214
174
215 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
175 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
216
176
217 \sa QPieSlice::hovered()
177 \sa QPieSlice::hovered()
218 */
178 */
219
179
220 /*!
180 /*!
221 Constructs a series object which is a child of \a parent.
181 Constructs a series object which is a child of \a parent.
222 */
182 */
223 QPieSeries::QPieSeries(QObject *parent) :
183 QPieSeries::QPieSeries(QObject *parent) :
224 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
184 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
225 {
185 {
226
186
227 }
187 }
228
188
229 /*!
189 /*!
230 Destroys the series and its slices.
190 Destroys the series and its slices.
231 */
191 */
232 QPieSeries::~QPieSeries()
192 QPieSeries::~QPieSeries()
233 {
193 {
234 // NOTE: d_prt destroyed by QObject
194 // NOTE: d_prt destroyed by QObject
235 }
195 }
236
196
237 /*!
197 /*!
238 Returns QChartSeries::SeriesTypePie.
198 Returns QChartSeries::SeriesTypePie.
239 */
199 */
240 QAbstractSeries::SeriesType QPieSeries::type() const
200 QAbstractSeries::SeriesType QPieSeries::type() const
241 {
201 {
242 return QAbstractSeries::SeriesTypePie;
202 return QAbstractSeries::SeriesTypePie;
243 }
203 }
244
204
245 /*!
205 /*!
246 Appends a single \a slice to the series.
206 Appends a single \a slice to the series.
247 Slice ownership is passed to the series.
207 Slice ownership is passed to the series.
248
208
249 Returns true if append was succesfull.
209 Returns true if append was succesfull.
250 */
210 */
251 bool QPieSeries::append(QPieSlice* slice)
211 bool QPieSeries::append(QPieSlice* slice)
252 {
212 {
253 return append(QList<QPieSlice*>() << slice);
213 return append(QList<QPieSlice*>() << slice);
254 }
214 }
255
215
256 /*!
216 /*!
257 Appends an array of \a slices to the series.
217 Appends an array of \a slices to the series.
258 Slice ownership is passed to the series.
218 Slice ownership is passed to the series.
259
219
260 Returns true if append was successfull.
220 Returns true if append was successfull.
261 */
221 */
262 bool QPieSeries::append(QList<QPieSlice*> slices)
222 bool QPieSeries::append(QList<QPieSlice*> slices)
263 {
223 {
264 Q_D(QPieSeries);
224 Q_D(QPieSeries);
265
225
266 if (slices.count() == 0)
226 if (slices.count() == 0)
267 return false;
227 return false;
268
228
269 foreach (QPieSlice* s, slices) {
229 foreach (QPieSlice* s, slices) {
270 if (!s || d->m_slices.contains(s))
230 if (!s || d->m_slices.contains(s))
271 return false;
231 return false;
272 if (s->series()) // already added to some series
232 if (s->series()) // already added to some series
273 return false;
233 return false;
274 }
234 }
275
235
276 foreach (QPieSlice* s, slices) {
236 foreach (QPieSlice* s, slices) {
277 s->setParent(this);
237 s->setParent(this);
278 QPieSlicePrivate::fromSlice(s)->m_series = this;
238 QPieSlicePrivate::fromSlice(s)->m_series = this;
279 d->m_slices << s;
239 d->m_slices << s;
280 }
240 }
281
241
282 d->updateDerivativeData();
242 d->updateDerivativeData();
283
243
284 foreach (QPieSlice* s, slices) {
244 foreach (QPieSlice* s, slices) {
285 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
245 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
286 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
246 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
287 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
247 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
288 }
248 }
289
249
290 emit added(slices);
250 emit added(slices);
291 emit countChanged();
251 emit countChanged();
292
252
293 return true;
253 return true;
294 }
254 }
295
255
296 /*!
256 /*!
297 Appends a single \a slice to the series and returns a reference to the series.
257 Appends a single \a slice to the series and returns a reference to the series.
298 Slice ownership is passed to the series.
258 Slice ownership is passed to the series.
299 */
259 */
300 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
260 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
301 {
261 {
302 append(slice);
262 append(slice);
303 return *this;
263 return *this;
304 }
264 }
305
265
306
266
307 /*!
267 /*!
308 Appends a single slice to the series with give \a value and \a label.
268 Appends a single slice to the series with give \a value and \a label.
309 Slice ownership is passed to the series.
269 Slice ownership is passed to the series.
310 */
270 */
311 QPieSlice* QPieSeries::append(QString label, qreal value)
271 QPieSlice* QPieSeries::append(QString label, qreal value)
312 {
272 {
313 QPieSlice* slice = new QPieSlice(label, value);
273 QPieSlice* slice = new QPieSlice(label, value);
314 append(slice);
274 append(slice);
315 return slice;
275 return slice;
316 }
276 }
317
277
318 /*!
278 /*!
319 Inserts a single \a slice to the series before the slice at \a index position.
279 Inserts a single \a slice to the series before the slice at \a index position.
320 Slice ownership is passed to the series.
280 Slice ownership is passed to the series.
321
281
322 Returns true if insert was successfull.
282 Returns true if insert was successfull.
323 */
283 */
324 bool QPieSeries::insert(int index, QPieSlice* slice)
284 bool QPieSeries::insert(int index, QPieSlice* slice)
325 {
285 {
326 Q_D(QPieSeries);
286 Q_D(QPieSeries);
327
287
328 if (index < 0 || index > d->m_slices.count())
288 if (index < 0 || index > d->m_slices.count())
329 return false;
289 return false;
330
290
331 if (!slice || d->m_slices.contains(slice))
291 if (!slice || d->m_slices.contains(slice))
332 return false;
292 return false;
333
293
334 if (slice->series()) // already added to some series
294 if (slice->series()) // already added to some series
335 return false;
295 return false;
336
296
337 slice->setParent(this);
297 slice->setParent(this);
338 QPieSlicePrivate::fromSlice(slice)->m_series = this;
298 QPieSlicePrivate::fromSlice(slice)->m_series = this;
339 d->m_slices.insert(index, slice);
299 d->m_slices.insert(index, slice);
340
300
341 d->updateDerivativeData();
301 d->updateDerivativeData();
342
302
343 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
303 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
344 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
304 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
345 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
305 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
346
306
347 emit added(QList<QPieSlice*>() << slice);
307 emit added(QList<QPieSlice*>() << slice);
348 emit countChanged();
308 emit countChanged();
349
309
350 return true;
310 return true;
351 }
311 }
352
312
353 /*!
313 /*!
354 Removes a single \a slice from the series and deletes the slice.
314 Removes a single \a slice from the series and deletes the slice.
355
315
356 Do not reference the pointer after this call.
316 Do not reference the pointer after this call.
357
317
358 Returns true if remove was successfull.
318 Returns true if remove was successfull.
359 */
319 */
360 bool QPieSeries::remove(QPieSlice* slice)
320 bool QPieSeries::remove(QPieSlice* slice)
361 {
321 {
362 Q_D(QPieSeries);
322 Q_D(QPieSeries);
363
323
364 if (!d->m_slices.removeOne(slice))
324 if (!d->m_slices.removeOne(slice))
365 return false;
325 return false;
366
326
367 d->updateDerivativeData();
327 d->updateDerivativeData();
368
328
369 emit removed(QList<QPieSlice*>() << slice);
329 emit removed(QList<QPieSlice*>() << slice);
370 emit countChanged();
330 emit countChanged();
371
331
372 delete slice;
332 delete slice;
373 slice = 0;
333 slice = 0;
374
334
375 return true;
335 return true;
376 }
336 }
377
337
378 /*!
338 /*!
379 Clears all slices from the series.
339 Clears all slices from the series.
380 */
340 */
381 void QPieSeries::clear()
341 void QPieSeries::clear()
382 {
342 {
383 Q_D(QPieSeries);
343 Q_D(QPieSeries);
384 if (d->m_slices.count() == 0)
344 if (d->m_slices.count() == 0)
385 return;
345 return;
386
346
387 QList<QPieSlice*> slices = d->m_slices;
347 QList<QPieSlice*> slices = d->m_slices;
388 foreach (QPieSlice* s, d->m_slices) {
348 foreach (QPieSlice* s, d->m_slices) {
389 d->m_slices.removeOne(s);
349 d->m_slices.removeOne(s);
390 delete s;
350 delete s;
391 }
351 }
392
352
393 d->updateDerivativeData();
353 d->updateDerivativeData();
394
354
395 emit removed(slices);
355 emit removed(slices);
396 emit countChanged();
356 emit countChanged();
397 }
357 }
398
358
399 /*!
359 /*!
400 Returns a list of slices that belong to this series.
360 Returns a list of slices that belong to this series.
401 */
361 */
402 QList<QPieSlice*> QPieSeries::slices() const
362 QList<QPieSlice*> QPieSeries::slices() const
403 {
363 {
404 Q_D(const QPieSeries);
364 Q_D(const QPieSeries);
405 return d->m_slices;
365 return d->m_slices;
406 }
366 }
407
367
408 /*!
368 /*!
409 returns the number of the slices in this series.
369 returns the number of the slices in this series.
410 */
370 */
411 int QPieSeries::count() const
371 int QPieSeries::count() const
412 {
372 {
413 Q_D(const QPieSeries);
373 Q_D(const QPieSeries);
414 return d->m_slices.count();
374 return d->m_slices.count();
415 }
375 }
416
376
417 /*!
377 /*!
418 Returns true is the series is empty.
378 Returns true is the series is empty.
419 */
379 */
420 bool QPieSeries::isEmpty() const
380 bool QPieSeries::isEmpty() const
421 {
381 {
422 Q_D(const QPieSeries);
382 Q_D(const QPieSeries);
423 return d->m_slices.isEmpty();
383 return d->m_slices.isEmpty();
424 }
384 }
425
385
426 /*!
386 /*!
427 Returns the sum of all slice values in this series.
387 Returns the sum of all slice values in this series.
428
388
429 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
389 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
430 */
390 */
431 qreal QPieSeries::sum() const
391 qreal QPieSeries::sum() const
432 {
392 {
433 Q_D(const QPieSeries);
393 Q_D(const QPieSeries);
434 return d->m_sum;
394 return d->m_sum;
435 }
395 }
436
396
437 void QPieSeries::setHorizontalPosition(qreal relativePosition)
397 void QPieSeries::setHorizontalPosition(qreal relativePosition)
438 {
398 {
439 Q_D(QPieSeries);
399 Q_D(QPieSeries);
440
400
441 if (relativePosition < 0.0)
401 if (relativePosition < 0.0)
442 relativePosition = 0.0;
402 relativePosition = 0.0;
443 if (relativePosition > 1.0)
403 if (relativePosition > 1.0)
444 relativePosition = 1.0;
404 relativePosition = 1.0;
445
405
446 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
406 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
447 d->m_pieRelativeHorPos = relativePosition;
407 d->m_pieRelativeHorPos = relativePosition;
448 emit horizontalPositionChanged();
408 emit d->horizontalPositionChanged();
449 }
409 }
450 }
410 }
451
411
452 qreal QPieSeries::horizontalPosition() const
412 qreal QPieSeries::horizontalPosition() const
453 {
413 {
454 Q_D(const QPieSeries);
414 Q_D(const QPieSeries);
455 return d->m_pieRelativeHorPos;
415 return d->m_pieRelativeHorPos;
456 }
416 }
457
417
458 void QPieSeries::setVerticalPosition(qreal relativePosition)
418 void QPieSeries::setVerticalPosition(qreal relativePosition)
459 {
419 {
460 Q_D(QPieSeries);
420 Q_D(QPieSeries);
461
421
462 if (relativePosition < 0.0)
422 if (relativePosition < 0.0)
463 relativePosition = 0.0;
423 relativePosition = 0.0;
464 if (relativePosition > 1.0)
424 if (relativePosition > 1.0)
465 relativePosition = 1.0;
425 relativePosition = 1.0;
466
426
467 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
427 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
468 d->m_pieRelativeVerPos = relativePosition;
428 d->m_pieRelativeVerPos = relativePosition;
469 emit verticalPositionChanged();
429 emit d->verticalPositionChanged();
470 }
430 }
471 }
431 }
472
432
473 qreal QPieSeries::verticalPosition() const
433 qreal QPieSeries::verticalPosition() const
474 {
434 {
475 Q_D(const QPieSeries);
435 Q_D(const QPieSeries);
476 return d->m_pieRelativeVerPos;
436 return d->m_pieRelativeVerPos;
477 }
437 }
478
438
479 void QPieSeries::setPieSize(qreal relativeSize)
439 void QPieSeries::setPieSize(qreal relativeSize)
480 {
440 {
481 Q_D(QPieSeries);
441 Q_D(QPieSeries);
482
442
483 if (relativeSize < 0.0)
443 if (relativeSize < 0.0)
484 relativeSize = 0.0;
444 relativeSize = 0.0;
485 if (relativeSize > 1.0)
445 if (relativeSize > 1.0)
486 relativeSize = 1.0;
446 relativeSize = 1.0;
487
447
488 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
448 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
489 d->m_pieRelativeSize = relativeSize;
449 d->m_pieRelativeSize = relativeSize;
490 emit pieSizeChanged();
450 emit d->pieSizeChanged();
491 }
451 }
492 }
452 }
493
453
494 qreal QPieSeries::pieSize() const
454 qreal QPieSeries::pieSize() const
495 {
455 {
496 Q_D(const QPieSeries);
456 Q_D(const QPieSeries);
497 return d->m_pieRelativeSize;
457 return d->m_pieRelativeSize;
498 }
458 }
499
459
500
460
501 void QPieSeries::setPieStartAngle(qreal angle)
461 void QPieSeries::setPieStartAngle(qreal angle)
502 {
462 {
503 Q_D(QPieSeries);
463 Q_D(QPieSeries);
504 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
464 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
505 return;
465 return;
506 d->m_pieStartAngle = angle;
466 d->m_pieStartAngle = angle;
507 d->updateDerivativeData();
467 d->updateDerivativeData();
508 emit pieStartAngleChanged();
468 emit d->pieStartAngleChanged();
509 }
469 }
510
470
511 qreal QPieSeries::pieStartAngle() const
471 qreal QPieSeries::pieStartAngle() const
512 {
472 {
513 Q_D(const QPieSeries);
473 Q_D(const QPieSeries);
514 return d->m_pieStartAngle;
474 return d->m_pieStartAngle;
515 }
475 }
516
476
517 /*!
477 /*!
518 Sets the end angle of the pie.
478 Sets the end angle of the pie.
519
479
520 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
480 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
521
481
522 \a angle must be greater than start angle.
482 \a angle must be greater than start angle.
523
483
524 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
484 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
525 */
485 */
526 void QPieSeries::setPieEndAngle(qreal angle)
486 void QPieSeries::setPieEndAngle(qreal angle)
527 {
487 {
528 Q_D(QPieSeries);
488 Q_D(QPieSeries);
529 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
489 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
530 return;
490 return;
531 d->m_pieEndAngle = angle;
491 d->m_pieEndAngle = angle;
532 d->updateDerivativeData();
492 d->updateDerivativeData();
533 emit pieEndAngleChanged();
493 emit d->pieEndAngleChanged();
534 }
494 }
535
495
536 /*!
496 /*!
537 Returns the end angle of the pie.
497 Returns the end angle of the pie.
538
498
539 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
499 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
540
500
541 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
501 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
542 */
502 */
543 qreal QPieSeries::pieEndAngle() const
503 qreal QPieSeries::pieEndAngle() const
544 {
504 {
545 Q_D(const QPieSeries);
505 Q_D(const QPieSeries);
546 return d->m_pieEndAngle;
506 return d->m_pieEndAngle;
547 }
507 }
548
508
549 /*!
509 /*!
550 Sets the all the slice labels \a visible or invisible.
510 Sets the all the slice labels \a visible or invisible.
551
511
552 Note that this affects only the current slices in the series.
512 Note that this affects only the current slices in the series.
553 If user adds a new slice the default label visibility is false.
513 If user adds a new slice the default label visibility is false.
554
514
555 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
515 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
556 */
516 */
557 void QPieSeries::setLabelsVisible(bool visible)
517 void QPieSeries::setLabelsVisible(bool visible)
558 {
518 {
559 Q_D(QPieSeries);
519 Q_D(QPieSeries);
560 foreach (QPieSlice* s, d->m_slices)
520 foreach (QPieSlice* s, d->m_slices)
561 s->setLabelVisible(visible);
521 s->setLabelVisible(visible);
562 }
522 }
563
523
564 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
524 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
565
525
566
526
567 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
527 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
568 QAbstractSeriesPrivate(parent),
528 QAbstractSeriesPrivate(parent),
569 m_pieRelativeHorPos(0.5),
529 m_pieRelativeHorPos(0.5),
570 m_pieRelativeVerPos(0.5),
530 m_pieRelativeVerPos(0.5),
571 m_pieRelativeSize(0.7),
531 m_pieRelativeSize(0.7),
572 m_pieStartAngle(0),
532 m_pieStartAngle(0),
573 m_pieEndAngle(360),
533 m_pieEndAngle(360),
574 m_sum(0)
534 m_sum(0)
575 {
535 {
576 }
536 }
577
537
578 QPieSeriesPrivate::~QPieSeriesPrivate()
538 QPieSeriesPrivate::~QPieSeriesPrivate()
579 {
539 {
580 }
540 }
581
541
582 void QPieSeriesPrivate::updateDerivativeData()
542 void QPieSeriesPrivate::updateDerivativeData()
583 {
543 {
584 // calculate sum of all slices
544 // calculate sum of all slices
585 qreal sum = 0;
545 qreal sum = 0;
586 foreach (QPieSlice* s, m_slices)
546 foreach (QPieSlice* s, m_slices)
587 sum += s->value();
547 sum += s->value();
588
548
589 if (!qFuzzyIsNull(m_sum - sum)) {
549 if (!qFuzzyIsNull(m_sum - sum)) {
590 m_sum = sum;
550 m_sum = sum;
591 emit q_func()->sumChanged();
551 emit q_func()->sumChanged();
592 }
552 }
593
553
594 // nothing to show..
554 // nothing to show..
595 if (qFuzzyIsNull(m_sum))
555 if (qFuzzyIsNull(m_sum))
596 return;
556 return;
597
557
598 // update slice attributes
558 // update slice attributes
599 qreal sliceAngle = m_pieStartAngle;
559 qreal sliceAngle = m_pieStartAngle;
600 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
560 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
601 QVector<QPieSlice*> changed;
561 QVector<QPieSlice*> changed;
602 foreach (QPieSlice* s, m_slices) {
562 foreach (QPieSlice* s, m_slices) {
603 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
563 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
604 d->setPercentage(s->value() / m_sum);
564 d->setPercentage(s->value() / m_sum);
605 d->setStartAngle(sliceAngle);
565 d->setStartAngle(sliceAngle);
606 d->setAngleSpan(pieSpan * s->percentage());
566 d->setAngleSpan(pieSpan * s->percentage());
607 sliceAngle += s->angleSpan();
567 sliceAngle += s->angleSpan();
608 }
568 }
609
569
610
570
611 emit calculatedDataChanged();
571 emit calculatedDataChanged();
612 }
572 }
613
573
614 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
574 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
615 {
575 {
616 return series->d_func();
576 return series->d_func();
617 }
577 }
618
578
619 void QPieSeriesPrivate::sliceValueChanged()
579 void QPieSeriesPrivate::sliceValueChanged()
620 {
580 {
621 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
581 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
622 updateDerivativeData();
582 updateDerivativeData();
623 }
583 }
624
584
625 void QPieSeriesPrivate::sliceClicked()
585 void QPieSeriesPrivate::sliceClicked()
626 {
586 {
627 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
587 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
628 Q_ASSERT(m_slices.contains(slice));
588 Q_ASSERT(m_slices.contains(slice));
629 Q_Q(QPieSeries);
589 Q_Q(QPieSeries);
630 emit q->clicked(slice);
590 emit q->clicked(slice);
631 }
591 }
632
592
633 void QPieSeriesPrivate::sliceHovered(bool state)
593 void QPieSeriesPrivate::sliceHovered(bool state)
634 {
594 {
635 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
595 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
636 Q_ASSERT(m_slices.contains(slice));
596 Q_ASSERT(m_slices.contains(slice));
637 Q_Q(QPieSeries);
597 Q_Q(QPieSeries);
638 emit q->hovered(slice, state);
598 emit q->hovered(slice, state);
639 }
599 }
640
600
641 void QPieSeriesPrivate::scaleDomain(Domain& domain)
601 void QPieSeriesPrivate::scaleDomain(Domain& domain)
642 {
602 {
643 Q_UNUSED(domain);
603 Q_UNUSED(domain);
644 // does not apply to pie
604 // does not apply to pie
645 }
605 }
646
606
647 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
607 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
648 {
608 {
649 Q_Q(QPieSeries);
609 Q_Q(QPieSeries);
650 PieChartItem* pie = new PieChartItem(q,presenter);
610 PieChartItem* pie = new PieChartItem(q,presenter);
651 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
611 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
652 presenter->animator()->addAnimation(pie);
612 presenter->animator()->addAnimation(pie);
653 }
613 }
654 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
614 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
655 return pie;
615 return pie;
656 }
616 }
657
617
658 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
618 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
659 {
619 {
660 Q_Q(QPieSeries);
620 Q_Q(QPieSeries);
661 QList<LegendMarker*> markers;
621 QList<LegendMarker*> markers;
662 foreach(QPieSlice* slice, q->slices()) {
622 foreach(QPieSlice* slice, q->slices()) {
663 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
623 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
664 markers << marker;
624 markers << marker;
665 }
625 }
666 return markers;
626 return markers;
667 }
627 }
668
628
669 #include "moc_qpieseries.cpp"
629 #include "moc_qpieseries.cpp"
670 #include "moc_qpieseries_p.cpp"
630 #include "moc_qpieseries_p.cpp"
671
631
672 QTCOMMERCIALCHART_END_NAMESPACE
632 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,101 +1,96
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 NOTIFY horizontalPositionChanged)
33 Q_PROPERTY(qreal horizontalPosition READ horizontalPosition WRITE setHorizontalPosition)
34 Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition NOTIFY verticalPositionChanged)
34 Q_PROPERTY(qreal verticalPosition READ verticalPosition WRITE setVerticalPosition)
35 Q_PROPERTY(qreal size READ pieSize WRITE setPieSize NOTIFY pieSizeChanged)
35 Q_PROPERTY(qreal size READ pieSize WRITE setPieSize)
36 Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle NOTIFY pieStartAngleChanged)
36 Q_PROPERTY(qreal startAngle READ pieStartAngle WRITE setPieStartAngle)
37 Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle NOTIFY pieEndAngleChanged)
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 setHorizontalPosition(qreal relativePosition);
64 void setHorizontalPosition(qreal relativePosition);
65 qreal horizontalPosition() const;
65 qreal horizontalPosition() const;
66
66
67 void setVerticalPosition(qreal relativePosition);
67 void setVerticalPosition(qreal relativePosition);
68 qreal verticalPosition() const;
68 qreal verticalPosition() const;
69
69
70 void setPieSize(qreal relativeSize);
70 void setPieSize(qreal relativeSize);
71 qreal pieSize() const;
71 qreal pieSize() const;
72
72
73 void setPieStartAngle(qreal startAngle);
73 void setPieStartAngle(qreal startAngle);
74 qreal pieStartAngle() const;
74 qreal pieStartAngle() const;
75
75
76 void setPieEndAngle(qreal endAngle);
76 void setPieEndAngle(qreal endAngle);
77 qreal pieEndAngle() const;
77 qreal pieEndAngle() const;
78
78
79 void setLabelsVisible(bool visible = true);
79 void setLabelsVisible(bool visible = true);
80
80
81 Q_SIGNALS:
81 Q_SIGNALS:
82 void added(QList<QPieSlice*> slices);
82 void added(QList<QPieSlice*> slices);
83 void removed(QList<QPieSlice*> slices);
83 void removed(QList<QPieSlice*> slices);
84 void clicked(QPieSlice* slice);
84 void clicked(QPieSlice* slice);
85 void hovered(QPieSlice* slice, bool state);
85 void hovered(QPieSlice* slice, bool state);
86 void countChanged();
86 void countChanged();
87 void sumChanged();
87 void sumChanged();
88 void pieSizeChanged();
89 void pieStartAngleChanged();
90 void pieEndAngleChanged();
91 void horizontalPositionChanged();
92 void verticalPositionChanged();
93
88
94 private:
89 private:
95 Q_DECLARE_PRIVATE(QPieSeries)
90 Q_DECLARE_PRIVATE(QPieSeries)
96 Q_DISABLE_COPY(QPieSeries)
91 Q_DISABLE_COPY(QPieSeries)
97 };
92 };
98
93
99 QTCOMMERCIALCHART_END_NAMESPACE
94 QTCOMMERCIALCHART_END_NAMESPACE
100
95
101 #endif // PIESERIES_H
96 #endif // PIESERIES_H
@@ -1,79 +1,84
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
50
51 void updateDerivativeData();
51 void updateDerivativeData();
52
52
53 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
53 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
54
54
55 signals:
55 signals:
56 void calculatedDataChanged();
56 void calculatedDataChanged();
57 void pieSizeChanged();
58 void pieStartAngleChanged();
59 void pieEndAngleChanged();
60 void horizontalPositionChanged();
61 void verticalPositionChanged();
57
62
58 public Q_SLOTS:
63 public Q_SLOTS:
59 void sliceValueChanged();
64 void sliceValueChanged();
60 void sliceClicked();
65 void sliceClicked();
61 void sliceHovered(bool state);
66 void sliceHovered(bool state);
62
67
63 private:
68 private:
64 QList<QPieSlice*> m_slices;
69 QList<QPieSlice*> m_slices;
65 qreal m_pieRelativeHorPos;
70 qreal m_pieRelativeHorPos;
66 qreal m_pieRelativeVerPos;
71 qreal m_pieRelativeVerPos;
67 qreal m_pieRelativeSize;
72 qreal m_pieRelativeSize;
68 qreal m_pieStartAngle;
73 qreal m_pieStartAngle;
69 qreal m_pieEndAngle;
74 qreal m_pieEndAngle;
70 qreal m_sum;
75 qreal m_sum;
71
76
72 private:
77 private:
73 friend class QLegendPrivate;
78 friend class QLegendPrivate;
74 Q_DECLARE_PUBLIC(QPieSeries)
79 Q_DECLARE_PUBLIC(QPieSeries)
75 };
80 };
76
81
77 QTCOMMERCIALCHART_END_NAMESPACE
82 QTCOMMERCIALCHART_END_NAMESPACE
78
83
79 #endif // QPIESERIES_P_H
84 #endif // QPIESERIES_P_H
@@ -1,563 +1,555
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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qchartview.h>
22 #include <qchartview.h>
23 #include <qchart.h>
23 #include <qchart.h>
24 #include <qpieseries.h>
24 #include <qpieseries.h>
25 #include <qpieslice.h>
25 #include <qpieslice.h>
26 #include <qpiemodelmapper.h>
26 #include <qpiemodelmapper.h>
27 #include <QStandardItemModel>
27 #include <QStandardItemModel>
28 #include <tst_definitions.h>
28 #include <tst_definitions.h>
29
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
31
32 Q_DECLARE_METATYPE(QPieSlice*)
32 Q_DECLARE_METATYPE(QPieSlice*)
33 Q_DECLARE_METATYPE(QList<QPieSlice*>)
33 Q_DECLARE_METATYPE(QList<QPieSlice*>)
34
34
35 class tst_qpieseries : public QObject
35 class tst_qpieseries : public QObject
36 {
36 {
37 Q_OBJECT
37 Q_OBJECT
38
38
39 public slots:
39 public slots:
40 void initTestCase();
40 void initTestCase();
41 void cleanupTestCase();
41 void cleanupTestCase();
42 void init();
42 void init();
43 void cleanup();
43 void cleanup();
44
44
45 private slots:
45 private slots:
46 void properties();
46 void properties();
47 void append();
47 void append();
48 void appendAnimated();
48 void appendAnimated();
49 void insert();
49 void insert();
50 void insertAnimated();
50 void insertAnimated();
51 void remove();
51 void remove();
52 void removeAnimated();
52 void removeAnimated();
53 void calculatedValues();
53 void calculatedValues();
54 void clickedSignal();
54 void clickedSignal();
55 void hoverSignal();
55 void hoverSignal();
56 void sliceSeries();
56 void sliceSeries();
57
57
58 private:
58 private:
59 void verifyCalculatedData(const QPieSeries &series, bool *ok);
59 void verifyCalculatedData(const QPieSeries &series, bool *ok);
60
60
61 private:
61 private:
62 QChartView *m_view;
62 QChartView *m_view;
63 QPieSeries *m_series;
63 QPieSeries *m_series;
64 };
64 };
65
65
66 void tst_qpieseries::initTestCase()
66 void tst_qpieseries::initTestCase()
67 {
67 {
68 qRegisterMetaType<QPieSlice*>("QPieSlice*");
68 qRegisterMetaType<QPieSlice*>("QPieSlice*");
69 qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>");
69 qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>");
70 }
70 }
71
71
72 void tst_qpieseries::cleanupTestCase()
72 void tst_qpieseries::cleanupTestCase()
73 {
73 {
74 }
74 }
75
75
76 void tst_qpieseries::init()
76 void tst_qpieseries::init()
77 {
77 {
78 m_view = new QChartView();
78 m_view = new QChartView();
79 m_series = new QPieSeries(m_view);
79 m_series = new QPieSeries(m_view);
80 }
80 }
81
81
82 void tst_qpieseries::cleanup()
82 void tst_qpieseries::cleanup()
83 {
83 {
84 delete m_view;
84 delete m_view;
85 m_view = 0;
85 m_view = 0;
86 m_series = 0;
86 m_series = 0;
87 }
87 }
88
88
89 void tst_qpieseries::properties()
89 void tst_qpieseries::properties()
90 {
90 {
91 QSignalSpy countSpy(m_series, SIGNAL(countChanged()));
91 QSignalSpy countSpy(m_series, SIGNAL(countChanged()));
92 QSignalSpy sumSpy(m_series, SIGNAL(sumChanged()));
92 QSignalSpy sumSpy(m_series, SIGNAL(sumChanged()));
93 QSignalSpy sizeSpy(m_series, SIGNAL(pieSizeChanged()));
94 QSignalSpy startAngleSpy(m_series, SIGNAL(pieStartAngleChanged()));
95 QSignalSpy endAngleSpy(m_series, SIGNAL(pieEndAngleChanged()));
96 QSignalSpy horPosSpy(m_series, SIGNAL(horizontalPositionChanged()));
97 QSignalSpy verPosSpy(m_series, SIGNAL(verticalPositionChanged()));
98
93
99 QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie);
94 QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie);
100 QVERIFY(m_series->count() == 0);
95 QVERIFY(m_series->count() == 0);
101 QVERIFY(m_series->isEmpty());
96 QVERIFY(m_series->isEmpty());
102 QCOMPARE(m_series->sum(), 0.0);
97 QCOMPARE(m_series->sum(), 0.0);
103 QCOMPARE(m_series->horizontalPosition(), 0.5);
98 QCOMPARE(m_series->horizontalPosition(), 0.5);
104 QCOMPARE(m_series->verticalPosition(), 0.5);
99 QCOMPARE(m_series->verticalPosition(), 0.5);
105 QCOMPARE(m_series->pieSize(), 0.7);
100 QCOMPARE(m_series->pieSize(), 0.7);
106 QCOMPARE(m_series->pieStartAngle(), 0.0);
101 QCOMPARE(m_series->pieStartAngle(), 0.0);
107 QCOMPARE(m_series->pieEndAngle(), 360.0);
102 QCOMPARE(m_series->pieEndAngle(), 360.0);
108
103
109 m_series->append("s1", 1);
104 m_series->append("s1", 1);
110 m_series->append("s2", 1);
105 m_series->append("s2", 1);
111 m_series->append("s3", 1);
106 m_series->append("s3", 1);
112 m_series->insert(1, new QPieSlice("s4", 1));
107 m_series->insert(1, new QPieSlice("s4", 1));
113 m_series->remove(m_series->slices().first());
108 m_series->remove(m_series->slices().first());
114 QCOMPARE(m_series->count(), 3);
109 QCOMPARE(m_series->count(), 3);
115 QCOMPARE(m_series->sum(), 3.0);
110 QCOMPARE(m_series->sum(), 3.0);
116 m_series->clear();
111 m_series->clear();
117 QCOMPARE(m_series->count(), 0);
112 QCOMPARE(m_series->count(), 0);
118 QCOMPARE(m_series->sum(), 0.0);
113 QCOMPARE(m_series->sum(), 0.0);
119 QCOMPARE(countSpy.count(), 6);
114 QCOMPARE(countSpy.count(), 6);
120 QCOMPARE(sumSpy.count(), 6);
115 QCOMPARE(sumSpy.count(), 6);
121
116
122 m_series->setPieSize(-1.0);
117 m_series->setPieSize(-1.0);
123 QCOMPARE(m_series->pieSize(), 0.0);
118 QCOMPARE(m_series->pieSize(), 0.0);
124 m_series->setPieSize(0.0);
119 m_series->setPieSize(0.0);
125 m_series->setPieSize(0.9);
120 m_series->setPieSize(0.9);
126 m_series->setPieSize(2.0);
121 m_series->setPieSize(2.0);
127 QCOMPARE(m_series->pieSize(), 1.0);
122 QCOMPARE(m_series->pieSize(), 1.0);
128 QCOMPARE(sizeSpy.count(), 3);
129
123
130 m_series->setPieStartAngle(0);
124 m_series->setPieStartAngle(0);
131 m_series->setPieStartAngle(-180);
125 m_series->setPieStartAngle(-180);
132 m_series->setPieStartAngle(180);
126 m_series->setPieStartAngle(180);
133 QCOMPARE(startAngleSpy.count(), 2);
127 QCOMPARE(m_series->pieStartAngle(), 180.0);
134
128
135 m_series->setPieEndAngle(360);
129 m_series->setPieEndAngle(360);
136 m_series->setPieEndAngle(-180);
130 m_series->setPieEndAngle(-180);
137 m_series->setPieEndAngle(180);
131 m_series->setPieEndAngle(180);
138 QCOMPARE(endAngleSpy.count(), 2);
132 QCOMPARE(m_series->pieEndAngle(), 180.0);
139
133
140 m_series->setHorizontalPosition(0.5);
134 m_series->setHorizontalPosition(0.5);
141 m_series->setHorizontalPosition(-1.0);
135 m_series->setHorizontalPosition(-1.0);
142 QCOMPARE(m_series->horizontalPosition(), 0.0);
136 QCOMPARE(m_series->horizontalPosition(), 0.0);
143 m_series->setHorizontalPosition(1.0);
137 m_series->setHorizontalPosition(1.0);
144 m_series->setHorizontalPosition(2.0);
138 m_series->setHorizontalPosition(2.0);
145 QCOMPARE(m_series->horizontalPosition(), 1.0);
139 QCOMPARE(m_series->horizontalPosition(), 1.0);
146 QCOMPARE(horPosSpy.count(), 2);
147
140
148 m_series->setVerticalPosition(0.5);
141 m_series->setVerticalPosition(0.5);
149 m_series->setVerticalPosition(-1.0);
142 m_series->setVerticalPosition(-1.0);
150 QCOMPARE(m_series->verticalPosition(), 0.0);
143 QCOMPARE(m_series->verticalPosition(), 0.0);
151 m_series->setVerticalPosition(1.0);
144 m_series->setVerticalPosition(1.0);
152 m_series->setVerticalPosition(2.0);
145 m_series->setVerticalPosition(2.0);
153 QCOMPARE(m_series->verticalPosition(), 1.0);
146 QCOMPARE(m_series->verticalPosition(), 1.0);
154 QCOMPARE(verPosSpy.count(), 2);
155 }
147 }
156
148
157 void tst_qpieseries::append()
149 void tst_qpieseries::append()
158 {
150 {
159 m_view->chart()->addSeries(m_series);
151 m_view->chart()->addSeries(m_series);
160 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
152 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
161
153
162 // append pointer
154 // append pointer
163 QPieSlice *slice1 = 0;
155 QPieSlice *slice1 = 0;
164 QVERIFY(!m_series->append(slice1));
156 QVERIFY(!m_series->append(slice1));
165 slice1 = new QPieSlice("slice 1", 1);
157 slice1 = new QPieSlice("slice 1", 1);
166 QVERIFY(m_series->append(slice1));
158 QVERIFY(m_series->append(slice1));
167 QVERIFY(!m_series->append(slice1));
159 QVERIFY(!m_series->append(slice1));
168 QCOMPARE(m_series->count(), 1);
160 QCOMPARE(m_series->count(), 1);
169 QCOMPARE(addedSpy.count(), 1);
161 QCOMPARE(addedSpy.count(), 1);
170 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
162 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
171 QCOMPARE(added.count(), 1);
163 QCOMPARE(added.count(), 1);
172 QCOMPARE(added.first(), slice1);
164 QCOMPARE(added.first(), slice1);
173
165
174 // try to append same slice to another series
166 // try to append same slice to another series
175 QPieSeries series2;
167 QPieSeries series2;
176 QVERIFY(!series2.append(slice1));
168 QVERIFY(!series2.append(slice1));
177
169
178 // append pointer list
170 // append pointer list
179 QList<QPieSlice *> list;
171 QList<QPieSlice *> list;
180 QVERIFY(!m_series->append(list));
172 QVERIFY(!m_series->append(list));
181 list << (QPieSlice *) 0;
173 list << (QPieSlice *) 0;
182 QVERIFY(!m_series->append(list));
174 QVERIFY(!m_series->append(list));
183 list.clear();
175 list.clear();
184 list << new QPieSlice("slice 2", 2);
176 list << new QPieSlice("slice 2", 2);
185 list << new QPieSlice("slice 3", 3);
177 list << new QPieSlice("slice 3", 3);
186 QVERIFY(m_series->append(list));
178 QVERIFY(m_series->append(list));
187 QVERIFY(!m_series->append(list));
179 QVERIFY(!m_series->append(list));
188 QCOMPARE(m_series->count(), 3);
180 QCOMPARE(m_series->count(), 3);
189 QCOMPARE(addedSpy.count(), 2);
181 QCOMPARE(addedSpy.count(), 2);
190 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
182 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
191 QCOMPARE(added.count(), 2);
183 QCOMPARE(added.count(), 2);
192 QCOMPARE(added, list);
184 QCOMPARE(added, list);
193
185
194 // append operator
186 // append operator
195 QPieSlice *slice4 = new QPieSlice("slice 4", 4);
187 QPieSlice *slice4 = new QPieSlice("slice 4", 4);
196 *m_series << slice4;
188 *m_series << slice4;
197 *m_series << slice1; // fails because already added
189 *m_series << slice1; // fails because already added
198 QCOMPARE(m_series->count(), 4);
190 QCOMPARE(m_series->count(), 4);
199 QCOMPARE(addedSpy.count(), 3);
191 QCOMPARE(addedSpy.count(), 3);
200 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
192 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
201 QCOMPARE(added.count(), 1);
193 QCOMPARE(added.count(), 1);
202 QCOMPARE(added.first(), slice4);
194 QCOMPARE(added.first(), slice4);
203
195
204 // append with params
196 // append with params
205 QPieSlice *slice5 = m_series->append("slice 5", 5);
197 QPieSlice *slice5 = m_series->append("slice 5", 5);
206 QVERIFY(slice5 != 0);
198 QVERIFY(slice5 != 0);
207 QCOMPARE(slice5->value(), 5.0);
199 QCOMPARE(slice5->value(), 5.0);
208 QCOMPARE(slice5->label(), QString("slice 5"));
200 QCOMPARE(slice5->label(), QString("slice 5"));
209 QCOMPARE(m_series->count(), 5);
201 QCOMPARE(m_series->count(), 5);
210 QCOMPARE(addedSpy.count(), 4);
202 QCOMPARE(addedSpy.count(), 4);
211 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
203 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
212 QCOMPARE(added.count(), 1);
204 QCOMPARE(added.count(), 1);
213 QCOMPARE(added.first(), slice5);
205 QCOMPARE(added.first(), slice5);
214
206
215 // check slices
207 // check slices
216 QVERIFY(!m_series->isEmpty());
208 QVERIFY(!m_series->isEmpty());
217 for (int i=0; i<m_series->count(); i++) {
209 for (int i=0; i<m_series->count(); i++) {
218 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
210 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
219 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
211 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
220 }
212 }
221 }
213 }
222
214
223 void tst_qpieseries::appendAnimated()
215 void tst_qpieseries::appendAnimated()
224 {
216 {
225 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
217 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
226 }
218 }
227
219
228 void tst_qpieseries::insert()
220 void tst_qpieseries::insert()
229 {
221 {
230 m_view->chart()->addSeries(m_series);
222 m_view->chart()->addSeries(m_series);
231 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
223 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
232
224
233 // insert one slice
225 // insert one slice
234 QPieSlice *slice1 = 0;
226 QPieSlice *slice1 = 0;
235 QVERIFY(!m_series->insert(0, slice1));
227 QVERIFY(!m_series->insert(0, slice1));
236 slice1 = new QPieSlice("slice 1", 1);
228 slice1 = new QPieSlice("slice 1", 1);
237 QVERIFY(!m_series->insert(-1, slice1));
229 QVERIFY(!m_series->insert(-1, slice1));
238 QVERIFY(!m_series->insert(5, slice1));
230 QVERIFY(!m_series->insert(5, slice1));
239 QVERIFY(m_series->insert(0, slice1));
231 QVERIFY(m_series->insert(0, slice1));
240 QVERIFY(!m_series->insert(0, slice1));
232 QVERIFY(!m_series->insert(0, slice1));
241 QCOMPARE(m_series->count(), 1);
233 QCOMPARE(m_series->count(), 1);
242 QCOMPARE(addedSpy.count(), 1);
234 QCOMPARE(addedSpy.count(), 1);
243 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
235 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
244 QCOMPARE(added.count(), 1);
236 QCOMPARE(added.count(), 1);
245 QCOMPARE(added.first(), slice1);
237 QCOMPARE(added.first(), slice1);
246
238
247 // try to insert same slice to another series
239 // try to insert same slice to another series
248 QPieSeries series2;
240 QPieSeries series2;
249 QVERIFY(!series2.insert(0, slice1));
241 QVERIFY(!series2.insert(0, slice1));
250
242
251 // add some more slices
243 // add some more slices
252 QPieSlice *slice2 = m_series->append("slice 2", 2);
244 QPieSlice *slice2 = m_series->append("slice 2", 2);
253 QPieSlice *slice4 = m_series->append("slice 4", 4);
245 QPieSlice *slice4 = m_series->append("slice 4", 4);
254 QCOMPARE(m_series->count(), 3);
246 QCOMPARE(m_series->count(), 3);
255 QCOMPARE(addedSpy.count(), 3);
247 QCOMPARE(addedSpy.count(), 3);
256 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
248 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
257 QCOMPARE(added.count(), 1);
249 QCOMPARE(added.count(), 1);
258 QCOMPARE(added.first(), slice2);
250 QCOMPARE(added.first(), slice2);
259 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
251 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
260 QCOMPARE(added.count(), 1);
252 QCOMPARE(added.count(), 1);
261 QCOMPARE(added.first(), slice4);
253 QCOMPARE(added.first(), slice4);
262
254
263 // insert between slices
255 // insert between slices
264 QPieSlice *slice3 = new QPieSlice("slice 3", 3);
256 QPieSlice *slice3 = new QPieSlice("slice 3", 3);
265 m_series->insert(2, slice3);
257 m_series->insert(2, slice3);
266 QCOMPARE(m_series->count(), 4);
258 QCOMPARE(m_series->count(), 4);
267 QCOMPARE(addedSpy.count(), 4);
259 QCOMPARE(addedSpy.count(), 4);
268 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
260 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
269 QCOMPARE(added.count(), 1);
261 QCOMPARE(added.count(), 1);
270 QCOMPARE(added.first(), slice3);
262 QCOMPARE(added.first(), slice3);
271
263
272 // check slices
264 // check slices
273 for (int i=0; i<m_series->count(); i++) {
265 for (int i=0; i<m_series->count(); i++) {
274 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
266 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
275 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
267 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
276 }
268 }
277 }
269 }
278
270
279 void tst_qpieseries::insertAnimated()
271 void tst_qpieseries::insertAnimated()
280 {
272 {
281 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
273 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
282 }
274 }
283
275
284 void tst_qpieseries::remove()
276 void tst_qpieseries::remove()
285 {
277 {
286 m_view->chart()->addSeries(m_series);
278 m_view->chart()->addSeries(m_series);
287 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
279 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
288
280
289 // add some slices
281 // add some slices
290 QPieSlice *slice1 = m_series->append("slice 1", 1);
282 QPieSlice *slice1 = m_series->append("slice 1", 1);
291 QPieSlice *slice2 = m_series->append("slice 2", 2);
283 QPieSlice *slice2 = m_series->append("slice 2", 2);
292 QPieSlice *slice3 = m_series->append("slice 3", 3);
284 QPieSlice *slice3 = m_series->append("slice 3", 3);
293 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
285 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
294 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
286 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
295 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
287 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
296 QCOMPARE(m_series->count(), 3);
288 QCOMPARE(m_series->count(), 3);
297
289
298 // null pointer remove
290 // null pointer remove
299 QVERIFY(!m_series->remove(0));
291 QVERIFY(!m_series->remove(0));
300
292
301 // remove first
293 // remove first
302 QVERIFY(m_series->remove(slice1));
294 QVERIFY(m_series->remove(slice1));
303 QVERIFY(!m_series->remove(slice1));
295 QVERIFY(!m_series->remove(slice1));
304 QCOMPARE(m_series->count(), 2);
296 QCOMPARE(m_series->count(), 2);
305 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
297 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
306 QCOMPARE(removedSpy.count(), 1);
298 QCOMPARE(removedSpy.count(), 1);
307 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
299 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
308 QCOMPARE(removed.count(), 1);
300 QCOMPARE(removed.count(), 1);
309 QCOMPARE(removed.first(), slice1);
301 QCOMPARE(removed.first(), slice1);
310
302
311 // remove all
303 // remove all
312 m_series->clear();
304 m_series->clear();
313 QVERIFY(m_series->isEmpty());
305 QVERIFY(m_series->isEmpty());
314 QVERIFY(m_series->slices().isEmpty());
306 QVERIFY(m_series->slices().isEmpty());
315 QCOMPARE(m_series->count(), 0);
307 QCOMPARE(m_series->count(), 0);
316 QCOMPARE(removedSpy.count(), 2);
308 QCOMPARE(removedSpy.count(), 2);
317 removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0));
309 removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0));
318 QCOMPARE(removed.count(), 2);
310 QCOMPARE(removed.count(), 2);
319 QCOMPARE(removed.first(), slice2);
311 QCOMPARE(removed.first(), slice2);
320 QCOMPARE(removed.last(), slice3);
312 QCOMPARE(removed.last(), slice3);
321
313
322 // check that slices were actually destroyed
314 // check that slices were actually destroyed
323 TRY_COMPARE(spy1.count(), 1);
315 TRY_COMPARE(spy1.count(), 1);
324 TRY_COMPARE(spy2.count(), 1);
316 TRY_COMPARE(spy2.count(), 1);
325 TRY_COMPARE(spy3.count(), 1);
317 TRY_COMPARE(spy3.count(), 1);
326 }
318 }
327
319
328 void tst_qpieseries::removeAnimated()
320 void tst_qpieseries::removeAnimated()
329 {
321 {
330 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
322 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
331 }
323 }
332
324
333 void tst_qpieseries::calculatedValues()
325 void tst_qpieseries::calculatedValues()
334 {
326 {
335 m_view->chart()->addSeries(m_series);
327 m_view->chart()->addSeries(m_series);
336
328
337 QPieSlice *slice1 = new QPieSlice("slice 1", 1);
329 QPieSlice *slice1 = new QPieSlice("slice 1", 1);
338 QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged()));
330 QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged()));
339 QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged()));
331 QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged()));
340 QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged()));
332 QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged()));
341
333
342 // add a slice
334 // add a slice
343 m_series->append(slice1);
335 m_series->append(slice1);
344 bool ok;
336 bool ok;
345 verifyCalculatedData(*m_series, &ok);
337 verifyCalculatedData(*m_series, &ok);
346 if (!ok)
338 if (!ok)
347 return;
339 return;
348 QCOMPARE(percentageSpy.count(), 1);
340 QCOMPARE(percentageSpy.count(), 1);
349 QCOMPARE(startAngleSpy.count(), 0);
341 QCOMPARE(startAngleSpy.count(), 0);
350 QCOMPARE(angleSpanSpy.count(), 1);
342 QCOMPARE(angleSpanSpy.count(), 1);
351
343
352 // add some more slices
344 // add some more slices
353 QList<QPieSlice *> list;
345 QList<QPieSlice *> list;
354 list << new QPieSlice("slice 2", 2);
346 list << new QPieSlice("slice 2", 2);
355 list << new QPieSlice("slice 3", 3);
347 list << new QPieSlice("slice 3", 3);
356 m_series->append(list);
348 m_series->append(list);
357 verifyCalculatedData(*m_series, &ok);
349 verifyCalculatedData(*m_series, &ok);
358 if (!ok)
350 if (!ok)
359 return;
351 return;
360 QCOMPARE(percentageSpy.count(), 2);
352 QCOMPARE(percentageSpy.count(), 2);
361 QCOMPARE(startAngleSpy.count(), 0);
353 QCOMPARE(startAngleSpy.count(), 0);
362 QCOMPARE(angleSpanSpy.count(), 2);
354 QCOMPARE(angleSpanSpy.count(), 2);
363
355
364 // remove a slice
356 // remove a slice
365 m_series->remove(list.first()); // remove slice 2
357 m_series->remove(list.first()); // remove slice 2
366 verifyCalculatedData(*m_series, &ok);
358 verifyCalculatedData(*m_series, &ok);
367 if (!ok)
359 if (!ok)
368 return;
360 return;
369 QCOMPARE(percentageSpy.count(), 3);
361 QCOMPARE(percentageSpy.count(), 3);
370 QCOMPARE(startAngleSpy.count(), 0);
362 QCOMPARE(startAngleSpy.count(), 0);
371 QCOMPARE(angleSpanSpy.count(), 3);
363 QCOMPARE(angleSpanSpy.count(), 3);
372
364
373 // insert a slice
365 // insert a slice
374 m_series->insert(0, new QPieSlice("Slice 4", 4));
366 m_series->insert(0, new QPieSlice("Slice 4", 4));
375 verifyCalculatedData(*m_series, &ok);
367 verifyCalculatedData(*m_series, &ok);
376 if (!ok)
368 if (!ok)
377 return;
369 return;
378 QCOMPARE(percentageSpy.count(), 4);
370 QCOMPARE(percentageSpy.count(), 4);
379 QCOMPARE(startAngleSpy.count(), 1);
371 QCOMPARE(startAngleSpy.count(), 1);
380 QCOMPARE(angleSpanSpy.count(), 4);
372 QCOMPARE(angleSpanSpy.count(), 4);
381
373
382 // modify pie angles
374 // modify pie angles
383 m_series->setPieStartAngle(-90);
375 m_series->setPieStartAngle(-90);
384 m_series->setPieEndAngle(90);
376 m_series->setPieEndAngle(90);
385 verifyCalculatedData(*m_series, &ok);
377 verifyCalculatedData(*m_series, &ok);
386 if (!ok)
378 if (!ok)
387 return;
379 return;
388 QCOMPARE(percentageSpy.count(), 4);
380 QCOMPARE(percentageSpy.count(), 4);
389 QCOMPARE(startAngleSpy.count(), 3);
381 QCOMPARE(startAngleSpy.count(), 3);
390 QCOMPARE(angleSpanSpy.count(), 6);
382 QCOMPARE(angleSpanSpy.count(), 6);
391
383
392 // clear all
384 // clear all
393 m_series->clear();
385 m_series->clear();
394 verifyCalculatedData(*m_series, &ok);
386 verifyCalculatedData(*m_series, &ok);
395 if (!ok)
387 if (!ok)
396 return;
388 return;
397 QCOMPARE(percentageSpy.count(), 4);
389 QCOMPARE(percentageSpy.count(), 4);
398 QCOMPARE(startAngleSpy.count(), 3);
390 QCOMPARE(startAngleSpy.count(), 3);
399 QCOMPARE(angleSpanSpy.count(), 6);
391 QCOMPARE(angleSpanSpy.count(), 6);
400 }
392 }
401
393
402 void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok)
394 void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok)
403 {
395 {
404 *ok = false;
396 *ok = false;
405
397
406 qreal sum = 0;
398 qreal sum = 0;
407 foreach (const QPieSlice *slice, series.slices())
399 foreach (const QPieSlice *slice, series.slices())
408 sum += slice->value();
400 sum += slice->value();
409 QCOMPARE(series.sum(), sum);
401 QCOMPARE(series.sum(), sum);
410
402
411 qreal startAngle = series.pieStartAngle();
403 qreal startAngle = series.pieStartAngle();
412 qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle();
404 qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle();
413 foreach (const QPieSlice *slice, series.slices()) {
405 foreach (const QPieSlice *slice, series.slices()) {
414 qreal ratio = slice->value() / sum;
406 qreal ratio = slice->value() / sum;
415 qreal sliceSpan = pieAngleSpan * ratio;
407 qreal sliceSpan = pieAngleSpan * ratio;
416 QCOMPARE(slice->startAngle(), startAngle);
408 QCOMPARE(slice->startAngle(), startAngle);
417 QCOMPARE(slice->angleSpan(), sliceSpan);
409 QCOMPARE(slice->angleSpan(), sliceSpan);
418 QCOMPARE(slice->percentage(), ratio);
410 QCOMPARE(slice->percentage(), ratio);
419 startAngle += sliceSpan;
411 startAngle += sliceSpan;
420 }
412 }
421
413
422 if (!series.isEmpty())
414 if (!series.isEmpty())
423 QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle());
415 QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle());
424
416
425 *ok = true;
417 *ok = true;
426 }
418 }
427
419
428
420
429 void tst_qpieseries::clickedSignal()
421 void tst_qpieseries::clickedSignal()
430 {
422 {
431 // add some slices
423 // add some slices
432 QPieSlice *s1 = m_series->append("slice 1", 1);
424 QPieSlice *s1 = m_series->append("slice 1", 1);
433 QPieSlice *s2 = m_series->append("slice 2", 1);
425 QPieSlice *s2 = m_series->append("slice 2", 1);
434 QPieSlice *s3 = m_series->append("slice 3", 1);
426 QPieSlice *s3 = m_series->append("slice 3", 1);
435 QPieSlice *s4 = m_series->append("slice 4", 1);
427 QPieSlice *s4 = m_series->append("slice 4", 1);
436 QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*)));
428 QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*)));
437
429
438 // add series to the chart
430 // add series to the chart
439 m_view->chart()->legend()->setVisible(false);
431 m_view->chart()->legend()->setVisible(false);
440 m_view->resize(200, 200);
432 m_view->resize(200, 200);
441 m_view->chart()->addSeries(m_series);
433 m_view->chart()->addSeries(m_series);
442 m_view->show();
434 m_view->show();
443 QTest::qWaitForWindowShown(m_view);
435 QTest::qWaitForWindowShown(m_view);
444
436
445 // if you devide the chart in four equal tiles these
437 // if you devide the chart in four equal tiles these
446 // are the center points of those tiles
438 // are the center points of those tiles
447 QPoint p1(90.25, 90);
439 QPoint p1(90.25, 90);
448 QPoint p2(150, 90);
440 QPoint p2(150, 90);
449 QPoint p3(90, 150);
441 QPoint p3(90, 150);
450 QPoint p4(150, 150);
442 QPoint p4(150, 150);
451
443
452 QPoint center(120, 120);
444 QPoint center(120, 120);
453
445
454 m_series->setPieSize(1.0);
446 m_series->setPieSize(1.0);
455 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
447 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
456 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
448 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
457 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
449 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
458 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
450 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
459 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
451 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
460 TRY_COMPARE(clickSpy.count(), 5); // all hit
452 TRY_COMPARE(clickSpy.count(), 5); // all hit
461 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4);
453 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4);
462 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1);
454 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1);
463 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
455 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3);
464 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2);
456 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2);
465 clickSpy.clear();
457 clickSpy.clear();
466
458
467 m_series->setPieSize(0.5);
459 m_series->setPieSize(0.5);
468 m_series->setVerticalPosition(0.25);
460 m_series->setVerticalPosition(0.25);
469 m_series->setHorizontalPosition(0.25);
461 m_series->setHorizontalPosition(0.25);
470 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits
462 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits
471 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
463 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
472 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
464 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
473 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
465 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
474 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
466 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
475 TRY_COMPARE(clickSpy.count(), 1);
467 TRY_COMPARE(clickSpy.count(), 1);
476 clickSpy.clear();
468 clickSpy.clear();
477
469
478 m_series->setVerticalPosition(0.25);
470 m_series->setVerticalPosition(0.25);
479 m_series->setHorizontalPosition(0.75);
471 m_series->setHorizontalPosition(0.75);
480 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
472 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
481 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits
473 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits
482 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
474 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
483 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
475 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
484 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
476 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
485 TRY_COMPARE(clickSpy.count(), 1);
477 TRY_COMPARE(clickSpy.count(), 1);
486 clickSpy.clear();
478 clickSpy.clear();
487
479
488 m_series->setVerticalPosition(0.75);
480 m_series->setVerticalPosition(0.75);
489 m_series->setHorizontalPosition(0.25);
481 m_series->setHorizontalPosition(0.25);
490 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
482 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
491 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
483 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
492 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits
484 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits
493 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
485 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
494 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
486 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
495 TRY_COMPARE(clickSpy.count(), 1);
487 TRY_COMPARE(clickSpy.count(), 1);
496 clickSpy.clear();
488 clickSpy.clear();
497
489
498 m_series->setVerticalPosition(0.75);
490 m_series->setVerticalPosition(0.75);
499 m_series->setHorizontalPosition(0.75);
491 m_series->setHorizontalPosition(0.75);
500 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
492 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
501 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
493 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
502 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
494 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
503 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits
495 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits
504 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
496 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
505 TRY_COMPARE(clickSpy.count(), 1);
497 TRY_COMPARE(clickSpy.count(), 1);
506 clickSpy.clear();
498 clickSpy.clear();
507 }
499 }
508
500
509 void tst_qpieseries::hoverSignal()
501 void tst_qpieseries::hoverSignal()
510 {
502 {
511 // add some slices
503 // add some slices
512 m_series->setPieSize(1.0);
504 m_series->setPieSize(1.0);
513 QPieSlice *s1 = m_series->append("slice 1", 1);
505 QPieSlice *s1 = m_series->append("slice 1", 1);
514 m_series->append("slice 2", 2);
506 m_series->append("slice 2", 2);
515 m_series->append("slice 3", 3);
507 m_series->append("slice 3", 3);
516
508
517 // add series to the chart
509 // add series to the chart
518 m_view->chart()->legend()->setVisible(false);
510 m_view->chart()->legend()->setVisible(false);
519 m_view->resize(200, 200);
511 m_view->resize(200, 200);
520 m_view->chart()->addSeries(m_series);
512 m_view->chart()->addSeries(m_series);
521 m_view->show();
513 m_view->show();
522 QTest::qWaitForWindowShown(m_view);
514 QTest::qWaitForWindowShown(m_view);
523
515
524 // first move to right top corner
516 // first move to right top corner
525 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
517 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
526 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
518 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
527
519
528 // move inside the slice
520 // move inside the slice
529 // pie rectangle: QRectF(60,60 121x121)
521 // pie rectangle: QRectF(60,60 121x121)
530 QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool)));
522 QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool)));
531 QTest::mouseMove(m_view->viewport(), QPoint(139, 85));
523 QTest::mouseMove(m_view->viewport(), QPoint(139, 85));
532 TRY_COMPARE(hoverSpy.count(), 1);
524 TRY_COMPARE(hoverSpy.count(), 1);
533 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1);
525 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1);
534 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true);
526 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true);
535
527
536 // move outside the slice
528 // move outside the slice
537 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
529 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
538 TRY_COMPARE(hoverSpy.count(), 2);
530 TRY_COMPARE(hoverSpy.count(), 2);
539 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1);
531 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1);
540 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
532 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
541 }
533 }
542
534
543 void tst_qpieseries::sliceSeries()
535 void tst_qpieseries::sliceSeries()
544 {
536 {
545 QPieSlice *slice = new QPieSlice();
537 QPieSlice *slice = new QPieSlice();
546 QVERIFY(!slice->series());
538 QVERIFY(!slice->series());
547 delete slice;
539 delete slice;
548
540
549 slice = new QPieSlice(m_series);
541 slice = new QPieSlice(m_series);
550 QVERIFY(!slice->series());
542 QVERIFY(!slice->series());
551
543
552 m_series->append(slice);
544 m_series->append(slice);
553 QCOMPARE(slice->series(), m_series);
545 QCOMPARE(slice->series(), m_series);
554
546
555 slice = new QPieSlice();
547 slice = new QPieSlice();
556 m_series->insert(0, slice);
548 m_series->insert(0, slice);
557 QCOMPARE(slice->series(), m_series);
549 QCOMPARE(slice->series(), m_series);
558 }
550 }
559
551
560 QTEST_MAIN(tst_qpieseries)
552 QTEST_MAIN(tst_qpieseries)
561
553
562 #include "tst_qpieseries.moc"
554 #include "tst_qpieseries.moc"
563
555
@@ -1,173 +1,168
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Flow {
24 Flow {
25 id: flow
25 id: flow
26 spacing: 5
26 spacing: 5
27 flow: Flow.TopToBottom
27 flow: Flow.TopToBottom
28 property variant series
28 property variant series
29
29
30 onSeriesChanged: {
30 onSeriesChanged: {
31 if (series && series.name == "pie") {
31 if (series && series.name == "pie") {
32 seriesConnections.target = series;
32 seriesConnections.target = series;
33 sliceConnections.target = series.at(0);
33 sliceConnections.target = series.at(0);
34 } else {
34 } else {
35 seriesConnections.target = null;
35 seriesConnections.target = null;
36 sliceConnections.target = null;
36 sliceConnections.target = null;
37 }
37 }
38 }
38 }
39
39
40 Connections {
40 Connections {
41 id: seriesConnections
41 id: seriesConnections
42 target: null
42 target: null
43 onVisibleChanged: console.log("series.onVisibleChanged: " + series.visible);
43 onVisibleChanged: console.log("series.onVisibleChanged: " + series.visible);
44 onHorizontalPositionChanged:console.log("series.onHorizontalPositionChanged: " + series.horizontalPosition);
45 onVerticalPositionChanged: console.log("series.onVerticalPositionChanged: " + series.verticalPosition);
46 onSizeChanged: console.log("series.onSizeChanged: " + series.size);
47 onStartAngleChanged: console.log("series.onStartAngleChanged: " + series.startAngle);
48 onEndAngleChanged: console.log("series.onEndAngleChanged: " + series.endAngle);
49 onCountChanged: console.log("series.onCountChanged: " + series.count);
44 onCountChanged: console.log("series.onCountChanged: " + series.count);
50 onSumChanged: console.log("series.onSumChanged: " + series.sum);
45 onSumChanged: console.log("series.onSumChanged: " + series.sum);
51 }
46 }
52
47
53 Connections {
48 Connections {
54 id: sliceConnections
49 id: sliceConnections
55 target: null
50 target: null
56 onValueChanged: console.log("slice.onValueChanged: " + series.at(0).value);
51 onValueChanged: console.log("slice.onValueChanged: " + series.at(0).value);
57 onLabelVisibleChanged: console.log("slice.onLabelVisibleChanged: " + series.at(0).labelVisible);
52 onLabelVisibleChanged: console.log("slice.onLabelVisibleChanged: " + series.at(0).labelVisible);
58 onLabelPositionChanged: console.log("slice.onLabelPositionChanged: " + series.at(0).labelPosition);
53 onLabelPositionChanged: console.log("slice.onLabelPositionChanged: " + series.at(0).labelPosition);
59 onExplodedChanged: console.log("slice.onExplodedChanged: " + series.at(0).exploded);
54 onExplodedChanged: console.log("slice.onExplodedChanged: " + series.at(0).exploded);
60 onPenChanged: console.log("slice.onPenChanged: " + series.at(0).pen);
55 onPenChanged: console.log("slice.onPenChanged: " + series.at(0).pen);
61 onBorderColorChanged: console.log("slice.onBorderColorChanged: " + series.at(0).borderColor);
56 onBorderColorChanged: console.log("slice.onBorderColorChanged: " + series.at(0).borderColor);
62 onBorderWidthChanged: console.log("slice.onBorderWidthChanged: " + series.at(0).borderWidth);
57 onBorderWidthChanged: console.log("slice.onBorderWidthChanged: " + series.at(0).borderWidth);
63 onBrushChanged: console.log("slice.onBrushChanged: " + series.at(0).brush);
58 onBrushChanged: console.log("slice.onBrushChanged: " + series.at(0).brush);
64 onColorChanged: console.log("slice.onColorChanged: " + series.at(0).color);
59 onColorChanged: console.log("slice.onColorChanged: " + series.at(0).color);
65 onLabelColorChanged: console.log("slice.onLabelColorChanged: " + series.at(0).labelColor);
60 onLabelColorChanged: console.log("slice.onLabelColorChanged: " + series.at(0).labelColor);
66 onLabelBrushChanged: console.log("slice.onLabelBrushChanged: " + series.at(0).labelBrush);
61 onLabelBrushChanged: console.log("slice.onLabelBrushChanged: " + series.at(0).labelBrush);
67 onLabelFontChanged: console.log("slice.onLabelFontChanged: " + series.at(0).labelFont);
62 onLabelFontChanged: console.log("slice.onLabelFontChanged: " + series.at(0).labelFont);
68 onLabelArmLengthFactorChanged: console.log("slice.onLabelArmLengthFactorChanged: " + series.at(0).labelArmLengthFactor);
63 onLabelArmLengthFactorChanged: console.log("slice.onLabelArmLengthFactorChanged: " + series.at(0).labelArmLengthFactor);
69 onExplodeDistanceFactorChanged: console.log("slice.onExplodeDistanceFactorChanged: " + series.at(0).explodeDistanceFactor);
64 onExplodeDistanceFactorChanged: console.log("slice.onExplodeDistanceFactorChanged: " + series.at(0).explodeDistanceFactor);
70 onPercentageChanged: console.log("slice.onPercentageChanged: " + series.at(0).percentage);
65 onPercentageChanged: console.log("slice.onPercentageChanged: " + series.at(0).percentage);
71 onStartAngleChanged: console.log("slice.onStartAngleChanged: " + series.at(0).startAngle);
66 onStartAngleChanged: console.log("slice.onStartAngleChanged: " + series.at(0).startAngle);
72 onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + series.at(0).angleSpan);
67 onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + series.at(0).angleSpan);
73 onClicked: console.log("slice.onClicked");
68 onClicked: console.log("slice.onClicked");
74 onHovered: console.log("slice.onHovered: " + state);
69 onHovered: console.log("slice.onHovered: " + state);
75 }
70 }
76
71
77 Button {
72 Button {
78 text: "visible"
73 text: "visible"
79 onClicked: series.visible = !series.visible;
74 onClicked: series.visible = !series.visible;
80 }
75 }
81 Button {
76 Button {
82 text: "series hpos +"
77 text: "series hpos +"
83 onClicked: series.horizontalPosition += 0.1;
78 onClicked: series.horizontalPosition += 0.1;
84 }
79 }
85 Button {
80 Button {
86 text: "series hpos -"
81 text: "series hpos -"
87 onClicked: series.horizontalPosition -= 0.1;
82 onClicked: series.horizontalPosition -= 0.1;
88 }
83 }
89 Button {
84 Button {
90 text: "series vpos +"
85 text: "series vpos +"
91 onClicked: series.verticalPosition += 0.1;
86 onClicked: series.verticalPosition += 0.1;
92 }
87 }
93 Button {
88 Button {
94 text: "series vpos -"
89 text: "series vpos -"
95 onClicked: series.verticalPosition -= 0.1;
90 onClicked: series.verticalPosition -= 0.1;
96 }
91 }
97 Button {
92 Button {
98 text: "series size +"
93 text: "series size +"
99 onClicked: series.size += 0.1;
94 onClicked: series.size += 0.1;
100 }
95 }
101 Button {
96 Button {
102 text: "series size -"
97 text: "series size -"
103 onClicked: series.size -= 0.1;
98 onClicked: series.size -= 0.1;
104 }
99 }
105 Button {
100 Button {
106 text: "series start angle +"
101 text: "series start angle +"
107 onClicked: series.startAngle += 1.1;
102 onClicked: series.startAngle += 1.1;
108 }
103 }
109 Button {
104 Button {
110 text: "series start angle -"
105 text: "series start angle -"
111 onClicked: series.startAngle -= 1.1;
106 onClicked: series.startAngle -= 1.1;
112 }
107 }
113 Button {
108 Button {
114 text: "series end angle +"
109 text: "series end angle +"
115 onClicked: series.endAngle += 1.1;
110 onClicked: series.endAngle += 1.1;
116 }
111 }
117 Button {
112 Button {
118 text: "series end angle -"
113 text: "series end angle -"
119 onClicked: series.endAngle -= 1.1;
114 onClicked: series.endAngle -= 1.1;
120 }
115 }
121 Button {
116 Button {
122 text: "slice color"
117 text: "slice color"
123 onClicked: series.at(0).color = main.nextColor();
118 onClicked: series.at(0).color = main.nextColor();
124 }
119 }
125 Button {
120 Button {
126 text: "slice border color"
121 text: "slice border color"
127 onClicked: series.at(0).borderColor = main.nextColor();
122 onClicked: series.at(0).borderColor = main.nextColor();
128 }
123 }
129 Button {
124 Button {
130 text: "slice border width +"
125 text: "slice border width +"
131 onClicked: series.at(0).borderWidth++;
126 onClicked: series.at(0).borderWidth++;
132 }
127 }
133 Button {
128 Button {
134 text: "slice border width -"
129 text: "slice border width -"
135 onClicked: series.at(0).borderWidth--;
130 onClicked: series.at(0).borderWidth--;
136 }
131 }
137 Button {
132 Button {
138 text: "slice label visible"
133 text: "slice label visible"
139 onClicked: series.at(0).labelVisible = !series.at(0).labelVisible;
134 onClicked: series.at(0).labelVisible = !series.at(0).labelVisible;
140 }
135 }
141 Button {
136 Button {
142 text: "slice label position inside"
137 text: "slice label position inside"
143 onClicked: series.at(0).labelPosition = PieSlice.LabelInside;
138 onClicked: series.at(0).labelPosition = PieSlice.LabelInside;
144 }
139 }
145 Button {
140 Button {
146 text: "slice label position outside"
141 text: "slice label position outside"
147 onClicked: series.at(0).labelPosition = PieSlice.LabelOutside;
142 onClicked: series.at(0).labelPosition = PieSlice.LabelOutside;
148 }
143 }
149 Button {
144 Button {
150 text: "slice label arm len +"
145 text: "slice label arm len +"
151 onClicked: series.at(0).labelArmLengthFactor += 0.1;
146 onClicked: series.at(0).labelArmLengthFactor += 0.1;
152 }
147 }
153 Button {
148 Button {
154 text: "slice label arm len -"
149 text: "slice label arm len -"
155 onClicked: series.at(0).labelArmLengthFactor -= 0.1;
150 onClicked: series.at(0).labelArmLengthFactor -= 0.1;
156 }
151 }
157 Button {
152 Button {
158 text: "slice label color"
153 text: "slice label color"
159 onClicked: series.at(0).labelColor = main.nextColor();
154 onClicked: series.at(0).labelColor = main.nextColor();
160 }
155 }
161 Button {
156 Button {
162 text: "slice exploded"
157 text: "slice exploded"
163 onClicked: series.at(0).exploded = !series.at(0).exploded;
158 onClicked: series.at(0).exploded = !series.at(0).exploded;
164 }
159 }
165 Button {
160 Button {
166 text: "slice explode dist +"
161 text: "slice explode dist +"
167 onClicked: series.at(0).explodeDistanceFactor += 0.1;
162 onClicked: series.at(0).explodeDistanceFactor += 0.1;
168 }
163 }
169 Button {
164 Button {
170 text: "slice explode dist -"
165 text: "slice explode dist -"
171 onClicked: series.at(0).explodeDistanceFactor -= 0.1;
166 onClicked: series.at(0).explodeDistanceFactor -= 0.1;
172 }
167 }
173 }
168 }
General Comments 0
You need to be logged in to leave comments. Login now