diff --git a/demos/piechartcustomization/mainwidget.cpp b/demos/piechartcustomization/mainwidget.cpp index f66ac57..e630421 100644 --- a/demos/piechartcustomization/mainwidget.cpp +++ b/demos/piechartcustomization/mainwidget.cpp @@ -152,8 +152,8 @@ MainWidget::MainWidget(QWidget* parent) m_brush = new QPushButton(); m_brushTool = new BrushTool("Slice brush", this); m_font = new QPushButton(); - m_labelPen = new QPushButton(); - m_labelPenTool = new PenTool("Label pen", this); + m_labelBrush = new QPushButton(); + m_labelBrushTool = new BrushTool("Label brush", this); QPushButton *removeSlice = new QPushButton("Remove slice"); QFormLayout* sliceSettingsLayout = new QFormLayout(); @@ -163,7 +163,7 @@ MainWidget::MainWidget(QWidget* parent) sliceSettingsLayout->addRow("Brush", m_brush); sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); sliceSettingsLayout->addRow("Label font", m_font); - sliceSettingsLayout->addRow("Label pen", m_labelPen); + sliceSettingsLayout->addRow("Label pen", m_labelBrush); sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); sliceSettingsLayout->addRow("Exploded", m_sliceExploded); sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); @@ -177,8 +177,8 @@ MainWidget::MainWidget(QWidget* parent) connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); - connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show())); - connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); + connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show())); + connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); @@ -241,7 +241,7 @@ void MainWidget::updateSliceSettings() m_slice->setPen(m_penTool->pen()); m_slice->setBrush(m_brushTool->brush()); - m_slice->setLabelPen(m_labelPenTool->pen()); + m_slice->setLabelBrush(m_labelBrushTool->brush()); m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); @@ -270,8 +270,8 @@ void MainWidget::handleSliceClicked(QPieSlice* slice) m_brushTool->setBrush(m_slice->originalBrush()); // label - m_labelPen->setText(PenTool::name(m_slice->labelPen())); - m_labelPenTool->setPen(m_slice->labelPen()); + m_labelBrush->setText(BrushTool::name(m_slice->labelBrush())); + m_labelBrushTool->setBrush(m_slice->labelBrush()); m_font->setText(slice->labelFont().toString()); m_sliceLabelVisible->blockSignals(true); m_sliceLabelVisible->setChecked(slice->isLabelVisible()); diff --git a/demos/piechartcustomization/mainwidget.h b/demos/piechartcustomization/mainwidget.h index 9489bac..8daaf84 100644 --- a/demos/piechartcustomization/mainwidget.h +++ b/demos/piechartcustomization/mainwidget.h @@ -84,8 +84,8 @@ private: QPushButton *m_pen; PenTool *m_penTool; QPushButton *m_font; - QPushButton *m_labelPen; - PenTool *m_labelPenTool; + QPushButton *m_labelBrush; + BrushTool *m_labelBrushTool; }; #endif // MAINWIDGET_H diff --git a/plugins/declarative/declarativepieseries.cpp b/plugins/declarative/declarativepieseries.cpp index d929f14..2e755cd 100644 --- a/plugins/declarative/declarativepieseries.cpp +++ b/plugins/declarative/declarativepieseries.cpp @@ -70,14 +70,15 @@ void DeclarativePieSlice::setBorderWidth(int width) QColor DeclarativePieSlice::labelColor() { - return labelPen().color(); + return labelBrush().color(); } void DeclarativePieSlice::setLabelColor(QColor color) { - QPen p = labelPen(); - p.setColor(color); - setLabelPen(p); + // TODO: use brush instead for label color + QBrush b = labelBrush(); + b.setColor(color); + setLabelBrush(b); } DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : diff --git a/src/barchart/qbarset.cpp b/src/barchart/qbarset.cpp index e799691..06f6cf6 100644 --- a/src/barchart/qbarset.cpp +++ b/src/barchart/qbarset.cpp @@ -267,25 +267,6 @@ QBrush QBarSet::brush() const } /*! - Sets \a pen of the values that are drawn on top of this barset -*/ -void QBarSet::setLabelPen(const QPen &pen) -{ - if(d_ptr->m_labelPen!=pen){ - d_ptr->m_labelPen = pen; - emit d_ptr->updatedBars(); - } -} - -/*! - Returns pen of the values that are drawn on top of this barset -*/ -QPen QBarSet::labelPen() const -{ - return d_ptr->m_labelPen; -} - -/*! Sets \a brush of the values that are drawn on top of this barset */ void QBarSet::setLabelBrush(const QBrush &brush) diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 98569bf..9afc363 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -63,9 +63,6 @@ public: void setBrush(const QBrush &brush); QBrush brush() const; - void setLabelPen(const QPen &pen); - QPen labelPen() const; - void setLabelBrush(const QBrush &brush); QBrush labelBrush() const; diff --git a/src/barchart/qbarset_p.h b/src/barchart/qbarset_p.h index 6fb4ad0..83393c2 100644 --- a/src/barchart/qbarset_p.h +++ b/src/barchart/qbarset_p.h @@ -57,7 +57,6 @@ public: QList m_values; QPen m_pen; QBrush m_brush; - QPen m_labelPen; QBrush m_labelBrush; QFont m_labelFont; diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 7c31b2f..d2fad69 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -234,8 +234,8 @@ void ChartTheme::decorate(QPieSeries *series, int index) if (d->m_data.m_sliceBrush.isThemed() || m_force) d->setBrush(brushColor, true); - if (d->m_data.m_labelPen.isThemed() || m_force) - d->setLabelPen(QPen(m_titleBrush.color()), true); + if (d->m_data.m_labelBrush.isThemed() || m_force) + d->setLabelBrush(QBrush(m_titleBrush.color()), true); if (d->m_data.m_labelFont.isThemed() || m_force) d->setLabelFont(m_labelFont, true); diff --git a/src/piechart/piechartitem.cpp b/src/piechart/piechartitem.cpp index 3cc4506..aba71e7 100644 --- a/src/piechart/piechartitem.cpp +++ b/src/piechart/piechartitem.cpp @@ -143,7 +143,7 @@ void PieChartItem::handleSlicesAdded(QList slices) connect(slice, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged())); connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged())); connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged())); - connect(slice, SIGNAL(labelPenChanged()), this, SLOT(handleSliceChanged())); + connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged())); connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged())); connect(slice, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged())); connect(slice, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged())); diff --git a/src/piechart/pieslicedata_p.h b/src/piechart/pieslicedata_p.h index 45b39e2..c6ba74d 100644 --- a/src/piechart/pieslicedata_p.h +++ b/src/piechart/pieslicedata_p.h @@ -91,7 +91,7 @@ public: m_labelText != other.m_labelText || m_labelFont != other.m_labelFont || !qFuzzyIsNull(m_labelArmLengthFactor - other.m_labelArmLengthFactor) || - m_labelPen != other.m_labelPen) + m_labelBrush != other.m_labelBrush) return true; if (!qFuzzyIsNull(m_percentage - other.m_percentage) || @@ -116,7 +116,7 @@ public: QString m_labelText; Themed m_labelFont; qreal m_labelArmLengthFactor; - Themed m_labelPen; + Themed m_labelBrush; qreal m_percentage; QPointF m_center; diff --git a/src/piechart/piesliceitem.cpp b/src/piechart/piesliceitem.cpp index 2992172..7842dd8 100644 --- a/src/piechart/piesliceitem.cpp +++ b/src/piechart/piesliceitem.cpp @@ -81,9 +81,10 @@ void PieSliceItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*op if (m_data.m_isLabelVisible) { painter->save(); painter->setClipRect(parentItem()->boundingRect()); - painter->setPen(m_data.m_labelPen); + // Pen for label arm not defined in the QPieSeries api, let's use brush's color instead + // Also, the drawText actually uses the pen color for the text color (unlike QGraphicsSimpleTextItem) + painter->setPen(m_data.m_labelBrush.color()); painter->drawPath(m_labelArmPath); - // the pen color will affect the font color as well painter->setFont(m_data.m_labelFont); painter->drawText(m_labelTextRect.bottomLeft(), m_data.m_labelText); painter->restore(); diff --git a/src/piechart/qpieslice.cpp b/src/piechart/qpieslice.cpp index 7fe0a5b..6dfde11 100644 --- a/src/piechart/qpieslice.cpp +++ b/src/piechart/qpieslice.cpp @@ -43,7 +43,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Label of the slice. - \sa labelVisible, labelPen, labelFont, labelArmLengthFactor + \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor */ /*! @@ -79,7 +79,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Default is not visible. - \sa label, labelPen, labelFont, labelArmLengthFactor + \sa label, labelBrush, labelFont, labelArmLengthFactor */ /*! @@ -135,7 +135,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \property QPieSlice::labelPen + \property QPieSlice::labelBrush Pen used to draw label and label arm of the slice. @@ -143,11 +143,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \fn void QPieSlice::labelPenChanged() + \fn void QPieSlice::labelBrushChanged() This signal is emitted when the label pen of the slice has changed. - \sa labelPen + \sa labelBrush */ /*! @@ -177,7 +177,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Default value is 0.15 - \sa label, labelVisible, labelPen, labelFont + \sa label, labelVisible, labelBrush, labelFont */ /*! @@ -391,14 +391,14 @@ QBrush QPieSlice::brush() const return d_ptr->m_data.m_sliceBrush; } -void QPieSlice::setLabelPen(const QPen &pen) +void QPieSlice::setLabelBrush(const QBrush &brush) { - d_ptr->setLabelPen(pen, false); + d_ptr->setLabelBrush(brush, false); } -QPen QPieSlice::labelPen() const +QBrush QPieSlice::labelBrush() const { - return d_ptr->m_data.m_labelPen; + return d_ptr->m_data.m_labelBrush; } void QPieSlice::setLabelFont(const QFont &font) @@ -487,12 +487,12 @@ void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed) } } -void QPieSlicePrivate::setLabelPen(const QPen &pen, bool themed) +void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed) { - if (m_data.m_labelPen != pen) { - m_data.m_labelPen = pen; - m_data.m_labelPen.setThemed(themed); - emit q_ptr->labelPenChanged(); + if (m_data.m_labelBrush != brush) { + m_data.m_labelBrush = brush; + m_data.m_labelBrush.setThemed(themed); + emit q_ptr->labelBrushChanged(); } } diff --git a/src/piechart/qpieslice.h b/src/piechart/qpieslice.h index e5b45e9..10dad96 100644 --- a/src/piechart/qpieslice.h +++ b/src/piechart/qpieslice.h @@ -39,7 +39,7 @@ class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject Q_PROPERTY(bool exploded READ isExploded WRITE setExploded NOTIFY explodedChanged) Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) - Q_PROPERTY(QPen labelPen READ labelPen WRITE setLabelPen NOTIFY labelPenChanged) + Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) 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) @@ -70,8 +70,8 @@ public: void setBrush(const QBrush &brush); QBrush brush() const; - void setLabelPen(const QPen &pen); - QPen labelPen() const; + void setLabelBrush(const QBrush &brush); + QBrush labelBrush() const; void setLabelFont(const QFont &font); QFont labelFont() const; @@ -93,7 +93,7 @@ Q_SIGNALS: void explodedChanged(); void penChanged(); void brushChanged(); - void labelPenChanged(); + void labelBrushChanged(); void labelFontChanged(); void labelArmLengthFactorChanged(); void explodeDistanceFactorChanged(); diff --git a/src/piechart/qpieslice_p.h b/src/piechart/qpieslice_p.h index f9c690f..b76d4aa 100644 --- a/src/piechart/qpieslice_p.h +++ b/src/piechart/qpieslice_p.h @@ -19,7 +19,7 @@ public: void setPen(const QPen &pen, bool themed); void setBrush(const QBrush &brush, bool themed); - void setLabelPen(const QPen &pen, bool themed); + void setLabelBrush(const QBrush &brush, bool themed); void setLabelFont(const QFont &font, bool themed); void setPercentage(qreal percentage); diff --git a/tests/auto/qbarset/tst_qbarset.cpp b/tests/auto/qbarset/tst_qbarset.cpp index 050b9a4..eb66097 100644 --- a/tests/auto/qbarset/tst_qbarset.cpp +++ b/tests/auto/qbarset/tst_qbarset.cpp @@ -60,8 +60,6 @@ private slots: void setPen(); void setBrush_data(); void setBrush(); - void setLabelPen_data(); - void setLabelPen(); void setLabelBrush_data(); void setLabelBrush(); void setLabelFont_data(); @@ -380,22 +378,6 @@ void tst_QBarSet::setBrush() QVERIFY(m_barset->brush() == brush); } -void tst_QBarSet::setLabelPen_data() -{ - -} - -void tst_QBarSet::setLabelPen() -{ - QVERIFY(m_barset->labelPen() == QPen()); - - QPen pen; - pen.setColor(QColor(128,128,128,128)); - m_barset->setLabelPen(pen); - - QVERIFY(m_barset->labelPen() == pen); -} - void tst_QBarSet::setLabelBrush_data() { diff --git a/tests/auto/qpieslice/tst_qpieslice.cpp b/tests/auto/qpieslice/tst_qpieslice.cpp index f3d2892..0dbb781 100644 --- a/tests/auto/qpieslice/tst_qpieslice.cpp +++ b/tests/auto/qpieslice/tst_qpieslice.cpp @@ -79,7 +79,7 @@ void tst_qpieslice::construction() QVERIFY(!slice1.isExploded()); QCOMPARE(slice1.pen(), QPen()); QCOMPARE(slice1.brush(), QBrush()); - QCOMPARE(slice1.labelPen(), QPen()); + QCOMPARE(slice1.labelBrush(), QBrush()); QCOMPARE(slice1.labelFont(), QFont()); QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value @@ -95,7 +95,7 @@ void tst_qpieslice::construction() QVERIFY(!slice2.isExploded()); QCOMPARE(slice2.pen(), QPen()); QCOMPARE(slice2.brush(), QBrush()); - QCOMPARE(slice2.labelPen(), QPen()); + QCOMPARE(slice2.labelBrush(), QBrush()); QCOMPARE(slice2.labelFont(), QFont()); QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value @@ -113,7 +113,7 @@ void tst_qpieslice::changedSignals() QSignalSpy explodedSpy(&slice, SIGNAL(explodedChanged())); QSignalSpy penSpy(&slice, SIGNAL(penChanged())); QSignalSpy brushSpy(&slice, SIGNAL(brushChanged())); - QSignalSpy labelPenSpy(&slice, SIGNAL(labelPenChanged())); + QSignalSpy labelBrushSpy(&slice, SIGNAL(labelBrushChanged())); QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged())); QSignalSpy labelArmLengthFactorSpy(&slice, SIGNAL(labelArmLengthFactorChanged())); QSignalSpy explodeDistanceFactorSpy(&slice, SIGNAL(explodeDistanceFactorChanged())); @@ -134,8 +134,8 @@ void tst_qpieslice::changedSignals() slice.setPen(QPen(Qt::red)); slice.setBrush(QBrush(Qt::red)); slice.setBrush(QBrush(Qt::red)); - slice.setLabelPen(QPen(Qt::green)); - slice.setLabelPen(QPen(Qt::green)); + slice.setLabelBrush(QBrush(Qt::green)); + slice.setLabelBrush(QBrush(Qt::green)); slice.setLabelFont(QFont("Tahoma")); slice.setLabelFont(QFont("Tahoma")); slice.setLabelArmLengthFactor(0.1); @@ -148,7 +148,7 @@ void tst_qpieslice::changedSignals() TRY_COMPARE(explodedSpy.count(), 1); TRY_COMPARE(penSpy.count(), 1); TRY_COMPARE(brushSpy.count(), 1); - TRY_COMPARE(labelPenSpy.count(), 1); + TRY_COMPARE(labelBrushSpy.count(), 1); TRY_COMPARE(labelFontSpy.count(), 1); TRY_COMPARE(labelArmLengthFactorSpy.count(), 1); TRY_COMPARE(explodeDistanceFactorSpy.count(), 1); @@ -167,7 +167,7 @@ void tst_qpieslice::customize() s1->setPen(p1); QBrush b1(Qt::red); s1->setBrush(b1); - s1->setLabelPen(p1); + s1->setLabelBrush(b1); QFont f1("Consolas"); s1->setLabelFont(f1); @@ -182,28 +182,28 @@ void tst_qpieslice::customize() // check that customizations persist QCOMPARE(s1->pen(), p1); QCOMPARE(s1->brush(), b1); - QCOMPARE(s1->labelPen(), p1); + QCOMPARE(s1->labelBrush(), b1); QCOMPARE(s1->labelFont(), f1); // remove a slice series->remove(s2); QCOMPARE(s1->pen(), p1); QCOMPARE(s1->brush(), b1); - QCOMPARE(s1->labelPen(), p1); + QCOMPARE(s1->labelBrush(), b1); QCOMPARE(s1->labelFont(), f1); // add a slice series->append("slice 4", 4); QCOMPARE(s1->pen(), p1); QCOMPARE(s1->brush(), b1); - QCOMPARE(s1->labelPen(), p1); + QCOMPARE(s1->labelBrush(), b1); QCOMPARE(s1->labelFont(), f1); // insert a slice series->insert(0, new QPieSlice("slice 5", 5)); QCOMPARE(s1->pen(), p1); QCOMPARE(s1->brush(), b1); - QCOMPARE(s1->labelPen(), p1); + QCOMPARE(s1->labelBrush(), b1); QCOMPARE(s1->labelFont(), f1); // change theme @@ -211,7 +211,7 @@ void tst_qpieslice::customize() view.chart()->setTheme(QChart::ChartThemeHighContrast); QVERIFY(s1->pen() != p1); QVERIFY(s1->brush() != b1); - QVERIFY(s1->labelPen() != p1); + QVERIFY(s1->labelBrush() != b1); QVERIFY(s1->labelFont() != f1); }