qpieseries.cpp
773 lines
| 17.9 KiB
| text/x-c
|
CppLexer
|
r794 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r142 | #include "qpieseries.h" | ||
|
r938 | #include "qpieseries_p.h" | ||
|
r818 | #include "qpieslice.h" | ||
|
r1274 | #include "qpieslice_p.h" | ||
|
r818 | #include "pieslicedata_p.h" | ||
|
r943 | #include "chartdataset_p.h" | ||
#include "charttheme_p.h" | ||||
#include "chartanimator_p.h" | ||||
|
r950 | #include "legendmarker_p.h" | ||
|
r1545 | #include "qabstractaxis.h" | ||
|
r142 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
|
r320 | /*! | ||
\class QPieSeries | ||||
\brief Pie series API for QtCommercial Charts | ||||
|
r952 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | ||
|
r320 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | ||
|
r386 | The actual slice size is determined by that relative value. | ||
|
r320 | |||
|
r952 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 | ||
These relate to the actual chart rectangle. | ||||
By default the pie is defined as a full pie but it can also be a partial pie. | ||||
|
r320 | This can be done by setting a starting angle and angle span to the series. | ||
|
r952 | Full pie is 360 degrees where 0 is at 12 a'clock. | ||
|
r995 | |||
See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. | ||||
\image examples_piechart.png | ||||
|
r320 | */ | ||
|
r1491 | /*! | ||
\qmlclass PieSeries QPieSeries | ||||
|
r1521 | \inherits AbstractSeries | ||
|
r1491 | |||
The following QML shows how to create a simple pie chart. | ||||
|
r1504 | |||
|
r1491 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | ||
|
r1504 | |||
|
r1491 | \beginfloatleft | ||
\image demos_qmlchart1.png | ||||
\endfloat | ||||
\clearfloat | ||||
*/ | ||||
|
r320 | |||
|
r924 | /*! | ||
|
r928 | \property QPieSeries::horizontalPosition | ||
|
r932 | \brief Defines the horizontal position of the pie. | ||
|
r1504 | |||
|
r932 | The value is a relative value to the chart rectangle where: | ||
|
r1504 | |||
|
r932 | \list | ||
\o 0.0 is the absolute left. | ||||
\o 1.0 is the absolute right. | ||||
\endlist | ||||
Default value is 0.5 (center). | ||||
|
r1491 | \sa verticalPosition | ||
*/ | ||||
|
r1504 | |||
|
r1491 | /*! | ||
\qmlproperty real PieSeries::horizontalPosition | ||||
|
r1504 | |||
Defines the horizontal position of the pie. | ||||
The value is a relative value to the chart rectangle where: | ||||
|
r1491 | \list | ||
\o 0.0 is the absolute left. | ||||
\o 1.0 is the absolute right. | ||||
\endlist | ||||
Default value is 0.5 (center). | ||||
|
r1279 | \sa verticalPosition | ||
*/ | ||||
|
r928 | /*! | ||
\property QPieSeries::verticalPosition | ||||
|
r932 | \brief Defines the vertical position of the pie. | ||
|
r1504 | |||
|
r932 | The value is a relative value to the chart rectangle where: | ||
|
r1504 | |||
|
r932 | \list | ||
\o 0.0 is the absolute top. | ||||
\o 1.0 is the absolute bottom. | ||||
\endlist | ||||
Default value is 0.5 (center). | ||||
|
r1491 | \sa horizontalPosition | ||
*/ | ||||
|
r1504 | |||
|
r1491 | /*! | ||
\qmlproperty real PieSeries::verticalPosition | ||||
|
r1504 | |||
Defines the vertical position of the pie. | ||||
The value is a relative value to the chart rectangle where: | ||||
|
r1491 | \list | ||
\o 0.0 is the absolute top. | ||||
\o 1.0 is the absolute bottom. | ||||
\endlist | ||||
Default value is 0.5 (center). | ||||
|
r1279 | \sa horizontalPosition | ||
*/ | ||||
|
r928 | /*! | ||
\property QPieSeries::size | ||||
|
r932 | \brief Defines the pie size. | ||
|
r928 | |||
|
r932 | The value is a relative value to the chart rectangle where: | ||
\list | ||||
|
r974 | \o 0.0 is the minimum size (pie not drawn). | ||
|
r932 | \o 1.0 is the maximum size that can fit the chart. | ||
\endlist | ||||
Default value is 0.7. | ||||
|
r928 | */ | ||
|
r1504 | /*! | ||
\qmlproperty real PieSeries::size | ||||
Defines the pie size. | ||||
The value is a relative value to the chart rectangle where: | ||||
\list | ||||
\o 0.0 is the minimum size (pie not drawn). | ||||
\o 1.0 is the maximum size that can fit the chart. | ||||
\endlist | ||||
Default value is 0.7. | ||||
*/ | ||||
|
r928 | /*! | ||
\property QPieSeries::startAngle | ||||
|
r932 | \brief Defines the starting angle of the pie. | ||
|
r928 | |||
|
r932 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||
|
r928 | |||
|
r932 | Default is value is 0. | ||
*/ | ||||
|
r928 | |||
|
r1504 | /*! | ||
\qmlproperty real PieSeries::startAngle | ||||
Defines the starting angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Default is value is 0. | ||||
*/ | ||||
|
r928 | /*! | ||
\property QPieSeries::endAngle | ||||
|
r932 | \brief Defines the ending angle of the pie. | ||
|
r928 | |||
|
r932 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||
|
r928 | |||
|
r932 | Default is value is 360. | ||
*/ | ||||
|
r928 | |||
|
r1504 | /*! | ||
\qmlproperty real PieSeries::endAngle | ||||
Defines the ending angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Default is value is 360. | ||||
*/ | ||||
|
r1224 | /*! | ||
\property QPieSeries::count | ||||
|
r1279 | Number of slices in the series. | ||
*/ | ||||
|
r1504 | /*! | ||
\qmlproperty int PieSeries::count | ||||
Number of slices in the series. | ||||
*/ | ||||
|
r1279 | /*! | ||
\fn void QPieSeries::countChanged() | ||||
Emitted when the slice count has changed. | ||||
\sa count | ||||
|
r1224 | */ | ||
|
r1531 | /*! | ||
\qmlsignal PieSeries::onCountChanged() | ||||
Emitted when the slice count has changed. | ||||
*/ | ||||
|
r1224 | |||
/*! | ||||
\property QPieSeries::sum | ||||
|
r1279 | |||
Sum of all slices. | ||||
|
r1224 | |||
The series keeps track of the sum of all slices it holds. | ||||
*/ | ||||
|
r1504 | /*! | ||
\qmlproperty real PieSeries::sum | ||||
Sum of all slices. | ||||
The series keeps track of the sum of all slices it holds. | ||||
*/ | ||||
|
r1279 | /*! | ||
\fn void QPieSeries::sumChanged() | ||||
Emitted when the sum of all slices has changed. | ||||
\sa sum | ||||
*/ | ||||
|
r1531 | /*! | ||
\qmlsignal PieSeries::onSumChanged() | ||||
Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | ||||
change value of a slice. | ||||
*/ | ||||
|
r1279 | |||
/*! | ||||
\fn void QPieSeries::added(QList<QPieSlice*> slices) | ||||
This signal is emitted when \a slices have been added to the series. | ||||
\sa append(), insert() | ||||
*/ | ||||
|
r1503 | /*! | ||
|
r1531 | \qmlsignal PieSeries::onAdded(PieSlice slice) | ||
|
r1503 | Emitted when \a slice has been added to the series. | ||
*/ | ||||
|
r1279 | |||
/*! | ||||
\fn void QPieSeries::removed(QList<QPieSlice*> slices) | ||||
This signal is emitted when \a slices have been removed from the series. | ||||
\sa remove() | ||||
*/ | ||||
|
r1503 | /*! | ||
|
r1531 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | ||
|
r1503 | Emitted when \a slice has been removed from the series. | ||
*/ | ||||
|
r1279 | |||
/*! | ||||
\fn void QPieSeries::clicked(QPieSlice* slice) | ||||
This signal is emitted when a \a slice has been clicked. | ||||
\sa QPieSlice::clicked() | ||||
*/ | ||||
|
r1531 | /*! | ||
\qmlsignal PieSeries::onClicked(PieSlice slice) | ||||
This signal is emitted when a \a slice has been clicked. | ||||
*/ | ||||
|
r1279 | |||
/*! | ||||
\fn void QPieSeries::hovered(QPieSlice* slice, bool state) | ||||
This signal is emitted when user has hovered over or away from the \a slice. | ||||
\a state is true when user has hovered over the slice and false when hover has moved away from the slice. | ||||
\sa QPieSlice::hovered() | ||||
*/ | ||||
|
r1531 | /*! | ||
\qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | ||||
This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | ||||
over the slice and false when hover has moved away from the slice. | ||||
*/ | ||||
|
r924 | |||
|
r1521 | /*! | ||
\qmlmethod PieSlice PieSeries::at(int index) | ||||
Returns slice at \a index. Returns null if the index is not valid. | ||||
*/ | ||||
/*! | ||||
\qmlmethod PieSlice PieSeries::find(string label) | ||||
Returns the first slice with \a label. Returns null if the index is not valid. | ||||
*/ | ||||
/*! | ||||
\qmlmethod PieSlice PieSeries::append(string label, real value) | ||||
Adds a new slice with \a label and \a value to the pie. | ||||
*/ | ||||
/*! | ||||
\qmlmethod bool PieSeries::remove(PieSlice slice) | ||||
Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. | ||||
*/ | ||||
/*! | ||||
\qmlmethod PieSeries::clear() | ||||
Removes all slices from the pie. | ||||
*/ | ||||
|
r314 | /*! | ||
Constructs a series object which is a child of \a parent. | ||||
*/ | ||||
|
r203 | QPieSeries::QPieSeries(QObject *parent) : | ||
|
r988 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) | ||
|
r203 | { | ||
|
r157 | |||
|
r203 | } | ||
|
r174 | |||
|
r314 | /*! | ||
|
r933 | Destroys the series and its slices. | ||
|
r314 | */ | ||
|
r203 | QPieSeries::~QPieSeries() | ||
{ | ||||
|
r669 | // NOTE: d_prt destroyed by QObject | ||
|
r203 | } | ||
|
r314 | /*! | ||
|
r320 | Returns QChartSeries::SeriesTypePie. | ||
|
r314 | */ | ||
|
r1107 | QAbstractSeries::SeriesType QPieSeries::type() const | ||
|
r314 | { | ||
|
r988 | return QAbstractSeries::SeriesTypePie; | ||
|
r314 | } | ||
|
r1279 | /*! | ||
Appends a single \a slice to the series. | ||||
Slice ownership is passed to the series. | ||||
Returns true if append was succesfull. | ||||
*/ | ||||
bool QPieSeries::append(QPieSlice* slice) | ||||
{ | ||||
return append(QList<QPieSlice*>() << slice); | ||||
} | ||||
|
r314 | /*! | ||
|
r933 | Appends an array of \a slices to the series. | ||
|
r314 | Slice ownership is passed to the series. | ||
|
r1224 | |||
Returns true if append was successfull. | ||||
|
r314 | */ | ||
|
r1104 | bool QPieSeries::append(QList<QPieSlice*> slices) | ||
|
r203 | { | ||
|
r669 | Q_D(QPieSeries); | ||
|
r1104 | if (slices.count() == 0) | ||
return false; | ||||
foreach (QPieSlice* s, slices) { | ||||
if (!s || d->m_slices.contains(s)) | ||||
return false; | ||||
|
r1324 | if (s->series()) // already added to some series | ||
return false; | ||||
|
r1104 | } | ||
|
r203 | foreach (QPieSlice* s, slices) { | ||
s->setParent(this); | ||||
|
r1323 | QPieSlicePrivate::fromSlice(s)->m_series = this; | ||
|
r669 | d->m_slices << s; | ||
|
r174 | } | ||
|
r157 | |||
|
r669 | d->updateDerivativeData(); | ||
|
r174 | |||
|
r203 | foreach (QPieSlice* s, slices) { | ||
|
r1274 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | ||
|
r1009 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | ||
connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | ||||
|
r203 | } | ||
|
r1213 | emit added(slices); | ||
|
r1255 | emit countChanged(); | ||
|
r1104 | |||
return true; | ||||
|
r142 | } | ||
|
r415 | /*! | ||
|
r933 | Appends a single \a slice to the series and returns a reference to the series. | ||
|
r415 | Slice ownership is passed to the series. | ||
*/ | ||||
|
r406 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | ||
{ | ||||
|
r796 | append(slice); | ||
|
r406 | return *this; | ||
} | ||||
|
r314 | |||
/*! | ||||
|
r1206 | Appends a single slice to the series with give \a value and \a label. | ||
|
r314 | Slice ownership is passed to the series. | ||
*/ | ||||
|
r1206 | QPieSlice* QPieSeries::append(QString label, qreal value) | ||
|
r142 | { | ||
|
r1206 | QPieSlice* slice = new QPieSlice(label, value); | ||
|
r796 | append(slice); | ||
|
r203 | return slice; | ||
} | ||||
|
r174 | |||
|
r809 | /*! | ||
Inserts a single \a slice to the series before the slice at \a index position. | ||||
Slice ownership is passed to the series. | ||||
|
r1224 | |||
Returns true if insert was successfull. | ||||
|
r809 | */ | ||
|
r1104 | bool QPieSeries::insert(int index, QPieSlice* slice) | ||
|
r604 | { | ||
|
r669 | Q_D(QPieSeries); | ||
|
r1104 | |||
if (index < 0 || index > d->m_slices.count()) | ||||
return false; | ||||
if (!slice || d->m_slices.contains(slice)) | ||||
return false; | ||||
|
r1324 | if (slice->series()) // already added to some series | ||
return false; | ||||
|
r1204 | slice->setParent(this); | ||
|
r1323 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | ||
|
r1204 | d->m_slices.insert(index, slice); | ||
|
r1195 | |||
|
r1204 | d->updateDerivativeData(); | ||
|
r604 | |||
|
r1274 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | ||
|
r1204 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | ||
connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | ||||
|
r604 | |||
|
r1213 | emit added(QList<QPieSlice*>() << slice); | ||
|
r1255 | emit countChanged(); | ||
|
r1104 | |||
return true; | ||||
|
r604 | } | ||
|
r314 | /*! | ||
Removes a single \a slice from the series and deletes the slice. | ||||
|
r320 | |||
|
r952 | Do not reference the pointer after this call. | ||
|
r1224 | |||
Returns true if remove was successfull. | ||||
|
r314 | */ | ||
|
r1104 | bool QPieSeries::remove(QPieSlice* slice) | ||
|
r203 | { | ||
|
r669 | Q_D(QPieSeries); | ||
|
r1104 | |||
if (!d->m_slices.removeOne(slice)) | ||||
return false; | ||||
|
r174 | |||
|
r669 | d->updateDerivativeData(); | ||
|
r174 | |||
|
r1213 | emit removed(QList<QPieSlice*>() << slice); | ||
|
r1255 | emit countChanged(); | ||
|
r621 | |||
|
r203 | delete slice; | ||
|
r823 | slice = 0; | ||
|
r1104 | |||
return true; | ||||
|
r142 | } | ||
|
r314 | /*! | ||
Clears all slices from the series. | ||||
*/ | ||||
|
r203 | void QPieSeries::clear() | ||
|
r142 | { | ||
|
r669 | Q_D(QPieSeries); | ||
|
r1204 | if (d->m_slices.count() == 0) | ||
|
r203 | return; | ||
|
r174 | |||
|
r1204 | QList<QPieSlice*> slices = d->m_slices; | ||
foreach (QPieSlice* s, d->m_slices) { | ||||
d->m_slices.removeOne(s); | ||||
delete s; | ||||
} | ||||
|
r566 | |||
|
r1204 | d->updateDerivativeData(); | ||
|
r621 | |||
|
r1213 | emit removed(slices); | ||
|
r1255 | emit countChanged(); | ||
|
r142 | } | ||
|
r1279 | /*! | ||
Returns a list of slices that belong to this series. | ||||
*/ | ||||
QList<QPieSlice*> QPieSeries::slices() const | ||||
{ | ||||
Q_D(const QPieSeries); | ||||
return d->m_slices; | ||||
} | ||||
|
r314 | /*! | ||
|
r933 | returns the number of the slices in this series. | ||
|
r314 | */ | ||
int QPieSeries::count() const | ||||
{ | ||||
|
r669 | Q_D(const QPieSeries); | ||
|
r1204 | return d->m_slices.count(); | ||
|
r314 | } | ||
|
r621 | /*! | ||
Returns true is the series is empty. | ||||
*/ | ||||
bool QPieSeries::isEmpty() const | ||||
{ | ||||
|
r669 | Q_D(const QPieSeries); | ||
return d->m_slices.isEmpty(); | ||||
|
r621 | } | ||
|
r314 | /*! | ||
|
r1279 | Returns the sum of all slice values in this series. | ||
\sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | ||||
|
r314 | */ | ||
|
r1279 | qreal QPieSeries::sum() const | ||
|
r314 | { | ||
|
r669 | Q_D(const QPieSeries); | ||
|
r1279 | return d->m_sum; | ||
|
r314 | } | ||
|
r884 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | ||
{ | ||||
Q_D(QPieSeries); | ||||
|
r1255 | |||
if (relativePosition < 0.0) | ||||
relativePosition = 0.0; | ||||
if (relativePosition > 1.0) | ||||
relativePosition = 1.0; | ||||
if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { | ||||
d->m_pieRelativeHorPos = relativePosition; | ||||
|
r1482 | emit d->horizontalPositionChanged(); | ||
|
r1255 | } | ||
|
r884 | } | ||
|
r454 | |||
|
r1279 | qreal QPieSeries::horizontalPosition() const | ||
{ | ||||
Q_D(const QPieSeries); | ||||
return d->m_pieRelativeHorPos; | ||||
} | ||||
|
r884 | void QPieSeries::setVerticalPosition(qreal relativePosition) | ||
|
r142 | { | ||
|
r669 | Q_D(QPieSeries); | ||
|
r1255 | |||
if (relativePosition < 0.0) | ||||
relativePosition = 0.0; | ||||
if (relativePosition > 1.0) | ||||
relativePosition = 1.0; | ||||
if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { | ||||
d->m_pieRelativeVerPos = relativePosition; | ||||
|
r1482 | emit d->verticalPositionChanged(); | ||
|
r1255 | } | ||
|
r142 | } | ||
|
r884 | qreal QPieSeries::verticalPosition() const | ||
|
r314 | { | ||
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieRelativeVerPos; | ||||
|
r314 | } | ||
|
r498 | void QPieSeries::setPieSize(qreal relativeSize) | ||
|
r437 | { | ||
|
r669 | Q_D(QPieSeries); | ||
|
r1255 | |||
if (relativeSize < 0.0) | ||||
relativeSize = 0.0; | ||||
if (relativeSize > 1.0) | ||||
relativeSize = 1.0; | ||||
if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { | ||||
d->m_pieRelativeSize = relativeSize; | ||||
|
r1482 | emit d->pieSizeChanged(); | ||
|
r1255 | } | ||
|
r437 | } | ||
|
r314 | |||
|
r498 | qreal QPieSeries::pieSize() const | ||
|
r203 | { | ||
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieRelativeSize; | ||||
|
r437 | } | ||
|
r498 | void QPieSeries::setPieStartAngle(qreal angle) | ||
|
r437 | { | ||
|
r669 | Q_D(QPieSeries); | ||
|
r1207 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | ||
return; | ||||
d->m_pieStartAngle = angle; | ||||
d->updateDerivativeData(); | ||||
|
r1482 | emit d->pieStartAngleChanged(); | ||
|
r203 | } | ||
|
r498 | qreal QPieSeries::pieStartAngle() const | ||
|
r437 | { | ||
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieStartAngle; | ||||
|
r437 | } | ||
|
r454 | /*! | ||
Sets the end angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
|
r498 | \a angle must be greater than start angle. | ||
|
r454 | |||
|
r498 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | ||
|
r454 | */ | ||
|
r498 | void QPieSeries::setPieEndAngle(qreal angle) | ||
|
r437 | { | ||
|
r669 | Q_D(QPieSeries); | ||
|
r1207 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | ||
return; | ||||
d->m_pieEndAngle = angle; | ||||
d->updateDerivativeData(); | ||||
|
r1482 | emit d->pieEndAngleChanged(); | ||
|
r437 | } | ||
|
r454 | /*! | ||
Returns the end angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
|
r498 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | ||
|
r454 | */ | ||
|
r498 | qreal QPieSeries::pieEndAngle() const | ||
|
r437 | { | ||
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieEndAngle; | ||||
|
r437 | } | ||
|
r314 | /*! | ||
Sets the all the slice labels \a visible or invisible. | ||||
|
r1279 | Note that this affects only the current slices in the series. | ||
If user adds a new slice the default label visibility is false. | ||||
|
r314 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | ||
*/ | ||||
|
r203 | void QPieSeries::setLabelsVisible(bool visible) | ||
{ | ||||
|
r669 | Q_D(QPieSeries); | ||
foreach (QPieSlice* s, d->m_slices) | ||||
|
r203 | s->setLabelVisible(visible); | ||
} | ||||
|
r938 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
r988 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | ||
QAbstractSeriesPrivate(parent), | ||||
|
r938 | m_pieRelativeHorPos(0.5), | ||
m_pieRelativeVerPos(0.5), | ||||
m_pieRelativeSize(0.7), | ||||
m_pieStartAngle(0), | ||||
m_pieEndAngle(360), | ||||
|
r1230 | m_sum(0) | ||
|
r938 | { | ||
} | ||||
QPieSeriesPrivate::~QPieSeriesPrivate() | ||||
{ | ||||
} | ||||
void QPieSeriesPrivate::updateDerivativeData() | ||||
{ | ||||
|
r939 | // calculate sum of all slices | ||
|
r1255 | qreal sum = 0; | ||
|
r938 | foreach (QPieSlice* s, m_slices) | ||
|
r1255 | sum += s->value(); | ||
if (!qFuzzyIsNull(m_sum - sum)) { | ||||
m_sum = sum; | ||||
emit q_func()->sumChanged(); | ||||
} | ||||
|
r938 | |||
// nothing to show.. | ||||
|
r939 | if (qFuzzyIsNull(m_sum)) | ||
|
r938 | return; | ||
// update slice attributes | ||||
qreal sliceAngle = m_pieStartAngle; | ||||
qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | ||||
QVector<QPieSlice*> changed; | ||||
foreach (QPieSlice* s, m_slices) { | ||||
|
r1274 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | ||
d->setPercentage(s->value() / m_sum); | ||||
d->setStartAngle(sliceAngle); | ||||
d->setAngleSpan(pieSpan * s->percentage()); | ||||
sliceAngle += s->angleSpan(); | ||||
|
r938 | } | ||
|
r1274 | |||
emit calculatedDataChanged(); | ||||
|
r938 | } | ||
|
r1274 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | ||
|
r938 | { | ||
|
r1274 | return series->d_func(); | ||
|
r938 | } | ||
|
r1274 | void QPieSeriesPrivate::sliceValueChanged() | ||
|
r938 | { | ||
|
r1009 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | ||
updateDerivativeData(); | ||||
|
r938 | } | ||
|
r1009 | void QPieSeriesPrivate::sliceClicked() | ||
|
r938 | { | ||
QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | ||||
Q_ASSERT(m_slices.contains(slice)); | ||||
Q_Q(QPieSeries); | ||||
|
r1009 | emit q->clicked(slice); | ||
|
r938 | } | ||
|
r1009 | void QPieSeriesPrivate::sliceHovered(bool state) | ||
|
r938 | { | ||
QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | ||||
Q_ASSERT(m_slices.contains(slice)); | ||||
Q_Q(QPieSeries); | ||||
|
r1009 | emit q->hovered(slice, state); | ||
|
r938 | } | ||
|
r943 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | ||
{ | ||||
Q_UNUSED(domain); | ||||
|
r1191 | // does not apply to pie | ||
|
r943 | } | ||
Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) | ||||
{ | ||||
Q_Q(QPieSeries); | ||||
PieChartItem* pie = new PieChartItem(q,presenter); | ||||
if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | ||||
presenter->animator()->addAnimation(pie); | ||||
} | ||||
presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | ||||
return pie; | ||||
} | ||||
|
r938 | |||
|
r950 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | ||
{ | ||||
Q_Q(QPieSeries); | ||||
QList<LegendMarker*> markers; | ||||
foreach(QPieSlice* slice, q->slices()) { | ||||
PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); | ||||
markers << marker; | ||||
} | ||||
return markers; | ||||
} | ||||
|
r1556 | QAbstractAxis* QPieSeriesPrivate::createAxisX(QObject* parent) | ||
|
r1545 | { | ||
|
r1556 | Q_UNUSED(parent); | ||
|
r1545 | return 0; | ||
} | ||||
|
r1556 | QAbstractAxis* QPieSeriesPrivate::createAxisY(QObject* parent) | ||
|
r1545 | { | ||
|
r1556 | Q_UNUSED(parent); | ||
|
r1545 | return 0; | ||
} | ||||
|
r142 | #include "moc_qpieseries.cpp" | ||
|
r938 | #include "moc_qpieseries_p.cpp" | ||
|
r142 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||