##// END OF EJS Templates
Added handling for pieslice add/remove to legend
sauimone -
r637:e242f9df3ad1
parent child
Show More
@@ -97,11 +97,14 void QLegend::handleSeriesAdded(QSeries* series, Domain* domain)
97
97
98 mSeriesList.append(series);
98 mSeriesList.append(series);
99 createMarkers(series);
99 createMarkers(series);
100 connectSeries(series);
100 layoutChanged();
101 layoutChanged();
101 }
102 }
102
103
103 void QLegend::handleSeriesRemoved(QSeries* series)
104 void QLegend::handleSeriesRemoved(QSeries* series)
104 {
105 {
106 disconnectSeries(series);
107
105 if (series->type() == QSeries::SeriesTypeArea)
108 if (series->type() == QSeries::SeriesTypeArea)
106 {
109 {
107 // This is special case. Area series has upper and lower series, which each have markers
110 // This is special case. Area series has upper and lower series, which each have markers
@@ -116,6 +119,122 void QLegend::handleSeriesRemoved(QSeries* series)
116 layoutChanged();
119 layoutChanged();
117 }
120 }
118
121
122 void QLegend::handleAdded(QList<QPieSlice*> slices)
123 {
124 QPieSeries* series = static_cast<QPieSeries*> (sender());
125 foreach(QPieSlice* s, slices) {
126 LegendMarker* marker = new LegendMarker(series,s,this);
127 marker->setName(s->label());
128 marker->setBrush(s->sliceBrush());
129 connect(marker,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)),this,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)));
130 connect(s,SIGNAL(changed()),marker,SLOT(changed()));
131 connect(s,SIGNAL(destroyed()),marker,SLOT(deleteLater()));
132 mMarkers.append(marker);
133 childItems().append(marker);
134 }
135 layoutChanged();
136 }
137
138 void QLegend::handleMarkerDestroyed()
139 {
140 // TODO: what if more than one markers are destroyed and we update layout after first one?
141 LegendMarker* m = static_cast<LegendMarker*> (sender());
142 mMarkers.removeOne(m);
143 layoutChanged();
144 }
145
146 void QLegend::connectSeries(QSeries *series)
147 {
148 // Connect relevant signals from series
149 switch (series->type())
150 {
151 case QSeries::SeriesTypeLine: {
152 // QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
153 break;
154 }
155 case QSeries::SeriesTypeArea: {
156 // QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
157 break;
158 }
159 case QSeries::SeriesTypeBar: {
160 // QBarSeries* barSeries = static_cast<QBarSeries*>(series);
161 break;
162 }
163 case QSeries::SeriesTypeStackedBar: {
164 // QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
165 break;
166 }
167 case QSeries::SeriesTypePercentBar: {
168 // QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
169 break;
170 }
171 case QSeries::SeriesTypeScatter: {
172 // QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
173 break;
174 }
175 case QSeries::SeriesTypePie: {
176 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
177 connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>)));
178 // connect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleRemoved(QList<QPieSlice*>)));
179 break;
180 }
181 case QSeries::SeriesTypeSpline: {
182 // QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
183 break;
184 }
185 default: {
186 qDebug()<< "QLegend::connectSeries" << series->type() << "not implemented.";
187 break;
188 }
189 }
190 }
191
192 void QLegend::disconnectSeries(QSeries *series)
193 {
194 // Connect relevant signals from series
195 switch (series->type())
196 {
197 case QSeries::SeriesTypeLine: {
198 // QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
199 break;
200 }
201 case QSeries::SeriesTypeArea: {
202 // QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
203 break;
204 }
205 case QSeries::SeriesTypeBar: {
206 // QBarSeries* barSeries = static_cast<QBarSeries*>(series);
207 break;
208 }
209 case QSeries::SeriesTypeStackedBar: {
210 // QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
211 break;
212 }
213 case QSeries::SeriesTypePercentBar: {
214 // QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
215 break;
216 }
217 case QSeries::SeriesTypeScatter: {
218 // QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
219 break;
220 }
221 case QSeries::SeriesTypePie: {
222 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
223 disconnect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>)));
224 // disconnect(pieSeries,SIGNAL(removed(QList<QPieSlice*>)),this,SLOT(handleRemoved(QList<QPieSlice*>)));
225 break;
226 }
227 case QSeries::SeriesTypeSpline: {
228 // QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
229 break;
230 }
231 default: {
232 qDebug()<< "QLegend::disconnectSeries" << series->type() << "not implemented.";
233 break;
234 }
235 }
236 }
237
119 void QLegend::createMarkers(QSeries *series)
238 void QLegend::createMarkers(QSeries *series)
120 {
239 {
121 switch (series->type())
240 switch (series->type())
@@ -181,6 +300,7 void QLegend::appendMarkers(QXYSeries* series)
181 marker->setName(series->name());
300 marker->setName(series->name());
182 marker->setBrush(series->brush());
301 marker->setBrush(series->brush());
183 connect(marker,SIGNAL(clicked(QSeries*,Qt::MouseButton)),this,SIGNAL(clicked(QSeries*,Qt::MouseButton)));
302 connect(marker,SIGNAL(clicked(QSeries*,Qt::MouseButton)),this,SIGNAL(clicked(QSeries*,Qt::MouseButton)));
303 connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed()));
184 mMarkers.append(marker);
304 mMarkers.append(marker);
185 childItems().append(marker);
305 childItems().append(marker);
186 }
306 }
@@ -193,6 +313,7 void QLegend::appendMarkers(QBarSeries *series)
193 marker->setBrush(s->brush());
313 marker->setBrush(s->brush());
194 connect(marker,SIGNAL(clicked(QBarSet*,Qt::MouseButton)),this,SIGNAL(clicked(QBarSet*,Qt::MouseButton)));
314 connect(marker,SIGNAL(clicked(QBarSet*,Qt::MouseButton)),this,SIGNAL(clicked(QBarSet*,Qt::MouseButton)));
195 connect(s,SIGNAL(changed()),marker,SLOT(changed()));
315 connect(s,SIGNAL(changed()),marker,SLOT(changed()));
316 connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed()));
196 mMarkers.append(marker);
317 mMarkers.append(marker);
197 childItems().append(marker);
318 childItems().append(marker);
198 }
319 }
@@ -206,6 +327,8 void QLegend::appendMarkers(QPieSeries *series)
206 marker->setBrush(s->sliceBrush());
327 marker->setBrush(s->sliceBrush());
207 connect(marker,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)),this,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)));
328 connect(marker,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)),this,SIGNAL(clicked(QPieSlice*,Qt::MouseButton)));
208 connect(s,SIGNAL(changed()),marker,SLOT(changed()));
329 connect(s,SIGNAL(changed()),marker,SLOT(changed()));
330 connect(s,SIGNAL(destroyed()),marker,SLOT(deleteLater()));
331 connect(marker,SIGNAL(destroyed()),this,SLOT(handleMarkerDestroyed()));
209 mMarkers.append(marker);
332 mMarkers.append(marker);
210 childItems().append(marker);
333 childItems().append(marker);
211 }
334 }
@@ -50,15 +50,20 signals:
50 public slots:
50 public slots:
51 void handleSeriesAdded(QSeries* series,Domain* domain);
51 void handleSeriesAdded(QSeries* series,Domain* domain);
52 void handleSeriesRemoved(QSeries* series);
52 void handleSeriesRemoved(QSeries* series);
53 void handleAdded(QList<QPieSlice*> slices);
54 // void handleRemoved(QList<QPieSlice*> slices);
55 void handleMarkerDestroyed();
53
56
54 private:
57 private:
55 // PIMPL --->
58 // PIMPL --->
59 void connectSeries(QSeries* series);
60 void disconnectSeries(QSeries* series);
56 void createMarkers(QSeries* series);
61 void createMarkers(QSeries* series);
57 void appendMarkers(QXYSeries* series); // All line series are derived from QXYSeries, so this works for now
62 void appendMarkers(QXYSeries* series); // All line series are derived from QXYSeries, so this works for now
58 void appendMarkers(QBarSeries* series);
63 void appendMarkers(QBarSeries* series);
59 void appendMarkers(QPieSeries* series);
64 void appendMarkers(QPieSeries* series);
60 void deleteMarkers(QSeries* series);
65 void deleteMarkers(QSeries* series);
61 void layoutChanged(); // TODO: rename this to layoutChanged and remove original layoutChanged, when ready
66 void layoutChanged();
62 // <--- PIMPL
67 // <--- PIMPL
63
68
64
69
General Comments 0
You need to be logged in to leave comments. Login now