From 12de1da93c515f89bb96c2db69d3b84f3e972ec9 2012-06-01 12:00:31 From: Jani Honkonen Date: 2012-06-01 12:00:31 Subject: [PATCH] Fix issues with pen/brush convenience properties and update docs --- diff --git a/src/piechart/qpieslice.cpp b/src/piechart/qpieslice.cpp index 1d25743..9f8878a 100644 --- a/src/piechart/qpieslice.cpp +++ b/src/piechart/qpieslice.cpp @@ -121,6 +121,42 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \property QPieSlice::borderColor + + Color used to draw the slice border. + + This is a convenience property for modifying the slice pen. + + \sa pen, borderWidth +*/ + +/*! + \fn void QPieSlice::borderColorChanged() + + This signal is emitted when slice border color changes. + + \sa pen, borderColor +*/ + +/*! + \property QPieSlice::borderWidth + + Width of the slice border. + + This is a convenience property for modifying the slice pen. + + \sa pen, borderColor +*/ + +/*! + \fn void QPieSlice::borderWidthChanged() + + This signal is emitted when slice border width changes. + + \sa pen, borderWidth +*/ + +/*! \property QPieSlice::brush Brush used to draw the slice. @@ -135,6 +171,24 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \property QPieSlice::color + + Color used to draw the slice. + + This is a convenience property for modifying the slice brush. + + \sa brush +*/ + +/*! + \fn void QPieSlice::colorChanged() + + This signal is emitted when slice color changes. + + \sa brush +*/ + +/*! \property QPieSlice::labelBrush Pen used to draw label and label arm of the slice. @@ -151,6 +205,24 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \property QPieSlice::labelColor + + Color used to draw the slice label. + + This is a convenience property for modifying the slice label brush. + + \sa labelBrush +*/ + +/*! + \fn void QPieSlice::labelColorChanged() + + This signal is emitted when slice label color changes. + + \sa labelColor +*/ + +/*! \property QPieSlice::labelFont Font used for drawing label text. @@ -381,6 +453,34 @@ QPen QPieSlice::pen() const return d_ptr->m_data.m_slicePen; } +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); + } +} + void QPieSlice::setBrush(const QBrush &brush) { d_ptr->setBrush(brush, false); @@ -391,6 +491,20 @@ QBrush QPieSlice::brush() const return d_ptr->m_data.m_sliceBrush; } +QColor QPieSlice::color() +{ + return brush().color(); +} + +void QPieSlice::setColor(QColor color) +{ + QBrush b = brush(); + if (color != b.color()) { + b.setColor(color); + setBrush(b); + } +} + void QPieSlice::setLabelBrush(const QBrush &brush) { d_ptr->setLabelBrush(brush, false); @@ -401,6 +515,20 @@ QBrush QPieSlice::labelBrush() const return d_ptr->m_data.m_labelBrush; } +QColor QPieSlice::labelColor() +{ + return labelBrush().color(); +} + +void QPieSlice::setLabelColor(QColor color) +{ + QBrush b = labelBrush(); + if (color != b.color()) { + b.setColor(color); + setLabelBrush(b); + } +} + void QPieSlice::setLabelFont(const QFont &font) { d_ptr->setLabelFont(font, false); @@ -452,63 +580,6 @@ qreal QPieSlice::angleSpan() const return d_ptr->m_data.m_angleSpan; } -QColor QPieSlice::color() -{ - return brush().color(); -} - -void QPieSlice::setColor(QColor color) -{ - QBrush b = brush(); - if (color != b.color()) { - b.setColor(color); - setBrush(b); - } -} - -QColor QPieSlice::borderColor() -{ - return pen().color(); -} - -void QPieSlice::setBorderColor(QColor color) -{ - QPen p = pen(); - if (color != p.color()) { - p.setColor(color); - setPen(p); - emit borderColorChanged(); - } -} - -int QPieSlice::borderWidth() -{ - return pen().width(); -} - -void QPieSlice::setBorderWidth(int width) -{ - QPen p = pen(); - if (width != p.width()) { - p.setWidth(width); - setPen(p); - } -} - -QColor QPieSlice::labelColor() -{ - return labelBrush().color(); -} - -void QPieSlice::setLabelColor(QColor color) -{ - QBrush b = labelBrush(); - if (color != b.color()) { - b.setColor(color); - setLabelBrush(b); - } -} - /*! Returns the series that this slice belongs to. @@ -540,35 +611,47 @@ QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice) void QPieSlicePrivate::setPen(const QPen &pen, bool themed) { if (m_data.m_slicePen != pen) { - if (m_data.m_slicePen.color() != pen.color()) - emit q_ptr->borderColorChanged(); - if (m_data.m_slicePen.width() != pen.width()) - emit q_ptr->borderWidthChanged(); + + QPen oldPen = m_data.m_slicePen; + m_data.m_slicePen = pen; m_data.m_slicePen.setThemed(themed); + emit q_ptr->penChanged(); + if (oldPen.color() != pen.color()) + emit q_ptr->borderColorChanged(); + if (oldPen.width() != pen.width()) + emit q_ptr->borderWidthChanged(); } } void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed) { if (m_data.m_sliceBrush != brush) { - if (m_data.m_sliceBrush.color() != brush.color()) - emit q_ptr->colorChanged(); + + QBrush oldBrush = m_data.m_sliceBrush; + m_data.m_sliceBrush = brush; m_data.m_sliceBrush.setThemed(themed); + emit q_ptr->brushChanged(); + if (oldBrush.color() != brush.color()) + emit q_ptr->colorChanged(); } } void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed) { if (m_data.m_labelBrush != brush) { - if (m_data.m_labelBrush.color() != brush.color()) - emit q_ptr->labelColorChanged(); + + QBrush oldBrush = m_data.m_labelBrush; + m_data.m_labelBrush = brush; m_data.m_labelBrush.setThemed(themed); + emit q_ptr->labelBrushChanged(); + if (oldBrush.color() != brush.color()) + emit q_ptr->labelColorChanged(); } } diff --git a/src/piechart/qpieslice.h b/src/piechart/qpieslice.h index 0b330d3..9a8d100 100644 --- a/src/piechart/qpieslice.h +++ b/src/piechart/qpieslice.h @@ -39,18 +39,18 @@ class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject Q_PROPERTY(bool labelVisible READ isLabelVisible WRITE setLabelVisible NOTIFY labelVisibleChanged) Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged) Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) + Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) + Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged) Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) + Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) Q_PROPERTY(qreal labelArmLengthFactor READ labelArmLengthFactor WRITE setLabelArmLengthFactor) Q_PROPERTY(qreal explodeDistanceFactor READ explodeDistanceFactor WRITE setExplodeDistanceFactor) Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged) Q_PROPERTY(qreal startAngle READ startAngle NOTIFY startAngleChanged) Q_PROPERTY(qreal angleSpan READ angleSpan NOTIFY angleSpanChanged) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) - Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderWidthChanged) - Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) public: explicit QPieSlice(QObject *parent = 0); @@ -72,12 +72,24 @@ public: void setPen(const QPen &pen); QPen pen() const; + QColor borderColor(); + void setBorderColor(QColor color); + + int borderWidth(); + void setBorderWidth(int width); + void setBrush(const QBrush &brush); QBrush brush() const; + QColor color(); + void setColor(QColor color); + void setLabelBrush(const QBrush &brush); QBrush labelBrush() const; + QColor labelColor(); + void setLabelColor(QColor color); + void setLabelFont(const QFont &font); QFont labelFont() const; @@ -91,15 +103,6 @@ public: qreal startAngle() const; qreal angleSpan() const; - QColor color(); - void setColor(QColor color); - QColor borderColor(); - void setBorderColor(QColor color); - int borderWidth(); - void setBorderWidth(int width); - QColor labelColor(); - void setLabelColor(QColor color); - QPieSeries *series() const; Q_SIGNALS: