##// END OF EJS Templates
Fix worng slot signature in axis initilization
Michal Klocek -
r688:4ee85b7c4526
parent child
Show More
@@ -1,317 +1,317
1 1 #include "chartdataset_p.h"
2 2 #include "qchartaxis.h"
3 3 //series
4 4 #include "qlineseries.h"
5 5 #include "qareaseries.h"
6 6 #include "qbarseries.h"
7 7 #include "qstackedbarseries.h"
8 8 #include "qpercentbarseries.h"
9 9 #include "qpieseries.h"
10 10 #include "qscatterseries.h"
11 11 #include "qsplineseries.h"
12 12
13 13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 14
15 15 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
16 16 m_axisX(new QChartAxis(this)),
17 17 m_axisY(new QChartAxis(this)),
18 18 m_domainIndex(0),
19 19 m_axisXInitialized(false)
20 20 {
21 21 }
22 22
23 23 ChartDataSet::~ChartDataSet()
24 24 {
25 25 }
26 26
27 27 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
28 28 {
29 29 if(axisY==0) axisY = m_axisY;
30 30
31 31 QChartAxis* axis = m_seriesAxisMap.value(series);
32 32
33 33 if(axis) {
34 34 qWarning() << "Can not add series. Series already on the chart";
35 35 return;
36 36 }
37 37
38 38 if(!series->parent()){
39 39 series->setParent(this); // take ownership
40 40 };
41 41
42 42 if(!axisY->parent()){
43 43 axisY->setParent(this); // take ownership
44 44 }
45 45
46 46 Domain* domain = m_axisDomainMap.value(axisY);
47 47
48 48 if(!domain) {
49 49 domain = new Domain();
50 QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,QChartAxis::LabelsSelection)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,QChartAxis::LabelsSelection)));
51 QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,QChartAxis::LabelsSelection)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,QChartAxis::LabelsSelection)));
50 QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
51 QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
52 52 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int)));
53 53 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
54 54 //initialize
55 55 m_axisDomainMap.insert(axisY,domain);
56 56 emit axisAdded(axisY,domain);
57 57 }
58 58
59 59 if(!m_axisXInitialized){
60 60 emit axisAdded(axisX(),domain);
61 61 m_axisXInitialized=true;
62 62 }
63 63
64 64 calculateDomain(series,domain);
65 65
66 66 m_seriesAxisMap.insert(series,axisY);
67 67 emit seriesAdded(series,domain);
68 68
69 69 }
70 70
71 71 void ChartDataSet::removeSeries(QSeries* series)
72 72 {
73 73
74 74 QChartAxis* axis = m_seriesAxisMap.value(series);
75 75
76 76 if(!axis){
77 77 qWarning()<<"Can not remove series. Series not found on the chart.";
78 78 return;
79 79 }
80 80 emit seriesRemoved(series);
81 81 m_seriesAxisMap.remove(series);
82 82
83 83 if(series->parent()==this){
84 84 delete series;
85 85 series=0;
86 86 }
87 87
88 88 QList<QChartAxis*> axes = m_seriesAxisMap.values();
89 89
90 90 int i = axes.indexOf(axis);
91 91
92 92 if(i==-1){
93 93 Domain* domain = m_axisDomainMap.take(axis);
94 94 emit axisRemoved(axis);
95 95 if(axis!=axisY()){
96 96 if(axis->parent()==this){
97 97 delete axis;
98 98 axis=0;
99 99 }
100 100 }
101 101 delete domain;
102 102 }
103 103
104 104 if(m_seriesAxisMap.values().size()==0)
105 105 {
106 106 m_axisXInitialized=false;
107 107 emit axisRemoved(axisX());
108 108 }
109 109 }
110 110
111 111 void ChartDataSet::removeAllSeries()
112 112 {
113 113
114 114 QList<QSeries*> series = m_seriesAxisMap.keys();
115 115
116 116 foreach(QSeries* s , series) {
117 117 removeSeries(s);
118 118 }
119 119
120 120 Q_ASSERT(m_seriesAxisMap.count()==0);
121 121 Q_ASSERT(m_axisDomainMap.count()==0);
122 122
123 123 }
124 124
125 125 //to be removed with PIMPL
126 126 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) const
127 127 {
128 128 switch(series->type())
129 129 {
130 130 case QSeries::SeriesTypeLine:
131 131 case QSeries::SeriesTypeSpline:
132 132 case QSeries::SeriesTypeScatter:
133 133 {
134 134
135 135 QXYSeries* xySeries = static_cast<QXYSeries*>(series);
136 136
137 137 qreal minX(domain->minX());
138 138 qreal minY(domain->minY());
139 139 qreal maxX(domain->maxX());
140 140 qreal maxY(domain->maxY());
141 141
142 142 for (int i = 0; i < xySeries->count(); i++)
143 143 {
144 144 qreal x = xySeries->x(i);
145 145 qreal y = xySeries->y(i);
146 146 minX = qMin(minX, x);
147 147 minY = qMin(minY, y);
148 148 maxX = qMax(maxX, x);
149 149 maxY = qMax(maxY, y);
150 150 }
151 151
152 152 domain->setRange(minX, maxX, minY, maxY);
153 153 break;
154 154 }
155 155 case QSeries::SeriesTypeArea: {
156 156
157 157 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
158 158
159 159 QLineSeries* upperSeries = areaSeries->upperSeries();
160 160 QLineSeries* lowerSeries = areaSeries->lowerSeries();
161 161
162 162 for (int i = 0; i < upperSeries->count(); i++)
163 163 {
164 164 qreal x = upperSeries->x(i);
165 165 qreal y = upperSeries->y(i);
166 166 domain->setMinX(qMin(domain->minX(),x));
167 167 domain->setMinY(qMin(domain->minY(),y));
168 168 domain->setMaxX(qMax(domain->maxX(),x));
169 169 domain->setMaxY(qMax(domain->maxY(),y));
170 170 }
171 171 if(lowerSeries) {
172 172 for (int i = 0; i < lowerSeries->count(); i++)
173 173 {
174 174 qreal x = lowerSeries->x(i);
175 175 qreal y = lowerSeries->y(i);
176 176 domain->setMinX(qMin(domain->minX(),x));
177 177 domain->setMinY(qMin(domain->minY(),y));
178 178 domain->setMaxX(qMax(domain->maxX(),x));
179 179 domain->setMaxY(qMax(domain->maxY(),y));
180 180 }}
181 181 break;
182 182 }
183 183 case QSeries::SeriesTypeBar: {
184 184 qDebug() << "QChartSeries::SeriesTypeBar";
185 185 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
186 186 qreal x = barSeries->categoryCount();
187 187 qreal y = barSeries->max();
188 188 domain->setMinX(qMin(domain->minX(),x));
189 189 domain->setMinY(qMin(domain->minY(),y));
190 190 domain->setMaxX(qMax(domain->maxX(),x));
191 191 domain->setMaxY(qMax(domain->maxY(),y));
192 192 break;
193 193 }
194 194 case QSeries::SeriesTypeStackedBar: {
195 195 qDebug() << "QChartSeries::SeriesTypeStackedBar";
196 196
197 197 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
198 198 qreal x = stackedBarSeries->categoryCount();
199 199 qreal y = stackedBarSeries->maxCategorySum();
200 200 domain->setMinX(qMin(domain->minX(),x));
201 201 domain->setMinY(qMin(domain->minY(),y));
202 202 domain->setMaxX(qMax(domain->maxX(),x));
203 203 domain->setMaxY(qMax(domain->maxY(),y));
204 204 break;
205 205 }
206 206 case QSeries::SeriesTypePercentBar: {
207 207 qDebug() << "QChartSeries::SeriesTypePercentBar";
208 208
209 209 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
210 210 qreal x = percentBarSeries->categoryCount();
211 211 domain->setMinX(qMin(domain->minX(),x));
212 212 domain->setMinY(0);
213 213 domain->setMaxX(qMax(domain->maxX(),x));
214 214 domain->setMaxY(100);
215 215 break;
216 216 }
217 217
218 218 case QSeries::SeriesTypePie: {
219 219 //QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
220 220 // TODO: domain stuff
221 221 break;
222 222 }
223 223
224 224
225 225 default: {
226 226 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
227 227 return;
228 228 break;
229 229 }
230 230
231 231 }
232 232 }
233 233
234 234 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
235 235 {
236 236 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
237 237 while (i.hasNext()) {
238 238 i.next();
239 239 i.value()->zoomIn(rect,size);
240 240 }
241 241 }
242 242
243 243 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
244 244 {
245 245 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
246 246 while (i.hasNext()) {
247 247 i.next();
248 248 i.value()->zoomOut(rect,size);
249 249 }
250 250 }
251 251
252 252 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
253 253 {
254 254 int count=0;
255 255 QMapIterator<QSeries*, QChartAxis*> i( m_seriesAxisMap);
256 256 while (i.hasNext()) {
257 257 i.next();
258 258 if(i.key()->type()==type) count++;
259 259 }
260 260 return count;
261 261 }
262 262
263 263 int ChartDataSet::seriesIndex(QSeries *series)
264 264 {
265 265 int count(-1);
266 266 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
267 267 while (i.hasNext()) {
268 268 i.next();
269 269 count++;
270 270 if (i.key() == series)
271 271 return count;
272 272 }
273 273 return count;
274 274 }
275 275
276 276 QChartAxis* ChartDataSet::axisY(QSeries* series) const
277 277 {
278 278 if(series == 0) return m_axisY;
279 279 return m_seriesAxisMap.value(series);
280 280 }
281 281
282 282 Domain* ChartDataSet::domain(QSeries* series) const
283 283 {
284 284 QChartAxis* axis = m_seriesAxisMap.value(series);
285 285 if(axis){
286 286 return m_axisDomainMap.value(axis);
287 287 }else
288 288 return 0;
289 289 }
290 290
291 291 Domain* ChartDataSet::domain(QChartAxis* axis) const
292 292 {
293 293 if(axis==axisX()) {
294 294 return m_axisDomainMap.value(axisY());
295 295 }
296 296 else {
297 297 return m_axisDomainMap.value(axis);
298 298 }
299 299 }
300 300
301 301 QChartAxis* ChartDataSet::axis(QSeries* series) const
302 302 {
303 303 return m_seriesAxisMap.value(series);
304 304 }
305 305
306 306 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
307 307 {
308 308 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
309 309 while (i.hasNext()) {
310 310 i.next();
311 311 i.value()->move(dx,dy,size);
312 312 }
313 313 }
314 314
315 315 #include "moc_chartdataset_p.cpp"
316 316
317 317 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now