From f9e61de51bfdad6437b198932f8723468a1aa33c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 8 May 2015 20:23:00 +0200 Subject: [PATCH] hopefully fix Plasmoid attached property Change-Id: I57d6d443b0a2f94e986e11e0e5cfb1ac6e6884bc --- src/plasmaquick/appletquickitem.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plasmaquick/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp index 17751ba90..a1ad7d2ec 100644 --- a/src/plasmaquick/appletquickitem.cpp +++ b/src/plasmaquick/appletquickitem.cpp @@ -407,15 +407,25 @@ AppletQuickItem::~AppletQuickItem() delete d->fullRepresentationItem; delete d->compactRepresentationExpanderItem; - AppletQuickItemPrivate::s_rootObjects.remove(d->qmlObject->engine()); + AppletQuickItemPrivate::s_rootObjects.remove(d->qmlObject->rootContext()); } AppletQuickItem *AppletQuickItem::qmlAttachedProperties(QObject *object) { + QQmlContext *context = QtQml::qmlContext(object); + //search the root context of the applet in which the object is in + while (context) { + //the rootcontext of an applet is a child of the engine root context + if (context->parentContext() == QtQml::qmlEngine(object)->rootContext()) { + break; + } + + context = context->parentContext(); + } //at the moment of the attached object creation, the root item is the only one that hasn't a parent //only way to avoid creation of this attached for everybody but the root item - if (!object->parent() && AppletQuickItemPrivate::s_rootObjects.contains(QtQml::qmlEngine(object))) { - return AppletQuickItemPrivate::s_rootObjects.value(QtQml::qmlEngine(object)); + if (!object->parent() && AppletQuickItemPrivate::s_rootObjects.contains(context)) { + return AppletQuickItemPrivate::s_rootObjects.value(context); } else { return 0; } @@ -429,11 +439,11 @@ Plasma::Applet *AppletQuickItem::applet() const void AppletQuickItem::init() { //FIXME: Plasmoid attached property should be fixed since can't be indexed by engine anymore - if (0&&AppletQuickItemPrivate::s_rootObjects.contains(d->qmlObject->engine())) { + if (0&&AppletQuickItemPrivate::s_rootObjects.contains(d->qmlObject->rootContext())) { return; } - AppletQuickItemPrivate::s_rootObjects[d->qmlObject->engine()] = this; + AppletQuickItemPrivate::s_rootObjects[d->qmlObject->rootContext()] = this; Q_ASSERT(d->applet);