@@ -1,49 +1,55 | |||||
1 | #include "baranimation_p.h" |
|
1 | #include "baranimation_p.h" | |
2 | #include "barchartitem_p.h" |
|
2 | #include "barchartitem_p.h" | |
3 | #include <QParallelAnimationGroup> |
|
3 | #include <QParallelAnimationGroup> | |
4 | #include <QTimer> |
|
4 | #include <QTimer> | |
5 |
|
5 | |||
6 |
Q_DECLARE_METATYPE(QVector<Q |
|
6 | Q_DECLARE_METATYPE(QVector<QRectF>) | |
|
7 | //Q_DECLARE_METATYPE(BarLayout) // TODO? | |||
|
8 | ||||
7 |
|
9 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
11 | |||
10 | BarAnimation::BarAnimation(BarChartItem *item) |
|
12 | BarAnimation::BarAnimation(BarChartItem *item) | |
11 | :ChartAnimation(item), |
|
13 | :ChartAnimation(item), | |
12 | m_item(item) |
|
14 | m_item(item) | |
13 | { |
|
15 | { | |
14 | } |
|
16 | } | |
15 |
|
17 | |||
16 | BarAnimation::~BarAnimation() |
|
18 | BarAnimation::~BarAnimation() | |
17 | { |
|
19 | { | |
18 | } |
|
20 | } | |
19 |
|
21 | |||
20 |
void BarAnimation::updateValues(const |
|
22 | void BarAnimation::updateValues(const QVector<QRectF>& layout) | |
21 | { |
|
23 | { | |
22 | // TODO: |
|
24 | // TODO?: | |
23 | qDebug() << "BarAnimation::updateValues"; |
|
25 | // qDebug() << "BarAnimation::updateValues" << layout.count(); | |
24 | } |
|
26 | } | |
25 |
|
27 | |||
26 |
|
28 | |||
27 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const |
|
29 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |
28 | { |
|
30 | { | |
29 |
QVector<Q |
|
31 | QVector<QRectF> startVector = qVariantValue<QVector<QRectF> > (from); | |
30 |
QVector<Q |
|
32 | QVector<QRectF> endVector = qVariantValue<QVector<QRectF> > (to); | |
31 |
QVector<Q |
|
33 | QVector<QRectF> result; | |
32 |
|
34 | |||
33 | Q_ASSERT(startVector.count() == endVector.count()) ; |
|
35 | Q_ASSERT(startVector.count() == endVector.count()) ; | |
34 |
|
36 | |||
35 | for(int i =0 ;i< startVector.count();i++){ |
|
37 | for(int i =0 ;i< startVector.count();i++){ | |
36 |
|
|
38 | //QRectF value = startVector[i] + ((endVector[i] - startVector[i]) * progress); | |
|
39 | QPointF topLeft = startVector[i].topLeft() + ((endVector[i].topLeft() - startVector[i].topLeft()) * progress); | |||
|
40 | QSizeF size = startVector[i].size() + ((endVector[i].size() - startVector[i].size()) * progress); | |||
|
41 | QRectF value(topLeft,size); | |||
37 |
|
|
42 | result << value; | |
38 | } |
|
43 | } | |
39 | return qVariantFromValue(result); |
|
44 | return qVariantFromValue(result); | |
40 | } |
|
45 | } | |
41 |
|
46 | |||
42 | void BarAnimation::updateCurrentValue(const QVariant &) |
|
47 | void BarAnimation::updateCurrentValue(const QVariant &value) | |
43 | { |
|
48 | { | |
44 | // TODO? |
|
49 | QVector<QRectF> layout = qVariantValue<QVector<QRectF> >(value); | |
|
50 | m_item->setLayout(layout); | |||
45 | } |
|
51 | } | |
46 |
|
52 | |||
47 | #include "moc_baranimation_p.cpp" |
|
53 | #include "moc_baranimation_p.cpp" | |
48 |
|
54 | |||
49 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,36 +1,36 | |||||
1 | #ifndef BARANIMATION_P_H_ |
|
1 | #ifndef BARANIMATION_P_H_ | |
2 | #define BARANIMATION_P_H_ |
|
2 | #define BARANIMATION_P_H_ | |
3 |
|
3 | |||
4 | #include "chartanimation_p.h" |
|
4 | #include "chartanimation_p.h" | |
5 | #include "barchartitem_p.h" |
|
5 | #include "barchartitem_p.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | class BarChartItem; |
|
9 | class BarChartItem; | |
10 | class QBarSet; |
|
10 | class QBarSet; | |
11 | class BarSetAnimation; |
|
11 | class BarSetAnimation; | |
12 |
|
12 | |||
13 | class BarAnimation : public ChartAnimation |
|
13 | class BarAnimation : public ChartAnimation | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 |
|
16 | |||
17 | public: |
|
17 | public: | |
18 | BarAnimation(BarChartItem *item); |
|
18 | BarAnimation(BarChartItem *item); | |
19 | ~BarAnimation(); |
|
19 | ~BarAnimation(); | |
20 |
|
20 | |||
21 |
void updateValues(const |
|
21 | void updateValues(const QVector<QRectF>& layout); | |
22 |
|
22 | |||
23 | public: // from QVariantAnimation |
|
23 | public: // from QVariantAnimation | |
24 | virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; |
|
24 | virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; | |
25 | virtual void updateCurrentValue (const QVariant & value ); |
|
25 | virtual void updateCurrentValue (const QVariant & value ); | |
26 |
|
26 | |||
27 | public Q_SLOTS: |
|
27 | public Q_SLOTS: | |
28 |
|
28 | |||
29 | private: |
|
29 | private: | |
30 | BarChartItem *m_item; |
|
30 | BarChartItem *m_item; | |
31 | QHash<QBarSet*, BarSetAnimation*> m_animations; |
|
31 | QHash<QBarSet*, BarSetAnimation*> m_animations; | |
32 | }; |
|
32 | }; | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_END_NAMESPACE |
|
34 | QTCOMMERCIALCHART_END_NAMESPACE | |
35 |
|
35 | |||
36 | #endif |
|
36 | #endif |
@@ -1,285 +1,290 | |||||
1 | #include "chartanimator_p.h" |
|
1 | #include "chartanimator_p.h" | |
2 | #include "axisanimation_p.h" |
|
2 | #include "axisanimation_p.h" | |
3 | #include "xyanimation_p.h" |
|
3 | #include "xyanimation_p.h" | |
4 | #include "splineanimation_p.h" |
|
4 | #include "splineanimation_p.h" | |
5 | #include "xychartitem_p.h" |
|
5 | #include "xychartitem_p.h" | |
6 | #include "pieanimation_p.h" |
|
6 | #include "pieanimation_p.h" | |
7 | #include "baranimation_p.h" |
|
7 | #include "baranimation_p.h" | |
8 | #include "barchartitem_p.h" |
|
8 | #include "barchartitem_p.h" | |
9 | #include "areachartitem_p.h" |
|
9 | #include "areachartitem_p.h" | |
10 | #include "splinechartitem_p.h" |
|
10 | #include "splinechartitem_p.h" | |
11 | #include "scatterchartitem_p.h" |
|
11 | #include "scatterchartitem_p.h" | |
12 | #include <QTimer> |
|
12 | #include <QTimer> | |
13 |
|
13 | |||
14 | Q_DECLARE_METATYPE(QVector<QPointF>) |
|
14 | Q_DECLARE_METATYPE(QVector<QPointF>) | |
15 | Q_DECLARE_METATYPE(QVector<qreal>) |
|
15 | Q_DECLARE_METATYPE(QVector<qreal>) | |
|
16 | Q_DECLARE_METATYPE(QVector<QRectF>) | |||
16 |
|
17 | |||
17 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
18 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
18 |
|
19 | |||
19 | const static int duration = 1000; |
|
20 | const static int duration = 1000; | |
20 |
|
21 | |||
21 | ChartAnimator::ChartAnimator(QObject *parent):QObject(parent) |
|
22 | ChartAnimator::ChartAnimator(QObject *parent):QObject(parent) | |
22 | { |
|
23 | { | |
23 | } |
|
24 | } | |
24 |
|
25 | |||
25 | ChartAnimator::~ChartAnimator() |
|
26 | ChartAnimator::~ChartAnimator() | |
26 | { |
|
27 | { | |
27 | } |
|
28 | } | |
28 |
|
29 | |||
29 | void ChartAnimator::addAnimation(Axis* item) |
|
30 | void ChartAnimator::addAnimation(Axis* item) | |
30 | { |
|
31 | { | |
31 | ChartAnimation* animation = m_animations.value(item); |
|
32 | ChartAnimation* animation = m_animations.value(item); | |
32 |
|
33 | |||
33 | if(!animation) { |
|
34 | if(!animation) { | |
34 | animation = new AxisAnimation(item); |
|
35 | animation = new AxisAnimation(item); | |
35 | m_animations.insert(item,animation); |
|
36 | m_animations.insert(item,animation); | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
38 | item->setAnimator(this); |
|
39 | item->setAnimator(this); | |
39 | } |
|
40 | } | |
40 |
|
41 | |||
41 | void ChartAnimator::addAnimation(SplineChartItem* item) |
|
42 | void ChartAnimator::addAnimation(SplineChartItem* item) | |
42 | { |
|
43 | { | |
43 | ChartAnimation* animation = m_animations.value(item); |
|
44 | ChartAnimation* animation = m_animations.value(item); | |
44 |
|
45 | |||
45 | if(!animation) { |
|
46 | if(!animation) { | |
46 | animation = new SplineAnimation(item); |
|
47 | animation = new SplineAnimation(item); | |
47 | m_animations.insert(item,animation); |
|
48 | m_animations.insert(item,animation); | |
48 | } |
|
49 | } | |
49 |
|
50 | |||
50 | item->setAnimator(this); |
|
51 | item->setAnimator(this); | |
51 | } |
|
52 | } | |
52 |
|
53 | |||
53 | void ChartAnimator::addAnimation(ScatterChartItem* item) |
|
54 | void ChartAnimator::addAnimation(ScatterChartItem* item) | |
54 | { |
|
55 | { | |
55 | ChartAnimation* animation = m_animations.value(item); |
|
56 | ChartAnimation* animation = m_animations.value(item); | |
56 |
|
57 | |||
57 | if(!animation) { |
|
58 | if(!animation) { | |
58 | animation = new XYAnimation(item); |
|
59 | animation = new XYAnimation(item); | |
59 | m_animations.insert(item,animation); |
|
60 | m_animations.insert(item,animation); | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | item->setAnimator(this); |
|
63 | item->setAnimator(this); | |
63 | } |
|
64 | } | |
64 |
|
65 | |||
65 | void ChartAnimator::addAnimation(LineChartItem* item) |
|
66 | void ChartAnimator::addAnimation(LineChartItem* item) | |
66 | { |
|
67 | { | |
67 | ChartAnimation* animation = m_animations.value(item); |
|
68 | ChartAnimation* animation = m_animations.value(item); | |
68 |
|
69 | |||
69 | if(!animation) { |
|
70 | if(!animation) { | |
70 | animation = new XYAnimation(item); |
|
71 | animation = new XYAnimation(item); | |
71 | m_animations.insert(item,animation); |
|
72 | m_animations.insert(item,animation); | |
72 | } |
|
73 | } | |
73 |
|
74 | |||
74 | item->setAnimator(this); |
|
75 | item->setAnimator(this); | |
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | void ChartAnimator::addAnimation(PieChartItem* item) |
|
78 | void ChartAnimator::addAnimation(PieChartItem* item) | |
78 | { |
|
79 | { | |
79 | ChartAnimation* animation = m_animations.value(item); |
|
80 | ChartAnimation* animation = m_animations.value(item); | |
80 |
|
81 | |||
81 | if(!animation) { |
|
82 | if(!animation) { | |
82 | animation = new PieAnimation(item); |
|
83 | animation = new PieAnimation(item); | |
83 | m_animations.insert(item,animation); |
|
84 | m_animations.insert(item,animation); | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | item->setAnimator(this); |
|
87 | item->setAnimator(this); | |
87 | } |
|
88 | } | |
88 |
|
89 | |||
89 | void ChartAnimator::addAnimation(BarChartItem* item) |
|
90 | void ChartAnimator::addAnimation(BarChartItem* item) | |
90 | { |
|
91 | { | |
91 | ChartAnimation* animation = m_animations.value(item); |
|
92 | ChartAnimation* animation = m_animations.value(item); | |
92 |
|
93 | |||
93 | if(!animation) { |
|
94 | if(!animation) { | |
94 | animation = new BarAnimation(item); |
|
95 | animation = new BarAnimation(item); | |
95 | m_animations.insert(item,animation); |
|
96 | m_animations.insert(item,animation); | |
96 | } |
|
97 | } | |
97 |
|
98 | |||
98 | item->setAnimator(this); |
|
99 | item->setAnimator(this); | |
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 |
|
102 | |||
102 | void ChartAnimator::removeAnimation(Chart* item) |
|
103 | void ChartAnimator::removeAnimation(Chart* item) | |
103 | { |
|
104 | { | |
104 | item->setAnimator(0); |
|
105 | item->setAnimator(0); | |
105 | m_animations.remove(item); |
|
106 | m_animations.remove(item); | |
106 | } |
|
107 | } | |
107 |
|
108 | |||
108 | void ChartAnimator::updateLayout(Axis* item , QVector<qreal>& newLayout) |
|
109 | void ChartAnimator::updateLayout(Axis* item , QVector<qreal>& newLayout) | |
109 | { |
|
110 | { | |
110 | AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item)); |
|
111 | AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item)); | |
111 |
|
112 | |||
112 | Q_ASSERT(animation); |
|
113 | Q_ASSERT(animation); | |
113 |
|
114 | |||
114 | QVector<qreal> oldLayout = item->layout(); |
|
115 | QVector<qreal> oldLayout = item->layout(); | |
115 |
|
116 | |||
116 | if(newLayout.count()==0) return; |
|
117 | if(newLayout.count()==0) return; | |
117 |
|
118 | |||
118 | switch(m_state) |
|
119 | switch(m_state) | |
119 | { |
|
120 | { | |
120 | case ZoomOutState: { |
|
121 | case ZoomOutState: { | |
121 | QRectF rect = item->geometry(); |
|
122 | QRectF rect = item->geometry(); | |
122 | oldLayout.resize(newLayout.count()); |
|
123 | oldLayout.resize(newLayout.count()); | |
123 |
|
124 | |||
124 | for(int i=0,j=oldLayout.count()-1;i<(oldLayout.count()+1)/2;i++,j--) |
|
125 | for(int i=0,j=oldLayout.count()-1;i<(oldLayout.count()+1)/2;i++,j--) | |
125 | { |
|
126 | { | |
126 | oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.bottom(); |
|
127 | oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.bottom(); | |
127 | oldLayout[j]= item->axisType()==Axis::X_AXIS?rect.right():rect.top(); |
|
128 | oldLayout[j]= item->axisType()==Axis::X_AXIS?rect.right():rect.top(); | |
128 | } |
|
129 | } | |
129 | } |
|
130 | } | |
130 | break; |
|
131 | break; | |
131 | case ZoomInState: { |
|
132 | case ZoomInState: { | |
132 | int index = qMin(oldLayout.count()*(item->axisType()==Axis::X_AXIS?m_point.x():(1 -m_point.y())),newLayout.count()-1.0); |
|
133 | int index = qMin(oldLayout.count()*(item->axisType()==Axis::X_AXIS?m_point.x():(1 -m_point.y())),newLayout.count()-1.0); | |
133 | oldLayout.resize(newLayout.count()); |
|
134 | oldLayout.resize(newLayout.count()); | |
134 |
|
135 | |||
135 | for(int i=0;i<oldLayout.count();i++) |
|
136 | for(int i=0;i<oldLayout.count();i++) | |
136 | { |
|
137 | { | |
137 | oldLayout[i]= oldLayout[index]; |
|
138 | oldLayout[i]= oldLayout[index]; | |
138 | } |
|
139 | } | |
139 | } |
|
140 | } | |
140 | break; |
|
141 | break; | |
141 | case ScrollDownState: |
|
142 | case ScrollDownState: | |
142 | case ScrollRightState: { |
|
143 | case ScrollRightState: { | |
143 | oldLayout.resize(newLayout.count()); |
|
144 | oldLayout.resize(newLayout.count()); | |
144 |
|
145 | |||
145 | for(int i=0, j=i+1;i<oldLayout.count()-1;i++,j++) |
|
146 | for(int i=0, j=i+1;i<oldLayout.count()-1;i++,j++) | |
146 | { |
|
147 | { | |
147 | oldLayout[i]= oldLayout[j]; |
|
148 | oldLayout[i]= oldLayout[j]; | |
148 | } |
|
149 | } | |
149 | } |
|
150 | } | |
150 | break; |
|
151 | break; | |
151 | case ScrollUpState: |
|
152 | case ScrollUpState: | |
152 | case ScrollLeftState: { |
|
153 | case ScrollLeftState: { | |
153 | oldLayout.resize(newLayout.count()); |
|
154 | oldLayout.resize(newLayout.count()); | |
154 |
|
155 | |||
155 | for(int i=oldLayout.count()-1, j=i-1;i>0;i--,j--) |
|
156 | for(int i=oldLayout.count()-1, j=i-1;i>0;i--,j--) | |
156 | { |
|
157 | { | |
157 | oldLayout[i]= oldLayout[j]; |
|
158 | oldLayout[i]= oldLayout[j]; | |
158 | } |
|
159 | } | |
159 | } |
|
160 | } | |
160 | break; |
|
161 | break; | |
161 | default: { |
|
162 | default: { | |
162 | oldLayout.resize(newLayout.count()); |
|
163 | oldLayout.resize(newLayout.count()); | |
163 | QRectF rect = item->geometry(); |
|
164 | QRectF rect = item->geometry(); | |
164 | for(int i=0, j=oldLayout.count()-1;i<oldLayout.count();i++,j--) |
|
165 | for(int i=0, j=oldLayout.count()-1;i<oldLayout.count();i++,j--) | |
165 | { |
|
166 | { | |
166 | oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.top(); |
|
167 | oldLayout[i]= item->axisType()==Axis::X_AXIS?rect.left():rect.top(); | |
167 | } |
|
168 | } | |
168 | } |
|
169 | } | |
169 | break; |
|
170 | break; | |
170 | } |
|
171 | } | |
171 |
|
172 | |||
172 |
|
173 | |||
173 | if(animation->state()!=QAbstractAnimation::Stopped) { |
|
174 | if(animation->state()!=QAbstractAnimation::Stopped) { | |
174 | animation->stop(); |
|
175 | animation->stop(); | |
175 | } |
|
176 | } | |
176 |
|
177 | |||
177 | animation->setDuration(duration); |
|
178 | animation->setDuration(duration); | |
178 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
179 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
179 | QVariantAnimation::KeyValues value; |
|
180 | QVariantAnimation::KeyValues value; | |
180 | animation->setKeyValues(value); //workaround for wrong interpolation call |
|
181 | animation->setKeyValues(value); //workaround for wrong interpolation call | |
181 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); |
|
182 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |
182 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); |
|
183 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |
183 |
|
184 | |||
184 | QTimer::singleShot(0,animation,SLOT(start())); |
|
185 | QTimer::singleShot(0,animation,SLOT(start())); | |
185 | } |
|
186 | } | |
186 |
|
187 | |||
187 | void ChartAnimator::updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints ,QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newControlPoints,int index) |
|
188 | void ChartAnimator::updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints ,QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newControlPoints,int index) | |
188 | { |
|
189 | { | |
189 | SplineAnimation* animation = static_cast<SplineAnimation*>(m_animations.value(item)); |
|
190 | SplineAnimation* animation = static_cast<SplineAnimation*>(m_animations.value(item)); | |
190 |
|
191 | |||
191 | Q_ASSERT(animation); |
|
192 | Q_ASSERT(animation); | |
192 |
|
193 | |||
193 | if(newPoints.count()<2 || newControlPoints.count()<2) return; |
|
194 | if(newPoints.count()<2 || newControlPoints.count()<2) return; | |
194 |
|
195 | |||
195 | bool empty = oldPoints.count()==0; |
|
196 | bool empty = oldPoints.count()==0; | |
196 |
|
197 | |||
197 |
|
198 | |||
198 | if(animation->state()!=QAbstractAnimation::Stopped) { |
|
199 | if(animation->state()!=QAbstractAnimation::Stopped) { | |
199 | animation->stop(); |
|
200 | animation->stop(); | |
200 | } |
|
201 | } | |
201 |
|
202 | |||
202 | animation->setDuration(duration); |
|
203 | animation->setDuration(duration); | |
203 | if(!empty) |
|
204 | if(!empty) | |
204 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); |
|
205 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); | |
205 | else |
|
206 | else | |
206 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); |
|
207 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); | |
207 |
|
208 | |||
208 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
209 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
209 | animation->setValues(oldPoints,newPoints,oldControlPoints,newControlPoints,index); |
|
210 | animation->setValues(oldPoints,newPoints,oldControlPoints,newControlPoints,index); | |
210 |
|
211 | |||
211 | QTimer::singleShot(0,animation,SLOT(start())); |
|
212 | QTimer::singleShot(0,animation,SLOT(start())); | |
212 | } |
|
213 | } | |
213 |
|
214 | |||
214 |
|
215 | |||
215 | void ChartAnimator::updateLayout(XYChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, int index) |
|
216 | void ChartAnimator::updateLayout(XYChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, int index) | |
216 | { |
|
217 | { | |
217 | XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item)); |
|
218 | XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item)); | |
218 |
|
219 | |||
219 | Q_ASSERT(animation); |
|
220 | Q_ASSERT(animation); | |
220 |
|
221 | |||
221 | if(newPoints.count()==0) return; |
|
222 | if(newPoints.count()==0) return; | |
222 |
|
223 | |||
223 | bool empty = oldPoints.count()==0; |
|
224 | bool empty = oldPoints.count()==0; | |
224 |
|
225 | |||
225 |
|
226 | |||
226 | if(animation->state()!=QAbstractAnimation::Stopped) { |
|
227 | if(animation->state()!=QAbstractAnimation::Stopped) { | |
227 | animation->stop(); |
|
228 | animation->stop(); | |
228 | } |
|
229 | } | |
229 |
|
230 | |||
230 | animation->setDuration(duration); |
|
231 | animation->setDuration(duration); | |
231 | if(!empty) |
|
232 | if(!empty) | |
232 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); |
|
233 | animation->setAnimationType(ChartAnimation::MoveDownAnimation); | |
233 | else |
|
234 | else | |
234 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); |
|
235 | animation->setAnimationType(ChartAnimation::LineDrawAnimation); | |
235 |
|
236 | |||
236 | animation->setEasingCurve(QEasingCurve::OutQuart); |
|
237 | animation->setEasingCurve(QEasingCurve::OutQuart); | |
237 | animation->setValues(oldPoints,newPoints,index); |
|
238 | animation->setValues(oldPoints,newPoints,index); | |
238 |
|
239 | |||
239 | QTimer::singleShot(0,animation,SLOT(start())); |
|
240 | QTimer::singleShot(0,animation,SLOT(start())); | |
240 | } |
|
241 | } | |
241 |
|
242 | |||
242 | void ChartAnimator::addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) |
|
243 | void ChartAnimator::addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty) | |
243 | { |
|
244 | { | |
244 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); |
|
245 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); | |
245 | Q_ASSERT(animation); |
|
246 | Q_ASSERT(animation); | |
246 | animation->addSlice(slice, sliceData, isEmpty); |
|
247 | animation->addSlice(slice, sliceData, isEmpty); | |
247 | } |
|
248 | } | |
248 |
|
249 | |||
249 | void ChartAnimator::removeAnimation(PieChartItem* item, QPieSlice *slice) |
|
250 | void ChartAnimator::removeAnimation(PieChartItem* item, QPieSlice *slice) | |
250 | { |
|
251 | { | |
251 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); |
|
252 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); | |
252 | Q_ASSERT(animation); |
|
253 | Q_ASSERT(animation); | |
253 | animation->removeSlice(slice); |
|
254 | animation->removeSlice(slice); | |
254 | } |
|
255 | } | |
255 |
|
256 | |||
256 | void ChartAnimator::updateLayout(PieChartItem* item, const PieLayout &layout) |
|
257 | void ChartAnimator::updateLayout(PieChartItem* item, const PieLayout &layout) | |
257 | { |
|
258 | { | |
258 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); |
|
259 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); | |
259 | Q_ASSERT(animation); |
|
260 | Q_ASSERT(animation); | |
260 | animation->updateValues(layout); |
|
261 | animation->updateValues(layout); | |
261 | } |
|
262 | } | |
262 |
|
263 | |||
263 | void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData) |
|
264 | void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData) | |
264 | { |
|
265 | { | |
265 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); |
|
266 | PieAnimation* animation = static_cast<PieAnimation*>(m_animations.value(item)); | |
266 | Q_ASSERT(animation); |
|
267 | Q_ASSERT(animation); | |
267 | animation->updateValue(slice, sliceData); |
|
268 | animation->updateValue(slice, sliceData); | |
268 | } |
|
269 | } | |
269 |
|
270 | |||
270 |
void ChartAnimator::updateLayout(BarChartItem* item, const |
|
271 | void ChartAnimator::updateLayout(BarChartItem* item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout) | |
271 | { |
|
272 | { | |
272 | qDebug() << "ChartAnimator::updateLayout"; |
|
273 | qDebug() << "ChartAnimator::updateLayout"; | |
273 | BarAnimation* animation = static_cast<BarAnimation*>(m_animations.value(item)); |
|
274 | BarAnimation* animation = static_cast<BarAnimation*>(m_animations.value(item)); | |
274 | Q_ASSERT(animation); |
|
275 | Q_ASSERT(animation); | |
275 | animation->updateValues(layout); |
|
276 | // animation->updateValues(layout); | |
|
277 | animation->setDuration(duration); | |||
|
278 | animation->setKeyValueAt(0.0, qVariantFromValue(oldLayout)); | |||
|
279 | animation->setKeyValueAt(1.0, qVariantFromValue(newLayout)); | |||
|
280 | QTimer::singleShot(0,animation,SLOT(start())); | |||
276 | } |
|
281 | } | |
277 |
|
282 | |||
278 |
|
283 | |||
279 | void ChartAnimator::setState(State state,const QPointF& point) |
|
284 | void ChartAnimator::setState(State state,const QPointF& point) | |
280 | { |
|
285 | { | |
281 | m_state=state; |
|
286 | m_state=state; | |
282 | m_point=point; |
|
287 | m_point=point; | |
283 | } |
|
288 | } | |
284 |
|
289 | |||
285 | QTCOMMERCIALCHART_END_NAMESPACE |
|
290 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,58 +1,58 | |||||
1 | #ifndef CHARTANIMATOR_P_H_ |
|
1 | #ifndef CHARTANIMATOR_P_H_ | |
2 | #define CHARTANIMATOR_P_H_ |
|
2 | #define CHARTANIMATOR_P_H_ | |
3 | #include "qchartglobal.h" |
|
3 | #include "qchartglobal.h" | |
4 | #include "chartanimation_p.h" |
|
4 | #include "chartanimation_p.h" | |
5 | #include "piechartitem_p.h" |
|
5 | #include "piechartitem_p.h" | |
6 | #include "barchartitem_p.h" |
|
6 | #include "barchartitem_p.h" | |
7 | #include <QPointF> |
|
7 | #include <QPointF> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class ChartItem; |
|
11 | class ChartItem; | |
12 | class Axis; |
|
12 | class Axis; | |
13 | class AreaChartItem; |
|
13 | class AreaChartItem; | |
14 | class SplineChartItem; |
|
14 | class SplineChartItem; | |
15 | class ScatterChartItem; |
|
15 | class ScatterChartItem; | |
16 | class LineChartItem; |
|
16 | class LineChartItem; | |
17 | class XYChartItem; |
|
17 | class XYChartItem; | |
18 |
|
18 | |||
19 | class ChartAnimator : public QObject { |
|
19 | class ChartAnimator : public QObject { | |
20 |
|
20 | |||
21 | public: |
|
21 | public: | |
22 | enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState,ScrollRightState,ZoomInState,ZoomOutState}; |
|
22 | enum State{ShowState, ScrollUpState, ScrollDownState, ScrollLeftState,ScrollRightState,ZoomInState,ZoomOutState}; | |
23 | Q_DECLARE_FLAGS(States, State); |
|
23 | Q_DECLARE_FLAGS(States, State); | |
24 |
|
24 | |||
25 | ChartAnimator(QObject *parent = 0); |
|
25 | ChartAnimator(QObject *parent = 0); | |
26 | virtual ~ChartAnimator(); |
|
26 | virtual ~ChartAnimator(); | |
27 |
|
27 | |||
28 | void addAnimation(Axis* item); |
|
28 | void addAnimation(Axis* item); | |
29 | void addAnimation(PieChartItem* item); |
|
29 | void addAnimation(PieChartItem* item); | |
30 | void addAnimation(ScatterChartItem* item); |
|
30 | void addAnimation(ScatterChartItem* item); | |
31 | void addAnimation(LineChartItem* item); |
|
31 | void addAnimation(LineChartItem* item); | |
32 | void addAnimation(SplineChartItem* item); |
|
32 | void addAnimation(SplineChartItem* item); | |
33 | void addAnimation(BarChartItem* item); |
|
33 | void addAnimation(BarChartItem* item); | |
34 | void removeAnimation(Chart* item); |
|
34 | void removeAnimation(Chart* item); | |
35 |
|
35 | |||
36 | void animationStarted(); |
|
36 | void animationStarted(); | |
37 | void updateLayout(XYChartItem* item, QVector<QPointF>& oldLayout,QVector<QPointF>& newLayout,int index); |
|
37 | void updateLayout(XYChartItem* item, QVector<QPointF>& oldLayout,QVector<QPointF>& newLayout,int index); | |
38 | void updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newContorlPoints,int index); |
|
38 | void updateLayout(SplineChartItem* item, QVector<QPointF>& oldPoints , QVector<QPointF>& newPoints, QVector<QPointF>& oldControlPoints, QVector<QPointF>& newContorlPoints,int index); | |
39 | void updateLayout(Axis* item, QVector<qreal>& layout); |
|
39 | void updateLayout(Axis* item, QVector<qreal>& layout); | |
40 |
|
40 | |||
41 | void addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty); |
|
41 | void addAnimation(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData, bool isEmpty); | |
42 | void removeAnimation(PieChartItem* item, QPieSlice *slice); |
|
42 | void removeAnimation(PieChartItem* item, QPieSlice *slice); | |
43 | void updateLayout(PieChartItem* item, const PieLayout &layout); |
|
43 | void updateLayout(PieChartItem* item, const PieLayout &layout); | |
44 | void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData); |
|
44 | void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData); | |
45 |
|
45 | |||
46 |
void updateLayout(BarChartItem* item, const |
|
46 | void updateLayout(BarChartItem* item, const QVector<QRectF> &oldLayout, const QVector<QRectF> &newLayout); | |
47 |
|
47 | |||
48 | void setState(State state,const QPointF& point = QPointF()); |
|
48 | void setState(State state,const QPointF& point = QPointF()); | |
49 |
|
49 | |||
50 | private: |
|
50 | private: | |
51 | QMap<Chart*,ChartAnimation*> m_animations; |
|
51 | QMap<Chart*,ChartAnimation*> m_animations; | |
52 | State m_state; |
|
52 | State m_state; | |
53 | QPointF m_point; |
|
53 | QPointF m_point; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE | |
57 |
|
57 | |||
58 | #endif |
|
58 | #endif |
@@ -1,266 +1,354 | |||||
1 | #include "barchartitem_p.h" |
|
1 | #include "barchartitem_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include "qchartaxis.h" |
|
7 | #include "qchartaxis.h" | |
8 | #include "qchartaxiscategories.h" |
|
8 | #include "qchartaxiscategories.h" | |
9 | #include "chartpresenter_p.h" |
|
9 | #include "chartpresenter_p.h" | |
10 | #include "chartanimator_p.h" |
|
10 | #include "chartanimator_p.h" | |
11 | #include "chartdataset_p.h" |
|
11 | #include "chartdataset_p.h" | |
12 | #include <QDebug> |
|
12 | #include <QDebug> | |
13 | #include <QToolTip> |
|
13 | #include <QToolTip> | |
14 |
|
14 | |||
15 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
15 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
16 |
|
16 | |||
17 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
17 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
18 | ChartItem(presenter), |
|
18 | ChartItem(presenter), | |
19 | mLayoutSet(false), |
|
19 | mLayoutSet(false), | |
20 | mSeries(series) |
|
20 | mSeries(series) | |
21 | { |
|
21 | { | |
22 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
22 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); | |
23 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); |
|
23 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
24 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); |
|
24 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); | |
25 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
25 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |
26 | setZValue(ChartPresenter::BarSeriesZValue); |
|
26 | setZValue(ChartPresenter::BarSeriesZValue); | |
27 | initAxisLabels(); |
|
27 | initAxisLabels(); | |
28 | dataChanged(); |
|
28 | dataChanged(); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | BarChartItem::~BarChartItem() |
|
31 | BarChartItem::~BarChartItem() | |
32 | { |
|
32 | { | |
33 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
33 | disconnect(this,SLOT(showToolTip(QPoint,QString))); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
36 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
37 | { |
|
37 | { | |
38 | if (!mLayoutSet) { |
|
38 | if (!mLayoutSet) { | |
39 | qDebug() << "BarChartItem::paint called without layout set. Aborting."; |
|
39 | qDebug() << "BarChartItem::paint called without layout set. Aborting."; | |
40 | return; |
|
40 | return; | |
41 | } |
|
41 | } | |
42 | foreach(QGraphicsItem* i, childItems()) { |
|
42 | foreach(QGraphicsItem* i, childItems()) { | |
43 | i->paint(painter,option,widget); |
|
43 | i->paint(painter,option,widget); | |
44 | } |
|
44 | } | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QRectF BarChartItem::boundingRect() const |
|
47 | QRectF BarChartItem::boundingRect() const | |
48 | { |
|
48 | { | |
49 | return m_rect; |
|
49 | return m_rect; | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void BarChartItem::dataChanged() |
|
52 | void BarChartItem::dataChanged() | |
53 | { |
|
53 | { | |
54 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
54 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
55 | // Delete old bars |
|
55 | // Delete old bars | |
56 | foreach (QGraphicsItem* item, childItems()) { |
|
56 | foreach (QGraphicsItem* item, childItems()) { | |
57 | delete item; |
|
57 | delete item; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | mBars.clear(); |
|
60 | mBars.clear(); | |
61 | mFloatingValues.clear(); |
|
61 | mFloatingValues.clear(); | |
|
62 | mLayout.clear(); | |||
62 |
|
63 | |||
63 | // Create new graphic items for bars |
|
64 | // Create new graphic items for bars | |
64 | for (int c=0; c<mSeries->categoryCount(); c++) { |
|
65 | for (int c=0; c<mSeries->categoryCount(); c++) { | |
65 | QString category = mSeries->categoryName(c); |
|
66 | QString category = mSeries->categoryName(c); | |
66 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
67 | for (int s=0; s<mSeries->barsetCount(); s++) { | |
67 | QBarSet *set = mSeries->barsetAt(s); |
|
68 | QBarSet *set = mSeries->barsetAt(s); | |
68 | Bar *bar = new Bar(category,this); |
|
69 | Bar *bar = new Bar(category,this); | |
69 | childItems().append(bar); |
|
70 | childItems().append(bar); | |
70 | mBars.append(bar); |
|
71 | mBars.append(bar); | |
71 | connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString))); |
|
72 | connect(bar,SIGNAL(clicked(QString)),set,SIGNAL(clicked(QString))); | |
72 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); |
|
73 | connect(bar,SIGNAL(rightClicked(QString)),set,SIGNAL(rightClicked(QString))); | |
73 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); |
|
74 | connect(bar,SIGNAL(hoverEntered(QPoint)),set,SLOT(barHoverEnterEvent(QPoint))); | |
74 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); |
|
75 | connect(bar,SIGNAL(hoverLeaved()),set,SLOT(barHoverLeaveEvent())); | |
|
76 | mLayout.append(QRectF(0,0,0,0)); | |||
75 | } |
|
77 | } | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 | // Create floating values |
|
80 | // Create floating values | |
79 | for (int category=0; category<mSeries->categoryCount(); category++) { |
|
81 | for (int category=0; category<mSeries->categoryCount(); category++) { | |
80 | for (int s=0; s<mSeries->barsetCount(); s++) { |
|
82 | for (int s=0; s<mSeries->barsetCount(); s++) { | |
81 | QBarSet *set = mSeries->barsetAt(s); |
|
83 | QBarSet *set = mSeries->barsetAt(s); | |
82 | BarValue *value = new BarValue(*set, this); |
|
84 | BarValue *value = new BarValue(*set, this); | |
83 | childItems().append(value); |
|
85 | childItems().append(value); | |
84 | mFloatingValues.append(value); |
|
86 | mFloatingValues.append(value); | |
85 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); |
|
87 | connect(set,SIGNAL(toggleFloatingValues()),value,SLOT(toggleVisible())); | |
86 | } |
|
88 | } | |
87 | } |
|
89 | } | |
88 | } |
|
90 | } | |
89 |
|
91 | /* | ||
90 | void BarChartItem::layoutChanged() |
|
92 | void BarChartItem::layoutChanged() | |
91 |
|
|
93 | { | |
|
94 | qDebug() << "Deprecated BarChartItem::layoutChanged called. aborting"; | |||
|
95 | return; | |||
92 | // Scale bars to new layout |
|
96 | // Scale bars to new layout | |
93 | // Layout for bars: |
|
97 | // Layout for bars: | |
94 | if (mSeries->barsetCount() <= 0) { |
|
98 | if (mSeries->barsetCount() <= 0) { | |
95 | qDebug() << "No sets in model!"; |
|
99 | qDebug() << "No sets in model!"; | |
96 | return; |
|
100 | return; | |
97 | } |
|
101 | } | |
98 |
|
|
102 | ||
99 | if (childItems().count() == 0) { |
|
103 | if (childItems().count() == 0) { | |
100 | qDebug() << "WARNING: BarChartitem::layoutChanged called before graphics items are created!"; |
|
104 | qDebug() << "WARNING: BarChartitem::layoutChanged called before graphics items are created!"; | |
101 | return; |
|
105 | return; | |
102 | } |
|
106 | } | |
103 |
|
|
107 | ||
104 |
|
|
108 | ||
105 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
109 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
106 | qreal categoryCount = mSeries->categoryCount(); |
|
110 | qreal categoryCount = mSeries->categoryCount(); | |
107 | qreal setCount = mSeries->barsetCount(); |
|
111 | qreal setCount = mSeries->barsetCount(); | |
108 | qreal max = mSeries->max(); |
|
112 | qreal max = mSeries->max(); | |
109 |
|
|
113 | ||
110 | // Domain: |
|
114 | // Domain: | |
111 | if (mDomainMaxY > max) { |
|
115 | if (mDomainMaxY > max) { | |
112 | max = mDomainMaxY; |
|
116 | max = mDomainMaxY; | |
113 | } |
|
117 | } | |
114 |
|
|
118 | ||
115 | qreal width = geometry().width(); |
|
119 | qreal width = geometry().width(); | |
116 | qreal height = geometry().height(); |
|
120 | qreal height = geometry().height(); | |
117 | qreal scale = (height/max); |
|
121 | qreal scale = (height/max); | |
118 | qreal categoryWidth = width/categoryCount; |
|
122 | qreal categoryWidth = width/categoryCount; | |
119 | qreal barWidth = categoryWidth / (setCount+1); |
|
123 | qreal barWidth = categoryWidth / (setCount+1); | |
120 |
|
|
124 | ||
|
125 | BarLayout layout; | |||
|
126 | ||||
121 | int itemIndex(0); |
|
127 | int itemIndex(0); | |
122 | for (int category=0; category < categoryCount; category++) { |
|
128 | for (int category=0; category < categoryCount; category++) { | |
123 | qreal xPos = categoryWidth * category + barWidth/2; |
|
129 | qreal xPos = categoryWidth * category + barWidth/2; | |
124 | qreal yPos = height; |
|
130 | qreal yPos = height; | |
125 | for (int set = 0; set < setCount; set++) { |
|
131 | for (int set = 0; set < setCount; set++) { | |
126 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
132 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
127 | Bar* bar = mBars.at(itemIndex); |
|
133 | Bar* bar = mBars.at(itemIndex); | |
128 |
|
|
134 | ||
|
135 | QRectF rect(xPos,yPos-barHeight,mBarWidth,barHeight); | |||
|
136 | layout.insert(bar,rect); | |||
129 | // TODO: width settable per bar? |
|
137 | // TODO: width settable per bar? | |
130 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); |
|
138 | bar->setRect(xPos, yPos-barHeight,barWidth, barHeight); | |
131 | bar->setPen(mSeries->barsetAt(set)->pen()); |
|
139 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
132 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
140 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
133 |
|
|
141 | ||
|
142 | // bar->resize(mBarWidth, barHeight); | |||
|
143 | // layout.insert(bar,QSizeF(mBarWidth,barHeight)); | |||
|
144 | bar->setPen(mSeries->barsetAt(set)->pen()); | |||
|
145 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |||
|
146 | // bar->setPos(xPos, yPos-barHeight); | |||
134 | itemIndex++; |
|
147 | itemIndex++; | |
135 | xPos += barWidth; |
|
148 | xPos += barWidth; | |
136 | } |
|
149 | } | |
137 | } |
|
150 | } | |
138 |
|
|
151 | ||
139 | // Position floating values |
|
152 | // Position floating values | |
140 | itemIndex = 0; |
|
153 | itemIndex = 0; | |
141 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
154 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
142 | qreal xPos = categoryWidth * category + categoryWidth/2 + barWidth; |
|
155 | qreal xPos = categoryWidth * category + categoryWidth/2 + barWidth; | |
143 | qreal yPos = height; |
|
156 | qreal yPos = height; | |
144 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
157 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
145 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
158 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
146 | BarValue* value = mFloatingValues.at(itemIndex); |
|
159 | BarValue* value = mFloatingValues.at(itemIndex); | |
147 |
|
|
160 | ||
148 | QBarSet* barSet = mSeries->barsetAt(set); |
|
161 | QBarSet* barSet = mSeries->barsetAt(set); | |
149 | value->resize(100,50); // TODO: proper layout for this. |
|
162 | value->resize(100,50); // TODO: proper layout for this. | |
150 | value->setPos(xPos, yPos-barHeight/2); |
|
163 | value->setPos(xPos, yPos-barHeight/2); | |
151 | value->setPen(barSet->floatingValuePen()); |
|
164 | value->setPen(barSet->floatingValuePen()); | |
152 |
|
|
165 | ||
153 | if (mSeries->valueAt(set,category) != 0) { |
|
166 | if (mSeries->valueAt(set,category) != 0) { | |
154 | value->setValueString(QString::number(mSeries->valueAt(set,category))); |
|
167 | value->setValueString(QString::number(mSeries->valueAt(set,category))); | |
155 | } else { |
|
168 | } else { | |
156 | value->setValueString(QString("")); |
|
169 | value->setValueString(QString("")); | |
157 | } |
|
170 | } | |
158 |
|
|
171 | ||
159 | itemIndex++; |
|
172 | itemIndex++; | |
160 | xPos += barWidth; |
|
173 | xPos += barWidth; | |
161 | } |
|
174 | } | |
162 | } |
|
175 | } | |
163 | update(); |
|
176 | // update(); | |
164 |
|
|
177 | } | |
165 |
|
178 | */ | ||
166 |
|
|
179 | QVector<QRectF> BarChartItem::calculateLayout() | |
167 | { |
|
180 | { | |
|
181 | // layoutChanged(); | |||
|
182 | /* | |||
168 | BarLayout layout; |
|
183 | BarLayout layout; | |
169 | foreach(Bar* bar, mBars) { |
|
184 | foreach(Bar* bar, mBars) { | |
170 | layout.insert(bar,bar->boundingRect()); |
|
185 | layout.insert(bar,bar->boundingRect()); | |
171 | } |
|
186 | } | |
|
187 | */ | |||
|
188 | QVector<QRectF> layout; | |||
|
189 | ||||
|
190 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |||
|
191 | int categoryCount = mSeries->categoryCount(); | |||
|
192 | int setCount = mSeries->barsetCount(); | |||
|
193 | ||||
|
194 | qreal tW = mWidth; | |||
|
195 | qreal tH = mHeight; | |||
|
196 | qreal tM = mSeries->max(); | |||
|
197 | ||||
|
198 | // Domain: | |||
|
199 | if (mDomainMaxY > tM) { | |||
|
200 | tM = mDomainMaxY; | |||
|
201 | } | |||
|
202 | ||||
|
203 | qreal scale = (tH/tM); | |||
|
204 | qreal tC = categoryCount + 1; | |||
|
205 | qreal categoryWidth = tW/tC; | |||
|
206 | mBarWidth = categoryWidth / (setCount+1); | |||
|
207 | ||||
|
208 | int itemIndex(0); | |||
|
209 | for (int category=0; category < categoryCount; category++) { | |||
|
210 | qreal xPos = categoryWidth * category + categoryWidth /2 + mBarWidth/2; | |||
|
211 | qreal yPos = mHeight; | |||
|
212 | for (int set = 0; set < setCount; set++) { | |||
|
213 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |||
|
214 | Bar* bar = mBars.at(itemIndex); | |||
|
215 | ||||
|
216 | QRectF rect(xPos,yPos-barHeight,mBarWidth,barHeight); | |||
|
217 | //layout.insert(bar,rect); | |||
|
218 | layout.append(rect); | |||
|
219 | // TODO: width settable per bar? | |||
|
220 | // bar->resize(mBarWidth, barHeight); | |||
|
221 | // layout.insert(bar,QSizeF(mBarWidth,barHeight)); | |||
|
222 | bar->setPen(mSeries->barsetAt(set)->pen()); | |||
|
223 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |||
|
224 | // bar->setPos(xPos, yPos-barHeight); | |||
|
225 | itemIndex++; | |||
|
226 | xPos += mBarWidth; | |||
|
227 | } | |||
|
228 | } | |||
|
229 | ||||
|
230 | // Position floating values | |||
|
231 | itemIndex = 0; | |||
|
232 | for (int category=0; category < mSeries->categoryCount(); category++) { | |||
|
233 | qreal xPos = categoryWidth * category + categoryWidth/2 + mBarWidth; | |||
|
234 | qreal yPos = mHeight; | |||
|
235 | for (int set=0; set < mSeries->barsetCount(); set++) { | |||
|
236 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |||
|
237 | BarValue* value = mFloatingValues.at(itemIndex); | |||
|
238 | ||||
|
239 | QBarSet* barSet = mSeries->barsetAt(set); | |||
|
240 | value->resize(100,50); // TODO: proper layout for this. | |||
|
241 | value->setPos(xPos, yPos-barHeight/2); | |||
|
242 | value->setPen(barSet->floatingValuePen()); | |||
|
243 | ||||
|
244 | if (mSeries->valueAt(set,category) != 0) { | |||
|
245 | value->setValueString(QString::number(mSeries->valueAt(set,category))); | |||
|
246 | } else { | |||
|
247 | value->setValueString(QString("")); | |||
|
248 | } | |||
|
249 | ||||
|
250 | itemIndex++; | |||
|
251 | xPos += mBarWidth; | |||
|
252 | } | |||
|
253 | } | |||
172 |
|
254 | |||
173 | return layout; |
|
255 | return layout; | |
174 | } |
|
256 | } | |
175 |
|
257 | |||
176 |
void BarChartItem::applyLayout(const |
|
258 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
177 | { |
|
259 | { | |
178 | if (animator()) |
|
260 | if (animator()) | |
179 | animator()->updateLayout(this, layout); |
|
261 | animator()->updateLayout(this, mLayout, layout); | |
180 | else |
|
262 | else | |
181 | setLayout(layout); |
|
263 | setLayout(layout); | |
182 | } |
|
264 | } | |
183 |
|
265 | |||
184 |
void BarChartItem::setLayout(const |
|
266 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
185 | { |
|
267 | { | |
186 | foreach (Bar *bar, layout.keys()) { |
|
268 | mLayout = layout; | |
187 | bar->setRect(layout.value(bar)); |
|
269 | ||
|
270 | for (int i=0; i<mBars.count(); i++) { | |||
|
271 | //mBars.at(i)->setSize(layout.at(i).size()); | |||
|
272 | //mBars.at(i)->setPos(layout.at(i).topLeft()); | |||
|
273 | mBars.at(i)->setRect(layout.at(i)); | |||
188 | } |
|
274 | } | |
|
275 | ||||
189 | update(); |
|
276 | update(); | |
190 | } |
|
277 | } | |
191 |
|
278 | |||
192 | void BarChartItem::initAxisLabels() |
|
279 | void BarChartItem::initAxisLabels() | |
193 | { |
|
280 | { | |
194 | int count = mSeries->categoryCount(); |
|
281 | int count = mSeries->categoryCount(); | |
195 | if (0 == count) { |
|
282 | if (0 == count) { | |
196 | return; |
|
283 | return; | |
197 | } |
|
284 | } | |
198 |
|
285 | |||
199 | Domain* domain = presenter()->dataSet()->domain(mSeries); |
|
286 | Domain* domain = presenter()->dataSet()->domain(mSeries); | |
200 |
|
287 | |||
201 | qreal min = 0; |
|
288 | qreal min = 0; | |
202 | qreal max = count+1; |
|
289 | qreal max = count+1; | |
203 |
|
290 | |||
204 | domain->setRangeX(min,max,count+1); |
|
291 | domain->setRangeX(min,max,count+1); | |
205 | } |
|
292 | } | |
206 |
|
293 | |||
207 | //handlers |
|
294 | //handlers | |
208 |
|
295 | |||
209 | void BarChartItem::handleModelChanged(int index) |
|
296 | void BarChartItem::handleModelChanged(int index) | |
210 | { |
|
297 | { | |
211 | Q_UNUSED(index) |
|
298 | Q_UNUSED(index) | |
212 | dataChanged(); |
|
299 | dataChanged(); | |
213 | } |
|
300 | } | |
214 |
|
301 | |||
215 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
302 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
216 | { |
|
303 | { | |
217 | mDomainMinX = minX; |
|
304 | mDomainMinX = minX; | |
218 | mDomainMaxX = maxX; |
|
305 | mDomainMaxX = maxX; | |
219 | mDomainMinY = minY; |
|
306 | mDomainMinY = minY; | |
220 | mDomainMaxY = maxY; |
|
307 | mDomainMaxY = maxY; | |
221 | layoutChanged(); |
|
308 | handleLayoutChanged(); | |
222 |
|
309 | |||
223 | /* |
|
310 | /* | |
224 | int count = mSeries->categoryCount(); |
|
311 | int count = mSeries->categoryCount(); | |
225 | if (0 == count) { |
|
312 | if (0 == count) { | |
226 | return; |
|
313 | return; | |
227 | } |
|
314 | } | |
228 |
|
315 | |||
229 | // Position labels to domain |
|
316 | // Position labels to domain | |
230 | qreal min = domain.minX(); |
|
317 | qreal min = domain.minX(); | |
231 | qreal max = domain.maxX(); |
|
318 | qreal max = domain.maxX(); | |
232 | qreal step = (max-min)/count; |
|
319 | qreal step = (max-min)/count; | |
233 | QChartAxisCategories& categories = mChart->axisX()->categories(); |
|
320 | QChartAxisCategories& categories = mChart->axisX()->categories(); | |
234 | categories.clear(); |
|
321 | categories.clear(); | |
235 | for (int i=0; i<count; i++) { |
|
322 | for (int i=0; i<count; i++) { | |
236 | categories.insert(min,mSeries->categoryName(i)); |
|
323 | categories.insert(min,mSeries->categoryName(i)); | |
237 | min += step; |
|
324 | min += step; | |
238 | } |
|
325 | } | |
239 | */ |
|
326 | */ | |
240 | } |
|
327 | } | |
241 |
|
328 | |||
242 | void BarChartItem::handleGeometryChanged(const QRectF& rect) |
|
329 | void BarChartItem::handleGeometryChanged(const QRectF& rect) | |
243 | { |
|
330 | { | |
244 | m_rect=rect; |
|
331 | m_rect=rect; | |
245 | layoutChanged(); |
|
332 | layoutChanged(); | |
246 | mLayoutSet = true; |
|
333 | mLayoutSet = true; | |
247 | setPos(rect.topLeft()); |
|
334 | setPos(rect.topLeft()); | |
248 | } |
|
335 | } | |
249 |
|
336 | |||
250 | void BarChartItem::handleLayoutChanged() |
|
337 | void BarChartItem::handleLayoutChanged() | |
251 | { |
|
338 | { | |
252 | BarLayout layout = calculateLayout(); |
|
339 | qDebug() << "BarChartItem::handleLayoutChanged"; | |
|
340 | QVector<QRectF> layout = calculateLayout(); | |||
253 | applyLayout(layout); |
|
341 | applyLayout(layout); | |
254 | update(); |
|
342 | update(); | |
255 | } |
|
343 | } | |
256 |
|
344 | |||
257 |
|
345 | |||
258 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
346 | void BarChartItem::showToolTip(QPoint pos, QString tip) | |
259 | { |
|
347 | { | |
260 | // TODO: cool tooltip instead of default |
|
348 | // TODO: cool tooltip instead of default | |
261 | QToolTip::showText(pos,tip); |
|
349 | QToolTip::showText(pos,tip); | |
262 | } |
|
350 | } | |
263 |
|
351 | |||
264 | #include "moc_barchartitem_p.cpp" |
|
352 | #include "moc_barchartitem_p.cpp" | |
265 |
|
353 | |||
266 | QTCOMMERCIALCHART_END_NAMESPACE |
|
354 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,77 +1,79 | |||||
1 | #ifndef BARCHARTITEM_H |
|
1 | #ifndef BARCHARTITEM_H | |
2 | #define BARCHARTITEM_H |
|
2 | #define BARCHARTITEM_H | |
3 |
|
3 | |||
4 | #include "chartitem_p.h" |
|
4 | #include "chartitem_p.h" | |
5 | #include "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 | #include <QBrush> |
|
7 | #include <QBrush> | |
8 | #include <QGraphicsItem> |
|
8 | #include <QGraphicsItem> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class Bar; |
|
12 | class Bar; | |
13 | class BarValue; |
|
13 | class BarValue; | |
14 | class QChartAxisCategories; |
|
14 | class QChartAxisCategories; | |
15 | class QChart; |
|
15 | class QChart; | |
16 |
|
16 | |||
17 |
typedef Q |
|
17 | //typedef QVector<QRectF> BarLayout; | |
18 |
|
18 | |||
19 | class BarChartItem : public ChartItem |
|
19 | class BarChartItem : public ChartItem | |
20 | { |
|
20 | { | |
21 | Q_OBJECT |
|
21 | Q_OBJECT | |
22 | public: |
|
22 | public: | |
23 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
23 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
24 | virtual ~BarChartItem(); |
|
24 | virtual ~BarChartItem(); | |
25 |
|
25 | |||
26 | // Common implemantation of different presenters. Not to be instantiated. |
|
26 | // Common implemantation of different presenters. Not to be instantiated. | |
27 | // TODO: combine this with BarPresenter and derive other presenters from it? |
|
27 | // TODO: combine this with BarPresenter and derive other presenters from it? | |
28 |
|
28 | |||
29 | public: |
|
29 | public: | |
30 | // From QGraphicsItem |
|
30 | // From QGraphicsItem | |
31 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
31 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
32 | QRectF boundingRect() const; |
|
32 | QRectF boundingRect() const; | |
33 |
|
33 | |||
34 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
34 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it | |
35 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
35 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
36 | private slots: |
|
36 | private slots: | |
37 | virtual void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
37 | //virtual void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 |
|
|
40 | QVector<QRectF> calculateLayout(); | |
41 |
void applyLayout(const |
|
41 | void applyLayout(const QVector<QRectF> &layout); | |
42 |
void setLayout(const |
|
42 | void setLayout(const QVector<QRectF> &layout); | |
|
43 | void updateLayout(const QVector<QRectF> &layout); | |||
43 |
|
44 | |||
44 | QRectF geometry() const { return m_rect;} |
|
45 | QRectF geometry() const { return m_rect;} | |
45 |
|
46 | |||
46 | protected: |
|
47 | protected: | |
47 | void initAxisLabels(); |
|
48 | void initAxisLabels(); | |
48 |
|
49 | |||
49 | public slots: |
|
50 | public slots: | |
50 | void handleModelChanged(int index); |
|
51 | void handleModelChanged(int index); | |
51 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
52 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
52 | void handleGeometryChanged(const QRectF& size); |
|
53 | void handleGeometryChanged(const QRectF& size); | |
53 | void handleLayoutChanged(); |
|
54 | void handleLayoutChanged(); | |
54 |
|
55 | |||
55 | // Internal slots |
|
56 | // Internal slots | |
56 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) |
|
57 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) | |
57 |
|
58 | |||
58 | protected: |
|
59 | protected: | |
59 |
|
60 | |||
60 | // TODO: consider these. |
|
61 | // TODO: consider these. | |
61 | qreal mDomainMinX; |
|
62 | qreal mDomainMinX; | |
62 | qreal mDomainMaxX; |
|
63 | qreal mDomainMaxX; | |
63 | qreal mDomainMinY; |
|
64 | qreal mDomainMinY; | |
64 | qreal mDomainMaxY; |
|
65 | qreal mDomainMaxY; | |
65 |
|
66 | |||
66 | QRectF m_rect; |
|
67 | QRectF m_rect; | |
67 | bool mLayoutSet; // True, if component has been laid out. |
|
68 | bool mLayoutSet; // True, if component has been laid out. | |
|
69 | QVector<QRectF> mLayout; | |||
68 |
|
70 | |||
69 | // Not owned. |
|
71 | // Not owned. | |
70 | QBarSeries* mSeries; |
|
72 | QBarSeries* mSeries; | |
71 | QList<Bar*> mBars; |
|
73 | QList<Bar*> mBars; | |
72 | QList<BarValue*> mFloatingValues; |
|
74 | QList<BarValue*> mFloatingValues; | |
73 | }; |
|
75 | }; | |
74 |
|
76 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE | |
76 |
|
78 | |||
77 | #endif // BARCHARTITEM_H |
|
79 | #endif // BARCHARTITEM_H |
@@ -1,368 +1,371 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "qbarseries.h" |
|
2 | #include "qbarseries.h" | |
3 | #include "qbarset.h" |
|
3 | #include "qbarset.h" | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | /*! |
|
8 | /*! | |
9 | \class QBarSeries |
|
9 | \class QBarSeries | |
10 | \brief part of QtCommercial chart API. |
|
10 | \brief part of QtCommercial chart API. | |
11 |
|
11 | |||
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
14 | by QStringList. |
|
14 | by QStringList. | |
15 |
|
15 | |||
16 | \mainclass |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \fn virtual QSeriesType QBarSeries::type() const |
|
22 | \fn virtual QSeriesType QBarSeries::type() const | |
23 | \brief Returns type of series. |
|
23 | \brief Returns type of series. | |
24 | \sa QSeries, QSeriesType |
|
24 | \sa QSeries, QSeriesType | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
29 | \brief \internal \a pos \a tip |
|
29 | \brief \internal \a pos \a tip | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
34 | QBarSeries is QObject which is a child of a \a parent. |
|
34 | QBarSeries is QObject which is a child of a \a parent. | |
35 | */ |
|
35 | */ | |
36 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) |
|
36 | QBarSeries::QBarSeries(QStringList categories, QObject *parent) | |
37 | : QSeries(parent) |
|
37 | : QSeries(parent) | |
38 | ,mModel(new BarChartModel(categories, this)) |
|
38 | ,mModel(new BarChartModel(categories, this)) | |
39 | { |
|
39 | { | |
40 | m_model = NULL; |
|
40 | m_model = NULL; | |
41 | m_mapCategories = -1; |
|
41 | m_mapCategories = -1; | |
42 | m_mapBarBottom = -1; |
|
42 | m_mapBarBottom = -1; | |
43 | m_mapBarTop = -1; |
|
43 | m_mapBarTop = -1; | |
44 | m_mapOrientation = Qt::Vertical; |
|
44 | m_mapOrientation = Qt::Vertical; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | Adds a set of bars to series. Takes ownership of \a set. |
|
48 | Adds a set of bars to series. Takes ownership of \a set. | |
49 | Connects the clicked(QString) and rightClicked(QString) signals |
|
49 | Connects the clicked(QString) and rightClicked(QString) signals | |
50 | of \a set to this series |
|
50 | of \a set to this series | |
51 | */ |
|
51 | */ | |
52 | void QBarSeries::addBarSet(QBarSet *set) |
|
52 | void QBarSeries::addBarSet(QBarSet *set) | |
53 | { |
|
53 | { | |
|
54 | qDebug() << "add bar set"; | |||
54 | mModel->addBarSet(set); |
|
55 | mModel->addBarSet(set); | |
55 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
56 | connect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
56 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
57 | connect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
57 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
58 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
|
59 | emit updatedBars(); | |||
58 | } |
|
60 | } | |
59 |
|
61 | |||
60 | /*! |
|
62 | /*! | |
61 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
63 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
62 | Disconnects the clicked(QString) and rightClicked(QString) signals |
|
64 | Disconnects the clicked(QString) and rightClicked(QString) signals | |
63 | of \a set from this series |
|
65 | of \a set from this series | |
64 | */ |
|
66 | */ | |
65 | void QBarSeries::removeBarSet(QBarSet *set) |
|
67 | void QBarSeries::removeBarSet(QBarSet *set) | |
66 | { |
|
68 | { | |
67 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); |
|
69 | disconnect(set,SIGNAL(clicked(QString)),this,SLOT(barsetClicked(QString))); | |
68 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); |
|
70 | disconnect(set,SIGNAL(rightClicked(QString)),this,SLOT(barsetRightClicked(QString))); | |
69 | mModel->removeBarSet(set); |
|
71 | mModel->removeBarSet(set); | |
|
72 | emit updatedBars(); | |||
70 | } |
|
73 | } | |
71 |
|
74 | |||
72 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
75 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
73 | { |
|
76 | { | |
74 | mModel->insertBarSet(i, set); |
|
77 | mModel->insertBarSet(i, set); | |
75 | // emit barsetChanged(); |
|
78 | // emit barsetChanged(); | |
76 | } |
|
79 | } | |
77 |
|
80 | |||
78 | void QBarSeries::insertCategory(int i, QString category) |
|
81 | void QBarSeries::insertCategory(int i, QString category) | |
79 | { |
|
82 | { | |
80 | mModel->insertCategory(i, category); |
|
83 | mModel->insertCategory(i, category); | |
81 | } |
|
84 | } | |
82 |
|
85 | |||
83 | void QBarSeries::removeCategory(int i) |
|
86 | void QBarSeries::removeCategory(int i) | |
84 | { |
|
87 | { | |
85 | mModel->removeCategory(i); |
|
88 | mModel->removeCategory(i); | |
86 | } |
|
89 | } | |
87 |
|
90 | |||
88 | /*! |
|
91 | /*! | |
89 | Returns number of sets in series. |
|
92 | Returns number of sets in series. | |
90 | */ |
|
93 | */ | |
91 | int QBarSeries::barsetCount() |
|
94 | int QBarSeries::barsetCount() | |
92 | { |
|
95 | { | |
93 | // if(m_model) |
|
96 | // if(m_model) | |
94 | // return m_mapBarTop - m_mapBarBottom; |
|
97 | // return m_mapBarTop - m_mapBarBottom; | |
95 | // else |
|
98 | // else | |
96 | return mModel->barsetCount(); |
|
99 | return mModel->barsetCount(); | |
97 | } |
|
100 | } | |
98 |
|
101 | |||
99 | /*! |
|
102 | /*! | |
100 | Returns number of categories in series |
|
103 | Returns number of categories in series | |
101 | */ |
|
104 | */ | |
102 | int QBarSeries::categoryCount() |
|
105 | int QBarSeries::categoryCount() | |
103 | { |
|
106 | { | |
104 | return mModel->categoryCount(); |
|
107 | return mModel->categoryCount(); | |
105 | } |
|
108 | } | |
106 |
|
109 | |||
107 | /*! |
|
110 | /*! | |
108 | Returns a list of sets in series. Keeps ownership of sets. |
|
111 | Returns a list of sets in series. Keeps ownership of sets. | |
109 | */ |
|
112 | */ | |
110 | QList<QBarSet*> QBarSeries::barSets() |
|
113 | QList<QBarSet*> QBarSeries::barSets() | |
111 | { |
|
114 | { | |
112 | return mModel->barSets(); |
|
115 | return mModel->barSets(); | |
113 | } |
|
116 | } | |
114 |
|
117 | |||
115 | /*! |
|
118 | /*! | |
116 | \internal \a index |
|
119 | \internal \a index | |
117 | */ |
|
120 | */ | |
118 | QBarSet* QBarSeries::barsetAt(int index) |
|
121 | QBarSet* QBarSeries::barsetAt(int index) | |
119 | { |
|
122 | { | |
120 | return mModel->setAt(index); |
|
123 | return mModel->setAt(index); | |
121 | } |
|
124 | } | |
122 |
|
125 | |||
123 | /*! |
|
126 | /*! | |
124 | \internal \a category |
|
127 | \internal \a category | |
125 | */ |
|
128 | */ | |
126 | QString QBarSeries::categoryName(int category) |
|
129 | QString QBarSeries::categoryName(int category) | |
127 | { |
|
130 | { | |
128 | return mModel->categoryName(category); |
|
131 | return mModel->categoryName(category); | |
129 | } |
|
132 | } | |
130 |
|
133 | |||
131 | /*! |
|
134 | /*! | |
132 | Enables or disables tooltip depending on parameter \a enabled. |
|
135 | Enables or disables tooltip depending on parameter \a enabled. | |
133 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
136 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
134 | Calling without parameter \a enabled, enables the tooltip |
|
137 | Calling without parameter \a enabled, enables the tooltip | |
135 | */ |
|
138 | */ | |
136 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
139 | void QBarSeries::setToolTipEnabled(bool enabled) | |
137 | { |
|
140 | { | |
138 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
141 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
139 | if (enabled) { |
|
142 | if (enabled) { | |
140 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
143 | for (int i=0; i<mModel->barsetCount(); i++) { | |
141 | QBarSet *set = mModel->setAt(i); |
|
144 | QBarSet *set = mModel->setAt(i); | |
142 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
145 | connect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
143 | } |
|
146 | } | |
144 | } else { |
|
147 | } else { | |
145 | for (int i=0; i<mModel->barsetCount(); i++) { |
|
148 | for (int i=0; i<mModel->barsetCount(); i++) { | |
146 | QBarSet *set = mModel->setAt(i); |
|
149 | QBarSet *set = mModel->setAt(i); | |
147 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); |
|
150 | disconnect(set,SIGNAL(showToolTip(QPoint,QString)),this,SIGNAL(showToolTip(QPoint,QString))); | |
148 | } |
|
151 | } | |
149 | } |
|
152 | } | |
150 | } |
|
153 | } | |
151 |
|
154 | |||
152 |
|
155 | |||
153 | /*! |
|
156 | /*! | |
154 | \internal \a category |
|
157 | \internal \a category | |
155 | */ |
|
158 | */ | |
156 | void QBarSeries::barsetClicked(QString category) |
|
159 | void QBarSeries::barsetClicked(QString category) | |
157 | { |
|
160 | { | |
158 | emit clicked(qobject_cast<QBarSet*>(sender()), category); |
|
161 | emit clicked(qobject_cast<QBarSet*>(sender()), category); | |
159 | } |
|
162 | } | |
160 |
|
163 | |||
161 | /*! |
|
164 | /*! | |
162 | \internal \a category |
|
165 | \internal \a category | |
163 | */ |
|
166 | */ | |
164 | void QBarSeries::barsetRightClicked(QString category) |
|
167 | void QBarSeries::barsetRightClicked(QString category) | |
165 | { |
|
168 | { | |
166 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); |
|
169 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); | |
167 | } |
|
170 | } | |
168 |
|
171 | |||
169 |
|
172 | |||
170 | /*! |
|
173 | /*! | |
171 | \internal |
|
174 | \internal | |
172 | */ |
|
175 | */ | |
173 | qreal QBarSeries::min() |
|
176 | qreal QBarSeries::min() | |
174 | { |
|
177 | { | |
175 | return mModel->min(); |
|
178 | return mModel->min(); | |
176 | } |
|
179 | } | |
177 |
|
180 | |||
178 | /*! |
|
181 | /*! | |
179 | \internal |
|
182 | \internal | |
180 | */ |
|
183 | */ | |
181 | qreal QBarSeries::max() |
|
184 | qreal QBarSeries::max() | |
182 | { |
|
185 | { | |
183 | return mModel->max(); |
|
186 | return mModel->max(); | |
184 | } |
|
187 | } | |
185 |
|
188 | |||
186 | /*! |
|
189 | /*! | |
187 | \internal \a set \a category |
|
190 | \internal \a set \a category | |
188 | */ |
|
191 | */ | |
189 | qreal QBarSeries::valueAt(int set, int category) |
|
192 | qreal QBarSeries::valueAt(int set, int category) | |
190 | { |
|
193 | { | |
191 | return mModel->valueAt(set,category); |
|
194 | return mModel->valueAt(set,category); | |
192 | } |
|
195 | } | |
193 |
|
196 | |||
194 | /*! |
|
197 | /*! | |
195 | \internal \a set \a category |
|
198 | \internal \a set \a category | |
196 | */ |
|
199 | */ | |
197 | qreal QBarSeries::percentageAt(int set, int category) |
|
200 | qreal QBarSeries::percentageAt(int set, int category) | |
198 | { |
|
201 | { | |
199 | return mModel->percentageAt(set,category); |
|
202 | return mModel->percentageAt(set,category); | |
200 | } |
|
203 | } | |
201 |
|
204 | |||
202 | /*! |
|
205 | /*! | |
203 | \internal \a category |
|
206 | \internal \a category | |
204 | */ |
|
207 | */ | |
205 | qreal QBarSeries::categorySum(int category) |
|
208 | qreal QBarSeries::categorySum(int category) | |
206 | { |
|
209 | { | |
207 | return mModel->categorySum(category); |
|
210 | return mModel->categorySum(category); | |
208 | } |
|
211 | } | |
209 |
|
212 | |||
210 | /*! |
|
213 | /*! | |
211 | \internal |
|
214 | \internal | |
212 | */ |
|
215 | */ | |
213 | qreal QBarSeries::maxCategorySum() |
|
216 | qreal QBarSeries::maxCategorySum() | |
214 | { |
|
217 | { | |
215 | return mModel->maxCategorySum(); |
|
218 | return mModel->maxCategorySum(); | |
216 | } |
|
219 | } | |
217 |
|
220 | |||
218 | /*! |
|
221 | /*! | |
219 | \internal |
|
222 | \internal | |
220 | */ |
|
223 | */ | |
221 | BarChartModel& QBarSeries::model() |
|
224 | BarChartModel& QBarSeries::model() | |
222 | { |
|
225 | { | |
223 | return *mModel; |
|
226 | return *mModel; | |
224 | } |
|
227 | } | |
225 |
|
228 | |||
226 | bool QBarSeries::setModel(QAbstractItemModel* model) |
|
229 | bool QBarSeries::setModel(QAbstractItemModel* model) | |
227 | { |
|
230 | { | |
228 | // disconnect signals from old model |
|
231 | // disconnect signals from old model | |
229 | if(m_model) |
|
232 | if(m_model) | |
230 | { |
|
233 | { | |
231 | disconnect(m_model, 0, this, 0); |
|
234 | disconnect(m_model, 0, this, 0); | |
232 | m_mapCategories = -1; |
|
235 | m_mapCategories = -1; | |
233 | m_mapBarBottom = -1; |
|
236 | m_mapBarBottom = -1; | |
234 | m_mapBarTop = -1; |
|
237 | m_mapBarTop = -1; | |
235 | m_mapOrientation = Qt::Vertical; |
|
238 | m_mapOrientation = Qt::Vertical; | |
236 | } |
|
239 | } | |
237 |
|
240 | |||
238 | // set new model |
|
241 | // set new model | |
239 | if(model) |
|
242 | if(model) | |
240 | { |
|
243 | { | |
241 | m_model = model; |
|
244 | m_model = model; | |
242 | return true; |
|
245 | return true; | |
243 | } |
|
246 | } | |
244 | else |
|
247 | else | |
245 | { |
|
248 | { | |
246 | m_model = NULL; |
|
249 | m_model = NULL; | |
247 | return false; |
|
250 | return false; | |
248 | } |
|
251 | } | |
249 | } |
|
252 | } | |
250 |
|
253 | |||
251 | // TODO |
|
254 | // TODO | |
252 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
255 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
253 | { |
|
256 | { | |
254 | if (m_model == NULL) |
|
257 | if (m_model == NULL) | |
255 | return; |
|
258 | return; | |
256 | m_mapCategories = categories; |
|
259 | m_mapCategories = categories; | |
257 | m_mapBarBottom = bottomBoundry; |
|
260 | m_mapBarBottom = bottomBoundry; | |
258 | m_mapBarTop = topBoundry; |
|
261 | m_mapBarTop = topBoundry; | |
259 | m_mapOrientation = orientation; |
|
262 | m_mapOrientation = orientation; | |
260 |
|
263 | |||
261 | // connect the signals |
|
264 | // connect the signals | |
262 | if (m_mapOrientation == Qt::Vertical) |
|
265 | if (m_mapOrientation == Qt::Vertical) | |
263 | { |
|
266 | { | |
264 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
267 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
265 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
268 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
266 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
269 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
267 | } |
|
270 | } | |
268 | else |
|
271 | else | |
269 | { |
|
272 | { | |
270 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
273 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
271 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
274 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
272 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
275 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
273 | } |
|
276 | } | |
274 |
|
277 | |||
275 |
|
278 | |||
276 | // create the initial bars |
|
279 | // create the initial bars | |
277 | delete mModel; |
|
280 | delete mModel; | |
278 | if (m_mapOrientation == Qt::Vertical) |
|
281 | if (m_mapOrientation == Qt::Vertical) | |
279 | { |
|
282 | { | |
280 | QStringList categories; |
|
283 | QStringList categories; | |
281 | for (int k = 0; k < m_model->rowCount(); k++) |
|
284 | for (int k = 0; k < m_model->rowCount(); k++) | |
282 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
285 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
283 | mModel = new BarChartModel(categories, this); |
|
286 | mModel = new BarChartModel(categories, this); | |
284 |
|
287 | |||
285 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
288 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
286 | { |
|
289 | { | |
287 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
290 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
288 | for(int m = 0; m < m_model->rowCount(); m++) |
|
291 | for(int m = 0; m < m_model->rowCount(); m++) | |
289 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
292 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
290 | addBarSet(barSet); |
|
293 | addBarSet(barSet); | |
291 | } |
|
294 | } | |
292 | } |
|
295 | } | |
293 | else |
|
296 | else | |
294 | { |
|
297 | { | |
295 | QStringList categories; |
|
298 | QStringList categories; | |
296 | for (int k = 0; k < m_model->columnCount(); k++) |
|
299 | for (int k = 0; k < m_model->columnCount(); k++) | |
297 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
300 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
298 | mModel = new BarChartModel(categories, this); |
|
301 | mModel = new BarChartModel(categories, this); | |
299 |
|
302 | |||
300 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) |
|
303 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) | |
301 | { |
|
304 | { | |
302 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
305 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
303 | for(int m = 0; m < m_model->columnCount(); m++) |
|
306 | for(int m = 0; m < m_model->columnCount(); m++) | |
304 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
307 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
305 | addBarSet(barSet); |
|
308 | addBarSet(barSet); | |
306 | } |
|
309 | } | |
307 | } |
|
310 | } | |
308 | } |
|
311 | } | |
309 |
|
312 | |||
310 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
313 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
311 | { |
|
314 | { | |
312 | Q_UNUSED(bottomRight) |
|
315 | Q_UNUSED(bottomRight) | |
313 |
|
316 | |||
314 | if (m_mapOrientation == Qt::Vertical) |
|
317 | if (m_mapOrientation == Qt::Vertical) | |
315 | { |
|
318 | { | |
316 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) |
|
319 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop) | |
317 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
320 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
318 | // else if (topLeft.column() == m_mapCategories) |
|
321 | // else if (topLeft.column() == m_mapCategories) | |
319 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
322 | // slices().at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
320 | } |
|
323 | } | |
321 | else |
|
324 | else | |
322 | { |
|
325 | { | |
323 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) |
|
326 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop) | |
324 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
327 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
325 | // else if (topLeft.row() == m_mapCategories) |
|
328 | // else if (topLeft.row() == m_mapCategories) | |
326 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
329 | // slices().at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
327 | } |
|
330 | } | |
328 | } |
|
331 | } | |
329 |
|
332 | |||
330 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
333 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
331 | { |
|
334 | { | |
332 | if (m_mapOrientation == Qt::Vertical) |
|
335 | if (m_mapOrientation == Qt::Vertical) | |
333 | { |
|
336 | { | |
334 | insertCategory(start, QString("Row: %1").arg(start + 1)); |
|
337 | insertCategory(start, QString("Row: %1").arg(start + 1)); | |
335 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
338 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
336 | { |
|
339 | { | |
337 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
340 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
338 | } |
|
341 | } | |
339 | } |
|
342 | } | |
340 | else |
|
343 | else | |
341 | { |
|
344 | { | |
342 | insertCategory(start, QString("Column: %1").arg(start + 1)); |
|
345 | insertCategory(start, QString("Column: %1").arg(start + 1)); | |
343 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
346 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
344 | { |
|
347 | { | |
345 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
348 | barsetAt(i)->insertValue(start, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
346 | } |
|
349 | } | |
347 | } |
|
350 | } | |
348 | emit restructuredBar(1); |
|
351 | emit restructuredBar(1); | |
349 | } |
|
352 | } | |
350 |
|
353 | |||
351 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int start, int /*end*/) |
|
354 | void QBarSeries::modelDataRemoved(QModelIndex /*parent*/, int start, int /*end*/) | |
352 | { |
|
355 | { | |
353 | removeCategory(start); |
|
356 | removeCategory(start); | |
354 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
357 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
355 | { |
|
358 | { | |
356 | barsetAt(i)->removeValue(start); |
|
359 | barsetAt(i)->removeValue(start); | |
357 | } |
|
360 | } | |
358 | emit restructuredBar(1); |
|
361 | emit restructuredBar(1); | |
359 | } |
|
362 | } | |
360 |
|
363 | |||
361 | void QBarSeries::barsetChanged() |
|
364 | void QBarSeries::barsetChanged() | |
362 | { |
|
365 | { | |
363 | emit updatedBars(); |
|
366 | emit updatedBars(); | |
364 | } |
|
367 | } | |
365 |
|
368 | |||
366 | #include "moc_qbarseries.cpp" |
|
369 | #include "moc_qbarseries.cpp" | |
367 |
|
370 | |||
368 | QTCOMMERCIALCHART_END_NAMESPACE |
|
371 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now