qpieslice.cpp
781 lines
| 19.2 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
|
r203 | #include "qpieslice.h" | ||
Jani Honkonen
|
r1274 | #include "qpieslice_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
|
r952 | This object defines the properties of a single slice in a QPieSeries. | ||
Jani Honkonen
|
r320 | |||
Jani Honkonen
|
r952 | In addition to the obvious value and label properties the user can also control | ||
the visual appearance of a slice. By modifying the visual appearance also means that | ||||
Jani Honkonen
|
r1277 | the user is overriding the default appearance set by the theme. | ||
Jani Honkonen
|
r952 | |||
Jani Honkonen
|
r1277 | Note that if the user has customized slices and theme is changed all customizations will be lost. | ||
To enable user interaction with the pie some basic signals are provided about clicking and hovering. | ||||
Jani Honkonen
|
r314 | */ | ||
Tero Ahola
|
r1470 | /*! | ||
\qmlclass PieSlice QPieSlice | ||||
PieSlice defines the properties of a single slice in a PieSeries. The element should be used | ||||
as a child for a PieSeries. For example: | ||||
\snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | ||||
An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append | ||||
method. | ||||
\snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4 | ||||
In that case you may want to use PieSeries.at or PieSeries.find to access the properties of | ||||
an individual PieSlice instance. | ||||
\snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5 | ||||
\sa PieSeries | ||||
*/ | ||||
Jani Honkonen
|
r1450 | /*! | ||
\enum QPieSlice::LabelPosition | ||||
This enum describes the position of the slice label. | ||||
\value LabelOutside Label is outside the slice with an arm. | ||||
Jani Honkonen
|
r1759 | \value LabelInsideHorizontal Label is centered inside the slice and laid out horizontally. | ||
\value LabelInsideTangential Label is centered inside the slice and rotated to be parallel to the tangential of the slice's arc. | ||||
Marek Rosa
|
r1731 | \value LabelInsideNormal Label is centered inside the slice rotated to be parallel to the normal of the slice's arc. | ||
Jani Honkonen
|
r1450 | */ | ||
Jani Honkonen
|
r314 | /*! | ||
\property QPieSlice::label | ||||
Label of the slice. | ||||
Tero Ahola
|
r1307 | \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor | ||
Jani Honkonen
|
r1277 | */ | ||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty string PieSlice::label | ||||
Label (text) of the slice. | ||||
*/ | ||||
Jani Honkonen
|
r1277 | |||
/*! | ||||
\fn void QPieSlice::labelChanged() | ||||
This signal emitted when the slice label has been changed. | ||||
Tero Ahola
|
r1470 | \sa label | ||
*/ | ||||
/*! | ||||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onLabelChanged() | ||
Tero Ahola
|
r1470 | This signal emitted when the slice label has been changed. | ||
Jani Honkonen
|
r1277 | \sa label | ||
Jani Honkonen
|
r314 | */ | ||
/*! | ||||
\property QPieSlice::value | ||||
Value of the slice. | ||||
Jani Honkonen
|
r1280 | Note that if users sets a negative value it is converted to a positive value. | ||
Jani Honkonen
|
r952 | \sa percentage(), QPieSeries::sum() | ||
Jani Honkonen
|
r314 | */ | ||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty real PieSlice::value | ||||
Value of the slice. Note that if users sets a negative value it is converted to a positive value. | ||||
*/ | ||||
Jani Honkonen
|
r314 | |||
/*! | ||||
Jani Honkonen
|
r1277 | \fn void QPieSlice::valueChanged() | ||
This signal is emitted when the slice value changes. | ||||
Tero Ahola
|
r1470 | \sa value | ||
*/ | ||||
/*! | ||||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onValueChanged() | ||
Tero Ahola
|
r1470 | This signal is emitted when the slice value changes. | ||
Jani Honkonen
|
r1277 | \sa value | ||
*/ | ||||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \property QPieSlice::labelVisible | ||
Tero Ahola
|
r1470 | Defines the visibility of slice label. By default the label is not visible. | ||
Tero Ahola
|
r1307 | \sa label, labelBrush, labelFont, labelArmLengthFactor | ||
Jani Honkonen
|
r314 | */ | ||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty bool PieSlice::labelVisible | ||||
Defines the visibility of slice label. By default the label is not visible. | ||||
*/ | ||||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \fn void QPieSlice::labelVisibleChanged() | ||
This signal emitted when visibility of the slice label has changed. | ||||
Tero Ahola
|
r1470 | \sa labelVisible | ||
*/ | ||||
/*! | ||||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onLabelVisibleChanged() | ||
Tero Ahola
|
r1470 | This signal emitted when visibility of the slice label has changed. | ||
Jani Honkonen
|
r1277 | \sa labelVisible | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \property QPieSlice::exploded | ||
Tero Ahola
|
r1470 | If set to true the slice is "exploded" away from the pie. | ||
\sa explodeDistanceFactor | ||||
*/ | ||||
/*! | ||||
\qmlproperty bool PieSlice::exploded | ||||
If set to true the slice is "exploded" away from the pie. | ||||
Jani Honkonen
|
r1277 | \sa explodeDistanceFactor | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \property QPieSlice::pen | ||
Pen used to draw the slice border. | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \fn void QPieSlice::penChanged() | ||
This signal is emitted when the pen of the slice has changed. | ||||
\sa pen | ||||
*/ | ||||
Jani Honkonen
|
r454 | |||
Jani Honkonen
|
r1338 | /*! | ||
\property QPieSlice::borderColor | ||||
Color used to draw the slice border. | ||||
This is a convenience property for modifying the slice pen. | ||||
\sa pen, borderWidth | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty color PieSlice::borderColor | ||||
Color used to draw the slice border (pen color). | ||||
\sa borderWidth | ||||
*/ | ||||
Jani Honkonen
|
r1338 | |||
/*! | ||||
\fn void QPieSlice::borderColorChanged() | ||||
This signal is emitted when slice border color changes. | ||||
\sa pen, borderColor | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onBorderColorChanged() | ||
Tero Ahola
|
r1470 | This signal is emitted when slice border color changes. | ||
\sa borderColor | ||||
*/ | ||||
Jani Honkonen
|
r1338 | |||
/*! | ||||
\property QPieSlice::borderWidth | ||||
Width of the slice border. | ||||
This is a convenience property for modifying the slice pen. | ||||
\sa pen, borderColor | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty int PieSlice::borderWidth | ||||
Width of the slice border. | ||||
This is a convenience property for modifying the slice pen. | ||||
\sa borderColor | ||||
*/ | ||||
Jani Honkonen
|
r1338 | |||
/*! | ||||
\fn void QPieSlice::borderWidthChanged() | ||||
This signal is emitted when slice border width changes. | ||||
\sa pen, borderWidth | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onBorderWidthChanged() | ||
Tero Ahola
|
r1470 | This signal is emitted when slice border width changes. | ||
\sa borderWidth | ||||
*/ | ||||
Jani Honkonen
|
r1338 | |||
Jani Honkonen
|
r1277 | /*! | ||
\property QPieSlice::brush | ||||
Brush used to draw the slice. | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r289 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \fn void QPieSlice::brushChanged() | ||
This signal is emitted when the brush of the slice has changed. | ||||
\sa brush | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r1338 | /*! | ||
\property QPieSlice::color | ||||
Tero Ahola
|
r1470 | Fill (brush) color of the slice. | ||
Jani Honkonen
|
r1338 | This is a convenience property for modifying the slice brush. | ||
\sa brush | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty color PieSlice::color | ||||
Fill (brush) color of the slice. | ||||
*/ | ||||
Jani Honkonen
|
r1338 | |||
/*! | ||||
\fn void QPieSlice::colorChanged() | ||||
This signal is emitted when slice color changes. | ||||
\sa brush | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onColorChanged() | ||
Tero Ahola
|
r1470 | This signal is emitted when slice color changes. | ||
*/ | ||||
Jani Honkonen
|
r1338 | |||
Jani Honkonen
|
r314 | /*! | ||
Tero Ahola
|
r1307 | \property QPieSlice::labelBrush | ||
Tero Ahola
|
r1470 | Brush used to draw label and label arm of the slice. | ||
Jani Honkonen
|
r1277 | \sa label, labelVisible, labelFont, labelArmLengthFactor | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r314 | /*! | ||
Tero Ahola
|
r1307 | \fn void QPieSlice::labelBrushChanged() | ||
Tero Ahola
|
r1529 | This signal is emitted when the label brush of the slice has changed. | ||
Tero Ahola
|
r1307 | \sa labelBrush | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r1338 | /*! | ||
\property QPieSlice::labelColor | ||||
Color used to draw the slice label. | ||||
This is a convenience property for modifying the slice label brush. | ||||
\sa labelBrush | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty color PieSlice::labelColor | ||||
Color used to draw the slice label. | ||||
*/ | ||||
Jani Honkonen
|
r1338 | |||
/*! | ||||
\fn void QPieSlice::labelColorChanged() | ||||
This signal is emitted when slice label color changes. | ||||
Tero Ahola
|
r1470 | \sa labelColor | ||
*/ | ||||
/*! | ||||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onLabelColorChanged() | ||
Tero Ahola
|
r1470 | This signal is emitted when slice label color changes. | ||
Jani Honkonen
|
r1338 | \sa labelColor | ||
*/ | ||||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \property QPieSlice::labelFont | ||
Font used for drawing label text. | ||||
\sa label, labelVisible, labelArmLengthFactor | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \fn void QPieSlice::labelFontChanged() | ||
This signal is emitted when the label font of the slice has changed. | ||||
\sa labelFont | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r1517 | /*! | ||
\qmlproperty Font PieSlice::labelFont | ||||
Defines the font used for slice label. | ||||
See the \l {Font} {QML Font Element} for detailed documentation. | ||||
\sa labelVisible, labelPosition | ||||
*/ | ||||
Jani Honkonen
|
r1450 | /*! | ||
\property QPieSlice::labelPosition | ||||
Position of the slice label. | ||||
\sa label, labelVisible | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty LabelPosition PieSlice::labelPosition | ||||
Position of the slice label. One of PieSlice.LabelOutside or PieSlice.LabelInside. | ||||
\sa labelVisible | ||||
*/ | ||||
Jani Honkonen
|
r1450 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \property QPieSlice::labelArmLengthFactor | ||
Defines the length of the label arm. | ||||
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. | ||||
Tero Ahola
|
r1470 | By default the arm length is 0.15 | ||
Tero Ahola
|
r1307 | \sa label, labelVisible, labelBrush, labelFont | ||
Jani Honkonen
|
r314 | */ | ||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty real PieSlice::labelArmLengthFactor | ||||
Defines the length of the label arm. | ||||
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. | ||||
By default the arm length is 0.15 | ||||
\sa labelVisible | ||||
*/ | ||||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | \property QPieSlice::explodeDistanceFactor | ||
When the slice is exploded this factor defines how far the slice is exploded away from the pie. | ||||
Jani Honkonen
|
r454 | The factor is relative to pie radius. For example: | ||
Jani Honkonen
|
r1277 | 1.0 means the distance is the same as the radius. | ||
0.5 means the distance is half of the radius. | ||||
Tero Ahola
|
r1470 | By default the distance is is 0.15 | ||
\sa exploded | ||||
*/ | ||||
/*! | ||||
\qmlproperty real PieSlice::explodeDistanceFactor | ||||
When the slice is exploded this factor defines how far the slice is exploded away from the pie. | ||||
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. | ||||
By default the distance is is 0.15 | ||||
Jani Honkonen
|
r1277 | \sa exploded | ||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r203 | |||
Jani Honkonen
|
r1224 | /*! | ||
Jani Honkonen
|
r1277 | \property QPieSlice::percentage | ||
Percentage of the slice compared to the sum of all slices in the series. | ||||
The actual value ranges from 0.0 to 1.0. | ||||
Updated automatically once the slice is added to the series. | ||||
\sa value, QPieSeries::sum | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
\qmlproperty real PieSlice::percentage | ||||
Percentage of the slice compared to the sum of all slices in the series. | ||||
The actual value ranges from 0.0 to 1.0. | ||||
Updated automatically once the slice is added to the series. | ||||
*/ | ||||
Jani Honkonen
|
r1277 | |||
/*! | ||||
\fn void QPieSlice::percentageChanged() | ||||
This signal is emitted when the percentage of the slice has changed. | ||||
Tero Ahola
|
r1470 | \sa percentage | ||
*/ | ||||
/*! | ||||
Tero Ahola
|
r1531 | \qmlsignal void PieSlice::onPercentageChanged() | ||
Tero Ahola
|
r1470 | This signal is emitted when the percentage of the slice has changed. | ||
Jani Honkonen
|
r1277 | \sa percentage | ||
*/ | ||||
/*! | ||||
\property QPieSlice::startAngle | ||||
Defines the starting angle of this slice in the series it belongs to. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Tero Ahola
|
r1470 | Updated automatically once the slice is added to the series. | ||
*/ | ||||
/*! | ||||
\qmlproperty real PieSlice::startAngle | ||||
Defines the starting angle of this slice in the series it belongs to. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r1277 | Updated automatically once the slice is added to the series. | ||
Jani Honkonen
|
r1224 | */ | ||
/*! | ||||
Jani Honkonen
|
r1277 | \fn void QPieSlice::startAngleChanged() | ||
This signal is emitted when the starting angle f the slice has changed. | ||||
Tero Ahola
|
r1470 | \sa startAngle | ||
*/ | ||||
/*! | ||||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onStartAngleChanged() | ||
Tero Ahola
|
r1470 | This signal is emitted when the starting angle f the slice has changed. | ||
Jani Honkonen
|
r1277 | \sa startAngle | ||
*/ | ||||
Jani Honkonen
|
r1224 | |||
Jani Honkonen
|
r1277 | /*! | ||
\property QPieSlice::angleSpan | ||||
Span of the slice in degrees. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Tero Ahola
|
r1470 | Updated automatically once the slice is added to the series. | ||
*/ | ||||
/*! | ||||
\qmlproperty real PieSlice::angleSpan | ||||
Span of the slice in degrees. | ||||
Full pie is 360 degrees where 0 degrees is at 12 a'clock. | ||||
Jani Honkonen
|
r1277 | Updated automatically once the slice is added to the series. | ||
Jani Honkonen
|
r1224 | */ | ||
/*! | ||||
Jani Honkonen
|
r1277 | \fn void QPieSlice::angleSpanChanged() | ||
This signal is emitted when the angle span of the slice has changed. | ||||
\sa angleSpan | ||||
Jani Honkonen
|
r1224 | */ | ||
Tero Ahola
|
r1470 | /*! | ||
Tero Ahola
|
r1531 | \qmlsignal PieSlice::onAngleSpanChanged() | ||
Tero Ahola
|
r1470 | This signal is emitted when the angle span of the slice has changed. | ||
\sa angleSpan | ||||
*/ | ||||
Jani Honkonen
|
r1277 | |||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1009 | \fn void QPieSlice::clicked() | ||
Jani Honkonen
|
r314 | This signal is emitted when user has clicked the slice. | ||
\sa QPieSeries::clicked() | ||||
*/ | ||||
Tero Ahola
|
r1470 | /*! | ||
\qmlsignal PieSlice::onClicked() | ||||
This signal is emitted when user has clicked the slice. | ||||
*/ | ||||
Jani Honkonen
|
r314 | |||
/*! | ||||
Jani Honkonen
|
r1009 | \fn void QPieSlice::hovered(bool state) | ||
This signal is emitted when user has hovered over or away from the slice. | ||||
\a state is true when user has hovered over the slice and false when hover has moved away from the slice. | ||||
\sa QPieSeries::hovered() | ||||
Jani Honkonen
|
r314 | */ | ||
Tero Ahola
|
r1470 | /*! | ||
\qmlsignal PieSlice::onHovered(bool state) | ||||
This signal is emitted when user has hovered over or away from the slice. | ||||
\a state is true when user has hovered over the slice and false when hover has moved away from the slice. | ||||
*/ | ||||
Jani Honkonen
|
r314 | |||
/*! | ||||
Jani Honkonen
|
r1277 | Constructs an empty slice with a \a parent. | ||
\sa QPieSeries::append(), QPieSeries::insert() | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r1277 | QPieSlice::QPieSlice(QObject *parent) | ||
:QObject(parent), | ||||
d_ptr(new QPieSlicePrivate(this)) | ||||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r1277 | |||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r314 | /*! | ||
Jani Honkonen
|
r1277 | Constructs an empty slice with given \a value, \a label and a \a parent. | ||
\sa QPieSeries::append(), QPieSeries::insert() | ||||
Jani Honkonen
|
r314 | */ | ||
Jani Honkonen
|
r1277 | QPieSlice::QPieSlice(QString label, qreal value, QObject *parent) | ||
:QObject(parent), | ||||
d_ptr(new QPieSlicePrivate(this)) | ||||
{ | ||||
Jani Honkonen
|
r1280 | setValue(value); | ||
setLabel(label); | ||||
Jani Honkonen
|
r1277 | } | ||
/*! | ||||
Destroys the slice. | ||||
User should not delete the slice if it has been added to the series. | ||||
*/ | ||||
QPieSlice::~QPieSlice() | ||||
{ | ||||
} | ||||
Jani Honkonen
|
r203 | void QPieSlice::setLabel(QString label) | ||
{ | ||||
Jani Honkonen
|
r1274 | if (d_ptr->m_data.m_labelText != label) { | ||
d_ptr->m_data.m_labelText = label; | ||||
Jani Honkonen
|
r1224 | emit labelChanged(); | ||
Jani Honkonen
|
r203 | } | ||
} | ||||
Jani Honkonen
|
r1277 | QString QPieSlice::label() const | ||
{ | ||||
return d_ptr->m_data.m_labelText; | ||||
} | ||||
void QPieSlice::setValue(qreal value) | ||||
{ | ||||
Jani Honkonen
|
r1280 | value = qAbs(value); // negative values not allowed | ||
Jani Honkonen
|
r1277 | if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) { | ||
d_ptr->m_data.m_value = value; | ||||
emit valueChanged(); | ||||
} | ||||
} | ||||
qreal QPieSlice::value() const | ||||
{ | ||||
return d_ptr->m_data.m_value; | ||||
} | ||||
Jani Honkonen
|
r203 | void QPieSlice::setLabelVisible(bool visible) | ||
{ | ||||
Jani Honkonen
|
r1274 | if (d_ptr->m_data.m_isLabelVisible != visible) { | ||
d_ptr->m_data.m_isLabelVisible = visible; | ||||
emit labelVisibleChanged(); | ||||
Jani Honkonen
|
r203 | } | ||
} | ||||
Jani Honkonen
|
r1277 | bool QPieSlice::isLabelVisible() const | ||
{ | ||||
return d_ptr->m_data.m_isLabelVisible; | ||||
} | ||||
Jani Honkonen
|
r952 | |||
Jani Honkonen
|
r203 | void QPieSlice::setExploded(bool exploded) | ||
{ | ||||
Jani Honkonen
|
r1274 | if (d_ptr->m_data.m_isExploded != exploded) { | ||
d_ptr->m_data.m_isExploded = exploded; | ||||
Tero Ahola
|
r1494 | emit d_ptr->explodedChanged(); | ||
Jani Honkonen
|
r203 | } | ||
} | ||||
Jani Honkonen
|
r1450 | QPieSlice::LabelPosition QPieSlice::labelPosition() | ||
{ | ||||
return d_ptr->m_data.m_labelPosition; | ||||
} | ||||
void QPieSlice::setLabelPosition(LabelPosition position) | ||||
{ | ||||
if (d_ptr->m_data.m_labelPosition != position) { | ||||
d_ptr->m_data.m_labelPosition = position; | ||||
Tero Ahola
|
r1494 | emit d_ptr->labelPositionChanged(); | ||
Jani Honkonen
|
r1450 | } | ||
} | ||||
Jani Honkonen
|
r1277 | bool QPieSlice::isExploded() const | ||
Jani Honkonen
|
r289 | { | ||
Jani Honkonen
|
r1277 | return d_ptr->m_data.m_isExploded; | ||
Jani Honkonen
|
r289 | } | ||
Jani Honkonen
|
r756 | void QPieSlice::setPen(const QPen &pen) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r1274 | d_ptr->setPen(pen, false); | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r1277 | QPen QPieSlice::pen() const | ||
{ | ||||
return d_ptr->m_data.m_slicePen; | ||||
} | ||||
Jani Honkonen
|
r952 | |||
Jani Honkonen
|
r1338 | QColor QPieSlice::borderColor() | ||
{ | ||||
return pen().color(); | ||||
} | ||||
void QPieSlice::setBorderColor(QColor color) | ||||
{ | ||||
QPen p = pen(); | ||||
if (color != p.color()) { | ||||
p.setColor(color); | ||||
setPen(p); | ||||
} | ||||
} | ||||
int QPieSlice::borderWidth() | ||||
{ | ||||
return pen().width(); | ||||
} | ||||
void QPieSlice::setBorderWidth(int width) | ||||
{ | ||||
QPen p = pen(); | ||||
if (width != p.width()) { | ||||
p.setWidth(width); | ||||
setPen(p); | ||||
} | ||||
} | ||||
Jani Honkonen
|
r756 | void QPieSlice::setBrush(const QBrush &brush) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r1274 | d_ptr->setBrush(brush, false); | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r1277 | QBrush QPieSlice::brush() const | ||
{ | ||||
return d_ptr->m_data.m_sliceBrush; | ||||
} | ||||
Jani Honkonen
|
r952 | |||
Jani Honkonen
|
r1338 | QColor QPieSlice::color() | ||
{ | ||||
return brush().color(); | ||||
} | ||||
void QPieSlice::setColor(QColor color) | ||||
{ | ||||
QBrush b = brush(); | ||||
Tero Ahola
|
r1830 | |||
if (b == QBrush()) | ||||
b.setStyle(Qt::SolidPattern); | ||||
b.setColor(color); | ||||
setBrush(b); | ||||
Jani Honkonen
|
r1338 | } | ||
Tero Ahola
|
r1307 | void QPieSlice::setLabelBrush(const QBrush &brush) | ||
Jani Honkonen
|
r203 | { | ||
Tero Ahola
|
r1307 | d_ptr->setLabelBrush(brush, false); | ||
Jani Honkonen
|
r203 | } | ||
Tero Ahola
|
r1307 | QBrush QPieSlice::labelBrush() const | ||
Jani Honkonen
|
r1277 | { | ||
Tero Ahola
|
r1307 | return d_ptr->m_data.m_labelBrush; | ||
Jani Honkonen
|
r1277 | } | ||
Jani Honkonen
|
r952 | |||
Jani Honkonen
|
r1338 | QColor QPieSlice::labelColor() | ||
{ | ||||
return labelBrush().color(); | ||||
} | ||||
void QPieSlice::setLabelColor(QColor color) | ||||
{ | ||||
QBrush b = labelBrush(); | ||||
if (color != b.color()) { | ||||
b.setColor(color); | ||||
setLabelBrush(b); | ||||
} | ||||
} | ||||
Jani Honkonen
|
r469 | void QPieSlice::setLabelFont(const QFont &font) | ||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r1274 | d_ptr->setLabelFont(font, false); | ||
Jani Honkonen
|
r203 | } | ||
Jani Honkonen
|
r1277 | QFont QPieSlice::labelFont() const | ||
{ | ||||
return d_ptr->m_data.m_labelFont; | ||||
} | ||||
Jani Honkonen
|
r454 | |||
void QPieSlice::setLabelArmLengthFactor(qreal factor) | ||||
Jani Honkonen
|
r203 | { | ||
Jani Honkonen
|
r1274 | if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) { | ||
d_ptr->m_data.m_labelArmLengthFactor = factor; | ||||
Tero Ahola
|
r1494 | emit d_ptr->labelArmLengthFactorChanged(); | ||
Jani Honkonen
|
r1274 | } | ||
} | ||||
Jani Honkonen
|
r1277 | qreal QPieSlice::labelArmLengthFactor() const | ||
{ | ||||
return d_ptr->m_data.m_labelArmLengthFactor; | ||||
} | ||||
void QPieSlice::setExplodeDistanceFactor(qreal factor) | ||||
{ | ||||
if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) { | ||||
d_ptr->m_data.m_explodeDistanceFactor = factor; | ||||
Tero Ahola
|
r1494 | emit d_ptr->explodeDistanceFactorChanged(); | ||
Jani Honkonen
|
r1277 | } | ||
} | ||||
qreal QPieSlice::explodeDistanceFactor() const | ||||
{ | ||||
return d_ptr->m_data.m_explodeDistanceFactor; | ||||
} | ||||
qreal QPieSlice::percentage() const | ||||
{ | ||||
return d_ptr->m_data.m_percentage; | ||||
} | ||||
qreal QPieSlice::startAngle() const | ||||
{ | ||||
return d_ptr->m_data.m_startAngle; | ||||
} | ||||
qreal QPieSlice::angleSpan() const | ||||
{ | ||||
return d_ptr->m_data.m_angleSpan; | ||||
} | ||||
Jani Honkonen
|
r1323 | /*! | ||
Returns the series that this slice belongs to. | ||||
\sa QPieSeries::append() | ||||
*/ | ||||
QPieSeries *QPieSlice::series() const | ||||
{ | ||||
return d_ptr->m_series; | ||||
} | ||||
Jani Honkonen
|
r1274 | QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent) | ||
:QObject(parent), | ||||
Jani Honkonen
|
r1323 | q_ptr(parent), | ||
m_series(0) | ||||
Jani Honkonen
|
r1274 | { | ||
} | ||||
QPieSlicePrivate::~QPieSlicePrivate() | ||||
{ | ||||
} | ||||
QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice) | ||||
{ | ||||
return slice->d_func(); | ||||
} | ||||
void QPieSlicePrivate::setPen(const QPen &pen, bool themed) | ||||
{ | ||||
if (m_data.m_slicePen != pen) { | ||||
Jani Honkonen
|
r1338 | |||
QPen oldPen = m_data.m_slicePen; | ||||
Jani Honkonen
|
r1274 | m_data.m_slicePen = pen; | ||
m_data.m_slicePen.setThemed(themed); | ||||
Jani Honkonen
|
r1338 | |||
Jani Honkonen
|
r1274 | emit q_ptr->penChanged(); | ||
Jani Honkonen
|
r1338 | if (oldPen.color() != pen.color()) | ||
emit q_ptr->borderColorChanged(); | ||||
if (oldPen.width() != pen.width()) | ||||
emit q_ptr->borderWidthChanged(); | ||||
Jani Honkonen
|
r1274 | } | ||
} | ||||
void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed) | ||||
{ | ||||
if (m_data.m_sliceBrush != brush) { | ||||
Jani Honkonen
|
r1338 | |||
QBrush oldBrush = m_data.m_sliceBrush; | ||||
Jani Honkonen
|
r1274 | m_data.m_sliceBrush = brush; | ||
m_data.m_sliceBrush.setThemed(themed); | ||||
Jani Honkonen
|
r1338 | |||
Jani Honkonen
|
r1274 | emit q_ptr->brushChanged(); | ||
Jani Honkonen
|
r1338 | if (oldBrush.color() != brush.color()) | ||
emit q_ptr->colorChanged(); | ||||
Jani Honkonen
|
r1274 | } | ||
} | ||||
Tero Ahola
|
r1307 | void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed) | ||
Jani Honkonen
|
r1274 | { | ||
Tero Ahola
|
r1307 | if (m_data.m_labelBrush != brush) { | ||
Jani Honkonen
|
r1338 | |||
QBrush oldBrush = m_data.m_labelBrush; | ||||
Tero Ahola
|
r1307 | m_data.m_labelBrush = brush; | ||
m_data.m_labelBrush.setThemed(themed); | ||||
Jani Honkonen
|
r1338 | |||
Tero Ahola
|
r1307 | emit q_ptr->labelBrushChanged(); | ||
Jani Honkonen
|
r1338 | if (oldBrush.color() != brush.color()) | ||
emit q_ptr->labelColorChanged(); | ||||
Jani Honkonen
|
r1274 | } | ||
} | ||||
void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed) | ||||
{ | ||||
if (m_data.m_labelFont != font) { | ||||
m_data.m_labelFont = font; | ||||
m_data.m_labelFont.setThemed(themed); | ||||
emit q_ptr->labelFontChanged(); | ||||
} | ||||
} | ||||
void QPieSlicePrivate::setPercentage(qreal percentage) | ||||
{ | ||||
if (!qFuzzyIsNull(m_data.m_percentage - percentage)) { | ||||
m_data.m_percentage = percentage; | ||||
emit q_ptr->percentageChanged(); | ||||
} | ||||
} | ||||
void QPieSlicePrivate::setStartAngle(qreal angle) | ||||
{ | ||||
if (!qFuzzyIsNull(m_data.m_startAngle - angle)) { | ||||
m_data.m_startAngle = angle; | ||||
emit q_ptr->startAngleChanged(); | ||||
} | ||||
} | ||||
void QPieSlicePrivate::setAngleSpan(qreal span) | ||||
{ | ||||
if (!qFuzzyIsNull(m_data.m_angleSpan - span)) { | ||||
m_data.m_angleSpan = span; | ||||
emit q_ptr->angleSpanChanged(); | ||||
Jani Honkonen
|
r203 | } | ||
} | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||
Tero Ahola
|
r837 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
#include "moc_qpieslice.cpp" | ||||
Jani Honkonen
|
r1274 | #include "moc_qpieslice_p.cpp" | ||