##// END OF EJS Templates
Add possibility to set markers in legend in reverse order...
Titta Heikkala -
r2676:23bf915495bc
parent child
Show More
@@ -1831,6 +1831,7 Module {
1831 1831 Property { name: "borderColor"; type: "QColor" }
1832 1832 Property { name: "font"; type: "QFont" }
1833 1833 Property { name: "labelColor"; type: "QColor" }
1834 Property { name: "reverseMarkers"; type: "bool" }
1834 1835 Signal {
1835 1836 name: "backgroundVisibleChanged"
1836 1837 Parameter { name: "visible"; type: "bool" }
@@ -1851,6 +1852,10 Module {
1851 1852 name: "labelColorChanged"
1852 1853 Parameter { name: "color"; type: "QColor" }
1853 1854 }
1855 Signal {
1856 name: "reverseMarkersChanged"
1857 Parameter { name: "reverseMarkers"; type: "bool" }
1858 }
1854 1859 }
1855 1860 Component { name: "QtCommercialChart::QLineSeries"; prototype: "QtCommercialChart::QXYSeries" }
1856 1861 Component {
@@ -204,7 +204,14 void LegendLayout::setAttachedGeometry(const QRectF &rect)
204 204 }
205 205
206 206 QPointF point(0,0);
207 foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
207
208 int markerCount = m_legend->d_ptr->markers().count();
209 for (int i = 0; i < markerCount; i++) {
210 QLegendMarker *marker;
211 if (m_legend->d_ptr->m_reverseMarkers)
212 marker = m_legend->d_ptr->markers().at(markerCount - 1 - i);
213 else
214 marker = m_legend->d_ptr->markers().at(i);
208 215 LegendMarkerItem *item = marker->d_ptr->item();
209 216 if (item->isVisible()) {
210 217 QRectF itemRect = geometry;
@@ -238,7 +245,13 void LegendLayout::setAttachedGeometry(const QRectF &rect)
238 245 case Qt::AlignLeft:
239 246 case Qt::AlignRight: {
240 247 QPointF point(0,0);
241 foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
248 int markerCount = m_legend->d_ptr->markers().count();
249 for (int i = 0; i < markerCount; i++) {
250 QLegendMarker *marker;
251 if (m_legend->d_ptr->m_reverseMarkers)
252 marker = m_legend->d_ptr->markers().at(markerCount - 1 - i);
253 else
254 marker = m_legend->d_ptr->markers().at(i);
242 255 LegendMarkerItem *item = marker->d_ptr->item();
243 256 if (item->isVisible()) {
244 257 item->setGeometry(geometry);
@@ -129,6 +129,15 QTCOMMERCIALCHART_BEGIN_NAMESPACE
129 129 */
130 130
131 131 /*!
132 \property QLegend::reverseMarkers
133 Whether reverse order is used for the markers in legend or not. False by default.
134 */
135 /*!
136 \qmlproperty bool Legend::reverseMarkers
137 Whether reverse order is used for the markers in legend or not. False by default.
138 */
139
140 /*!
132 141 \fn void QLegend::backgroundVisibleChanged(bool)
133 142 The visibility of the legend background changed to \a visible.
134 143 */
@@ -391,6 +400,20 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
391 400 return d_ptr->markers(series);
392 401 }
393 402
403 bool QLegend::reverseMarkers()
404 {
405 return d_ptr->m_reverseMarkers;
406 }
407
408 void QLegend::setReverseMarkers(bool reverseMarkers)
409 {
410 if (d_ptr->m_reverseMarkers != reverseMarkers) {
411 d_ptr->m_reverseMarkers = reverseMarkers;
412 layout()->invalidate();
413 emit reverseMarkersChanged(reverseMarkers);
414 }
415 }
416
394 417 /*!
395 418 \internal \a event see QGraphicsWidget for details
396 419 */
@@ -425,7 +448,8 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend
425 448 m_labelBrush(QBrush()),
426 449 m_diameter(5),
427 450 m_attachedToChart(true),
428 m_backgroundVisible(false)
451 m_backgroundVisible(false),
452 m_reverseMarkers(false)
429 453 {
430 454 m_items->setHandlesChildEvents(false);
431 455 }
@@ -42,6 +42,7 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
42 42 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
43 43 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
44 44 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
45 Q_PROPERTY(bool reverseMarkers READ reverseMarkers WRITE setReverseMarkers NOTIFY reverseMarkersChanged)
45 46
46 47 private:
47 48 explicit QLegend(QChart *chart);
@@ -81,6 +82,9 public:
81 82
82 83 QList <QLegendMarker*> markers(QAbstractSeries *series = 0) const;
83 84
85 bool reverseMarkers();
86 void setReverseMarkers(bool reverseMarkers = true);
87
84 88 protected:
85 89 void hideEvent(QHideEvent *event);
86 90 void showEvent(QShowEvent *event);
@@ -91,6 +95,7 Q_SIGNALS:
91 95 void borderColorChanged(QColor color);
92 96 void fontChanged(QFont font);
93 97 void labelColorChanged(QColor color);
98 void reverseMarkersChanged(bool reverseMarkers);
94 99
95 100 private:
96 101 QScopedPointer<QLegendPrivate> d_ptr;
@@ -82,6 +82,7 private:
82 82 qreal m_diameter;
83 83 bool m_attachedToChart;
84 84 bool m_backgroundVisible;
85 bool m_reverseMarkers;
85 86
86 87 QList<QLegendMarker *> m_markers;
87 88 QList<QAbstractSeries *> m_series;
@@ -420,6 +420,7 void tst_QChart::legend()
420 420 {
421 421 QLegend *legend = m_chart->legend();
422 422 QVERIFY(legend);
423 QVERIFY(!m_chart->legend()->reverseMarkers());
423 424
424 425 // Colors related signals
425 426 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
@@ -456,6 +457,13 void tst_QChart::legend()
456 457 f.setBold(!f.bold());
457 458 legend->setFont(f);
458 459 QCOMPARE(fontSpy.count(), 1);
460
461 // reverseMarkersChanged
462 QSignalSpy reverseMarkersSpy(legend, SIGNAL(reverseMarkersChanged(bool)));
463 QCOMPARE(reverseMarkersSpy.count(), 0);
464 legend->setReverseMarkers();
465 QCOMPARE(reverseMarkersSpy.count(), 1);
466 QVERIFY(legend->reverseMarkers());
459 467 }
460 468
461 469 void tst_QChart::plotArea_data()
@@ -55,6 +55,7 Rectangle {
55 55 compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible");
56 56 verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor");
57 57 verify(chartView.legend.color != undefined, "ChartView.legend.color");
58 compare(chartView.legend.reverseMarkers, false, "ChartView.legend.reverseMarkers");
58 59 // Legend font
59 60 compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold");
60 61 compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization");
@@ -52,6 +52,8 ChartView {
52 52 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
53 53 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
54 54 legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
55 legend.onReverseMarkersChanged: console.log("legend.onReverseMarkersChanged: "
56 + chart.legend.reverseMarkers)
55 57 margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top );
56 58 margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom);
57 59 margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left);
@@ -65,6 +65,10 Row {
65 65 text: "legend right"
66 66 onClicked: chartLegend.alignment = Qt.AlignRight;
67 67 }
68 Button {
69 text: "legend use reverse order"
70 onClicked: chartLegend.reverseMarkers = !chartLegend.reverseMarkers;
71 }
68 72 }
69 73
70 74 FontEditor {
@@ -52,6 +52,8 ChartView {
52 52 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
53 53 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
54 54 legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
55 legend.onReverseMarkersChanged: console.log("legend.onReverseMarkersChanged: "
56 + chart.legend.reverseMarkers)
55 57 margins.onTopChanged: console.log("chart.margins.onTopChanged: " + top );
56 58 margins.onBottomChanged: console.log("chart.margins.onBottomChanged: " + bottom);
57 59 margins.onLeftChanged: console.log("chart.margins.onLeftChanged: " + left);
@@ -65,6 +65,10 Row {
65 65 text: "legend right"
66 66 onClicked: chartLegend.alignment = Qt.AlignRight;
67 67 }
68 Button {
69 text: "legend use reverse order"
70 onClicked: chartLegend.reverseMarkers = !chartLegend.reverseMarkers;
71 }
68 72 }
69 73
70 74 FontEditor {
General Comments 0
You need to be logged in to leave comments. Login now