##// END OF EJS Templates
added map for yaxises methods to set axis
sauimone -
r1554:9a708aa57671
parent child
Show More
@@ -1,292 +1,304
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 "qchart.h"
22 #include "qchart.h"
23 #include "qvaluesaxis.h"
23 #include "qvaluesaxis.h"
24 #include "qvaluesaxis_p.h"
24 #include "qvaluesaxis_p.h"
25 #include "qabstractseries_p.h"
25 #include "qabstractseries_p.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
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
33 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
34 m_axisX(new QValuesAxis(this)),
34 m_axisX(new QValuesAxis(this)),
35 m_axisY(new QValuesAxis(this)),
35 m_axisY(new QValuesAxis(this)),
36 m_domainIndex(0),
36 m_domainIndex(0),
37 m_axisXInitialized(false),
37 m_axisXInitialized(false),
38 m_axisYInitialized(false)
38 m_axisYInitialized(false)
39 {
39 {
40 //create main domain
40 //create main domain
41 Domain* domain = new Domain(m_axisY);
41 Domain* domain = new Domain(m_axisY);
42 m_axisDomainMap.insert(m_axisY,domain);
42 m_axisDomainMap.insert(m_axisY,domain);
43 QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
43 QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
44 QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
44 QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
45 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
45 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
46 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
46 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
47 }
47 }
48
48
49 ChartDataSet::~ChartDataSet()
49 ChartDataSet::~ChartDataSet()
50 {
50 {
51 removeAllSeries();
51 removeAllSeries();
52 }
52 }
53
53
54 void ChartDataSet::addSeries(QAbstractSeries* series)
54 void ChartDataSet::addSeries(QAbstractSeries* series)
55 {
55 {
56 QAbstractAxis* axis = m_seriesAxisMap.value(series);
56 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
57
57
58 if(axis) {
58 if(axis) {
59 qWarning() << "Can not add series. Series already on the chart";
59 qWarning() << "Can not add series. Series already on the chart";
60 return;
60 return;
61 }
61 }
62
62
63 QAbstractAxis* axisX = m_axisX ; //series->d_ptr->createAxisX();
63 QAbstractAxis* axisX = series->d_ptr->createAxisX();
64 QAbstractAxis* axisY = m_axisY ; //series->d_ptr->createAxisY();
64 QAbstractAxis* axisY = m_axisY ; //series->d_ptr->createAxisY();
65
65
66 series->setParent(this); // take ownership
66 series->setParent(this); // take ownership
67 //axisY->setParent(this); // take ownership
67 //axisY->setParent(this); // take ownership
68
68
69 Domain* domain = m_axisDomainMap.value(axisY);
69 Domain* domain = m_axisDomainMap.value(axisY);
70
70
71 if(!domain) {
71 if(!domain) {
72 domain = new Domain(axisY);
72 domain = new Domain(axisY);
73 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
73 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
74 QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int)));
74 QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int)));
75 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
75 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
76 //initialize
76 //initialize
77 m_axisDomainMap.insert(axisY,domain);
77 m_axisDomainMap.insert(axisY,domain);
78 emit axisAdded(axisY,domain);
78 emit axisAdded(axisY,domain);
79 }
79 }
80
80
81 if(!m_axisXInitialized){
81 if(!m_axisXInitialized){
82 m_axisXInitialized=true;
82 m_axisXInitialized=true;
83 emit axisAdded(m_axisX,domain);
83 // emit axisAdded(m_axisX,domain);
84 emit axisAdded(axisX,domain);
84 }
85 }
85
86
86 if(!m_axisYInitialized && axisY==m_axisY){
87 if(!m_axisYInitialized && axisY==m_axisY){
87 m_axisYInitialized=true;
88 m_axisYInitialized=true;
88 emit axisAdded(m_axisY,domain);
89 emit axisAdded(m_axisY,domain);
89 }
90 }
90
91
91 series->d_ptr->scaleDomain(*domain);
92 series->d_ptr->scaleDomain(*domain);
92
93
93 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) {
94 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisXMap.count() == 0) {
94 axisX->hide();
95 axisX->hide();
95 axisY->hide();
96 axisY->hide();
96 }
97 }
97
98
98 m_seriesAxisMap.insert(series,axisY);
99 m_seriesAxisXMap.insert(series,axisY);
99
100
100 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
101 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
101
102
102 int key=0;
103 int key=0;
103 while (i.hasNext()) {
104 while (i.hasNext()) {
104 i.next();
105 i.next();
105 if(i.key()!=key) {
106 if(i.key()!=key) {
106 break;
107 break;
107 }
108 }
108 key++;
109 key++;
109 }
110 }
110
111
111 m_indexSeriesMap.insert(key,series);
112 m_indexSeriesMap.insert(key,series);
112
113
113 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
114 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
114 series->d_ptr->m_dataset = this;
115 series->d_ptr->m_dataset = this;
115
116
116 emit seriesAdded(series,domain);
117 emit seriesAdded(series,domain);
117
118
118 }
119 }
119
120
120 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
121 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
121 {
122 {
122 QAbstractAxis* axis = m_seriesAxisMap.value(series);
123 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
123
124
124 if(!axis){
125 if(!axis){
125 qWarning()<<"Can not remove series. Series not found on the chart.";
126 qWarning()<<"Can not remove series. Series not found on the chart.";
126 return 0;
127 return 0;
127 }
128 }
128
129
129 emit seriesRemoved(series);
130 emit seriesRemoved(series);
130
131
131 m_seriesAxisMap.remove(series);
132 m_seriesAxisXMap.remove(series);
132 int key = seriesIndex(series);
133 int key = seriesIndex(series);
133 Q_ASSERT(key!=-1);
134 Q_ASSERT(key!=-1);
134
135
135 m_indexSeriesMap.remove(key);
136 m_indexSeriesMap.remove(key);
136
137
137 series->setParent(0);
138 series->setParent(0);
138 series->d_ptr->m_chart = 0;
139 series->d_ptr->m_chart = 0;
139 series->d_ptr->m_dataset = 0;
140 series->d_ptr->m_dataset = 0;
140
141
141 QList<QAbstractAxis*> axes = m_seriesAxisMap.values();
142 QList<QAbstractAxis*> axes = m_seriesAxisXMap.values();
142
143
143 int i = axes.indexOf(axis);
144 int i = axes.indexOf(axis);
144
145
145 if(i==-1){
146 if(i==-1){
146 Domain* domain = m_axisDomainMap.take(axis);
147 Domain* domain = m_axisDomainMap.take(axis);
147 emit axisRemoved(axis);
148 emit axisRemoved(axis);
148 if(axis!=m_axisY){
149 if(axis!=m_axisY){
149 axis->setParent(0);
150 axis->setParent(0);
150 delete domain;
151 delete domain;
151 }else{
152 }else{
152 m_axisYInitialized=false;
153 m_axisYInitialized=false;
153 m_axisDomainMap.insert(m_axisY,domain);
154 m_axisDomainMap.insert(m_axisY,domain);
154 }
155 }
155 }
156 }
156
157
157 if(m_seriesAxisMap.values().size()==0)
158 if(m_seriesAxisXMap.values().size()==0)
158 {
159 {
159 m_axisXInitialized=false;
160 m_axisXInitialized=false;
160 emit axisRemoved(m_axisX);
161 emit axisRemoved(m_axisX);
161 }
162 }
162
163
163 return axis;
164 return axis;
164 }
165 }
165
166
166 void ChartDataSet::removeAllSeries()
167 void ChartDataSet::removeAllSeries()
167 {
168 {
168 QList<QAbstractSeries*> series = m_seriesAxisMap.keys();
169 QList<QAbstractSeries*> series = m_seriesAxisXMap.keys();
169 QList<QAbstractAxis*> axes;
170 QList<QAbstractAxis*> axes;
170 foreach(QAbstractSeries *s , series) {
171 foreach(QAbstractSeries *s , series) {
171 QAbstractAxis* axis = removeSeries(s);
172 QAbstractAxis* axis = removeSeries(s);
172 if(axis==m_axisY) continue;
173 if(axis==m_axisY) continue;
173 int i = axes.indexOf(axis);
174 int i = axes.indexOf(axis);
174 if(i==-1){
175 if(i==-1){
175 axes<<axis;
176 axes<<axis;
176 }
177 }
177 }
178 }
178
179
179 Q_ASSERT(m_seriesAxisMap.count()==0);
180 Q_ASSERT(m_seriesAxisXMap.count()==0);
180 Q_ASSERT(m_axisDomainMap.count()==1);
181 Q_ASSERT(m_axisDomainMap.count()==1);
181
182
182 qDeleteAll(series);
183 qDeleteAll(series);
183 qDeleteAll(axes);
184 qDeleteAll(axes);
184 }
185 }
185
186
186 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
187 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
187 {
188 {
188 QMapIterator<QAbstractAxis*, Domain*> i(m_axisDomainMap);
189 QMapIterator<QAbstractAxis*, Domain*> i(m_axisDomainMap);
189 //main domain has to be the last one;
190 //main domain has to be the last one;
190 Domain *domain = m_axisDomainMap.value(m_axisY);
191 Domain *domain = m_axisDomainMap.value(m_axisY);
191 Q_ASSERT(domain);
192 Q_ASSERT(domain);
192 while (i.hasNext()) {
193 while (i.hasNext()) {
193 i.next();
194 i.next();
194 if(i.value()==domain) continue;
195 if(i.value()==domain) continue;
195 i.value()->zoomIn(rect,size);
196 i.value()->zoomIn(rect,size);
196 }
197 }
197 domain->zoomIn(rect,size);
198 domain->zoomIn(rect,size);
198 }
199 }
199
200
200 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
201 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
201 {
202 {
202 QMapIterator<QAbstractAxis*, Domain*> i(m_axisDomainMap);
203 QMapIterator<QAbstractAxis*, Domain*> i(m_axisDomainMap);
203 //main domain has to be the last one;
204 //main domain has to be the last one;
204 Domain *domain = m_axisDomainMap.value(m_axisY);
205 Domain *domain = m_axisDomainMap.value(m_axisY);
205 Q_ASSERT(domain);
206 Q_ASSERT(domain);
206 while (i.hasNext()) {
207 while (i.hasNext()) {
207 i.next();
208 i.next();
208 if(i.value()==domain) continue;
209 if(i.value()==domain) continue;
209 i.value()->zoomOut(rect,size);
210 i.value()->zoomOut(rect,size);
210 }
211 }
211 domain->zoomOut(rect,size);
212 domain->zoomOut(rect,size);
212 }
213 }
213
214
214 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
215 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
215 {
216 {
216 int count=0;
217 int count=0;
217 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisMap);
218 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap);
218 while (i.hasNext()) {
219 while (i.hasNext()) {
219 i.next();
220 i.next();
220 if(i.key()->type()==type) count++;
221 if(i.key()->type()==type) count++;
221 }
222 }
222 return count;
223 return count;
223 }
224 }
224
225
225 int ChartDataSet::seriesIndex(QAbstractSeries *series)
226 int ChartDataSet::seriesIndex(QAbstractSeries *series)
226 {
227 {
227 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
228 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
228 while (i.hasNext()) {
229 while (i.hasNext()) {
229 i.next();
230 i.next();
230 if (i.value() == series)
231 if (i.value() == series)
231 return i.key();
232 return i.key();
232 }
233 }
233 return -1;
234 return -1;
234 }
235 }
235
236
237 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
238 {
239 qDebug() << "axisX";
240 if (series == 0) return m_axisX;
241 return m_seriesAxisXMap.value(series);
242 }
243
236 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
244 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
237 {
245 {
238 if(series == 0) return m_axisY;
246 if(series == 0) return m_axisY;
239 return m_seriesAxisMap.value(series);
247 return m_seriesAxisYMap.value(series);
240 }
248 }
241
249
242 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
250 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
251 {
252 m_seriesAxisXMap.insert(series,axis);
253 }
254
255 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
243 {
256 {
244 Q_UNUSED(series)
257 m_seriesAxisYMap.insert(series,axis);
245 return m_axisX;
246 }
258 }
247
259
248 Domain* ChartDataSet::domain(QAbstractSeries *series) const
260 Domain* ChartDataSet::domain(QAbstractSeries *series) const
249 {
261 {
250 QAbstractAxis* axis = m_seriesAxisMap.value(series);
262 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
251 if(axis){
263 if(axis){
252 return m_axisDomainMap.value(axis);
264 return m_axisDomainMap.value(axis);
253 }else
265 }else
254 return 0;
266 return 0;
255 }
267 }
256
268
257 Domain* ChartDataSet::domain(QAbstractAxis* axis) const
269 Domain* ChartDataSet::domain(QAbstractAxis* axis) const
258 {
270 {
259 if(!axis || axis==m_axisX) {
271 if(!axis || axis==m_axisX) {
260 return m_axisDomainMap.value(m_axisY);
272 return m_axisDomainMap.value(m_axisY);
261 }
273 }
262 else {
274 else {
263 return m_axisDomainMap.value(axis);
275 return m_axisDomainMap.value(axis);
264 }
276 }
265 }
277 }
266
278
267 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
279 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
268 {
280 {
269 QMapIterator<QAbstractAxis*, Domain*> i( m_axisDomainMap);
281 QMapIterator<QAbstractAxis*, Domain*> i( m_axisDomainMap);
270 //main domain has to be the last one;
282 //main domain has to be the last one;
271 Domain *domain = m_axisDomainMap.value(m_axisY);
283 Domain *domain = m_axisDomainMap.value(m_axisY);
272 while (i.hasNext()) {
284 while (i.hasNext()) {
273 i.next();
285 i.next();
274 if(i.value()==domain) continue;
286 if(i.value()==domain) continue;
275 i.value()->move(dx,dy,size);
287 i.value()->move(dx,dy,size);
276 }
288 }
277 domain->move(dx,dy,size);
289 domain->move(dx,dy,size);
278 }
290 }
279
291
280 QList<QAbstractSeries*> ChartDataSet::series() const
292 QList<QAbstractSeries*> ChartDataSet::series() const
281 {
293 {
282 return m_seriesAxisMap.keys();
294 return m_seriesAxisXMap.keys();
283 }
295 }
284
296
285 void ChartDataSet::updateSeries(QAbstractSeries *series)
297 void ChartDataSet::updateSeries(QAbstractSeries *series)
286 {
298 {
287 emit seriesUpdated(series);
299 emit seriesUpdated(series);
288 }
300 }
289
301
290 #include "moc_chartdataset_p.cpp"
302 #include "moc_chartdataset_p.cpp"
291
303
292 QTCOMMERCIALCHART_END_NAMESPACE
304 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,93 +1,97
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTDATASET_P_H
30 #ifndef CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35 #include <QVector>
35 #include <QVector>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class QAbstractAxis;
39 class QAbstractAxis;
40
40
41 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
41 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44 public:
44 public:
45 ChartDataSet(QChart* parent=0);
45 ChartDataSet(QChart* parent=0);
46 virtual ~ChartDataSet();
46 virtual ~ChartDataSet();
47
47
48 void addSeries(QAbstractSeries* series);
48 void addSeries(QAbstractSeries* series);
49 QAbstractAxis* removeSeries(QAbstractSeries* series);
49 QAbstractAxis* removeSeries(QAbstractSeries* series);
50 void removeAllSeries();
50 void removeAllSeries();
51 void updateSeries(QAbstractSeries* series);
51 void updateSeries(QAbstractSeries* series);
52
52
53 void zoomInDomain(const QRectF& rect, const QSizeF& size);
53 void zoomInDomain(const QRectF& rect, const QSizeF& size);
54 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
54 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
55 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
55 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
56
56
57 int seriesCount(QAbstractSeries::SeriesType type);
57 int seriesCount(QAbstractSeries::SeriesType type);
58 int seriesIndex(QAbstractSeries *series);
58 int seriesIndex(QAbstractSeries *series);
59
59
60 Domain* domain(QAbstractSeries* series) const;
60 Domain* domain(QAbstractSeries* series) const;
61 Domain* domain(QAbstractAxis* axis) const;
61 Domain* domain(QAbstractAxis* axis) const;
62
62
63 QAbstractAxis* axisX(QAbstractSeries *series) const;
63 QAbstractAxis* axisX(QAbstractSeries *series) const;
64 QAbstractAxis* axisY(QAbstractSeries *series) const;
64 QAbstractAxis* axisY(QAbstractSeries *series) const;
65
65
66 void setAxisX(QAbstractSeries *series, QAbstractAxis *axis);
67 void setAxisY(QAbstractSeries *series, QAbstractAxis *axis);
68
66 QList<QAbstractSeries*> series() const;
69 QList<QAbstractSeries*> series() const;
67
70
68 Q_SIGNALS:
71 Q_SIGNALS:
69 void seriesAdded(QAbstractSeries* series, Domain* domain);
72 void seriesAdded(QAbstractSeries* series, Domain* domain);
70 void seriesRemoved(QAbstractSeries* series);
73 void seriesRemoved(QAbstractSeries* series);
71 void seriesUpdated(QAbstractSeries* series);
74 void seriesUpdated(QAbstractSeries* series);
72 void axisAdded(QAbstractAxis* axis,Domain* domain);
75 void axisAdded(QAbstractAxis* axis,Domain* domain);
73 void axisRemoved(QAbstractAxis* axis);
76 void axisRemoved(QAbstractAxis* axis);
74
77
75 private:
78 private:
76 QStringList createLabels(QAbstractAxis* axis,qreal min, qreal max);
79 QStringList createLabels(QAbstractAxis* axis,qreal min, qreal max);
77 void calculateDomain(QAbstractSeries* series,Domain* domain);
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
78
81
79 private:
82 private:
80 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisMap;
83 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
84 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
81 QMap<QAbstractAxis*, Domain*> m_axisDomainMap;
85 QMap<QAbstractAxis*, Domain*> m_axisDomainMap;
82 QMap<int, QAbstractSeries*> m_indexSeriesMap;
86 QMap<int, QAbstractSeries*> m_indexSeriesMap;
83 QAbstractAxis* m_axisX;
87 QAbstractAxis* m_axisX;
84 QAbstractAxis* m_axisY;
88 QAbstractAxis* m_axisY;
85
89
86 int m_domainIndex;
90 int m_domainIndex;
87 bool m_axisXInitialized;
91 bool m_axisXInitialized;
88 bool m_axisYInitialized;
92 bool m_axisYInitialized;
89 };
93 };
90
94
91 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
92
96
93 #endif /* CHARTENGINE_P_H_ */
97 #endif /* CHARTENGINE_P_H_ */
@@ -1,437 +1,439
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 "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include <QGraphicsScene>
27 #include <QGraphicsScene>
28 #include <QGraphicsSceneResizeEvent>
28 #include <QGraphicsSceneResizeEvent>
29 #include <QGraphicsLayout>
29 #include <QGraphicsLayout>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \enum QChart::ChartTheme
34 \enum QChart::ChartTheme
35
35
36 This enum describes the theme used by the chart.
36 This enum describes the theme used by the chart.
37
37
38 \value ChartThemeLight The default theme
38 \value ChartThemeLight The default theme
39 \value ChartThemeBlueCerulean
39 \value ChartThemeBlueCerulean
40 \value ChartThemeDark
40 \value ChartThemeDark
41 \value ChartThemeBrownSand
41 \value ChartThemeBrownSand
42 \value ChartThemeBlueNcs
42 \value ChartThemeBlueNcs
43 \value ChartThemeHighContrast
43 \value ChartThemeHighContrast
44 \value ChartThemeBlueIcy
44 \value ChartThemeBlueIcy
45 */
45 */
46
46
47 /*!
47 /*!
48 \enum QChart::AnimationOption
48 \enum QChart::AnimationOption
49
49
50 For enabling/disabling animations. Defaults to NoAnimation.
50 For enabling/disabling animations. Defaults to NoAnimation.
51
51
52 \value NoAnimation
52 \value NoAnimation
53 \value GridAxisAnimations
53 \value GridAxisAnimations
54 \value SeriesAnimations
54 \value SeriesAnimations
55 \value AllAnimations
55 \value AllAnimations
56 */
56 */
57
57
58 /*!
58 /*!
59 \class QChart
59 \class QChart
60 \brief QtCommercial chart API.
60 \brief QtCommercial chart API.
61
61
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 representation of different types of series and other chart related objects like
63 representation of different types of series and other chart related objects like
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 convenience class QChartView instead of QChart.
65 convenience class QChartView instead of QChart.
66 \sa QChartView
66 \sa QChartView
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QChart::animationOptions
70 \property QChart::animationOptions
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QChart::backgroundVisible
75 \property QChart::backgroundVisible
76 Whether the chart background is visible or not.
76 Whether the chart background is visible or not.
77 \sa setBackgroundBrush(), setBackgroundPen()
77 \sa setBackgroundBrush(), setBackgroundPen()
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QChart::dropShadowEnabled
81 \property QChart::dropShadowEnabled
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
84 */
84 */
85
85
86 /*!
86 /*!
87 \property QChart::margins
87 \property QChart::margins
88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
89 */
89 */
90
90
91 /*!
91 /*!
92 \property QChart::theme
92 \property QChart::theme
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 different themes.
95 different themes.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QChart::title
100 \property QChart::title
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
102 */
102 */
103
103
104 /*!
104 /*!
105 \fn void QChart::marginsChanged(QRectF newMargins)
105 \fn void QChart::marginsChanged(QRectF newMargins)
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
107 modify axes or hide/show legend.
107 modify axes or hide/show legend.
108 */
108 */
109
109
110 /*!
110 /*!
111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
112 */
112 */
113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
114 d_ptr(new QChartPrivate())
114 d_ptr(new QChartPrivate())
115 {
115 {
116 d_ptr->m_dataset = new ChartDataSet(this);
116 d_ptr->m_dataset = new ChartDataSet(this);
117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
118 d_ptr->createConnections();
118 d_ptr->createConnections();
119 d_ptr->m_legend = new LegendScroller(this);
119 d_ptr->m_legend = new LegendScroller(this);
120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
122 setLayout(d_ptr->m_presenter->layout());
122 setLayout(d_ptr->m_presenter->layout());
123 }
123 }
124
124
125 /*!
125 /*!
126 Destroys the object and it's children, like series and axis objects added to it.
126 Destroys the object and it's children, like series and axis objects added to it.
127 */
127 */
128 QChart::~QChart()
128 QChart::~QChart()
129 {
129 {
130 //delete first presenter , since this is a root of all the graphical items
130 //delete first presenter , since this is a root of all the graphical items
131 setLayout(0);
131 setLayout(0);
132 delete d_ptr->m_presenter;
132 delete d_ptr->m_presenter;
133 d_ptr->m_presenter=0;
133 d_ptr->m_presenter=0;
134 }
134 }
135
135
136 /*!
136 /*!
137 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
137 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 the y axis).
139 the y axis).
140
140
141 \sa removeSeries(), removeAllSeries()
141 \sa removeSeries(), removeAllSeries()
142 */
142 */
143 void QChart::addSeries(QAbstractSeries *series)
143 void QChart::addSeries(QAbstractSeries *series)
144 {
144 {
145 Q_ASSERT(series);
145 Q_ASSERT(series);
146 d_ptr->m_dataset->addSeries(series);
146 d_ptr->m_dataset->addSeries(series);
147 }
147 }
148
148
149 /*!
149 /*!
150 Removes the \a series specified in a perameter from the QChartView.
150 Removes the \a series specified in a perameter from the QChartView.
151 It releses its ownership of the specified QChartSeries object.
151 It releses its ownership of the specified QChartSeries object.
152 It does not delete the pointed QChartSeries data object
152 It does not delete the pointed QChartSeries data object
153 \sa addSeries(), removeAllSeries()
153 \sa addSeries(), removeAllSeries()
154 */
154 */
155 void QChart::removeSeries(QAbstractSeries *series)
155 void QChart::removeSeries(QAbstractSeries *series)
156 {
156 {
157 Q_ASSERT(series);
157 Q_ASSERT(series);
158 d_ptr->m_dataset->removeSeries(series);
158 d_ptr->m_dataset->removeSeries(series);
159 }
159 }
160
160
161 /*!
161 /*!
162 Removes all the QChartSeries that have been added to the QChartView
162 Removes all the QChartSeries that have been added to the QChartView
163 It also deletes the pointed QChartSeries data objects
163 It also deletes the pointed QChartSeries data objects
164 \sa addSeries(), removeSeries()
164 \sa addSeries(), removeSeries()
165 */
165 */
166 void QChart::removeAllSeries()
166 void QChart::removeAllSeries()
167 {
167 {
168 d_ptr->m_dataset->removeAllSeries();
168 d_ptr->m_dataset->removeAllSeries();
169 }
169 }
170
170
171 /*!
171 /*!
172 Sets the \a brush that is used for painting the background of the chart area.
172 Sets the \a brush that is used for painting the background of the chart area.
173 */
173 */
174 void QChart::setBackgroundBrush(const QBrush& brush)
174 void QChart::setBackgroundBrush(const QBrush& brush)
175 {
175 {
176 d_ptr->m_presenter->setBackgroundBrush(brush);
176 d_ptr->m_presenter->setBackgroundBrush(brush);
177 }
177 }
178
178
179 /*!
179 /*!
180 Gets the brush that is used for painting the background of the chart area.
180 Gets the brush that is used for painting the background of the chart area.
181 */
181 */
182 QBrush QChart::backgroundBrush() const
182 QBrush QChart::backgroundBrush() const
183 {
183 {
184 return d_ptr->m_presenter->backgroundBrush();
184 return d_ptr->m_presenter->backgroundBrush();
185 }
185 }
186
186
187 /*!
187 /*!
188 Sets the \a pen that is used for painting the background of the chart area.
188 Sets the \a pen that is used for painting the background of the chart area.
189 */
189 */
190 void QChart::setBackgroundPen(const QPen& pen)
190 void QChart::setBackgroundPen(const QPen& pen)
191 {
191 {
192 d_ptr->m_presenter->setBackgroundPen(pen);
192 d_ptr->m_presenter->setBackgroundPen(pen);
193 }
193 }
194
194
195 /*!
195 /*!
196 Gets the pen that is used for painting the background of the chart area.
196 Gets the pen that is used for painting the background of the chart area.
197 */
197 */
198 QPen QChart::backgroundPen() const
198 QPen QChart::backgroundPen() const
199 {
199 {
200 return d_ptr->m_presenter->backgroundPen();
200 return d_ptr->m_presenter->backgroundPen();
201 }
201 }
202
202
203 /*!
203 /*!
204 Sets the chart \a title. The description text that is drawn above the chart.
204 Sets the chart \a title. The description text that is drawn above the chart.
205 */
205 */
206 void QChart::setTitle(const QString& title)
206 void QChart::setTitle(const QString& title)
207 {
207 {
208 d_ptr->m_presenter->setTitle(title);
208 d_ptr->m_presenter->setTitle(title);
209 }
209 }
210
210
211 /*!
211 /*!
212 Returns the chart title. The description text that is drawn above the chart.
212 Returns the chart title. The description text that is drawn above the chart.
213 */
213 */
214 QString QChart::title() const
214 QString QChart::title() const
215 {
215 {
216 return d_ptr->m_presenter->title();
216 return d_ptr->m_presenter->title();
217 }
217 }
218
218
219 /*!
219 /*!
220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 */
221 */
222 void QChart::setTitleFont(const QFont& font)
222 void QChart::setTitleFont(const QFont& font)
223 {
223 {
224 d_ptr->m_presenter->setTitleFont(font);
224 d_ptr->m_presenter->setTitleFont(font);
225 }
225 }
226
226
227 /*!
227 /*!
228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 */
229 */
230 QFont QChart::titleFont() const
230 QFont QChart::titleFont() const
231 {
231 {
232 return d_ptr->m_presenter->titleFont();
232 return d_ptr->m_presenter->titleFont();
233 }
233 }
234
234
235 /*!
235 /*!
236 Sets the \a brush used for rendering the title text.
236 Sets the \a brush used for rendering the title text.
237 */
237 */
238 void QChart::setTitleBrush(const QBrush &brush)
238 void QChart::setTitleBrush(const QBrush &brush)
239 {
239 {
240 d_ptr->m_presenter->setTitleBrush(brush);
240 d_ptr->m_presenter->setTitleBrush(brush);
241 }
241 }
242
242
243 /*!
243 /*!
244 Returns the brush used for rendering the title text.
244 Returns the brush used for rendering the title text.
245 */
245 */
246 QBrush QChart::titleBrush() const
246 QBrush QChart::titleBrush() const
247 {
247 {
248 return d_ptr->m_presenter->titleBrush();
248 return d_ptr->m_presenter->titleBrush();
249 }
249 }
250
250
251 void QChart::setTheme(QChart::ChartTheme theme)
251 void QChart::setTheme(QChart::ChartTheme theme)
252 {
252 {
253 d_ptr->m_presenter->setTheme(theme);
253 d_ptr->m_presenter->setTheme(theme);
254 }
254 }
255
255
256 QChart::ChartTheme QChart::theme() const
256 QChart::ChartTheme QChart::theme() const
257 {
257 {
258 return d_ptr->m_presenter->theme();
258 return d_ptr->m_presenter->theme();
259 }
259 }
260
260
261 /*!
261 /*!
262 Zooms in the view by a factor of 2
262 Zooms in the view by a factor of 2
263 */
263 */
264 void QChart::zoomIn()
264 void QChart::zoomIn()
265 {
265 {
266 d_ptr->m_presenter->zoomIn(2.0);
266 d_ptr->m_presenter->zoomIn(2.0);
267 }
267 }
268
268
269 /*!
269 /*!
270 Zooms in the view to a maximum level at which \a rect is still fully visible.
270 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 */
271 */
272 void QChart::zoomIn(const QRectF& rect)
272 void QChart::zoomIn(const QRectF& rect)
273 {
273 {
274 if (!rect.isValid()) return;
274 if (!rect.isValid()) return;
275 d_ptr->m_presenter->zoomIn(rect);
275 d_ptr->m_presenter->zoomIn(rect);
276 }
276 }
277
277
278 /*!
278 /*!
279 Restores the view zoom level to the previous one.
279 Restores the view zoom level to the previous one.
280 */
280 */
281 void QChart::zoomOut()
281 void QChart::zoomOut()
282 {
282 {
283 d_ptr->m_presenter->zoomOut(2.0);
283 d_ptr->m_presenter->zoomOut(2.0);
284 }
284 }
285
285
286 /*!
286 /*!
287 Zooms in the view by a \a factor.
287 Zooms in the view by a \a factor.
288
288
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 */
290 */
291 void QChart::zoom(qreal factor)
291 void QChart::zoom(qreal factor)
292 {
292 {
293 if (qFuzzyIsNull(factor))
293 if (qFuzzyIsNull(factor))
294 return;
294 return;
295
295
296 if (qFuzzyCompare(factor, 1.0))
296 if (qFuzzyCompare(factor, 1.0))
297 return;
297 return;
298
298
299 if (factor < 0)
299 if (factor < 0)
300 return;
300 return;
301
301
302 if (factor > 1.0)
302 if (factor > 1.0)
303 d_ptr->m_presenter->zoomIn(factor);
303 d_ptr->m_presenter->zoomIn(factor);
304 else
304 else
305 d_ptr->m_presenter->zoomOut(1.0 / factor);
305 d_ptr->m_presenter->zoomOut(1.0 / factor);
306 }
306 }
307
307
308 /*!
308 /*!
309 Returns the pointer to the x axis object of the chart
309 Returns the pointer to the x axis object of the chart
310 */
310 */
311 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
311 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
312 {
312 {
313 return d_ptr->m_dataset->axisX(series);
313 return d_ptr->m_dataset->axisX(series);
314 }
314 }
315
315
316 /*!
316 /*!
317 Returns the pointer to the y axis object of the \a series
317 Returns the pointer to the y axis object of the \a series
318 If no \a series is provided then default Y axis of the chart is returned.
318 If no \a series is provided then default Y axis of the chart is returned.
319 */
319 */
320 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
320 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
321 {
321 {
322 return d_ptr->m_dataset->axisY(series);
322 return d_ptr->m_dataset->axisY(series);
323 }
323 }
324
324
325 /*!
325 /*!
326 Returns the legend object of the chart. Ownership stays in chart.
326 Returns the legend object of the chart. Ownership stays in chart.
327 */
327 */
328 QLegend* QChart::legend() const
328 QLegend* QChart::legend() const
329 {
329 {
330 return d_ptr->m_legend;
330 return d_ptr->m_legend;
331 }
331 }
332
332
333 /*!
333 /*!
334 Returns the rect that contains information about margins (distance between chart widget edge and axes).
334 Returns the rect that contains information about margins (distance between chart widget edge and axes).
335 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
335 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
336 */
336 */
337 QRectF QChart::margins() const
337 QRectF QChart::margins() const
338 {
338 {
339 return d_ptr->m_presenter->margins();
339 return d_ptr->m_presenter->margins();
340 }
340 }
341
341
342 /*!
342 /*!
343 Sets animation \a options for the chart
343 Sets animation \a options for the chart
344 */
344 */
345
345
346 void QChart::setAnimationOptions(AnimationOptions options)
346 void QChart::setAnimationOptions(AnimationOptions options)
347 {
347 {
348 d_ptr->m_presenter->setAnimationOptions(options);
348 d_ptr->m_presenter->setAnimationOptions(options);
349 }
349 }
350
350
351 QChart::AnimationOptions QChart::animationOptions() const
351 QChart::AnimationOptions QChart::animationOptions() const
352 {
352 {
353 return d_ptr->m_presenter->animationOptions();
353 return d_ptr->m_presenter->animationOptions();
354 }
354 }
355
355
356 /*!
356 /*!
357 Scrolls the visible area of the chart by the distance defined in the \a delta.
357 Scrolls the visible area of the chart by the distance defined in the \a delta.
358 */
358 */
359 void QChart::scroll(qreal dx, qreal dy)
359 void QChart::scroll(qreal dx, qreal dy)
360 {
360 {
361 d_ptr->m_presenter->scroll(dx, dy);
361 d_ptr->m_presenter->scroll(dx, dy);
362 }
362 }
363
363
364 void QChart::setBackgroundVisible(bool visible)
364 void QChart::setBackgroundVisible(bool visible)
365 {
365 {
366 d_ptr->m_presenter->setBackgroundVisible(visible);
366 d_ptr->m_presenter->setBackgroundVisible(visible);
367 }
367 }
368
368
369 bool QChart::isBackgroundVisible() const
369 bool QChart::isBackgroundVisible() const
370 {
370 {
371 return d_ptr->m_presenter->isBackgroundVisible();
371 return d_ptr->m_presenter->isBackgroundVisible();
372 }
372 }
373
373
374 void QChart::setDropShadowEnabled(bool enabled)
374 void QChart::setDropShadowEnabled(bool enabled)
375 {
375 {
376 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
376 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
377 }
377 }
378
378
379 bool QChart::isDropShadowEnabled() const
379 bool QChart::isDropShadowEnabled() const
380 {
380 {
381 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
381 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
382 }
382 }
383
383
384 /*!
384 /*!
385 Returns all the series that are added to the chart.
385 Returns all the series that are added to the chart.
386
386
387 \sa addSeries(), removeSeries(), removeAllSeries()
387 \sa addSeries(), removeSeries(), removeAllSeries()
388 */
388 */
389 QList<QAbstractSeries*> QChart::series() const
389 QList<QAbstractSeries*> QChart::series() const
390 {
390 {
391 return d_ptr->m_dataset->series();
391 return d_ptr->m_dataset->series();
392 }
392 }
393
393
394 void QChart::setMarginsMinimum(const QRectF& margins)
394 void QChart::setMarginsMinimum(const QRectF& margins)
395 {
395 {
396 d_ptr->m_presenter->setMarginsMinimum(margins);
396 d_ptr->m_presenter->setMarginsMinimum(margins);
397 }
397 }
398
398
399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
400 {
400 {
401 Q_UNUSED(series);
401 // Q_UNUSED(series);
402 Q_UNUSED(axis);
402 // Q_UNUSED(axis);
403 d_ptr->m_dataset->setAxisX(series, axis);
403 }
404 }
404
405
405 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
406 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
406 {
407 {
407 Q_UNUSED(series);
408 // Q_UNUSED(series);
408 Q_UNUSED(axis);
409 // Q_UNUSED(axis);
410 d_ptr->m_dataset->setAxisY(series, axis);
409 }
411 }
410
412
411 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
413 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
412
414
413 QChartPrivate::QChartPrivate():
415 QChartPrivate::QChartPrivate():
414 m_legend(0),
416 m_legend(0),
415 m_dataset(0),
417 m_dataset(0),
416 m_presenter(0)
418 m_presenter(0)
417 {
419 {
418
420
419 }
421 }
420
422
421 QChartPrivate::~QChartPrivate()
423 QChartPrivate::~QChartPrivate()
422 {
424 {
423
425
424 }
426 }
425
427
426 void QChartPrivate::createConnections()
428 void QChartPrivate::createConnections()
427 {
429 {
428 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
430 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
429 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
431 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
430 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
432 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
431 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
433 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
432 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
434 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
433 }
435 }
434
436
435 #include "moc_qchart.cpp"
437 #include "moc_qchart.cpp"
436
438
437 QTCOMMERCIALCHART_END_NAMESPACE
439 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now