##// END OF EJS Templates
minor. removes debug leftover
Michal Klocek -
r1242:8f2f7e1849ba
parent child
Show More
@@ -1,251 +1,250
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 "xychart_p.h"
21 #include "xychart_p.h"
22 #include "qxyseries.h"
22 #include "qxyseries.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "chartanimator_p.h"
25 #include "chartanimator_p.h"
26 #include <QPainter>
26 #include <QPainter>
27 #include <QAbstractItemModel>
27 #include <QAbstractItemModel>
28 #include "qxymodelmapper.h"
28 #include "qxymodelmapper.h"
29 #include <QDebug>
29 #include <QDebug>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 //TODO: optimize : remove points which are not visible
33 //TODO: optimize : remove points which are not visible
34
34
35 XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter):Chart(presenter),
35 XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter):Chart(presenter),
36 m_minX(0),
36 m_minX(0),
37 m_maxX(0),
37 m_maxX(0),
38 m_minY(0),
38 m_minY(0),
39 m_maxY(0),
39 m_maxY(0),
40 m_series(series),
40 m_series(series),
41 m_animation(0),
41 m_animation(0),
42 m_dirty(true)
42 m_dirty(true)
43 {
43 {
44 QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
44 QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
45 QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
45 QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
46 QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
46 QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
47 QObject::connect(series->d_func(),SIGNAL(reinitialized()),this,SLOT(handleReinitialized()));
47 QObject::connect(series->d_func(),SIGNAL(reinitialized()),this,SLOT(handleReinitialized()));
48 QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF)));
48 QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF)));
49 }
49 }
50
50
51 void XYChart::setGeometryPoints(const QVector<QPointF>& points)
51 void XYChart::setGeometryPoints(const QVector<QPointF>& points)
52 {
52 {
53 m_points = points;
53 m_points = points;
54 }
54 }
55
55
56 void XYChart::setClipRect(const QRectF &rect)
56 void XYChart::setClipRect(const QRectF &rect)
57 {
57 {
58 m_clipRect = rect;
58 m_clipRect = rect;
59 }
59 }
60
60
61 void XYChart::setAnimation(XYAnimation* animation)
61 void XYChart::setAnimation(XYAnimation* animation)
62 {
62 {
63 m_animation=animation;
63 m_animation=animation;
64 }
64 }
65
65
66 void XYChart::setDirty(bool dirty)
66 void XYChart::setDirty(bool dirty)
67 {
67 {
68 m_dirty=dirty;
68 m_dirty=dirty;
69 }
69 }
70
70
71 QPointF XYChart::calculateGeometryPoint(const QPointF &point) const
71 QPointF XYChart::calculateGeometryPoint(const QPointF &point) const
72 {
72 {
73 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
73 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
74 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
74 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
75 qreal x = (point.x() - m_minX)* deltaX;
75 qreal x = (point.x() - m_minX)* deltaX;
76 qreal y = (point.y() - m_minY)*-deltaY + m_size.height();
76 qreal y = (point.y() - m_minY)*-deltaY + m_size.height();
77 return QPointF(x,y);
77 return QPointF(x,y);
78 }
78 }
79
79
80 QPointF XYChart::calculateGeometryPoint(int index) const
80 QPointF XYChart::calculateGeometryPoint(int index) const
81 {
81 {
82 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
82 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
83 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
83 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
84 const QList<QPointF>& vector = m_series->points();
84 const QList<QPointF>& vector = m_series->points();
85 qreal x = (vector[index].x() - m_minX)* deltaX;
85 qreal x = (vector[index].x() - m_minX)* deltaX;
86 qreal y = (vector[index].y() - m_minY)*-deltaY + m_size.height();
86 qreal y = (vector[index].y() - m_minY)*-deltaY + m_size.height();
87 return QPointF(x,y);
87 return QPointF(x,y);
88 }
88 }
89
89
90 QVector<QPointF> XYChart::calculateGeometryPoints() const
90 QVector<QPointF> XYChart::calculateGeometryPoints() const
91 {
91 {
92 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
92 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
93 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
93 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
94
94
95 QVector<QPointF> result;
95 QVector<QPointF> result;
96 result.resize(m_series->count());
96 result.resize(m_series->count());
97 const QList<QPointF>& vector = m_series->points();
97 const QList<QPointF>& vector = m_series->points();
98 for (int i = 0; i < m_series->count(); ++i) {
98 for (int i = 0; i < m_series->count(); ++i) {
99 qreal x = (vector[i].x() - m_minX)* deltaX;
99 qreal x = (vector[i].x() - m_minX)* deltaX;
100 qreal y = (vector[i].y() - m_minY)*-deltaY + m_size.height();
100 qreal y = (vector[i].y() - m_minY)*-deltaY + m_size.height();
101 result[i].setX(x);
101 result[i].setX(x);
102 result[i].setY(y);
102 result[i].setY(y);
103 }
103 }
104 return result;
104 return result;
105 }
105 }
106
106
107 QPointF XYChart::calculateDomainPoint(const QPointF &point) const
107 QPointF XYChart::calculateDomainPoint(const QPointF &point) const
108 {
108 {
109 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
109 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
110 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
110 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
111 qreal x = point.x()/deltaX +m_minX;
111 qreal x = point.x()/deltaX +m_minX;
112 qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY;
112 qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY;
113 return QPointF(x,y);
113 return QPointF(x,y);
114 }
114 }
115
115
116 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
116 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
117 {
117 {
118 if (m_animation) {
118 if (m_animation) {
119 m_animation->setValues(oldPoints, newPoints, index);
119 m_animation->setValues(oldPoints, newPoints, index);
120 setGeometryPoints(newPoints);
120 setGeometryPoints(newPoints);
121 setDirty(false);
121 setDirty(false);
122 presenter()->startAnimation(m_animation);
122 presenter()->startAnimation(m_animation);
123 }
123 }
124 else {
124 else {
125 setGeometryPoints(newPoints);
125 setGeometryPoints(newPoints);
126 updateGeometry();
126 updateGeometry();
127 }
127 }
128 }
128 }
129
129
130 //handlers
130 //handlers
131
131
132 void XYChart::handlePointAdded(int index)
132 void XYChart::handlePointAdded(int index)
133 {
133 {
134 Q_ASSERT(index<m_series->count());
134 Q_ASSERT(index<m_series->count());
135 Q_ASSERT(index>=0);
135 Q_ASSERT(index>=0);
136
136
137 QVector<QPointF> points;
137 QVector<QPointF> points;
138
138
139 if(m_animation) {
139 if(m_animation) {
140 m_animation->setAnimationType(XYAnimation::AddPointAnimation);
140 m_animation->setAnimationType(XYAnimation::AddPointAnimation);
141 }
141 }
142
142
143 if(m_dirty) {
143 if(m_dirty) {
144 points = calculateGeometryPoints();
144 points = calculateGeometryPoints();
145 } else {
145 } else {
146 points = m_points;
146 points = m_points;
147 QPointF point = calculateGeometryPoint(index);
147 QPointF point = calculateGeometryPoint(index);
148 points.insert(index, point);
148 points.insert(index, point);
149 }
149 }
150
150
151 updateChart(m_points,points,index);
151 updateChart(m_points,points,index);
152 }
152 }
153
153
154 void XYChart::handlePointRemoved(int index)
154 void XYChart::handlePointRemoved(int index)
155 {
155 {
156 Q_ASSERT(index<=m_series->count());
156 Q_ASSERT(index<=m_series->count());
157 Q_ASSERT(index>=0);
157 Q_ASSERT(index>=0);
158
158
159 QVector<QPointF> points;
159 QVector<QPointF> points;
160
160
161 if(m_animation) {
161 if(m_animation) {
162 m_animation->setAnimationType(XYAnimation::RemovePointAnimation);
162 m_animation->setAnimationType(XYAnimation::RemovePointAnimation);
163 }
163 }
164
164
165 if(m_dirty) {
165 if(m_dirty) {
166 points = calculateGeometryPoints();
166 points = calculateGeometryPoints();
167 } else {
167 } else {
168 points = m_points;
168 points = m_points;
169 points.remove(index);
169 points.remove(index);
170 }
170 }
171
171
172 updateChart(m_points,points,index);
172 updateChart(m_points,points,index);
173 }
173 }
174
174
175 void XYChart::handlePointReplaced(int index)
175 void XYChart::handlePointReplaced(int index)
176 {
176 {
177 Q_ASSERT(index<m_series->count());
177 Q_ASSERT(index<m_series->count());
178 Q_ASSERT(index>=0);
178 Q_ASSERT(index>=0);
179
179
180 QVector<QPointF> points;
180 QVector<QPointF> points;
181
181
182 if(m_animation) {
182 if(m_animation) {
183 m_animation->setAnimationType(XYAnimation::ReplacePointAnimation);
183 m_animation->setAnimationType(XYAnimation::ReplacePointAnimation);
184 }
184 }
185
185
186 if(m_dirty) {
186 if(m_dirty) {
187 points = calculateGeometryPoints();
187 points = calculateGeometryPoints();
188 } else {
188 } else {
189 QPointF point = calculateGeometryPoint(index);
189 QPointF point = calculateGeometryPoint(index);
190 points = m_points;
190 points = m_points;
191 points.replace(index,point);
191 points.replace(index,point);
192 }
192 }
193
193
194 updateChart(m_points,points,index);
194 updateChart(m_points,points,index);
195 }
195 }
196
196
197 void XYChart::handleReinitialized()
197 void XYChart::handleReinitialized()
198 {
198 {
199 QVector<QPointF> points = calculateGeometryPoints();
199 QVector<QPointF> points = calculateGeometryPoints();
200
200
201 if(m_animation) {
201 if(m_animation) {
202 m_animation->setAnimationType(XYAnimation::NewAnimation);
202 m_animation->setAnimationType(XYAnimation::NewAnimation);
203 }
203 }
204
204
205 updateChart(m_points,points);
205 updateChart(m_points,points);
206 }
206 }
207
207
208 void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
208 void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
209 {
209 {
210 qDebug()<<__FUNCTION__;
211 m_minX=minX;
210 m_minX=minX;
212 m_maxX=maxX;
211 m_maxX=maxX;
213 m_minY=minY;
212 m_minY=minY;
214 m_maxY=maxY;
213 m_maxY=maxY;
215 if (isEmpty()) return;
214 if (isEmpty()) return;
216
215
217 QVector<QPointF> points = calculateGeometryPoints();
216 QVector<QPointF> points = calculateGeometryPoints();
218
217
219 if(m_animation) {
218 if(m_animation) {
220 m_animation->setAnimationType(XYAnimation::ReplacePointAnimation);
219 m_animation->setAnimationType(XYAnimation::ReplacePointAnimation);
221 }
220 }
222
221
223 updateChart(m_points,points);
222 updateChart(m_points,points);
224 }
223 }
225
224
226 void XYChart::handleGeometryChanged(const QRectF &rect)
225 void XYChart::handleGeometryChanged(const QRectF &rect)
227 {
226 {
228 Q_ASSERT(rect.isValid());
227 Q_ASSERT(rect.isValid());
229 m_size=rect.size();
228 m_size=rect.size();
230 m_clipRect=rect.translated(-rect.topLeft());
229 m_clipRect=rect.translated(-rect.topLeft());
231 m_origin=rect.topLeft();
230 m_origin=rect.topLeft();
232
231
233 if (isEmpty()) return;
232 if (isEmpty()) return;
234
233
235 QVector<QPointF> points = calculateGeometryPoints();
234 QVector<QPointF> points = calculateGeometryPoints();
236
235
237 if(m_animation) {
236 if(m_animation) {
238 m_animation->setAnimationType(XYAnimation::NewAnimation);
237 m_animation->setAnimationType(XYAnimation::NewAnimation);
239 }
238 }
240
239
241 updateChart(m_points,points);
240 updateChart(m_points,points);
242 }
241 }
243
242
244 bool XYChart::isEmpty()
243 bool XYChart::isEmpty()
245 {
244 {
246 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty();
245 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty();
247 }
246 }
248
247
249 #include "moc_xychart_p.cpp"
248 #include "moc_xychart_p.cpp"
250
249
251 QTCOMMERCIALCHART_END_NAMESPACE
250 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now