##// END OF EJS Templates
Add animations to pie. Works but has some visual issues when adding slices.
Add animations to pie. Works but has some visual issues when adding slices.

File last commit:

r618:249071e508d1
r618:249071e508d1
Show More
qpieslice.cpp
407 lines | 8.4 KiB | text/x-c | CppLexer
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 #include "qpieslice.h"
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618 #include "qpieseries.h"
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 #define DEFAULT_PEN_COLOR Qt::black
#define DEFAULT_BRUSH_COLOR Qt::white
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 #define DEFAULT_LABEL_ARM_LENGTH_FACTOR 0.15
#define DEFAULT_EXPOLODE_DISTANCE_FACTOR 0.15
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203
Jani Honkonen
Add documentation to pie
r314 /*!
\class QPieSlice
Jani Honkonen
Typo fix for slice doc
r339 \brief Defines a slice in pie series.
Jani Honkonen
Add documentation to pie
r314
Jani Honkonen
More documentation for pie
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
Add documentation to pie
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
More documentation for pie
r320
Jani Honkonen
Add documentation to pie
r314 Note that QPieSeries takes ownership of the slice when it is set/added.
Jani Honkonen
More documentation for pie
r320
Michal Klocek
minor. doc fix for pieslice
r361 \sa QPieSeries::replace(), QPieSeries::add()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 QPieSlice::QPieSlice(QObject *parent)
:QObject(parent),
m_value(0),
Jani Honkonen
Hide slice label by default
r294 m_isLabelVisible(false),
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 m_isExploded(false),
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 m_explodeDistanceFactor(DEFAULT_EXPOLODE_DISTANCE_FACTOR),
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 m_percentage(0),
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 m_startAngle(0),
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 m_angleSpan(0),
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 m_slicePen(DEFAULT_PEN_COLOR),
m_sliceBrush(DEFAULT_BRUSH_COLOR),
m_labelArmPen(DEFAULT_PEN_COLOR),
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 m_labelArmLengthFactor(DEFAULT_LABEL_ARM_LENGTH_FACTOR)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
}
Jani Honkonen
Add documentation to pie
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
minor. doc fix for pieslice
r361 \sa QPieSeries::replace(), QPieSeries::add()
Jani Honkonen
Add documentation to pie
r314 */
QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 :QObject(parent),
m_value(value),
m_label(label),
Jani Honkonen
Add documentation to pie
r314 m_isLabelVisible(false),
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 m_isExploded(false),
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 m_explodeDistanceFactor(DEFAULT_EXPOLODE_DISTANCE_FACTOR),
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 m_percentage(0),
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 m_startAngle(0),
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 m_angleSpan(0),
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 m_slicePen(DEFAULT_PEN_COLOR),
m_sliceBrush(DEFAULT_BRUSH_COLOR),
m_labelArmPen(DEFAULT_PEN_COLOR),
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 m_labelArmLengthFactor(DEFAULT_LABEL_ARM_LENGTH_FACTOR)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
}
Jani Honkonen
Add documentation to pie
r314 /*!
Destroys the slice.
User should not delete the slice if it has been added to the series.
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 QPieSlice::~QPieSlice()
{
}
Jani Honkonen
Add documentation to pie
r314 /*!
Gets the value of the slice.
Note that all values in the series
\sa setValue()
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 qreal QPieSlice::value() const
{
return m_value;
}
Jani Honkonen
Add documentation to pie
r314 /*!
Gets the label of the slice.
\sa setLabel()
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 QString QPieSlice::label() const
{
return m_label;
}
Jani Honkonen
Add documentation to pie
r314 /*!
Returns true if label is set as visible.
\sa setLabelVisible()
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 bool QPieSlice::isLabelVisible() const
{
return m_isLabelVisible;
}
Jani Honkonen
Add documentation to pie
r314 /*!
Returns true if slice is exloded from the pie.
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 \sa setExploded(), setExplodeDistanceFactor()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 bool QPieSlice::isExploded() const
{
return m_isExploded;
}
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
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
Add documentation to pie
r314 */
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 qreal QPieSlice::explodeDistanceFactor() const
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 {
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 return m_explodeDistanceFactor;
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 }
Jani Honkonen
Add documentation to pie
r314 /*!
Returns the percentage of this slice compared to all slices in the same series.
Jani Honkonen
Review corrections for pie
r386 The returned value ranges from 0 to 1.0.
Jani Honkonen
More documentation for pie
r320
Jani Honkonen
Add documentation to pie
r314 Updated internally after the slice is added to the series.
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 qreal QPieSlice::percentage() const
{
return m_percentage;
}
Jani Honkonen
Add documentation to pie
r314 /*!
Returns the starting angle of this slice in the series it belongs to.
Jani Honkonen
More documentation for pie
r320
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
Jani Honkonen
Add documentation to pie
r314 Updated internally after the slice is added to the series.
*/
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 qreal QPieSlice::startAngle() const
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 return m_startAngle;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 Returns the end angle of this slice in the series it belongs to.
Jani Honkonen
More documentation for pie
r320
Full pie is 360 degrees where 0 degrees is at 12 a'clock.
Jani Honkonen
Add documentation to pie
r314 Updated internally after the slice is added to the series.
*/
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 qreal QPieSlice::endAngle() const
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
QPieSlice: angle() -> startAngle(), angleSpan() -> endAngle()
r355 return m_startAngle + m_angleSpan;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Add documentation to pie
r314 /*!
Returns the pen used to draw this slice.
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 \sa setSlicePen()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 QPen QPieSlice::slicePen() const
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 return m_slicePen;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Add documentation to pie
r314 /*!
Returns the brush used to draw this slice.
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 \sa setSliceBrush()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 QBrush QPieSlice::sliceBrush() const
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 return m_sliceBrush;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 Returns the pen used to draw label arm in this slice.
\sa setLabelArmPen()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 QPen QPieSlice::labelArmPen() const
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 return m_labelArmPen;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Add documentation to pie
r314 /*!
Returns the font used to draw label in this slice.
\sa setLabelFont()
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 QFont QPieSlice::labelFont() const
{
return m_labelFont;
}
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 Gets the label arm lenght factor.
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
Add documentation to pie
r314 */
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 qreal QPieSlice::labelArmLengthFactor() const
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 return m_labelArmLengthFactor;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
Jani Honkonen
Add documentation to pie
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
Introducing vertical and horizontal factors to control the position of the pie.
r454 Sets the \a value of this slice.
Jani Honkonen
Add documentation to pie
r314 \sa value()
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 void QPieSlice::setValue(qreal value)
{
if (m_value != value) {
m_value = value;
Jani Honkonen
Add animations to pie. Works but has some visual issues when adding slices.
r618
QPieSeries *series = qobject_cast<QPieSeries*>(parent());
if (series)
series->updateDerivativeData(); // will emit changed()
else
emit changed();
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 }
}
Jani Honkonen
Add documentation to pie
r314 /*!
Sets the \a label of the slice.
\sa label()
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 void QPieSlice::setLabel(QString label)
{
if (m_label != label) {
m_label = label;
emit changed();
}
}
Jani Honkonen
Add documentation to pie
r314 /*!
Sets the label \a visible in this slice.
\sa isLabelVisible(), QPieSeries::setLabelsVisible()
*/
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 void QPieSlice::setLabelVisible(bool visible)
{
if (m_isLabelVisible != visible) {
m_isLabelVisible = visible;
emit changed();
}
}
Jani Honkonen
Add documentation to pie
r314 /*!
Sets this slice \a exploded.
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 \sa isExploded(), explodeDistanceFactor()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 void QPieSlice::setExploded(bool exploded)
{
if (m_isExploded != exploded) {
m_isExploded = exploded;
emit changed();
}
}
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
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
Add documentation to pie
r314 */
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 void QPieSlice::setExplodeDistanceFactor(qreal factor)
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 {
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 if (m_explodeDistanceFactor != factor) {
m_explodeDistanceFactor = factor;
Jani Honkonen
Make pie fit better inside its given rectangle. Label texts still go outside. Needs a bit more work...
r289 emit changed();
}
}
Jani Honkonen
Add documentation to pie
r314 /*!
Sets the \a pen used to draw this slice.
Note that applying a theme will override this.
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 \sa slicePen()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 void QPieSlice::setSlicePen(const QPen &pen)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 if (m_slicePen != pen) {
m_slicePen = pen;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 emit changed();
}
}
Jani Honkonen
Add documentation to pie
r314 /*!
Sets the \a brush used to draw this slice.
Note that applying a theme will override this.
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 \sa sliceBrush()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 void QPieSlice::setSliceBrush(const QBrush &brush)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 if (m_sliceBrush != brush) {
m_sliceBrush = brush;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 emit changed();
}
}
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 Sets the \a pen used to draw the label arm in this slice.
Jani Honkonen
Add documentation to pie
r314 Note that applying a theme will override this.
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 \sa labelArmPen()
Jani Honkonen
Add documentation to pie
r314 */
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 void QPieSlice::setLabelArmPen(const QPen &pen)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Renaming pen & brush functions for pie and adding const
r469 if (m_labelArmPen != pen) {
m_labelArmPen = pen;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 emit changed();
}
}
Jani Honkonen
Add documentation to pie
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
Renaming pen & brush functions for pie and adding const
r469 void QPieSlice::setLabelFont(const QFont &font)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Add documentation to pie
r314 if (m_labelFont != font) {
m_labelFont = font;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 emit changed();
}
}
Jani Honkonen
Add documentation to pie
r314 /*!
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 Sets the label arm lenght \a factor.
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
Add documentation to pie
r314 */
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 void QPieSlice::setLabelArmLengthFactor(qreal factor)
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 {
Jani Honkonen
Introducing vertical and horizontal factors to control the position of the pie.
r454 if (m_labelArmLengthFactor != factor) {
m_labelArmLengthFactor = factor;
Jani Honkonen
Refactor pie (again). QPieSlice's now emit signals and no id's anymore. Just pointers in the interface.
r203 emit changed();
}
}
#include "moc_qpieslice.cpp"
QTCOMMERCIALCHART_END_NAMESPACE