qpieseries.cpp
672 lines
| 15.1 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
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$ | ||||
** | ||||
****************************************************************************/ | ||||
Jani Honkonen
|
r142 | #include "qpieseries.h" | ||
Michal Klocek
|
r938 | #include "qpieseries_p.h" | ||
Jani Honkonen
|
r818 | #include "qpieslice.h" | ||
Jani Honkonen
|
r1274 | #include "qpieslice_p.h" | ||
Jani Honkonen
|
r818 | #include "pieslicedata_p.h" | ||
Michal Klocek
|
r943 | #include "chartdataset_p.h" | ||
#include "charttheme_p.h" | ||||
#include "chartanimator_p.h" | ||||
Michal Klocek
|
r950 | #include "legendmarker_p.h" | ||
Jani Honkonen
|
r142 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Jani Honkonen
|
r320 | /*! | ||
\class QPieSeries | ||||
\brief Pie series API for QtCommercial Charts | ||||
Jani Honkonen
|
r952 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | ||
Jani Honkonen
|
r320 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | ||
Jani Honkonen
|
r386 | The actual slice size is determined by that relative value. | ||
Jani Honkonen
|
r320 | |||
Jani Honkonen
|
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. | ||||
Jani Honkonen
|
r320 | This can be done by setting a starting angle and angle span to the series. | ||
Jani Honkonen
|
r952 | Full pie is 360 degrees where 0 is at 12 a'clock. | ||
Tero Ahola
|
r995 | |||
See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. | ||||
\image examples_piechart.png | ||||
Jani Honkonen
|
r320 | */ | ||
Marek Rosa
|
r924 | /*! | ||
Jani Honkonen
|
r928 | \property QPieSeries::horizontalPosition | ||
Jani Honkonen
|
r932 | \brief Defines the horizontal position of the pie. | ||
Marek Rosa
|
r924 | |||
Jani Honkonen
|
r932 | The value is a relative value to the chart rectangle where: | ||
\list | ||||
\o 0.0 is the absolute left. | ||||
\o 1.0 is the absolute right. | ||||
\endlist | ||||
Default value is 0.5 (center). | ||||
Jani Honkonen
|
r1279 | |||
\sa verticalPosition | ||||
*/ | ||||
/*! | ||||
\fn void QPieSeries::horizontalPositionChanged() | ||||
Emitted then the horizontal position of the pie has changed. | ||||
\sa horizontalPosition | ||||
Marek Rosa
|
r924 | */ | ||
Jani Honkonen
|
r928 | /*! | ||
\property QPieSeries::verticalPosition | ||||
Jani Honkonen
|
r932 | \brief Defines the vertical position of the pie. | ||
The value is a relative value to the chart rectangle where: | ||||
\list | ||||
\o 0.0 is the absolute top. | ||||
\o 1.0 is the absolute bottom. | ||||
\endlist | ||||
Jani Honkonen
|
r928 | |||
Jani Honkonen
|
r932 | Default value is 0.5 (center). | ||
Jani Honkonen
|
r1279 | |||
\sa horizontalPosition | ||||
*/ | ||||
/*! | ||||
\fn void QPieSeries::verticalPositionChanged() | ||||
Emitted then the vertical position of the pie has changed. | ||||
\sa verticalPosition | ||||
Jani Honkonen
|
r928 | */ | ||
/*! | ||||
\property QPieSeries::size | ||||
Jani Honkonen
|
r932 | \brief Defines the pie size. | ||
Jani Honkonen
|
r928 | |||
Jani Honkonen
|
r932 | The value is a relative value to the chart rectangle where: | ||
\list | ||||
Michal Klocek
|
r974 | \o 0.0 is the minimum size (pie not drawn). | ||
Jani Honkonen
|
r932 | \o 1.0 is the maximum size that can fit the chart. | ||
\endlist | ||||
Default value is 0.7. | ||||
Jani Honkonen
|
r928 | */ | ||
Jani Honkonen
|
r1279 | /*! | ||
\fn void QPieSeries::pieSizeChanged() | ||||
Emitted when the pie size has changed. | ||||
\sa size | ||||
*/ | ||||
Jani Honkonen
|
r928 | /*! | ||
\property QPieSeries::startAngle | ||||
Jani Honkonen
|
r932 | \brief Defines the starting angle of the pie. | ||
Jani Honkonen
|
r928 | |||
Jani Honkonen
|
r932 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||
Jani Honkonen
|
r928 | |||
Jani Honkonen
|
r932 | Default is value is 0. | ||
*/ | ||||
Jani Honkonen
|
r928 | |||
Jani Honkonen
|
r1279 | /*! | ||
\fn void QPieSeries::pieStartAngleChanged() | ||||
Emitted when the starting angle of the pie has changed. | ||||
\sa startAngle | ||||
*/ | ||||
Jani Honkonen
|
r928 | /*! | ||
\property QPieSeries::endAngle | ||||
Jani Honkonen
|
r932 | \brief Defines the ending angle of the pie. | ||
Jani Honkonen
|
r928 | |||
Jani Honkonen
|
r932 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||
Jani Honkonen
|
r928 | |||
Jani Honkonen
|
r932 | Default is value is 360. | ||
*/ | ||||
Jani Honkonen
|
r928 | |||
Jani Honkonen
|
r1279 | /*! | ||
\fn void QPieSeries::pieEndAngleChanged() | ||||
Emitted when the ending angle of the pie has changed. | ||||
\sa endAngle | ||||
*/ | ||||
Jani Honkonen
|
r1224 | /*! | ||
\property QPieSeries::count | ||||
Jani Honkonen
|
r1279 | Number of slices in the series. | ||
*/ | ||||
/*! | ||||
\fn void QPieSeries::countChanged() | ||||
Emitted when the slice count has changed. | ||||
\sa count | ||||
Jani Honkonen
|
r1224 | */ | ||
/*! | ||||
\property QPieSeries::sum | ||||
Jani Honkonen
|
r1279 | |||
Sum of all slices. | ||||
Jani Honkonen
|
r1224 | |||
The series keeps track of the sum of all slices it holds. | ||||
*/ | ||||
Jani Honkonen
|
r1279 | /*! | ||
\fn void QPieSeries::sumChanged() | ||||
Emitted when the sum of all slices has changed. | ||||
\sa sum | ||||
*/ | ||||
/*! | ||||
\fn void QPieSeries::added(QList<QPieSlice*> slices) | ||||
This signal is emitted when \a slices have been added to the series. | ||||
\sa append(), insert() | ||||
*/ | ||||
/*! | ||||
\fn void QPieSeries::removed(QList<QPieSlice*> slices) | ||||
This signal is emitted when \a slices have been removed from the series. | ||||
\sa remove() | ||||
*/ | ||||
/*! | ||||
\fn void QPieSeries::clicked(QPieSlice* slice) | ||||
This signal is emitted when a \a slice has been clicked. | ||||
\sa QPieSlice::clicked() | ||||
*/ | ||||
/*! | ||||
\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() | ||||
*/ | ||||
Marek Rosa
|
r924 | |||
Jani Honkonen
|
r314 | /*! | ||
Constructs a series object which is a child of \a parent. | ||||
*/ | ||||
Jani Honkonen
|
r203 | QPieSeries::QPieSeries(QObject *parent) : | ||
Tero Ahola
|
r988 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r157 | |||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r933 | Destroys the series and its slices. | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | QPieSeries::~QPieSeries() | ||
{ | ||||
Jani Honkonen
|
r669 | // NOTE: d_prt destroyed by QObject | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r320 | Returns QChartSeries::SeriesTypePie. | ||
Jani Honkonen
|
r314 | */ | ||
Michal Klocek
|
r1107 | QAbstractSeries::SeriesType QPieSeries::type() const | ||
Jani Honkonen
|
r314 | { | ||
Tero Ahola
|
r988 | return QAbstractSeries::SeriesTypePie; | ||
Jani Honkonen
|
r314 | } | ||
Jani Honkonen
|
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); | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r933 | Appends an array of \a slices to the series. | ||
Jani Honkonen
|
r314 | Slice ownership is passed to the series. | ||
Jani Honkonen
|
r1224 | |||
Returns true if append was successfull. | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r1104 | bool QPieSeries::append(QList<QPieSlice*> slices) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
r1104 | if (slices.count() == 0) | ||
return false; | ||||
foreach (QPieSlice* s, slices) { | ||||
if (!s || d->m_slices.contains(s)) | ||||
return false; | ||||
Jani Honkonen
|
r1324 | if (s->series()) // already added to some series | ||
return false; | ||||
Jani Honkonen
|
r1104 | } | ||
Jani Honkonen
|
r203 | foreach (QPieSlice* s, slices) { | ||
s->setParent(this); | ||||
Jani Honkonen
|
r1323 | QPieSlicePrivate::fromSlice(s)->m_series = this; | ||
Jani Honkonen
|
r669 | d->m_slices << s; | ||
Jani Honkonen
|
r174 | } | ||
Jani Honkonen
|
r157 | |||
Jani Honkonen
|
r669 | d->updateDerivativeData(); | ||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r203 | foreach (QPieSlice* s, slices) { | ||
Jani Honkonen
|
r1274 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | ||
Jani Honkonen
|
r1009 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | ||
connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r1213 | emit added(slices); | ||
Jani Honkonen
|
r1255 | emit countChanged(); | ||
Jani Honkonen
|
r1104 | |||
return true; | ||||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r415 | /*! | ||
Jani Honkonen
|
r933 | Appends a single \a slice to the series and returns a reference to the series. | ||
Jani Honkonen
|
r415 | Slice ownership is passed to the series. | ||
*/ | ||||
Jani Honkonen
|
r406 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | ||
{ | ||||
Jani Honkonen
|
r796 | append(slice); | ||
Jani Honkonen
|
r406 | return *this; | ||
} | ||||
Jani Honkonen
|
r314 | |||
/*! | ||||
Jani Honkonen
|
r1206 | Appends a single slice to the series with give \a value and \a label. | ||
Jani Honkonen
|
r314 | Slice ownership is passed to the series. | ||
*/ | ||||
Jani Honkonen
|
r1206 | QPieSlice* QPieSeries::append(QString label, qreal value) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r1206 | QPieSlice* slice = new QPieSlice(label, value); | ||
Jani Honkonen
|
r796 | append(slice); | ||
Jani Honkonen
|
r203 | return slice; | ||
} | ||||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r809 | /*! | ||
Inserts a single \a slice to the series before the slice at \a index position. | ||||
Slice ownership is passed to the series. | ||||
Jani Honkonen
|
r1224 | |||
Returns true if insert was successfull. | ||||
Jani Honkonen
|
r809 | */ | ||
Jani Honkonen
|
r1104 | bool QPieSeries::insert(int index, QPieSlice* slice) | ||
Marek Rosa
|
r604 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
r1104 | |||
if (index < 0 || index > d->m_slices.count()) | ||||
return false; | ||||
if (!slice || d->m_slices.contains(slice)) | ||||
return false; | ||||
Jani Honkonen
|
r1324 | if (slice->series()) // already added to some series | ||
return false; | ||||
Marek Rosa
|
r1204 | slice->setParent(this); | ||
Jani Honkonen
|
r1323 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | ||
Marek Rosa
|
r1204 | d->m_slices.insert(index, slice); | ||
Marek Rosa
|
r1195 | |||
Marek Rosa
|
r1204 | d->updateDerivativeData(); | ||
Marek Rosa
|
r604 | |||
Jani Honkonen
|
r1274 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | ||
Marek Rosa
|
r1204 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | ||
connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | ||||
Marek Rosa
|
r604 | |||
Jani Honkonen
|
r1213 | emit added(QList<QPieSlice*>() << slice); | ||
Jani Honkonen
|
r1255 | emit countChanged(); | ||
Jani Honkonen
|
r1104 | |||
return true; | ||||
Marek Rosa
|
r604 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Removes a single \a slice from the series and deletes the slice. | ||||
Jani Honkonen
|
r320 | |||
Jani Honkonen
|
r952 | Do not reference the pointer after this call. | ||
Jani Honkonen
|
r1224 | |||
Returns true if remove was successfull. | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r1104 | bool QPieSeries::remove(QPieSlice* slice) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
r1104 | |||
if (!d->m_slices.removeOne(slice)) | ||||
return false; | ||||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r669 | d->updateDerivativeData(); | ||
Jani Honkonen
|
r174 | |||
Jani Honkonen
|
r1213 | emit removed(QList<QPieSlice*>() << slice); | ||
Jani Honkonen
|
r1255 | emit countChanged(); | ||
Jani Honkonen
|
r621 | |||
Jani Honkonen
|
r203 | delete slice; | ||
Jani Honkonen
|
r823 | slice = 0; | ||
Jani Honkonen
|
r1104 | |||
return true; | ||||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Clears all slices from the series. | ||||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSeries::clear() | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Marek Rosa
|
r1204 | if (d->m_slices.count() == 0) | ||
Jani Honkonen
|
r203 | return; | ||
Jani Honkonen
|
r174 | |||
Marek Rosa
|
r1204 | QList<QPieSlice*> slices = d->m_slices; | ||
foreach (QPieSlice* s, d->m_slices) { | ||||
d->m_slices.removeOne(s); | ||||
delete s; | ||||
} | ||||
Jani Honkonen
|
r566 | |||
Marek Rosa
|
r1204 | d->updateDerivativeData(); | ||
Jani Honkonen
|
r621 | |||
Jani Honkonen
|
r1213 | emit removed(slices); | ||
Jani Honkonen
|
r1255 | emit countChanged(); | ||
Jani Honkonen
|
r142 | } | ||
Jani Honkonen
|
r1279 | /*! | ||
Returns a list of slices that belong to this series. | ||||
*/ | ||||
QList<QPieSlice*> QPieSeries::slices() const | ||||
{ | ||||
Q_D(const QPieSeries); | ||||
return d->m_slices; | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r933 | returns the number of the slices in this series. | ||
Jani Honkonen
|
r314 | */ | ||
int QPieSeries::count() const | ||||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
Marek Rosa
|
r1204 | return d->m_slices.count(); | ||
Jani Honkonen
|
r314 | } | ||
Jani Honkonen
|
r621 | /*! | ||
Returns true is the series is empty. | ||||
*/ | ||||
bool QPieSeries::isEmpty() const | ||||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_slices.isEmpty(); | ||||
Jani Honkonen
|
r621 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1279 | Returns the sum of all slice values in this series. | ||
\sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r1279 | qreal QPieSeries::sum() const | ||
Jani Honkonen
|
r314 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
Jani Honkonen
|
r1279 | return d->m_sum; | ||
Jani Honkonen
|
r314 | } | ||
Tero Ahola
|
r884 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | ||
{ | ||||
Q_D(QPieSeries); | ||||
Jani Honkonen
|
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; | ||||
emit horizontalPositionChanged(); | ||||
} | ||||
Tero Ahola
|
r884 | } | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r1279 | qreal QPieSeries::horizontalPosition() const | ||
{ | ||||
Q_D(const QPieSeries); | ||||
return d->m_pieRelativeHorPos; | ||||
} | ||||
Tero Ahola
|
r884 | void QPieSeries::setVerticalPosition(qreal relativePosition) | ||
Jani Honkonen
|
r142 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
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; | ||||
emit verticalPositionChanged(); | ||||
} | ||||
Jani Honkonen
|
r142 | } | ||
Tero Ahola
|
r884 | qreal QPieSeries::verticalPosition() const | ||
Jani Honkonen
|
r314 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieRelativeVerPos; | ||||
Jani Honkonen
|
r314 | } | ||
Jani Honkonen
|
r498 | void QPieSeries::setPieSize(qreal relativeSize) | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
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; | ||||
emit pieSizeChanged(); | ||||
} | ||||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r314 | |||
Jani Honkonen
|
r498 | qreal QPieSeries::pieSize() const | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieRelativeSize; | ||||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r498 | void QPieSeries::setPieStartAngle(qreal angle) | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
r1207 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | ||
return; | ||||
d->m_pieStartAngle = angle; | ||||
d->updateDerivativeData(); | ||||
Jani Honkonen
|
r1255 | emit pieStartAngleChanged(); | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r498 | qreal QPieSeries::pieStartAngle() const | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieStartAngle; | ||||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r454 | /*! | ||
Sets the end angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r498 | \a angle must be greater than start angle. | ||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r498 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | ||
Jani Honkonen
|
r454 | */ | ||
Jani Honkonen
|
r498 | void QPieSeries::setPieEndAngle(qreal angle) | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
Jani Honkonen
|
r1207 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | ||
return; | ||||
d->m_pieEndAngle = angle; | ||||
d->updateDerivativeData(); | ||||
Jani Honkonen
|
r1255 | emit pieEndAngleChanged(); | ||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r454 | /*! | ||
Returns the end angle of the pie. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r498 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | ||
Jani Honkonen
|
r454 | */ | ||
Jani Honkonen
|
r498 | qreal QPieSeries::pieEndAngle() const | ||
Jani Honkonen
|
r437 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSeries); | ||
return d->m_pieEndAngle; | ||||
Jani Honkonen
|
r437 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Sets the all the slice labels \a visible or invisible. | ||||
Jani Honkonen
|
r1279 | Note that this affects only the current slices in the series. | ||
If user adds a new slice the default label visibility is false. | ||||
Jani Honkonen
|
r314 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | ||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSeries::setLabelsVisible(bool visible) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSeries); | ||
foreach (QPieSlice* s, d->m_slices) | ||||
Jani Honkonen
|
r203 | s->setLabelVisible(visible); | ||
} | ||||
Michal Klocek
|
r938 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
Tero Ahola
|
r988 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | ||
QAbstractSeriesPrivate(parent), | ||||
Michal Klocek
|
r938 | m_pieRelativeHorPos(0.5), | ||
m_pieRelativeVerPos(0.5), | ||||
m_pieRelativeSize(0.7), | ||||
m_pieStartAngle(0), | ||||
m_pieEndAngle(360), | ||||
Marek Rosa
|
r1230 | m_sum(0) | ||
Michal Klocek
|
r938 | { | ||
} | ||||
QPieSeriesPrivate::~QPieSeriesPrivate() | ||||
{ | ||||
} | ||||
void QPieSeriesPrivate::updateDerivativeData() | ||||
{ | ||||
Jani Honkonen
|
r939 | // calculate sum of all slices | ||
Jani Honkonen
|
r1255 | qreal sum = 0; | ||
Michal Klocek
|
r938 | foreach (QPieSlice* s, m_slices) | ||
Jani Honkonen
|
r1255 | sum += s->value(); | ||
if (!qFuzzyIsNull(m_sum - sum)) { | ||||
m_sum = sum; | ||||
emit q_func()->sumChanged(); | ||||
} | ||||
Michal Klocek
|
r938 | |||
// nothing to show.. | ||||
Jani Honkonen
|
r939 | if (qFuzzyIsNull(m_sum)) | ||
Michal Klocek
|
r938 | return; | ||
// update slice attributes | ||||
qreal sliceAngle = m_pieStartAngle; | ||||
qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | ||||
QVector<QPieSlice*> changed; | ||||
foreach (QPieSlice* s, m_slices) { | ||||
Jani Honkonen
|
r1274 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | ||
d->setPercentage(s->value() / m_sum); | ||||
d->setStartAngle(sliceAngle); | ||||
d->setAngleSpan(pieSpan * s->percentage()); | ||||
sliceAngle += s->angleSpan(); | ||||
Michal Klocek
|
r938 | } | ||
Jani Honkonen
|
r1274 | |||
emit calculatedDataChanged(); | ||||
Michal Klocek
|
r938 | } | ||
Jani Honkonen
|
r1274 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | ||
Michal Klocek
|
r938 | { | ||
Jani Honkonen
|
r1274 | return series->d_func(); | ||
Michal Klocek
|
r938 | } | ||
Jani Honkonen
|
r1274 | void QPieSeriesPrivate::sliceValueChanged() | ||
Michal Klocek
|
r938 | { | ||
Jani Honkonen
|
r1009 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | ||
updateDerivativeData(); | ||||
Michal Klocek
|
r938 | } | ||
Jani Honkonen
|
r1009 | void QPieSeriesPrivate::sliceClicked() | ||
Michal Klocek
|
r938 | { | ||
QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | ||||
Q_ASSERT(m_slices.contains(slice)); | ||||
Q_Q(QPieSeries); | ||||
Jani Honkonen
|
r1009 | emit q->clicked(slice); | ||
Michal Klocek
|
r938 | } | ||
Jani Honkonen
|
r1009 | void QPieSeriesPrivate::sliceHovered(bool state) | ||
Michal Klocek
|
r938 | { | ||
QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | ||||
Q_ASSERT(m_slices.contains(slice)); | ||||
Q_Q(QPieSeries); | ||||
Jani Honkonen
|
r1009 | emit q->hovered(slice, state); | ||
Michal Klocek
|
r938 | } | ||
Michal Klocek
|
r943 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | ||
{ | ||||
Q_UNUSED(domain); | ||||
Jani Honkonen
|
r1191 | // does not apply to pie | ||
Michal Klocek
|
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; | ||||
} | ||||
Michal Klocek
|
r938 | |||
Michal Klocek
|
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; | ||||
} | ||||
Jani Honkonen
|
r142 | #include "moc_qpieseries.cpp" | ||
Michal Klocek
|
r938 | #include "moc_qpieseries_p.cpp" | ||
Jani Honkonen
|
r142 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||