summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomi Korpipaa <tomi.korpipaa@qt.io>2021-10-12 14:16:38 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-10-15 11:07:16 +0000
commitf5de71486771405c6767a79c4e97b6acc1c28272 (patch)
tree9f84e339eeaf8f3ee834a91aaa56bab01e525ce2 /src
parent6adc42ef8a62a7fc7566adf2fbc8a4a78f56b733 (diff)
Fix incorrect plotArea before resize
If plotArea is set inside ChartView, contentGeometry is updated too early and we end up with incorrect plotArea. Invalidate the layout to correct the geometry. Fixes: QTBUG-95870 Change-Id: I761125633bcbb8297e629b3e98d61e7d95975806 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> (cherry picked from commit f78e11381f2dedcab4bda44e52b3c75d810766c4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/charts/chartpresenter.cpp2
-rw-r--r--src/charts/domain/abstractdomain.cpp3
-rw-r--r--src/charts/layout/abstractchartlayout.cpp15
-rw-r--r--src/chartsqml2/declarativechart.cpp5
4 files changed, 18 insertions, 7 deletions
diff --git a/src/charts/chartpresenter.cpp b/src/charts/chartpresenter.cpp
index 39ba35f6..b33a3355 100644
--- a/src/charts/chartpresenter.cpp
+++ b/src/charts/chartpresenter.cpp
@@ -98,7 +98,7 @@ void ChartPresenter::setFixedGeometry(const QRectF &rect)
void ChartPresenter::setGeometry(const QRectF rect)
{
- if (m_rect != rect) {
+ if (rect.isValid() && m_rect != rect) {
m_rect = rect;
if (!m_fixedRect.isNull())
return;
diff --git a/src/charts/domain/abstractdomain.cpp b/src/charts/domain/abstractdomain.cpp
index 263c72a4..1ccffde0 100644
--- a/src/charts/domain/abstractdomain.cpp
+++ b/src/charts/domain/abstractdomain.cpp
@@ -58,6 +58,9 @@ AbstractDomain::~AbstractDomain()
void AbstractDomain::setSize(const QSizeF &size)
{
+ if (!size.isValid())
+ return;
+
if (m_size != size) {
m_size=size;
emit updated();
diff --git a/src/charts/layout/abstractchartlayout.cpp b/src/charts/layout/abstractchartlayout.cpp
index 3826c75e..e5c3eb36 100644
--- a/src/charts/layout/abstractchartlayout.cpp
+++ b/src/charts/layout/abstractchartlayout.cpp
@@ -53,6 +53,7 @@ void AbstractChartLayout::setGeometry(const QRectF &rect)
{
if (!rect.isValid())
return;
+
// If the chart has a fixed geometry then don't update visually
const bool updateLayout = (!m_presenter->isFixedGeometry() || m_presenter->geometry() == rect);
if (m_presenter->chart()->isVisible()) {
@@ -73,12 +74,14 @@ void AbstractChartLayout::setGeometry(const QRectF &rect)
contentGeometry = calculateAxisGeometry(contentGeometry, axes, updateLayout);
- m_presenter->setGeometry(contentGeometry);
- if (updateLayout) {
- if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian)
- static_cast<QGraphicsRectItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry);
- else
- static_cast<QGraphicsEllipseItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry);
+ if (contentGeometry.isValid()) {
+ m_presenter->setGeometry(contentGeometry);
+ if (updateLayout) {
+ if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian)
+ static_cast<QGraphicsRectItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry);
+ else
+ static_cast<QGraphicsEllipseItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry);
+ }
}
}
diff --git a/src/chartsqml2/declarativechart.cpp b/src/chartsqml2/declarativechart.cpp
index 5dd6c5bb..82410cb2 100644
--- a/src/chartsqml2/declarativechart.cpp
+++ b/src/chartsqml2/declarativechart.cpp
@@ -70,6 +70,7 @@
#include <QtCore/QTimer>
#include <QtCore/QThread>
#include <QtQuick/QQuickWindow>
+#include <QtWidgets/QGraphicsLayout>
#if QT_CONFIG(charts_datetime_axis)
#include <QtCharts/QDateTimeAxis>
@@ -1550,6 +1551,10 @@ QPointF DeclarativeChart::mapToPosition(const QPointF &value, QAbstractSeries *s
void DeclarativeChart::setPlotArea(const QRectF &rect)
{
m_chart->setPlotArea(rect);
+
+ // If plotArea is set inside ChartView, contentGeometry is updated too early and we end up
+ // with incorrect plotArea. Invalidate the layout to correct the geometry.
+ m_chart->layout()->invalidate();
}
QT_END_NAMESPACE