@@ -0,0 +1,49 | |||||
|
1 | #include "baranimation_p.h" | |||
|
2 | #include "barchartitem_p.h" | |||
|
3 | #include <QParallelAnimationGroup> | |||
|
4 | #include <QTimer> | |||
|
5 | ||||
|
6 | Q_DECLARE_METATYPE(QVector<QSizeF>) | |||
|
7 | ||||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
9 | ||||
|
10 | BarAnimation::BarAnimation(BarChartItem *item) | |||
|
11 | :ChartAnimation(item), | |||
|
12 | m_item(item) | |||
|
13 | { | |||
|
14 | } | |||
|
15 | ||||
|
16 | BarAnimation::~BarAnimation() | |||
|
17 | { | |||
|
18 | } | |||
|
19 | ||||
|
20 | void BarAnimation::updateValues(const BarLayout& layout) | |||
|
21 | { | |||
|
22 | // TODO: | |||
|
23 | qDebug() << "BarAnimation::updateValues"; | |||
|
24 | } | |||
|
25 | ||||
|
26 | ||||
|
27 | QVariant BarAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | |||
|
28 | { | |||
|
29 | QVector<QSizeF> startVector = qVariantValue<QVector<QSizeF> > (from); | |||
|
30 | QVector<QSizeF> endVector = qVariantValue<QVector<QSizeF> > (to); | |||
|
31 | QVector<QSizeF> result; | |||
|
32 | ||||
|
33 | Q_ASSERT(startVector.count() == endVector.count()) ; | |||
|
34 | ||||
|
35 | for(int i =0 ;i< startVector.count();i++){ | |||
|
36 | QSizeF value = startVector[i] + ((endVector[i]- endVector[i]) * progress); | |||
|
37 | result << value; | |||
|
38 | } | |||
|
39 | return qVariantFromValue(result); | |||
|
40 | } | |||
|
41 | ||||
|
42 | void BarAnimation::updateCurrentValue(const QVariant &) | |||
|
43 | { | |||
|
44 | // TODO? | |||
|
45 | } | |||
|
46 | ||||
|
47 | #include "moc_baranimation_p.cpp" | |||
|
48 | ||||
|
49 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,36 | |||||
|
1 | #ifndef BARANIMATION_P_H_ | |||
|
2 | #define BARANIMATION_P_H_ | |||
|
3 | ||||
|
4 | #include "chartanimation_p.h" | |||
|
5 | #include "barchartitem_p.h" | |||
|
6 | ||||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
8 | ||||
|
9 | class BarChartItem; | |||
|
10 | class QBarSet; | |||
|
11 | class BarSetAnimation; | |||
|
12 | ||||
|
13 | class BarAnimation : public ChartAnimation | |||
|
14 | { | |||
|
15 | Q_OBJECT | |||
|
16 | ||||
|
17 | public: | |||
|
18 | BarAnimation(BarChartItem *item); | |||
|
19 | ~BarAnimation(); | |||
|
20 | ||||
|
21 | void updateValues(const BarLayout& layout); | |||
|
22 | ||||
|
23 | public: // from QVariantAnimation | |||
|
24 | virtual QVariant interpolated (const QVariant & from, const QVariant & to, qreal progress ) const; | |||
|
25 | virtual void updateCurrentValue (const QVariant & value ); | |||
|
26 | ||||
|
27 | public Q_SLOTS: | |||
|
28 | ||||
|
29 | private: | |||
|
30 | BarChartItem *m_item; | |||
|
31 | QHash<QBarSet*, BarSetAnimation*> m_animations; | |||
|
32 | }; | |||
|
33 | ||||
|
34 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
35 | ||||
|
36 | #endif |
@@ -7,7 +7,9 SOURCES += \ | |||||
7 | $$PWD/xyanimation.cpp \ |
|
7 | $$PWD/xyanimation.cpp \ | |
8 | $$PWD/pieanimation.cpp \ |
|
8 | $$PWD/pieanimation.cpp \ | |
9 | $$PWD/piesliceanimation.cpp \ |
|
9 | $$PWD/piesliceanimation.cpp \ | |
10 | $$PWD/splineanimation.cpp |
|
10 | $$PWD/splineanimation.cpp \ | |
|
11 | $$PWD/baranimation.cpp | |||
|
12 | ||||
11 |
|
13 | |||
12 |
|
14 | |||
13 | PRIVATE_HEADERS += \ |
|
15 | PRIVATE_HEADERS += \ | |
@@ -17,4 +19,6 PRIVATE_HEADERS += \ | |||||
17 | $$PWD/xyanimation_p.h \ |
|
19 | $$PWD/xyanimation_p.h \ | |
18 | $$PWD/pieanimation_p.h \ |
|
20 | $$PWD/pieanimation_p.h \ | |
19 | $$PWD/piesliceanimation_p.h \ |
|
21 | $$PWD/piesliceanimation_p.h \ | |
20 | $$PWD/splineanimation_p.h |
|
22 | $$PWD/splineanimation_p.h \ | |
|
23 | $$PWD/baranimation_p.h | |||
|
24 |
@@ -4,6 +4,8 | |||||
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" | |||
|
8 | #include "barchartitem_p.h" | |||
7 | #include "areachartitem_p.h" |
|
9 | #include "areachartitem_p.h" | |
8 | #include "splinechartitem_p.h" |
|
10 | #include "splinechartitem_p.h" | |
9 | #include "scatterchartitem_p.h" |
|
11 | #include "scatterchartitem_p.h" | |
@@ -84,6 +86,19 void ChartAnimator::addAnimation(PieChartItem* item) | |||||
84 | item->setAnimator(this); |
|
86 | item->setAnimator(this); | |
85 | } |
|
87 | } | |
86 |
|
88 | |||
|
89 | void ChartAnimator::addAnimation(BarChartItem* item) | |||
|
90 | { | |||
|
91 | ChartAnimation* animation = m_animations.value(item); | |||
|
92 | ||||
|
93 | if(!animation) { | |||
|
94 | animation = new BarAnimation(item); | |||
|
95 | m_animations.insert(item,animation); | |||
|
96 | } | |||
|
97 | ||||
|
98 | item->setAnimator(this); | |||
|
99 | } | |||
|
100 | ||||
|
101 | ||||
87 | void ChartAnimator::removeAnimation(ChartItem* item) |
|
102 | void ChartAnimator::removeAnimation(ChartItem* item) | |
88 | { |
|
103 | { | |
89 | item->setAnimator(0); |
|
104 | item->setAnimator(0); | |
@@ -252,6 +267,15 void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const Pie | |||||
252 | animation->updateValue(slice, sliceData); |
|
267 | animation->updateValue(slice, sliceData); | |
253 | } |
|
268 | } | |
254 |
|
269 | |||
|
270 | void ChartAnimator::updateLayout(BarChartItem* item, const BarLayout &layout) | |||
|
271 | { | |||
|
272 | qDebug() << "ChartAnimator::updateLayout"; | |||
|
273 | BarAnimation* animation = static_cast<BarAnimation*>(m_animations.value(item)); | |||
|
274 | Q_ASSERT(animation); | |||
|
275 | animation->updateValues(layout); | |||
|
276 | } | |||
|
277 | ||||
|
278 | ||||
255 | void ChartAnimator::setState(State state,const QPointF& point) |
|
279 | void ChartAnimator::setState(State state,const QPointF& point) | |
256 | { |
|
280 | { | |
257 | m_state=state; |
|
281 | m_state=state; |
@@ -3,6 +3,7 | |||||
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 <QPointF> |
|
7 | #include <QPointF> | |
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -28,6 +29,7 public: | |||||
28 | void addAnimation(ScatterChartItem* item); |
|
29 | void addAnimation(ScatterChartItem* item); | |
29 | void addAnimation(LineChartItem* item); |
|
30 | void addAnimation(LineChartItem* item); | |
30 | void addAnimation(SplineChartItem* item); |
|
31 | void addAnimation(SplineChartItem* item); | |
|
32 | void addAnimation(BarChartItem* item); | |||
31 | void removeAnimation(ChartItem* item); |
|
33 | void removeAnimation(ChartItem* item); | |
32 |
|
34 | |||
33 | void animationStarted(); |
|
35 | void animationStarted(); | |
@@ -40,6 +42,8 public: | |||||
40 | void updateLayout(PieChartItem* item, const PieLayout &layout); |
|
42 | void updateLayout(PieChartItem* item, const PieLayout &layout); | |
41 | void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData); |
|
43 | void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData); | |
42 |
|
44 | |||
|
45 | void updateLayout(BarChartItem* item, const BarLayout &layout); | |||
|
46 | ||||
43 | void setState(State state,const QPointF& point = QPointF()); |
|
47 | void setState(State state,const QPointF& point = QPointF()); | |
44 |
|
48 | |||
45 | private: |
|
49 | private: |
@@ -7,6 +7,7 | |||||
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 <QDebug> |
|
11 | #include <QDebug> | |
11 | #include <QToolTip> |
|
12 | #include <QToolTip> | |
12 |
|
13 | |||
@@ -22,6 +23,8 BarChartItem::BarChartItem(QBarSeries *series, QChart *parent) : | |||||
22 | { |
|
23 | { | |
23 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
24 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); | |
24 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); |
|
25 | connect(series, SIGNAL(updatedBars()), this, SLOT(layoutChanged())); | |
|
26 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); | |||
|
27 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |||
25 | setZValue(ChartPresenter::BarSeriesZValue); |
|
28 | setZValue(ChartPresenter::BarSeriesZValue); | |
26 | initAxisLabels(); |
|
29 | initAxisLabels(); | |
27 | dataChanged(); |
|
30 | dataChanged(); | |
@@ -157,6 +160,31 void BarChartItem::layoutChanged() | |||||
157 | update(); |
|
160 | update(); | |
158 | } |
|
161 | } | |
159 |
|
162 | |||
|
163 | BarLayout BarChartItem::calculateLayout() | |||
|
164 | { | |||
|
165 | BarLayout layout; | |||
|
166 | foreach(Bar* bar, mBars) { | |||
|
167 | layout.insert(bar,bar->boundingRect().size()); | |||
|
168 | } | |||
|
169 | ||||
|
170 | return layout; | |||
|
171 | } | |||
|
172 | ||||
|
173 | void BarChartItem::applyLayout(const BarLayout &layout) | |||
|
174 | { | |||
|
175 | if (m_animator) | |||
|
176 | m_animator->updateLayout(this, layout); | |||
|
177 | else | |||
|
178 | setLayout(layout); | |||
|
179 | } | |||
|
180 | ||||
|
181 | void BarChartItem::setLayout(const BarLayout &layout) | |||
|
182 | { | |||
|
183 | foreach (Bar *bar, layout.keys()) { | |||
|
184 | bar->setSize(layout.value(bar)); | |||
|
185 | } | |||
|
186 | update(); | |||
|
187 | } | |||
160 |
|
188 | |||
161 | void BarChartItem::initAxisLabels() |
|
189 | void BarChartItem::initAxisLabels() | |
162 | { |
|
190 | { | |
@@ -228,6 +256,14 void BarChartItem::handleGeometryChanged(const QRectF& rect) | |||||
228 | setPos(rect.topLeft()); |
|
256 | setPos(rect.topLeft()); | |
229 | } |
|
257 | } | |
230 |
|
258 | |||
|
259 | void BarChartItem::handleLayoutChanged() | |||
|
260 | { | |||
|
261 | BarLayout layout = calculateLayout(); | |||
|
262 | applyLayout(layout); | |||
|
263 | update(); | |||
|
264 | } | |||
|
265 | ||||
|
266 | ||||
231 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
267 | void BarChartItem::showToolTip(QPoint pos, QString tip) | |
232 | { |
|
268 | { | |
233 | // TODO: cool tooltip instead of default |
|
269 | // TODO: cool tooltip instead of default |
@@ -14,7 +14,8 class BarValue; | |||||
14 | class QChartAxisCategories; |
|
14 | class QChartAxisCategories; | |
15 | class QChart; |
|
15 | class QChart; | |
16 |
|
16 | |||
17 | // Common implemantation of different presenters. |
|
17 | typedef QHash<Bar*, QSizeF> BarLayout; | |
|
18 | ||||
18 | class BarChartItem : public QObject, public ChartItem |
|
19 | class BarChartItem : public QObject, public ChartItem | |
19 | { |
|
20 | { | |
20 | Q_OBJECT |
|
21 | Q_OBJECT | |
@@ -32,6 +33,11 public: | |||||
32 | private slots: |
|
33 | private slots: | |
33 | virtual void layoutChanged(); // layout has changed -> need to recalculate bar sizes |
|
34 | virtual void layoutChanged(); // layout has changed -> need to recalculate bar sizes | |
34 |
|
35 | |||
|
36 | public: | |||
|
37 | BarLayout calculateLayout(); | |||
|
38 | void applyLayout(const BarLayout &layout); | |||
|
39 | void setLayout(const BarLayout &layout); | |||
|
40 | ||||
35 | protected: |
|
41 | protected: | |
36 | void initAxisLabels(); |
|
42 | void initAxisLabels(); | |
37 |
|
43 | |||
@@ -39,6 +45,7 public slots: | |||||
39 | void handleModelChanged(int index); |
|
45 | void handleModelChanged(int index); | |
40 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
46 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
41 | void handleGeometryChanged(const QRectF& size); |
|
47 | void handleGeometryChanged(const QRectF& size); | |
|
48 | void handleLayoutChanged(); | |||
42 |
|
49 | |||
43 | // Internal slots |
|
50 | // Internal slots | |
44 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) |
|
51 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) |
@@ -162,7 +162,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||||
162 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
162 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
163 | BarChartItem* bar = new BarChartItem(barSeries,m_chart); |
|
163 | BarChartItem* bar = new BarChartItem(barSeries,m_chart); | |
164 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
164 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
165 |
|
|
165 | m_animator->addAnimation(bar); | |
166 | } |
|
166 | } | |
167 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); |
|
167 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); | |
168 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
168 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
@@ -175,7 +175,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||||
175 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
175 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
176 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,m_chart); |
|
176 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,m_chart); | |
177 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
177 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
178 |
|
|
178 | m_animator->addAnimation(bar); | |
179 | } |
|
179 | } | |
180 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); |
|
180 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); | |
181 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
181 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
@@ -188,7 +188,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||||
188 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
188 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
189 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,m_chart); |
|
189 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,m_chart); | |
190 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
190 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
191 |
|
|
191 | m_animator->addAnimation(bar); | |
192 | } |
|
192 | } | |
193 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); |
|
193 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); | |
194 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
194 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
General Comments 0
You need to be logged in to leave comments.
Login now