From 93b68f9a12198f226a8d59717bc1cd36d47c5dbe Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 18 Aug 2016 16:12:27 +0200 Subject: QQuickToolTip: fix destruction of the shared tooltip Make the QML engine the parent of the shared tooltip instance, and make sure the instances are per engine. This ensures that the shared tooltip gets properly destructed when the associated QML engine is destructed. The same technique is used for the global styles in QQuickStyleAttached. Change-Id: I08dcb4f9bc6ddafb7449afe43362e560c0952e88 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquicktooltip.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/quicktemplates2/qquicktooltip.cpp') diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index cc0b6350..65e81fda 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -325,7 +325,13 @@ public: QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const { - static QPointer tip; + QQmlEngine *engine = qmlEngine(parent); + if (!engine) + return nullptr; + + static const char *name = "_q_QQuickToolTip"; + + QQuickToolTip *tip = engine->property(name).value(); if (!tip && create) { // TODO: a cleaner way to create the instance? QQml(Meta)Type? QQmlContext *context = qmlContext(parent); @@ -334,9 +340,14 @@ QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const component.setData("import QtQuick.Controls 2.0; ToolTip { }", QUrl()); QObject *object = component.create(context); + if (object) + object->setParent(engine); + tip = qobject_cast(object); if (!tip) delete object; + else + engine->setProperty(name, QVariant::fromValue(object)); } } return tip; -- cgit v1.2.3 From 449a655fd7c1b049ea2cc57033987a2556aadcd8 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 17 Aug 2016 19:30:25 +0200 Subject: Fix attached ToolTip properties The attached properties should apply to the shared/global tooltip instance only when the shared tooltip is visible for the attachee item. Task-number: QTBUG-55347 Change-Id: Ia822f2d1de62d2d6dfb28519817edce674d8c2b8 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquicktooltip.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/quicktemplates2/qquicktooltip.cpp') diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index 65e81fda..d47589ba 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -379,8 +379,8 @@ void QQuickToolTipAttached::setText(const QString &text) d->text = text; emit textChanged(); - if (QQuickToolTip *tip = d->instance(true)) - tip->setText(text); + if (isVisible()) + d->instance(true)->setText(text); } /*! @@ -405,6 +405,9 @@ void QQuickToolTipAttached::setDelay(int delay) d->delay = delay; emit delayChanged(); + + if (isVisible()) + d->instance(true)->setDelay(delay); } /*! @@ -429,6 +432,9 @@ void QQuickToolTipAttached::setTimeout(int timeout) d->timeout = timeout; emit timeoutChanged(); + + if (isVisible()) + d->instance(true)->setTimeout(timeout); } /*! -- cgit v1.2.3 From 53c780f15c2d170514f74d949a8165033275bddd Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 19 Aug 2016 17:42:15 +0200 Subject: QQuickToolTip: fix the creation context of the shared tooltip Don't create the shared tooltip in the parent item's context, because that may be destroyed and invalidate all bindings in ToolTip.qml. The QML engine is the effective parent of the shared tooltip, so use the engine's root context for creation as well. We do not need to pass any specific context to QQmlComponent::create(), because it will pick the root context by default. Change-Id: I624b53fa9ba02123398e76b5eccf1a8091826b37 Task-number: QTBUG-55347 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquicktooltip.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src/quicktemplates2/qquicktooltip.cpp') diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index d47589ba..e08078f6 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -334,21 +334,18 @@ QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const QQuickToolTip *tip = engine->property(name).value(); if (!tip && create) { // TODO: a cleaner way to create the instance? QQml(Meta)Type? - QQmlContext *context = qmlContext(parent); - if (context) { - QQmlComponent component(context->engine()); - component.setData("import QtQuick.Controls 2.0; ToolTip { }", QUrl()); - - QObject *object = component.create(context); - if (object) - object->setParent(engine); - - tip = qobject_cast(object); - if (!tip) - delete object; - else - engine->setProperty(name, QVariant::fromValue(object)); - } + QQmlComponent component(engine); + component.setData("import QtQuick.Controls 2.0; ToolTip { }", QUrl()); + + QObject *object = component.create(); + if (object) + object->setParent(engine); + + tip = qobject_cast(object); + if (!tip) + delete object; + else + engine->setProperty(name, QVariant::fromValue(object)); } return tip; } -- cgit v1.2.3