qpieslice.cpp
375 lines
| 7.3 KiB
| text/x-c
|
CppLexer
|
r203 | #include "qpieslice.h" | ||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
|
r289 | #define DEFAULT_PEN_COLOR Qt::black | ||
#define DEFAULT_BRUSH_COLOR Qt::white | ||||
|
r314 | #define DEFAULT_LABEL_ARM_LENGTH 40 | ||
|
r289 | #define DEFAULT_EXPOLODE_DISTANCE 20 | ||
|
r203 | |||
|
r314 | /*! | ||
\class QPieSlice | ||||
|
r339 | \brief Defines a slice in pie series. | ||
|
r314 | |||
|
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. | ||||
|
r314 | */ | ||
/*! | ||||
\property QPieSlice::label | ||||
Label of the slice. | ||||
*/ | ||||
/*! | ||||
\property QPieSlice::value | ||||
Value of the slice. | ||||
*/ | ||||
/*! | ||||
Constructs an empty slice with a \a parent. | ||||
|
r320 | |||
|
r314 | Note that QPieSeries takes ownership of the slice when it is set/added. | ||
|
r320 | |||
|
r361 | \sa QPieSeries::replace(), QPieSeries::add() | ||
|
r314 | */ | ||
|
r203 | QPieSlice::QPieSlice(QObject *parent) | ||
:QObject(parent), | ||||
m_value(0), | ||||
|
r294 | m_isLabelVisible(false), | ||
|
r203 | m_isExploded(false), | ||
|
r289 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), | ||
|
r203 | m_percentage(0), | ||
|
r355 | m_startAngle(0), | ||
|
r289 | m_angleSpan(0), | ||
|
r203 | m_pen(DEFAULT_PEN_COLOR), | ||
m_brush(DEFAULT_BRUSH_COLOR), | ||||
m_labelPen(DEFAULT_PEN_COLOR), | ||||
m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) | ||||
{ | ||||
} | ||||
|
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. | ||||
|
r361 | \sa QPieSeries::replace(), QPieSeries::add() | ||
|
r314 | */ | ||
QPieSlice::QPieSlice(qreal value, QString label, QObject *parent) | ||||
|
r203 | :QObject(parent), | ||
m_value(value), | ||||
m_label(label), | ||||
|
r314 | m_isLabelVisible(false), | ||
|
r203 | m_isExploded(false), | ||
|
r289 | m_explodeDistance(DEFAULT_EXPOLODE_DISTANCE), | ||
|
r203 | m_percentage(0), | ||
|
r355 | m_startAngle(0), | ||
|
r289 | m_angleSpan(0), | ||
|
r203 | m_pen(DEFAULT_PEN_COLOR), | ||
m_brush(DEFAULT_BRUSH_COLOR), | ||||
m_labelPen(DEFAULT_PEN_COLOR), | ||||
m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) | ||||
{ | ||||
} | ||||
|
r314 | /*! | ||
Destroys the slice. | ||||
User should not delete the slice if it has been added to the series. | ||||
*/ | ||||
|
r203 | QPieSlice::~QPieSlice() | ||
{ | ||||
} | ||||
|
r314 | /*! | ||
Gets the value of the slice. | ||||
Note that all values in the series | ||||
\sa setValue() | ||||
*/ | ||||
|
r203 | qreal QPieSlice::value() const | ||
{ | ||||
return m_value; | ||||
} | ||||
|
r314 | /*! | ||
Gets the label of the slice. | ||||
\sa setLabel() | ||||
*/ | ||||
|
r203 | QString QPieSlice::label() const | ||
{ | ||||
return m_label; | ||||
} | ||||
|
r314 | /*! | ||
Returns true if label is set as visible. | ||||
\sa setLabelVisible() | ||||
*/ | ||||
|
r203 | bool QPieSlice::isLabelVisible() const | ||
{ | ||||
return m_isLabelVisible; | ||||
} | ||||
|
r314 | /*! | ||
Returns true if slice is exloded from the pie. | ||||
\sa setExploded() | ||||
*/ | ||||
|
r203 | bool QPieSlice::isExploded() const | ||
{ | ||||
return m_isExploded; | ||||
} | ||||
|
r314 | /*! | ||
Returns the explosion distance of the slice. | ||||
Default value is 20. | ||||
\sa setExplodeDistance() | ||||
*/ | ||||
|
r289 | qreal QPieSlice::explodeDistance() const | ||
{ | ||||
return m_explodeDistance; | ||||
} | ||||
|
r314 | /*! | ||
Returns the percentage of this slice compared to all slices in the same series. | ||||
|
r320 | |||
|
r314 | Updated internally after the slice is added to the series. | ||
*/ | ||||
|
r203 | qreal QPieSlice::percentage() const | ||
{ | ||||
return m_percentage; | ||||
} | ||||
|
r314 | /*! | ||
Returns the starting angle of this slice in the series it belongs to. | ||||
|
r320 | |||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
|
r314 | Updated internally after the slice is added to the series. | ||
*/ | ||||
|
r355 | qreal QPieSlice::startAngle() const | ||
|
r203 | { | ||
|
r355 | return m_startAngle; | ||
|
r203 | } | ||
|
r314 | /*! | ||
|
r355 | Returns the end angle of this slice in the series it belongs to. | ||
|
r320 | |||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
|
r314 | Updated internally after the slice is added to the series. | ||
*/ | ||||
|
r355 | qreal QPieSlice::endAngle() const | ||
|
r203 | { | ||
|
r355 | return m_startAngle + m_angleSpan; | ||
|
r203 | } | ||
|
r314 | /*! | ||
Returns the pen used to draw this slice. | ||||
\sa setPen() | ||||
*/ | ||||
|
r203 | QPen QPieSlice::pen() const | ||
{ | ||||
return m_pen; | ||||
} | ||||
|
r314 | /*! | ||
Returns the brush used to draw this slice. | ||||
\sa setBrush() | ||||
*/ | ||||
|
r203 | QBrush QPieSlice::brush() const | ||
{ | ||||
return m_brush; | ||||
} | ||||
|
r314 | /*! | ||
Returns the pen used to draw label in this slice. | ||||
\sa setLabelPen() | ||||
*/ | ||||
|
r203 | QPen QPieSlice::labelPen() const | ||
{ | ||||
return m_labelPen; | ||||
} | ||||
|
r314 | /*! | ||
Returns the font used to draw label in this slice. | ||||
\sa setLabelFont() | ||||
*/ | ||||
|
r203 | QFont QPieSlice::labelFont() const | ||
{ | ||||
return m_labelFont; | ||||
} | ||||
|
r314 | /*! | ||
Returns the label arm lenght used in this slice. | ||||
Default value is 40 pixels. | ||||
\sa setLabelArmLength() | ||||
*/ | ||||
|
r289 | qreal QPieSlice::labelArmLength() const | ||
|
r203 | { | ||
return m_labelArmLength; | ||||
} | ||||
|
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() | ||||
*/ | ||||
/*! | ||||
Sets the value of this slice. | ||||
\sa value() | ||||
*/ | ||||
|
r203 | void QPieSlice::setValue(qreal value) | ||
{ | ||||
if (m_value != value) { | ||||
m_value = value; | ||||
emit changed(); | ||||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets the \a label of the slice. | ||||
\sa label() | ||||
*/ | ||||
|
r203 | void QPieSlice::setLabel(QString label) | ||
{ | ||||
if (m_label != label) { | ||||
m_label = label; | ||||
emit changed(); | ||||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets the label \a visible in this slice. | ||||
\sa isLabelVisible(), QPieSeries::setLabelsVisible() | ||||
*/ | ||||
|
r203 | void QPieSlice::setLabelVisible(bool visible) | ||
{ | ||||
if (m_isLabelVisible != visible) { | ||||
m_isLabelVisible = visible; | ||||
emit changed(); | ||||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets this slice \a exploded. | ||||
\sa isExploded(), setExplodeDistance(), QPieSeries::enableClickExplodes() | ||||
*/ | ||||
|
r203 | void QPieSlice::setExploded(bool exploded) | ||
{ | ||||
if (m_isExploded != exploded) { | ||||
m_isExploded = exploded; | ||||
emit changed(); | ||||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets the explosion \a distance of this slice. | ||||
It is the distance the slice is moved away from the pie center. | ||||
\sa explodeDistance(), isExploded(), QPieSeries::enableClickExplodes() | ||||
*/ | ||||
|
r289 | void QPieSlice::setExplodeDistance(qreal distance) | ||
{ | ||||
if (m_explodeDistance != distance) { | ||||
m_explodeDistance = distance; | ||||
emit changed(); | ||||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets the \a pen used to draw this slice. | ||||
Note that applying a theme will override this. | ||||
\sa pen() | ||||
*/ | ||||
|
r203 | void QPieSlice::setPen(QPen pen) | ||
{ | ||||
if (m_pen != pen) { | ||||
m_pen = pen; | ||||
emit changed(); | ||||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets the \a brush used to draw this slice. | ||||
Note that applying a theme will override this. | ||||
\sa brush() | ||||
*/ | ||||
|
r203 | void QPieSlice::setBrush(QBrush brush) | ||
{ | ||||
if (m_brush != brush) { | ||||
m_brush = brush; | ||||
emit changed(); | ||||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets the \a pen used to draw the label in this slice. | ||||
Note that applying a theme will override this. | ||||
\sa labelPen() | ||||
*/ | ||||
void QPieSlice::setLabelPen(QPen pen) | ||||
|
r203 | { | ||
|
r314 | if (m_labelPen != pen) { | ||
m_labelPen = pen; | ||||
|
r203 | emit changed(); | ||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets the \a font used to draw the label in this slice. | ||||
Note that applying a theme will override this. | ||||
\sa labelFont() | ||||
*/ | ||||
void QPieSlice::setLabelFont(QFont font) | ||||
|
r203 | { | ||
|
r314 | if (m_labelFont != font) { | ||
m_labelFont = font; | ||||
|
r203 | emit changed(); | ||
} | ||||
} | ||||
|
r314 | /*! | ||
Sets the label arm \a length used to draw the label in this slice. | ||||
\sa labelArmLength() | ||||
*/ | ||||
void QPieSlice::setLabelArmLength(qreal length) | ||||
|
r203 | { | ||
|
r314 | if (m_labelArmLength != length) { | ||
m_labelArmLength = length; | ||||
|
r203 | emit changed(); | ||
} | ||||
} | ||||
#include "moc_qpieslice.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||