##// END OF EJS Templates
Add documentation to pie
Jani Honkonen -
r314:9957a05c8211
parent child
Show More
@@ -7,6 +7,24
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 /*!
11 \enum QPieSeries::PiePosition
12
13 This enum describes pie position within its bounding rectangle
14
15 \value PiePositionMaximized
16 \value PiePositionTopLeft
17 \value PiePositionTopRight
18 \value PiePositionBottomLeft
19 \value PiePositionBottomRight
20 */
21
22 /*!
23 \class QPieSeries
24 \brief QtCommercial charts pie series API.
25
26 */
27
10 28 void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice)
11 29 {
12 30 if (!m_added.contains(slice))
@@ -31,21 +49,37 void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice)
31 49 m_removed << slice;
32 50 }
33 51
52 /*!
53 Returns a list of slices that have been added to the series.
54 \sa QPieSeries::changed()
55 */
34 56 QList<QPieSlice*> QPieSeries::ChangeSet::added() const
35 57 {
36 58 return m_added;
37 59 }
38 60
61 /*!
62 Returns a list of slices that have been changed in the series.
63 \sa QPieSeries::changed()
64 */
39 65 QList<QPieSlice*> QPieSeries::ChangeSet::changed() const
40 66 {
41 67 return m_changed;
42 68 }
43 69
70 /*!
71 Returns a list of slices that have been removed from the series.
72 \sa QPieSeries::changed()
73 */
44 74 QList<QPieSlice*> QPieSeries::ChangeSet::removed() const
45 75 {
46 76 return m_removed;
47 77 }
48 78
79
80 /*!
81 Returns true if there are no added/changed or removed slices in the change set.
82 */
49 83 bool QPieSeries::ChangeSet::isEmpty() const
50 84 {
51 85 if (m_added.count() || m_changed.count() || m_removed.count())
@@ -53,22 +87,39 bool QPieSeries::ChangeSet::isEmpty() const
53 87 return true;
54 88 }
55 89
56
90 /*!
91 Constructs a series object which is a child of \a parent.
92 */
57 93 QPieSeries::QPieSeries(QObject *parent) :
58 94 QChartSeries(parent),
59 95 m_sizeFactor(1.0),
60 96 m_position(PiePositionMaximized),
61 97 m_pieStartAngle(0),
62 m_pieSpan(360)
98 m_pieAngleSpan(360)
63 99 {
64 100
65 101 }
66 102
103 /*!
104 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
105 */
67 106 QPieSeries::~QPieSeries()
68 107 {
69 108
70 109 }
71 110
111 /*!
112 Returns the type of the series which is always QChartSeries::SeriesTypePie.
113 */
114 QChartSeries::QChartSeriesType QPieSeries::type() const
115 {
116 return QChartSeries::SeriesTypePie;
117 }
118
119 /*!
120 Sets an array of values to the series.
121 TO BE REMOVED
122 */
72 123 bool QPieSeries::setData(QList<qreal> data)
73 124 {
74 125 // TODO: remove this function
@@ -79,12 +130,20 bool QPieSeries::setData(QList<qreal> data)
79 130 return true;
80 131 }
81 132
133 /*!
134 Sets an array of \a slices to the series.
135 Slice ownership is passed to the series.
136 */
82 137 void QPieSeries::set(QList<QPieSlice*> slices)
83 138 {
84 139 clear();
85 140 add(slices);
86 141 }
87 142
143 /*!
144 Adds an array of slices to the series.
145 Slice ownership is passed to the series.
146 */
88 147 void QPieSeries::add(QList<QPieSlice*> slices)
89 148 {
90 149 ChangeSet changeSet;
@@ -106,11 +165,20 void QPieSeries::add(QList<QPieSlice*> slices)
106 165 emit changed(changeSet);
107 166 }
108 167
168 /*!
169 Adds a single \a slice to the series.
170 Slice ownership is passed to the series.
171 */
109 172 void QPieSeries::add(QPieSlice* slice)
110 173 {
111 174 add(QList<QPieSlice*>() << slice);
112 175 }
113 176
177
178 /*!
179 Adds a single slice to the series with give \a value and \a name.
180 Slice ownership is passed to the series.
181 */
114 182 QPieSlice* QPieSeries::add(qreal value, QString name)
115 183 {
116 184 QPieSlice* slice = new QPieSlice(value, name);
@@ -118,6 +186,10 QPieSlice* QPieSeries::add(qreal value, QString name)
118 186 return slice;
119 187 }
120 188
189 /*!
190 Removes a single \a slice from the series and deletes the slice.
191 Do not reference this pointer after this call.
192 */
121 193 void QPieSeries::remove(QPieSlice* slice)
122 194 {
123 195 if (!m_slices.removeOne(slice)) {
@@ -135,6 +207,9 void QPieSeries::remove(QPieSlice* slice)
135 207 updateDerivativeData();
136 208 }
137 209
210 /*!
211 Clears all slices from the series.
212 */
138 213 void QPieSeries::clear()
139 214 {
140 215 if (m_slices.count() == 0)
@@ -150,6 +225,28 void QPieSeries::clear()
150 225 updateDerivativeData();
151 226 }
152 227
228 /*!
229 Counts the number of the slices in this series.
230 */
231 int QPieSeries::count() const
232 {
233 return m_slices.count();
234 }
235
236 /*!
237 Returns a list of slices that belong to this series.
238 */
239 QList<QPieSlice*> QPieSeries::slices() const
240 {
241 return m_slices;
242 }
243
244 /*!
245 Sets the size \a factor of the pie. 1.0 is the default value.
246 Note that the pie will not grow beyond its absolute maximum size.
247 In practice its use is to make the pie appear smaller.
248 \sa sizeFactor()
249 */
153 250 void QPieSeries::setSizeFactor(qreal factor)
154 251 {
155 252 if (factor < 0.0)
@@ -161,6 +258,19 void QPieSeries::setSizeFactor(qreal factor)
161 258 }
162 259 }
163 260
261 /*!
262 Gets the size factor of the pie.
263 \sa setSizeFactor()
264 */
265 qreal QPieSeries::sizeFactor() const
266 {
267 return m_sizeFactor;
268 }
269
270 /*!
271 Sets the \a position of the pie within its bounding rectangle.
272 \sa PiePosition, position()
273 */
164 274 void QPieSeries::setPosition(PiePosition position)
165 275 {
166 276 if (m_position != position) {
@@ -169,22 +279,47 void QPieSeries::setPosition(PiePosition position)
169 279 }
170 280 }
171 281
172 void QPieSeries::setSpan(qreal startAngle, qreal span)
282 /*!
283 Gets the position of the pie within its bounding rectangle.
284 \sa PiePosition, setPosition()
285 */
286 QPieSeries::PiePosition QPieSeries::position() const
287 {
288 return m_position;
289 }
290
291
292 /*!
293 Sets the \a startAngle and \a angleSpan of this series.
294
295 \sa
296 */
297 void QPieSeries::setSpan(qreal startAngle, qreal angleSpan)
173 298 {
174 299 if (startAngle >= 0 && startAngle < 360 &&
175 span > 0 && span <= 360) {
300 angleSpan > 0 && angleSpan <= 360) {
176 301 m_pieStartAngle = startAngle;
177 m_pieSpan = span;
302 m_pieAngleSpan = angleSpan;
178 303 updateDerivativeData();
179 304 }
180 305 }
181 306
307 /*!
308 Sets the all the slice labels \a visible or invisible.
309
310 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
311 */
182 312 void QPieSeries::setLabelsVisible(bool visible)
183 313 {
184 314 foreach (QPieSlice* s, m_slices)
185 315 s->setLabelVisible(visible);
186 316 }
187 317
318 /*!
319 Convenience method for exploding a slice when user clicks the pie.
320
321 \sa QPieSlice::isExploded(), QPieSlice::setExploded()
322 */
188 323 void QPieSeries::enableClickExplodes(bool enable)
189 324 {
190 325 if (enable)
@@ -193,6 +328,13 void QPieSeries::enableClickExplodes(bool enable)
193 328 disconnect(this, SLOT(toggleExploded(QPieSlice*)));
194 329 }
195 330
331 /*!
332 Convenience method for highlighting a slice when user hovers over the slice.
333 It changes the slice color to be lighter and shows the label of the slice.
334
335 \sa QPieSlice::isExploded(), QPieSlice::setExploded()
336 */
337
196 338 void QPieSeries::enableHoverHighlight(bool enable)
197 339 {
198 340 if (enable) {
@@ -204,6 +346,55 void QPieSeries::enableHoverHighlight(bool enable)
204 346 }
205 347 }
206 348
349 /*!
350 \fn void QPieSeries::changed(const QPieSeries::ChangeSet& changeSet)
351
352 This signal emitted when something has changed in the series.
353 The \a changeSet contains the details of which slices have been added, changed or removed.
354
355 \sa QPieSeries::ChangeSet, QPieSlice::changed()
356 */
357
358 /*!
359 \fn void QPieSeries::clicked(QPieSlice* slice)
360
361 This signal is emitted when a \a slice has been clicked.
362
363 \sa QPieSlice::clicked()
364 */
365
366 /*!
367 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
368
369 This signal is emitted when user has hovered over a \a slice.
370
371 \sa QPieSlice::hoverEnter()
372 */
373
374 /*!
375 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
376
377 This signal is emitted when user has hovered away from a \a slice.
378
379 \sa QPieSlice::hoverLeave()
380 */
381
382 /*!
383 \fn void QPieSeries::sizeFactorChanged()
384
385 This signal is emitted when size factor has been changed.
386
387 \sa sizeFactor(), setSizeFactor()
388 */
389
390 /*!
391 \fn void QPieSeries::positionChanged()
392
393 This signal is emitted when position of the pie has been changed.
394
395 \sa position(), setPosition()
396 */
397
207 398 void QPieSeries::sliceChanged()
208 399 {
209 400 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
@@ -286,7 +477,7 void QPieSeries::updateDerivativeData()
286 477 changed = true;
287 478 }
288 479
289 qreal sliceSpan = m_pieSpan * percentage;
480 qreal sliceSpan = m_pieAngleSpan * percentage;
290 481 if (s->m_angleSpan != sliceSpan) {
291 482 s->m_angleSpan = sliceSpan;
292 483 changed = true;
@@ -31,6 +31,8 public:
31 31 class ChangeSet
32 32 {
33 33 public:
34
35 // TODO: these should not really be exposed to the public API
34 36 void appendAdded(QPieSlice* slice);
35 37 void appendAdded(QList<QPieSlice*> slices);
36 38 void appendChanged(QPieSlice* slice);
@@ -53,7 +55,7 public:
53 55 virtual ~QPieSeries();
54 56
55 57 public: // from QChartSeries
56 QChartSeriesType type() const { return QChartSeries::SeriesTypePie; }
58 QChartSeriesType type() const;
57 59 virtual bool setData(QList<qreal> data); // TODO: remove this
58 60
59 61 public:
@@ -64,17 +66,17 public:
64 66 void remove(QPieSlice* slice);
65 67 void clear();
66 68
67 int count() const { return m_slices.count(); }
69 int count() const;
68 70
69 QList<QPieSlice*> slices() const { return m_slices; }
71 QList<QPieSlice*> slices() const;
70 72
71 73 void setSizeFactor(qreal sizeFactor);
72 qreal sizeFactor() const { return m_sizeFactor; }
74 qreal sizeFactor() const;
73 75
74 76 void setPosition(PiePosition position);
75 PiePosition position() const { return m_position; }
77 PiePosition position() const;
76 78
77 void setSpan(qreal startAngle, qreal span);
79 void setSpan(qreal startAngle, qreal angleSpan);
78 80
79 81 void setLabelsVisible(bool visible);
80 82 void enableClickExplodes(bool enable);
@@ -123,7 +125,7 private:
123 125 PiePosition m_position;
124 126 qreal m_total;
125 127 qreal m_pieStartAngle;
126 qreal m_pieSpan;
128 qreal m_pieAngleSpan;
127 129 };
128 130
129 131 QTCOMMERCIALCHART_END_NAMESPACE
@@ -4,9 +4,32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 #define DEFAULT_PEN_COLOR Qt::black
6 6 #define DEFAULT_BRUSH_COLOR Qt::white
7 #define DEFAULT_LABEL_ARM_LENGTH 50
7 #define DEFAULT_LABEL_ARM_LENGTH 40
8 8 #define DEFAULT_EXPOLODE_DISTANCE 20
9 9
10 /*!
11 \class QPieSlice
12 \brief QtCommercial charts pie series API.
13
14 */
15
16 /*!
17 \property QPieSlice::label
18
19 Label of the slice.
20 */
21
22 /*!
23 \property QPieSlice::value
24
25 Value of the slice.
26 */
27
28 /*!
29 Constructs an empty slice with a \a parent.
30 Note that QPieSeries takes ownership of the slice when it is set/added.
31 \sa QPieSeries::set(), QPieSeries::add()
32 */
10 33 QPieSlice::QPieSlice(QObject *parent)
11 34 :QObject(parent),
12 35 m_value(0),
@@ -24,11 +47,16 QPieSlice::QPieSlice(QObject *parent)
24 47
25 48 }
26 49
27 QPieSlice::QPieSlice(qreal value, QString label, bool labelVisible, QObject *parent)
50 /*!
51 Constructs an empty slice with given \a value, \a label and a \a parent.
52 Note that QPieSeries takes ownership of the slice when it is set/added.
53 \sa QPieSeries::set(), QPieSeries::add()
54 */
55 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
28 56 :QObject(parent),
29 57 m_value(value),
30 58 m_label(label),
31 m_isLabelVisible(labelVisible),
59 m_isLabelVisible(false),
32 60 m_isExploded(false),
33 61 m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE),
34 62 m_percentage(0),
@@ -42,76 +70,171 QPieSlice::QPieSlice(qreal value, QString label, bool labelVisible, QObject *par
42 70
43 71 }
44 72
73 /*!
74 Destroys the slice.
75 User should not delete the slice if it has been added to the series.
76 */
45 77 QPieSlice::~QPieSlice()
46 78 {
47 79
48 80 }
49 81
82 /*!
83 Gets the value of the slice.
84 Note that all values in the series
85 \sa setValue()
86 */
50 87 qreal QPieSlice::value() const
51 88 {
52 89 return m_value;
53 90 }
54 91
92 /*!
93 Gets the label of the slice.
94 \sa setLabel()
95 */
55 96 QString QPieSlice::label() const
56 97 {
57 98 return m_label;
58 99 }
59 100
101 /*!
102 Returns true if label is set as visible.
103 \sa setLabelVisible()
104 */
60 105 bool QPieSlice::isLabelVisible() const
61 106 {
62 107 return m_isLabelVisible;
63 108 }
64 109
110 /*!
111 Returns true if slice is exloded from the pie.
112 \sa setExploded()
113 */
65 114 bool QPieSlice::isExploded() const
66 115 {
67 116 return m_isExploded;
68 117 }
69 118
119 /*!
120 Returns the explosion distance of the slice.
121 Default value is 20.
122 \sa setExplodeDistance()
123 */
70 124 qreal QPieSlice::explodeDistance() const
71 125 {
72 126 return m_explodeDistance;
73 127 }
74 128
129 /*!
130 Returns the percentage of this slice compared to all slices in the same series.
131 Updated internally after the slice is added to the series.
132 */
75 133 qreal QPieSlice::percentage() const
76 134 {
77 135 return m_percentage;
78 136 }
79 137
138 /*!
139 Returns the starting angle of this slice in the series it belongs to.
140 Updated internally after the slice is added to the series.
141 */
80 142 qreal QPieSlice::angle() const
81 143 {
82 144 return m_angle;
83 145 }
84 146
147 /*!
148 Returns the angle span of this slice in the series it belongs to.
149 Updated internally after the slice is added to the series.
150 */
85 151 qreal QPieSlice::angleSpan() const
86 152 {
87 153 return m_angleSpan;
88 154 }
89 155
156 /*!
157 Returns the pen used to draw this slice.
158 \sa setPen()
159 */
90 160 QPen QPieSlice::pen() const
91 161 {
92 162 return m_pen;
93 163 }
94 164
165 /*!
166 Returns the brush used to draw this slice.
167 \sa setBrush()
168 */
95 169 QBrush QPieSlice::brush() const
96 170 {
97 171 return m_brush;
98 172 }
99 173
174 /*!
175 Returns the pen used to draw label in this slice.
176 \sa setLabelPen()
177 */
100 178 QPen QPieSlice::labelPen() const
101 179 {
102 180 return m_labelPen;
103 181 }
104 182
183 /*!
184 Returns the font used to draw label in this slice.
185 \sa setLabelFont()
186 */
105 187 QFont QPieSlice::labelFont() const
106 188 {
107 189 return m_labelFont;
108 190 }
109 191
192 /*!
193 Returns the label arm lenght used in this slice.
194 Default value is 40 pixels.
195 \sa setLabelArmLength()
196 */
110 197 qreal QPieSlice::labelArmLength() const
111 198 {
112 199 return m_labelArmLength;
113 200 }
114 201
202 /*!
203 \fn void QPieSlice::clicked()
204
205 This signal is emitted when user has clicked the slice.
206
207 \sa QPieSeries::clicked()
208 */
209
210 /*!
211 \fn void QPieSlice::hoverEnter()
212
213 This signal is emitted when user has hovered over the slice.
214
215 \sa QPieSeries::hoverEnter()
216 */
217
218 /*!
219 \fn void QPieSlice::hoverLeave()
220
221 This signal is emitted when user has hovered away from the slice.
222
223 \sa QPieSeries::hoverLeave()
224 */
225
226 /*!
227 \fn void QPieSlice::changed()
228
229 This signal emitted when something has changed in the slice.
230
231 \sa QPieSeries::changed()
232 */
233
234 /*!
235 Sets the value of this slice.
236 \sa value()
237 */
115 238 void QPieSlice::setValue(qreal value)
116 239 {
117 240 if (m_value != value) {
@@ -120,6 +243,10 void QPieSlice::setValue(qreal value)
120 243 }
121 244 }
122 245
246 /*!
247 Sets the \a label of the slice.
248 \sa label()
249 */
123 250 void QPieSlice::setLabel(QString label)
124 251 {
125 252 if (m_label != label) {
@@ -128,6 +255,10 void QPieSlice::setLabel(QString label)
128 255 }
129 256 }
130 257
258 /*!
259 Sets the label \a visible in this slice.
260 \sa isLabelVisible(), QPieSeries::setLabelsVisible()
261 */
131 262 void QPieSlice::setLabelVisible(bool visible)
132 263 {
133 264 if (m_isLabelVisible != visible) {
@@ -136,6 +267,10 void QPieSlice::setLabelVisible(bool visible)
136 267 }
137 268 }
138 269
270 /*!
271 Sets this slice \a exploded.
272 \sa isExploded(), setExplodeDistance(), QPieSeries::enableClickExplodes()
273 */
139 274 void QPieSlice::setExploded(bool exploded)
140 275 {
141 276 if (m_isExploded != exploded) {
@@ -144,6 +279,11 void QPieSlice::setExploded(bool exploded)
144 279 }
145 280 }
146 281
282 /*!
283 Sets the explosion \a distance of this slice.
284 It is the distance the slice is moved away from the pie center.
285 \sa explodeDistance(), isExploded(), QPieSeries::enableClickExplodes()
286 */
147 287 void QPieSlice::setExplodeDistance(qreal distance)
148 288 {
149 289 if (m_explodeDistance != distance) {
@@ -152,6 +292,11 void QPieSlice::setExplodeDistance(qreal distance)
152 292 }
153 293 }
154 294
295 /*!
296 Sets the \a pen used to draw this slice.
297 Note that applying a theme will override this.
298 \sa pen()
299 */
155 300 void QPieSlice::setPen(QPen pen)
156 301 {
157 302 if (m_pen != pen) {
@@ -160,6 +305,11 void QPieSlice::setPen(QPen pen)
160 305 }
161 306 }
162 307
308 /*!
309 Sets the \a brush used to draw this slice.
310 Note that applying a theme will override this.
311 \sa brush()
312 */
163 313 void QPieSlice::setBrush(QBrush brush)
164 314 {
165 315 if (m_brush != brush) {
@@ -168,26 +318,40 void QPieSlice::setBrush(QBrush brush)
168 318 }
169 319 }
170 320
171 void QPieSlice::setLabelFont(QFont font)
321 /*!
322 Sets the \a pen used to draw the label in this slice.
323 Note that applying a theme will override this.
324 \sa labelPen()
325 */
326 void QPieSlice::setLabelPen(QPen pen)
172 327 {
173 if (m_labelFont != font) {
174 m_labelFont = font;
328 if (m_labelPen != pen) {
329 m_labelPen = pen;
175 330 emit changed();
176 331 }
177 332 }
178 333
179 void QPieSlice::setLabelPen(QPen pen)
334 /*!
335 Sets the \a font used to draw the label in this slice.
336 Note that applying a theme will override this.
337 \sa labelFont()
338 */
339 void QPieSlice::setLabelFont(QFont font)
180 340 {
181 if (m_labelPen != pen) {
182 m_labelPen = pen;
341 if (m_labelFont != font) {
342 m_labelFont = font;
183 343 emit changed();
184 344 }
185 345 }
186 346
187 void QPieSlice::setLabelArmLength(qreal len)
347 /*!
348 Sets the label arm \a length used to draw the label in this slice.
349 \sa labelArmLength()
350 */
351 void QPieSlice::setLabelArmLength(qreal length)
188 352 {
189 if (m_labelArmLength != len) {
190 m_labelArmLength = len;
353 if (m_labelArmLength != length) {
354 m_labelArmLength = length;
191 355 emit changed();
192 356 }
193 357 }
@@ -12,12 +12,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 12 class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject
13 13 {
14 14 Q_OBJECT
15 Q_PROPERTY(QString label READ label WRITE setLabel /*NOTIFY dataYChanged*/)
16 Q_PROPERTY(qreal value READ value WRITE setValue /*NOTIFY dataXChanged*/)
15 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY changed)
16 Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed)
17 17
18 18 public:
19 19 QPieSlice(QObject *parent = 0);
20 QPieSlice(qreal value, QString label, bool labelVisible = false, QObject *parent = 0);
20 QPieSlice(qreal value, QString label, QObject *parent = 0);
21 21 virtual ~QPieSlice();
22 22
23 23 // data
General Comments 0
You need to be logged in to leave comments. Login now