##// END OF EJS Templates
Visible property to abstract series
Tero Ahola -
r1342:8e3983e15cdc
parent child
Show More
@@ -27,7 +27,7 Rectangle {
27 27 height: parent.height
28 28
29 29 ChartView {
30 id: chart
30 id: chartView
31 31 title: "Top-5 car brand shares in Finland"
32 32 anchors.fill: parent
33 33 theme: ChartView.ChartThemeLight
@@ -53,6 +53,7 Rectangle {
53 53 BarSeries {
54 54 name: "Others"
55 55 barMargin: 0
56 visible: false
56 57 HBarModelMapper {
57 58 model: customModel
58 59 firstBarSetRow: 6
@@ -62,10 +63,9 Rectangle {
62 63 }
63 64
64 65 LineSeries {
65 id: lineSeries
66 66 name: "Volkswagen"
67 visible: false
67 68 HXYModelMapper {
68 id: lineSeriesMapper
69 69 model: customModel
70 70 xRow: 0
71 71 yRow: 1
@@ -73,6 +73,50 Rectangle {
73 73 }
74 74 }
75 75
76 LineSeries {
77 name: "Toyota"
78 visible: false
79 HXYModelMapper {
80 model: customModel
81 xRow: 0
82 yRow: 2
83 first: 2
84 }
85 }
86
87 LineSeries {
88 name: "Ford"
89 visible: false
90 HXYModelMapper {
91 model: customModel
92 xRow: 0
93 yRow: 2
94 first: 2
95 }
96 }
97
98 LineSeries {
99 name: "Skoda"
100 visible: false
101 HXYModelMapper {
102 model: customModel
103 xRow: 0
104 yRow: 3
105 first: 2
106 }
107 }
108
109 LineSeries {
110 name: "Volvo"
111 visible: false
112 HXYModelMapper {
113 model: customModel
114 xRow: 0
115 yRow: 4
116 first: 2
117 }
118 }
119
76 120 PieSeries {
77 121 id: pieSeries
78 122 size: 0.4
@@ -80,15 +124,12 Rectangle {
80 124 verticalPosition: 0.4
81 125 onClicked: {
82 126 // Show the selection by exploding the slice
83 for (var i = 0; i < pieSeries.count; i++)
84 pieSeries.at(i).exploded = false;
85 slice.exploded = true;
127 slice.exploded = !slice.exploded;
86 128
87 129 // Update the line series to show the yearly data for this slice
88 lineSeries.name = slice.label;
89 for (var j = 0; j < customModel.rowCount; j++) {
90 if (customModel.at(j, 1) == slice.label) {
91 lineSeriesMapper.yRow = j;
130 for (var i = 0; i < chartView.count; i++) {
131 if (chartView.series(i).name == slice.label) {
132 chartView.series(i).visible = slice.exploded;
92 133 }
93 134 }
94 135 }
@@ -45,6 +45,7 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter)
45 45 m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter);
46 46
47 47 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
48 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
48 49 QObject::connect(this,SIGNAL(clicked(QPointF)),areaSeries,SIGNAL(clicked(QPointF)));
49 50
50 51 handleUpdated();
@@ -119,6 +120,7 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
119 120 Q_UNUSED(widget)
120 121 Q_UNUSED(option)
121 122
123 if (m_series->isVisible()) {
122 124 painter->save();
123 125 painter->setPen(m_linePen);
124 126 painter->setBrush(m_brush);
@@ -132,6 +134,7 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
132 134 }
133 135 painter->restore();
134 136 }
137 }
135 138
136 139 void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
137 140 {
@@ -40,6 +40,7 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
40 40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
41 41 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
42 42 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
43 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleLayoutChanged()));
43 44 setZValue(ChartPresenter::BarSeriesZValue);
44 45 handleDataStructureChanged();
45 46 }
@@ -183,24 +183,6 QList<QBarSet*> QBarSeries::barSets() const
183 183 }
184 184
185 185 /*!
186 Sets the visibility of series to \a visible
187 */
188 void QBarSeries::setVisible(bool visible)
189 {
190 Q_D(QBarSeries);
191 d->setVisible(visible);
192 }
193
194 /*!
195 Returns the visibility of series
196 */
197 bool QBarSeries::isVisible() const
198 {
199 Q_D(const QBarSeries);
200 return d->isVisible();
201 }
202
203 /*!
204 186 Sets the visibility of labels in series to \a visible
205 187 */
206 188 void QBarSeries::setLabelsVisible(bool visible)
@@ -34,8 +34,7 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
34 34 {
35 35 Q_OBJECT
36 36 Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin)
37 Q_PROPERTY(int count READ barsetCount) // TODO: categoryCount to be removed
38 Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
37 Q_PROPERTY(int count READ barsetCount)
39 38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible)
40 39
41 40 public:
@@ -55,8 +54,6 public:
55 54 QList<QBarSet*> barSets() const;
56 55 void clear();
57 56
58 void setVisible(bool visible = true);
59 bool isVisible() const;
60 57 void setLabelsVisible(bool visible = true);
61 58 bool isLabelsVisible() const;
62 59
@@ -37,6 +37,7 m_pointsVisible(false)
37 37 {
38 38 setZValue(ChartPresenter::LineChartZValue);
39 39 QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
40 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
40 41 handleUpdated();
41 42 }
42 43
@@ -90,6 +91,7 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
90 91 Q_UNUSED(widget)
91 92 Q_UNUSED(option)
92 93
94 if (m_series->isVisible()) {
93 95 painter->save();
94 96 painter->setPen(m_linePen);
95 97 painter->setClipRect(clipRect());
@@ -100,6 +102,7 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
100 102 }
101 103 painter->restore();
102 104 }
105 }
103 106
104 107 void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
105 108 {
@@ -100,7 +100,7 void QAbstractSeries::setName(const QString& name)
100 100 {
101 101 if (name != d_ptr->m_name) {
102 102 d_ptr->m_name = name;
103 nameChanged();
103 emit nameChanged();
104 104 }
105 105 }
106 106
@@ -114,6 +114,25 QString QAbstractSeries::name() const
114 114 }
115 115
116 116 /*!
117 Sets the visibility of series to \a visible
118 */
119 void QAbstractSeries::setVisible(bool visible)
120 {
121 if (visible != d_ptr->m_visible) {
122 d_ptr->m_visible = visible;
123 emit visibleChanged();
124 }
125 }
126
127 /*!
128 Returns the visibility of series
129 */
130 bool QAbstractSeries::isVisible() const
131 {
132 return d_ptr->m_visible;
133 }
134
135 /*!
117 136 \brief Returns the chart where series belongs to.
118 137
119 138 Set automatically when the series is added to the chart
@@ -129,7 +148,8 QChart* QAbstractSeries::chart() const
129 148 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
130 149 q_ptr(q),
131 150 m_chart(0),
132 m_dataset(0)
151 m_dataset(0),
152 m_visible(true)
133 153 {
134 154 }
135 155
@@ -34,6 +34,7 class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject
34 34 {
35 35 Q_OBJECT
36 36 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
37 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 38 Q_ENUMS(SeriesType)
38 39
39 40 public:
@@ -57,10 +58,13 public:
57 58 virtual SeriesType type() const = 0;
58 59 void setName(const QString& name);
59 60 QString name() const;
61 void setVisible(bool visible = true);
62 bool isVisible() const;
60 63 QChart* chart() const;
61 64
62 65 Q_SIGNALS:
63 66 void nameChanged();
67 void visibleChanged();
64 68
65 69 protected:
66 70 QScopedPointer<QAbstractSeriesPrivate> d_ptr;
@@ -57,6 +57,7 protected:
57 57 QChart *m_chart;
58 58 ChartDataSet *m_dataset;
59 59 QString m_name;
60 bool m_visible;
60 61
61 62 friend class QAbstractSeries;
62 63 friend class ChartDataSet;
@@ -38,6 +38,7 m_shape(QScatterSeries::MarkerShapeRectangle),
38 38 m_size(15)
39 39 {
40 40 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated()));
41 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
41 42
42 43 setZValue(ChartPresenter::ScatterSeriesZValue);
43 44 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
@@ -36,6 +36,7 m_animation(0)
36 36 {
37 37 setZValue(ChartPresenter::LineChartZValue);
38 38 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
39 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
39 40 handleUpdated();
40 41 }
41 42
@@ -147,6 +148,7 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
147 148 {
148 149 Q_UNUSED(widget)
149 150 Q_UNUSED(option)
151 if (m_series->isVisible()) {
150 152 painter->save();
151 153 painter->setClipRect(clipRect());
152 154 painter->setPen(m_linePen);
@@ -157,6 +159,7 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
157 159 }
158 160 painter->restore();
159 161 }
162 }
160 163
161 164 void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
162 165 {
@@ -90,8 +90,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
90 90 */
91 91 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
92 92 {
93
94 93 }
94
95 95 /*!
96 96 Destroys the object. Series added to QChartView or QChart instances are owned by those,
97 97 and are deleted when mentioned object are destroyed.
@@ -401,7 +401,6 void tst_QBarSet::customize()
401 401 // Test adding data to the sets
402 402 *set1 << 1 << 2 << 1 << 3;
403 403 *set2 << 2 << 1 << 3 << 1;
404 QTest::qWait(3000);
405 404 }
406 405
407 406 QTEST_MAIN(tst_QBarSet)
@@ -348,3 +348,15 void tst_QXYSeries::pointsVisible_raw()
348 348 TRY_COMPARE(spy0.count(), 0);
349 349 QCOMPARE(m_series->pointsVisible(), pointsVisible);
350 350 }
351
352 void tst_QXYSeries::changedSignals()
353 {
354 QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged()));
355
356 m_series->setVisible(false);
357 m_series->setVisible(false);
358 TRY_COMPARE(visibleSpy.count(), 1);
359 m_series->setVisible(true);
360 TRY_COMPARE(visibleSpy.count(), 2);
361 }
362
@@ -74,6 +74,7 private slots:
74 74 void replace_chart();
75 75 void replace_chart_animation_data();
76 76 void replace_chart_animation();
77 void changedSignals();
77 78 protected:
78 79 void append_data();
79 80 void count_data();
@@ -29,6 +29,10 Flow {
29 29 property variant series
30 30
31 31 Button {
32 text: "visible"
33 onClicked: series.visible = !series.visible;
34 }
35 Button {
32 36 text: "color"
33 37 onClicked: series.color = main.nextColor();
34 38 }
@@ -28,18 +28,6 Flow {
28 28 property variant series
29 29
30 30 Button {
31 text: "set 1 color"
32 onClicked: series.at(0).color = main.nextColor();
33 }
34 Button {
35 text: "set 1 border color"
36 onClicked: series.at(0).borderColor = main.nextColor();
37 }
38 Button {
39 text: "set 1 label color"
40 onClicked: series.at(0).labelColor = main.nextColor();
41 }
42 Button {
43 31 text: "visible"
44 32 onClicked: series.visible = !series.visible;
45 33 }
@@ -56,6 +44,18 Flow {
56 44 onClicked: series.barMargin -= 0.1;
57 45 }
58 46 Button {
47 text: "set 1 color"
48 onClicked: series.at(0).color = main.nextColor();
49 }
50 Button {
51 text: "set 1 border color"
52 onClicked: series.at(0).borderColor = main.nextColor();
53 }
54 Button {
55 text: "set 1 label color"
56 onClicked: series.at(0).labelColor = main.nextColor();
57 }
58 Button {
59 59 text: "set 1 font size +"
60 60 onClicked: series.at(0).labelFont.pixelSize += 1;
61 61 }
@@ -29,6 +29,10 Flow {
29 29 property variant series
30 30
31 31 Button {
32 text: "visible"
33 onClicked: series.visible = !series.visible;
34 }
35 Button {
32 36 text: "color"
33 37 onClicked: series.color = main.nextColor();
34 38 }
@@ -28,6 +28,50 Flow {
28 28 property variant series
29 29
30 30 Button {
31 text: "visible"
32 onClicked: series.visible = !series.visible;
33 }
34 Button {
35 text: "series hpos +"
36 onClicked: series.horizontalPosition += 0.1;
37 }
38 Button {
39 text: "series hpos -"
40 onClicked: series.horizontalPosition -= 0.1;
41 }
42 Button {
43 text: "series vpos +"
44 onClicked: series.verticalPosition += 0.1;
45 }
46 Button {
47 text: "series vpos -"
48 onClicked: series.verticalPosition -= 0.1;
49 }
50 Button {
51 text: "series size +"
52 onClicked: series.size += 0.1;
53 }
54 Button {
55 text: "series size -"
56 onClicked: series.size -= 0.1;
57 }
58 Button {
59 text: "series start angle +"
60 onClicked: series.startAngle += 0.1;
61 }
62 Button {
63 text: "series start angle -"
64 onClicked: series.startAngle -= 0.1;
65 }
66 Button {
67 text: "series end angle +"
68 onClicked: series.endAngle += 0.1;
69 }
70 Button {
71 text: "series end angle -"
72 onClicked: series.endAngle -= 0.1;
73 }
74 Button {
31 75 text: "slice color"
32 76 onClicked: series.at(0).color = main.nextColor();
33 77 }
@@ -71,44 +115,4 Flow {
71 115 text: "slice explode dist -"
72 116 onClicked: series.at(0).explodeDistanceFactor -= 0.1;
73 117 }
74 Button {
75 text: "series hpos +"
76 onClicked: series.horizontalPosition += 0.1;
77 }
78 Button {
79 text: "series hpos -"
80 onClicked: series.horizontalPosition -= 0.1;
81 }
82 Button {
83 text: "series vpos +"
84 onClicked: series.verticalPosition += 0.1;
85 }
86 Button {
87 text: "series vpos -"
88 onClicked: series.verticalPosition -= 0.1;
89 }
90 Button {
91 text: "series size +"
92 onClicked: series.size += 0.1;
93 }
94 Button {
95 text: "series size -"
96 onClicked: series.size -= 0.1;
97 }
98 Button {
99 text: "series start angle +"
100 onClicked: series.startAngle += 0.1;
101 }
102 Button {
103 text: "series start angle -"
104 onClicked: series.startAngle -= 0.1;
105 }
106 Button {
107 text: "series end angle +"
108 onClicked: series.endAngle += 0.1;
109 }
110 Button {
111 text: "series end angle -"
112 onClicked: series.endAngle -= 0.1;
113 }
114 118 }
@@ -29,6 +29,10 Flow {
29 29 property variant series
30 30
31 31 Button {
32 text: "visible"
33 onClicked: series.visible = !series.visible;
34 }
35 Button {
32 36 text: "color"
33 37 onClicked: series.color = main.nextColor();
34 38 }
General Comments 0
You need to be logged in to leave comments. Login now