From 047096c16fcf267dcb0e70555a679a2754fc1d25 2012-06-27 06:41:29 From: Tero Ahola Date: 2012-06-27 06:41:29 Subject: [PATCH] Fixed signaling in QLegend --- diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index 24df89f..48a67eb 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -225,6 +225,7 @@ void QLegend::setBrush(const QBrush &brush) if (d_ptr->m_brush != brush) { d_ptr->m_brush = brush; update(); + emit colorChanged(brush.color()); } } @@ -243,7 +244,6 @@ void QLegend::setColor(QColor color) b.setStyle(Qt::SolidPattern); b.setColor(color); setBrush(b); - emit colorChanged(color); } } @@ -260,6 +260,7 @@ void QLegend::setPen(const QPen &pen) if (d_ptr->m_pen != pen) { d_ptr->m_pen = pen; update(); + emit borderColorChanged(pen.color()); } } @@ -296,7 +297,6 @@ void QLegend::setBorderColor(QColor color) if (p.color() != color) { p.setColor(color); setPen(p); - emit borderColorChanged(color); } } @@ -311,13 +311,11 @@ QColor QLegend::borderColor() void QLegend::setLabelBrush(const QBrush &brush) { if (d_ptr->m_labelBrush != brush) { - d_ptr->m_labelBrush = brush; - foreach (LegendMarker *marker, d_ptr->markers()) { marker->setLabelBrush(d_ptr->m_labelBrush); } - emit labelBrushChanged(brush); + emit labelColorChanged(brush.color()); } } @@ -336,7 +334,6 @@ void QLegend::setLabelColor(QColor color) b.setStyle(Qt::SolidPattern); b.setColor(color); setLabelBrush(b); - emit labelColorChanged(color); } } diff --git a/src/legend/qlegend.h b/src/legend/qlegend.h index 2284952..a774e3b 100644 --- a/src/legend/qlegend.h +++ b/src/legend/qlegend.h @@ -96,7 +96,6 @@ Q_SIGNALS: void colorChanged(QColor color); void borderColorChanged(QColor color); void fontChanged(QFont font); - void labelBrushChanged(QBrush brush); void labelColorChanged(QColor color); private: diff --git a/tests/auto/qchart/tst_qchart.cpp b/tests/auto/qchart/tst_qchart.cpp index 3a3fa0a..34718ed 100644 --- a/tests/auto/qchart/tst_qchart.cpp +++ b/tests/auto/qchart/tst_qchart.cpp @@ -360,7 +360,44 @@ void tst_QChart::legend_data() void tst_QChart::legend() { - QVERIFY(m_chart->legend()); + QLegend *legend = m_chart->legend(); + QVERIFY(legend); + + // Colors related signals + QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); + QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); + QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); + + // colorChanged + legend->setColor(QColor("aliceblue")); + QCOMPARE(colorSpy.count(), 1); + QBrush b = legend->brush(); + b.setColor(QColor("aqua")); + legend->setBrush(b); + QCOMPARE(colorSpy.count(), 2); + + // borderColorChanged + legend->setBorderColor(QColor("aliceblue")); + QCOMPARE(borderColorSpy.count(), 1); + QPen p = legend->pen(); + p.setColor(QColor("aqua")); + legend->setPen(p); + QCOMPARE(borderColorSpy.count(), 2); + + // labelColorChanged + legend->setLabelColor(QColor("lightsalmon")); + QCOMPARE(labelColorSpy.count(), 1); + b = legend->labelBrush(); + b.setColor(QColor("lightseagreen")); + legend->setLabelBrush(b); + QCOMPARE(labelColorSpy.count(), 2); + + // fontChanged + QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); + QFont f = legend->font(); + f.setBold(!f.bold()); + legend->setFont(f); + QCOMPARE(fontSpy.count(), 1); } void tst_QChart::margins_data() diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml index 5f810c8..7c02b74 100644 --- a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml +++ b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml @@ -64,7 +64,6 @@ ChartView { legend.onColorChanged: console.log("legend.onColorChanged: " + color); legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color); - legend.onLabelBrushChanged: console.log("legend.onLabelBrushChanged: " + brush); axisX.onColorChanged: console.log("axisX.onColorChanged: " + color); axisX.onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible);