diff options
Diffstat (limited to 'src/quicktemplates2/qquicktumbler.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktumbler.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/quicktemplates2/qquicktumbler.cpp b/src/quicktemplates2/qquicktumbler.cpp index 608044ec..f2c548bb 100644 --- a/src/quicktemplates2/qquicktumbler.cpp +++ b/src/quicktemplates2/qquicktumbler.cpp @@ -36,6 +36,7 @@ #include "qquicktumbler_p.h" +#include <QtQml/qqmlinfo.h> #include <QtQuick/private/qquickflickable_p.h> #include <QtQuickTemplates2/private/qquickcontrol_p_p.h> #include <QtQuickTemplates2/private/qquicktumbler_p_p.h> @@ -441,13 +442,7 @@ void QQuickTumbler::resetWrap() QQuickTumblerAttached *QQuickTumbler::qmlAttachedProperties(QObject *object) { - QQuickItem *delegateItem = qobject_cast<QQuickItem *>(object); - if (!delegateItem) { - qWarning() << "Tumbler: attached properties of Tumbler must be accessed through a delegate item"; - return nullptr; - } - - return new QQuickTumblerAttached(delegateItem); + return new QQuickTumblerAttached(object); } void QQuickTumbler::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) @@ -674,11 +669,15 @@ class QQuickTumblerAttachedPrivate : public QObjectPrivate, public QQuickItemCha { Q_DECLARE_PUBLIC(QQuickTumblerAttached) public: - QQuickTumblerAttachedPrivate(QQuickItem *delegateItem) : + QQuickTumblerAttachedPrivate() : tumbler(nullptr), index(-1), displacement(0) { + } + + void init(QQuickItem *delegateItem) + { if (!delegateItem->parentItem()) { qWarning() << "Tumbler: attached properties must be accessed through a delegate item that has a parent"; return; @@ -699,9 +698,6 @@ public: } } - ~QQuickTumblerAttachedPrivate() { - } - void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override; void itemChildAdded(QQuickItem *, QQuickItem *) override; void itemChildRemoved(QQuickItem *, QQuickItem *) override; @@ -788,10 +784,16 @@ void QQuickTumblerAttachedPrivate::_q_calculateDisplacement() emit q->displacementChanged(); } -QQuickTumblerAttached::QQuickTumblerAttached(QQuickItem *delegateItem) : - QObject(*(new QQuickTumblerAttachedPrivate(delegateItem)), delegateItem) +QQuickTumblerAttached::QQuickTumblerAttached(QObject *parent) : + QObject(*(new QQuickTumblerAttachedPrivate), parent) { Q_D(QQuickTumblerAttached); + QQuickItem *delegateItem = qobject_cast<QQuickItem *>(parent); + if (delegateItem) + d->init(delegateItem); + else if (parent) + qmlInfo(parent) << "Tumbler: attached properties of Tumbler must be accessed through a delegate item"; + if (d->tumbler) { // When the Tumbler is completed, wrapChanged() is emitted to let QQuickTumblerView // know that it can create the view. The view itself might instantiate delegates |