##// END OF EJS Templates
handleThemeChanged slot to legend.
sauimone -
r586:306855f16f30
parent child
Show More
@@ -62,108 +62,102 void QLegend::setMinimumSize(const QSizeF size)
62 void QLegend::handleSeriesAdded(QSeries* series,Domain* domain)
62 void QLegend::handleSeriesAdded(QSeries* series,Domain* domain)
63 {
63 {
64 mSeriesList.append(series);
64 mSeriesList.append(series);
65 createMarkers(series);
66 layoutChanged();
67 }
68
69 void QLegend::handleSeriesRemoved(QSeries* series)
70 {
71 if (series->type() == QSeries::SeriesTypeArea)
72 {
73 // This is special case. Area series has upper and lower series, which each have markers
74 QAreaSeries* s = static_cast<QAreaSeries*> (series);
75 deleteMarkers(s->upperSeries());
76 deleteMarkers(s->lowerSeries());
77 } else {
78 deleteMarkers(series);
79 }
80
81 mSeriesList.removeOne(series);
82 layoutChanged();
83 }
84
85 void QLegend::handleGeometryChanged(const QRectF& size)
86 {
87 mBoundingRect = size;
88 layoutChanged();
89 }
65
90
91 void QLegend::handleThemeChanged()
92 {
93 foreach(QSeries *s, mSeriesList) {
94 deleteMarkers(s);
95 }
96 foreach(QSeries *s, mSeriesList) {
97 createMarkers(s);
98 }
99 }
100
101 void QLegend::createMarkers(QSeries *series)
102 {
66 switch (series->type())
103 switch (series->type())
67 {
104 {
68 case QSeries::SeriesTypeLine: {
105 case QSeries::SeriesTypeLine: {
69
70 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
106 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
71 createMarker(lineSeries);
107 appendMarkers(lineSeries);
72 break;
108 break;
73 }
109 }
74 case QSeries::SeriesTypeArea: {
110 case QSeries::SeriesTypeArea: {
75
76 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
111 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
77 createMarker(areaSeries->upperSeries());
112 appendMarkers(areaSeries->upperSeries());
78 if(areaSeries->lowerSeries())
113 if(areaSeries->lowerSeries())
79 createMarker(areaSeries->lowerSeries());
114 appendMarkers(areaSeries->lowerSeries());
80 break;
115 break;
81 }
116 }
82
117
83 case QSeries::SeriesTypeBar: {
118 case QSeries::SeriesTypeBar: {
84
85 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
119 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
86 createMarkers(barSeries);
120 appendMarkers(barSeries);
87 break;
121 break;
88 }
122 }
89
123
90 case QSeries::SeriesTypeStackedBar: {
124 case QSeries::SeriesTypeStackedBar: {
91
92 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
125 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
93 createMarkers(stackedBarSeries);
126 appendMarkers(stackedBarSeries);
94 break;
127 break;
95 }
128 }
96
129
97 case QSeries::SeriesTypePercentBar: {
130 case QSeries::SeriesTypePercentBar: {
98
99 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
131 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
100 createMarkers(percentBarSeries);
132 appendMarkers(percentBarSeries);
101 break;
133 break;
102 }
134 }
103
135
104 case QSeries::SeriesTypeScatter: {
136 case QSeries::SeriesTypeScatter: {
105
106 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
137 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
107 createMarker(scatterSeries);
138 appendMarkers(scatterSeries);
108 break;
139 break;
109 }
140 }
110
141
111 case QSeries::SeriesTypePie: {
142 case QSeries::SeriesTypePie: {
112
113 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
143 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
114 createMarkers(pieSeries);
144 appendMarkers(pieSeries);
115 break;
145 break;
116 }
146 }
117
147
118 case QSeries::SeriesTypeSpline: {
148 case QSeries::SeriesTypeSpline: {
119
120 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
149 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
121 createMarker(splineSeries);
150 appendMarkers(splineSeries);
122 break;
151 break;
123 }
152 }
124 default: {
153 default: {
125 qDebug()<< "QLegend::handleSeriesAdded" << series->type() << "not implemented.";
154 qDebug()<< "QLegend::createMarkers" << series->type() << "not implemented.";
126 break;
155 break;
127 }
156 }
128 }
157 }
129
130 layoutChanged();
131 }
132
133 void QLegend::handleSeriesRemoved(QSeries* series)
134 {
135 if (series->type() == QSeries::SeriesTypeArea)
136 {
137 // This is special case. Area series has upper and lower series, which each have markers
138 QAreaSeries* s = static_cast<QAreaSeries*> (series);
139 deleteMarkers(s->upperSeries());
140 deleteMarkers(s->lowerSeries());
141 } else {
142 deleteMarkers(series);
143 }
144
145 mSeriesList.removeOne(series);
146 layoutChanged();
147 }
148
149 void QLegend::handleGeometryChanged(const QRectF& size)
150 {
151 mBoundingRect = size;
152 layoutChanged();
153 }
154
155 void QLegend::deleteMarkers(QSeries *series)
156 {
157 // Search all markers that belong to given series and delete them.
158 foreach (LegendMarker *m, mMarkers) {
159 if (m->series() == series) {
160 mMarkers.removeOne(m);
161 delete m;
162 }
163 }
164 }
158 }
165
159
166 void QLegend::createMarker(QXYSeries* series)
160 void QLegend::appendMarkers(QXYSeries* series)
167 {
161 {
168 LegendMarker* marker = new LegendMarker(series,this);
162 LegendMarker* marker = new LegendMarker(series,this);
169 marker->setName(series->name());
163 marker->setName(series->name());
@@ -173,7 +167,7 void QLegend::createMarker(QXYSeries* series)
173 childItems().append(marker);
167 childItems().append(marker);
174 }
168 }
175
169
176 void QLegend::createMarkers(QBarSeries *series)
170 void QLegend::appendMarkers(QBarSeries *series)
177 {
171 {
178 foreach(QBarSet* s, series->barSets()) {
172 foreach(QBarSet* s, series->barSets()) {
179 LegendMarker* marker = new LegendMarker(series,s,this);
173 LegendMarker* marker = new LegendMarker(series,s,this);
@@ -185,7 +179,7 void QLegend::createMarkers(QBarSeries *series)
185 }
179 }
186 }
180 }
187
181
188 void QLegend::createMarkers(QPieSeries *series)
182 void QLegend::appendMarkers(QPieSeries *series)
189 {
183 {
190 foreach(QPieSlice* s, series->slices()) {
184 foreach(QPieSlice* s, series->slices()) {
191 LegendMarker* marker = new LegendMarker(series,s,this);
185 LegendMarker* marker = new LegendMarker(series,s,this);
@@ -197,6 +191,17 void QLegend::createMarkers(QPieSeries *series)
197 }
191 }
198 }
192 }
199
193
194 void QLegend::deleteMarkers(QSeries *series)
195 {
196 // Search all markers that belong to given series and delete them.
197 foreach (LegendMarker *m, mMarkers) {
198 if (m->series() == series) {
199 mMarkers.removeOne(m);
200 delete m;
201 }
202 }
203 }
204
200 void QLegend::layoutChanged()
205 void QLegend::layoutChanged()
201 {
206 {
202 // Calculate layout for markers and text
207 // Calculate layout for markers and text
@@ -42,11 +42,17 public slots:
42 void handleSeriesRemoved(QSeries* series);
42 void handleSeriesRemoved(QSeries* series);
43 void handleGeometryChanged(const QRectF& size);
43 void handleGeometryChanged(const QRectF& size);
44
44
45 // PIMPL --->
46 // Internal slot. Legend needs to know when theme has changed (or color of some series, if user changes it)
47 void handleThemeChanged();
48 // <--- PIMPL
49
45 private:
50 private:
46 // PIMPL --->
51 // PIMPL --->
47 void createMarker(QXYSeries* series);
52 void createMarkers(QSeries* series);
48 void createMarkers(QBarSeries* series);
53 void appendMarkers(QXYSeries* series);
49 void createMarkers(QPieSeries* series);
54 void appendMarkers(QBarSeries* series);
55 void appendMarkers(QPieSeries* series);
50 void deleteMarkers(QSeries* series);
56 void deleteMarkers(QSeries* series);
51 void layoutChanged();
57 void layoutChanged();
52 // <--- PIMPL
58 // <--- PIMPL
General Comments 0
You need to be logged in to leave comments. Login now