@@ -29,7 +29,7 class AxisAnimator: public QVariantAnimation | |||
|
29 | 29 | { |
|
30 | 30 | public: |
|
31 | 31 | AxisAnimator(AxisItem *axis,QObject *parent = 0); |
|
32 |
|
|
|
32 | ~AxisAnimator(); | |
|
33 | 33 | protected: |
|
34 | 34 | virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; |
|
35 | 35 | virtual void updateCurrentValue (const QVariant & value ); |
@@ -58,9 +58,6 void AxisItem::clear(int count) | |||
|
58 | 58 | if(lines.size()%2) delete(shades.takeLast()); |
|
59 | 59 | delete(axis.takeLast()); |
|
60 | 60 | } |
|
61 | ||
|
62 | m_thicksList.clear(); | |
|
63 | ||
|
64 | 61 | } |
|
65 | 62 | |
|
66 | 63 | void AxisItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
@@ -35,7 +35,7 public: | |||
|
35 | 35 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
36 | 36 | virtual void layoutChanged() = 0; // layout has changed -> need to recalculate bar sizes |
|
37 | 37 | |
|
38 |
p |
|
|
38 | public slots: | |
|
39 | 39 | void handleModelChanged(int index); |
|
40 | 40 | void handleDomainChanged(const Domain& domain); |
|
41 | 41 | void handleGeometryChanged(const QRectF& size); |
@@ -150,12 +150,11 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||
|
150 | 150 | m_axisXInitialized=true; |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | ||
|
154 | emit seriesAdded(series); | |
|
155 | 153 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); |
|
156 | 154 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
157 | 155 | emit axisLabelsChanged(axisY,ylabels); |
|
158 | 156 | emit axisLabelsChanged(axisX(),xlabels); |
|
157 | emit seriesAdded(series); | |
|
159 | 158 | emit seriesDomainChanged(series,domain); |
|
160 | 159 | |
|
161 | 160 | } |
@@ -118,8 +118,11 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
118 | 118 | } |
|
119 | 119 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
120 | 120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
121 |
QObject::connect(lineSeries,SIGNAL(point |
|
|
121 | QObject::connect(lineSeries,SIGNAL(pointReplaced(int)),item,SLOT(handlePointReplaced(int))); | |
|
122 | QObject::connect(lineSeries,SIGNAL(pointAdded(int)),item,SLOT(handlePointAdded(int))); | |
|
123 | QObject::connect(lineSeries,SIGNAL(pointRemoved(int)),item,SLOT(handlePointRemoved(int))); | |
|
122 | 124 | m_chartItems.insert(series,item); |
|
125 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
|
123 | 126 | break; |
|
124 | 127 | } |
|
125 | 128 | |
@@ -131,6 +134,7 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
131 | 134 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
132 | 135 | m_chartItems.insert(series,item); |
|
133 | 136 | // m_axisXItem->setVisible(false); |
|
137 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
|
134 | 138 | break; |
|
135 | 139 | } |
|
136 | 140 | |
@@ -142,6 +146,7 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
142 | 146 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
143 | 147 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
144 | 148 | m_chartItems.insert(series,item); |
|
149 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
|
145 | 150 | break; |
|
146 | 151 | } |
|
147 | 152 | |
@@ -153,6 +158,7 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
153 | 158 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
154 | 159 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
155 | 160 | m_chartItems.insert(series,item); |
|
161 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
|
156 | 162 | break; |
|
157 | 163 | } |
|
158 | 164 | case QSeries::SeriesTypeScatter: { |
@@ -163,6 +169,7 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
163 | 169 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
164 | 170 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
165 | 171 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
172 | if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect); | |
|
166 | 173 | break; |
|
167 | 174 | } |
|
168 | 175 | case QSeries::SeriesTypePie: { |
@@ -186,6 +193,7 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
186 | 193 | } |
|
187 | 194 | |
|
188 | 195 | m_chartItems.insert(series, pie); |
|
196 | pie->handleGeometryChanged(m_rect); | |
|
189 | 197 | break; |
|
190 | 198 | } |
|
191 | 199 | default: { |
@@ -193,8 +201,6 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
193 | 201 | break; |
|
194 | 202 | } |
|
195 | 203 | } |
|
196 | ||
|
197 | if(m_rect.isValid()) emit geometryChanged(m_rect); | |
|
198 | 204 | } |
|
199 | 205 | |
|
200 | 206 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
@@ -203,11 +209,6 void ChartPresenter::handleSeriesRemoved(QSeries* series) | |||
|
203 | 209 | delete item; |
|
204 | 210 | } |
|
205 | 211 | |
|
206 | void ChartPresenter::handleSeriesChanged(QSeries* series) | |
|
207 | { | |
|
208 | //TODO: | |
|
209 | } | |
|
210 | ||
|
211 | 212 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) |
|
212 | 213 | { |
|
213 | 214 | m_chartItems.value(series)->handleDomainChanged(domain); |
@@ -53,7 +53,6 public slots: | |||
|
53 | 53 | void handleAxisRemoved(QChartAxis* axis); |
|
54 | 54 | void handleSeriesDomainChanged(QSeries* series, const Domain& domain); |
|
55 | 55 | void handleAxisLabelsChanged(QChartAxis* axis, const QStringList& labels); |
|
56 | void handleSeriesChanged(QSeries* series); | |
|
57 | 56 | void handleGeometryChanged(); |
|
58 | 57 | signals: |
|
59 | 58 | void geometryChanged(const QRectF& rect); |
@@ -19,8 +19,19 LineChartAnimationItem::~LineChartAnimationItem() | |||
|
19 | 19 | |
|
20 | 20 | void LineChartAnimationItem::addPoints(const QVector<QPointF>& points) |
|
21 | 21 | { |
|
22 | m_data=points; | |
|
23 | clearView(); | |
|
22 | QVector<qreal> vector0 = vector1; | |
|
23 | calculateLayout(vector1); | |
|
24 | if(vector1.count()==0) return; | |
|
25 | vector0.resize(vector1.size()); | |
|
26 | ||
|
27 | ||
|
28 | LineChartAnimatator *animation = new LineChartAnimatator(this,this); | |
|
29 | animation->setDuration(duration); | |
|
30 | animation->setEasingCurve(QEasingCurve::InOutBack); | |
|
31 | animation->setKeyValueAt(0.0, qVariantFromValue(vector0)); | |
|
32 | animation->setKeyValueAt(1.0, qVariantFromValue(vector1)); | |
|
33 | animation->start(QAbstractAnimation::DeleteWhenStopped); | |
|
34 | ||
|
24 | 35 | QPropertyAnimation *animation = new QPropertyAnimation(this, "a_addPoints", parent()); |
|
25 | 36 | animation->setDuration(duration); |
|
26 | 37 | //animation->setEasingCurve(QEasingCurve::InOutBack); |
@@ -29,7 +40,7 void LineChartAnimationItem::addPoints(const QVector<QPointF>& points) | |||
|
29 | 40 | animation->start(QAbstractAnimation::DeleteWhenStopped); |
|
30 | 41 | } |
|
31 | 42 | |
|
32 |
void LineChartAnimationItem:: |
|
|
43 | void LineChartAnimationItem::replacePoint(int index,const QPointF& point) | |
|
33 | 44 | { |
|
34 | 45 | AnimationHelper* helper = new AnimationHelper(this,index); |
|
35 | 46 | QPropertyAnimation *animation = new QPropertyAnimation(helper, "point", parent()); |
@@ -52,11 +63,42 void LineChartAnimationItem::aw_addPoints(int points) | |||
|
52 | 63 | |
|
53 | 64 | void LineChartAnimationItem::aw_setPoint(int index,const QPointF& point) |
|
54 | 65 | { |
|
55 |
LineChartItem:: |
|
|
66 | LineChartItem::replacePoint(index,point); | |
|
56 | 67 | updateGeometry(); |
|
57 | 68 | update(); |
|
58 | 69 | } |
|
59 | 70 | |
|
71 | LineChartAnimatator::LineChartAnimatator(LineChartItem *item, int index , QObject *parent = 0 ):QVariantAnimation(parent), | |
|
72 | m_item(item), | |
|
73 | m_index(index) | |
|
74 | { | |
|
75 | }; | |
|
76 | ||
|
77 | LineChartAnimatator::~LineChartAnimatator() | |
|
78 | { | |
|
79 | } | |
|
80 | ||
|
81 | QVariant LineChartAnimatator::interpolated(const QVariant &start, const QVariant & end, qreal progress ) const | |
|
82 | { | |
|
83 | QVector<qreal> startVector = qVariantValue<QVector<qreal> >(start); | |
|
84 | QVector<qreal> endVecotr = qVariantValue<QVector<qreal> >(end); | |
|
85 | QVector<qreal> result; | |
|
86 | Q_ASSERT(startVector.count() == endVecotr.count()); | |
|
87 | ||
|
88 | for(int i =0 ;i< startVector.count();i++){ | |
|
89 | qreal value = startVector[i] + ((endVecotr[i]- startVector[i]) * progress);//qBound(0.0, progress, 1.0)); | |
|
90 | result << value; | |
|
91 | } | |
|
92 | return qVariantFromValue(result); | |
|
93 | } | |
|
94 | ||
|
95 | ||
|
96 | void LineChartAnimatator::updateCurrentValue (const QVariant & value ) | |
|
97 | { | |
|
98 | QVector<qreal> vector = qVariantValue<QVector<qreal> >(value); | |
|
99 | m_axis->applyLayout(vector); | |
|
100 | } | |
|
101 | ||
|
60 | 102 | |
|
61 | 103 | #include "moc_linechartanimationitem_p.cpp" |
|
62 | 104 |
@@ -10,22 +10,13 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
10 | 10 | class LineChartItem; |
|
11 | 11 | |
|
12 | 12 | class LineChartAnimationItem : public LineChartItem { |
|
13 | Q_OBJECT | |
|
14 | Q_PROPERTY(int a_addPoints READ ar_addPoints WRITE aw_addPoints); | |
|
15 | // Q_PROPERTY(QPointF a_setPoint READ ar_setPoint WRITE aw_setPoint); | |
|
13 | ||
|
16 | 14 | public: |
|
17 | 15 | LineChartAnimationItem(ChartPresenter* presenter, QLineSeries *series, QGraphicsItem *parent = 0); |
|
18 | 16 | virtual ~LineChartAnimationItem(); |
|
19 | 17 | |
|
20 | 18 | void addPoints(const QVector<QPointF>& points); |
|
21 |
void |
|
|
22 | //void removePoint(const QPointF& point){}; | |
|
23 | //void setPoint(const QPointF& oldPoint, const QPointF& newPoint){}; | |
|
24 | ||
|
25 | int ar_addPoints() const { return m_addPoints;} | |
|
26 | void aw_addPoints(int points); | |
|
27 | const QPointF& ar_setPoint() const { return m_setPoint;} | |
|
28 | void aw_setPoint(int index,const QPointF& point); | |
|
19 | void replacePoint(int index,const QPointF& point); | |
|
29 | 20 | |
|
30 | 21 | private: |
|
31 | 22 | QVector<QPointF> m_data; |
@@ -35,16 +26,12 private: | |||
|
35 | 26 | int m_setPoint_index; |
|
36 | 27 | }; |
|
37 | 28 | |
|
38 | class AnimationHelper: public QObject | |
|
29 | class LineChartAnimatator: public QVariantAnimation | |
|
39 | 30 | { |
|
40 | Q_OBJECT | |
|
41 | Q_PROPERTY(QPointF point READ point WRITE setPoint); | |
|
31 | ||
|
42 | 32 | public: |
|
43 |
Animat |
|
|
44 | void setPoint(const QPointF& point){ | |
|
45 | m_item->aw_setPoint(m_index,point); | |
|
46 | } | |
|
47 | QPointF point(){return m_point;} | |
|
33 | LineChartAnimatator(LineChartItem *item, int index , QObject *parent = 0 ):m_item(item),m_index(index){}; | |
|
34 | ||
|
48 | 35 | QPointF m_point; |
|
49 | 36 | LineChartAnimationItem* m_item; |
|
50 | 37 | int m_index; |
@@ -10,10 +10,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
10 | 10 | |
|
11 | 11 | LineChartItem::LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):ChartItem(parent), |
|
12 | 12 | m_presenter(presenter), |
|
13 |
m_series(series) |
|
|
14 | m_dirtyData(false), | |
|
15 | m_dirtyGeometry(false), | |
|
16 | m_dirtyDomain(false) | |
|
13 | m_series(series) | |
|
17 | 14 | { |
|
18 | 15 | setZValue(ChartPresenter::LineChartZValue); |
|
19 | 16 | } |
@@ -28,76 +25,21 QPainterPath LineChartItem::shape() const | |||
|
28 | 25 | return m_path; |
|
29 | 26 | } |
|
30 | 27 | |
|
31 | ||
|
32 | void LineChartItem::addPoints(const QVector<QPointF>& points) | |
|
28 | void LineChartItem::createPoints(int count) | |
|
33 | 29 | { |
|
34 | m_data = points; | |
|
35 | for(int i=0; i<m_data.size();i++){ | |
|
36 | const QPointF& point =m_data[i]; | |
|
30 | for (int i = 0; i < count; ++i) { | |
|
37 | 31 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); |
|
38 | item->setPos(point.x()-1,point.y()-1);; | |
|
39 | if(!m_clipRect.contains(point) || !m_series->pointsVisible()) item->setVisible(false); | |
|
40 | m_points << item; | |
|
41 | } | |
|
42 | } | |
|
43 | ||
|
44 | void LineChartItem::addPoint(const QPointF& point) | |
|
45 | { | |
|
46 | m_data << point; | |
|
47 | QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this); | |
|
48 | m_clipRect.contains(point); | |
|
49 | item->setPos(point.x()-1,point.y()-1); | |
|
50 | if(!m_clipRect.contains(point) || !m_series->pointsVisible()) item->setVisible(false); | |
|
51 | m_points << item; | |
|
52 | } | |
|
53 | ||
|
54 | void LineChartItem::removePoint(const QPointF& point) | |
|
55 | { | |
|
56 | Q_ASSERT(m_data.count() == m_points.count()); | |
|
57 | int index = m_data.lastIndexOf(point,0); | |
|
58 | m_data.remove(index); | |
|
59 | delete(m_points.takeAt(index)); | |
|
60 | } | |
|
61 | ||
|
62 | void LineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint) | |
|
63 | { | |
|
64 | Q_ASSERT(m_data.count() == m_points.count()); | |
|
65 | int index = m_data.lastIndexOf(oldPoint,0); | |
|
66 | ||
|
67 | if(index > -1){ | |
|
68 | m_data.replace(index,newPoint); | |
|
69 | QGraphicsItem* item = m_points.at(index); | |
|
70 | item->setPos(newPoint.x()-1,newPoint.y()-1); | |
|
32 | m_items.addToGroup(item); | |
|
71 | 33 | } |
|
72 | 34 | } |
|
73 | 35 | |
|
74 |
void LineChartItem:: |
|
|
36 | void LineChartItem::clearPoints(int count) | |
|
75 | 37 | { |
|
76 | Q_ASSERT(m_data.count() == m_points.count()); | |
|
77 | Q_ASSERT(index>=0); | |
|
78 | ||
|
79 | m_data.replace(index,point); | |
|
80 | QGraphicsItem* item = m_points.at(index); | |
|
81 | item->setPos(point.x()-1,point.y()-1); | |
|
82 | } | |
|
38 | QList<QGraphicsItem *> items = m_items.childItems(); | |
|
83 | 39 | |
|
84 | void LineChartItem::clear() | |
|
85 | { | |
|
86 | qDeleteAll(m_points); | |
|
87 | m_points.clear(); | |
|
88 | m_hash.clear(); | |
|
89 | m_path = QPainterPath(); | |
|
90 | m_rect = QRect(); | |
|
91 | m_data.clear(); | |
|
40 | for (int i = 0; i < count; ++i) { | |
|
41 | delete(items.takeLast()); | |
|
92 | 42 | } |
|
93 | ||
|
94 | void LineChartItem::clearView() | |
|
95 | { | |
|
96 | qDeleteAll(m_points); | |
|
97 | m_points.clear(); | |
|
98 | m_path = QPainterPath(); | |
|
99 | m_rect = QRect(); | |
|
100 | m_data.clear(); | |
|
101 | 43 | } |
|
102 | 44 | |
|
103 | 45 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
@@ -111,58 +53,66 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt | |||
|
111 | 53 | painter->restore(); |
|
112 | 54 | } |
|
113 | 55 | |
|
114 | void LineChartItem::calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const | |
|
56 | QPointF LineChartItem::calculatePoint(int index) const | |
|
115 | 57 | { |
|
116 | const qreal deltaX = size.width()/domain.spanX(); | |
|
117 | const qreal deltaY = size.height()/domain.spanY(); | |
|
118 | qreal x = (series->x(index) - domain.m_minX)* deltaX; | |
|
119 | qreal y = (series->y(index) - domain.m_minY)*-deltaY + size.height(); | |
|
120 | point.setX(x); | |
|
121 | point.setY(y); | |
|
58 | const qreal deltaX = m_size.width()/m_domain.spanX(); | |
|
59 | const qreal deltaY = m_size.height()/m_domain.spanY(); | |
|
60 | qreal x = (m_series->x(index) - m_domain.m_minX)* deltaX; | |
|
61 | qreal y = (m_series->y(index) - m_domain.m_minY)*-deltaY + m_size.height(); | |
|
62 | return QPointF(x,y); | |
|
122 | 63 | } |
|
123 | 64 | |
|
124 | 65 | |
|
125 |
void LineChartItem::calculatePoints(QVector<QPointF>& points, Q |
|
|
66 | void LineChartItem::calculatePoints(QVector<QPointF>& points, QVector<int>& map) const | |
|
126 | 67 | { |
|
127 | const qreal deltaX = size.width()/domain.spanX(); | |
|
128 | const qreal deltaY = size.height()/domain.spanY(); | |
|
68 | const qreal deltaX = m_size.width()/m_domain.spanX(); | |
|
69 | const qreal deltaY = m_size.height()/m_domain.spanY(); | |
|
129 | 70 | |
|
130 | for (int i = 0; i < series->count(); ++i) { | |
|
131 | qreal x = (series->x(i) - domain.m_minX)* deltaX; | |
|
132 | qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height(); | |
|
133 | hash[i] = points.size(); | |
|
71 | for (int i = 0; i < m_series->count(); ++i) { | |
|
72 | qreal x = (m_series->x(i) - m_domain.m_minX)* deltaX; | |
|
73 | qreal y = (m_series->y(i) - m_domain.m_minY)*-deltaY + m_size.height(); | |
|
74 | map << i; | |
|
134 | 75 | points << QPointF(x,y); |
|
135 | 76 | } |
|
136 | 77 | } |
|
137 | 78 | |
|
138 | void LineChartItem::updateDomain() | |
|
79 | void LineChartItem::updateItem(QVector<QPointF>& points,QVector<int>& map) | |
|
139 | 80 | { |
|
140 | clear(); | |
|
141 | prepareGeometryChange(); | |
|
142 | calculatePoints(m_data,m_hash,m_series,m_size, m_domain); | |
|
143 | addPoints(m_data); | |
|
81 | int diff = m_points.size() - points.size(); | |
|
82 | ||
|
83 | if(diff>0) { | |
|
84 | clearPoints(diff); | |
|
85 | } | |
|
86 | else if(diff<0) { | |
|
87 | createPoints(-diff); | |
|
144 | 88 | } |
|
145 | 89 | |
|
146 | void LineChartItem::updateData() | |
|
147 | { | |
|
148 | //for now the same | |
|
149 | updateDomain(); | |
|
90 | applyGeometry(points); | |
|
91 | m_points=points; | |
|
92 | m_map=map; | |
|
150 | 93 | } |
|
151 | 94 | |
|
152 |
void LineChartItem:: |
|
|
95 | void LineChartItem::applyGeometry(QVector<QPointF>& points) | |
|
153 | 96 | { |
|
97 | if(points.size()==0) return; | |
|
154 | 98 | |
|
155 | if(m_data.size()==0) return; | |
|
99 | QList<QGraphicsItem*> items = m_items.childItems(); | |
|
156 | 100 | |
|
157 | prepareGeometryChange(); | |
|
158 | 101 | QPainterPath path; |
|
159 |
const QPointF& point = |
|
|
102 | const QPointF& point = points.at(0); | |
|
160 | 103 | path.moveTo(point); |
|
104 | QGraphicsItem* item = items.at(0); | |
|
105 | item->setPos(point.x()-1,point.y()-1); | |
|
161 | 106 | |
|
162 | foreach( const QPointF& point , m_data) { | |
|
107 | for(int i=1 ; i< points.size();i++) { | |
|
108 | QGraphicsItem* item = items.at(i); | |
|
109 | const QPointF& point = points.at(i); | |
|
110 | item->setPos(point.x()-1,point.y()-1); | |
|
111 | if(!m_clipRect.contains(point)) item->setVisible(false); | |
|
163 | 112 | path.lineTo(point); |
|
164 | 113 | } |
|
165 | 114 | |
|
115 | prepareGeometryChange(); | |
|
166 | 116 | m_path = path; |
|
167 | 117 | m_rect = path.boundingRect(); |
|
168 | 118 | } |
@@ -174,14 +124,78 void LineChartItem::setPen(const QPen& pen) | |||
|
174 | 124 | |
|
175 | 125 | //handlers |
|
176 | 126 | |
|
177 |
void LineChartItem::handle |
|
|
127 | void LineChartItem::handlePointAdded(int index) | |
|
128 | { | |
|
129 | Q_ASSERT(index<m_series->count()); | |
|
130 | Q_ASSERT(index>=0); | |
|
131 | ||
|
132 | if(m_map.contains(index)){ | |
|
133 | ||
|
134 | int i = m_map.indexOf(index); | |
|
135 | ||
|
136 | QPointF point = calculatePoint(index); | |
|
137 | ||
|
138 | if(point.isNull()) return; | |
|
139 | ||
|
140 | QVector<QPointF> points = m_points; | |
|
141 | points.insert(i,point); | |
|
142 | ||
|
143 | for(int j=i;j<m_map.count();j++) | |
|
144 | m_map[j]-=1; | |
|
145 | ||
|
146 | updateItem(points,m_map); | |
|
147 | ||
|
148 | }else{ | |
|
149 | //ignore | |
|
150 | return; | |
|
151 | } | |
|
152 | update(); | |
|
153 | } | |
|
154 | void LineChartItem::handlePointRemoved(int index) | |
|
155 | { | |
|
156 | Q_ASSERT(index<m_series->count()); | |
|
157 | Q_ASSERT(index>=0); | |
|
158 | ||
|
159 | if(m_map.contains(index)){ | |
|
160 | ||
|
161 | int i = m_map.value(index); | |
|
162 | ||
|
163 | QVector<QPointF> points = m_points; | |
|
164 | points.remove(i); | |
|
165 | ||
|
166 | for(int j=i;j<m_map.count();j++) | |
|
167 | m_map[j]+=1; | |
|
168 | ||
|
169 | m_map<< | |
|
170 | ||
|
171 | updateItem(points,m_map); | |
|
172 | ||
|
173 | }else{ | |
|
174 | //ignore | |
|
175 | return; | |
|
176 | } | |
|
177 | update(); | |
|
178 | } | |
|
179 | ||
|
180 | void LineChartItem::handlePointReplaced(int index) | |
|
178 | 181 | { |
|
179 | 182 | Q_ASSERT(index<m_series->count()); |
|
180 | if(m_hash.contains(index)){ | |
|
181 | int i = m_hash.value(index); | |
|
182 | QPointF point; | |
|
183 | calculatePoint(point,index,m_series,m_size,m_domain); | |
|
184 | setPoint(i,point); | |
|
183 | Q_ASSERT(index>=0); | |
|
184 | ||
|
185 | if(m_map.contains(index)){ | |
|
186 | ||
|
187 | int i = m_map.indexOf(index); | |
|
188 | ||
|
189 | QPointF point = calculatePoint(index); | |
|
190 | ||
|
191 | QVector<QPointF> points = m_points; | |
|
192 | points.replace(i,point); | |
|
193 | ||
|
194 | updateItem(points,m_map); | |
|
195 | ||
|
196 | }else{ | |
|
197 | //ignore | |
|
198 | return; | |
|
185 | 199 | } |
|
186 | 200 | update(); |
|
187 | 201 | } |
@@ -189,7 +203,12 void LineChartItem::handleModelChanged(int index) | |||
|
189 | 203 | void LineChartItem::handleDomainChanged(const Domain& domain) |
|
190 | 204 | { |
|
191 | 205 | m_domain = domain; |
|
192 | updateDomain(); | |
|
206 | if(m_domain.isEmpty()) return; | |
|
207 | ||
|
208 | QVector<QPointF> points; | |
|
209 | QVector<int> map; | |
|
210 | calculatePoints(points,map); | |
|
211 | updateItem(points,map); | |
|
193 | 212 | update(); |
|
194 | 213 | } |
|
195 | 214 | |
@@ -198,9 +217,24 void LineChartItem::handleGeometryChanged(const QRectF& rect) | |||
|
198 | 217 | Q_ASSERT(rect.isValid()); |
|
199 | 218 | m_size=rect.size(); |
|
200 | 219 | m_clipRect=rect.translated(-rect.topLeft()); |
|
201 | updateDomain(); | |
|
202 | updateGeometry(); | |
|
203 | 220 | setPos(rect.topLeft()); |
|
221 | ||
|
222 | if(m_domain.isEmpty()) return; | |
|
223 | if(m_points.isEmpty()) return; | |
|
224 | ||
|
225 | QVector<QPointF> points; | |
|
226 | QVector<int> map; | |
|
227 | calculatePoints(points,map); | |
|
228 | updateItem(points,map); | |
|
229 | update(); | |
|
230 | } | |
|
231 | ||
|
232 | void LineChartItem::handleSeriesUpdated() | |
|
233 | { | |
|
234 | if(m_points.count()==0) return; | |
|
235 | ||
|
236 | m_items.setVisible(m_series->pointsVisible()); | |
|
237 | setPen(m_series->pen()); | |
|
204 | 238 | update(); |
|
205 | 239 | } |
|
206 | 240 |
@@ -9,7 +9,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | 9 | |
|
10 | 10 | class ChartPresenter; |
|
11 | 11 | class QLineSeries; |
|
12 | class LineChartAnimationItem; | |
|
13 | 12 | |
|
14 | 13 | class LineChartItem : public QObject , public ChartItem |
|
15 | 14 | { |
@@ -24,32 +23,28 public: | |||
|
24 | 23 | QPainterPath shape() const; |
|
25 | 24 | |
|
26 | 25 | void setPen(const QPen& pen); |
|
27 | const Domain& domain() const { return m_domain;} | |
|
26 | void setPointsVisible(bool visible); | |
|
27 | ||
|
28 | public slots: | |
|
29 | void handlePointAdded(int index); | |
|
30 | void handlePointRemoved(int index); | |
|
31 | void handlePointReplaced(int index); | |
|
32 | void handleDomainChanged(const Domain& domain); | |
|
33 | void handleGeometryChanged(const QRectF& size); | |
|
28 | 34 | |
|
35 | protected: | |
|
29 | 36 | virtual void addPoint(const QPointF& ); |
|
30 | 37 | virtual void addPoints(const QVector<QPointF>& points); |
|
31 | 38 | virtual void removePoint(const QPointF& point); |
|
32 |
virtual void |
|
|
33 |
virtual void |
|
|
34 | void setPointsVisible(bool visible); | |
|
35 | void clear(); | |
|
36 | void clearView(); | |
|
37 | int count() const { return m_data.size();} | |
|
38 | ||
|
39 | const QVector<QPointF>& points(){ return m_data;} | |
|
39 | virtual void replacePoint(const QPointF& oldPoint, const QPointF& newPoint); | |
|
40 | virtual void replacePoint(int index,const QPointF& point); | |
|
41 | virtual void updateItem(QVector<QPointF>& points,QVector<int>& map); | |
|
42 | virtual void applyGeometry(QVector<QPointF>& points); | |
|
40 | 43 | |
|
41 | protected: | |
|
42 | virtual void updateGeometry(); | |
|
43 | virtual void updateData(); | |
|
44 | virtual void updateDomain(); | |
|
45 | //refactor | |
|
46 | void calculatePoint(QPointF& point, int index, const QLineSeries* series,const QSizeF& size, const Domain& domain) const; | |
|
47 | void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QLineSeries* series, const QSizeF& size, const Domain& domain) const; | |
|
44 | void clear(); | |
|
48 | 45 | |
|
49 | protected slots: | |
|
50 | void handleModelChanged(int index); | |
|
51 | void handleDomainChanged(const Domain& domain); | |
|
52 | void handleGeometryChanged(const QRectF& size); | |
|
46 | QPointF calculatePoint(int index) const; | |
|
47 | void calculatePoints(QVector<QPointF>& points,QVector<int>& map) const; | |
|
53 | 48 | |
|
54 | 49 | private: |
|
55 | 50 | ChartPresenter* m_presenter; |
@@ -58,14 +53,11 private: | |||
|
58 | 53 | QRectF m_rect; |
|
59 | 54 | QRectF m_clipRect; |
|
60 | 55 | Domain m_domain; |
|
61 |
QList<QGraphicsItem*> m_ |
|
|
62 |
QVector<QPointF> m_ |
|
|
63 |
Q |
|
|
56 | QList<QGraphicsItem*> m_items; | |
|
57 | QVector<QPointF> m_points; | |
|
58 | QVector<int> m_map; | |
|
64 | 59 | QLineSeries* m_series; |
|
65 | 60 | QPen m_pen; |
|
66 | bool m_dirtyData; | |
|
67 | bool m_dirtyGeometry; | |
|
68 | bool m_dirtyDomain; | |
|
69 | 61 | |
|
70 | 62 | }; |
|
71 | 63 |
@@ -43,7 +43,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 |
\fn void QLineSeries::point |
|
|
46 | \fn void QLineSeries::pointReplaced(int index) | |
|
47 | 47 | \brief \internal \a index |
|
48 | 48 | */ |
|
49 | 49 | |
@@ -101,7 +101,7 void QLineSeries::replace(qreal x,qreal y) | |||
|
101 | 101 | int index = m_x.indexOf(x); |
|
102 | 102 | m_x[index]=x; |
|
103 | 103 | m_y[index]=y; |
|
104 |
emit point |
|
|
104 | emit pointReplaced(index); | |
|
105 | 105 | } |
|
106 | 106 | |
|
107 | 107 | /*! |
General Comments 0
You need to be logged in to leave comments.
Login now