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