##// END OF EJS Templates
Fix precision issue when scrolling domain
Michal Klocek -
r1267:e23f2bdfce30
parent child
Show More
@@ -1,296 +1,296
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 "qaxis.h"
22 #include "qaxis.h"
23 #include "qaxis_p.h"
23 #include "qaxis_p.h"
24 #include "qabstractseries_p.h"
24 #include "qabstractseries_p.h"
25 #include "qbarseries.h"
25 #include "qbarseries.h"
26 #include "qstackedbarseries.h"
26 #include "qstackedbarseries.h"
27 #include "qpercentbarseries.h"
27 #include "qpercentbarseries.h"
28 #include "qpieseries.h"
28 #include "qpieseries.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
32 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
33 m_axisX(new QAxis(this)),
33 m_axisX(new QAxis(this)),
34 m_axisY(new QAxis(this)),
34 m_axisY(new QAxis(this)),
35 m_domainIndex(0),
35 m_domainIndex(0),
36 m_axisXInitialized(false),
36 m_axisXInitialized(false),
37 m_axisYInitialized(false)
37 m_axisYInitialized(false)
38 {
38 {
39 //create main domain
39 //create main domain
40 Domain* domain = new Domain(m_axisY);
40 Domain* domain = new Domain(m_axisY);
41 m_axisDomainMap.insert(m_axisY,domain);
41 m_axisDomainMap.insert(m_axisY,domain);
42 QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
42 QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
43 QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
43 QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
44 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
44 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
45 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
45 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
46 }
46 }
47
47
48 ChartDataSet::~ChartDataSet()
48 ChartDataSet::~ChartDataSet()
49 {
49 {
50 removeAllSeries();
50 removeAllSeries();
51 }
51 }
52
52
53 void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY)
53 void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY)
54 {
54 {
55 if(axisY==0) axisY = m_axisY;
55 if(axisY==0) axisY = m_axisY;
56
56
57 QAxis* axis = m_seriesAxisMap.value(series);
57 QAxis* axis = m_seriesAxisMap.value(series);
58
58
59 if(axis) {
59 if(axis) {
60 qWarning() << "Can not add series. Series already on the chart";
60 qWarning() << "Can not add series. Series already on the chart";
61 return;
61 return;
62 }
62 }
63
63
64 series->setParent(this); // take ownership
64 series->setParent(this); // take ownership
65 axisY->setParent(this); // take ownership
65 axisY->setParent(this); // take ownership
66
66
67 Domain* domain = m_axisDomainMap.value(axisY);
67 Domain* domain = m_axisDomainMap.value(axisY);
68
68
69 if(!domain) {
69 if(!domain) {
70 domain = new Domain(axisY);
70 domain = new Domain(axisY);
71 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
71 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
72 QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int)));
72 QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int)));
73 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
73 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),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 m_axisXInitialized=true;
80 m_axisXInitialized=true;
81 emit axisAdded(m_axisX,domain);
81 emit axisAdded(m_axisX,domain);
82 }
82 }
83
83
84 if(!m_axisYInitialized && axisY==m_axisY){
84 if(!m_axisYInitialized && axisY==m_axisY){
85 m_axisYInitialized=true;
85 m_axisYInitialized=true;
86 emit axisAdded(m_axisY,domain);
86 emit axisAdded(m_axisY,domain);
87 }
87 }
88
88
89 series->d_ptr->scaleDomain(*domain);
89 series->d_ptr->scaleDomain(*domain);
90
90
91 // Note that with SeriesTypeBar we don't set up categories, but use real values on x-asis
91 // Note that with SeriesTypeBar we don't set up categories, but use real values on x-asis
92 if(series->type() == QAbstractSeries::SeriesTypeGroupedBar
92 if(series->type() == QAbstractSeries::SeriesTypeGroupedBar
93 || series->type() == QAbstractSeries::SeriesTypeStackedBar
93 || series->type() == QAbstractSeries::SeriesTypeStackedBar
94 || series->type() == QAbstractSeries::SeriesTypePercentBar) {
94 || series->type() == QAbstractSeries::SeriesTypePercentBar) {
95 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
95 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
96 setupCategories(barSeries);
96 setupCategories(barSeries);
97 }
97 }
98
98
99 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) {
99 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) {
100 axisX()->hide();
100 axisX()->hide();
101 this->axisY()->hide();
101 this->axisY()->hide();
102 }
102 }
103
103
104 m_seriesAxisMap.insert(series,axisY);
104 m_seriesAxisMap.insert(series,axisY);
105
105
106 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
106 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
107
107
108 int key=0;
108 int key=0;
109 while (i.hasNext()) {
109 while (i.hasNext()) {
110 i.next();
110 i.next();
111 if(i.key()!=key) {
111 if(i.key()!=key) {
112 break;
112 break;
113 }
113 }
114 key++;
114 key++;
115 }
115 }
116
116
117 m_indexSeriesMap.insert(key,series);
117 m_indexSeriesMap.insert(key,series);
118
118
119 series->d_ptr->m_dataset=this;
119 series->d_ptr->m_dataset=this;
120
120
121 emit seriesAdded(series,domain);
121 emit seriesAdded(series,domain);
122
122
123 }
123 }
124
124
125 QAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
125 QAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
126 {
126 {
127 QAxis* axis = m_seriesAxisMap.value(series);
127 QAxis* axis = m_seriesAxisMap.value(series);
128
128
129 if(!axis){
129 if(!axis){
130 qWarning()<<"Can not remove series. Series not found on the chart.";
130 qWarning()<<"Can not remove series. Series not found on the chart.";
131 return 0;
131 return 0;
132 }
132 }
133
133
134 emit seriesRemoved(series);
134 emit seriesRemoved(series);
135
135
136 m_seriesAxisMap.remove(series);
136 m_seriesAxisMap.remove(series);
137 int key = seriesIndex(series);
137 int key = seriesIndex(series);
138 Q_ASSERT(key!=-1);
138 Q_ASSERT(key!=-1);
139
139
140 m_indexSeriesMap.remove(key);
140 m_indexSeriesMap.remove(key);
141 series->setParent(0);
141 series->setParent(0);
142 series->d_ptr->m_dataset=0;
142 series->d_ptr->m_dataset=0;
143
143
144 QList<QAxis*> axes = m_seriesAxisMap.values();
144 QList<QAxis*> axes = m_seriesAxisMap.values();
145
145
146 int i = axes.indexOf(axis);
146 int i = axes.indexOf(axis);
147
147
148 if(i==-1){
148 if(i==-1){
149 Domain* domain = m_axisDomainMap.take(axis);
149 Domain* domain = m_axisDomainMap.take(axis);
150 emit axisRemoved(axis);
150 emit axisRemoved(axis);
151 if(axis!=m_axisY){
151 if(axis!=m_axisY){
152 axis->setParent(0);
152 axis->setParent(0);
153 delete domain;
153 delete domain;
154 }else{
154 }else{
155 m_axisYInitialized=false;
155 m_axisYInitialized=false;
156 m_axisDomainMap.insert(m_axisY,domain);
156 m_axisDomainMap.insert(m_axisY,domain);
157 }
157 }
158 }
158 }
159
159
160 if(m_seriesAxisMap.values().size()==0)
160 if(m_seriesAxisMap.values().size()==0)
161 {
161 {
162 m_axisXInitialized=false;
162 m_axisXInitialized=false;
163 emit axisRemoved(axisX());
163 emit axisRemoved(axisX());
164 }
164 }
165
165
166 return axis;
166 return axis;
167 }
167 }
168
168
169 void ChartDataSet::removeAllSeries()
169 void ChartDataSet::removeAllSeries()
170 {
170 {
171 QList<QAbstractSeries*> series = m_seriesAxisMap.keys();
171 QList<QAbstractSeries*> series = m_seriesAxisMap.keys();
172 QList<QAxis*> axes;
172 QList<QAxis*> axes;
173 foreach(QAbstractSeries *s , series) {
173 foreach(QAbstractSeries *s , series) {
174 QAxis* axis = removeSeries(s);
174 QAxis* axis = removeSeries(s);
175 if(axis==axisY()) continue;
175 if(axis==axisY()) continue;
176 int i = axes.indexOf(axis);
176 int i = axes.indexOf(axis);
177 if(i==-1){
177 if(i==-1){
178 axes<<axis;
178 axes<<axis;
179 }
179 }
180 }
180 }
181
181
182 Q_ASSERT(m_seriesAxisMap.count()==0);
182 Q_ASSERT(m_seriesAxisMap.count()==0);
183 Q_ASSERT(m_axisDomainMap.count()==1);
183 Q_ASSERT(m_axisDomainMap.count()==1);
184
184
185 qDeleteAll(series);
185 qDeleteAll(series);
186 qDeleteAll(axes);
186 qDeleteAll(axes);
187 }
187 }
188
188
189 void ChartDataSet::setupCategories(QBarSeries* series)
189 void ChartDataSet::setupCategories(QBarSeries* series)
190 {
190 {
191 QAxisCategories* categories = axisX()->categories();
191 QAxisCategories* categories = axisX()->categories();
192 categories->clear();
192 categories->clear();
193 categories->insert(series->categories());
193 categories->insert(series->categories());
194 }
194 }
195
195
196 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
196 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
197 {
197 {
198 QMapIterator<QAxis*, Domain*> i(m_axisDomainMap);
198 QMapIterator<QAxis*, Domain*> i(m_axisDomainMap);
199 //main domain has to be the last one;
199 //main domain has to be the last one;
200 Domain *domain = m_axisDomainMap.value(axisY());
200 Domain *domain = m_axisDomainMap.value(axisY());
201 Q_ASSERT(domain);
201 Q_ASSERT(domain);
202 while (i.hasNext()) {
202 while (i.hasNext()) {
203 i.next();
203 i.next();
204 if(i.value()==domain) continue;
204 if(i.value()==domain) continue;
205 i.value()->zoomIn(rect,size);
205 i.value()->zoomIn(rect,size);
206 }
206 }
207 domain->zoomIn(rect,size);
207 domain->zoomIn(rect,size);
208 }
208 }
209
209
210 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
210 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
211 {
211 {
212 QMapIterator<QAxis*, Domain*> i(m_axisDomainMap);
212 QMapIterator<QAxis*, Domain*> i(m_axisDomainMap);
213 //main domain has to be the last one;
213 //main domain has to be the last one;
214 Domain *domain = m_axisDomainMap.value(axisY());
214 Domain *domain = m_axisDomainMap.value(axisY());
215 Q_ASSERT(domain);
215 Q_ASSERT(domain);
216 while (i.hasNext()) {
216 while (i.hasNext()) {
217 i.next();
217 i.next();
218 if(i.value()==domain) continue;
218 if(i.value()==domain) continue;
219 i.value()->zoomOut(rect,size);
219 i.value()->zoomOut(rect,size);
220 }
220 }
221 domain->zoomOut(rect,size);
221 domain->zoomOut(rect,size);
222 }
222 }
223
223
224 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
224 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
225 {
225 {
226 int count=0;
226 int count=0;
227 QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap);
227 QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap);
228 while (i.hasNext()) {
228 while (i.hasNext()) {
229 i.next();
229 i.next();
230 if(i.key()->type()==type) count++;
230 if(i.key()->type()==type) count++;
231 }
231 }
232 return count;
232 return count;
233 }
233 }
234
234
235 int ChartDataSet::seriesIndex(QAbstractSeries *series)
235 int ChartDataSet::seriesIndex(QAbstractSeries *series)
236 {
236 {
237 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
237 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
238 while (i.hasNext()) {
238 while (i.hasNext()) {
239 i.next();
239 i.next();
240 if (i.value() == series)
240 if (i.value() == series)
241 return i.key();
241 return i.key();
242 }
242 }
243 return -1;
243 return -1;
244 }
244 }
245
245
246 QAxis* ChartDataSet::axisY(QAbstractSeries *series) const
246 QAxis* ChartDataSet::axisY(QAbstractSeries *series) const
247 {
247 {
248 if(series == 0) return m_axisY;
248 if(series == 0) return m_axisY;
249 return m_seriesAxisMap.value(series);
249 return m_seriesAxisMap.value(series);
250 }
250 }
251
251
252 Domain* ChartDataSet::domain(QAbstractSeries *series) const
252 Domain* ChartDataSet::domain(QAbstractSeries *series) const
253 {
253 {
254 QAxis* axis = m_seriesAxisMap.value(series);
254 QAxis* axis = m_seriesAxisMap.value(series);
255 if(axis){
255 if(axis){
256 return m_axisDomainMap.value(axis);
256 return m_axisDomainMap.value(axis);
257 }else
257 }else
258 return 0;
258 return 0;
259 }
259 }
260
260
261 Domain* ChartDataSet::domain(QAxis* axis) const
261 Domain* ChartDataSet::domain(QAxis* axis) const
262 {
262 {
263 if(!axis || axis==axisX()) {
263 if(!axis || axis==axisX()) {
264 return m_axisDomainMap.value(axisY());
264 return m_axisDomainMap.value(axisY());
265 }
265 }
266 else {
266 else {
267 return m_axisDomainMap.value(axis);
267 return m_axisDomainMap.value(axis);
268 }
268 }
269 }
269 }
270
270
271 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
271 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
272 {
272 {
273 QMapIterator<QAxis*, Domain*> i( m_axisDomainMap);
273 QMapIterator<QAxis*, Domain*> i( m_axisDomainMap);
274 //main domain has to be the last one;
274 //main domain has to be the last one;
275 Domain *domain = m_axisDomainMap.value(axisY());
275 Domain *domain = m_axisDomainMap.value(axisY());
276 while (i.hasNext()) {
276 while (i.hasNext()) {
277 i.next();
277 i.next();
278 if(i.value()==domain) continue;
278 if(i.value()==domain) continue;
279 i.value()->move(dx,dy,size);
279 i.value()->move(dx,dy,size);
280 }
280 }
281 domain->move(dx,dy,size);
281 domain->move(dx,dy,size);
282 }
282 }
283
283
284 QList<QAbstractSeries*> ChartDataSet::series() const
284 QList<QAbstractSeries*> ChartDataSet::series() const
285 {
285 {
286 return m_seriesAxisMap.keys();
286 return m_seriesAxisMap.keys();
287 }
287 }
288
288
289 void ChartDataSet::updateSeries(QAbstractSeries *series)
289 void ChartDataSet::updateSeries(QAbstractSeries *series)
290 {
290 {
291 emit seriesUpdated(series);
291 emit seriesUpdated(series);
292 }
292 }
293
293
294 #include "moc_chartdataset_p.cpp"
294 #include "moc_chartdataset_p.cpp"
295
295
296 QTCOMMERCIALCHART_END_NAMESPACE
296 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,95 +1,95
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 QAxis;
39 class QAxis;
40 class QBarSeries;
40 class QBarSeries;
41
41
42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 ChartDataSet(QObject* parent=0);
46 ChartDataSet(QObject* parent=0);
47 virtual ~ChartDataSet();
47 virtual ~ChartDataSet();
48
48
49 void addSeries(QAbstractSeries* series,QAxis *axisY = 0);
49 void addSeries(QAbstractSeries* series,QAxis *axisY = 0);
50 QAxis* removeSeries(QAbstractSeries* series);
50 QAxis* removeSeries(QAbstractSeries* series);
51 void removeAllSeries();
51 void removeAllSeries();
52 void updateSeries(QAbstractSeries* series);
52 void updateSeries(QAbstractSeries* series);
53
53
54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
56 void scrollDomain(int dx,int dy,const QSizeF& size);
56 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
57
57
58 int seriesCount(QAbstractSeries::SeriesType type);
58 int seriesCount(QAbstractSeries::SeriesType type);
59 int seriesIndex(QAbstractSeries *series);
59 int seriesIndex(QAbstractSeries *series);
60
60
61 Domain* domain(QAbstractSeries* series) const;
61 Domain* domain(QAbstractSeries* series) const;
62 Domain* domain(QAxis* axis) const;
62 Domain* domain(QAxis* axis) const;
63
63
64 QAxis* axisX() const { return m_axisX; }
64 QAxis* axisX() const { return m_axisX; }
65 QAxis* axisY(QAbstractSeries *series = 0) const;
65 QAxis* axisY(QAbstractSeries *series = 0) const;
66
66
67 QList<QAbstractSeries*> series() const;
67 QList<QAbstractSeries*> series() const;
68
68
69 Q_SIGNALS:
69 Q_SIGNALS:
70 void seriesAdded(QAbstractSeries* series, Domain* domain);
70 void seriesAdded(QAbstractSeries* series, Domain* domain);
71 void seriesRemoved(QAbstractSeries* series);
71 void seriesRemoved(QAbstractSeries* series);
72 void seriesUpdated(QAbstractSeries* series);
72 void seriesUpdated(QAbstractSeries* series);
73 void axisAdded(QAxis* axis,Domain* domain);
73 void axisAdded(QAxis* axis,Domain* domain);
74 void axisRemoved(QAxis* axis);
74 void axisRemoved(QAxis* axis);
75
75
76 private:
76 private:
77 QStringList createLabels(QAxis* axis,qreal min, qreal max);
77 QStringList createLabels(QAxis* axis,qreal min, qreal max);
78 void calculateDomain(QAbstractSeries* series,Domain* domain);
78 void calculateDomain(QAbstractSeries* series,Domain* domain);
79 void setupCategories(QBarSeries* series);
79 void setupCategories(QBarSeries* series);
80
80
81 private:
81 private:
82 QMap<QAbstractSeries *, QAxis *> m_seriesAxisMap;
82 QMap<QAbstractSeries *, QAxis *> m_seriesAxisMap;
83 QMap<QAxis*, Domain *> m_axisDomainMap;
83 QMap<QAxis*, Domain *> m_axisDomainMap;
84 QMap<int, QAbstractSeries *> m_indexSeriesMap;
84 QMap<int, QAbstractSeries *> m_indexSeriesMap;
85 QAxis* m_axisX;
85 QAxis* m_axisX;
86 QAxis* m_axisY;
86 QAxis* m_axisY;
87
87
88 int m_domainIndex;
88 int m_domainIndex;
89 bool m_axisXInitialized;
89 bool m_axisXInitialized;
90 bool m_axisYInitialized;
90 bool m_axisYInitialized;
91 };
91 };
92
92
93 QTCOMMERCIALCHART_END_NAMESPACE
93 QTCOMMERCIALCHART_END_NAMESPACE
94
94
95 #endif /* CHARTENGINE_P_H_ */
95 #endif /* CHARTENGINE_P_H_ */
@@ -1,430 +1,429
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 #include "chartpresenter_p.h"
20 #include "chartpresenter_p.h"
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qaxis.h"
23 #include "qaxis.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27 #include "chartanimation_p.h"
27 #include "chartanimation_p.h"
28 #include "qabstractseries_p.h"
28 #include "qabstractseries_p.h"
29 #include "qareaseries.h"
29 #include "qareaseries.h"
30 #include "chartaxis_p.h"
30 #include "chartaxis_p.h"
31 #include "chartaxisx_p.h"
31 #include "chartaxisx_p.h"
32 #include "chartaxisy_p.h"
32 #include "chartaxisy_p.h"
33 #include "areachartitem_p.h"
33 #include "areachartitem_p.h"
34 #include "chartbackground_p.h"
34 #include "chartbackground_p.h"
35 #include <QTimer>
35 #include <QTimer>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
39 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
40 m_chart(chart),
40 m_chart(chart),
41 m_animator(0),
41 m_animator(0),
42 m_dataset(dataset),
42 m_dataset(dataset),
43 m_chartTheme(0),
43 m_chartTheme(0),
44 m_chartRect(QRectF(QPoint(0,0),m_chart->size())),
44 m_chartRect(QRectF(QPoint(0,0),m_chart->size())),
45 m_options(QChart::NoAnimation),
45 m_options(QChart::NoAnimation),
46 m_minLeftMargin(0),
46 m_minLeftMargin(0),
47 m_minBottomMargin(0),
47 m_minBottomMargin(0),
48 m_state(ShowState),
48 m_state(ShowState),
49 m_backgroundItem(0),
49 m_backgroundItem(0),
50 m_titleItem(0),
50 m_titleItem(0),
51 m_marginBig(60),
51 m_marginBig(60),
52 m_marginSmall(20),
52 m_marginSmall(20),
53 m_marginTiny(10),
53 m_marginTiny(10),
54 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
54 m_chartMargins(QRect(m_marginBig,m_marginBig,0,0))
55 {
55 {
56
56
57 }
57 }
58
58
59 ChartPresenter::~ChartPresenter()
59 ChartPresenter::~ChartPresenter()
60 {
60 {
61 delete m_chartTheme;
61 delete m_chartTheme;
62 }
62 }
63
63
64 void ChartPresenter::setGeometry(const QRectF& rect)
64 void ChartPresenter::setGeometry(const QRectF& rect)
65 {
65 {
66 m_rect = rect;
66 m_rect = rect;
67 Q_ASSERT(m_rect.isValid());
67 Q_ASSERT(m_rect.isValid());
68 updateLayout();
68 updateLayout();
69 }
69 }
70
70
71 void ChartPresenter::setMinimumMarginWidth(ChartAxis* axis, qreal width)
71 void ChartPresenter::setMinimumMarginWidth(ChartAxis* axis, qreal width)
72 {
72 {
73 switch(axis->axisType()){
73 switch(axis->axisType()){
74 case ChartAxis::X_AXIS:
74 case ChartAxis::X_AXIS:
75 {
75 {
76 if(width>m_chartRect.width()+ m_chartMargins.left()) {
76 if(width>m_chartRect.width()+ m_chartMargins.left()) {
77 m_minLeftMargin= width - m_chartRect.width();
77 m_minLeftMargin= width - m_chartRect.width();
78 updateLayout();
78 updateLayout();
79 }
79 }
80 break;
80 break;
81 }
81 }
82 case ChartAxis::Y_AXIS:
82 case ChartAxis::Y_AXIS:
83 {
83 {
84
84
85 if(m_minLeftMargin!=width){
85 if(m_minLeftMargin!=width){
86 m_minLeftMargin= width;
86 m_minLeftMargin= width;
87 updateLayout();
87 updateLayout();
88 }
88 }
89 break;
89 break;
90 }
90 }
91
91
92 }
92 }
93 }
93 }
94
94
95 void ChartPresenter::setMinimumMarginHeight(ChartAxis* axis, qreal height)
95 void ChartPresenter::setMinimumMarginHeight(ChartAxis* axis, qreal height)
96 {
96 {
97 switch(axis->axisType()){
97 switch(axis->axisType()){
98 case ChartAxis::X_AXIS:
98 case ChartAxis::X_AXIS:
99 {
99 {
100 if(m_minBottomMargin!=height) {
100 if(m_minBottomMargin!=height) {
101 m_minBottomMargin= height;
101 m_minBottomMargin= height;
102 updateLayout();
102 updateLayout();
103 }
103 }
104 break;
104 break;
105 }
105 }
106 case ChartAxis::Y_AXIS:
106 case ChartAxis::Y_AXIS:
107 {
107 {
108
108
109 if(height>m_chartMargins.bottom()+m_chartRect.height()){
109 if(height>m_chartMargins.bottom()+m_chartRect.height()){
110 m_minBottomMargin= height - m_chartRect.height();
110 m_minBottomMargin= height - m_chartRect.height();
111 updateLayout();
111 updateLayout();
112 }
112 }
113 break;
113 break;
114 }
114 }
115
115
116 }
116 }
117 }
117 }
118
118
119 void ChartPresenter::handleAxisAdded(QAxis* axis,Domain* domain)
119 void ChartPresenter::handleAxisAdded(QAxis* axis,Domain* domain)
120 {
120 {
121 ChartAxis* item;
121 ChartAxis* item;
122
122
123 if(axis == m_dataset->axisX()){
123 if(axis == m_dataset->axisX()){
124 item = new ChartAxisX(axis,this);
124 item = new ChartAxisX(axis,this);
125 }else{
125 }else{
126 item = new ChartAxisY(axis,this);
126 item = new ChartAxisY(axis,this);
127 }
127 }
128
128
129 if(m_options.testFlag(QChart::GridAxisAnimations)){
129 if(m_options.testFlag(QChart::GridAxisAnimations)){
130 item->setAnimator(m_animator);
130 item->setAnimator(m_animator);
131 item->setAnimation(new AxisAnimation(item));
131 item->setAnimation(new AxisAnimation(item));
132 }
132 }
133
133
134 if(axis==m_dataset->axisX()){
134 if(axis==m_dataset->axisX()){
135 m_chartTheme->decorate(axis,true);
135 m_chartTheme->decorate(axis,true);
136 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
136 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
137 //initialize
137 //initialize
138 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
138 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
139
139
140 }
140 }
141 else{
141 else{
142 m_chartTheme->decorate(axis,false);
142 m_chartTheme->decorate(axis,false);
143 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
143 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
144 //initialize
144 //initialize
145 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
145 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
146 }
146 }
147
147
148 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
148 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
149 //initialize
149 //initialize
150 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
150 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
151 m_axisItems.insert(axis, item);
151 m_axisItems.insert(axis, item);
152 }
152 }
153
153
154 void ChartPresenter::handleAxisRemoved(QAxis* axis)
154 void ChartPresenter::handleAxisRemoved(QAxis* axis)
155 {
155 {
156 ChartAxis* item = m_axisItems.take(axis);
156 ChartAxis* item = m_axisItems.take(axis);
157 Q_ASSERT(item);
157 Q_ASSERT(item);
158 if(m_animator) m_animator->removeAnimation(item);
158 if(m_animator) m_animator->removeAnimation(item);
159 delete item;
159 delete item;
160 }
160 }
161
161
162
162
163 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
163 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
164 {
164 {
165 Chart *item = series->d_ptr->createGraphics(this);
165 Chart *item = series->d_ptr->createGraphics(this);
166 Q_ASSERT(item);
166 Q_ASSERT(item);
167 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
167 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
168 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
168 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
169 //initialize
169 //initialize
170 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
170 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
171 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
171 if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect);
172 m_chartItems.insert(series,item);
172 m_chartItems.insert(series,item);
173 }
173 }
174
174
175 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
175 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
176 {
176 {
177 Chart* item = m_chartItems.take(series);
177 Chart* item = m_chartItems.take(series);
178 Q_ASSERT(item);
178 Q_ASSERT(item);
179 if(m_animator) {
179 if(m_animator) {
180 //small hack to handle area animations
180 //small hack to handle area animations
181 if(series->type() == QAbstractSeries::SeriesTypeArea){
181 if(series->type() == QAbstractSeries::SeriesTypeArea){
182 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
182 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
183 AreaChartItem* area = static_cast<AreaChartItem*>(item);
183 AreaChartItem* area = static_cast<AreaChartItem*>(item);
184 m_animator->removeAnimation(area->upperLineItem());
184 m_animator->removeAnimation(area->upperLineItem());
185 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
185 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
186 }else
186 }else
187 m_animator->removeAnimation(item);
187 m_animator->removeAnimation(item);
188 }
188 }
189 delete item;
189 delete item;
190 }
190 }
191
191
192 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
192 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
193 {
193 {
194 if(m_chartTheme && m_chartTheme->id() == theme) return;
194 if(m_chartTheme && m_chartTheme->id() == theme) return;
195 delete m_chartTheme;
195 delete m_chartTheme;
196 m_chartTheme = ChartTheme::createTheme(theme);
196 m_chartTheme = ChartTheme::createTheme(theme);
197 m_chartTheme->setForced(force);
197 m_chartTheme->setForced(force);
198 m_chartTheme->decorate(m_chart);
198 m_chartTheme->decorate(m_chart);
199 m_chartTheme->decorate(m_chart->legend());
199 m_chartTheme->decorate(m_chart->legend());
200 resetAllElements();
200 resetAllElements();
201
201
202 // We do not want "force" to stay on.
202 // We do not want "force" to stay on.
203 // Bar/pie are calling decorate when adding/removing slices/bars which means
203 // Bar/pie are calling decorate when adding/removing slices/bars which means
204 // that to preserve users colors "force" must not be on.
204 // that to preserve users colors "force" must not be on.
205 m_chartTheme->setForced(false);
205 m_chartTheme->setForced(false);
206 }
206 }
207
207
208 QChart::ChartTheme ChartPresenter::theme()
208 QChart::ChartTheme ChartPresenter::theme()
209 {
209 {
210 return m_chartTheme->id();
210 return m_chartTheme->id();
211 }
211 }
212
212
213 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
213 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
214 {
214 {
215 if(m_options!=options) {
215 if(m_options!=options) {
216
216
217 m_options=options;
217 m_options=options;
218
218
219 if(m_options!=QChart::NoAnimation && !m_animator) {
219 if(m_options!=QChart::NoAnimation && !m_animator) {
220 m_animator= new ChartAnimator(this);
220 m_animator= new ChartAnimator(this);
221 }
221 }
222 resetAllElements();
222 resetAllElements();
223 }
223 }
224
224
225 }
225 }
226
226
227 void ChartPresenter::resetAllElements()
227 void ChartPresenter::resetAllElements()
228 {
228 {
229 QList<QAxis *> axisList = m_axisItems.uniqueKeys();
229 QList<QAxis *> axisList = m_axisItems.uniqueKeys();
230 QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys();
230 QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys();
231
231
232 foreach(QAxis *axis, axisList) {
232 foreach(QAxis *axis, axisList) {
233 handleAxisRemoved(axis);
233 handleAxisRemoved(axis);
234 handleAxisAdded(axis,m_dataset->domain(axis));
234 handleAxisAdded(axis,m_dataset->domain(axis));
235 }
235 }
236 foreach(QAbstractSeries *series, seriesList) {
236 foreach(QAbstractSeries *series, seriesList) {
237 handleSeriesRemoved(series);
237 handleSeriesRemoved(series);
238 handleSeriesAdded(series,m_dataset->domain(series));
238 handleSeriesAdded(series,m_dataset->domain(series));
239 // m_dataset->removeSeries(series);
239 // m_dataset->removeSeries(series);
240 // m_dataset->addSeries(series);
240 // m_dataset->addSeries(series);
241 }
241 }
242 }
242 }
243
243
244 void ChartPresenter::zoomIn(qreal factor)
244 void ChartPresenter::zoomIn(qreal factor)
245 {
245 {
246 QRectF rect = chartGeometry();
246 QRectF rect = chartGeometry();
247 rect.setWidth(rect.width()/factor);
247 rect.setWidth(rect.width()/factor);
248 rect.setHeight(rect.height()/factor);
248 rect.setHeight(rect.height()/factor);
249 rect.moveCenter(chartGeometry().center());
249 rect.moveCenter(chartGeometry().center());
250 zoomIn(rect);
250 zoomIn(rect);
251 }
251 }
252
252
253 void ChartPresenter::zoomIn(const QRectF& rect)
253 void ChartPresenter::zoomIn(const QRectF& rect)
254 {
254 {
255 QRectF r = rect.normalized();
255 QRectF r = rect.normalized();
256 r.translate(-m_chartMargins.topLeft());
256 r.translate(-m_chartMargins.topLeft());
257 if (!r.isValid())
257 if (!r.isValid())
258 return;
258 return;
259
259
260 m_state = ZoomInState;
260 m_state = ZoomInState;
261 m_statePoint = QPointF(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
261 m_statePoint = QPointF(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height());
262 m_dataset->zoomInDomain(r,chartGeometry().size());
262 m_dataset->zoomInDomain(r,chartGeometry().size());
263 m_state = ShowState;
263 m_state = ShowState;
264 }
264 }
265
265
266 void ChartPresenter::zoomOut(qreal factor)
266 void ChartPresenter::zoomOut(qreal factor)
267 {
267 {
268 m_state = ZoomOutState;
268 m_state = ZoomOutState;
269
269
270 QRectF chartRect;
270 QRectF chartRect;
271 chartRect.setSize(chartGeometry().size());
271 chartRect.setSize(chartGeometry().size());
272
272
273 QRectF rect;
273 QRectF rect;
274 rect.setSize(chartRect.size()/factor);
274 rect.setSize(chartRect.size()/factor);
275 rect.moveCenter(chartRect.center());
275 rect.moveCenter(chartRect.center());
276 if (!rect.isValid())
276 if (!rect.isValid())
277 return;
277 return;
278 m_statePoint = QPointF(rect.center().x()/chartGeometry().width(),rect.center().y()/chartGeometry().height());
278 m_statePoint = QPointF(rect.center().x()/chartGeometry().width(),rect.center().y()/chartGeometry().height());
279 m_dataset->zoomOutDomain(rect, chartRect.size());
279 m_dataset->zoomOutDomain(rect, chartRect.size());
280 m_state = ShowState;
280 m_state = ShowState;
281 }
281 }
282
282
283 void ChartPresenter::scroll(int dx,int dy)
283 void ChartPresenter::scroll(qreal dx,qreal dy)
284 {
284 {
285
286 if(dx<0) m_state=ScrollLeftState;
285 if(dx<0) m_state=ScrollLeftState;
287 if(dx>0) m_state=ScrollRightState;
286 if(dx>0) m_state=ScrollRightState;
288 if(dy<0) m_state=ScrollUpState;
287 if(dy<0) m_state=ScrollUpState;
289 if(dy>0) m_state=ScrollDownState;
288 if(dy>0) m_state=ScrollDownState;
290
289
291 m_dataset->scrollDomain(dx,dy,chartGeometry().size());
290 m_dataset->scrollDomain(dx,dy,chartGeometry().size());
292 m_state = ShowState;
291 m_state = ShowState;
293 }
292 }
294
293
295 QChart::AnimationOptions ChartPresenter::animationOptions() const
294 QChart::AnimationOptions ChartPresenter::animationOptions() const
296 {
295 {
297 return m_options;
296 return m_options;
298 }
297 }
299
298
300 void ChartPresenter::updateLayout()
299 void ChartPresenter::updateLayout()
301 {
300 {
302 if (!m_rect.isValid()) return;
301 if (!m_rect.isValid()) return;
303
302
304 // recalculate title size
303 // recalculate title size
305
304
306 QSize titleSize;
305 QSize titleSize;
307 int titlePadding=0;
306 int titlePadding=0;
308
307
309 if (m_titleItem) {
308 if (m_titleItem) {
310 titleSize= m_titleItem->boundingRect().size().toSize();
309 titleSize= m_titleItem->boundingRect().size().toSize();
311 }
310 }
312
311
313 //defaults
312 //defaults
314 m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig));
313 m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig));
315 titlePadding = m_chartMargins.top()/2;
314 titlePadding = m_chartMargins.top()/2;
316
315
317 QLegend* legend = m_chart->d_ptr->m_legend;
316 QLegend* legend = m_chart->d_ptr->m_legend;
318
317
319 // recalculate legend position
318 // recalculate legend position
320 if (legend->isAttachedToChart() && legend->isEnabled()) {
319 if (legend->isAttachedToChart() && legend->isEnabled()) {
321
320
322 QRect legendRect;
321 QRect legendRect;
323
322
324 // Reserve some space for legend
323 // Reserve some space for legend
325 switch (legend->alignment()) {
324 switch (legend->alignment()) {
326
325
327 case QLegend::AlignmentTop: {
326 case QLegend::AlignmentTop: {
328 int ledgendSize = legend->minHeight();
327 int ledgendSize = legend->minHeight();
329 int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny;
328 int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny;
330 m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
329 m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
331 m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny));
330 m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny));
332 titlePadding = m_marginTiny + m_marginTiny;
331 titlePadding = m_marginTiny + m_marginTiny;
333 break;
332 break;
334 }
333 }
335 case QLegend::AlignmentBottom: {
334 case QLegend::AlignmentBottom: {
336 int ledgendSize = legend->minHeight();
335 int ledgendSize = legend->minHeight();
337 int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin;
336 int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin;
338 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding));
337 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding));
339 m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall));
338 m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall));
340 titlePadding = m_chartMargins.top()/2;
339 titlePadding = m_chartMargins.top()/2;
341 break;
340 break;
342 }
341 }
343 case QLegend::AlignmentLeft: {
342 case QLegend::AlignmentLeft: {
344 int ledgendSize = legend->minWidth();
343 int ledgendSize = legend->minWidth();
345 int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin;
344 int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin;
346 m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
345 m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom()));
347 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom()));
346 m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom()));
348 titlePadding = m_chartMargins.top()/2;
347 titlePadding = m_chartMargins.top()/2;
349 break;
348 break;
350 }
349 }
351 case QLegend::AlignmentRight: {
350 case QLegend::AlignmentRight: {
352 int ledgendSize = legend->minWidth();
351 int ledgendSize = legend->minWidth();
353 int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny;
352 int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny;
354 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
353 m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom()));
355 m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom()));
354 m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom()));
356 titlePadding = m_chartMargins.top()/2;
355 titlePadding = m_chartMargins.top()/2;
357 break;
356 break;
358 }
357 }
359 default: {
358 default: {
360 break;
359 break;
361 }
360 }
362 }
361 }
363 }
362 }
364
363
365 if(m_rect.width()<2*(m_chartMargins.top()+m_chartMargins.bottom()) || m_rect.height()< 2*(m_chartMargins.top() + m_chartMargins.bottom()))
364 if(m_rect.width()<2*(m_chartMargins.top()+m_chartMargins.bottom()) || m_rect.height()< 2*(m_chartMargins.top() + m_chartMargins.bottom()))
366 {
365 {
367 m_chart->setMinimumSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom()));
366 m_chart->setMinimumSize(2*(m_chartMargins.top()+m_chartMargins.bottom()),2*(m_chartMargins.top() + m_chartMargins.bottom()));
368 return;
367 return;
369 }
368 }
370
369
371
370
372 // recalculate title position
371 // recalculate title position
373 if (m_titleItem) {
372 if (m_titleItem) {
374 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
373 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
375 m_titleItem->setPos(center.x(),titlePadding);
374 m_titleItem->setPos(center.x(),titlePadding);
376 }
375 }
377
376
378 //recalculate background gradient
377 //recalculate background gradient
379 if (m_backgroundItem) {
378 if (m_backgroundItem) {
380 m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
379 m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny));
381 }
380 }
382
381
383
382
384 QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
383 QRectF chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom());
385
384
386 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
385 legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom()));
387
386
388 if(m_chartRect!=chartRect && chartRect.isValid()){
387 if(m_chartRect!=chartRect && chartRect.isValid()){
389 m_chartRect=chartRect;
388 m_chartRect=chartRect;
390 emit geometryChanged(m_chartRect);
389 emit geometryChanged(m_chartRect);
391 }
390 }
392
391
393 }
392 }
394
393
395 void ChartPresenter::createChartBackgroundItem()
394 void ChartPresenter::createChartBackgroundItem()
396 {
395 {
397 if (!m_backgroundItem) {
396 if (!m_backgroundItem) {
398 m_backgroundItem = new ChartBackground(rootItem());
397 m_backgroundItem = new ChartBackground(rootItem());
399 m_backgroundItem->setPen(Qt::NoPen);
398 m_backgroundItem->setPen(Qt::NoPen);
400 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
399 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
401 }
400 }
402 }
401 }
403
402
404 void ChartPresenter::createChartTitleItem()
403 void ChartPresenter::createChartTitleItem()
405 {
404 {
406 if (!m_titleItem) {
405 if (!m_titleItem) {
407 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
406 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
408 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
407 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
409 }
408 }
410 }
409 }
411
410
412 void ChartPresenter::handleAnimationFinished()
411 void ChartPresenter::handleAnimationFinished()
413 {
412 {
414 m_animations.removeAll(qobject_cast<ChartAnimation*>(sender()));
413 m_animations.removeAll(qobject_cast<ChartAnimation*>(sender()));
415 if(m_animations.empty()) emit animationsFinished();
414 if(m_animations.empty()) emit animationsFinished();
416 }
415 }
417
416
418 void ChartPresenter::startAnimation(ChartAnimation* animation)
417 void ChartPresenter::startAnimation(ChartAnimation* animation)
419 {
418 {
420 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
419 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
421 QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection);
420 QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection);
422 if(!m_animations.isEmpty()){
421 if(!m_animations.isEmpty()){
423 m_animations.append(animation);
422 m_animations.append(animation);
424 }
423 }
425 QTimer::singleShot(0, animation, SLOT(start()));
424 QTimer::singleShot(0, animation, SLOT(start()));
426 }
425 }
427
426
428 #include "moc_chartpresenter_p.cpp"
427 #include "moc_chartpresenter_p.cpp"
429
428
430 QTCOMMERCIALCHART_END_NAMESPACE
429 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,145 +1,145
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 #ifndef CHARTPRESENTER_H
21 #ifndef CHARTPRESENTER_H
22 #define CHARTPRESENTER_H
22 #define CHARTPRESENTER_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
25 #include "qchart.h" //becouse of QChart::ChartThemeId //TODO
26 #include <QRectF>
26 #include <QRectF>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class Chart;
30 class Chart;
31 class QAbstractSeries;
31 class QAbstractSeries;
32 class ChartDataSet;
32 class ChartDataSet;
33 class Domain;
33 class Domain;
34 class ChartAxis;
34 class ChartAxis;
35 class ChartTheme;
35 class ChartTheme;
36 class ChartAnimator;
36 class ChartAnimator;
37 class ChartBackground;
37 class ChartBackground;
38 class ChartAnimation;
38 class ChartAnimation;
39
39
40 class ChartPresenter: public QObject
40 class ChartPresenter: public QObject
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 enum ZValues {
44 enum ZValues {
45 BackgroundZValue = -1,
45 BackgroundZValue = -1,
46 ShadesZValue,
46 ShadesZValue,
47 GridZValue,
47 GridZValue,
48 SeriesZValue,
48 SeriesZValue,
49 LineChartZValue = SeriesZValue,
49 LineChartZValue = SeriesZValue,
50 BarSeriesZValue = SeriesZValue,
50 BarSeriesZValue = SeriesZValue,
51 ScatterSeriesZValue = SeriesZValue,
51 ScatterSeriesZValue = SeriesZValue,
52 PieSeriesZValue = SeriesZValue,
52 PieSeriesZValue = SeriesZValue,
53 AxisZValue,
53 AxisZValue,
54 LegendZValue
54 LegendZValue
55 };
55 };
56
56
57 enum State {
57 enum State {
58 ShowState,
58 ShowState,
59 ScrollUpState,
59 ScrollUpState,
60 ScrollDownState,
60 ScrollDownState,
61 ScrollLeftState,
61 ScrollLeftState,
62 ScrollRightState,
62 ScrollRightState,
63 ZoomInState,
63 ZoomInState,
64 ZoomOutState
64 ZoomOutState
65 };
65 };
66
66
67 ChartPresenter(QChart* chart,ChartDataSet *dataset);
67 ChartPresenter(QChart* chart,ChartDataSet *dataset);
68 virtual ~ChartPresenter();
68 virtual ~ChartPresenter();
69
69
70 ChartAnimator* animator() const { return m_animator; }
70 ChartAnimator* animator() const { return m_animator; }
71 ChartTheme *chartTheme() const { return m_chartTheme; }
71 ChartTheme *chartTheme() const { return m_chartTheme; }
72 ChartDataSet *dataSet() const { return m_dataset; }
72 ChartDataSet *dataSet() const { return m_dataset; }
73 QGraphicsItem* rootItem() const { return m_chart; }
73 QGraphicsItem* rootItem() const { return m_chart; }
74
74
75 void setTheme(QChart::ChartTheme theme,bool force = true);
75 void setTheme(QChart::ChartTheme theme,bool force = true);
76 QChart::ChartTheme theme();
76 QChart::ChartTheme theme();
77
77
78 void setAnimationOptions(QChart::AnimationOptions options);
78 void setAnimationOptions(QChart::AnimationOptions options);
79 QChart::AnimationOptions animationOptions() const;
79 QChart::AnimationOptions animationOptions() const;
80
80
81 void zoomIn(qreal factor);
81 void zoomIn(qreal factor);
82 void zoomIn(const QRectF& rect);
82 void zoomIn(const QRectF& rect);
83 void zoomOut(qreal factor);
83 void zoomOut(qreal factor);
84 void scroll(int dx,int dy);
84 void scroll(qreal dx,qreal dy);
85
85
86 void setGeometry(const QRectF& rect);
86 void setGeometry(const QRectF& rect);
87 QRectF chartGeometry() const { return m_chartRect; }
87 QRectF chartGeometry() const { return m_chartRect; }
88
88
89 void setMinimumMarginHeight(ChartAxis* axis, qreal height);
89 void setMinimumMarginHeight(ChartAxis* axis, qreal height);
90 void setMinimumMarginWidth(ChartAxis* axis, qreal width);
90 void setMinimumMarginWidth(ChartAxis* axis, qreal width);
91 qreal minimumLeftMargin() const { return m_minLeftMargin; }
91 qreal minimumLeftMargin() const { return m_minLeftMargin; }
92 qreal minimumBottomMargin() const { return m_minBottomMargin; }
92 qreal minimumBottomMargin() const { return m_minBottomMargin; }
93
93
94 void startAnimation(ChartAnimation* animation);
94 void startAnimation(ChartAnimation* animation);
95 State state() const { return m_state; }
95 State state() const { return m_state; }
96 QPointF statePoint() const { return m_statePoint; }
96 QPointF statePoint() const { return m_statePoint; }
97 public: //TODO: fix me
97 public: //TODO: fix me
98 void resetAllElements();
98 void resetAllElements();
99 void createChartBackgroundItem();
99 void createChartBackgroundItem();
100 void createChartTitleItem();
100 void createChartTitleItem();
101 QRectF margins() const { return m_chartMargins;}
101 QRectF margins() const { return m_chartMargins;}
102
102
103 public Q_SLOTS:
103 public Q_SLOTS:
104 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
104 void handleSeriesAdded(QAbstractSeries* series,Domain* domain);
105 void handleSeriesRemoved(QAbstractSeries* series);
105 void handleSeriesRemoved(QAbstractSeries* series);
106 void handleAxisAdded(QAxis* axis,Domain* domain);
106 void handleAxisAdded(QAxis* axis,Domain* domain);
107 void handleAxisRemoved(QAxis* axis);
107 void handleAxisRemoved(QAxis* axis);
108 void updateLayout();
108 void updateLayout();
109
109
110 private Q_SLOTS:
110 private Q_SLOTS:
111 void handleAnimationFinished();
111 void handleAnimationFinished();
112
112
113 Q_SIGNALS:
113 Q_SIGNALS:
114 void geometryChanged(const QRectF& rect);
114 void geometryChanged(const QRectF& rect);
115 void animationsFinished();
115 void animationsFinished();
116
116
117 private:
117 private:
118 QChart* m_chart;
118 QChart* m_chart;
119 ChartAnimator* m_animator;
119 ChartAnimator* m_animator;
120 ChartDataSet* m_dataset;
120 ChartDataSet* m_dataset;
121 ChartTheme *m_chartTheme;
121 ChartTheme *m_chartTheme;
122 QMap<QAbstractSeries *, Chart *> m_chartItems;
122 QMap<QAbstractSeries *, Chart *> m_chartItems;
123 QMap<QAxis *, ChartAxis *> m_axisItems;
123 QMap<QAxis *, ChartAxis *> m_axisItems;
124 QRectF m_rect;
124 QRectF m_rect;
125 QRectF m_chartRect;
125 QRectF m_chartRect;
126 QChart::AnimationOptions m_options;
126 QChart::AnimationOptions m_options;
127 qreal m_minLeftMargin;
127 qreal m_minLeftMargin;
128 qreal m_minBottomMargin;
128 qreal m_minBottomMargin;
129 State m_state;
129 State m_state;
130 QPointF m_statePoint;
130 QPointF m_statePoint;
131 QList<ChartAnimation*> m_animations;
131 QList<ChartAnimation*> m_animations;
132
132
133 public: //TODO: fixme
133 public: //TODO: fixme
134 ChartBackground* m_backgroundItem;
134 ChartBackground* m_backgroundItem;
135 QGraphicsSimpleTextItem* m_titleItem;
135 QGraphicsSimpleTextItem* m_titleItem;
136 int m_marginBig;
136 int m_marginBig;
137 int m_marginSmall;
137 int m_marginSmall;
138 int m_marginTiny;
138 int m_marginTiny;
139 QRectF m_chartMargins;
139 QRectF m_chartMargins;
140 QRectF m_legendMargins;
140 QRectF m_legendMargins;
141 };
141 };
142
142
143 QTCOMMERCIALCHART_END_NAMESPACE
143 QTCOMMERCIALCHART_END_NAMESPACE
144
144
145 #endif /* CHARTPRESENTER_H_ */
145 #endif /* CHARTPRESENTER_H_ */
@@ -1,302 +1,302
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 "domain_p.h"
21 #include "domain_p.h"
22 #include <cmath>
22 #include <cmath>
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 Domain::Domain(QObject* parent) : QObject(parent),
26 Domain::Domain(QObject* parent) : QObject(parent),
27 m_minX(0),
27 m_minX(0),
28 m_maxX(0),
28 m_maxX(0),
29 m_minY(0),
29 m_minY(0),
30 m_maxY(0),
30 m_maxY(0),
31 m_tickXCount(5),
31 m_tickXCount(5),
32 m_tickYCount(5),
32 m_tickYCount(5),
33 m_niceXNumbers(false),
33 m_niceXNumbers(false),
34 m_niceYNumbers(false)
34 m_niceYNumbers(false)
35 {
35 {
36 }
36 }
37
37
38 Domain::~Domain()
38 Domain::~Domain()
39 {
39 {
40 }
40 }
41
41
42 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
42 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
43 {
43 {
44 setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount);
44 setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount);
45 }
45 }
46
46
47 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount)
47 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount)
48 {
48 {
49 bool axisXChanged = false;
49 bool axisXChanged = false;
50 bool axisYChanged = false;
50 bool axisYChanged = false;
51
51
52 if(m_tickXCount!=tickXCount) {
52 if(m_tickXCount!=tickXCount) {
53 m_tickXCount=tickXCount;
53 m_tickXCount=tickXCount;
54 axisXChanged=true;
54 axisXChanged=true;
55 }
55 }
56
56
57 if(m_tickYCount!=tickYCount) {
57 if(m_tickYCount!=tickYCount) {
58 m_tickYCount=tickYCount;
58 m_tickYCount=tickYCount;
59 axisYChanged=true;
59 axisYChanged=true;
60 }
60 }
61
61
62 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
62 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
63 if(m_niceXNumbers) looseNiceNumbers(minX, maxX, m_tickXCount);
63 if(m_niceXNumbers) looseNiceNumbers(minX, maxX, m_tickXCount);
64 m_minX=minX;
64 m_minX=minX;
65 m_maxX=maxX;
65 m_maxX=maxX;
66 axisXChanged=true;
66 axisXChanged=true;
67 }
67 }
68
68
69 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
69 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
70 if(m_niceYNumbers) looseNiceNumbers(minY, maxY, m_tickYCount);
70 if(m_niceYNumbers) looseNiceNumbers(minY, maxY, m_tickYCount);
71 m_minY=minY;
71 m_minY=minY;
72 m_maxY=maxY;
72 m_maxY=maxY;
73 axisYChanged=true;
73 axisYChanged=true;
74 }
74 }
75
75
76 if(axisXChanged || axisYChanged) {
76 if(axisXChanged || axisYChanged) {
77 emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY);
77 emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY);
78 }
78 }
79
79
80 if(axisXChanged) {
80 if(axisXChanged) {
81 emit rangeXChanged(minX,maxX, m_tickXCount);
81 emit rangeXChanged(minX,maxX, m_tickXCount);
82 }
82 }
83
83
84 if(axisYChanged) {
84 if(axisYChanged) {
85 emit rangeYChanged(minY,maxY, m_tickYCount);
85 emit rangeYChanged(minY,maxY, m_tickYCount);
86 }
86 }
87 }
87 }
88
88
89 void Domain::setRangeX(qreal min, qreal max)
89 void Domain::setRangeX(qreal min, qreal max)
90 {
90 {
91 setRange(min,max,m_minY, m_maxY);
91 setRange(min,max,m_minY, m_maxY);
92 }
92 }
93
93
94 void Domain::setRangeX(qreal min, qreal max, int tickCount)
94 void Domain::setRangeX(qreal min, qreal max, int tickCount)
95 {
95 {
96 setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount);
96 setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount);
97 }
97 }
98
98
99 void Domain::setRangeY(qreal min, qreal max)
99 void Domain::setRangeY(qreal min, qreal max)
100 {
100 {
101 setRange(m_minX, m_maxX, min, max);
101 setRange(m_minX, m_maxX, min, max);
102 }
102 }
103
103
104 void Domain::setRangeY(qreal min, qreal max,int tickCount)
104 void Domain::setRangeY(qreal min, qreal max,int tickCount)
105 {
105 {
106 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount);
106 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount);
107 }
107 }
108
108
109 void Domain::setMinX(qreal min)
109 void Domain::setMinX(qreal min)
110 {
110 {
111 setRange(min, m_maxX, m_minY, m_maxY);
111 setRange(min, m_maxX, m_minY, m_maxY);
112 }
112 }
113
113
114 void Domain::setMaxX(qreal max)
114 void Domain::setMaxX(qreal max)
115 {
115 {
116 setRange(m_minX, max, m_minY, m_maxY);
116 setRange(m_minX, max, m_minY, m_maxY);
117 }
117 }
118
118
119 void Domain::setMinY(qreal min)
119 void Domain::setMinY(qreal min)
120 {
120 {
121 setRange(m_minX, m_maxX, min, m_maxY);
121 setRange(m_minX, m_maxX, min, m_maxY);
122 }
122 }
123
123
124 void Domain::setMaxY(qreal max)
124 void Domain::setMaxY(qreal max)
125 {
125 {
126 setRange(m_minX, m_maxX, m_minY, max);
126 setRange(m_minX, m_maxX, m_minY, max);
127 }
127 }
128
128
129 qreal Domain::spanX() const
129 qreal Domain::spanX() const
130 {
130 {
131 Q_ASSERT(m_maxX >= m_minX);
131 Q_ASSERT(m_maxX >= m_minX);
132 return m_maxX - m_minX;
132 return m_maxX - m_minX;
133 }
133 }
134
134
135 qreal Domain::spanY() const
135 qreal Domain::spanY() const
136 {
136 {
137 Q_ASSERT(m_maxY >= m_minY);
137 Q_ASSERT(m_maxY >= m_minY);
138 return m_maxY - m_minY;
138 return m_maxY - m_minY;
139 }
139 }
140
140
141 bool Domain::isEmpty() const
141 bool Domain::isEmpty() const
142 {
142 {
143 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY());
143 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY());
144 }
144 }
145
145
146 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
146 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
147 {
147 {
148 qreal dx = spanX() / size.width();
148 qreal dx = spanX() / size.width();
149 qreal dy = spanY() / size.height();
149 qreal dy = spanY() / size.height();
150
150
151 qreal maxX = m_maxX;
151 qreal maxX = m_maxX;
152 qreal minX = m_minX;
152 qreal minX = m_minX;
153 qreal minY = m_minY;
153 qreal minY = m_minY;
154 qreal maxY = m_maxY;
154 qreal maxY = m_maxY;
155
155
156 maxX = minX + dx * rect.right();
156 maxX = minX + dx * rect.right();
157 minX = minX + dx * rect.left();
157 minX = minX + dx * rect.left();
158 minY = maxY - dy * rect.bottom();
158 minY = maxY - dy * rect.bottom();
159 maxY = maxY - dy * rect.top();
159 maxY = maxY - dy * rect.top();
160
160
161 int tickXCount = m_tickXCount;
161 int tickXCount = m_tickXCount;
162 int tickYCount = m_tickYCount;
162 int tickYCount = m_tickYCount;
163
163
164 if(m_niceXNumbers) {
164 if(m_niceXNumbers) {
165 looseNiceNumbers(minX, maxX, tickXCount);
165 looseNiceNumbers(minX, maxX, tickXCount);
166 }
166 }
167 if(m_niceYNumbers) {
167 if(m_niceYNumbers) {
168 looseNiceNumbers(minY, maxY, tickYCount);
168 looseNiceNumbers(minY, maxY, tickYCount);
169 }
169 }
170 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
170 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
171 }
171 }
172
172
173 void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
173 void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
174 {
174 {
175 qreal dx = spanX() / rect.width();
175 qreal dx = spanX() / rect.width();
176 qreal dy = spanY() / rect.height();
176 qreal dy = spanY() / rect.height();
177
177
178 qreal maxX = m_maxX;
178 qreal maxX = m_maxX;
179 qreal minX = m_minX;
179 qreal minX = m_minX;
180 qreal minY = m_minY;
180 qreal minY = m_minY;
181 qreal maxY = m_maxY;
181 qreal maxY = m_maxY;
182
182
183 minX = maxX - dx * rect.right();
183 minX = maxX - dx * rect.right();
184 maxX = minX + dx * size.width();
184 maxX = minX + dx * size.width();
185 maxY = minY + dy * rect.bottom();
185 maxY = minY + dy * rect.bottom();
186 minY = maxY - dy * size.height();
186 minY = maxY - dy * size.height();
187
187
188 int tickXCount = m_tickXCount;
188 int tickXCount = m_tickXCount;
189 int tickYCount = m_tickYCount;
189 int tickYCount = m_tickYCount;
190
190
191 if(m_niceXNumbers) {
191 if(m_niceXNumbers) {
192 looseNiceNumbers(minX, maxX, tickXCount);
192 looseNiceNumbers(minX, maxX, tickXCount);
193 }
193 }
194 if(m_niceYNumbers) {
194 if(m_niceYNumbers) {
195 looseNiceNumbers(minY, maxY, tickYCount);
195 looseNiceNumbers(minY, maxY, tickYCount);
196 }
196 }
197 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
197 setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
198 }
198 }
199
199
200 void Domain::move(int dx,int dy,const QSizeF& size)
200 void Domain::move(qreal dx,qreal dy,const QSizeF& size)
201 {
201 {
202 qreal x = spanX() / size.width();
202 qreal x = spanX() / size.width();
203 qreal y = spanY() / size.height();
203 qreal y = spanY() / size.height();
204
204
205 qreal maxX = m_maxX;
205 qreal maxX = m_maxX;
206 qreal minX = m_minX;
206 qreal minX = m_minX;
207 qreal minY = m_minY;
207 qreal minY = m_minY;
208 qreal maxY = m_maxY;
208 qreal maxY = m_maxY;
209
209
210 if(dx!=0) {
210 if(dx!=0) {
211 minX = minX + x * dx;
211 minX = minX + x * dx;
212 maxX = maxX + x * dx;
212 maxX = maxX + x * dx;
213 }
213 }
214 if(dy!=0) {
214 if(dy!=0) {
215 minY = minY + y * dy;
215 minY = minY + y * dy;
216 maxY = maxY + y * dy;
216 maxY = maxY + y * dy;
217 }
217 }
218 setRange(minX,maxX,minY,maxY);
218 setRange(minX,maxX,minY,maxY);
219 }
219 }
220
220
221 void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers)
221 void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers)
222 {
222 {
223 if (m_niceXNumbers != niceNumbers) {
223 if (m_niceXNumbers != niceNumbers) {
224 m_niceXNumbers = niceNumbers;
224 m_niceXNumbers = niceNumbers;
225 //force recalculation
225 //force recalculation
226 m_minX = 0;
226 m_minX = 0;
227 m_maxX = 0;
227 m_maxX = 0;
228 }
228 }
229 setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount);
229 setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount);
230 }
230 }
231
231
232 void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers)
232 void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers)
233 {
233 {
234 if (m_niceYNumbers != niceNumbers) {
234 if (m_niceYNumbers != niceNumbers) {
235 m_niceYNumbers = niceNumbers;
235 m_niceYNumbers = niceNumbers;
236 //force recalculation
236 //force recalculation
237 m_minY = 0;
237 m_minY = 0;
238 m_maxY = 0;
238 m_maxY = 0;
239 }
239 }
240 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount);
240 setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount);
241 }
241 }
242
242
243 //algorithm defined by Paul S.Heckbert GraphicalGems I
243 //algorithm defined by Paul S.Heckbert GraphicalGems I
244
244
245 void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
245 void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
246 {
246 {
247 qreal range = niceNumber(max-min,true); //range with ceiling
247 qreal range = niceNumber(max-min,true); //range with ceiling
248 qreal step = niceNumber(range/(ticksCount-1),false);
248 qreal step = niceNumber(range/(ticksCount-1),false);
249 min = floor(min/step);
249 min = floor(min/step);
250 max = ceil(max/step);
250 max = ceil(max/step);
251 ticksCount = int(max-min) +1;
251 ticksCount = int(max-min) +1;
252 min*=step;
252 min*=step;
253 max*=step;
253 max*=step;
254 }
254 }
255
255
256 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
256 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
257
257
258 qreal Domain::niceNumber(qreal x,bool ceiling) const
258 qreal Domain::niceNumber(qreal x,bool ceiling) const
259 {
259 {
260 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
260 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
261 qreal q = x/z;//q<10 && q>=1;
261 qreal q = x/z;//q<10 && q>=1;
262
262
263 if(ceiling) {
263 if(ceiling) {
264 if(q <= 1.0) q=1;
264 if(q <= 1.0) q=1;
265 else if(q <= 2.0) q=2;
265 else if(q <= 2.0) q=2;
266 else if(q <= 5.0) q=5;
266 else if(q <= 5.0) q=5;
267 else q=10;
267 else q=10;
268 }
268 }
269 else {
269 else {
270 if(q < 1.5) q=1;
270 if(q < 1.5) q=1;
271 else if(q < 3.0) q=2;
271 else if(q < 3.0) q=2;
272 else if(q < 7.0) q=5;
272 else if(q < 7.0) q=5;
273 else q=10;
273 else q=10;
274 }
274 }
275 return q*z;
275 return q*z;
276 }
276 }
277
277
278
278
279 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
279 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
280 {
280 {
281 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
281 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
282 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
282 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
283 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
283 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
284 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
284 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
285 }
285 }
286
286
287
287
288 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2)
288 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2)
289 {
289 {
290 return !(domain1 == domain2);
290 return !(domain1 == domain2);
291 }
291 }
292
292
293
293
294 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
294 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
295 {
295 {
296 dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ;
296 dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ;
297 return dbg.maybeSpace();
297 return dbg.maybeSpace();
298 }
298 }
299
299
300 #include "moc_domain_p.cpp"
300 #include "moc_domain_p.cpp"
301
301
302 QTCOMMERCIALCHART_END_NAMESPACE
302 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,93 +1,93
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 #ifndef DOMAIN_H
21 #ifndef DOMAIN_H
22 #define DOMAIN_H
22 #define DOMAIN_H
23 #include "qchartglobal.h"
23 #include "qchartglobal.h"
24 #include <QRectF>
24 #include <QRectF>
25 #include <QSizeF>
25 #include <QSizeF>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class QTCOMMERCIALCHART_AUTOTEST_EXPORT Domain: public QObject {
30 class QTCOMMERCIALCHART_AUTOTEST_EXPORT Domain: public QObject {
31 Q_OBJECT
31 Q_OBJECT
32 public:
32 public:
33 explicit Domain(QObject* object=0);
33 explicit Domain(QObject* object=0);
34 virtual ~Domain();
34 virtual ~Domain();
35
35
36 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
36 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
37 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount);
37 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount);
38 void setRangeX(qreal min, qreal max);
38 void setRangeX(qreal min, qreal max);
39 void setRangeX(qreal min, qreal max, int tickCount);
39 void setRangeX(qreal min, qreal max, int tickCount);
40 void setRangeY(qreal min, qreal max);
40 void setRangeY(qreal min, qreal max);
41 void setRangeY(qreal min, qreal max, int tickCount);
41 void setRangeY(qreal min, qreal max, int tickCount);
42 void setMinX(qreal min);
42 void setMinX(qreal min);
43 void setMaxX(qreal max);
43 void setMaxX(qreal max);
44 void setMinY(qreal min);
44 void setMinY(qreal min);
45 void setMaxY(qreal max);
45 void setMaxY(qreal max);
46
46
47 qreal minX() const { return m_minX; }
47 qreal minX() const { return m_minX; }
48 qreal maxX() const { return m_maxX; }
48 qreal maxX() const { return m_maxX; }
49 qreal minY() const { return m_minY; }
49 qreal minY() const { return m_minY; }
50 qreal maxY() const { return m_maxY; }
50 qreal maxY() const { return m_maxY; }
51
51
52 qreal spanX() const;
52 qreal spanX() const;
53 qreal spanY() const;
53 qreal spanY() const;
54 bool isEmpty() const;
54 bool isEmpty() const;
55
55
56 int tickXCount() const {return m_tickXCount;}
56 int tickXCount() const {return m_tickXCount;}
57 int tickYCount() const {return m_tickYCount;}
57 int tickYCount() const {return m_tickYCount;}
58
58
59 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2);
59 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2);
60 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2);
60 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2);
61 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain);
61 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain);
62
62
63 void zoomIn(const QRectF& rect, const QSizeF& size);
63 void zoomIn(const QRectF& rect, const QSizeF& size);
64 void zoomOut(const QRectF& rect, const QSizeF& size);
64 void zoomOut(const QRectF& rect, const QSizeF& size);
65 void move(int dx,int dy,const QSizeF& size);
65 void move(qreal dx,qreal dy,const QSizeF& size);
66
66
67 Q_SIGNALS:
67 Q_SIGNALS:
68 void domainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
68 void domainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
69 void rangeXChanged(qreal min, qreal max, int tickXCount);
69 void rangeXChanged(qreal min, qreal max, int tickXCount);
70 void rangeYChanged(qreal min, qreal max, int tickYCount);
70 void rangeYChanged(qreal min, qreal max, int tickYCount);
71
71
72 public Q_SLOTS:
72 public Q_SLOTS:
73 void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5,bool niceNumbers = false);
73 void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5,bool niceNumbers = false);
74 void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5,bool niceNumbers = false);
74 void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5,bool niceNumbers = false);
75
75
76 private:
76 private:
77 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
77 void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const;
78 qreal niceNumber(qreal x,bool celing) const;
78 qreal niceNumber(qreal x,bool celing) const;
79
79
80 private:
80 private:
81 qreal m_minX;
81 qreal m_minX;
82 qreal m_maxX;
82 qreal m_maxX;
83 qreal m_minY;
83 qreal m_minY;
84 qreal m_maxY;
84 qreal m_maxY;
85 int m_tickXCount;
85 int m_tickXCount;
86 int m_tickYCount;
86 int m_tickYCount;
87 bool m_niceXNumbers;
87 bool m_niceXNumbers;
88 bool m_niceYNumbers;
88 bool m_niceYNumbers;
89 };
89 };
90
90
91 QTCOMMERCIALCHART_END_NAMESPACE
91 QTCOMMERCIALCHART_END_NAMESPACE
92
92
93 #endif
93 #endif
General Comments 0
You need to be logged in to leave comments. Login now