@@ -45,8 +45,8 MainWindow::MainWindow(QWidget *parent) | |||
|
45 | 45 | m_pie->add(1.1, "1"); |
|
46 | 46 | m_pie->add(2.1, "2"); |
|
47 | 47 | m_pie->add(3.0, "3"); |
|
48 |
m_pie->setPosition |
|
|
49 |
m_pie->setSize |
|
|
48 | m_pie->setPiePosition(0.7, 0.7); | |
|
49 | m_pie->setPieSize(0.5); | |
|
50 | 50 | m_chartView->addSeries(m_pie); |
|
51 | 51 | |
|
52 | 52 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize())); |
@@ -70,30 +70,30 public: | |||
|
70 | 70 | m_hPosition->setMinimum(0.0); |
|
71 | 71 | m_hPosition->setMaximum(1.0); |
|
72 | 72 | m_hPosition->setSingleStep(0.1); |
|
73 |
m_hPosition->setValue(m_series-> |
|
|
73 | m_hPosition->setValue(m_series->pieHorizontalPosition()); | |
|
74 | 74 | |
|
75 | 75 | m_vPosition = new QDoubleSpinBox(); |
|
76 | 76 | m_vPosition->setMinimum(0.0); |
|
77 | 77 | m_vPosition->setMaximum(1.0); |
|
78 | 78 | m_vPosition->setSingleStep(0.1); |
|
79 |
m_vPosition->setValue(m_series-> |
|
|
79 | m_vPosition->setValue(m_series->pieVerticalPosition()); | |
|
80 | 80 | |
|
81 | 81 | m_sizeFactor = new QDoubleSpinBox(); |
|
82 | 82 | m_sizeFactor->setMinimum(0.0); |
|
83 | 83 | m_sizeFactor->setMaximum(1.0); |
|
84 | 84 | m_sizeFactor->setSingleStep(0.1); |
|
85 |
m_sizeFactor->setValue(m_series-> |
|
|
85 | m_sizeFactor->setValue(m_series->pieSize()); | |
|
86 | 86 | |
|
87 | 87 | m_startAngle = new QDoubleSpinBox(); |
|
88 | 88 | m_startAngle->setMinimum(0.0); |
|
89 | 89 | m_startAngle->setMaximum(360); |
|
90 |
m_startAngle->setValue(m_series-> |
|
|
90 | m_startAngle->setValue(m_series->pieStartAngle()); | |
|
91 | 91 | m_startAngle->setSingleStep(1); |
|
92 | 92 | |
|
93 | 93 | m_endAngle = new QDoubleSpinBox(); |
|
94 | 94 | m_endAngle->setMinimum(0.0); |
|
95 | 95 | m_endAngle->setMaximum(360); |
|
96 | m_endAngle->setValue(m_series->endAngle()); | |
|
96 | m_endAngle->setValue(m_series->pieEndAngle()); | |
|
97 | 97 | m_endAngle->setSingleStep(1); |
|
98 | 98 | |
|
99 | 99 | QFormLayout* seriesSettingsLayout = new QFormLayout(); |
@@ -153,12 +153,10 public Q_SLOTS: | |||
|
153 | 153 | |
|
154 | 154 | void updateSerieSettings() |
|
155 | 155 | { |
|
156 |
m_series->setPosition |
|
|
157 | ||
|
158 |
m_series->set |
|
|
159 | ||
|
160 | m_series->setStartAngle(m_startAngle->value()); | |
|
161 | m_series->setEndAngle(m_endAngle->value()); | |
|
156 | m_series->setPiePosition(m_vPosition->value(), m_hPosition->value()); | |
|
157 | m_series->setPieSize(m_sizeFactor->value()); | |
|
158 | m_series->setPieStartAngle(m_startAngle->value()); | |
|
159 | m_series->setPieEndAngle(m_endAngle->value()); | |
|
162 | 160 | } |
|
163 | 161 | |
|
164 | 162 | void updateSliceSettings() |
@@ -15,8 +15,8 PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series) | |||
|
15 | 15 | { |
|
16 | 16 | Q_ASSERT(series); |
|
17 | 17 | connect(series, SIGNAL(changed(const QPieSeries::ChangeSet&)), this, SLOT(handleSeriesChanged(const QPieSeries::ChangeSet&))); |
|
18 |
connect(series, SIGNAL( |
|
|
19 |
connect(series, SIGNAL(p |
|
|
18 | connect(series, SIGNAL(piePositionChanged()), this, SLOT(updateGeometry())); | |
|
19 | connect(series, SIGNAL(pieSizeChanged()), this, SLOT(updateGeometry())); | |
|
20 | 20 | |
|
21 | 21 | if (m_series->count()) { |
|
22 | 22 | QPieSeries::ChangeSet changeSet; |
@@ -80,8 +80,8 void PiePresenter::updateGeometry() | |||
|
80 | 80 | |
|
81 | 81 | // find pie center coordinates |
|
82 | 82 | QPointF center; |
|
83 |
center.setX(m_rect.left() + (m_rect.width() * m_series-> |
|
|
84 |
center.setY(m_rect.top() + (m_rect.height() * m_series-> |
|
|
83 | center.setX(m_rect.left() + (m_rect.width() * m_series->pieHorizontalPosition())); | |
|
84 | center.setY(m_rect.top() + (m_rect.height() * m_series->pieVerticalPosition())); | |
|
85 | 85 | |
|
86 | 86 | // find maximum radius for pie |
|
87 | 87 | qreal radius = m_rect.height() / 2; |
@@ -89,7 +89,7 void PiePresenter::updateGeometry() | |||
|
89 | 89 | radius = m_rect.width() / 2; |
|
90 | 90 | |
|
91 | 91 | // apply size factor |
|
92 |
radius *= m_series-> |
|
|
92 | radius *= m_series->pieSize(); | |
|
93 | 93 | |
|
94 | 94 | // update slices |
|
95 | 95 | if (m_pieCenter != center || m_pieRadius != radius) { |
@@ -105,9 +105,9 bool QPieSeries::ChangeSet::isEmpty() const | |||
|
105 | 105 | */ |
|
106 | 106 | QPieSeries::QPieSeries(QObject *parent) : |
|
107 | 107 | QSeries(parent), |
|
108 | m_hPositionFactor(0.5), | |
|
109 | m_vPositionFactor(0.5), | |
|
110 |
m_pieSize |
|
|
108 | m_pieRelativeHorPos(0.5), | |
|
109 | m_pieRelativeVerPos(0.5), | |
|
110 | m_pieRelativeSize(0.7), | |
|
111 | 111 | m_pieStartAngle(0), |
|
112 | 112 | m_pieEndAngle(360), |
|
113 | 113 | m_total(0) |
@@ -254,97 +254,98 QList<QPieSlice*> QPieSeries::slices() const | |||
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | /*! |
|
257 |
Sets the center position of the pie by \a |
|
|
257 | Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition. | |
|
258 | 258 | |
|
259 | 259 | The factors are relative to the chart rectangle where: |
|
260 | 260 | |
|
261 |
\a |
|
|
262 |
\a |
|
|
263 |
\a vertical |
|
|
264 |
\a vertical |
|
|
261 | \a relativeHorizontalPosition 0.0 means the absolute left. | |
|
262 | \a relativeHorizontalPosition 1.0 means the absolute right. | |
|
263 | \a relativeVerticalPosition 0.0 means the absolute top. | |
|
264 | \a relativeVerticalPosition 1.0 means the absolute bottom. | |
|
265 | 265 | |
|
266 |
By default |
|
|
266 | By default both values are 0.5 which puts the pie in the middle of the chart rectangle. | |
|
267 | 267 | |
|
268 |
\sa |
|
|
268 | \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize() | |
|
269 | 269 | */ |
|
270 |
void QPieSeries::setPosition |
|
|
270 | void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition) | |
|
271 | 271 | { |
|
272 | if (horizontalFactor < 0.0 || horizontalFactor > 1.0 || verticalFactor < 0.0 || verticalFactor > 1.0) | |
|
272 | if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 || | |
|
273 | relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0) | |
|
273 | 274 | return; |
|
274 | 275 | |
|
275 | if (m_hPositionFactor != horizontalFactor || m_vPositionFactor != verticalFactor) { | |
|
276 | m_hPositionFactor = horizontalFactor; | |
|
277 | m_vPositionFactor = verticalFactor; | |
|
278 | emit positionChanged(); | |
|
276 | if (m_pieRelativeHorPos != relativeHorizontalPosition || m_pieRelativeVerPos != relativeVerticalPosition) { | |
|
277 | m_pieRelativeHorPos = relativeHorizontalPosition; | |
|
278 | m_pieRelativeVerPos = relativeVerticalPosition; | |
|
279 | emit piePositionChanged(); | |
|
279 | 280 | } |
|
280 | 281 | } |
|
281 | 282 | |
|
282 | 283 | /*! |
|
283 |
Gets the horizontal position |
|
|
284 | Gets the horizontal position of the pie. | |
|
284 | 285 | |
|
285 |
The |
|
|
286 | The returned value is relative to the chart rectangle where: | |
|
286 | 287 | |
|
287 |
|
|
|
288 |
|
|
|
288 | 0.0 means the absolute left. | |
|
289 | 1.0 means the absolute right. | |
|
289 | 290 | |
|
290 |
By default |
|
|
291 | By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle. | |
|
291 | 292 | |
|
292 |
\sa setPosition |
|
|
293 | \sa setPiePosition(), pieVerticalPosition(), setPieSize() | |
|
293 | 294 | */ |
|
294 |
qreal QPieSeries:: |
|
|
295 | qreal QPieSeries::pieHorizontalPosition() const | |
|
295 | 296 | { |
|
296 | return m_hPositionFactor; | |
|
297 | return m_pieRelativeHorPos; | |
|
297 | 298 | } |
|
298 | 299 | |
|
299 | 300 | /*! |
|
300 |
Gets the vertical position |
|
|
301 | Gets the vertical position position of the pie. | |
|
301 | 302 | |
|
302 |
The |
|
|
303 | The returned value is relative to the chart rectangle where: | |
|
303 | 304 | |
|
304 |
|
|
|
305 |
|
|
|
305 | 0.0 means the absolute top. | |
|
306 | 1.0 means the absolute bottom. | |
|
306 | 307 | |
|
307 |
By default |
|
|
308 | By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle. | |
|
308 | 309 | |
|
309 |
\sa setPosition |
|
|
310 | \sa setPiePosition(), pieHorizontalPosition(), setPieSize() | |
|
310 | 311 | */ |
|
311 |
qreal QPieSeries:: |
|
|
312 | qreal QPieSeries::pieVerticalPosition() const | |
|
312 | 313 | { |
|
313 |
return m_ |
|
|
314 | return m_pieRelativeVerPos; | |
|
314 | 315 | } |
|
315 | 316 | |
|
316 | 317 | /*! |
|
317 |
Sets the |
|
|
318 | Sets the relative size of the pie. | |
|
318 | 319 | |
|
319 |
The |
|
|
320 | The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | |
|
320 | 321 | |
|
321 | 322 | Default value is 0.7. |
|
322 | 323 | |
|
323 |
\sa |
|
|
324 | \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | |
|
324 | 325 | */ |
|
325 |
void QPieSeries::setSize |
|
|
326 | void QPieSeries::setPieSize(qreal relativeSize) | |
|
326 | 327 | { |
|
327 | if (sizeFactor < 0.0) | |
|
328 | if (relativeSize < 0.0 || relativeSize > 1.0) | |
|
328 | 329 | return; |
|
329 | 330 | |
|
330 |
if (m_pieSize |
|
|
331 |
m_pieSize |
|
|
332 |
emit |
|
|
331 | if (m_pieRelativeSize != relativeSize) { | |
|
332 | m_pieRelativeSize = relativeSize; | |
|
333 | emit pieSizeChanged(); | |
|
333 | 334 | } |
|
334 | 335 | } |
|
335 | 336 | |
|
336 | 337 | /*! |
|
337 |
Gets the size |
|
|
338 | Gets the relative size of the pie. | |
|
338 | 339 | |
|
339 |
The size |
|
|
340 | The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle. | |
|
340 | 341 | |
|
341 | 342 | Default value is 0.7. |
|
342 | 343 | |
|
343 |
\sa setSize |
|
|
344 | \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition() | |
|
344 | 345 | */ |
|
345 |
qreal QPieSeries:: |
|
|
346 | qreal QPieSeries::pieSize() const | |
|
346 | 347 | { |
|
347 |
return m_pieSize |
|
|
348 | return m_pieRelativeSize; | |
|
348 | 349 | } |
|
349 | 350 | |
|
350 | 351 | |
@@ -353,14 +354,14 qreal QPieSeries::sizeFactor() const | |||
|
353 | 354 | |
|
354 | 355 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
355 | 356 | |
|
356 |
\a |
|
|
357 | \a angle must be less than pie end angle. Default value is 0. | |
|
357 | 358 | |
|
358 |
\sa |
|
|
359 | \sa pieStartAngle(), pieEndAngle(), setPieEndAngle() | |
|
359 | 360 | */ |
|
360 |
void QPieSeries::setStartAngle(qreal |
|
|
361 | void QPieSeries::setPieStartAngle(qreal angle) | |
|
361 | 362 | { |
|
362 |
if ( |
|
|
363 |
m_pieStartAngle = |
|
|
363 | if (angle >= 0 && angle <= 360 && angle != m_pieStartAngle && angle <= m_pieEndAngle) { | |
|
364 | m_pieStartAngle = angle; | |
|
364 | 365 | updateDerivativeData(); |
|
365 | 366 | } |
|
366 | 367 | } |
@@ -370,9 +371,9 void QPieSeries::setStartAngle(qreal startAngle) | |||
|
370 | 371 | |
|
371 | 372 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360. |
|
372 | 373 | |
|
373 | \sa setStartAngle(), endAngle(), setEndAngle() | |
|
374 | \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle() | |
|
374 | 375 | */ |
|
375 |
qreal QPieSeries:: |
|
|
376 | qreal QPieSeries::pieStartAngle() const | |
|
376 | 377 | { |
|
377 | 378 | return m_pieStartAngle; |
|
378 | 379 | } |
@@ -382,14 +383,14 qreal QPieSeries::startAngle() const | |||
|
382 | 383 | |
|
383 | 384 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
384 | 385 | |
|
385 |
\a |
|
|
386 | \a angle must be greater than start angle. | |
|
386 | 387 | |
|
387 |
\sa endAngle(), |
|
|
388 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
|
388 | 389 | */ |
|
389 |
void QPieSeries::setEndAngle(qreal |
|
|
390 | void QPieSeries::setPieEndAngle(qreal angle) | |
|
390 | 391 | { |
|
391 |
if ( |
|
|
392 |
m_pieEndAngle = |
|
|
392 | if (angle >= 0 && angle <= 360 && angle != m_pieEndAngle && angle >= m_pieStartAngle) { | |
|
393 | m_pieEndAngle = angle; | |
|
393 | 394 | updateDerivativeData(); |
|
394 | 395 | } |
|
395 | 396 | } |
@@ -399,9 +400,9 void QPieSeries::setEndAngle(qreal endAngle) | |||
|
399 | 400 | |
|
400 | 401 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
401 | 402 | |
|
402 |
\sa setEndAngle(), |
|
|
403 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
|
403 | 404 | */ |
|
404 | qreal QPieSeries::endAngle() const | |
|
405 | qreal QPieSeries::pieEndAngle() const | |
|
405 | 406 | { |
|
406 | 407 | return m_pieEndAngle; |
|
407 | 408 | } |
@@ -461,19 +462,19 qreal QPieSeries::total() const | |||
|
461 | 462 | */ |
|
462 | 463 | |
|
463 | 464 | /*! |
|
464 |
\fn void QPieSeries:: |
|
|
465 | \fn void QPieSeries::pieSizeChanged() | |
|
465 | 466 | |
|
466 | 467 | This signal is emitted when size factor has been changed. |
|
467 | 468 | |
|
468 |
\sa |
|
|
469 | \sa pieSize(), setPieSize() | |
|
469 | 470 | */ |
|
470 | 471 | |
|
471 | 472 | /*! |
|
472 | \fn void QPieSeries::positionChanged() | |
|
473 | \fn void QPieSeries::piePositionChanged() | |
|
473 | 474 | |
|
474 | 475 | This signal is emitted when position of the pie has been changed. |
|
475 | 476 | |
|
476 |
\sa |
|
|
477 | \sa pieHorizontalPosition(), pieVerticalPosition(), setPiePosition() | |
|
477 | 478 | */ |
|
478 | 479 | |
|
479 | 480 | void QPieSeries::sliceChanged() |
@@ -67,15 +67,15 public: | |||
|
67 | 67 | qreal total() const; |
|
68 | 68 | |
|
69 | 69 | // pie customization |
|
70 |
void setPosition |
|
|
71 |
qreal |
|
|
72 |
qreal |
|
|
73 |
void setSize |
|
|
74 |
qreal |
|
|
75 | void setStartAngle(qreal startAngle); | |
|
76 |
qreal |
|
|
77 | void setEndAngle(qreal endAngle); | |
|
78 | qreal endAngle() const; | |
|
70 | void setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition); | |
|
71 | qreal pieHorizontalPosition() const; | |
|
72 | qreal pieVerticalPosition() const; | |
|
73 | void setPieSize(qreal relativeSize); | |
|
74 | qreal pieSize() const; | |
|
75 | void setPieStartAngle(qreal startAngle); | |
|
76 | qreal pieStartAngle() const; | |
|
77 | void setPieEndAngle(qreal endAngle); | |
|
78 | qreal pieEndAngle() const; | |
|
79 | 79 | |
|
80 | 80 | // convenience function |
|
81 | 81 | QPieSeries& operator << (QPieSlice* slice); |
@@ -94,15 +94,14 public: | |||
|
94 | 94 | // setDropShadows |
|
95 | 95 | |
|
96 | 96 | Q_SIGNALS: |
|
97 | ||
|
98 | void changed(const QPieSeries::ChangeSet& changeSet); | |
|
99 | ||
|
100 | 97 | void clicked(QPieSlice* slice); |
|
101 | 98 | void hoverEnter(QPieSlice* slice); |
|
102 | 99 | void hoverLeave(QPieSlice* slice); |
|
103 | 100 | |
|
104 |
void |
|
|
105 | void positionChanged(); | |
|
101 | void pieSizeChanged(); | |
|
102 | void piePositionChanged(); | |
|
103 | ||
|
104 | void changed(const QPieSeries::ChangeSet& changeSet); // TODO: hide this in PIMPL | |
|
106 | 105 | |
|
107 | 106 | private Q_SLOTS: // TODO: should be private and not visible in the interface at all |
|
108 | 107 | void sliceChanged(); |
@@ -121,9 +120,9 private: | |||
|
121 | 120 | friend class PieSlice; |
|
122 | 121 | |
|
123 | 122 | QList<QPieSlice*> m_slices; |
|
124 | qreal m_hPositionFactor; | |
|
125 | qreal m_vPositionFactor; | |
|
126 |
qreal m_pieSize |
|
|
123 | qreal m_pieRelativeHorPos; | |
|
124 | qreal m_pieRelativeVerPos; | |
|
125 | qreal m_pieRelativeSize; | |
|
127 | 126 | qreal m_pieStartAngle; |
|
128 | 127 | qreal m_pieEndAngle; |
|
129 | 128 | qreal m_total; |
General Comments 0
You need to be logged in to leave comments.
Login now