diff options
Diffstat (limited to 'src/quicktemplates2')
-rw-r--r-- | src/quicktemplates2/qquickscrollbar.cpp | 23 | ||||
-rw-r--r-- | src/quicktemplates2/qquickscrollbar_p.h | 2 |
2 files changed, 11 insertions, 14 deletions
diff --git a/src/quicktemplates2/qquickscrollbar.cpp b/src/quicktemplates2/qquickscrollbar.cpp index f7a5c246..bcb86fa3 100644 --- a/src/quicktemplates2/qquickscrollbar.cpp +++ b/src/quicktemplates2/qquickscrollbar.cpp @@ -281,11 +281,7 @@ QQuickScrollBar::QQuickScrollBar(QQuickItem *parent) QQuickScrollBarAttached *QQuickScrollBar::qmlAttachedProperties(QObject *object) { - QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(object); - if (!flickable) - qmlWarning(object) << "ScrollBar must be attached to a Flickable"; - - return new QQuickScrollBarAttached(flickable); + return new QQuickScrollBarAttached(object); } /*! @@ -606,8 +602,8 @@ QAccessible::Role QQuickScrollBar::accessibleRole() const class QQuickScrollBarAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener { public: - QQuickScrollBarAttachedPrivate(QQuickFlickable *flickable) - : flickable(flickable), + QQuickScrollBarAttachedPrivate() + : flickable(nullptr), horizontal(nullptr), vertical(nullptr) { @@ -727,14 +723,15 @@ void QQuickScrollBarAttachedPrivate::itemDestroyed(QQuickItem *item) vertical = nullptr; } -QQuickScrollBarAttached::QQuickScrollBarAttached(QQuickFlickable *flickable) - : QObject(*(new QQuickScrollBarAttachedPrivate(flickable)), flickable) +QQuickScrollBarAttached::QQuickScrollBarAttached(QObject *parent) + : QObject(*(new QQuickScrollBarAttachedPrivate), parent) { Q_D(QQuickScrollBarAttached); - if (flickable) { - QQuickItemPrivate *p = QQuickItemPrivate::get(flickable); - p->updateOrAddGeometryChangeListener(d, QQuickGeometryChange::Size); - } + d->flickable = qobject_cast<QQuickFlickable *>(parent); + if (d->flickable) + QQuickItemPrivate::get(d->flickable)->updateOrAddGeometryChangeListener(d, QQuickGeometryChange::Size); + else if (parent) + qmlWarning(parent) << "ScrollBar must be attached to a Flickable"; } QQuickScrollBarAttached::~QQuickScrollBarAttached() diff --git a/src/quicktemplates2/qquickscrollbar_p.h b/src/quicktemplates2/qquickscrollbar_p.h index 9709f183..512e0b06 100644 --- a/src/quicktemplates2/qquickscrollbar_p.h +++ b/src/quicktemplates2/qquickscrollbar_p.h @@ -144,7 +144,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollBarAttached : public QObject Q_PROPERTY(QQuickScrollBar *vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL) public: - explicit QQuickScrollBarAttached(QQuickFlickable *flickable); + explicit QQuickScrollBarAttached(QObject *parent = nullptr); ~QQuickScrollBarAttached(); QQuickScrollBar *horizontal() const; |