aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-08-26 18:01:40 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-08-27 14:04:13 +0000
commit1b5abea39ed68fbd6984aa54c456fd320e1202ad (patch)
treeeb17b0a83513fa5af0dc40a5f3fb98046086d15d
parent4a6292afc8609c2b51a53ba52ff14adcfc0833fa (diff)
StackView: fix initialization of items
Only items that were created from pushed components were initialized. This change fixes item initialization for StackView::initialItem and pushed items. Change-Id: I6fe1afa233e63320180dfe8eac3874fed69cbb3b Task-number: QTBUG-47318 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/controls/qquickstackview_p.cpp47
-rw-r--r--src/controls/qquickstackview_p_p.h5
-rw-r--r--tests/auto/applicationwindow/tst_applicationwindow.cpp2
3 files changed, 27 insertions, 27 deletions
diff --git a/src/controls/qquickstackview_p.cpp b/src/controls/qquickstackview_p.cpp
index c0969199..67cdde59 100644
--- a/src/controls/qquickstackview_p.cpp
+++ b/src/controls/qquickstackview_p.cpp
@@ -58,14 +58,14 @@ public:
QQuickStackIncubator(QQuickStackElement *element) : QQmlIncubator(Synchronous), element(element) { }
protected:
- void setInitialState(QObject *object) Q_DECL_OVERRIDE { element->initItem(object); }
+ void setInitialState(QObject *object) Q_DECL_OVERRIDE { element->incubate(object); }
private:
QQuickStackElement *element;
};
QQuickStackElement::QQuickStackElement() : QQuickItemViewTransitionableItem(Q_NULLPTR),
- index(-1), removal(false), ownItem(false), ownComponent(false),
+ index(-1), init(false), removal(false), ownItem(false), ownComponent(false),
context(Q_NULLPTR), component(Q_NULLPTR), incubator(Q_NULLPTR), view(Q_NULLPTR),
status(QQuickStackView::Inactive)
{
@@ -114,11 +114,8 @@ QQuickStackElement *QQuickStackElement::fromObject(QObject *object, QQuickStackV
element->ownComponent = true;
}
element->item = qobject_cast<QQuickItem *>(object);
- if (element->item) {
+ if (element->item)
element->originalParent = element->item->parentItem();
- element->item->setParentItem(view);
- QQuickItemPrivate::get(element->item)->addItemChangeListener(element, QQuickItemPrivate::Destroyed);
- }
return element;
}
@@ -138,32 +135,34 @@ bool QQuickStackElement::load(QQuickStackView *parent)
incubator = new QQuickStackIncubator(this);
component->create(*incubator, context);
}
- initProperties();
+ initialize();
return item;
}
-void QQuickStackElement::initItem(QObject *object)
+void QQuickStackElement::incubate(QObject *object)
{
item = qmlobject_cast<QQuickItem *>(object);
- if (item) {
+ if (item)
QQmlEngine::setObjectOwnership(item, QQmlEngine::CppOwnership);
- QQuickItemPrivate *p = QQuickItemPrivate::get(item);
- if (!p->widthValid) {
- item->setWidth(view->width());
- p->widthValid = true;
- }
- if (!p->heightValid) {
- item->setHeight(view->height());
- p->heightValid = true;
- }
- item->setParentItem(view);
- p->addItemChangeListener(this, QQuickItemPrivate::Destroyed);
- }
- initProperties();
}
-void QQuickStackElement::initProperties()
+void QQuickStackElement::initialize()
{
+ if (!item || init)
+ return;
+
+ QQuickItemPrivate *p = QQuickItemPrivate::get(item);
+ if (!p->widthValid) {
+ item->setWidth(view->width());
+ p->widthValid = false;
+ }
+ if (!p->heightValid) {
+ item->setHeight(view->height());
+ p->heightValid = false;
+ }
+ item->setParentItem(view);
+ p->addItemChangeListener(this, QQuickItemPrivate::Destroyed);
+
if (!properties.isUndefined()) {
QQmlComponentPrivate *d = QQmlComponentPrivate::get(component);
Q_ASSERT(d && d->engine);
@@ -174,6 +173,8 @@ void QQuickStackElement::initProperties()
d->initializeObjectWithInitialProperties(ipv, item);
properties.clear();
}
+
+ init = true;
}
void QQuickStackElement::setIndex(int value)
diff --git a/src/controls/qquickstackview_p_p.h b/src/controls/qquickstackview_p_p.h
index 063ce17e..84ed9f35 100644
--- a/src/controls/qquickstackview_p_p.h
+++ b/src/controls/qquickstackview_p_p.h
@@ -71,8 +71,8 @@ public:
static QQuickStackElement *fromObject(QObject *object, QQuickStackView *view);
bool load(QQuickStackView *parent);
- void initItem(QObject *object);
- void initProperties();
+ void incubate(QObject *object);
+ void initialize();
void setIndex(int index);
void setView(QQuickStackView *view);
@@ -85,6 +85,7 @@ public:
void itemDestroyed(QQuickItem *item) Q_DECL_OVERRIDE;
int index;
+ bool init;
bool removal;
bool ownItem;
bool ownComponent;
diff --git a/tests/auto/applicationwindow/tst_applicationwindow.cpp b/tests/auto/applicationwindow/tst_applicationwindow.cpp
index 4d53c8cf..bdb55ce7 100644
--- a/tests/auto/applicationwindow/tst_applicationwindow.cpp
+++ b/tests/auto/applicationwindow/tst_applicationwindow.cpp
@@ -247,9 +247,7 @@ void tst_applicationwindow::implicitFill()
QVERIFY(nextItem);
QVERIFY(QMetaObject::invokeMethod(window, "pushNextItem"));
- QEXPECT_FAIL("", "QTBUG-47318", Continue);
QCOMPARE(nextItem->width(), 400.0);
- QEXPECT_FAIL("", "QTBUG-47318", Continue);
QCOMPARE(nextItem->height(), 400.0);
}