|
@@
-1,815
+1,813
|
|
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 "pieslicedata_p.h"
|
|
24
|
#include "pieslicedata_p.h"
|
|
25
|
#include "chartdataset_p.h"
|
|
25
|
#include "chartdataset_p.h"
|
|
26
|
#include "charttheme_p.h"
|
|
26
|
#include "charttheme_p.h"
|
|
27
|
#include "chartanimator_p.h"
|
|
27
|
#include "chartanimator_p.h"
|
|
28
|
#include "legendmarker_p.h"
|
|
28
|
#include "legendmarker_p.h"
|
|
29
|
#include <QAbstractItemModel>
|
|
29
|
#include <QAbstractItemModel>
|
|
30
|
#include "qpiemodelmapper.h"
|
|
30
|
#include "qpiemodelmapper.h"
|
|
31
|
|
|
31
|
|
|
32
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
32
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
33
|
|
|
33
|
|
|
34
|
/*!
|
|
34
|
/*!
|
|
35
|
\class QPieSeries
|
|
35
|
\class QPieSeries
|
|
36
|
\brief Pie series API for QtCommercial Charts
|
|
36
|
\brief Pie series API for QtCommercial Charts
|
|
37
|
|
|
37
|
|
|
38
|
The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
|
|
38
|
The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
|
|
39
|
The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
|
|
39
|
The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
|
|
40
|
The actual slice size is determined by that relative value.
|
|
40
|
The actual slice size is determined by that relative value.
|
|
41
|
|
|
41
|
|
|
42
|
Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
|
|
42
|
Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
|
|
43
|
These relate to the actual chart rectangle.
|
|
43
|
These relate to the actual chart rectangle.
|
|
44
|
|
|
44
|
|
|
45
|
By default the pie is defined as a full pie but it can also be a partial pie.
|
|
45
|
By default the pie is defined as a full pie but it can also be a partial pie.
|
|
46
|
This can be done by setting a starting angle and angle span to the series.
|
|
46
|
This can be done by setting a starting angle and angle span to the series.
|
|
47
|
Full pie is 360 degrees where 0 is at 12 a'clock.
|
|
47
|
Full pie is 360 degrees where 0 is at 12 a'clock.
|
|
48
|
|
|
48
|
|
|
49
|
See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
|
|
49
|
See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
|
|
50
|
\image examples_piechart.png
|
|
50
|
\image examples_piechart.png
|
|
51
|
*/
|
|
51
|
*/
|
|
52
|
|
|
52
|
|
|
53
|
/*!
|
|
53
|
/*!
|
|
54
|
\property QPieSeries::horizontalPosition
|
|
54
|
\property QPieSeries::horizontalPosition
|
|
55
|
\brief Defines the horizontal position of the pie.
|
|
55
|
\brief Defines the horizontal position of the pie.
|
|
56
|
|
|
56
|
|
|
57
|
The value is a relative value to the chart rectangle where:
|
|
57
|
The value is a relative value to the chart rectangle where:
|
|
58
|
|
|
58
|
|
|
59
|
\list
|
|
59
|
\list
|
|
60
|
\o 0.0 is the absolute left.
|
|
60
|
\o 0.0 is the absolute left.
|
|
61
|
\o 1.0 is the absolute right.
|
|
61
|
\o 1.0 is the absolute right.
|
|
62
|
\endlist
|
|
62
|
\endlist
|
|
63
|
|
|
63
|
|
|
64
|
Default value is 0.5 (center).
|
|
64
|
Default value is 0.5 (center).
|
|
65
|
*/
|
|
65
|
*/
|
|
66
|
|
|
66
|
|
|
67
|
/*!
|
|
67
|
/*!
|
|
68
|
\property QPieSeries::verticalPosition
|
|
68
|
\property QPieSeries::verticalPosition
|
|
69
|
\brief Defines the vertical position of the pie.
|
|
69
|
\brief Defines the vertical position of the pie.
|
|
70
|
|
|
70
|
|
|
71
|
The value is a relative value to the chart rectangle where:
|
|
71
|
The value is a relative value to the chart rectangle where:
|
|
72
|
|
|
72
|
|
|
73
|
\list
|
|
73
|
\list
|
|
74
|
\o 0.0 is the absolute top.
|
|
74
|
\o 0.0 is the absolute top.
|
|
75
|
\o 1.0 is the absolute bottom.
|
|
75
|
\o 1.0 is the absolute bottom.
|
|
76
|
\endlist
|
|
76
|
\endlist
|
|
77
|
|
|
77
|
|
|
78
|
Default value is 0.5 (center).
|
|
78
|
Default value is 0.5 (center).
|
|
79
|
*/
|
|
79
|
*/
|
|
80
|
|
|
80
|
|
|
81
|
/*!
|
|
81
|
/*!
|
|
82
|
\property QPieSeries::size
|
|
82
|
\property QPieSeries::size
|
|
83
|
\brief Defines the pie size.
|
|
83
|
\brief Defines the pie size.
|
|
84
|
|
|
84
|
|
|
85
|
The value is a relative value to the chart rectangle where:
|
|
85
|
The value is a relative value to the chart rectangle where:
|
|
86
|
|
|
86
|
|
|
87
|
\list
|
|
87
|
\list
|
|
88
|
\o 0.0 is the minimum size (pie not drawn).
|
|
88
|
\o 0.0 is the minimum size (pie not drawn).
|
|
89
|
\o 1.0 is the maximum size that can fit the chart.
|
|
89
|
\o 1.0 is the maximum size that can fit the chart.
|
|
90
|
\endlist
|
|
90
|
\endlist
|
|
91
|
|
|
91
|
|
|
92
|
Default value is 0.7.
|
|
92
|
Default value is 0.7.
|
|
93
|
*/
|
|
93
|
*/
|
|
94
|
|
|
94
|
|
|
95
|
/*!
|
|
95
|
/*!
|
|
96
|
\property QPieSeries::startAngle
|
|
96
|
\property QPieSeries::startAngle
|
|
97
|
\brief Defines the starting angle of the pie.
|
|
97
|
\brief Defines the starting angle of the pie.
|
|
98
|
|
|
98
|
|
|
99
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
99
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
100
|
|
|
100
|
|
|
101
|
Default is value is 0.
|
|
101
|
Default is value is 0.
|
|
102
|
*/
|
|
102
|
*/
|
|
103
|
|
|
103
|
|
|
104
|
/*!
|
|
104
|
/*!
|
|
105
|
\property QPieSeries::endAngle
|
|
105
|
\property QPieSeries::endAngle
|
|
106
|
\brief Defines the ending angle of the pie.
|
|
106
|
\brief Defines the ending angle of the pie.
|
|
107
|
|
|
107
|
|
|
108
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
108
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
109
|
|
|
109
|
|
|
110
|
Default is value is 360.
|
|
110
|
Default is value is 360.
|
|
111
|
*/
|
|
111
|
*/
|
|
112
|
|
|
112
|
|
|
113
|
|
|
113
|
|
|
114
|
/*!
|
|
114
|
/*!
|
|
115
|
Constructs a series object which is a child of \a parent.
|
|
115
|
Constructs a series object which is a child of \a parent.
|
|
116
|
*/
|
|
116
|
*/
|
|
117
|
QPieSeries::QPieSeries(QObject *parent) :
|
|
117
|
QPieSeries::QPieSeries(QObject *parent) :
|
|
118
|
QAbstractSeries(*new QPieSeriesPrivate(this),parent)
|
|
118
|
QAbstractSeries(*new QPieSeriesPrivate(this),parent)
|
|
119
|
{
|
|
119
|
{
|
|
120
|
|
|
120
|
|
|
121
|
}
|
|
121
|
}
|
|
122
|
|
|
122
|
|
|
123
|
/*!
|
|
123
|
/*!
|
|
124
|
Destroys the series and its slices.
|
|
124
|
Destroys the series and its slices.
|
|
125
|
*/
|
|
125
|
*/
|
|
126
|
QPieSeries::~QPieSeries()
|
|
126
|
QPieSeries::~QPieSeries()
|
|
127
|
{
|
|
127
|
{
|
|
128
|
// NOTE: d_prt destroyed by QObject
|
|
128
|
// NOTE: d_prt destroyed by QObject
|
|
129
|
}
|
|
129
|
}
|
|
130
|
|
|
130
|
|
|
131
|
/*!
|
|
131
|
/*!
|
|
132
|
Returns QChartSeries::SeriesTypePie.
|
|
132
|
Returns QChartSeries::SeriesTypePie.
|
|
133
|
*/
|
|
133
|
*/
|
|
134
|
QAbstractSeries::SeriesType QPieSeries::type() const
|
|
134
|
QAbstractSeries::SeriesType QPieSeries::type() const
|
|
135
|
{
|
|
135
|
{
|
|
136
|
return QAbstractSeries::SeriesTypePie;
|
|
136
|
return QAbstractSeries::SeriesTypePie;
|
|
137
|
}
|
|
137
|
}
|
|
138
|
|
|
138
|
|
|
139
|
/*!
|
|
139
|
/*!
|
|
140
|
Appends an array of \a slices to the series.
|
|
140
|
Appends an array of \a slices to the series.
|
|
141
|
Slice ownership is passed to the series.
|
|
141
|
Slice ownership is passed to the series.
|
|
142
|
*/
|
|
142
|
*/
|
|
143
|
bool QPieSeries::append(QList<QPieSlice*> slices)
|
|
143
|
bool QPieSeries::append(QList<QPieSlice*> slices)
|
|
144
|
{
|
|
144
|
{
|
|
145
|
Q_D(QPieSeries);
|
|
145
|
Q_D(QPieSeries);
|
|
146
|
|
|
146
|
|
|
147
|
if (slices.count() == 0)
|
|
147
|
if (slices.count() == 0)
|
|
148
|
return false;
|
|
148
|
return false;
|
|
149
|
|
|
149
|
|
|
150
|
foreach (QPieSlice* s, slices) {
|
|
150
|
foreach (QPieSlice* s, slices) {
|
|
151
|
if (!s || d->m_slices.contains(s))
|
|
151
|
if (!s || d->m_slices.contains(s))
|
|
152
|
return false;
|
|
152
|
return false;
|
|
153
|
}
|
|
153
|
}
|
|
154
|
|
|
154
|
|
|
155
|
foreach (QPieSlice* s, slices) {
|
|
155
|
foreach (QPieSlice* s, slices) {
|
|
156
|
s->setParent(this);
|
|
156
|
s->setParent(this);
|
|
157
|
d->m_slices << s;
|
|
157
|
d->m_slices << s;
|
|
158
|
}
|
|
158
|
}
|
|
159
|
|
|
159
|
|
|
160
|
d->updateDerivativeData();
|
|
160
|
d->updateDerivativeData();
|
|
161
|
|
|
161
|
|
|
162
|
foreach (QPieSlice* s, slices) {
|
|
162
|
foreach (QPieSlice* s, slices) {
|
|
163
|
connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
|
|
163
|
connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
|
|
164
|
connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
|
|
164
|
connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
|
|
165
|
connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
|
|
165
|
connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
|
|
166
|
}
|
|
166
|
}
|
|
167
|
|
|
167
|
|
|
168
|
emit d->added(slices);
|
|
168
|
emit d->added(slices);
|
|
169
|
|
|
169
|
|
|
170
|
return true;
|
|
170
|
return true;
|
|
171
|
}
|
|
171
|
}
|
|
172
|
|
|
172
|
|
|
173
|
/*!
|
|
173
|
/*!
|
|
174
|
Appends a single \a slice to the series.
|
|
174
|
Appends a single \a slice to the series.
|
|
175
|
Slice ownership is passed to the series.
|
|
175
|
Slice ownership is passed to the series.
|
|
176
|
*/
|
|
176
|
*/
|
|
177
|
bool QPieSeries::append(QPieSlice* slice)
|
|
177
|
bool QPieSeries::append(QPieSlice* slice)
|
|
178
|
{
|
|
178
|
{
|
|
179
|
return append(QList<QPieSlice*>() << slice);
|
|
179
|
return append(QList<QPieSlice*>() << slice);
|
|
180
|
}
|
|
180
|
}
|
|
181
|
|
|
181
|
|
|
182
|
/*!
|
|
182
|
/*!
|
|
183
|
Appends a single \a slice to the series and returns a reference to the series.
|
|
183
|
Appends a single \a slice to the series and returns a reference to the series.
|
|
184
|
Slice ownership is passed to the series.
|
|
184
|
Slice ownership is passed to the series.
|
|
185
|
*/
|
|
185
|
*/
|
|
186
|
QPieSeries& QPieSeries::operator << (QPieSlice* slice)
|
|
186
|
QPieSeries& QPieSeries::operator << (QPieSlice* slice)
|
|
187
|
{
|
|
187
|
{
|
|
188
|
append(slice);
|
|
188
|
append(slice);
|
|
189
|
return *this;
|
|
189
|
return *this;
|
|
190
|
}
|
|
190
|
}
|
|
191
|
|
|
191
|
|
|
192
|
|
|
192
|
|
|
193
|
/*!
|
|
193
|
/*!
|
|
194
|
Appends a single slice to the series with give \a value and \a name.
|
|
194
|
Appends a single slice to the series with give \a value and \a name.
|
|
195
|
Slice ownership is passed to the series.
|
|
195
|
Slice ownership is passed to the series.
|
|
196
|
*/
|
|
196
|
*/
|
|
197
|
QPieSlice* QPieSeries::append(qreal value, QString name)
|
|
197
|
QPieSlice* QPieSeries::append(qreal value, QString name)
|
|
198
|
{
|
|
198
|
{
|
|
199
|
QPieSlice* slice = new QPieSlice(value, name);
|
|
199
|
QPieSlice* slice = new QPieSlice(value, name);
|
|
200
|
append(slice);
|
|
200
|
append(slice);
|
|
201
|
return slice;
|
|
201
|
return slice;
|
|
202
|
}
|
|
202
|
}
|
|
203
|
|
|
203
|
|
|
204
|
/*!
|
|
204
|
/*!
|
|
205
|
Inserts a single \a slice to the series before the slice at \a index position.
|
|
205
|
Inserts a single \a slice to the series before the slice at \a index position.
|
|
206
|
Slice ownership is passed to the series.
|
|
206
|
Slice ownership is passed to the series.
|
|
207
|
*/
|
|
207
|
*/
|
|
208
|
bool QPieSeries::insert(int index, QPieSlice* slice)
|
|
208
|
bool QPieSeries::insert(int index, QPieSlice* slice)
|
|
209
|
{
|
|
209
|
{
|
|
210
|
Q_D(QPieSeries);
|
|
210
|
Q_D(QPieSeries);
|
|
211
|
|
|
211
|
|
|
212
|
if (index < 0 || index > d->m_slices.count())
|
|
212
|
if (index < 0 || index > d->m_slices.count())
|
|
213
|
return false;
|
|
213
|
return false;
|
|
214
|
|
|
214
|
|
|
215
|
if (!slice || d->m_slices.contains(slice))
|
|
215
|
if (!slice || d->m_slices.contains(slice))
|
|
216
|
return false;
|
|
216
|
return false;
|
|
217
|
|
|
217
|
|
|
218
|
slice->setParent(this);
|
|
218
|
slice->setParent(this);
|
|
219
|
d->m_slices.insert(index, slice);
|
|
219
|
d->m_slices.insert(index, slice);
|
|
220
|
|
|
220
|
|
|
221
|
d->updateDerivativeData();
|
|
221
|
d->updateDerivativeData();
|
|
222
|
|
|
222
|
|
|
223
|
connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
|
|
223
|
connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
|
|
224
|
connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
|
|
224
|
connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
|
|
225
|
connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
|
|
225
|
connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
|
|
226
|
|
|
226
|
|
|
227
|
emit d->added(QList<QPieSlice*>() << slice);
|
|
227
|
emit d->added(QList<QPieSlice*>() << slice);
|
|
228
|
|
|
228
|
|
|
229
|
return true;
|
|
229
|
return true;
|
|
230
|
}
|
|
230
|
}
|
|
231
|
|
|
231
|
|
|
232
|
/*!
|
|
232
|
/*!
|
|
233
|
Removes a single \a slice from the series and deletes the slice.
|
|
233
|
Removes a single \a slice from the series and deletes the slice.
|
|
234
|
|
|
234
|
|
|
235
|
Do not reference the pointer after this call.
|
|
235
|
Do not reference the pointer after this call.
|
|
236
|
*/
|
|
236
|
*/
|
|
237
|
bool QPieSeries::remove(QPieSlice* slice)
|
|
237
|
bool QPieSeries::remove(QPieSlice* slice)
|
|
238
|
{
|
|
238
|
{
|
|
239
|
Q_D(QPieSeries);
|
|
239
|
Q_D(QPieSeries);
|
|
240
|
|
|
240
|
|
|
241
|
if (!d->m_slices.removeOne(slice))
|
|
241
|
if (!d->m_slices.removeOne(slice))
|
|
242
|
return false;
|
|
242
|
return false;
|
|
243
|
|
|
243
|
|
|
244
|
d->updateDerivativeData();
|
|
244
|
d->updateDerivativeData();
|
|
245
|
|
|
245
|
|
|
246
|
emit d->removed(QList<QPieSlice*>() << slice);
|
|
246
|
emit d->removed(QList<QPieSlice*>() << slice);
|
|
247
|
|
|
247
|
|
|
248
|
delete slice;
|
|
248
|
delete slice;
|
|
249
|
slice = 0;
|
|
249
|
slice = 0;
|
|
250
|
|
|
250
|
|
|
251
|
return true;
|
|
251
|
return true;
|
|
252
|
}
|
|
252
|
}
|
|
253
|
|
|
253
|
|
|
254
|
/*!
|
|
254
|
/*!
|
|
255
|
Clears all slices from the series.
|
|
255
|
Clears all slices from the series.
|
|
256
|
*/
|
|
256
|
*/
|
|
257
|
void QPieSeries::clear()
|
|
257
|
void QPieSeries::clear()
|
|
258
|
{
|
|
258
|
{
|
|
259
|
Q_D(QPieSeries);
|
|
259
|
Q_D(QPieSeries);
|
|
260
|
if (d->m_slices.count() == 0)
|
|
260
|
if (d->m_slices.count() == 0)
|
|
261
|
return;
|
|
261
|
return;
|
|
262
|
|
|
262
|
|
|
263
|
QList<QPieSlice*> slices = d->m_slices;
|
|
263
|
QList<QPieSlice*> slices = d->m_slices;
|
|
264
|
foreach (QPieSlice* s, d->m_slices) {
|
|
264
|
foreach (QPieSlice* s, d->m_slices) {
|
|
265
|
d->m_slices.removeOne(s);
|
|
265
|
d->m_slices.removeOne(s);
|
|
266
|
delete s;
|
|
266
|
delete s;
|
|
267
|
}
|
|
267
|
}
|
|
268
|
|
|
268
|
|
|
269
|
d->updateDerivativeData();
|
|
269
|
d->updateDerivativeData();
|
|
270
|
|
|
270
|
|
|
271
|
emit d->removed(slices);
|
|
271
|
emit d->removed(slices);
|
|
272
|
}
|
|
272
|
}
|
|
273
|
|
|
273
|
|
|
274
|
/*!
|
|
274
|
/*!
|
|
275
|
returns the number of the slices in this series.
|
|
275
|
returns the number of the slices in this series.
|
|
276
|
*/
|
|
276
|
*/
|
|
277
|
int QPieSeries::count() const
|
|
277
|
int QPieSeries::count() const
|
|
278
|
{
|
|
278
|
{
|
|
279
|
Q_D(const QPieSeries);
|
|
279
|
Q_D(const QPieSeries);
|
|
280
|
return d->m_slices.count();
|
|
280
|
return d->m_slices.count();
|
|
281
|
}
|
|
281
|
}
|
|
282
|
|
|
282
|
|
|
283
|
/*!
|
|
283
|
/*!
|
|
284
|
Returns true is the series is empty.
|
|
284
|
Returns true is the series is empty.
|
|
285
|
*/
|
|
285
|
*/
|
|
286
|
bool QPieSeries::isEmpty() const
|
|
286
|
bool QPieSeries::isEmpty() const
|
|
287
|
{
|
|
287
|
{
|
|
288
|
Q_D(const QPieSeries);
|
|
288
|
Q_D(const QPieSeries);
|
|
289
|
return d->m_slices.isEmpty();
|
|
289
|
return d->m_slices.isEmpty();
|
|
290
|
}
|
|
290
|
}
|
|
291
|
|
|
291
|
|
|
292
|
/*!
|
|
292
|
/*!
|
|
293
|
Returns a list of slices that belong to this series.
|
|
293
|
Returns a list of slices that belong to this series.
|
|
294
|
*/
|
|
294
|
*/
|
|
295
|
QList<QPieSlice*> QPieSeries::slices() const
|
|
295
|
QList<QPieSlice*> QPieSeries::slices() const
|
|
296
|
{
|
|
296
|
{
|
|
297
|
Q_D(const QPieSeries);
|
|
297
|
Q_D(const QPieSeries);
|
|
298
|
return d->m_slices;
|
|
298
|
return d->m_slices;
|
|
299
|
}
|
|
299
|
}
|
|
300
|
|
|
300
|
|
|
301
|
void QPieSeries::setHorizontalPosition(qreal relativePosition)
|
|
301
|
void QPieSeries::setHorizontalPosition(qreal relativePosition)
|
|
302
|
{
|
|
302
|
{
|
|
303
|
Q_D(QPieSeries);
|
|
303
|
Q_D(QPieSeries);
|
|
304
|
if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0))
|
|
304
|
if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0))
|
|
305
|
emit d->piePositionChanged();
|
|
305
|
emit d->piePositionChanged();
|
|
306
|
}
|
|
306
|
}
|
|
307
|
|
|
307
|
|
|
308
|
void QPieSeries::setVerticalPosition(qreal relativePosition)
|
|
308
|
void QPieSeries::setVerticalPosition(qreal relativePosition)
|
|
309
|
{
|
|
309
|
{
|
|
310
|
Q_D(QPieSeries);
|
|
310
|
Q_D(QPieSeries);
|
|
311
|
if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0))
|
|
311
|
if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0))
|
|
312
|
emit d->piePositionChanged();
|
|
312
|
emit d->piePositionChanged();
|
|
313
|
}
|
|
313
|
}
|
|
314
|
|
|
314
|
|
|
315
|
qreal QPieSeries::horizontalPosition() const
|
|
315
|
qreal QPieSeries::horizontalPosition() const
|
|
316
|
{
|
|
316
|
{
|
|
317
|
Q_D(const QPieSeries);
|
|
317
|
Q_D(const QPieSeries);
|
|
318
|
return d->m_pieRelativeHorPos;
|
|
318
|
return d->m_pieRelativeHorPos;
|
|
319
|
}
|
|
319
|
}
|
|
320
|
|
|
320
|
|
|
321
|
qreal QPieSeries::verticalPosition() const
|
|
321
|
qreal QPieSeries::verticalPosition() const
|
|
322
|
{
|
|
322
|
{
|
|
323
|
Q_D(const QPieSeries);
|
|
323
|
Q_D(const QPieSeries);
|
|
324
|
return d->m_pieRelativeVerPos;
|
|
324
|
return d->m_pieRelativeVerPos;
|
|
325
|
}
|
|
325
|
}
|
|
326
|
|
|
326
|
|
|
327
|
void QPieSeries::setPieSize(qreal relativeSize)
|
|
327
|
void QPieSeries::setPieSize(qreal relativeSize)
|
|
328
|
{
|
|
328
|
{
|
|
329
|
Q_D(QPieSeries);
|
|
329
|
Q_D(QPieSeries);
|
|
330
|
if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0))
|
|
330
|
if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0))
|
|
331
|
emit d->pieSizeChanged();
|
|
331
|
emit d->pieSizeChanged();
|
|
332
|
}
|
|
332
|
}
|
|
333
|
|
|
333
|
|
|
334
|
qreal QPieSeries::pieSize() const
|
|
334
|
qreal QPieSeries::pieSize() const
|
|
335
|
{
|
|
335
|
{
|
|
336
|
Q_D(const QPieSeries);
|
|
336
|
Q_D(const QPieSeries);
|
|
337
|
return d->m_pieRelativeSize;
|
|
337
|
return d->m_pieRelativeSize;
|
|
338
|
}
|
|
338
|
}
|
|
339
|
|
|
339
|
|
|
340
|
|
|
340
|
|
|
341
|
void QPieSeries::setPieStartAngle(qreal angle)
|
|
341
|
void QPieSeries::setPieStartAngle(qreal angle)
|
|
342
|
{
|
|
342
|
{
|
|
343
|
Q_D(QPieSeries);
|
|
343
|
Q_D(QPieSeries);
|
|
344
|
if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle))
|
|
344
|
if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle))
|
|
345
|
d->updateDerivativeData();
|
|
345
|
d->updateDerivativeData();
|
|
346
|
}
|
|
346
|
}
|
|
347
|
|
|
347
|
|
|
348
|
qreal QPieSeries::pieStartAngle() const
|
|
348
|
qreal QPieSeries::pieStartAngle() const
|
|
349
|
{
|
|
349
|
{
|
|
350
|
Q_D(const QPieSeries);
|
|
350
|
Q_D(const QPieSeries);
|
|
351
|
return d->m_pieStartAngle;
|
|
351
|
return d->m_pieStartAngle;
|
|
352
|
}
|
|
352
|
}
|
|
353
|
|
|
353
|
|
|
354
|
/*!
|
|
354
|
/*!
|
|
355
|
Sets the end angle of the pie.
|
|
355
|
Sets the end angle of the pie.
|
|
356
|
|
|
356
|
|
|
357
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
357
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
358
|
|
|
358
|
|
|
359
|
\a angle must be greater than start angle.
|
|
359
|
\a angle must be greater than start angle.
|
|
360
|
|
|
360
|
|
|
361
|
\sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
|
|
361
|
\sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
|
|
362
|
*/
|
|
362
|
*/
|
|
363
|
void QPieSeries::setPieEndAngle(qreal angle)
|
|
363
|
void QPieSeries::setPieEndAngle(qreal angle)
|
|
364
|
{
|
|
364
|
{
|
|
365
|
Q_D(QPieSeries);
|
|
365
|
Q_D(QPieSeries);
|
|
366
|
|
|
366
|
|
|
367
|
if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle))
|
|
367
|
if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle))
|
|
368
|
d->updateDerivativeData();
|
|
368
|
d->updateDerivativeData();
|
|
369
|
}
|
|
369
|
}
|
|
370
|
|
|
370
|
|
|
371
|
/*!
|
|
371
|
/*!
|
|
372
|
Returns the end angle of the pie.
|
|
372
|
Returns the end angle of the pie.
|
|
373
|
|
|
373
|
|
|
374
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
374
|
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
|
|
375
|
|
|
375
|
|
|
376
|
\sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
|
|
376
|
\sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
|
|
377
|
*/
|
|
377
|
*/
|
|
378
|
qreal QPieSeries::pieEndAngle() const
|
|
378
|
qreal QPieSeries::pieEndAngle() const
|
|
379
|
{
|
|
379
|
{
|
|
380
|
Q_D(const QPieSeries);
|
|
380
|
Q_D(const QPieSeries);
|
|
381
|
return d->m_pieEndAngle;
|
|
381
|
return d->m_pieEndAngle;
|
|
382
|
}
|
|
382
|
}
|
|
383
|
|
|
383
|
|
|
384
|
/*!
|
|
384
|
/*!
|
|
385
|
Sets the all the slice labels \a visible or invisible.
|
|
385
|
Sets the all the slice labels \a visible or invisible.
|
|
386
|
|
|
386
|
|
|
387
|
\sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
|
|
387
|
\sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
|
|
388
|
*/
|
|
388
|
*/
|
|
389
|
void QPieSeries::setLabelsVisible(bool visible)
|
|
389
|
void QPieSeries::setLabelsVisible(bool visible)
|
|
390
|
{
|
|
390
|
{
|
|
391
|
Q_D(QPieSeries);
|
|
391
|
Q_D(QPieSeries);
|
|
392
|
foreach (QPieSlice* s, d->m_slices)
|
|
392
|
foreach (QPieSlice* s, d->m_slices)
|
|
393
|
s->setLabelVisible(visible);
|
|
393
|
s->setLabelVisible(visible);
|
|
394
|
}
|
|
394
|
}
|
|
395
|
|
|
395
|
|
|
396
|
/*!
|
|
396
|
/*!
|
|
397
|
Returns the sum of all slice values in this series.
|
|
397
|
Returns the sum of all slice values in this series.
|
|
398
|
|
|
398
|
|
|
399
|
\sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
|
|
399
|
\sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
|
|
400
|
*/
|
|
400
|
*/
|
|
401
|
qreal QPieSeries::sum() const
|
|
401
|
qreal QPieSeries::sum() const
|
|
402
|
{
|
|
402
|
{
|
|
403
|
Q_D(const QPieSeries);
|
|
403
|
Q_D(const QPieSeries);
|
|
404
|
return d->m_sum;
|
|
404
|
return d->m_sum;
|
|
405
|
}
|
|
405
|
}
|
|
406
|
|
|
406
|
|
|
407
|
/*!
|
|
407
|
/*!
|
|
408
|
\fn void QPieSeries::clicked(QPieSlice* slice)
|
|
408
|
\fn void QPieSeries::clicked(QPieSlice* slice)
|
|
409
|
|
|
409
|
|
|
410
|
This signal is emitted when a \a slice has been clicked.
|
|
410
|
This signal is emitted when a \a slice has been clicked.
|
|
411
|
|
|
411
|
|
|
412
|
\sa QPieSlice::clicked()
|
|
412
|
\sa QPieSlice::clicked()
|
|
413
|
*/
|
|
413
|
*/
|
|
414
|
|
|
414
|
|
|
415
|
/*!
|
|
415
|
/*!
|
|
416
|
\fn void QPieSeries::hovered(QPieSlice* slice, bool state)
|
|
416
|
\fn void QPieSeries::hovered(QPieSlice* slice, bool state)
|
|
417
|
|
|
417
|
|
|
418
|
This signal is emitted when user has hovered over or away from the \a slice.
|
|
418
|
This signal is emitted when user has hovered over or away from the \a slice.
|
|
419
|
|
|
419
|
|
|
420
|
\a state is true when user has hovered over the slice and false when hover has moved away from the slice.
|
|
420
|
\a state is true when user has hovered over the slice and false when hover has moved away from the slice.
|
|
421
|
|
|
421
|
|
|
422
|
\sa QPieSlice::hovered()
|
|
422
|
\sa QPieSlice::hovered()
|
|
423
|
*/
|
|
423
|
*/
|
|
424
|
|
|
424
|
|
|
425
|
/*!
|
|
425
|
/*!
|
|
426
|
\fn bool QPieSeries::setModel(QAbstractItemModel *model)
|
|
426
|
\fn bool QPieSeries::setModel(QAbstractItemModel *model)
|
|
427
|
Sets the \a model to be used as a data source
|
|
427
|
Sets the \a model to be used as a data source
|
|
428
|
*/
|
|
428
|
*/
|
|
429
|
void QPieSeries::setModel(QAbstractItemModel* model)
|
|
429
|
void QPieSeries::setModel(QAbstractItemModel* model)
|
|
430
|
{
|
|
430
|
{
|
|
431
|
Q_D(QPieSeries);
|
|
431
|
Q_D(QPieSeries);
|
|
432
|
// disconnect signals from old model
|
|
432
|
// disconnect signals from old model
|
|
433
|
if(d->m_model)
|
|
433
|
if(d->m_model)
|
|
434
|
{
|
|
434
|
{
|
|
435
|
disconnect(d->m_model, 0, this, 0);
|
|
435
|
disconnect(d->m_model, 0, this, 0);
|
|
436
|
}
|
|
436
|
}
|
|
437
|
|
|
437
|
|
|
438
|
// set new model
|
|
438
|
// set new model
|
|
439
|
if(model)
|
|
439
|
if(model)
|
|
440
|
{
|
|
440
|
{
|
|
441
|
d->m_model = model;
|
|
441
|
d->m_model = model;
|
|
442
|
// connect signals from the model
|
|
442
|
// connect signals from the model
|
|
443
|
connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
|
|
443
|
connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
|
|
444
|
connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
|
|
444
|
connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
|
|
445
|
connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
|
|
445
|
connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
|
|
446
|
connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
|
|
446
|
connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
|
|
447
|
connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
|
|
447
|
connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
|
|
448
|
|
|
448
|
|
|
449
|
if (d->m_mapper)
|
|
449
|
if (d->m_mapper)
|
|
450
|
d->initializePieFromModel();
|
|
450
|
d->initializePieFromModel();
|
|
451
|
}
|
|
451
|
}
|
|
452
|
else
|
|
452
|
else
|
|
453
|
{
|
|
453
|
{
|
|
454
|
d->m_model = 0;
|
|
454
|
d->m_model = 0;
|
|
455
|
}
|
|
455
|
}
|
|
456
|
}
|
|
456
|
}
|
|
457
|
|
|
457
|
|
|
458
|
void QPieSeries::setModelMapper(QPieModelMapper *mapper)
|
|
458
|
void QPieSeries::setModelMapper(QPieModelMapper *mapper)
|
|
459
|
{
|
|
459
|
{
|
|
460
|
Q_D(QPieSeries);
|
|
460
|
Q_D(QPieSeries);
|
|
461
|
// disconnect signals from old mapper
|
|
461
|
// disconnect signals from old mapper
|
|
462
|
if (d->m_mapper) {
|
|
462
|
if (d->m_mapper) {
|
|
463
|
QObject::disconnect(d->m_mapper, 0, this, 0);
|
|
463
|
QObject::disconnect(d->m_mapper, 0, this, 0);
|
|
464
|
}
|
|
464
|
}
|
|
465
|
|
|
465
|
|
|
466
|
if (mapper) {
|
|
466
|
if (mapper) {
|
|
467
|
d->m_mapper = mapper;
|
|
467
|
d->m_mapper = mapper;
|
|
468
|
// connect the signal from the mapper
|
|
468
|
// connect the signal from the mapper
|
|
469
|
connect(d->m_mapper, SIGNAL(updated()), d, SLOT(initializePieFromModel()));
|
|
469
|
connect(d->m_mapper, SIGNAL(updated()), d, SLOT(initializePieFromModel()));
|
|
470
|
|
|
470
|
|
|
471
|
if (d->m_model)
|
|
471
|
if (d->m_model)
|
|
472
|
d->initializePieFromModel();
|
|
472
|
d->initializePieFromModel();
|
|
473
|
} else {
|
|
473
|
} else {
|
|
474
|
d->m_mapper = 0;
|
|
474
|
d->m_mapper = 0;
|
|
475
|
}
|
|
475
|
}
|
|
476
|
}
|
|
476
|
}
|
|
477
|
|
|
477
|
|
|
478
|
QPieModelMapper* QPieSeries::modelMapper() const
|
|
478
|
QPieModelMapper* QPieSeries::modelMapper() const
|
|
479
|
{
|
|
479
|
{
|
|
480
|
Q_D(const QPieSeries);
|
|
480
|
Q_D(const QPieSeries);
|
|
481
|
return d->m_mapper;
|
|
481
|
return d->m_mapper;
|
|
482
|
}
|
|
482
|
}
|
|
483
|
|
|
483
|
|
|
484
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
484
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
485
|
|
|
485
|
|
|
486
|
|
|
486
|
|
|
487
|
QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
|
|
487
|
QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
|
|
488
|
QAbstractSeriesPrivate(parent),
|
|
488
|
QAbstractSeriesPrivate(parent),
|
|
489
|
m_pieRelativeHorPos(0.5),
|
|
489
|
m_pieRelativeHorPos(0.5),
|
|
490
|
m_pieRelativeVerPos(0.5),
|
|
490
|
m_pieRelativeVerPos(0.5),
|
|
491
|
m_pieRelativeSize(0.7),
|
|
491
|
m_pieRelativeSize(0.7),
|
|
492
|
m_pieStartAngle(0),
|
|
492
|
m_pieStartAngle(0),
|
|
493
|
m_pieEndAngle(360),
|
|
493
|
m_pieEndAngle(360),
|
|
494
|
m_sum(0),
|
|
494
|
m_sum(0),
|
|
495
|
m_mapper(0)
|
|
495
|
m_mapper(0)
|
|
496
|
{
|
|
496
|
{
|
|
497
|
|
|
497
|
|
|
498
|
}
|
|
498
|
}
|
|
499
|
|
|
499
|
|
|
500
|
QPieSeriesPrivate::~QPieSeriesPrivate()
|
|
500
|
QPieSeriesPrivate::~QPieSeriesPrivate()
|
|
501
|
{
|
|
501
|
{
|
|
502
|
|
|
502
|
|
|
503
|
}
|
|
503
|
}
|
|
504
|
|
|
504
|
|
|
505
|
void QPieSeriesPrivate::updateDerivativeData()
|
|
505
|
void QPieSeriesPrivate::updateDerivativeData()
|
|
506
|
{
|
|
506
|
{
|
|
507
|
m_sum = 0;
|
|
507
|
m_sum = 0;
|
|
508
|
|
|
508
|
|
|
509
|
// nothing to do?
|
|
509
|
// nothing to do?
|
|
510
|
if (m_slices.count() == 0)
|
|
510
|
if (m_slices.count() == 0)
|
|
511
|
return;
|
|
511
|
return;
|
|
512
|
|
|
512
|
|
|
513
|
// calculate sum of all slices
|
|
513
|
// calculate sum of all slices
|
|
514
|
foreach (QPieSlice* s, m_slices)
|
|
514
|
foreach (QPieSlice* s, m_slices)
|
|
515
|
m_sum += s->value();
|
|
515
|
m_sum += s->value();
|
|
516
|
|
|
516
|
|
|
517
|
// nothing to show..
|
|
517
|
// nothing to show..
|
|
518
|
if (qFuzzyIsNull(m_sum))
|
|
518
|
if (qFuzzyIsNull(m_sum))
|
|
519
|
return;
|
|
519
|
return;
|
|
520
|
|
|
520
|
|
|
521
|
// update slice attributes
|
|
521
|
// update slice attributes
|
|
522
|
qreal sliceAngle = m_pieStartAngle;
|
|
522
|
qreal sliceAngle = m_pieStartAngle;
|
|
523
|
qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
|
|
523
|
qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
|
|
524
|
QVector<QPieSlice*> changed;
|
|
524
|
QVector<QPieSlice*> changed;
|
|
525
|
foreach (QPieSlice* s, m_slices) {
|
|
525
|
foreach (QPieSlice* s, m_slices) {
|
|
526
|
|
|
526
|
|
|
527
|
PieSliceData data = PieSliceData::data(s);
|
|
527
|
PieSliceData data = PieSliceData::data(s);
|
|
528
|
data.m_percentage = s->value() / m_sum;
|
|
528
|
data.m_percentage = s->value() / m_sum;
|
|
529
|
data.m_angleSpan = pieSpan * data.m_percentage;
|
|
529
|
data.m_angleSpan = pieSpan * data.m_percentage;
|
|
530
|
data.m_startAngle = sliceAngle;
|
|
530
|
data.m_startAngle = sliceAngle;
|
|
531
|
sliceAngle += data.m_angleSpan;
|
|
531
|
sliceAngle += data.m_angleSpan;
|
|
532
|
|
|
532
|
|
|
533
|
if (PieSliceData::data(s) != data) {
|
|
533
|
if (PieSliceData::data(s) != data) {
|
|
534
|
PieSliceData::data(s) = data;
|
|
534
|
PieSliceData::data(s) = data;
|
|
535
|
changed << s;
|
|
535
|
changed << s;
|
|
536
|
}
|
|
536
|
}
|
|
537
|
}
|
|
537
|
}
|
|
538
|
|
|
538
|
|
|
539
|
// emit signals
|
|
539
|
// emit signals
|
|
540
|
foreach (QPieSlice* s, changed)
|
|
540
|
foreach (QPieSlice* s, changed)
|
|
541
|
PieSliceData::data(s).emitChangedSignal(s);
|
|
541
|
PieSliceData::data(s).emitChangedSignal(s);
|
|
542
|
}
|
|
542
|
}
|
|
543
|
|
|
543
|
|
|
544
|
QPieSeriesPrivate* QPieSeriesPrivate::seriesData(QPieSeries &series)
|
|
544
|
QPieSeriesPrivate* QPieSeriesPrivate::seriesData(QPieSeries &series)
|
|
545
|
{
|
|
545
|
{
|
|
546
|
return series.d_func();
|
|
546
|
return series.d_func();
|
|
547
|
}
|
|
547
|
}
|
|
548
|
|
|
548
|
|
|
549
|
void QPieSeriesPrivate::sliceChanged()
|
|
549
|
void QPieSeriesPrivate::sliceChanged()
|
|
550
|
{
|
|
550
|
{
|
|
551
|
Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
|
|
551
|
Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
|
|
552
|
updateDerivativeData();
|
|
552
|
updateDerivativeData();
|
|
553
|
}
|
|
553
|
}
|
|
554
|
|
|
554
|
|
|
555
|
void QPieSeriesPrivate::sliceClicked()
|
|
555
|
void QPieSeriesPrivate::sliceClicked()
|
|
556
|
{
|
|
556
|
{
|
|
557
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
557
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
558
|
Q_ASSERT(m_slices.contains(slice));
|
|
558
|
Q_ASSERT(m_slices.contains(slice));
|
|
559
|
Q_Q(QPieSeries);
|
|
559
|
Q_Q(QPieSeries);
|
|
560
|
emit q->clicked(slice);
|
|
560
|
emit q->clicked(slice);
|
|
561
|
}
|
|
561
|
}
|
|
562
|
|
|
562
|
|
|
563
|
void QPieSeriesPrivate::sliceHovered(bool state)
|
|
563
|
void QPieSeriesPrivate::sliceHovered(bool state)
|
|
564
|
{
|
|
564
|
{
|
|
565
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
565
|
QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
|
|
566
|
Q_ASSERT(m_slices.contains(slice));
|
|
566
|
Q_ASSERT(m_slices.contains(slice));
|
|
567
|
Q_Q(QPieSeries);
|
|
567
|
Q_Q(QPieSeries);
|
|
568
|
emit q->hovered(slice, state);
|
|
568
|
emit q->hovered(slice, state);
|
|
569
|
}
|
|
569
|
}
|
|
570
|
|
|
570
|
|
|
571
|
void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
|
|
571
|
void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
|
|
572
|
{
|
|
572
|
{
|
|
573
|
if (m_mapper) {
|
|
573
|
if (m_mapper) {
|
|
574
|
for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
|
|
574
|
for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
|
|
575
|
for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
|
|
575
|
for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
|
|
576
|
if (m_mapper->orientation() == Qt::Vertical)
|
|
576
|
if (m_mapper->orientation() == Qt::Vertical)
|
|
577
|
{
|
|
577
|
{
|
|
578
|
if ( topLeft.row() >= m_mapper->first() && (m_mapper->count() == - 1 || topLeft.row() < m_mapper->first() + m_mapper->count())) {
|
|
578
|
if ( topLeft.row() >= m_mapper->first() && (m_mapper->count() == - 1 || topLeft.row() < m_mapper->first() + m_mapper->count())) {
|
|
579
|
if (topLeft.column() == m_mapper->mapValues())
|
|
579
|
if (topLeft.column() == m_mapper->mapValues())
|
|
580
|
m_slices.at(topLeft.row() - m_mapper->first())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
580
|
m_slices.at(topLeft.row() - m_mapper->first())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
581
|
if (topLeft.column() == m_mapper->mapLabels())
|
|
581
|
if (topLeft.column() == m_mapper->mapLabels())
|
|
582
|
m_slices.at(topLeft.row() - m_mapper->first())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
|
|
582
|
m_slices.at(topLeft.row() - m_mapper->first())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
|
|
583
|
}
|
|
583
|
}
|
|
584
|
}
|
|
584
|
}
|
|
585
|
else
|
|
585
|
else
|
|
586
|
{
|
|
586
|
{
|
|
587
|
if (topLeft.column() >= m_mapper->first() && (m_mapper->count() == - 1 || topLeft.column() < m_mapper->first() + m_mapper->count())) {
|
|
587
|
if (topLeft.column() >= m_mapper->first() && (m_mapper->count() == - 1 || topLeft.column() < m_mapper->first() + m_mapper->count())) {
|
|
588
|
if (topLeft.row() == m_mapper->mapValues())
|
|
588
|
if (topLeft.row() == m_mapper->mapValues())
|
|
589
|
m_slices.at(topLeft.column() - m_mapper->first())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
589
|
m_slices.at(topLeft.column() - m_mapper->first())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
|
|
590
|
if (topLeft.row() == m_mapper->mapLabels())
|
|
590
|
if (topLeft.row() == m_mapper->mapLabels())
|
|
591
|
m_slices.at(topLeft.column() - m_mapper->first())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
|
|
591
|
m_slices.at(topLeft.column() - m_mapper->first())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
|
|
592
|
}
|
|
592
|
}
|
|
593
|
}
|
|
593
|
}
|
|
594
|
}
|
|
594
|
}
|
|
595
|
}
|
|
595
|
}
|
|
596
|
}
|
|
596
|
}
|
|
597
|
}
|
|
597
|
}
|
|
598
|
|
|
598
|
|
|
599
|
|
|
599
|
|
|
600
|
void QPieSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
|
|
600
|
void QPieSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
|
|
601
|
{
|
|
601
|
{
|
|
602
|
Q_UNUSED(parent);
|
|
602
|
Q_UNUSED(parent);
|
|
603
|
if (m_mapper) {
|
|
603
|
if (m_mapper) {
|
|
604
|
if (m_mapper->orientation() == Qt::Vertical)
|
|
604
|
if (m_mapper->orientation() == Qt::Vertical)
|
|
605
|
insertData(start, end);
|
|
605
|
insertData(start, end);
|
|
606
|
else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
|
|
606
|
else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
|
|
607
|
initializePieFromModel();
|
|
607
|
initializePieFromModel();
|
|
608
|
}
|
|
608
|
}
|
|
609
|
}
|
|
609
|
}
|
|
610
|
|
|
610
|
|
|
611
|
void QPieSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
|
|
611
|
void QPieSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
|
|
612
|
{
|
|
612
|
{
|
|
613
|
Q_UNUSED(parent);
|
|
613
|
Q_UNUSED(parent);
|
|
614
|
if (m_mapper) {
|
|
614
|
if (m_mapper) {
|
|
615
|
if (m_mapper->orientation() == Qt::Vertical)
|
|
615
|
if (m_mapper->orientation() == Qt::Vertical)
|
|
616
|
removeData(start, end);
|
|
616
|
removeData(start, end);
|
|
617
|
else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
|
|
617
|
else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
|
|
618
|
initializePieFromModel();
|
|
618
|
initializePieFromModel();
|
|
619
|
}
|
|
619
|
}
|
|
620
|
}
|
|
620
|
}
|
|
621
|
|
|
621
|
|
|
622
|
void QPieSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
|
|
622
|
void QPieSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
|
|
623
|
{
|
|
623
|
{
|
|
624
|
Q_UNUSED(parent);
|
|
624
|
Q_UNUSED(parent);
|
|
625
|
if (m_mapper) {
|
|
625
|
if (m_mapper) {
|
|
626
|
if (m_mapper->orientation() == Qt::Horizontal)
|
|
626
|
if (m_mapper->orientation() == Qt::Horizontal)
|
|
627
|
insertData(start, end);
|
|
627
|
insertData(start, end);
|
|
628
|
else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
|
|
628
|
else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
|
|
629
|
initializePieFromModel();
|
|
629
|
initializePieFromModel();
|
|
630
|
}
|
|
630
|
}
|
|
631
|
}
|
|
631
|
}
|
|
632
|
|
|
632
|
|
|
633
|
void QPieSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
|
|
633
|
void QPieSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
|
|
634
|
{
|
|
634
|
{
|
|
635
|
Q_UNUSED(parent);
|
|
635
|
Q_UNUSED(parent);
|
|
636
|
if (m_mapper) {
|
|
636
|
if (m_mapper) {
|
|
637
|
if (m_mapper->orientation() == Qt::Horizontal)
|
|
637
|
if (m_mapper->orientation() == Qt::Horizontal)
|
|
638
|
removeData(start, end);
|
|
638
|
removeData(start, end);
|
|
639
|
else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
|
|
639
|
else if (start <= m_mapper->mapValues() || start <= m_mapper->mapLabels()) // if the changes affect the map - reinitialize the pie
|
|
640
|
initializePieFromModel();
|
|
640
|
initializePieFromModel();
|
|
641
|
}
|
|
641
|
}
|
|
642
|
}
|
|
642
|
}
|
|
643
|
|
|
643
|
|
|
644
|
void QPieSeriesPrivate::insertData(int start, int end)
|
|
644
|
void QPieSeriesPrivate::insertData(int start, int end)
|
|
645
|
{
|
|
645
|
{
|
|
646
|
Q_Q(QPieSeries);
|
|
646
|
Q_Q(QPieSeries);
|
|
647
|
if (m_mapper) {
|
|
647
|
if (m_mapper) {
|
|
648
|
if (m_mapper->count() != -1 && start >= m_mapper->first() + m_mapper->count()) {
|
|
648
|
if (m_mapper->count() != -1 && start >= m_mapper->first() + m_mapper->count()) {
|
|
649
|
return;
|
|
649
|
return;
|
|
650
|
} else {
|
|
650
|
} else {
|
|
651
|
int addedCount = end - start + 1;
|
|
651
|
int addedCount = end - start + 1;
|
|
652
|
if (m_mapper->count() != -1 && addedCount > m_mapper->count())
|
|
652
|
if (m_mapper->count() != -1 && addedCount > m_mapper->count())
|
|
653
|
addedCount = m_mapper->count();
|
|
653
|
addedCount = m_mapper->count();
|
|
654
|
int first = qMax(start, m_mapper->first());
|
|
654
|
int first = qMax(start, m_mapper->first());
|
|
655
|
int last = qMin(first + addedCount - 1, m_mapper->orientation() == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
|
|
655
|
int last = qMin(first + addedCount - 1, m_mapper->orientation() == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
|
|
656
|
for (int i = first; i <= last; i++) {
|
|
656
|
for (int i = first; i <= last; i++) {
|
|
657
|
QPieSlice *slice = new QPieSlice;
|
|
657
|
QPieSlice *slice = new QPieSlice;
|
|
658
|
if (m_mapper->orientation() == Qt::Vertical) {
|
|
658
|
if (m_mapper->orientation() == Qt::Vertical) {
|
|
659
|
slice->setValue(m_model->data(m_model->index(i, m_mapper->mapValues()), Qt::DisplayRole).toDouble());
|
|
659
|
slice->setValue(m_model->data(m_model->index(i, m_mapper->mapValues()), Qt::DisplayRole).toDouble());
|
|
660
|
slice->setLabel(m_model->data(m_model->index(i, m_mapper->mapLabels()), Qt::DisplayRole).toString());
|
|
660
|
slice->setLabel(m_model->data(m_model->index(i, m_mapper->mapLabels()), Qt::DisplayRole).toString());
|
|
661
|
} else {
|
|
661
|
} else {
|
|
662
|
slice->setValue(m_model->data(m_model->index(m_mapper->mapValues(), i), Qt::DisplayRole).toDouble());
|
|
662
|
slice->setValue(m_model->data(m_model->index(m_mapper->mapValues(), i), Qt::DisplayRole).toDouble());
|
|
663
|
slice->setLabel(m_model->data(m_model->index(m_mapper->mapLabels(), i), Qt::DisplayRole).toString());
|
|
663
|
slice->setLabel(m_model->data(m_model->index(m_mapper->mapLabels(), i), Qt::DisplayRole).toString());
|
|
664
|
}
|
|
664
|
}
|
|
665
|
slice->setLabelVisible();
|
|
665
|
slice->setLabelVisible();
|
|
666
|
q->insert(i - m_mapper->first(), slice);
|
|
666
|
q->insert(i - m_mapper->first(), slice);
|
|
667
|
}
|
|
667
|
}
|
|
668
|
if (m_mapper->count() != -1 && m_slices.size() > m_mapper->count())
|
|
668
|
if (m_mapper->count() != -1 && m_slices.size() > m_mapper->count())
|
|
669
|
for (int i = m_slices.size() - 1; i >= m_mapper->count(); i--)
|
|
669
|
for (int i = m_slices.size() - 1; i >= m_mapper->count(); i--)
|
|
670
|
q->remove(q->slices().at(i));
|
|
670
|
q->remove(q->slices().at(i));
|
|
671
|
}
|
|
671
|
}
|
|
672
|
}
|
|
672
|
}
|
|
673
|
}
|
|
673
|
}
|
|
674
|
|
|
674
|
|
|
675
|
void QPieSeriesPrivate::removeData(int start, int end)
|
|
675
|
void QPieSeriesPrivate::removeData(int start, int end)
|
|
676
|
{
|
|
676
|
{
|
|
677
|
Q_Q(QPieSeries);
|
|
677
|
Q_Q(QPieSeries);
|
|
678
|
if (m_mapper) {
|
|
678
|
if (m_mapper) {
|
|
679
|
int removedCount = end - start + 1;
|
|
679
|
int removedCount = end - start + 1;
|
|
680
|
if (m_mapper->count() != -1 && start >= m_mapper->first() + m_mapper->count()) {
|
|
680
|
if (m_mapper->count() != -1 && start >= m_mapper->first() + m_mapper->count()) {
|
|
681
|
return;
|
|
681
|
return;
|
|
682
|
} else {
|
|
682
|
} else {
|
|
683
|
int toRemove = qMin(m_slices.size(), removedCount); // first find how many items can actually be removed
|
|
683
|
int toRemove = qMin(m_slices.size(), removedCount); // first find how many items can actually be removed
|
|
684
|
int first = qMax(start, m_mapper->first()); // get the index of the first item that will be removed.
|
|
684
|
int first = qMax(start, m_mapper->first()); // get the index of the first item that will be removed.
|
|
685
|
int last = qMin(first + toRemove - 1, m_slices.size() + m_mapper->first() - 1); // get the index of the last item that will be removed.
|
|
685
|
int last = qMin(first + toRemove - 1, m_slices.size() + m_mapper->first() - 1); // get the index of the last item that will be removed.
|
|
686
|
for (int i = last; i >= first; i--)
|
|
686
|
for (int i = last; i >= first; i--)
|
|
687
|
q->remove(q->slices().at(i - m_mapper->first()));
|
|
687
|
q->remove(q->slices().at(i - m_mapper->first()));
|
|
688
|
|
|
688
|
|
|
689
|
if (m_mapper->count() != -1) {
|
|
689
|
if (m_mapper->count() != -1) {
|
|
690
|
int itemsAvailable; // check how many are available to be added
|
|
690
|
int itemsAvailable; // check how many are available to be added
|
|
691
|
if (m_mapper->orientation() == Qt::Vertical)
|
|
691
|
if (m_mapper->orientation() == Qt::Vertical)
|
|
692
|
itemsAvailable = m_model->rowCount() - m_mapper->first() - m_slices.size();
|
|
692
|
itemsAvailable = m_model->rowCount() - m_mapper->first() - m_slices.size();
|
|
693
|
else
|
|
693
|
else
|
|
694
|
itemsAvailable = m_model->columnCount() - m_mapper->first() - m_slices.size();
|
|
694
|
itemsAvailable = m_model->columnCount() - m_mapper->first() - m_slices.size();
|
|
695
|
int toBeAdded = qMin(itemsAvailable, m_mapper->count() - m_slices.size()); // add not more items than there is space left to be filled.
|
|
695
|
int toBeAdded = qMin(itemsAvailable, m_mapper->count() - m_slices.size()); // add not more items than there is space left to be filled.
|
|
696
|
int currentSize = m_slices.size();
|
|
696
|
int currentSize = m_slices.size();
|
|
697
|
if (toBeAdded > 0)
|
|
697
|
if (toBeAdded > 0)
|
|
698
|
for (int i = m_slices.size(); i < currentSize + toBeAdded; i++) {
|
|
698
|
for (int i = m_slices.size(); i < currentSize + toBeAdded; i++) {
|
|
699
|
QPieSlice *slice = new QPieSlice;
|
|
699
|
QPieSlice *slice = new QPieSlice;
|
|
700
|
if (m_mapper->orientation() == Qt::Vertical) {
|
|
700
|
if (m_mapper->orientation() == Qt::Vertical) {
|
|
701
|
slice->setValue(m_model->data(m_model->index(i + m_mapper->first(), m_mapper->mapValues()), Qt::DisplayRole).toDouble());
|
|
701
|
slice->setValue(m_model->data(m_model->index(i + m_mapper->first(), m_mapper->mapValues()), Qt::DisplayRole).toDouble());
|
|
702
|
slice->setLabel(m_model->data(m_model->index(i + m_mapper->first(), m_mapper->mapLabels()), Qt::DisplayRole).toString());
|
|
702
|
slice->setLabel(m_model->data(m_model->index(i + m_mapper->first(), m_mapper->mapLabels()), Qt::DisplayRole).toString());
|
|
703
|
} else {
|
|
703
|
} else {
|
|
704
|
slice->setValue(m_model->data(m_model->index(m_mapper->mapValues(), i + m_mapper->first()), Qt::DisplayRole).toDouble());
|
|
704
|
slice->setValue(m_model->data(m_model->index(m_mapper->mapValues(), i + m_mapper->first()), Qt::DisplayRole).toDouble());
|
|
705
|
slice->setLabel(m_model->data(m_model->index(m_mapper->mapLabels(), i + m_mapper->first()), Qt::DisplayRole).toString());
|
|
705
|
slice->setLabel(m_model->data(m_model->index(m_mapper->mapLabels(), i + m_mapper->first()), Qt::DisplayRole).toString());
|
|
706
|
}
|
|
706
|
}
|
|
707
|
slice->setLabelVisible();
|
|
707
|
slice->setLabelVisible();
|
|
708
|
q->insert(i, slice);
|
|
708
|
q->insert(i, slice);
|
|
709
|
}
|
|
709
|
}
|
|
710
|
}
|
|
710
|
}
|
|
711
|
}
|
|
711
|
}
|
|
712
|
}
|
|
712
|
}
|
|
713
|
}
|
|
713
|
}
|
|
714
|
|
|
714
|
|
|
715
|
void QPieSeriesPrivate::initializePieFromModel()
|
|
715
|
void QPieSeriesPrivate::initializePieFromModel()
|
|
716
|
{
|
|
716
|
{
|
|
717
|
Q_Q(QPieSeries);
|
|
717
|
Q_Q(QPieSeries);
|
|
718
|
|
|
718
|
|
|
719
|
// clear current content
|
|
719
|
// clear current content
|
|
720
|
q->clear();
|
|
720
|
q->clear();
|
|
721
|
|
|
721
|
|
|
722
|
if (m_model == 0 || m_mapper == 0)
|
|
722
|
if (m_model == 0 || m_mapper == 0)
|
|
723
|
return;
|
|
723
|
return;
|
|
724
|
|
|
724
|
|
|
725
|
// check if mappings are set
|
|
725
|
// check if mappings are set
|
|
726
|
if (m_mapper->mapValues() == -1 || m_mapper->mapLabels() == -1)
|
|
726
|
if (m_mapper->mapValues() == -1 || m_mapper->mapLabels() == -1)
|
|
727
|
return;
|
|
727
|
return;
|
|
728
|
|
|
728
|
|
|
729
|
// create the initial slices set
|
|
729
|
// create the initial slices set
|
|
730
|
if (m_mapper->orientation() == Qt::Vertical) {
|
|
730
|
if (m_mapper->orientation() == Qt::Vertical) {
|
|
731
|
if (m_mapper->mapValues() >= m_model->columnCount() || m_mapper->mapLabels() >= m_model->columnCount())
|
|
731
|
if (m_mapper->mapValues() >= m_model->columnCount() || m_mapper->mapLabels() >= m_model->columnCount())
|
|
732
|
return; // mapped columns are not existing
|
|
732
|
return; // mapped columns are not existing
|
|
733
|
|
|
733
|
|
|
734
|
int sliceCount = 0;
|
|
734
|
int sliceCount = 0;
|
|
735
|
if(m_mapper->count() == -1)
|
|
735
|
if(m_mapper->count() == -1)
|
|
736
|
sliceCount = m_model->rowCount() - m_mapper->first();
|
|
736
|
sliceCount = m_model->rowCount() - m_mapper->first();
|
|
737
|
else
|
|
737
|
else
|
|
738
|
sliceCount = qMin(m_mapper->count(), m_model->rowCount() - m_mapper->first());
|
|
738
|
sliceCount = qMin(m_mapper->count(), m_model->rowCount() - m_mapper->first());
|
|
739
|
for (int i = m_mapper->first(); i < m_mapper->first() + sliceCount; i++)
|
|
739
|
for (int i = m_mapper->first(); i < m_mapper->first() + sliceCount; i++)
|
|
740
|
q->append(m_model->data(m_model->index(i, m_mapper->mapValues()), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapper->mapLabels()), Qt::DisplayRole).toString());
|
|
740
|
q->append(m_model->data(m_model->index(i, m_mapper->mapValues()), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapper->mapLabels()), Qt::DisplayRole).toString());
|
|
741
|
} else {
|
|
741
|
} else {
|
|
742
|
if (m_mapper->mapValues() >= m_model->rowCount() || m_mapper->mapLabels() >= m_model->rowCount())
|
|
742
|
if (m_mapper->mapValues() >= m_model->rowCount() || m_mapper->mapLabels() >= m_model->rowCount())
|
|
743
|
return; // mapped columns are not existing
|
|
743
|
return; // mapped columns are not existing
|
|
744
|
|
|
744
|
|
|
745
|
int sliceCount = 0;
|
|
745
|
int sliceCount = 0;
|
|
746
|
if(m_mapper->count() == -1)
|
|
746
|
if(m_mapper->count() == -1)
|
|
747
|
sliceCount = m_model->columnCount() - m_mapper->first();
|
|
747
|
sliceCount = m_model->columnCount() - m_mapper->first();
|
|
748
|
else
|
|
748
|
else
|
|
749
|
sliceCount = qMin(m_mapper->count(), m_model->columnCount() - m_mapper->first());
|
|
749
|
sliceCount = qMin(m_mapper->count(), m_model->columnCount() - m_mapper->first());
|
|
750
|
for (int i = m_mapper->first(); i < m_mapper->first() + sliceCount; i++)
|
|
750
|
for (int i = m_mapper->first(); i < m_mapper->first() + sliceCount; i++)
|
|
751
|
q->append(m_model->data(m_model->index(m_mapper->mapValues(), i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapper->mapLabels(), i), Qt::DisplayRole).toString());
|
|
751
|
q->append(m_model->data(m_model->index(m_mapper->mapValues(), i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapper->mapLabels(), i), Qt::DisplayRole).toString());
|
|
752
|
}
|
|
752
|
}
|
|
753
|
q->setLabelsVisible(true);
|
|
753
|
q->setLabelsVisible(true);
|
|
754
|
}
|
|
754
|
}
|
|
755
|
|
|
755
|
|
|
756
|
bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min)
|
|
756
|
bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min)
|
|
757
|
{
|
|
757
|
{
|
|
758
|
// Remove rounding errors
|
|
758
|
// Remove rounding errors
|
|
759
|
qreal roundedValue = newValue;
|
|
759
|
qreal roundedValue = newValue;
|
|
760
|
if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue))
|
|
760
|
if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue))
|
|
761
|
roundedValue = 0.0;
|
|
761
|
roundedValue = 0.0;
|
|
762
|
else if (qFuzzyCompare(newValue, max))
|
|
762
|
else if (qFuzzyCompare(newValue, max))
|
|
763
|
roundedValue = max;
|
|
763
|
roundedValue = max;
|
|
764
|
else if (qFuzzyCompare(newValue, min))
|
|
764
|
else if (qFuzzyCompare(newValue, min))
|
|
765
|
roundedValue = min;
|
|
765
|
roundedValue = min;
|
|
766
|
|
|
766
|
|
|
767
|
// Check if the position is valid after removing the rounding errors
|
|
767
|
// Check if the position is valid after removing the rounding errors
|
|
768
|
if (roundedValue < min || roundedValue > max) {
|
|
768
|
if (roundedValue < min || roundedValue > max) {
|
|
769
|
qWarning("QPieSeries: Illegal value");
|
|
769
|
qWarning("QPieSeries: Illegal value");
|
|
770
|
return false;
|
|
770
|
return false;
|
|
771
|
}
|
|
771
|
}
|
|
772
|
|
|
772
|
|
|
773
|
if (!qFuzzyIsNull(value - roundedValue)) {
|
|
773
|
if (!qFuzzyIsNull(value - roundedValue)) {
|
|
774
|
value = roundedValue;
|
|
774
|
value = roundedValue;
|
|
775
|
return true;
|
|
775
|
return true;
|
|
776
|
}
|
|
776
|
}
|
|
777
|
|
|
777
|
|
|
778
|
// The change was so small it is considered a rounding error
|
|
778
|
// The change was so small it is considered a rounding error
|
|
779
|
return false;
|
|
779
|
return false;
|
|
780
|
}
|
|
780
|
}
|
|
781
|
|
|
781
|
|
|
782
|
void QPieSeriesPrivate::scaleDomain(Domain& domain)
|
|
782
|
void QPieSeriesPrivate::scaleDomain(Domain& domain)
|
|
783
|
{
|
|
783
|
{
|
|
784
|
Q_UNUSED(domain);
|
|
784
|
Q_UNUSED(domain);
|
|
785
|
#ifndef QT_NO_DEBUG
|
|
785
|
// does not apply to pie
|
|
786
|
qWarning() << __FILE__<<__FUNCTION__<<"not implemented";
|
|
|
|
|
787
|
#endif
|
|
|
|
|
788
|
}
|
|
786
|
}
|
|
789
|
|
|
787
|
|
|
790
|
Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
|
|
788
|
Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
|
|
791
|
{
|
|
789
|
{
|
|
792
|
Q_Q(QPieSeries);
|
|
790
|
Q_Q(QPieSeries);
|
|
793
|
PieChartItem* pie = new PieChartItem(q,presenter);
|
|
791
|
PieChartItem* pie = new PieChartItem(q,presenter);
|
|
794
|
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
|
|
792
|
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
|
|
795
|
presenter->animator()->addAnimation(pie);
|
|
793
|
presenter->animator()->addAnimation(pie);
|
|
796
|
}
|
|
794
|
}
|
|
797
|
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
|
|
795
|
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
|
|
798
|
return pie;
|
|
796
|
return pie;
|
|
799
|
}
|
|
797
|
}
|
|
800
|
|
|
798
|
|
|
801
|
QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
|
|
799
|
QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
|
|
802
|
{
|
|
800
|
{
|
|
803
|
Q_Q(QPieSeries);
|
|
801
|
Q_Q(QPieSeries);
|
|
804
|
QList<LegendMarker*> markers;
|
|
802
|
QList<LegendMarker*> markers;
|
|
805
|
foreach(QPieSlice* slice, q->slices()) {
|
|
803
|
foreach(QPieSlice* slice, q->slices()) {
|
|
806
|
PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
|
|
804
|
PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
|
|
807
|
markers << marker;
|
|
805
|
markers << marker;
|
|
808
|
}
|
|
806
|
}
|
|
809
|
return markers;
|
|
807
|
return markers;
|
|
810
|
}
|
|
808
|
}
|
|
811
|
|
|
809
|
|
|
812
|
#include "moc_qpieseries.cpp"
|
|
810
|
#include "moc_qpieseries.cpp"
|
|
813
|
#include "moc_qpieseries_p.cpp"
|
|
811
|
#include "moc_qpieseries_p.cpp"
|
|
814
|
|
|
812
|
|
|
815
|
QTCOMMERCIALCHART_END_NAMESPACE
|
|
813
|
QTCOMMERCIALCHART_END_NAMESPACE
|