summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTitta Heikkala <titta.heikkala@digia.com>2014-04-03 09:36:26 +0300
committerTitta Heikkala <titta.heikkala@digia.com>2014-04-04 08:41:30 +0300
commit23bf915495bcbba30c874b0951b4d23df0f5acf3 (patch)
tree8b5a2f2dd3668d60755f40e4d089525d5a40e6b6
parent235cef4135ee65cd566a8b9db8cbb3f694bf425e (diff)
Add possibility to set markers in legend in reverse order
Added new property for legend which defines whether the markers in legend are shown in reverse order or not. Task-number: QTRD-2512 Change-Id: Ia6e6551be74a183c9f544d7cb9fff679150f4d7e Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r--plugins/quick2/plugins.qmltypes5
-rw-r--r--src/legend/legendlayout.cpp17
-rw-r--r--src/legend/qlegend.cpp26
-rw-r--r--src/legend/qlegend.h5
-rw-r--r--src/legend/qlegend_p.h1
-rw-r--r--tests/auto/qchart/tst_qchart.cpp8
-rw-r--r--tests/auto/qml-qtquicktest/tst_chartview.qml1
-rw-r--r--tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml2
-rw-r--r--tests/qmlchartproperties/qml/qmlchartproperties/ChartEditorLegend.qml4
-rw-r--r--tests/quick2chartproperties/qml/quick2chartproperties/Chart.qml2
-rw-r--r--tests/quick2chartproperties/qml/quick2chartproperties/ChartEditorLegend.qml4
11 files changed, 72 insertions, 3 deletions
diff --git a/plugins/quick2/plugins.qmltypes b/plugins/quick2/plugins.qmltypes
index cb0719b2..8f715cb1 100644
--- a/plugins/quick2/plugins.qmltypes
+++ b/plugins/quick2/plugins.qmltypes
@@ -1831,6 +1831,7 @@ Module {
Property { name: "borderColor"; type: "QColor" }
Property { name: "font"; type: "QFont" }
Property { name: "labelColor"; type: "QColor" }
+ Property { name: "reverseMarkers"; type: "bool" }
Signal {
name: "backgroundVisibleChanged"
Parameter { name: "visible"; type: "bool" }
@@ -1851,6 +1852,10 @@ Module {
name: "labelColorChanged"
Parameter { name: "color"; type: "QColor" }
}
+ Signal {
+ name: "reverseMarkersChanged"
+ Parameter { name: "reverseMarkers"; type: "bool" }
+ }
}
Component { name: "QtCommercialChart::QLineSeries"; prototype: "QtCommercialChart::QXYSeries" }
Component {
diff --git a/src/legend/legendlayout.cpp b/src/legend/legendlayout.cpp
index dfabb2c1..aae18e25 100644
--- a/src/legend/legendlayout.cpp
+++ b/src/legend/legendlayout.cpp
@@ -204,7 +204,14 @@ void LegendLayout::setAttachedGeometry(const QRectF &rect)
}
QPointF point(0,0);
- foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
+
+ int markerCount = m_legend->d_ptr->markers().count();
+ for (int i = 0; i < markerCount; i++) {
+ QLegendMarker *marker;
+ if (m_legend->d_ptr->m_reverseMarkers)
+ marker = m_legend->d_ptr->markers().at(markerCount - 1 - i);
+ else
+ marker = m_legend->d_ptr->markers().at(i);
LegendMarkerItem *item = marker->d_ptr->item();
if (item->isVisible()) {
QRectF itemRect = geometry;
@@ -238,7 +245,13 @@ void LegendLayout::setAttachedGeometry(const QRectF &rect)
case Qt::AlignLeft:
case Qt::AlignRight: {
QPointF point(0,0);
- foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
+ int markerCount = m_legend->d_ptr->markers().count();
+ for (int i = 0; i < markerCount; i++) {
+ QLegendMarker *marker;
+ if (m_legend->d_ptr->m_reverseMarkers)
+ marker = m_legend->d_ptr->markers().at(markerCount - 1 - i);
+ else
+ marker = m_legend->d_ptr->markers().at(i);
LegendMarkerItem *item = marker->d_ptr->item();
if (item->isVisible()) {
item->setGeometry(geometry);
diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp
index 199409e3..0cba1bd7 100644
--- a/src/legend/qlegend.cpp
+++ b/src/legend/qlegend.cpp
@@ -129,6 +129,15 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE
*/
/*!
+ \property QLegend::reverseMarkers
+ Whether reverse order is used for the markers in legend or not. False by default.
+*/
+/*!
+ \qmlproperty bool Legend::reverseMarkers
+ Whether reverse order is used for the markers in legend or not. False by default.
+*/
+
+/*!
\fn void QLegend::backgroundVisibleChanged(bool)
The visibility of the legend background changed to \a visible.
*/
@@ -391,6 +400,20 @@ QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
return d_ptr->markers(series);
}
+bool QLegend::reverseMarkers()
+{
+ return d_ptr->m_reverseMarkers;
+}
+
+void QLegend::setReverseMarkers(bool reverseMarkers)
+{
+ if (d_ptr->m_reverseMarkers != reverseMarkers) {
+ d_ptr->m_reverseMarkers = reverseMarkers;
+ layout()->invalidate();
+ emit reverseMarkersChanged(reverseMarkers);
+ }
+}
+
/*!
\internal \a event see QGraphicsWidget for details
*/
@@ -425,7 +448,8 @@ QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend
m_labelBrush(QBrush()),
m_diameter(5),
m_attachedToChart(true),
- m_backgroundVisible(false)
+ m_backgroundVisible(false),
+ m_reverseMarkers(false)
{
m_items->setHandlesChildEvents(false);
}
diff --git a/src/legend/qlegend.h b/src/legend/qlegend.h
index 81fc9d1a..995a03fa 100644
--- a/src/legend/qlegend.h
+++ b/src/legend/qlegend.h
@@ -42,6 +42,7 @@ class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
+ Q_PROPERTY(bool reverseMarkers READ reverseMarkers WRITE setReverseMarkers NOTIFY reverseMarkersChanged)
private:
explicit QLegend(QChart *chart);
@@ -81,6 +82,9 @@ public:
QList <QLegendMarker*> markers(QAbstractSeries *series = 0) const;
+ bool reverseMarkers();
+ void setReverseMarkers(bool reverseMarkers = true);
+
protected:
void hideEvent(QHideEvent *event);
void showEvent(QShowEvent *event);
@@ -91,6 +95,7 @@ Q_SIGNALS:
void borderColorChanged(QColor color);
void fontChanged(QFont font);
void labelColorChanged(QColor color);
+ void reverseMarkersChanged(bool reverseMarkers);
private:
QScopedPointer<QLegendPrivate> d_ptr;
diff --git a/src/legend/qlegend_p.h b/src/legend/qlegend_p.h
index 0a23f469..6d7ce8e9 100644
--- a/src/legend/qlegend_p.h
+++ b/src/legend/qlegend_p.h
@@ -82,6 +82,7 @@ private:
qreal m_diameter;
bool m_attachedToChart;
bool m_backgroundVisible;
+ bool m_reverseMarkers;
QList<QLegendMarker *> m_markers;
QList<QAbstractSeries *> m_series;
diff --git a/tests/auto/qchart/tst_qchart.cpp b/tests/auto/qchart/tst_qchart.cpp
index 6035fd76..c0a8eee3 100644
--- a/tests/auto/qchart/tst_qchart.cpp
+++ b/tests/auto/qchart/tst_qchart.cpp
@@ -420,6 +420,7 @@ void tst_QChart::legend()
{
QLegend *legend = m_chart->legend();
QVERIFY(legend);
+ QVERIFY(!m_chart->legend()->reverseMarkers());
// Colors related signals
QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
@@ -456,6 +457,13 @@ void tst_QChart::legend()
f.setBold(!f.bold());
legend->setFont(f);
QCOMPARE(fontSpy.count(), 1);
+
+ // reverseMarkersChanged
+ QSignalSpy reverseMarkersSpy(legend, SIGNAL(reverseMarkersChanged(bool)));
+ QCOMPARE(reverseMarkersSpy.count(), 0);
+ legend->setReverseMarkers();
+ QCOMPARE(reverseMarkersSpy.count(), 1);
+ QVERIFY(legend->reverseMarkers());
}
void tst_QChart::plotArea_data()
diff --git a/tests/auto/qml-qtquicktest/tst_chartview.qml b/tests/auto/qml-qtquicktest/tst_chartview.qml
index 11e4e191..bcfb605a 100644
--- a/tests/auto/qml-qtquicktest/tst_chartview.qml
+++ b/tests/auto/qml-qtquicktest/tst_chartview.qml
@@ -55,6 +55,7 @@ Rectangle {
compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible");
verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor");
verify(chartView.legend.color != undefined, "ChartView.legend.color");
+ compare(chartView.legend.reverseMarkers, false, "ChartView.legend.reverseMarkers");
// Legend font
compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold");
compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization");
diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml
index 983b2d2f..e8cc0952 100644
--- a/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml
+++ b/tests/qmlchartproperties/qml/qmlchartproperties/Chart.qml
@@ -52,6 +52,8 @@ ChartView {
legend.onColorChanged: console.log("legend.onColorChanged: " + color);
legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
+ legend.onReverseMarkersChanged: console.log("legend.onReverseMarkersChanged: "
+ + chart.legend.reverseMarkers)
margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top );
margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom);
margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left);
diff --git a/tests/qmlchartproperties/qml/qmlchartproperties/ChartEditorLegend.qml b/tests/qmlchartproperties/qml/qmlchartproperties/ChartEditorLegend.qml
index 25d82754..c4db0e36 100644
--- a/tests/qmlchartproperties/qml/qmlchartproperties/ChartEditorLegend.qml
+++ b/tests/qmlchartproperties/qml/qmlchartproperties/ChartEditorLegend.qml
@@ -65,6 +65,10 @@ Row {
text: "legend right"
onClicked: chartLegend.alignment = Qt.AlignRight;
}
+ Button {
+ text: "legend use reverse order"
+ onClicked: chartLegend.reverseMarkers = !chartLegend.reverseMarkers;
+ }
}
FontEditor {
diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/Chart.qml b/tests/quick2chartproperties/qml/quick2chartproperties/Chart.qml
index a4ba0f20..0dc17215 100644
--- a/tests/quick2chartproperties/qml/quick2chartproperties/Chart.qml
+++ b/tests/quick2chartproperties/qml/quick2chartproperties/Chart.qml
@@ -52,6 +52,8 @@ ChartView {
legend.onColorChanged: console.log("legend.onColorChanged: " + color);
legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
+ legend.onReverseMarkersChanged: console.log("legend.onReverseMarkersChanged: "
+ + chart.legend.reverseMarkers)
margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top );
margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom);
margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left);
diff --git a/tests/quick2chartproperties/qml/quick2chartproperties/ChartEditorLegend.qml b/tests/quick2chartproperties/qml/quick2chartproperties/ChartEditorLegend.qml
index be22da98..063cbf60 100644
--- a/tests/quick2chartproperties/qml/quick2chartproperties/ChartEditorLegend.qml
+++ b/tests/quick2chartproperties/qml/quick2chartproperties/ChartEditorLegend.qml
@@ -65,6 +65,10 @@ Row {
text: "legend right"
onClicked: chartLegend.alignment = Qt.AlignRight;
}
+ Button {
+ text: "legend use reverse order"
+ onClicked: chartLegend.reverseMarkers = !chartLegend.reverseMarkers;
+ }
}
FontEditor {