##// END OF EJS Templates
Bugfix , fix warnging from CppCheck
Michal Klocek -
r781:87c44aec5e79
parent child
Show More
@@ -1,62 +1,61
1 #include "qchartaxiscategories.h"
1 #include "qchartaxiscategories.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 QChartAxisCategories::QChartAxisCategories()
5 QChartAxisCategories::QChartAxisCategories()
6 {
6 {
7 // TODO Auto-generated constructor stub
7 // TODO Auto-generated constructor stub
8
8
9 }
9 }
10
10
11 QChartAxisCategories::~QChartAxisCategories()
11 QChartAxisCategories::~QChartAxisCategories()
12 {
12 {
13 // TODO Auto-generated destructor stub
13 // TODO Auto-generated destructor stub
14 }
14 }
15
15
16 void QChartAxisCategories::insert(const QBarCategories &categories)
16 void QChartAxisCategories::insert(const QBarCategories &categories)
17 {
17 {
18 int i=1;
18 int i=1;
19 foreach (QString string , categories) {
19 foreach (QString string , categories) {
20 m_map.insert(i,string);
20 m_map.insert(i,string);
21 i++;
21 i++;
22 }
22 }
23 emit updated();
23 emit updated();
24 }
24 }
25
25
26 void QChartAxisCategories::insert(qreal value,QString label)
26 void QChartAxisCategories::insert(qreal value,QString label)
27 {
27 {
28 m_map.insert(value,label);
28 m_map.insert(value,label);
29 emit updated();
29 emit updated();
30 }
30 }
31
31
32 void QChartAxisCategories::remove(qreal value)
32 void QChartAxisCategories::remove(qreal value)
33 {
33 {
34 m_map.remove(value);
34 m_map.remove(value);
35 emit updated();
35 emit updated();
36 }
36 }
37
37
38 void QChartAxisCategories::clear()
38 void QChartAxisCategories::clear()
39 {
39 {
40 m_map.clear();
40 m_map.clear();
41 emit updated();
41 emit updated();
42 }
42 }
43
43
44 int QChartAxisCategories::count()
44 int QChartAxisCategories::count()
45 {
45 {
46 return m_map.count();
46 return m_map.count();
47 emit updated();
48 }
47 }
49
48
50 QList<qreal> QChartAxisCategories::values() const
49 QList<qreal> QChartAxisCategories::values() const
51 {
50 {
52 return m_map.keys();
51 return m_map.keys();
53 }
52 }
54
53
55 QString QChartAxisCategories::label(qreal value) const
54 QString QChartAxisCategories::label(qreal value) const
56 {
55 {
57 return m_map.value(value);
56 return m_map.value(value);
58 }
57 }
59
58
60 #include "moc_qchartaxiscategories.cpp"
59 #include "moc_qchartaxiscategories.cpp"
61
60
62 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,346 +1,345
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchartaxis.h"
22 #include "qchartaxis.h"
23 //series
23 //series
24 #include "qlineseries.h"
24 #include "qlineseries.h"
25 #include "qareaseries.h"
25 #include "qareaseries.h"
26 #include "qbarseries.h"
26 #include "qbarseries.h"
27 #include "qstackedbarseries.h"
27 #include "qstackedbarseries.h"
28 #include "qpercentbarseries.h"
28 #include "qpercentbarseries.h"
29 #include "qpieseries.h"
29 #include "qpieseries.h"
30 #include "qscatterseries.h"
30 #include "qscatterseries.h"
31 #include "qsplineseries.h"
31 #include "qsplineseries.h"
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
35 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
36 m_axisX(new QChartAxis(this)),
36 m_axisX(new QChartAxis(this)),
37 m_axisY(new QChartAxis(this)),
37 m_axisY(new QChartAxis(this)),
38 m_domainIndex(0),
38 m_domainIndex(0),
39 m_axisXInitialized(false)
39 m_axisXInitialized(false)
40 {
40 {
41 }
41 }
42
42
43 ChartDataSet::~ChartDataSet()
43 ChartDataSet::~ChartDataSet()
44 {
44 {
45 }
45 }
46
46
47 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
47 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
48 {
48 {
49 if(axisY==0) axisY = m_axisY;
49 if(axisY==0) axisY = m_axisY;
50
50
51 QChartAxis* axis = m_seriesAxisMap.value(series);
51 QChartAxis* axis = m_seriesAxisMap.value(series);
52
52
53 if(axis) {
53 if(axis) {
54 qWarning() << "Can not add series. Series already on the chart";
54 qWarning() << "Can not add series. Series already on the chart";
55 return;
55 return;
56 }
56 }
57
57
58 if(!series->parent()){
58 if(!series->parent()){
59 series->setParent(this); // take ownership
59 series->setParent(this); // take ownership
60 };
60 };
61
61
62 if(!axisY->parent()){
62 if(!axisY->parent()){
63 axisY->setParent(this); // take ownership
63 axisY->setParent(this); // take ownership
64 }
64 }
65
65
66 Domain* domain = m_axisDomainMap.value(axisY);
66 Domain* domain = m_axisDomainMap.value(axisY);
67
67
68 if(!domain) {
68 if(!domain) {
69 domain = new Domain();
69 domain = new Domain();
70 QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
70 QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
71 QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
71 QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
72 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int)));
72 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int)));
73 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
73 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
74 //initialize
74 //initialize
75 m_axisDomainMap.insert(axisY,domain);
75 m_axisDomainMap.insert(axisY,domain);
76 emit axisAdded(axisY,domain);
76 emit axisAdded(axisY,domain);
77 }
77 }
78
78
79 if(!m_axisXInitialized){
79 if(!m_axisXInitialized){
80 emit axisAdded(axisX(),domain);
80 emit axisAdded(axisX(),domain);
81 m_axisXInitialized=true;
81 m_axisXInitialized=true;
82 }
82 }
83
83
84 calculateDomain(series,domain);
84 calculateDomain(series,domain);
85
85
86 m_seriesAxisMap.insert(series,axisY);
86 m_seriesAxisMap.insert(series,axisY);
87 emit seriesAdded(series,domain);
87 emit seriesAdded(series,domain);
88
88
89 }
89 }
90
90
91 void ChartDataSet::removeSeries(QSeries* series)
91 void ChartDataSet::removeSeries(QSeries* series)
92 {
92 {
93
93
94 QChartAxis* axis = m_seriesAxisMap.value(series);
94 QChartAxis* axis = m_seriesAxisMap.value(series);
95
95
96 if(!axis){
96 if(!axis){
97 qWarning()<<"Can not remove series. Series not found on the chart.";
97 qWarning()<<"Can not remove series. Series not found on the chart.";
98 return;
98 return;
99 }
99 }
100 emit seriesRemoved(series);
100 emit seriesRemoved(series);
101 m_seriesAxisMap.remove(series);
101 m_seriesAxisMap.remove(series);
102
102
103 if(series->parent()==this){
103 if(series->parent()==this){
104 delete series;
104 delete series;
105 series=0;
105 series=0;
106 }
106 }
107
107
108 QList<QChartAxis*> axes = m_seriesAxisMap.values();
108 QList<QChartAxis*> axes = m_seriesAxisMap.values();
109
109
110 int i = axes.indexOf(axis);
110 int i = axes.indexOf(axis);
111
111
112 if(i==-1){
112 if(i==-1){
113 Domain* domain = m_axisDomainMap.take(axis);
113 Domain* domain = m_axisDomainMap.take(axis);
114 emit axisRemoved(axis);
114 emit axisRemoved(axis);
115 if(axis!=axisY()){
115 if(axis!=axisY()){
116 if(axis->parent()==this){
116 if(axis->parent()==this){
117 delete axis;
117 delete axis;
118 axis=0;
118 axis=0;
119 }
119 }
120 }
120 }
121 delete domain;
121 delete domain;
122 }
122 }
123
123
124 if(m_seriesAxisMap.values().size()==0)
124 if(m_seriesAxisMap.values().size()==0)
125 {
125 {
126 m_axisXInitialized=false;
126 m_axisXInitialized=false;
127 emit axisRemoved(axisX());
127 emit axisRemoved(axisX());
128 }
128 }
129 }
129 }
130
130
131 void ChartDataSet::removeAllSeries()
131 void ChartDataSet::removeAllSeries()
132 {
132 {
133
133
134 QList<QSeries*> series = m_seriesAxisMap.keys();
134 QList<QSeries*> series = m_seriesAxisMap.keys();
135
135
136 foreach(QSeries* s , series) {
136 foreach(QSeries* s , series) {
137 removeSeries(s);
137 removeSeries(s);
138 }
138 }
139
139
140 Q_ASSERT(m_seriesAxisMap.count()==0);
140 Q_ASSERT(m_seriesAxisMap.count()==0);
141 Q_ASSERT(m_axisDomainMap.count()==0);
141 Q_ASSERT(m_axisDomainMap.count()==0);
142
142
143 }
143 }
144
144
145 //to be removed with PIMPL
145 //to be removed with PIMPL
146 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain)
146 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain)
147 {
147 {
148 qreal minX(domain->minX());
148 qreal minX(domain->minX());
149 qreal minY(domain->minY());
149 qreal minY(domain->minY());
150 qreal maxX(domain->maxX());
150 qreal maxX(domain->maxX());
151 qreal maxY(domain->maxY());
151 qreal maxY(domain->maxY());
152 int tickXCount(domain->tickXCount());
152 int tickXCount(domain->tickXCount());
153 int tickYCount(domain->tickYCount());
153 int tickYCount(domain->tickYCount());
154
154
155
155
156 switch(series->type())
156 switch(series->type())
157 {
157 {
158 case QSeries::SeriesTypeLine:
158 case QSeries::SeriesTypeLine:
159 case QSeries::SeriesTypeSpline:
159 case QSeries::SeriesTypeSpline:
160 case QSeries::SeriesTypeScatter:
160 case QSeries::SeriesTypeScatter:
161 {
161 {
162
162
163 QXYSeries* xySeries = static_cast<QXYSeries*>(series);
163 QXYSeries* xySeries = static_cast<QXYSeries*>(series);
164
164
165 for (int i = 0; i < xySeries->count(); i++)
165 for (int i = 0; i < xySeries->count(); i++)
166 {
166 {
167 qreal x = xySeries->x(i);
167 qreal x = xySeries->x(i);
168 qreal y = xySeries->y(i);
168 qreal y = xySeries->y(i);
169 minX = qMin(minX, x);
169 minX = qMin(minX, x);
170 minY = qMin(minY, y);
170 minY = qMin(minY, y);
171 maxX = qMax(maxX, x);
171 maxX = qMax(maxX, x);
172 maxY = qMax(maxY, y);
172 maxY = qMax(maxY, y);
173 }
173 }
174 break;
174 break;
175 }
175 }
176 case QSeries::SeriesTypeArea: {
176 case QSeries::SeriesTypeArea: {
177
177
178 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
178 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
179 QLineSeries* upperSeries = areaSeries->upperSeries();
179 QLineSeries* upperSeries = areaSeries->upperSeries();
180 QLineSeries* lowerSeries = areaSeries->lowerSeries();
180 QLineSeries* lowerSeries = areaSeries->lowerSeries();
181
181
182 for (int i = 0; i < upperSeries->count(); i++)
182 for (int i = 0; i < upperSeries->count(); i++)
183 {
183 {
184 qreal x = upperSeries->x(i);
184 qreal x = upperSeries->x(i);
185 qreal y = upperSeries->y(i);
185 qreal y = upperSeries->y(i);
186 minX = qMin(minX, x);
186 minX = qMin(minX, x);
187 minY = qMin(minY, y);
187 minY = qMin(minY, y);
188 maxX = qMax(maxX, x);
188 maxX = qMax(maxX, x);
189 maxY = qMax(maxY, y);
189 maxY = qMax(maxY, y);
190 }
190 }
191 if(lowerSeries) {
191 if(lowerSeries) {
192 for (int i = 0; i < lowerSeries->count(); i++)
192 for (int i = 0; i < lowerSeries->count(); i++)
193 {
193 {
194 qreal x = lowerSeries->x(i);
194 qreal x = lowerSeries->x(i);
195 qreal y = lowerSeries->y(i);
195 qreal y = lowerSeries->y(i);
196 minX = qMin(minX, x);
196 minX = qMin(minX, x);
197 minY = qMin(minY, y);
197 minY = qMin(minY, y);
198 maxX = qMax(maxX, x);
198 maxX = qMax(maxX, x);
199 maxY = qMax(maxY, y);
199 maxY = qMax(maxY, y);
200 }}
200 }}
201 break;
201 break;
202 }
202 }
203 case QSeries::SeriesTypeBar: {
203 case QSeries::SeriesTypeBar: {
204
204
205 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
205 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
206 qreal x = barSeries->categoryCount();
206 qreal x = barSeries->categoryCount();
207 qreal y = barSeries->max();
207 qreal y = barSeries->max();
208 minX = qMin(minX, x);
208 minX = qMin(minX, x);
209 minY = qMin(minY, y);
209 minY = qMin(minY, y);
210 maxX = qMax(maxX, x);
210 maxX = qMax(maxX, x);
211 maxY = qMax(maxY, y);
211 maxY = qMax(maxY, y);
212 tickXCount = x+1;
212 tickXCount = x+1;
213 setupCategories(barSeries);
213 setupCategories(barSeries);
214 break;
214 break;
215 }
215 }
216 case QSeries::SeriesTypeStackedBar: {
216 case QSeries::SeriesTypeStackedBar: {
217
217
218 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
218 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
219 qreal x = stackedBarSeries->categoryCount();
219 qreal x = stackedBarSeries->categoryCount();
220 qreal y = stackedBarSeries->maxCategorySum();
220 qreal y = stackedBarSeries->maxCategorySum();
221 minX = qMin(minX, x);
221 minX = qMin(minX, x);
222 minY = qMin(minY, y);
222 minY = qMin(minY, y);
223 maxX = qMax(maxX, x);
223 maxX = qMax(maxX, x);
224 maxY = qMax(maxY, y);
224 maxY = qMax(maxY, y);
225 tickXCount = x+1;
225 tickXCount = x+1;
226 setupCategories(stackedBarSeries);
226 setupCategories(stackedBarSeries);
227 break;
227 break;
228 }
228 }
229 case QSeries::SeriesTypePercentBar: {
229 case QSeries::SeriesTypePercentBar: {
230
230
231 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
231 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
232 qreal x = percentBarSeries->categoryCount();
232 qreal x = percentBarSeries->categoryCount();
233 minX = qMin(minX, x);
233 minX = qMin(minX, x);
234 maxX = qMax(maxX, x);
234 maxX = qMax(maxX, x);
235 minY = 0;
235 minY = 0;
236 maxY = 100;
236 maxY = 100;
237 setupCategories(percentBarSeries);
237 setupCategories(percentBarSeries);
238 break;
238 break;
239 }
239 }
240
240
241 case QSeries::SeriesTypePie: {
241 case QSeries::SeriesTypePie: {
242 //QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
242 //QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
243 // TODO: domain stuff
243 // TODO: domain stuff
244 break;
244 break;
245 }
245 }
246
246
247
247
248 default: {
248 default: {
249 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
249 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
250 return;
250 return;
251 break;
252 }
251 }
253
252
254 }
253 }
255
254
256 domain->setRangeX(minX,maxX,tickXCount);
255 domain->setRangeX(minX,maxX,tickXCount);
257 domain->setRangeY(minY,maxY,tickYCount);
256 domain->setRangeY(minY,maxY,tickYCount);
258 }
257 }
259
258
260
259
261 void ChartDataSet::setupCategories(QBarSeries* series)
260 void ChartDataSet::setupCategories(QBarSeries* series)
262 {
261 {
263 QChartAxisCategories* categories = axisX()->categories();
262 QChartAxisCategories* categories = axisX()->categories();
264 categories->clear();
263 categories->clear();
265 categories->insert(series->categories());
264 categories->insert(series->categories());
266 }
265 }
267
266
268 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
267 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
269 {
268 {
270 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
269 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
271 while (i.hasNext()) {
270 while (i.hasNext()) {
272 i.next();
271 i.next();
273 i.value()->zoomIn(rect,size);
272 i.value()->zoomIn(rect,size);
274 }
273 }
275 }
274 }
276
275
277 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
276 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
278 {
277 {
279 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
278 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
280 while (i.hasNext()) {
279 while (i.hasNext()) {
281 i.next();
280 i.next();
282 i.value()->zoomOut(rect,size);
281 i.value()->zoomOut(rect,size);
283 }
282 }
284 }
283 }
285
284
286 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
285 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
287 {
286 {
288 int count=0;
287 int count=0;
289 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
288 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
290 while (i.hasNext()) {
289 while (i.hasNext()) {
291 i.next();
290 i.next();
292 if(i.key()->type()==type) count++;
291 if(i.key()->type()==type) count++;
293 }
292 }
294 return count;
293 return count;
295 }
294 }
296
295
297 int ChartDataSet::seriesIndex(QSeries *series)
296 int ChartDataSet::seriesIndex(QSeries *series)
298 {
297 {
299 int count=-1;
298 int count=-1;
300 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
299 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
301 while (i.hasNext()) {
300 while (i.hasNext()) {
302 i.next();
301 i.next();
303 count++;
302 count++;
304 if (i.key() == series)
303 if (i.key() == series)
305 return count;
304 return count;
306 }
305 }
307 return count;
306 return count;
308 }
307 }
309
308
310 QChartAxis* ChartDataSet::axisY(QSeries* series) const
309 QChartAxis* ChartDataSet::axisY(QSeries* series) const
311 {
310 {
312 if(series == 0) return m_axisY;
311 if(series == 0) return m_axisY;
313 return m_seriesAxisMap.value(series);
312 return m_seriesAxisMap.value(series);
314 }
313 }
315
314
316 Domain* ChartDataSet::domain(QSeries* series) const
315 Domain* ChartDataSet::domain(QSeries* series) const
317 {
316 {
318 QChartAxis* axis = m_seriesAxisMap.value(series);
317 QChartAxis* axis = m_seriesAxisMap.value(series);
319 if(axis){
318 if(axis){
320 return m_axisDomainMap.value(axis);
319 return m_axisDomainMap.value(axis);
321 }else
320 }else
322 return 0;
321 return 0;
323 }
322 }
324
323
325 Domain* ChartDataSet::domain(QChartAxis* axis) const
324 Domain* ChartDataSet::domain(QChartAxis* axis) const
326 {
325 {
327 if(!axis || axis==axisX()) {
326 if(!axis || axis==axisX()) {
328 return m_axisDomainMap.value(axisY());
327 return m_axisDomainMap.value(axisY());
329 }
328 }
330 else {
329 else {
331 return m_axisDomainMap.value(axis);
330 return m_axisDomainMap.value(axis);
332 }
331 }
333 }
332 }
334
333
335 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
334 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
336 {
335 {
337 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
336 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
338 while (i.hasNext()) {
337 while (i.hasNext()) {
339 i.next();
338 i.next();
340 i.value()->move(dx,dy,size);
339 i.value()->move(dx,dy,size);
341 }
340 }
342 }
341 }
343
342
344 #include "moc_chartdataset_p.cpp"
343 #include "moc_chartdataset_p.cpp"
345
344
346 QTCOMMERCIALCHART_END_NAMESPACE
345 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,120 +1,120
1 #ifndef SCATTERPRESENTER_H
1 #ifndef SCATTERPRESENTER_H
2 #define SCATTERPRESENTER_H
2 #define SCATTERPRESENTER_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "xychartitem_p.h"
5 #include "xychartitem_p.h"
6 #include <QGraphicsEllipseItem>
6 #include <QGraphicsEllipseItem>
7 #include <QPen>
7 #include <QPen>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 class QScatterSeries;
11 class QScatterSeries;
12 class Marker;
12 class Marker;
13
13
14 class ScatterChartItem : public XYChartItem
14 class ScatterChartItem : public XYChartItem
15 {
15 {
16 Q_OBJECT
16 Q_OBJECT
17 public:
17 public:
18 explicit ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter);
18 explicit ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter);
19
19
20 public:
20 public:
21 //from QGraphicsItem
21 //from QGraphicsItem
22 QRectF boundingRect() const;
22 QRectF boundingRect() const;
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24
24
25 void setPen(const QPen &pen);
25 void setPen(const QPen &pen);
26 void setBrush(const QBrush &brush);
26 void setBrush(const QBrush &brush);
27
27
28 void markerSelected(Marker *item);
28 void markerSelected(Marker *item);
29
29
30 public Q_SLOTS:
30 public Q_SLOTS:
31 void handleUpdated();
31 void handleUpdated();
32
32
33 private:
33 private:
34 void createPoints(int count);
34 void createPoints(int count);
35 void deletePoints(int count);
35 void deletePoints(int count);
36
36
37 protected:
37 protected:
38 void setLayout(QVector<QPointF> &points);
38 void setLayout(QVector<QPointF> &points);
39
39
40 private:
40 private:
41 QScatterSeries *m_series;
41 QScatterSeries *m_series;
42 QGraphicsItemGroup m_items;
42 QGraphicsItemGroup m_items;
43 int m_shape;
43 int m_shape;
44 int m_size;
44 int m_size;
45 QRectF m_rect;
45 QRectF m_rect;
46
46
47 };
47 };
48
48
49
49
50 class Marker: public QAbstractGraphicsShapeItem
50 class Marker: public QAbstractGraphicsShapeItem
51 {
51 {
52
52
53 public:
53 public:
54
54
55 Marker(QAbstractGraphicsShapeItem *item , ScatterChartItem *parent) : QAbstractGraphicsShapeItem(0) ,m_item(item), m_parent(parent)
55 Marker(QAbstractGraphicsShapeItem *item , ScatterChartItem *parent) : QAbstractGraphicsShapeItem(0) ,m_item(item), m_parent(parent), m_index(-1)
56 {
56 {
57 };
57 };
58
58
59 ~Marker()
59 ~Marker()
60 {
60 {
61 delete m_item;
61 delete m_item;
62 }
62 }
63
63
64 void setIndex(int index)
64 void setIndex(int index)
65 {
65 {
66 m_index=index;
66 m_index=index;
67 }
67 }
68
68
69 int index() const
69 int index() const
70 {
70 {
71 return m_index;
71 return m_index;
72 }
72 }
73
73
74 QPainterPath shape() const
74 QPainterPath shape() const
75 {
75 {
76 return m_item->shape();
76 return m_item->shape();
77 }
77 }
78
78
79 QRectF boundingRect() const
79 QRectF boundingRect() const
80 {
80 {
81 return m_item->boundingRect();
81 return m_item->boundingRect();
82 }
82 }
83
83
84 bool contains(const QPointF &point) const
84 bool contains(const QPointF &point) const
85 {
85 {
86 return m_item->contains(point);
86 return m_item->contains(point);
87 }
87 }
88
88
89 void setPen(const QPen &pen)
89 void setPen(const QPen &pen)
90 {
90 {
91 m_item->setPen(pen);
91 m_item->setPen(pen);
92 }
92 }
93
93
94 void setBrush(const QBrush &brush)
94 void setBrush(const QBrush &brush)
95 {
95 {
96 m_item->setBrush(brush);
96 m_item->setBrush(brush);
97 }
97 }
98
98
99 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
99 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
100 {
100 {
101 m_item->paint(painter,option,widget);
101 m_item->paint(painter,option,widget);
102 }
102 }
103
103
104 protected:
104 protected:
105
105
106 void mousePressEvent(QGraphicsSceneMouseEvent *event)
106 void mousePressEvent(QGraphicsSceneMouseEvent *event)
107 {
107 {
108 Q_UNUSED(event)
108 Q_UNUSED(event)
109 m_parent->markerSelected(this);
109 m_parent->markerSelected(this);
110 }
110 }
111
111
112 private:
112 private:
113 QAbstractGraphicsShapeItem* m_item;
113 QAbstractGraphicsShapeItem* m_item;
114 ScatterChartItem* m_parent;
114 ScatterChartItem* m_parent;
115 int m_index;
115 int m_index;
116 };
116 };
117
117
118 QTCOMMERCIALCHART_END_NAMESPACE
118 QTCOMMERCIALCHART_END_NAMESPACE
119
119
120 #endif // SCATTERPRESENTER_H
120 #endif // SCATTERPRESENTER_H
General Comments 0
You need to be logged in to leave comments. Login now