##// END OF EJS Templates
Refactors linechart update calls
Michal Klocek -
r464:407de0c5cf5b
parent child
Show More
@@ -1,66 +1,66
1 1 #ifndef AREACHARTITEM_H
2 2 #define AREACHARTITEM_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "linechartitem_p.h"
6 6 #include <QPen>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class ChartPresenter;
11 11 class QAreaSeries;
12 12 class AreaChartItem;
13 13
14 14 class AreaChartItem : public QObject ,public ChartItem
15 15 {
16 16 Q_OBJECT
17 17 public:
18 18 AreaChartItem(QAreaSeries* areaSeries, QGraphicsItem *parent = 0);
19 19 ~ AreaChartItem();
20 20
21 21 //from QGraphicsItem
22 22 QRectF boundingRect() const;
23 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24 24 QPainterPath shape() const;
25 25
26 26 void setPen(const QPen& pen);
27 27 void setBrush(const QBrush& brush);
28 28 void setPointsVisible(bool visible);
29 29 void updatePath();
30 30 public slots:
31 31 void handleUpdated();
32 32 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
33 33 void handleGeometryChanged(const QRectF& size);
34 34
35 35 private:
36 36 QAreaSeries* m_series;
37 37 LineChartItem* m_upper;
38 38 LineChartItem* m_lower;
39 39 QPainterPath m_path;
40 40 QRectF m_rect;
41 41 QRectF m_clipRect;
42 42 QPen m_pen;
43 43 QBrush m_brush;
44 44 };
45 45
46 46 class AreaBoundItem : public LineChartItem
47 47 {
48 48 public:
49 49 AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries):LineChartItem(lineSeries),
50 50 m_item(item){};
51 51
52 52 ~AreaBoundItem(){};
53 53
54 void applyGeometry(QVector<QPointF>& points){
55 LineChartItem::applyGeometry(points);
54 void setGeometry(QVector<QPointF>& points){
55 LineChartItem::setGeometry(points);
56 56 m_item->updatePath();
57 57 }
58 58
59 59 private:
60 60 AreaChartItem* m_item;
61 61
62 62 };
63 63
64 64 QTCOMMERCIALCHART_END_NAMESPACE
65 65
66 66 #endif
@@ -1,103 +1,113
1 1 #include "linechartanimationitem_p.h"
2 2 #include "linechartitem_p.h"
3 3 #include <QPropertyAnimation>
4 4 #include <QTimer>
5 5
6 6 Q_DECLARE_METATYPE(QVector<QPointF>)
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 const static int duration = 500;
11 11
12 12 LineChartAnimationItem::LineChartAnimationItem(QLineSeries* series,QGraphicsItem *parent):
13 13 LineChartItem(series,parent),
14 14 m_animation(new LineChartAnimatator(this,this)),
15 15 m_dirty(false)
16 16 {
17 17 }
18 18
19 19 LineChartAnimationItem::~LineChartAnimationItem()
20 20 {
21 21 }
22 22
23 void LineChartAnimationItem::updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints)
23 void LineChartAnimationItem::updateAllPoints()
24 24 {
25 QVector<QPointF> oldPoints = points();
26 LineChartItem::updateAllPoints();
27 QVector<QPointF> newPoints = points();
28
25 29 if(newPoints.count()==0) return;
26 30 oldPoints.resize(newPoints.size());
27 31
28 32 if(m_animation->state()!=QAbstractAnimation::Stopped){
29 33 m_animation->stop();
30 34 }
31 35
32 36 m_animation->setDuration(duration);
33 37 m_animation->setEasingCurve(QEasingCurve::InOutBack);
34 38 m_animation->setKeyValueAt(0.0, qVariantFromValue(oldPoints));
35 39 m_animation->setKeyValueAt(1.0, qVariantFromValue(newPoints));
36 40 QTimer::singleShot(0,m_animation,SLOT(start()));
37 41
38 oldPoints = newPoints;
42
39 43 m_points = newPoints;
40 44 m_dirty=false;
45
41 46 }
42 47
43 void LineChartAnimationItem::updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint)
48 void LineChartAnimationItem::updatePoint(int index,QPointF& newPoint)
44 49 {
50
45 51 if(m_animation->state()!=QAbstractAnimation::Stopped){
46 52 m_animation->stop();
47 53 m_dirty=true;
48 54 }
49 55
50 56 if(m_dirty){
51 m_points=oldPoints;
57 m_points=points();
52 58 m_dirty=false;
53 59 }
54 60
55 oldPoints.replace(index,newPoint);
61 LineChartItem::updatePoint(index,newPoint);
56 62
57 63 m_animation->setDuration(duration);
58 64 m_animation->setEasingCurve(QEasingCurve::InOutBack);
59 65 m_animation->setKeyValueAt(0.0, qVariantFromValue(m_points));
60 m_animation->setKeyValueAt(1.0, qVariantFromValue(oldPoints));
66 m_animation->setKeyValueAt(1.0, qVariantFromValue( points()));
67
61 68 QTimer::singleShot(0,this,SLOT(startAnimation()));
62 69
70
63 71 }
64 72
65 73 void LineChartAnimationItem::startAnimation()
66 74 {
67 75 m_dirty=true;
68 76 m_animation->start();
69 77 }
70 78
71 79 LineChartAnimatator::LineChartAnimatator(LineChartAnimationItem *item , QObject *parent):QVariantAnimation(parent),
72 80 m_item(item)
73 81 {
74 82 }
75 83
76 84 LineChartAnimatator::~LineChartAnimatator()
77 85 {
78 86 }
79 87
80 88 QVariant LineChartAnimatator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const
81 89 {
82 90 QVector<QPointF> startVector = qVariantValue<QVector<QPointF> >(start);
83 91 QVector<QPointF> endVecotr = qVariantValue<QVector<QPointF> >(end);
84 92 QVector<QPointF> result;
85 93 Q_ASSERT(startVector.count() == endVecotr.count());
86 94
87 95 for(int i =0 ;i< startVector.count();i++){
88 96 qreal x = startVector[i].x() + ((endVecotr[i].x()- startVector[i].x()) * progress);//qBound(0.0, progress, 1.0));
89 97 qreal y = startVector[i].y() + ((endVecotr[i].y()- startVector[i].y()) * progress);//qBound(0.0, progress, 1.0));
90 98 result << QPointF(x,y);
91 99 }
92 100 return qVariantFromValue(result);
93 101 }
94 102
95 103 void LineChartAnimatator::updateCurrentValue (const QVariant & value )
96 104 {
97 105 QVector<QPointF> vector = qVariantValue<QVector<QPointF> >(value);
98 m_item->applyGeometry(vector);
106 if(state()!=QAbstractAnimation::Stopped){ //workaround
107 m_item->setGeometry(vector);
108 }
99 109 }
100 110
101 111 #include "moc_linechartanimationitem_p.cpp"
102 112
103 113 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,50 +1,50
1 1 #ifndef LINECHARTANIMATIONITEM_P_H_
2 2 #define LINECHARTANIMATIONITEM_P_H_
3 3
4 4 #include "qchartglobal.h"
5 5 #include "linechartitem_p.h"
6 6 #include "domain_p.h"
7 7 #include <QVariantAnimation>
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class LineChartAnimatator;
12 12
13 13 class LineChartAnimationItem : public LineChartItem {
14 14
15 15 Q_OBJECT
16 16
17 17 public:
18 18 LineChartAnimationItem(QLineSeries *series, QGraphicsItem *parent = 0);
19 19 virtual ~LineChartAnimationItem();
20 20
21 21 protected:
22 virtual void updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints);
23 virtual void updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint);
22 virtual void updateAllPoints();
23 virtual void updatePoint(int index,QPointF& newPoint);
24 24
25 25 private slots:
26 26 void startAnimation();
27 27
28 28 private:
29 29 LineChartAnimatator *m_animation;
30 30 QVector<QPointF> m_points;
31 31 bool m_dirty;
32 32 };
33 33
34 34 class LineChartAnimatator: public QVariantAnimation
35 35 {
36 36 public:
37 37 LineChartAnimatator(LineChartAnimationItem *item, QObject *parent = 0 );
38 38 ~LineChartAnimatator();
39 39
40 40 protected:
41 41 QVariant interpolated(const QVariant &start, const QVariant & end, qreal progress ) const;
42 42 void updateCurrentValue (const QVariant & value );
43 43
44 44 private:
45 45 LineChartAnimationItem* m_item;
46 46 };
47 47
48 48 QTCOMMERCIALCHART_END_NAMESPACE
49 49
50 50 #endif
@@ -1,239 +1,245
1 1 #include "linechartitem_p.h"
2 2 #include "qlineseries.h"
3 3 #include "chartpresenter_p.h"
4 4 #include <QPainter>
5 5
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 //TODO: optimize : remove points which are not visible
10 10
11 11 LineChartItem::LineChartItem(QLineSeries* series,QGraphicsItem *parent):ChartItem(parent),
12 12 m_minX(0),
13 13 m_maxX(0),
14 14 m_minY(0),
15 15 m_maxY(0),
16 16 m_series(series),
17 17 m_items(this)
18 18 {
19 19 //m_items.setZValue(ChartPresenter::LineChartZValue);
20 20 setZValue(ChartPresenter::LineChartZValue);
21 21
22 22 QObject::connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
23 23 QObject::connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
24 24 QObject::connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
25 25 QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated()));
26 26
27 27 handleUpdated();
28 28 }
29 29
30 30 QRectF LineChartItem::boundingRect() const
31 31 {
32 32 return m_rect;
33 33 }
34 34
35 35 QPainterPath LineChartItem::shape() const
36 36 {
37 37 return m_path;
38 38 }
39 39
40 40 void LineChartItem::createPoints(int count)
41 41 {
42 42 for (int i = 0; i < count; ++i) {
43 43 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3);
44 44 m_items.addToGroup(item);
45 45 }
46 46 }
47 47
48 48 void LineChartItem::clearPoints(int count)
49 49 {
50 50 QList<QGraphicsItem *> items = m_items.childItems();
51 51
52 52 for (int i = 0; i < count; ++i) {
53 53 delete(items.takeLast());
54 54 }
55 55 }
56 56
57 57 QPointF LineChartItem::calculateGeometryPoint(int index) const
58 58 {
59 59 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
60 60 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
61 61 qreal x = (m_series->x(index) - m_minX)* deltaX;
62 62 qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height();
63 63 return QPointF(x,y);
64 64 }
65 65
66 66 QVector<QPointF> LineChartItem::calculateGeometryPoints() const
67 67 {
68 68 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
69 69 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
70 70
71 71 QVector<QPointF> points;
72 72 points.reserve(m_series->count());
73 73 for (int i = 0; i < m_series->count(); ++i) {
74 74 qreal x = (m_series->x(i) - m_minX)* deltaX;
75 75 qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height();
76 76 points << QPointF(x,y);
77 77 }
78 78 return points;
79 79 }
80 80
81 void LineChartItem::updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints)
81 void LineChartItem::updateAllPoints()
82 82 {
83 applyGeometry(newPoints);
84 oldPoints = newPoints;
83 QVector<QPointF> points = calculateGeometryPoints();
84
85 int diff = m_points.size() - points.size();
86
87 if(diff>0) {
88 clearPoints(diff);
89 }
90 else if(diff<0) {
91 createPoints(-diff);
92 }
93
94 setGeometry(points);
85 95 }
86 96
87 void LineChartItem::updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint)
97 void LineChartItem::updatePoints(QVector<QPointF>& points)
88 98 {
89 oldPoints.replace(index,newPoint);
90 applyGeometry(oldPoints);
99 int diff = m_points.size() - points.size();
100
101 if(diff>0) {
102 clearPoints(diff);
103 }
104 else if(diff<0) {
105 createPoints(-diff);
106 }
107
108 setGeometry(points);
109 }
110
111 void LineChartItem::updatePoint(int index,QPointF& newPoint)
112 {
113 m_points.replace(index,newPoint);
114 setGeometry(m_points);
91 115 }
92 116
93 void LineChartItem::applyGeometry(QVector<QPointF>& points)
117 void LineChartItem::setGeometry(QVector<QPointF>& points)
94 118 {
95 119 if(points.size()==0) return;
96 120
97 121 QList<QGraphicsItem*> items = m_items.childItems();
98 122
99 123 QPainterPath path;
100 124 const QPointF& point = points.at(0);
101 125 path.moveTo(point);
102 126 QGraphicsItem* item = items.at(0);
103 127 item->setPos(point.x()-1,point.y()-1);
104 128 if(!m_clipRect.contains(point)) {
105 129 item->setVisible(false);
106 130 }else{
107 131 item->setVisible(true);
108 132 }
109 133
110 134 for(int i=1 ; i< points.size();i++) {
111 135 QGraphicsItem* item = items.at(i);
112 136 const QPointF& point = points.at(i);
113 137 item->setPos(point.x()-1,point.y()-1);
114 138 if(!m_clipRect.contains(point)) {
115 139 item->setVisible(false);
116 140 }else{
117 141 item->setVisible(true);
118 142 }
119 143 path.lineTo(point);
120 144 }
121 145
122 146 prepareGeometryChange();
123 147 m_path = path;
124 148 m_rect = path.boundingRect();
149 m_points = points;
125 150 }
126 151
127 152 void LineChartItem::setPen(const QPen& pen)
128 153 {
129 154 m_pen = pen;
130 155 }
131 156
132 157 //handlers
133 158
134 159 void LineChartItem::handlePointAdded(int index)
135 160 {
136 161 Q_ASSERT(index<m_series->count());
137 162 Q_ASSERT(index>=0);
138 163
139 164 QPointF point = calculateGeometryPoint(index);
140 165 createPoints(1);
141 166 QVector<QPointF> points = m_points;
142 167 points.insert(index,point);
143 updateItem(m_points,points);
168
169 updatePoints(points);
144 170 update();
145 171 }
146 172 void LineChartItem::handlePointRemoved(int index)
147 173 {
148 174 Q_ASSERT(index<m_series->count());
149 175 Q_ASSERT(index>=0);
176
150 177 QPointF point = calculateGeometryPoint(index);
151 178 clearPoints(1);
152 179 QVector<QPointF> points = m_points;
153 180 points.remove(index);
154 updateItem(m_points,points);
181 updatePoints(points);
155 182 update();
156 183 }
157 184
158 185 void LineChartItem::handlePointReplaced(int index)
159 186 {
160 187 Q_ASSERT(index<m_series->count());
161 188 Q_ASSERT(index>=0);
162 189 QPointF point = calculateGeometryPoint(index);
163 updateItem(m_points,index,point);
190 updatePoint(index,point);
164 191 update();
165 192 }
166 193
167 194 void LineChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
168 195 {
169 196 m_minX=minX;
170 197 m_maxX=maxX;
171 198 m_minY=minY;
172 199 m_maxY=maxY;
173 200
174 if( (m_maxX - m_minX) == 0|| (m_maxY - m_minY) == 0) return;
175 if(!m_clipRect.isValid()) return;
176
177 QVector<QPointF> points = calculateGeometryPoints();
178
179 int diff = m_points.size() - points.size();
180
181 if(diff>0) {
182 clearPoints(diff);
183 }
184 else if(diff<0) {
185 createPoints(-diff);
186 }
187
188 updateItem(m_points,points);
201 if(isEmpty()) return;
202 updateAllPoints();
189 203 update();
190 204 }
191 205
192 206 void LineChartItem::handleGeometryChanged(const QRectF& rect)
193 207 {
194 208 Q_ASSERT(rect.isValid());
195 209 m_size=rect.size();
196 210 m_clipRect=rect.translated(-rect.topLeft());
197 211 setPos(rect.topLeft());
198 212
199 if( (m_maxX - m_minX) == 0|| (m_maxY - m_minY) == 0) return;
200
201 QVector<QPointF> points = calculateGeometryPoints();
202
203 int diff = m_points.size() - points.size();
204
205 if(diff>0) {
206 clearPoints(diff);
207 }
208 else if(diff<0) {
209 createPoints(-diff);
210 }
211
212 updateItem(m_points,points);
213 if(isEmpty()) return;
214 updateAllPoints();
213 215 update();
214 216 }
215 217
216 218 void LineChartItem::handleUpdated()
217 219 {
218 220 m_items.setVisible(m_series->pointsVisible());
219 221 setPen(m_series->pen());
220 222 update();
221 223 }
222 224
223 225 //painter
224 226
225 227 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
226 228 {
227 229 Q_UNUSED(widget);
228 230 Q_UNUSED(option);
229 231 painter->save();
230 232 painter->setPen(m_pen);
231 233 painter->setClipRect(m_clipRect);
232 234 painter->drawPath(m_path);
233 235 painter->restore();
234 236 }
235 237
238 bool LineChartItem::isEmpty()
239 {
240 return !m_clipRect.isValid() || m_maxX - m_minX == 0 || m_maxY - m_minY ==0 ;
241 }
236 242
237 243 #include "moc_linechartitem_p.cpp"
238 244
239 245 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,63 +1,69
1 1 #ifndef LINECHARTITEM_H
2 2 #define LINECHARTITEM_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include "chartitem_p.h"
6 6 #include <QPen>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class ChartPresenter;
11 11 class QLineSeries;
12 12
13 13 class LineChartItem : public QObject , public ChartItem
14 14 {
15 15 Q_OBJECT
16 16 public:
17 17 LineChartItem(QLineSeries* series,QGraphicsItem *parent = 0);
18 18 ~ LineChartItem(){};
19 19
20 20 //from QGraphicsItem
21 21 QRectF boundingRect() const;
22 22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 23 QPainterPath shape() const;
24 24
25 25 void setPen(const QPen& pen);
26 26 void setPointsVisible(bool visible);
27 27
28 28 public slots:
29 29 void handlePointAdded(int index);
30 30 void handlePointRemoved(int index);
31 31 void handlePointReplaced(int index);
32 32 void handleUpdated();
33 33 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
34 34 void handleGeometryChanged(const QRectF& size);
35 35
36 public:
37 virtual void updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints);
38 virtual void updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint);
39 virtual void applyGeometry(QVector<QPointF>& points);
36 protected:
37 virtual void updateAllPoints();
38 virtual void updatePoints(QVector<QPointF>& points);
39 virtual void updatePoint(int index,QPointF& newPoint);
40 virtual void setGeometry(QVector<QPointF>& points);
41
42 QVector<QPointF> points() {return m_points;}
40 43 void createPoints(int count);
41 44 void clearPoints(int count);
42 45 QPointF calculateGeometryPoint(int index) const;
43 46 QVector<QPointF> calculateGeometryPoints() const;
47 inline bool isEmpty();
44 48
45 49 protected:
46 50 qreal m_minX;
47 51 qreal m_maxX;
48 52 qreal m_minY;
49 53 qreal m_maxY;
50 54 QPainterPath m_path;
51 55 QRectF m_rect;
52 56 QLineSeries* m_series;
53 57 QSizeF m_size;
54 58 QRectF m_clipRect;
55 59 QGraphicsItemGroup m_items;
56 60 QVector<QPointF> m_points;
57 61 QPen m_pen;
58 62
63 friend class LineChartAnimatator;
64
59 65 };
60 66
61 67 QTCOMMERCIALCHART_END_NAMESPACE
62 68
63 69 #endif
@@ -1,75 +1,75
1 1 #include "splinechartitem_p.h"
2 2 #include <QPainter>
3 3
4 4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 5
6 6 SplineChartItem::SplineChartItem(QSplineSeries* series, QGraphicsObject *parent) :
7 7 LineChartItem(series, parent)//,m_boundingRect()
8 8 {
9 9 //
10 10 }
11 11
12 12
13 13
14 14 QPointF SplineChartItem::calculateGeometryControlPoint(int index) const
15 15 {
16 16 QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series);
17 17 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
18 18 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
19 19 qreal x = (splineSeries->controlPoint(index).x() - m_minX)* deltaX;
20 20 qreal y = (splineSeries->controlPoint(index).y() - m_minY)*-deltaY + m_size.height();
21 21 return QPointF(x,y);
22 22 }
23 23
24 void SplineChartItem::applyGeometry(QVector<QPointF>& points)
24 void SplineChartItem::setGeometry(QVector<QPointF>& points)
25 25 {
26 26 if(points.size()==0) return;
27 27
28 28 QPainterPath splinePath;
29 29 const QPointF& point = points.at(0);
30 30 splinePath.moveTo(point);
31 31
32 32 // QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series);
33 33 for (int i = 0; i < points.size() - 1; i++)
34 34 {
35 35 const QPointF& point = points.at(i + 1);
36 36 splinePath.cubicTo(calculateGeometryControlPoint(2 * i), calculateGeometryControlPoint(2 * i + 1), point);
37 37 }
38 38
39 39 prepareGeometryChange();
40 40 m_path = splinePath;
41 41 m_rect = splinePath.boundingRect();
42 42 }
43 43
44 44 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
45 45 {
46 46 Q_UNUSED(widget);
47 47 Q_UNUSED(option);
48 48 painter->save();
49 49 painter->setPen(m_pen);
50 50 painter->setClipRect(m_clipRect);
51 51 painter->drawPath(m_path);
52 52
53 53 QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series);
54 54 for (int i = 0; i < m_points.size() - 1; i++)
55 55 {
56 56 painter->setPen(Qt::red);
57 57 painter->drawEllipse(m_points[i], 2, 2);
58 58
59 59 painter->setPen(Qt::blue);
60 60 // painter->drawLine(m_series->at(i), m_series->controlPoint(2 * i));
61 61 // painter->drawLine(m_series->at(i + 1), m_series->controlPoint(2 * i + 1));
62 62 // painter->drawEllipse(calculateGeometryControlPoint(2 * i), 4, 4);
63 63 // painter->drawEllipse(calculateGeometryControlPoint(2 * i + 1), 4, 4);
64 64 }
65 65 if (m_points.count() > 0)
66 66 {
67 67 painter->setPen(Qt::red);
68 68 painter->drawEllipse(m_points[m_points.count() - 1], 2, 2);
69 69 }
70 70 painter->restore();
71 71 }
72 72
73 73 #include "moc_splinechartitem_p.cpp"
74 74
75 75 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,28 +1,28
1 1 #ifndef SPLINECHARTITEM_P_H
2 2 #define SPLINECHARTITEM_P_H
3 3
4 4 #include "chartitem_p.h"
5 5 #include <QObject>
6 6 #include "qsplineseries.h"
7 7 #include "linechartitem_p.h"
8 8
9 9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 10
11 11 class SplineChartItem : public LineChartItem
12 12 {
13 13 Q_OBJECT
14 14 public:
15 15 SplineChartItem(QSplineSeries* series, QGraphicsObject *parent = 0);
16 16
17 17 void updateGeometry();
18 18
19 void applyGeometry(QVector<QPointF>& points);
19 void setGeometry(QVector<QPointF>& points);
20 20
21 21 QPointF calculateGeometryControlPoint(int index) const;
22 22
23 23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24 24 };
25 25
26 26 QTCOMMERCIALCHART_END_NAMESPACE
27 27
28 28 #endif // SPLINECHARTITEM_P_H
General Comments 0
You need to be logged in to leave comments. Login now