aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandr Akulich <akulichalexander@gmail.com>2016-06-16 10:40:12 +0500
committerShawn Rutledge <shawn.rutledge@qt.io>2017-10-20 12:33:19 +0000
commit5a979e2d24b51e931a158062d322d0340e666bff (patch)
treef61123b92ec5499c759076620db327c3960f7607
parente3e890dbb3106c8360d6c4a75b7905b7b1a75f09 (diff)
QQuickLoader: Use setSize() to resize item
Sequential call of setWidth() and setHeight() results in outdated height on widthChanged() signal. Use setSize() to set width and height at once. Change-Id: I86ff5cef2da912a8855c66a614d5d7d2e71f1de8 Reviewed-by: Risto Avila <risto.avila@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/quick/items/qquickloader.cpp9
-rw-r--r--tests/auto/quick/qquickloader/qquickloader.pro1
-rw-r--r--tests/auto/quick/qquickloader/tst_qquickloader.cpp15
3 files changed, 19 insertions, 6 deletions
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp
index cd356a9eeb..27afe5a5db 100644
--- a/src/quick/items/qquickloader.cpp
+++ b/src/quick/items/qquickloader.cpp
@@ -916,9 +916,14 @@ void QQuickLoaderPrivate::_q_updateSize(bool loaderGeometryChanged)
if (!item)
return;
- if (loaderGeometryChanged && q->widthValid())
+ const bool needToUpdateWidth = loaderGeometryChanged && q->widthValid();
+ const bool needToUpdateHeight = loaderGeometryChanged && q->heightValid();
+
+ if (needToUpdateWidth && needToUpdateHeight)
+ item->setSize(QSizeF(q->width(), q->height()));
+ else if (needToUpdateWidth)
item->setWidth(q->width());
- if (loaderGeometryChanged && q->heightValid())
+ else if (needToUpdateHeight)
item->setHeight(q->height());
if (updatingSize)
diff --git a/tests/auto/quick/qquickloader/qquickloader.pro b/tests/auto/quick/qquickloader/qquickloader.pro
index 32350388e8..06fb75793d 100644
--- a/tests/auto/quick/qquickloader/qquickloader.pro
+++ b/tests/auto/quick/qquickloader/qquickloader.pro
@@ -9,6 +9,7 @@ SOURCES += tst_qquickloader.cpp \
../../shared/testhttpserver.cpp
include (../../shared/util.pri)
+include (../shared/util.pri)
TESTDATA = data/*
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
index 3e7439f3e9..521388c5fa 100644
--- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp
+++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
@@ -35,6 +35,7 @@
#include <private/qquickloader_p.h>
#include "testhttpserver.h"
#include "../../shared/util.h"
+#include "../shared/geometrytestutil.h"
class SlowComponent : public QQmlComponent
{
@@ -403,10 +404,16 @@ void tst_QQuickLoader::sizeItemToLoader()
QCOMPARE(rect->height(), 80.0);
// Check resize
- loader->setWidth(180);
- loader->setHeight(30);
- QCOMPARE(rect->width(), 180.0);
- QCOMPARE(rect->height(), 30.0);
+ QSizeChangeListener sizeListener(rect);
+ const QSizeF size(180, 30);
+ loader->setSize(size);
+ QVERIFY2(!sizeListener.isEmpty(), "There should be at least one signal about the size changed");
+ for (const QSizeF sizeOnGeometryChanged : sizeListener) {
+ // Check that we have the correct size on all signals
+ QCOMPARE(sizeOnGeometryChanged, size);
+ }
+ QCOMPARE(rect->width(), size.width());
+ QCOMPARE(rect->height(), size.height());
// Switch mode
loader->resetWidth(); // reset explicit size