##// END OF EJS Templates
Adds area chart animations...
Michal Klocek -
r560:5b64457c513a
parent child
Show More
@@ -2,6 +2,7
2 #include <qlineseries.h>
2 #include <qlineseries.h>
3 #include <qscatterseries.h>
3 #include <qscatterseries.h>
4 #include <qsplineseries.h>
4 #include <qsplineseries.h>
5 #include <qareaseries.h>
5 #include <QTime>
6 #include <QTime>
6
7
7 ChartView::ChartView(QWidget* parent):QChartView(parent),
8 ChartView::ChartView(QWidget* parent):QChartView(parent),
@@ -30,6 +31,12 m_index(0)
30 QPen green(Qt::green);
31 QPen green(Qt::green);
31 green.setWidth(3);
32 green.setWidth(3);
32 series2->setPen(green);
33 series2->setPen(green);
34
35 QAreaSeries* series3 = new QAreaSeries(series0);
36 QPen yellow(Qt::black);
37 yellow.setWidth(3);
38 series3->setPen(yellow);
39 series3->setBrush(Qt::yellow);
33 //![1]
40 //![1]
34
41
35 //![2]
42 //![2]
@@ -50,6 +57,8 m_index(0)
50 m_titles<<chartTitle()+": ScatterChart";
57 m_titles<<chartTitle()+": ScatterChart";
51 m_series<<series2;
58 m_series<<series2;
52 m_titles<<chartTitle()+": SplineChart";
59 m_titles<<chartTitle()+": SplineChart";
60 m_series<<series3;
61 m_titles<<chartTitle()+": AreaChart";
53 //![3]
62 //![3]
54 addSeries(series0);
63 addSeries(series0);
55 setChartTitle(m_titles.at(0));
64 setChartTitle(m_titles.at(0));
@@ -2,6 +2,7
2 #include "axisanimation_p.h"
2 #include "axisanimation_p.h"
3 #include "xyanimation_p.h"
3 #include "xyanimation_p.h"
4 #include "xychartitem_p.h"
4 #include "xychartitem_p.h"
5 #include "areachartitem_p.h"
5 #include <QTimer>
6 #include <QTimer>
6
7
7 Q_DECLARE_METATYPE(QVector<QPointF>)
8 Q_DECLARE_METATYPE(QVector<QPointF>)
@@ -21,7 +22,7 ChartAnimator::~ChartAnimator()
21
22
22 void ChartAnimator::addAnimation(AxisItem* item)
23 void ChartAnimator::addAnimation(AxisItem* item)
23 {
24 {
24 AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item));
25 ChartAnimation* animation = m_animations.value(item);
25
26
26 if(!animation) {
27 if(!animation) {
27 animation = new AxisAnimation(item);
28 animation = new AxisAnimation(item);
@@ -33,7 +34,7 void ChartAnimator::addAnimation(AxisItem* item)
33
34
34 void ChartAnimator::addAnimation(XYChartItem* item)
35 void ChartAnimator::addAnimation(XYChartItem* item)
35 {
36 {
36 XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item));
37 ChartAnimation* animation = m_animations.value(item);
37
38
38 if(!animation) {
39 if(!animation) {
39 animation = new XYAnimation(item);
40 animation = new XYAnimation(item);
@@ -53,7 +54,7 void ChartAnimator::applyLayout(AxisItem* item , QVector<qreal>& newLayout)
53 {
54 {
54 AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item));
55 AxisAnimation* animation = static_cast<AxisAnimation*>(m_animations.value(item));
55
56
56 if(!animation) return;
57 Q_ASSERT(animation);
57
58
58 QVector<qreal> oldLayout = item->layout();
59 QVector<qreal> oldLayout = item->layout();
59
60
@@ -133,7 +134,7 void ChartAnimator::applyLayout(XYChartItem* item, QVector<QPointF>& newPoints)
133
134
134 XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item));
135 XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item));
135
136
136 if(!animation) return;
137 Q_ASSERT(animation);
137
138
138 QVector<QPointF> oldPoints = item->points();
139 QVector<QPointF> oldPoints = item->points();
139
140
@@ -160,7 +161,7 void ChartAnimator::updateLayout(XYChartItem* item, QVector<QPointF>& newPoints)
160 {
161 {
161 XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item));
162 XYAnimation* animation = static_cast<XYAnimation*>(m_animations.value(item));
162
163
163 if(!animation) return;
164 Q_ASSERT(animation);
164
165
165 animation->setDuration(duration);
166 animation->setDuration(duration);
166 animation->setAnimationType(XYAnimation::MoveDownAnimation);
167 animation->setAnimationType(XYAnimation::MoveDownAnimation);
@@ -9,6 +9,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 class ChartItem;
9 class ChartItem;
10 class XYChartItem;
10 class XYChartItem;
11 class AxisItem;
11 class AxisItem;
12 class AreaChartItem;
12
13
13
14
14 class ChartAnimator : public QObject {
15 class ChartAnimator : public QObject {
@@ -22,6 +22,9 public:
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 QPainterPath shape() const;
23 QPainterPath shape() const;
24
24
25 LineChartItem* upperLineItem() const { return m_upper ;}
26 LineChartItem* lowerLineItem() const { return m_lower ;}
27
25 void setPointsVisible(bool visible);
28 void setPointsVisible(bool visible);
26 void updatePath();
29 void updatePath();
27 public slots:
30 public slots:
@@ -157,7 +157,8 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
157 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
157 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
158 AreaChartItem* area = new AreaChartItem(areaSeries,m_chart);
158 AreaChartItem* area = new AreaChartItem(areaSeries,m_chart);
159 if(m_options.testFlag(QChart::SeriesAnimations)) {
159 if(m_options.testFlag(QChart::SeriesAnimations)) {
160 // m_animator->addAnimation(area);
160 m_animator->addAnimation(area->upperLineItem());
161 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
161 }
162 }
162 m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series));
163 m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series));
163 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
164 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
@@ -267,7 +268,16 void ChartPresenter::handleSeriesRemoved(QSeries* series)
267 {
268 {
268 ChartItem* item = m_chartItems.take(series);
269 ChartItem* item = m_chartItems.take(series);
269 Q_ASSERT(item);
270 Q_ASSERT(item);
270 if(m_animator) m_animator->removeAnimation(item);
271 if(m_animator) {
272 //small hack to handle area animations
273 if(series->type()==QSeries::SeriesTypeArea){
274 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
275 AreaChartItem* area = static_cast<AreaChartItem*>(item);
276 m_animator->removeAnimation(area->upperLineItem());
277 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
278 }else
279 m_animator->removeAnimation(item);
280 }
271 delete item;
281 delete item;
272 }
282 }
273
283
@@ -76,13 +76,13 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series, int index)
76 QPen pen;
76 QPen pen;
77 QBrush brush;
77 QBrush brush;
78
78
79 if (pen != series->pen()){
79 if (pen == series->pen()){
80 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0));
80 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0));
81 pen.setWidthF(2);
81 pen.setWidthF(2);
82 series->setPen(pen);
82 series->setPen(pen);
83 }
83 }
84
84
85 if (brush != series->brush()) {
85 if (brush == series->brush()) {
86 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
86 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
87 series->setBrush(brush);
87 series->setBrush(brush);
88 }
88 }
@@ -92,10 +92,7 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series, int index)
92 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int index)
92 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int index)
93 {
93 {
94 QPen pen;
94 QPen pen;
95 if(pen != series->pen()){
95 if(pen == series->pen()){
96 series->setPen(series->pen());
97 return;
98 }else{
99 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
96 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
100 pen.setWidthF(2);
97 pen.setWidthF(2);
101 series->setPen(pen);
98 series->setPen(pen);
General Comments 0
You need to be logged in to leave comments. Login now