@@ -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 | 7 | $$PWD/xyanimation.cpp \ |
|
8 | 8 | $$PWD/pieanimation.cpp \ |
|
9 | 9 | $$PWD/piesliceanimation.cpp \ |
|
10 | $$PWD/splineanimation.cpp | |
|
10 | $$PWD/splineanimation.cpp \ | |
|
11 | $$PWD/baranimation.cpp | |
|
12 | ||
|
11 | 13 | |
|
12 | 14 | |
|
13 | 15 | PRIVATE_HEADERS += \ |
@@ -17,4 +19,6 PRIVATE_HEADERS += \ | |||
|
17 | 19 | $$PWD/xyanimation_p.h \ |
|
18 | 20 | $$PWD/pieanimation_p.h \ |
|
19 | 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 | 4 | #include "splineanimation_p.h" |
|
5 | 5 | #include "xychartitem_p.h" |
|
6 | 6 | #include "pieanimation_p.h" |
|
7 | #include "baranimation_p.h" | |
|
8 | #include "barchartitem_p.h" | |
|
7 | 9 | #include "areachartitem_p.h" |
|
8 | 10 | #include "splinechartitem_p.h" |
|
9 | 11 | #include "scatterchartitem_p.h" |
@@ -84,6 +86,19 void ChartAnimator::addAnimation(PieChartItem* item) | |||
|
84 | 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 | 102 | void ChartAnimator::removeAnimation(ChartItem* item) |
|
88 | 103 | { |
|
89 | 104 | item->setAnimator(0); |
@@ -252,6 +267,15 void ChartAnimator::updateLayout(PieChartItem* item, QPieSlice *slice, const Pie | |||
|
252 | 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 | 279 | void ChartAnimator::setState(State state,const QPointF& point) |
|
256 | 280 | { |
|
257 | 281 | m_state=state; |
@@ -3,6 +3,7 | |||
|
3 | 3 | #include "qchartglobal.h" |
|
4 | 4 | #include "chartanimation_p.h" |
|
5 | 5 | #include "piechartitem_p.h" |
|
6 | #include "barchartitem_p.h" | |
|
6 | 7 | #include <QPointF> |
|
7 | 8 | |
|
8 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -28,6 +29,7 public: | |||
|
28 | 29 | void addAnimation(ScatterChartItem* item); |
|
29 | 30 | void addAnimation(LineChartItem* item); |
|
30 | 31 | void addAnimation(SplineChartItem* item); |
|
32 | void addAnimation(BarChartItem* item); | |
|
31 | 33 | void removeAnimation(ChartItem* item); |
|
32 | 34 | |
|
33 | 35 | void animationStarted(); |
@@ -40,6 +42,8 public: | |||
|
40 | 42 | void updateLayout(PieChartItem* item, const PieLayout &layout); |
|
41 | 43 | void updateLayout(PieChartItem* item, QPieSlice *slice, const PieSliceData &sliceData); |
|
42 | 44 | |
|
45 | void updateLayout(BarChartItem* item, const BarLayout &layout); | |
|
46 | ||
|
43 | 47 | void setState(State state,const QPointF& point = QPointF()); |
|
44 | 48 | |
|
45 | 49 | private: |
@@ -7,6 +7,7 | |||
|
7 | 7 | #include "qchartaxis.h" |
|
8 | 8 | #include "qchartaxiscategories.h" |
|
9 | 9 | #include "chartpresenter_p.h" |
|
10 | #include "chartanimator_p.h" | |
|
10 | 11 | #include <QDebug> |
|
11 | 12 | #include <QToolTip> |
|
12 | 13 | |
@@ -22,6 +23,8 BarChartItem::BarChartItem(QBarSeries *series, QChart *parent) : | |||
|
22 | 23 | { |
|
23 | 24 | connect(series,SIGNAL(showToolTip(QPoint,QString)),this,SLOT(showToolTip(QPoint,QString))); |
|
24 | 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 | 28 | setZValue(ChartPresenter::BarSeriesZValue); |
|
26 | 29 | initAxisLabels(); |
|
27 | 30 | dataChanged(); |
@@ -157,6 +160,31 void BarChartItem::layoutChanged() | |||
|
157 | 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 | 189 | void BarChartItem::initAxisLabels() |
|
162 | 190 | { |
@@ -228,6 +256,14 void BarChartItem::handleGeometryChanged(const QRectF& rect) | |||
|
228 | 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 | 267 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
232 | 268 | { |
|
233 | 269 | // TODO: cool tooltip instead of default |
@@ -14,7 +14,8 class BarValue; | |||
|
14 | 14 | class QChartAxisCategories; |
|
15 | 15 | class QChart; |
|
16 | 16 | |
|
17 | // Common implemantation of different presenters. | |
|
17 | typedef QHash<Bar*, QSizeF> BarLayout; | |
|
18 | ||
|
18 | 19 | class BarChartItem : public QObject, public ChartItem |
|
19 | 20 | { |
|
20 | 21 | Q_OBJECT |
@@ -32,6 +33,11 public: | |||
|
32 | 33 | private slots: |
|
33 | 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 | 41 | protected: |
|
36 | 42 | void initAxisLabels(); |
|
37 | 43 | |
@@ -39,6 +45,7 public slots: | |||
|
39 | 45 | void handleModelChanged(int index); |
|
40 | 46 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
41 | 47 | void handleGeometryChanged(const QRectF& size); |
|
48 | void handleLayoutChanged(); | |
|
42 | 49 | |
|
43 | 50 | // Internal slots |
|
44 | 51 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) |
@@ -162,7 +162,7 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
162 | 162 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
163 | 163 | BarChartItem* bar = new BarChartItem(barSeries,m_chart); |
|
164 | 164 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
165 |
|
|
|
165 | m_animator->addAnimation(bar); | |
|
166 | 166 | } |
|
167 | 167 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); |
|
168 | 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 | 175 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
176 | 176 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,m_chart); |
|
177 | 177 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
178 |
|
|
|
178 | m_animator->addAnimation(bar); | |
|
179 | 179 | } |
|
180 | 180 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); |
|
181 | 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 | 188 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
189 | 189 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,m_chart); |
|
190 | 190 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
191 |
|
|
|
191 | m_animator->addAnimation(bar); | |
|
192 | 192 | } |
|
193 | 193 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); |
|
194 | 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