summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomi Korpipaa <tomi.korpipaa@qt.io>2021-10-12 14:16:38 +0300
committerTomi Korpipaa <tomi.korpipaa@qt.io>2021-10-15 12:27:47 +0300
commitf78e11381f2dedcab4bda44e52b3c75d810766c4 (patch)
tree7911d7847405fc81e3df5c6511fcf1acc0160c50 /src
parent11e785a4a67a89999fd15124e418ff324c375224 (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. Pick-to: 5.15 6.2 Fixes: QTBUG-95870 Change-Id: I761125633bcbb8297e629b3e98d61e7d95975806 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
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 b340d503..f7ccd92f 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