From 57e4c71e553298f77b37e6e56b9f310b0f901e5e 2015-10-30 09:55:23 From: Miikka Heikkinen Date: 2015-10-30 09:55:23 Subject: [PATCH] Clear chart image to transparent when necessary. If there is any transparency in the background, image clear should be done every time chart is rendered to avoid artifacts from previous render. Background shape change also triggers the clear, but that is needed only once. Change-Id: If0a762d2e2e01cf3a94a5d2f6845613deb619bdd Reviewed-by: Titta Heikkala --- diff --git a/src/charts/qabstractseries.cpp b/src/charts/qabstractseries.cpp index 79e3143..f932639 100644 --- a/src/charts/qabstractseries.cpp +++ b/src/charts/qabstractseries.cpp @@ -167,8 +167,8 @@ QT_CHARTS_BEGIN_NAMESPACE hardware and drivers. \li Polar charts do not support accelerated series. \li Mouse events are not supported for accelerated series. - \li Enabling chart drop shadow is not recommended when using accelerated series, - as that can slow the frame rate down significantly. + \li Enabling chart drop shadow or using transparent chart background color is not recommended + when using accelerated series, as that can slow the frame rate down significantly. \endlist These additional restrictions stem from the fact that the accelerated series is drawn on a @@ -223,8 +223,8 @@ QT_CHARTS_BEGIN_NAMESPACE hardware and drivers. \li Polar charts do not support accelerated series. \li Mouse events are not supported for accelerated series. - \li Enabling chart drop shadow is not recommended when using accelerated series, - as that can slow the frame rate down significantly. + \li Enabling chart drop shadow or using transparent chart background color is not recommended + when using accelerated series, as that can slow the frame rate down significantly. \endlist The default value is \c{false}. diff --git a/src/chartsqml2/declarativechart.cpp b/src/chartsqml2/declarativechart.cpp index 6644151..d76180a 100644 --- a/src/chartsqml2/declarativechart.cpp +++ b/src/chartsqml2/declarativechart.cpp @@ -334,6 +334,7 @@ void DeclarativeChart::initChart(QChart::ChartType type) { m_sceneImage = 0; m_sceneImageDirty = false; + m_sceneImageNeedsClear = false; m_guiThreadId = QThread::currentThreadId(); m_paintThreadId = 0; m_updatePending = false; @@ -590,9 +591,15 @@ void DeclarativeChart::renderScene() if (!m_sceneImage || chartSize != m_sceneImage->size()) { delete m_sceneImage; m_sceneImage = new QImage(chartSize, QImage::Format_ARGB32); - m_sceneImage->fill(Qt::transparent); + m_sceneImageNeedsClear = true; } + if (m_sceneImageNeedsClear) { + m_sceneImage->fill(Qt::transparent); + // Don't clear the flag if chart background has any transparent element to it + if (m_chart->backgroundBrush().color().alpha() == 0xff && !m_chart->isDropShadowEnabled()) + m_sceneImageNeedsClear = false; + } QPainter painter(m_sceneImage); if (antialiasing()) { painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing @@ -822,6 +829,8 @@ void DeclarativeChart::setBackgroundColor(QColor color) { QBrush b = m_chart->backgroundBrush(); if (b.style() != Qt::SolidPattern || color != b.color()) { + if (color.alpha() < 0xff) + m_sceneImageNeedsClear = true; b.setStyle(Qt::SolidPattern); b.setColor(color); m_chart->setBackgroundBrush(b); @@ -885,6 +894,7 @@ int DeclarativeChart::count() void DeclarativeChart::setDropShadowEnabled(bool enabled) { if (enabled != m_chart->isDropShadowEnabled()) { + m_sceneImageNeedsClear = true; m_chart->setDropShadowEnabled(enabled); dropShadowEnabledChanged(enabled); } @@ -903,6 +913,7 @@ qreal DeclarativeChart::backgroundRoundness() const void DeclarativeChart::setBackgroundRoundness(qreal diameter) { if (m_chart->backgroundRoundness() != diameter) { + m_sceneImageNeedsClear = true; m_chart->setBackgroundRoundness(diameter); emit backgroundRoundnessChanged(diameter); } diff --git a/src/chartsqml2/declarativechart.h b/src/chartsqml2/declarativechart.h index acb961b..618a9fb 100644 --- a/src/chartsqml2/declarativechart.h +++ b/src/chartsqml2/declarativechart.h @@ -238,6 +238,7 @@ private: Qt::HANDLE m_guiThreadId; DeclarativeMargins *m_margins; GLXYSeriesDataManager *m_glXYDataManager; + bool m_sceneImageNeedsClear; }; QT_CHARTS_END_NAMESPACE