summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-04-26 09:55:38 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-04-26 14:10:25 +0000
commit1448df4988763d163b6753f9afddbec7999aedd8 (patch)
tree2e5b588d706e822071b5edcd48dcb3c4bf66b634 /tests
parentd3f9275cbaa6a6059298ec248dd28dd6ef065e51 (diff)
Maintain correct order of legend items when inserting pie chart items
Rewrite QLegendPrivate::handleCountChanged() so that the order of the markers is preserved. Split out helper functions for insertion/removal that leave the m_markers list untouched and add helpers for finding markers by series and related objects. In QLegendPrivate::handleCountChanged(), remove the markers of the series from m_markers and replace the existing ones in the createdMarkers. Finally re-insert createdMarkers into m_markers, preserving the order. Task-number: QTBUG-62082 Change-Id: I03c81dcf5dfd5a5883377630cad16c943503a1be Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qpieslice/tst_qpieslice.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/auto/qpieslice/tst_qpieslice.cpp b/tests/auto/qpieslice/tst_qpieslice.cpp
index 19d838f5..977ed35b 100644
--- a/tests/auto/qpieslice/tst_qpieslice.cpp
+++ b/tests/auto/qpieslice/tst_qpieslice.cpp
@@ -31,6 +31,8 @@
#include <tst_definitions.h>
#include <QtCharts/QChartView>
#include <QtCharts/QChart>
+#include <QtCharts/QLegend>
+#include <QtCharts/QLegendMarker>
#include <QtCharts/QPieSlice>
#include <QtCharts/QPieSeries>
@@ -217,12 +219,20 @@ void tst_qpieslice::customize()
QCOMPARE(s1->labelFont(), f1);
// insert a slice
- series->insert(0, new QPieSlice("slice 5", 5));
+ series->insert(0, new QPieSlice("slice 0", 5));
QCOMPARE(s1->pen(), p1);
QCOMPARE(s1->brush(), b1);
QCOMPARE(s1->labelBrush(), b1);
QCOMPARE(s1->labelFont(), f1);
+ // QTBUG-62082, verify correct insertion at 0.
+ const QStringList expectedLabels{"slice 0", "slice 1", "slice 3", "slice 4"};
+ const auto legendMarkers = view.chart()->legend()->markers();
+ const int legendMarkersSize = legendMarkers.size();
+ QCOMPARE(legendMarkersSize, expectedLabels.size());
+ for (int m = 0; m < legendMarkersSize; ++m)
+ QCOMPARE(legendMarkers.at(m)->label(), expectedLabels.at(m));
+
// change theme
// theme will overwrite customizations
view.chart()->setTheme(QChart::ChartThemeHighContrast);