qpieslice.cpp
413 lines
| 8.8 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r203 | #include "qpieslice.h" | ||
Jani Honkonen
|
r669 | #include "qpiesliceprivate_p.h" | ||
Jani Honkonen
|
r618 | #include "qpieseries.h" | ||
Jani Honkonen
|
r669 | #include "qpieseriesprivate_p.h" | ||
Jani Honkonen
|
r203 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Jani Honkonen
|
r314 | /*! | ||
\class QPieSlice | ||||
Jani Honkonen
|
r339 | \brief Defines a slice in pie series. | ||
Jani Honkonen
|
r314 | |||
Jani Honkonen
|
r320 | Holds all the data of a single slice in a QPieSeries and provides the means | ||
to modify slice data and customize the visual appearance of the slice. | ||||
It also provides the means to customize user interaction with the slice by | ||||
providing signals for clicking and hover events. | ||||
Jani Honkonen
|
r314 | */ | ||
/*! | ||||
\property QPieSlice::label | ||||
Label of the slice. | ||||
*/ | ||||
/*! | ||||
\property QPieSlice::value | ||||
Value of the slice. | ||||
*/ | ||||
/*! | ||||
Constructs an empty slice with a \a parent. | ||||
Jani Honkonen
|
r320 | |||
Jani Honkonen
|
r314 | Note that QPieSeries takes ownership of the slice when it is set/added. | ||
Jani Honkonen
|
r320 | |||
Michal Klocek
|
r361 | \sa QPieSeries::replace(), QPieSeries::add() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | QPieSlice::QPieSlice(QObject *parent) | ||
:QObject(parent), | ||||
Jani Honkonen
|
r669 | d_ptr(new QPieSlicePrivate(this)) | ||
Jani Honkonen
|
r203 | { | ||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Constructs an empty slice with given \a value, \a label and a \a parent. | ||||
Note that QPieSeries takes ownership of the slice when it is set/added. | ||||
Michal Klocek
|
r361 | \sa QPieSeries::replace(), QPieSeries::add() | ||
Jani Honkonen
|
r314 | */ | ||
QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) | ||||
Jani Honkonen
|
r203 | :QObject(parent), | ||
Jani Honkonen
|
r669 | d_ptr(new QPieSlicePrivate(this)) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
d->m_data.m_value = value; | ||||
d->m_data.m_labelText = label; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Destroys the slice. | ||||
User should not delete the slice if it has been added to the series. | ||||
*/ | ||||
Jani Honkonen
|
r203 | QPieSlice::~QPieSlice() | ||
{ | ||||
Jani Honkonen
|
r669 | delete d_ptr; | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Gets the value of the slice. | ||||
Note that all values in the series | ||||
\sa setValue() | ||||
*/ | ||||
Jani Honkonen
|
r203 | qreal QPieSlice::value() const | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_value; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Gets the label of the slice. | ||||
\sa setLabel() | ||||
*/ | ||||
Jani Honkonen
|
r203 | QString QPieSlice::label() const | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_labelText; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Returns true if label is set as visible. | ||||
\sa setLabelVisible() | ||||
*/ | ||||
Jani Honkonen
|
r203 | bool QPieSlice::isLabelVisible() const | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
Jani Honkonen
|
r691 | return d->m_data.m_isLabelVisible; | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Returns true if slice is exloded from the pie. | ||||
Jani Honkonen
|
r454 | \sa setExploded(), setExplodeDistanceFactor() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | bool QPieSlice::isExploded() const | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_isExploded; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r454 | Returns the explode distance factor. | ||
The factor is relative to pie radius. For example: | ||||
1.0 means the distance is the same as the radius. | ||||
0.5 means the distance is half of the radius. | ||||
Default value is 0.15. | ||||
\sa setExplodeDistanceFactor() | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r454 | qreal QPieSlice::explodeDistanceFactor() const | ||
Jani Honkonen
|
r289 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_explodeDistanceFactor; | ||||
Jani Honkonen
|
r289 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Returns the percentage of this slice compared to all slices in the same series. | ||||
Jani Honkonen
|
r386 | The returned value ranges from 0 to 1.0. | ||
Jani Honkonen
|
r320 | |||
Jani Honkonen
|
r314 | Updated internally after the slice is added to the series. | ||
*/ | ||||
Jani Honkonen
|
r203 | qreal QPieSlice::percentage() const | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_percentage; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Returns the starting angle of this slice in the series it belongs to. | ||||
Jani Honkonen
|
r320 | |||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r314 | Updated internally after the slice is added to the series. | ||
*/ | ||||
Jani Honkonen
|
r355 | qreal QPieSlice::startAngle() const | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_startAngle; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r355 | Returns the end angle of this slice in the series it belongs to. | ||
Jani Honkonen
|
r320 | |||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r314 | Updated internally after the slice is added to the series. | ||
*/ | ||||
Jani Honkonen
|
r355 | qreal QPieSlice::endAngle() const | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_startAngle + d->m_data.m_angleSpan; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Returns the pen used to draw this slice. | ||||
Jani Honkonen
|
r469 | \sa setSlicePen() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r469 | QPen QPieSlice::slicePen() const | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_slicePen; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Returns the brush used to draw this slice. | ||||
Jani Honkonen
|
r469 | \sa setSliceBrush() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r469 | QBrush QPieSlice::sliceBrush() const | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_sliceBrush; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r714 | Returns the pen used to draw the label in this slice. | ||
Jani Honkonen
|
r469 | \sa setLabelArmPen() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r714 | QPen QPieSlice::labelPen() const | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
Jani Honkonen
|
r714 | return d->m_data.m_labelPen; | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Returns the font used to draw label in this slice. | ||||
\sa setLabelFont() | ||||
*/ | ||||
Jani Honkonen
|
r203 | QFont QPieSlice::labelFont() const | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_labelFont; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r691 | Gets the label arm length factor. | ||
Jani Honkonen
|
r454 | |||
The factor is relative to pie radius. For example: | ||||
1.0 means the length is the same as the radius. | ||||
0.5 means the length is half of the radius. | ||||
Default value is 0.15 | ||||
\sa setLabelArmLengthFactor() | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r454 | qreal QPieSlice::labelArmLengthFactor() const | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(const QPieSlice); | ||
return d->m_data.m_labelArmLengthFactor; | ||||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
\fn void QPieSlice::clicked() | ||||
This signal is emitted when user has clicked the slice. | ||||
\sa QPieSeries::clicked() | ||||
*/ | ||||
/*! | ||||
\fn void QPieSlice::hoverEnter() | ||||
This signal is emitted when user has hovered over the slice. | ||||
\sa QPieSeries::hoverEnter() | ||||
*/ | ||||
/*! | ||||
\fn void QPieSlice::hoverLeave() | ||||
This signal is emitted when user has hovered away from the slice. | ||||
\sa QPieSeries::hoverLeave() | ||||
*/ | ||||
/*! | ||||
\fn void QPieSlice::changed() | ||||
This signal emitted when something has changed in the slice. | ||||
\sa QPieSeries::changed() | ||||
*/ | ||||
/*! | ||||
Jani Honkonen
|
r454 | Sets the \a value of this slice. | ||
Jani Honkonen
|
r314 | \sa value() | ||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSlice::setValue(qreal value) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
if (d->m_data.m_value != value) { | ||||
d->m_data.m_value = value; | ||||
Jani Honkonen
|
r618 | |||
QPieSeries *series = qobject_cast<QPieSeries*>(parent()); | ||||
if (series) | ||||
Jani Honkonen
|
r676 | series->data_ptr()->updateDerivativeData(); // will emit changed() | ||
Jani Honkonen
|
r618 | else | ||
emit changed(); | ||||
Jani Honkonen
|
r203 | } | ||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Sets the \a label of the slice. | ||||
\sa label() | ||||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSlice::setLabel(QString label) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
if (d->m_data.m_labelText != label) { | ||||
d->m_data.m_labelText = label; | ||||
Jani Honkonen
|
r203 | emit changed(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Sets the label \a visible in this slice. | ||||
\sa isLabelVisible(), QPieSeries::setLabelsVisible() | ||||
*/ | ||||
Jani Honkonen
|
r203 | void QPieSlice::setLabelVisible(bool visible) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
Jani Honkonen
|
r691 | if (d->m_data.m_isLabelVisible != visible) { | ||
d->m_data.m_isLabelVisible = visible; | ||||
Jani Honkonen
|
r203 | emit changed(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Sets this slice \a exploded. | ||||
Jani Honkonen
|
r454 | \sa isExploded(), explodeDistanceFactor() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | void QPieSlice::setExploded(bool exploded) | ||
{ | ||||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
if (d->m_data.m_isExploded != exploded) { | ||||
d->m_data.m_isExploded = exploded; | ||||
Jani Honkonen
|
r203 | emit changed(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r454 | Sets the explode distance \a factor. | ||
The factor is relative to pie radius. For example: | ||||
1.0 means the distance is the same as the radius. | ||||
0.5 means the distance is half of the radius. | ||||
Default value is 0.15 | ||||
\sa explodeDistanceFactor() | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r454 | void QPieSlice::setExplodeDistanceFactor(qreal factor) | ||
Jani Honkonen
|
r289 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
if (d->m_data.m_explodeDistanceFactor != factor) { | ||||
d->m_data.m_explodeDistanceFactor = factor; | ||||
Jani Honkonen
|
r289 | emit changed(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Sets the \a pen used to draw this slice. | ||||
Note that applying a theme will override this. | ||||
Jani Honkonen
|
r469 | \sa slicePen() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r469 | void QPieSlice::setSlicePen(const QPen &pen) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
if (d->m_data.m_slicePen != pen) { | ||||
d->m_data.m_slicePen = pen; | ||||
Jani Honkonen
|
r691 | d->m_data.m_slicePen.setThemed(false); | ||
Jani Honkonen
|
r203 | emit changed(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Sets the \a brush used to draw this slice. | ||||
Note that applying a theme will override this. | ||||
Jani Honkonen
|
r469 | \sa sliceBrush() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r469 | void QPieSlice::setSliceBrush(const QBrush &brush) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
if (d->m_data.m_sliceBrush != brush) { | ||||
d->m_data.m_sliceBrush = brush; | ||||
Jani Honkonen
|
r691 | d->m_data.m_sliceBrush.setThemed(false); | ||
Jani Honkonen
|
r203 | emit changed(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r714 | Sets the \a pen used to draw the label in this slice. | ||
Jani Honkonen
|
r314 | Note that applying a theme will override this. | ||
Jani Honkonen
|
r469 | \sa labelArmPen() | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r714 | void QPieSlice::setLabelPen(const QPen &pen) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
Jani Honkonen
|
r714 | if (d->m_data.m_labelPen != pen) { | ||
d->m_data.m_labelPen = pen; | ||||
d->m_data.m_labelPen.setThemed(false); | ||||
Jani Honkonen
|
r203 | emit changed(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Sets the \a font used to draw the label in this slice. | ||||
Note that applying a theme will override this. | ||||
\sa labelFont() | ||||
*/ | ||||
Jani Honkonen
|
r469 | void QPieSlice::setLabelFont(const QFont &font) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
if (d->m_data.m_labelFont != font) { | ||||
d->m_data.m_labelFont = font; | ||||
Jani Honkonen
|
r691 | d->m_data.m_labelFont.setThemed(false); | ||
Jani Honkonen
|
r203 | emit changed(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r691 | Sets the label arm length \a factor. | ||
Jani Honkonen
|
r454 | |||
The factor is relative to pie radius. For example: | ||||
1.0 means the length is the same as the radius. | ||||
0.5 means the length is half of the radius. | ||||
Default value is 0.15 | ||||
\sa labelArmLengthFactor() | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r454 | void QPieSlice::setLabelArmLengthFactor(qreal factor) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r669 | Q_D(QPieSlice); | ||
if (d->m_data.m_labelArmLengthFactor != factor) { | ||||
d->m_data.m_labelArmLengthFactor = factor; | ||||
Jani Honkonen
|
r203 | emit changed(); | ||
} | ||||
} | ||||
#include "moc_qpieslice.cpp" | ||||
Jani Honkonen
|
r676 | #include "moc_qpiesliceprivate_p.cpp" | ||
Jani Honkonen
|
r203 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||