|
@@
-1,528
+1,531
|
|
1
|
#include "qpieseries.h"
|
|
1
|
#include "qpieseries.h"
|
|
2
|
#include "qpieslice.h"
|
|
2
|
#include "qpieslice.h"
|
|
3
|
#include "piepresenter.h"
|
|
3
|
#include "piepresenter.h"
|
|
4
|
#include "pieslice.h"
|
|
4
|
#include "pieslice.h"
|
|
5
|
#include <QFontMetrics>
|
|
5
|
#include <QFontMetrics>
|
|
6
|
#include <QDebug>
|
|
6
|
#include <QDebug>
|
|
7
|
|
|
7
|
|
|
8
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
8
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
9
|
|
|
9
|
|
|
10
|
|
|
10
|
|
|
11
|
/*!
|
|
11
|
/*!
|
|
12
|
\class QPieSeries::ChangeSet
|
|
12
|
\class QPieSeries::ChangeSet
|
|
13
|
\brief Defines the changes in the series.
|
|
13
|
\brief Defines the changes in the series.
|
|
14
|
|
|
14
|
|
|
15
|
Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
|
|
15
|
Contains the changes that have occurred in the series. Lists of added, changed and removed slices.
|
|
16
|
|
|
16
|
|
|
17
|
\sa QPieSeries::changed()
|
|
17
|
\sa QPieSeries::changed()
|
|
18
|
*/
|
|
18
|
*/
|
|
19
|
|
|
19
|
|
|
20
|
/*!
|
|
20
|
/*!
|
|
21
|
\internal
|
|
21
|
\internal
|
|
22
|
*/
|
|
22
|
*/
|
|
23
|
void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
|
|
23
|
void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
|
|
24
|
{
|
|
24
|
{
|
|
25
|
if (!m_added.contains(slice))
|
|
25
|
if (!m_added.contains(slice))
|
|
26
|
m_added << slice;
|
|
26
|
m_added << slice;
|
|
27
|
}
|
|
27
|
}
|
|
28
|
|
|
28
|
|
|
29
|
/*!
|
|
29
|
/*!
|
|
30
|
\internal
|
|
30
|
\internal
|
|
31
|
*/
|
|
31
|
*/
|
|
32
|
void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
|
|
32
|
void QPieSeries::ChangeSet::appendAdded(QList<QPieSlice*> slices)
|
|
33
|
{
|
|
33
|
{
|
|
34
|
foreach (QPieSlice* s, slices)
|
|
34
|
foreach (QPieSlice* s, slices)
|
|
35
|
appendAdded(s);
|
|
35
|
appendAdded(s);
|
|
36
|
}
|
|
36
|
}
|
|
37
|
|
|
37
|
|
|
38
|
/*!
|
|
38
|
/*!
|
|
39
|
\internal
|
|
39
|
\internal
|
|
40
|
*/
|
|
40
|
*/
|
|
41
|
void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
|
|
41
|
void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice)
|
|
42
|
{
|
|
42
|
{
|
|
43
|
if (!m_changed.contains(slice))
|
|
43
|
if (!m_changed.contains(slice))
|
|
44
|
m_changed << slice;
|
|
44
|
m_changed << slice;
|
|
45
|
}
|
|
45
|
}
|
|
46
|
|
|
46
|
|
|
47
|
/*!
|
|
47
|
/*!
|
|
48
|
\internal
|
|
48
|
\internal
|
|
49
|
*/
|
|
49
|
*/
|
|
50
|
void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
|
|
50
|
void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
|
|
51
|
{
|
|
51
|
{
|
|
52
|
if (!m_removed.contains(slice))
|
|
52
|
if (!m_removed.contains(slice))
|
|
53
|
m_removed << slice;
|
|
53
|
m_removed << slice;
|
|
54
|
}
|
|
54
|
}
|
|
55
|
|
|
55
|
|
|
56
|
/*!
|
|
56
|
/*!
|
|
57
|
Returns a list of slices that have been added to the series.
|
|
57
|
Returns a list of slices that have been added to the series.
|
|
58
|
\sa QPieSeries::changed()
|
|
58
|
\sa QPieSeries::changed()
|
|
59
|
*/
|
|
59
|
*/
|
|
60
|
QList<QPieSlice*> QPieSeries::ChangeSet::added() const
|
|
60
|
QList<QPieSlice*> QPieSeries::ChangeSet::added() const
|
|
61
|
{
|
|
61
|
{
|
|
62
|
return m_added;
|
|
62
|
return m_added;
|
|
63
|
}
|
|
63
|
}
|
|
64
|
|
|
64
|
|
|
65
|
/*!
|
|
65
|
/*!
|
|
66
|
Returns a list of slices that have been changed in the series.
|
|
66
|
Returns a list of slices that have been changed in the series.
|
|
67
|
\sa QPieSeries::changed()
|
|
67
|
\sa QPieSeries::changed()
|
|
68
|
*/
|
|
68
|
*/
|
|
69
|
QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
|
|
69
|
QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
|
|
70
|
{
|
|
70
|
{
|
|
71
|
return m_changed;
|
|
71
|
return m_changed;
|
|
72
|
}
|
|
72
|
}
|
|
73
|
|
|
73
|
|
|
74
|
/*!
|
|
74
|
/*!
|
|
75
|
Returns a list of slices that have been removed from the series.
|
|
75
|
Returns a list of slices that have been removed from the series.
|
|
76
|
\sa QPieSeries::changed()
|
|
76
|
\sa QPieSeries::changed()
|
|
77
|
*/
|
|
77
|
*/
|
|
78
|
QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
|
|
78
|
QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
|
|
79
|
{
|
|
79
|
{
|
|
80
|
return m_removed;
|
|
80
|
return m_removed;
|
|
81
|
}
|
|
81
|
}
|
|
82
|
|
|
82
|
|
|
83
|
|
|
83
|
|
|
84
|
/*!
|
|
84
|
/*!
|
|
85
|
Returns true if there are no added/changed or removed slices in the change set.
|
|
85
|
Returns true if there are no added/changed or removed slices in the change set.
|
|
86
|
*/
|
|
86
|
*/
|
|
87
|
bool QPieSeries::ChangeSet::isEmpty() const
|
|
87
|
bool QPieSeries::ChangeSet::isEmpty() const
|
|
88
|
{
|
|
88
|
{
|
|
89
|
if (m_added.count() || m_changed.count() || m_removed.count())
|
|
89
|
if (m_added.count() || m_changed.count() || m_removed.count())
|
|
90
|
return false;
|
|
90
|
return false;
|
|
91
|
return true;
|
|
91
|
return true;
|
|
92
|
}
|
|
92
|
}
|
|
93
|
|
|
93
|
|
|
94
|
/*!
|
|
94
|
/*!
|
|
95
|
\enum QPieSeries::PiePosition
|
|
95
|
\enum QPieSeries::PiePosition
|
|
96
|
|
|
96
|
|
|
97
|
This enum describes pie position within its bounding rectangle
|
|
97
|
This enum describes pie position within its bounding rectangle
|
|
98
|
|
|
98
|
|
|
99
|
\value PiePositionMaximized
|
|
99
|
\value PiePositionMaximized
|
|
100
|
\value PiePositionTopLeft
|
|
100
|
\value PiePositionTopLeft
|
|
101
|
\value PiePositionTopRight
|
|
101
|
\value PiePositionTopRight
|
|
102
|
\value PiePositionBottomLeft
|
|
102
|
\value PiePositionBottomLeft
|
|
103
|
\value PiePositionBottomRight
|
|
103
|
\value PiePositionBottomRight
|
|
104
|
*/
|
|
104
|
*/
|
|
105
|
|
|
105
|
|
|
106
|
/*!
|
|
106
|
/*!
|
|
107
|
\class QPieSeries
|
|
107
|
\class QPieSeries
|
|
108
|
\brief Pie series API for QtCommercial Charts
|
|
108
|
\brief Pie series API for QtCommercial Charts
|
|
109
|
|
|
109
|
|
|
110
|
The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
|
|
110
|
The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
|
|
111
|
The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
|
|
111
|
The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
|
|
112
|
The actual slice size (span) is determined by that relative value.
|
|
112
|
The actual slice size (span) is determined by that relative value.
|
|
113
|
|
|
113
|
|
|
114
|
By default the pie is defined as full but it can be a partial pie.
|
|
114
|
By default the pie is defined as full but it can be a partial pie.
|
|
115
|
This can be done by setting a starting angle and angle span to the series.
|
|
115
|
This can be done by setting a starting angle and angle span to the series.
|
|
|
|
|
116
|
|
|
|
|
|
117
|
Example on how to create a chart with pie series:
|
|
|
|
|
118
|
\snippet ../example/piechart/main.cpp 1
|
|
116
|
*/
|
|
119
|
*/
|
|
117
|
|
|
120
|
|
|
118
|
/*!
|
|
121
|
/*!
|
|
119
|
Constructs a series object which is a child of \a parent.
|
|
122
|
Constructs a series object which is a child of \a parent.
|
|
120
|
*/
|
|
123
|
*/
|
|
121
|
QPieSeries::QPieSeries(QObject *parent) :
|
|
124
|
QPieSeries::QPieSeries(QObject *parent) :
|
|
122
|
QChartSeries(parent),
|
|
125
|
QChartSeries(parent),
|
|
123
|
m_sizeFactor(1.0),
|
|
126
|
m_sizeFactor(1.0),
|
|
124
|
m_position(PiePositionMaximized),
|
|
127
|
m_position(PiePositionMaximized),
|
|
125
|
m_pieStartAngle(0),
|
|
128
|
m_pieStartAngle(0),
|
|
126
|
m_pieAngleSpan(360)
|
|
129
|
m_pieAngleSpan(360)
|
|
127
|
{
|
|
130
|
{
|
|
128
|
|
|
131
|
|
|
129
|
}
|
|
132
|
}
|
|
130
|
|
|
133
|
|
|
131
|
/*!
|
|
134
|
/*!
|
|
132
|
Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
|
|
135
|
Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
|
|
133
|
*/
|
|
136
|
*/
|
|
134
|
QPieSeries::~QPieSeries()
|
|
137
|
QPieSeries::~QPieSeries()
|
|
135
|
{
|
|
138
|
{
|
|
136
|
|
|
139
|
|
|
137
|
}
|
|
140
|
}
|
|
138
|
|
|
141
|
|
|
139
|
/*!
|
|
142
|
/*!
|
|
140
|
Returns QChartSeries::SeriesTypePie.
|
|
143
|
Returns QChartSeries::SeriesTypePie.
|
|
141
|
*/
|
|
144
|
*/
|
|
142
|
QChartSeries::QChartSeriesType QPieSeries::type() const
|
|
145
|
QChartSeries::QChartSeriesType QPieSeries::type() const
|
|
143
|
{
|
|
146
|
{
|
|
144
|
return QChartSeries::SeriesTypePie;
|
|
147
|
return QChartSeries::SeriesTypePie;
|
|
145
|
}
|
|
148
|
}
|
|
146
|
|
|
149
|
|
|
147
|
/*!
|
|
150
|
/*!
|
|
148
|
Sets an array of values to the series.
|
|
151
|
Sets an array of values to the series.
|
|
149
|
TO BE REMOVED
|
|
152
|
TO BE REMOVED
|
|
150
|
*/
|
|
153
|
*/
|
|
151
|
bool QPieSeries::setData(QList<qreal> data)
|
|
154
|
bool QPieSeries::setData(QList<qreal> data)
|
|
152
|
{
|
|
155
|
{
|
|
153
|
// TODO: remove this function
|
|
156
|
// TODO: remove this function
|
|
154
|
QList<QPieSlice*> slices;
|
|
157
|
QList<QPieSlice*> slices;
|
|
155
|
foreach (qreal value, data)
|
|
158
|
foreach (qreal value, data)
|
|
156
|
slices << new QPieSlice(value, QString::number(value));
|
|
159
|
slices << new QPieSlice(value, QString::number(value));
|
|
157
|
set(slices);
|
|
160
|
set(slices);
|
|
158
|
return true;
|
|
161
|
return true;
|
|
159
|
}
|
|
162
|
}
|
|
160
|
|
|
163
|
|
|
161
|
/*!
|
|
164
|
/*!
|
|
162
|
Sets an array of \a slices to the series.
|
|
165
|
Sets an array of \a slices to the series.
|
|
163
|
Slice ownership is passed to the series.
|
|
166
|
Slice ownership is passed to the series.
|
|
164
|
*/
|
|
167
|
*/
|
|
165
|
void QPieSeries::set(QList<QPieSlice*> slices)
|
|
168
|
void QPieSeries::set(QList<QPieSlice*> slices)
|
|
166
|
{
|
|
169
|
{
|
|
167
|
clear();
|
|
170
|
clear();
|
|
168
|
add(slices);
|
|
171
|
add(slices);
|
|
169
|
}
|
|
172
|
}
|
|
170
|
|
|
173
|
|
|
171
|
/*!
|
|
174
|
/*!
|
|
172
|
Adds an array of slices to the series.
|
|
175
|
Adds an array of slices to the series.
|
|
173
|
Slice ownership is passed to the series.
|
|
176
|
Slice ownership is passed to the series.
|
|
174
|
*/
|
|
177
|
*/
|
|
175
|
void QPieSeries::add(QList<QPieSlice*> slices)
|
|
178
|
void QPieSeries::add(QList<QPieSlice*> slices)
|
|
176
|
{
|
|
179
|
{
|
|
177
|
ChangeSet changeSet;
|
|
180
|
ChangeSet changeSet;
|
|
178
|
foreach (QPieSlice* s, slices) {
|
|
181
|
foreach (QPieSlice* s, slices) {
|
|
179
|
s->setParent(this);
|
|
182
|
s->setParent(this);
|
|
180
|
m_slices << s;
|
|
183
|
m_slices << s;
|
|
181
|
changeSet.appendAdded(s);
|
|
184
|
changeSet.appendAdded(s);
|
|
182
|
}
|
|
185
|
}
|
|
183
|
|
|
186
|
|
|
184
|
updateDerivativeData();
|
|
187
|
updateDerivativeData();
|
|
185
|
|
|
188
|
|
|
186
|
foreach (QPieSlice* s, slices) {
|
|
189
|
foreach (QPieSlice* s, slices) {
|
|
187
|
connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
|
|
190
|
connect(s, SIGNAL(changed()), this, SLOT(sliceChanged()));
|
|
188
|
connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
|
|
191
|
connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked()));
|
|
189
|
connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
|
|
192
|
connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter()));
|
|
190
|
connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
|
|
193
|
connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave()));
|
|
191
|
}
|
|
194
|
}
|
|
192
|
|
|
195
|
|
|
193
|
emit changed(changeSet);
|
|
196
|
emit changed(changeSet);
|
|
194
|
}
|
|
197
|
}
|
|
195
|
|
|
198
|
|
|
196
|
/*!
|
|
199
|
/*!
|
|
197
|
Adds a single \a slice to the series.
|
|
200
|
Adds a single \a slice to the series.
|
|
198
|
Slice ownership is passed to the series.
|
|
201
|
Slice ownership is passed to the series.
|
|
199
|
*/
|
|
202
|
*/
|
|
200
|
void QPieSeries::add(QPieSlice* slice)
|
|
203
|
void QPieSeries::add(QPieSlice* slice)
|
|
201
|
{
|
|
204
|
{
|
|
202
|
add(QList<QPieSlice*>() << slice);
|
|
205
|
add(QList<QPieSlice*>() << slice);
|
|
203
|
}
|
|
206
|
}
|
|
204
|
|
|
207
|
|
|
205
|
|
|
208
|
|
|
206
|
/*!
|
|
209
|
/*!
|
|
207
|
Adds a single slice to the series with give \a value and \a name.
|
|
210
|
Adds a single slice to the series with give \a value and \a name.
|
|
208
|
Slice ownership is passed to the series.
|
|
211
|
Slice ownership is passed to the series.
|
|
209
|
*/
|
|
212
|
*/
|
|
210
|
QPieSlice* QPieSeries::add(qreal value, QString name)
|
|
213
|
QPieSlice* QPieSeries::add(qreal value, QString name)
|
|
211
|
{
|
|
214
|
{
|
|
212
|
QPieSlice* slice = new QPieSlice(value, name);
|
|
215
|
QPieSlice* slice = new QPieSlice(value, name);
|
|
213
|
add(slice);
|
|
216
|
add(slice);
|
|
214
|
return slice;
|
|
217
|
return slice;
|
|
215
|
}
|
|
218
|
}
|
|
216
|
|
|
219
|
|
|
217
|
/*!
|
|
220
|
/*!
|
|
218
|
Removes a single \a slice from the series and deletes the slice.
|
|
221
|
Removes a single \a slice from the series and deletes the slice.
|
|
219
|
|
|
222
|
|
|
220
|
Do not reference this pointer after this call.
|
|
223
|
Do not reference this pointer after this call.
|
|
221
|
*/
|
|
224
|
*/
|
|
222
|
void QPieSeries::remove(QPieSlice* slice)
|
|
225
|
void QPieSeries::remove(QPieSlice* slice)
|
|
223
|
{
|
|
226
|
{
|
|
224
|
if (!m_slices.removeOne(slice)) {
|
|
227
|
if (!m_slices.removeOne(slice)) {
|
|
225
|
Q_ASSERT(0); // TODO: how should this be reported?
|
|
228
|
Q_ASSERT(0); // TODO: how should this be reported?
|
|
226
|
return;
|
|
229
|
return;
|
|
227
|
}
|
|
230
|
}
|
|
228
|
|
|
231
|
|
|
229
|
ChangeSet changeSet;
|
|
232
|
ChangeSet changeSet;
|
|
230
|
changeSet.appendRemoved(slice);
|
|
233
|
changeSet.appendRemoved(slice);
|
|
231
|
emit changed(changeSet);
|
|
234
|
emit changed(changeSet);
|
|
232
|
|
|
235
|
|
|
233
|
delete slice;
|
|
236
|
delete slice;
|
|
234
|
slice = NULL;
|
|
237
|
slice = NULL;
|
|
235
|
|
|
238
|
|
|
236
|
updateDerivativeData();
|
|
239
|
updateDerivativeData();
|
|
237
|
}
|
|
240
|
}
|
|
238
|
|
|
241
|
|
|
239
|
/*!
|
|
242
|
/*!
|
|
240
|
Clears all slices from the series.
|
|
243
|
Clears all slices from the series.
|
|
241
|
*/
|
|
244
|
*/
|
|
242
|
void QPieSeries::clear()
|
|
245
|
void QPieSeries::clear()
|
|
243
|
{
|
|
246
|
{
|
|
244
|
if (m_slices.count() == 0)
|
|
247
|
if (m_slices.count() == 0)
|
|
245
|
return;
|
|
248
|
return;
|
|
246
|
|
|
249
|
|
|
247
|
ChangeSet changeSet;
|
|
250
|
ChangeSet changeSet;
|
|
248
|
foreach (QPieSlice* s, m_slices) {
|
|
251
|
foreach (QPieSlice* s, m_slices) {
|
|
249
|
changeSet.appendRemoved(s);
|
|
252
|
changeSet.appendRemoved(s);
|
|
250
|
m_slices.removeOne(s);
|
|
253
|
m_slices.removeOne(s);
|
|
251
|
delete s;
|
|
254
|
delete s;
|
|
252
|
}
|
|
255
|
}
|
|
253
|
emit changed(changeSet);
|
|
256
|
emit changed(changeSet);
|
|
254
|
updateDerivativeData();
|
|
257
|
updateDerivativeData();
|
|
255
|
}
|
|
258
|
}
|
|
256
|
|
|
259
|
|
|
257
|
/*!
|
|
260
|
/*!
|
|
258
|
Counts the number of the slices in this series.
|
|
261
|
Counts the number of the slices in this series.
|
|
259
|
*/
|
|
262
|
*/
|
|
260
|
int QPieSeries::count() const
|
|
263
|
int QPieSeries::count() const
|
|
261
|
{
|
|
264
|
{
|
|
262
|
return m_slices.count();
|
|
265
|
return m_slices.count();
|
|
263
|
}
|
|
266
|
}
|
|
264
|
|
|
267
|
|
|
265
|
/*!
|
|
268
|
/*!
|
|
266
|
Returns a list of slices that belong to this series.
|
|
269
|
Returns a list of slices that belong to this series.
|
|
267
|
*/
|
|
270
|
*/
|
|
268
|
QList<QPieSlice*> QPieSeries::slices() const
|
|
271
|
QList<QPieSlice*> QPieSeries::slices() const
|
|
269
|
{
|
|
272
|
{
|
|
270
|
return m_slices;
|
|
273
|
return m_slices;
|
|
271
|
}
|
|
274
|
}
|
|
272
|
|
|
275
|
|
|
273
|
/*!
|
|
276
|
/*!
|
|
274
|
Sets the size \a factor of the pie. 1.0 is the default value.
|
|
277
|
Sets the size \a factor of the pie. 1.0 is the default value.
|
|
275
|
Note that the pie will not grow beyond its absolute maximum size.
|
|
278
|
Note that the pie will not grow beyond its absolute maximum size.
|
|
276
|
In practice its use is to make the pie appear smaller.
|
|
279
|
In practice its use is to make the pie appear smaller.
|
|
277
|
\sa sizeFactor()
|
|
280
|
\sa sizeFactor()
|
|
278
|
*/
|
|
281
|
*/
|
|
279
|
void QPieSeries::setSizeFactor(qreal factor)
|
|
282
|
void QPieSeries::setSizeFactor(qreal factor)
|
|
280
|
{
|
|
283
|
{
|
|
281
|
if (factor < 0.0)
|
|
284
|
if (factor < 0.0)
|
|
282
|
return;
|
|
285
|
return;
|
|
283
|
|
|
286
|
|
|
284
|
if (m_sizeFactor != factor) {
|
|
287
|
if (m_sizeFactor != factor) {
|
|
285
|
m_sizeFactor = factor;
|
|
288
|
m_sizeFactor = factor;
|
|
286
|
emit sizeFactorChanged();
|
|
289
|
emit sizeFactorChanged();
|
|
287
|
}
|
|
290
|
}
|
|
288
|
}
|
|
291
|
}
|
|
289
|
|
|
292
|
|
|
290
|
/*!
|
|
293
|
/*!
|
|
291
|
Gets the size factor of the pie.
|
|
294
|
Gets the size factor of the pie.
|
|
292
|
\sa setSizeFactor()
|
|
295
|
\sa setSizeFactor()
|
|
293
|
*/
|
|
296
|
*/
|
|
294
|
qreal QPieSeries::sizeFactor() const
|
|
297
|
qreal QPieSeries::sizeFactor() const
|
|
295
|
{
|
|
298
|
{
|
|
296
|
return m_sizeFactor;
|
|
299
|
return m_sizeFactor;
|
|
297
|
}
|
|
300
|
}
|
|
298
|
|
|
301
|
|
|
299
|
/*!
|
|
302
|
/*!
|
|
300
|
Sets the \a position of the pie within its bounding rectangle.
|
|
303
|
Sets the \a position of the pie within its bounding rectangle.
|
|
301
|
\sa PiePosition, position()
|
|
304
|
\sa PiePosition, position()
|
|
302
|
*/
|
|
305
|
*/
|
|
303
|
void QPieSeries::setPosition(PiePosition position)
|
|
306
|
void QPieSeries::setPosition(PiePosition position)
|
|
304
|
{
|
|
307
|
{
|
|
305
|
if (m_position != position) {
|
|
308
|
if (m_position != position) {
|
|
306
|
m_position = position;
|
|
309
|
m_position = position;
|
|
307
|
emit positionChanged();
|
|
310
|
emit positionChanged();
|
|
308
|
}
|
|
311
|
}
|
|
309
|
}
|
|
312
|
}
|
|
310
|
|
|
313
|
|
|
311
|
/*!
|
|
314
|
/*!
|
|
312
|
Gets the position of the pie within its bounding rectangle.
|
|
315
|
Gets the position of the pie within its bounding rectangle.
|
|
313
|
\sa PiePosition, setPosition()
|
|
316
|
\sa PiePosition, setPosition()
|
|
314
|
*/
|
|
317
|
*/
|
|
315
|
QPieSeries::PiePosition QPieSeries::position() const
|
|
318
|
QPieSeries::PiePosition QPieSeries::position() const
|
|
316
|
{
|
|
319
|
{
|
|
317
|
return m_position;
|
|
320
|
return m_position;
|
|
318
|
}
|
|
321
|
}
|
|
319
|
|
|
322
|
|
|
320
|
|
|
323
|
|
|
321
|
/*!
|
|
324
|
/*!
|
|
322
|
Sets the \a startAngle and \a angleSpan of this series.
|
|
325
|
Sets the \a startAngle and \a angleSpan of this series.
|
|
323
|
|
|
326
|
|
|
324
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
327
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
325
|
*/
|
|
328
|
*/
|
|
326
|
void QPieSeries::setSpan(qreal startAngle, qreal angleSpan)
|
|
329
|
void QPieSeries::setSpan(qreal startAngle, qreal angleSpan)
|
|
327
|
{
|
|
330
|
{
|
|
328
|
if (startAngle >= 0 && startAngle < 360 &&
|
|
331
|
if (startAngle >= 0 && startAngle < 360 &&
|
|
329
|
angleSpan > 0 && angleSpan <= 360) {
|
|
332
|
angleSpan > 0 && angleSpan <= 360) {
|
|
330
|
m_pieStartAngle = startAngle;
|
|
333
|
m_pieStartAngle = startAngle;
|
|
331
|
m_pieAngleSpan = angleSpan;
|
|
334
|
m_pieAngleSpan = angleSpan;
|
|
332
|
updateDerivativeData();
|
|
335
|
updateDerivativeData();
|
|
333
|
}
|
|
336
|
}
|
|
334
|
}
|
|
337
|
}
|
|
335
|
|
|
338
|
|
|
336
|
/*!
|
|
339
|
/*!
|
|
337
|
Sets the all the slice labels \a visible or invisible.
|
|
340
|
Sets the all the slice labels \a visible or invisible.
|
|
338
|
|
|
341
|
|
|
339
|
\sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
|
|
342
|
\sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
|
|
340
|
*/
|
|
343
|
*/
|
|
341
|
void QPieSeries::setLabelsVisible(bool visible)
|
|
344
|
void QPieSeries::setLabelsVisible(bool visible)
|
|
342
|
{
|
|
345
|
{
|
|
343
|
foreach (QPieSlice* s, m_slices)
|
|
346
|
foreach (QPieSlice* s, m_slices)
|
|
344
|
s->setLabelVisible(visible);
|
|
347
|
s->setLabelVisible(visible);
|
|
345
|
}
|
|
348
|
}
|
|
346
|
|
|
349
|
|
|
347
|
/*!
|
|
350
|
/*!
|
|
348
|
Convenience method for exploding a slice when user clicks the pie.
|
|
351
|
Convenience method for exploding a slice when user clicks the pie.
|
|
349
|
|
|
352
|
|
|
350
|
\sa QPieSlice::isExploded(), QPieSlice::setExploded()
|
|
353
|
\sa QPieSlice::isExploded(), QPieSlice::setExploded()
|
|
351
|
*/
|
|
354
|
*/
|
|
352
|
void QPieSeries::enableClickExplodes(bool enable)
|
|
355
|
void QPieSeries::enableClickExplodes(bool enable)
|
|
353
|
{
|
|
356
|
{
|
|
354
|
if (enable)
|
|
357
|
if (enable)
|
|
355
|
connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*)));
|
|
358
|
connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*)));
|
|
356
|
else
|
|
359
|
else
|
|
357
|
disconnect(this, SLOT(toggleExploded(QPieSlice*)));
|
|
360
|
disconnect(this, SLOT(toggleExploded(QPieSlice*)));
|
|
358
|
}
|
|
361
|
}
|
|
359
|
|
|
362
|
|
|
360
|
/*!
|
|
363
|
/*!
|
|
361
|
Convenience method for highlighting a slice when user hovers over the slice.
|
|
364
|
Convenience method for highlighting a slice when user hovers over the slice.
|
|
362
|
It changes the slice color to be lighter and shows the label of the slice.
|
|
365
|
It changes the slice color to be lighter and shows the label of the slice.
|
|
363
|
|
|
366
|
|
|
364
|
\sa QPieSlice::isExploded(), QPieSlice::setExploded()
|
|
367
|
\sa QPieSlice::isExploded(), QPieSlice::setExploded()
|
|
365
|
*/
|
|
368
|
*/
|
|
366
|
|
|
369
|
|
|
367
|
void QPieSeries::enableHoverHighlight(bool enable)
|
|
370
|
void QPieSeries::enableHoverHighlight(bool enable)
|
|
368
|
{
|
|
371
|
{
|
|
369
|
if (enable) {
|
|
372
|
if (enable) {
|
|
370
|
connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*)));
|
|
373
|
connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*)));
|
|
371
|
connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*)));
|
|
374
|
connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*)));
|
|
372
|
} else {
|
|
375
|
} else {
|
|
373
|
disconnect(this, SLOT(hoverEnter(QPieSlice*)));
|
|
376
|
disconnect(this, SLOT(hoverEnter(QPieSlice*)));
|
|
374
|
disconnect(this, SLOT(hoverLeave(QPieSlice*)));
|
|
377
|
disconnect(this, SLOT(hoverLeave(QPieSlice*)));
|
|
375
|
}
|
|
378
|
}
|
|
376
|
}
|
|
379
|
}
|
|
377
|
|
|
380
|
|
|
378
|
/*!
|
|
381
|
/*!
|
|
379
|
\fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
|
|
382
|
\fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
|
|
380
|
|
|
383
|
|
|
381
|
This signal emitted when something has changed in the series.
|
|
384
|
This signal emitted when something has changed in the series.
|
|
382
|
The \a changeSet contains the details of which slices have been added, changed or removed.
|
|
385
|
The \a changeSet contains the details of which slices have been added, changed or removed.
|
|
383
|
|
|
386
|
|
|
384
|
\sa QPieSeries::ChangeSet, QPieSlice::changed()
|
|
387
|
\sa QPieSeries::ChangeSet, QPieSlice::changed()
|
|
385
|
*/
|
|
388
|
*/
|
|
386
|
|
|
389
|
|
|
387
|
/*!
|
|
390
|
/*!
|
|
388
|
\fn void QPieSeries::clicked(QPieSlice* slice)
|
|
391
|
\fn void QPieSeries::clicked(QPieSlice* slice)
|
|
389
|
|
|
392
|
|
|
390
|
This signal is emitted when a \a slice has been clicked.
|
|
393
|
This signal is emitted when a \a slice has been clicked.
|
|
391
|
|
|
394
|
|
|
392
|
\sa QPieSlice::clicked()
|
|
395
|
\sa QPieSlice::clicked()
|
|
393
|
*/
|
|
396
|
*/
|
|
394
|
|
|
397
|
|
|
395
|
/*!
|
|
398
|
/*!
|
|
396
|
\fn void QPieSeries::hoverEnter(QPieSlice* slice)
|
|
399
|
\fn void QPieSeries::hoverEnter(QPieSlice* slice)
|
|
397
|
|
|
400
|
|
|
398
|
This signal is emitted when user has hovered over a \a slice.
|
|
401
|
This signal is emitted when user has hovered over a \a slice.
|
|
399
|
|
|
402
|
|
|
400
|
\sa QPieSlice::hoverEnter()
|
|
403
|
\sa QPieSlice::hoverEnter()
|
|
401
|
*/
|
|
404
|
*/
|
|
402
|
|
|
405
|
|
|
403
|
/*!
|
|
406
|
/*!
|
|
404
|
\fn void QPieSeries::hoverLeave(QPieSlice* slice)
|
|
407
|
\fn void QPieSeries::hoverLeave(QPieSlice* slice)
|
|
405
|
|
|
408
|
|
|
406
|
This signal is emitted when user has hovered away from a \a slice.
|
|
409
|
This signal is emitted when user has hovered away from a \a slice.
|
|
407
|
|
|
410
|
|
|
408
|
\sa QPieSlice::hoverLeave()
|
|
411
|
\sa QPieSlice::hoverLeave()
|
|
409
|
*/
|
|
412
|
*/
|
|
410
|
|
|
413
|
|
|
411
|
/*!
|
|
414
|
/*!
|
|
412
|
\fn void QPieSeries::sizeFactorChanged()
|
|
415
|
\fn void QPieSeries::sizeFactorChanged()
|
|
413
|
|
|
416
|
|
|
414
|
This signal is emitted when size factor has been changed.
|
|
417
|
This signal is emitted when size factor has been changed.
|
|
415
|
|
|
418
|
|
|
416
|
\sa sizeFactor(), setSizeFactor()
|
|
419
|
\sa sizeFactor(), setSizeFactor()
|
|
417
|
*/
|
|
420
|
*/
|
|
418
|
|
|
421
|
|
|
419
|
/*!
|
|
422
|
/*!
|
|
420
|
\fn void QPieSeries::positionChanged()
|
|
423
|
\fn void QPieSeries::positionChanged()
|
|
421
|
|
|
424
|
|
|
422
|
This signal is emitted when position of the pie has been changed.
|
|
425
|
This signal is emitted when position of the pie has been changed.
|
|
423
|
|
|
426
|
|
|
424
|
\sa position(), setPosition()
|
|
427
|
\sa position(), setPosition()
|
|
425
|
*/
|
|
428
|
*/
|
|
426
|
|
|
429
|
|
|
427
|
void QPieSeries::sliceChanged()
|
|
430
|
void QPieSeries::sliceChanged()
|
|
428
|
{
|
|
431
|
{
|
|
429
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
432
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
430
|
Q_ASSERT(m_slices.contains(slice));
|
|
433
|
Q_ASSERT(m_slices.contains(slice));
|
|
431
|
|
|
434
|
|
|
432
|
ChangeSet changeSet;
|
|
435
|
ChangeSet changeSet;
|
|
433
|
changeSet.appendChanged(slice);
|
|
436
|
changeSet.appendChanged(slice);
|
|
434
|
emit changed(changeSet);
|
|
437
|
emit changed(changeSet);
|
|
435
|
|
|
438
|
|
|
436
|
updateDerivativeData();
|
|
439
|
updateDerivativeData();
|
|
437
|
}
|
|
440
|
}
|
|
438
|
|
|
441
|
|
|
439
|
void QPieSeries::sliceClicked()
|
|
442
|
void QPieSeries::sliceClicked()
|
|
440
|
{
|
|
443
|
{
|
|
441
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
444
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
442
|
Q_ASSERT(m_slices.contains(slice));
|
|
445
|
Q_ASSERT(m_slices.contains(slice));
|
|
443
|
emit clicked(slice);
|
|
446
|
emit clicked(slice);
|
|
444
|
}
|
|
447
|
}
|
|
445
|
|
|
448
|
|
|
446
|
void QPieSeries::sliceHoverEnter()
|
|
449
|
void QPieSeries::sliceHoverEnter()
|
|
447
|
{
|
|
450
|
{
|
|
448
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
451
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
449
|
Q_ASSERT(m_slices.contains(slice));
|
|
452
|
Q_ASSERT(m_slices.contains(slice));
|
|
450
|
emit hoverEnter(slice);
|
|
453
|
emit hoverEnter(slice);
|
|
451
|
}
|
|
454
|
}
|
|
452
|
|
|
455
|
|
|
453
|
void QPieSeries::sliceHoverLeave()
|
|
456
|
void QPieSeries::sliceHoverLeave()
|
|
454
|
{
|
|
457
|
{
|
|
455
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
458
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
456
|
Q_ASSERT(m_slices.contains(slice));
|
|
459
|
Q_ASSERT(m_slices.contains(slice));
|
|
457
|
emit hoverLeave(slice);
|
|
460
|
emit hoverLeave(slice);
|
|
458
|
}
|
|
461
|
}
|
|
459
|
|
|
462
|
|
|
460
|
void QPieSeries::toggleExploded(QPieSlice* slice)
|
|
463
|
void QPieSeries::toggleExploded(QPieSlice* slice)
|
|
461
|
{
|
|
464
|
{
|
|
462
|
Q_ASSERT(slice);
|
|
465
|
Q_ASSERT(slice);
|
|
463
|
slice->setExploded(!slice->isExploded());
|
|
466
|
slice->setExploded(!slice->isExploded());
|
|
464
|
}
|
|
467
|
}
|
|
465
|
|
|
468
|
|
|
466
|
void QPieSeries::highlightOn(QPieSlice* slice)
|
|
469
|
void QPieSeries::highlightOn(QPieSlice* slice)
|
|
467
|
{
|
|
470
|
{
|
|
468
|
Q_ASSERT(slice);
|
|
471
|
Q_ASSERT(slice);
|
|
469
|
QColor c = slice->brush().color().lighter();
|
|
472
|
QColor c = slice->brush().color().lighter();
|
|
470
|
slice->setBrush(c);
|
|
473
|
slice->setBrush(c);
|
|
471
|
slice->setLabelVisible(true);
|
|
474
|
slice->setLabelVisible(true);
|
|
472
|
}
|
|
475
|
}
|
|
473
|
|
|
476
|
|
|
474
|
void QPieSeries::highlightOff(QPieSlice* slice)
|
|
477
|
void QPieSeries::highlightOff(QPieSlice* slice)
|
|
475
|
{
|
|
478
|
{
|
|
476
|
Q_ASSERT(slice);
|
|
479
|
Q_ASSERT(slice);
|
|
477
|
QColor c = slice->brush().color().darker(150);
|
|
480
|
QColor c = slice->brush().color().darker(150);
|
|
478
|
slice->setBrush(c);
|
|
481
|
slice->setBrush(c);
|
|
479
|
slice->setLabelVisible(false);
|
|
482
|
slice->setLabelVisible(false);
|
|
480
|
}
|
|
483
|
}
|
|
481
|
|
|
484
|
|
|
482
|
void QPieSeries::updateDerivativeData()
|
|
485
|
void QPieSeries::updateDerivativeData()
|
|
483
|
{
|
|
486
|
{
|
|
484
|
m_total = 0;
|
|
487
|
m_total = 0;
|
|
485
|
|
|
488
|
|
|
486
|
// nothing to do?
|
|
489
|
// nothing to do?
|
|
487
|
if (m_slices.count() == 0)
|
|
490
|
if (m_slices.count() == 0)
|
|
488
|
return;
|
|
491
|
return;
|
|
489
|
|
|
492
|
|
|
490
|
// calculate total
|
|
493
|
// calculate total
|
|
491
|
foreach (QPieSlice* s, m_slices)
|
|
494
|
foreach (QPieSlice* s, m_slices)
|
|
492
|
m_total += s->value();
|
|
495
|
m_total += s->value();
|
|
493
|
|
|
496
|
|
|
494
|
// we must have some values
|
|
497
|
// we must have some values
|
|
495
|
Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
|
|
498
|
Q_ASSERT(m_total > 0); // TODO: is this the correct way to handle this?
|
|
496
|
|
|
499
|
|
|
497
|
// update slice attributes
|
|
500
|
// update slice attributes
|
|
498
|
qreal sliceAngle = m_pieStartAngle;
|
|
501
|
qreal sliceAngle = m_pieStartAngle;
|
|
499
|
foreach (QPieSlice* s, m_slices) {
|
|
502
|
foreach (QPieSlice* s, m_slices) {
|
|
500
|
|
|
503
|
|
|
501
|
bool changed = false;
|
|
504
|
bool changed = false;
|
|
502
|
|
|
505
|
|
|
503
|
qreal percentage = s->value() / m_total;
|
|
506
|
qreal percentage = s->value() / m_total;
|
|
504
|
if (s->m_percentage != percentage) {
|
|
507
|
if (s->m_percentage != percentage) {
|
|
505
|
s->m_percentage = percentage;
|
|
508
|
s->m_percentage = percentage;
|
|
506
|
changed = true;
|
|
509
|
changed = true;
|
|
507
|
}
|
|
510
|
}
|
|
508
|
|
|
511
|
|
|
509
|
qreal sliceSpan = m_pieAngleSpan * percentage;
|
|
512
|
qreal sliceSpan = m_pieAngleSpan * percentage;
|
|
510
|
if (s->m_angleSpan != sliceSpan) {
|
|
513
|
if (s->m_angleSpan != sliceSpan) {
|
|
511
|
s->m_angleSpan = sliceSpan;
|
|
514
|
s->m_angleSpan = sliceSpan;
|
|
512
|
changed = true;
|
|
515
|
changed = true;
|
|
513
|
}
|
|
516
|
}
|
|
514
|
|
|
517
|
|
|
515
|
if (s->m_angle != sliceAngle) {
|
|
518
|
if (s->m_angle != sliceAngle) {
|
|
516
|
s->m_angle = sliceAngle;
|
|
519
|
s->m_angle = sliceAngle;
|
|
517
|
changed = true;
|
|
520
|
changed = true;
|
|
518
|
}
|
|
521
|
}
|
|
519
|
sliceAngle += sliceSpan;
|
|
522
|
sliceAngle += sliceSpan;
|
|
520
|
|
|
523
|
|
|
521
|
if (changed)
|
|
524
|
if (changed)
|
|
522
|
emit s->changed();
|
|
525
|
emit s->changed();
|
|
523
|
}
|
|
526
|
}
|
|
524
|
}
|
|
527
|
}
|
|
525
|
|
|
528
|
|
|
526
|
#include "moc_qpieseries.cpp"
|
|
529
|
#include "moc_qpieseries.cpp"
|
|
527
|
|
|
530
|
|
|
528
|
QTCOMMERCIALCHART_END_NAMESPACE
|
|
531
|
QTCOMMERCIALCHART_END_NAMESPACE
|