diff --git a/examples/presenterchart/chartview.cpp b/examples/presenterchart/chartview.cpp index f559680..70f746c 100644 --- a/examples/presenterchart/chartview.cpp +++ b/examples/presenterchart/chartview.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include ChartView::ChartView(QWidget* parent):QChartView(parent), @@ -30,6 +31,12 @@ m_index(0) QPen green(Qt::green); green.setWidth(3); series2->setPen(green); + + QAreaSeries* series3 = new QAreaSeries(series0); + QPen yellow(Qt::black); + yellow.setWidth(3); + series3->setPen(yellow); + series3->setBrush(Qt::yellow); //![1] //![2] @@ -50,6 +57,8 @@ m_index(0) m_titles< Q_DECLARE_METATYPE(QVector) @@ -21,7 +22,7 @@ ChartAnimator::~ChartAnimator() void ChartAnimator::addAnimation(AxisItem* item) { - AxisAnimation* animation = static_cast(m_animations.value(item)); + ChartAnimation* animation = m_animations.value(item); if(!animation) { animation = new AxisAnimation(item); @@ -33,7 +34,7 @@ void ChartAnimator::addAnimation(AxisItem* item) void ChartAnimator::addAnimation(XYChartItem* item) { - XYAnimation* animation = static_cast(m_animations.value(item)); + ChartAnimation* animation = m_animations.value(item); if(!animation) { animation = new XYAnimation(item); @@ -53,7 +54,7 @@ void ChartAnimator::applyLayout(AxisItem* item , QVector& newLayout) { AxisAnimation* animation = static_cast(m_animations.value(item)); - if(!animation) return; + Q_ASSERT(animation); QVector oldLayout = item->layout(); @@ -133,7 +134,7 @@ void ChartAnimator::applyLayout(XYChartItem* item, QVector& newPoints) XYAnimation* animation = static_cast(m_animations.value(item)); - if(!animation) return; + Q_ASSERT(animation); QVector oldPoints = item->points(); @@ -160,7 +161,7 @@ void ChartAnimator::updateLayout(XYChartItem* item, QVector& newPoints) { XYAnimation* animation = static_cast(m_animations.value(item)); - if(!animation) return; + Q_ASSERT(animation); animation->setDuration(duration); animation->setAnimationType(XYAnimation::MoveDownAnimation); diff --git a/src/animations/chartanimator_p.h b/src/animations/chartanimator_p.h index b694e61..dc430a7 100644 --- a/src/animations/chartanimator_p.h +++ b/src/animations/chartanimator_p.h @@ -9,6 +9,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class ChartItem; class XYChartItem; class AxisItem; +class AreaChartItem; class ChartAnimator : public QObject { diff --git a/src/areachart/areachartitem_p.h b/src/areachart/areachartitem_p.h index 4c6bc3f..26db2ff 100644 --- a/src/areachart/areachartitem_p.h +++ b/src/areachart/areachartitem_p.h @@ -22,6 +22,9 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QPainterPath shape() const; + LineChartItem* upperLineItem() const { return m_upper ;} + LineChartItem* lowerLineItem() const { return m_lower ;} + void setPointsVisible(bool visible); void updatePath(); public slots: diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index a3807d9..54ab20d 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -157,7 +157,8 @@ void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) QAreaSeries* areaSeries = static_cast(series); AreaChartItem* area = new AreaChartItem(areaSeries,m_chart); if(m_options.testFlag(QChart::SeriesAnimations)) { - // m_animator->addAnimation(area); + m_animator->addAnimation(area->upperLineItem()); + if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); } m_chartTheme->decorate(area, areaSeries, m_dataset->seriesIndex(series)); QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); @@ -267,7 +268,16 @@ void ChartPresenter::handleSeriesRemoved(QSeries* series) { ChartItem* item = m_chartItems.take(series); Q_ASSERT(item); - if(m_animator) m_animator->removeAnimation(item); + if(m_animator) { + //small hack to handle area animations + if(series->type()==QSeries::SeriesTypeArea){ + QAreaSeries* areaSeries = static_cast(series); + AreaChartItem* area = static_cast(item); + m_animator->removeAnimation(area->upperLineItem()); + if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); + }else + m_animator->removeAnimation(item); + } delete item; } diff --git a/src/charttheme.cpp b/src/charttheme.cpp index 0a173a9..ebf037c 100644 --- a/src/charttheme.cpp +++ b/src/charttheme.cpp @@ -76,13 +76,13 @@ void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series, int index) QPen pen; QBrush brush; - if (pen != series->pen()){ + if (pen == series->pen()){ pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); pen.setWidthF(2); series->setPen(pen); } - if (brush != series->brush()) { + if (brush == series->brush()) { QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); series->setBrush(brush); } @@ -92,10 +92,7 @@ void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series, int index) void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int index) { QPen pen; - if(pen != series->pen()){ - series->setPen(series->pen()); - return; - }else{ + if(pen == series->pen()){ pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); pen.setWidthF(2); series->setPen(pen);