38 QML_NAMED_ELEMENT(InternalObjectRegistry)
41 explicit QObjectRegistrySingleton(QObject *parent =
nullptr);
42 ~QObjectRegistrySingleton();
44 void registerRef(QAbstractObjectRegistryRefPrivate *ref);
45 void deregisterRef(QAbstractObjectRegistryRefPrivate *ref);
47 void add(
const QString &key, QObject *obj);
48 void remove(
const QString &key, QObject *obj);
49 QSet<QObject*> objects(
const QString &key)
const;
51 static QObjectRegistrySingleton *registryForObject(QObject *obj);
52 static QObjectRegistrySingleton *registryForEngine(QQmlEngine *engine);
55 enum class Notification { ObjectAdded, ObjectRemoved };
57 void notifyRefs(
const QString &key, QObject *obj, Notification notification);
59 class ObjectGuard :
public QQmlGuard<QObject>
62 ObjectGuard(QObjectRegistrySingleton *owner,
const QString &key, QObject *obj)
63 : QQmlGuard<QObject>(&ObjectGuard::objectDestroyedImpl, obj)
71 static void objectDestroyedImpl(QQmlGuardImpl *guard)
73 ObjectGuard *self =
static_cast<ObjectGuard *>(guard);
74 QObjectRegistrySingleton *owner = self->m_owner;
75 const QString key = self->m_key;
76 QObject *obj = self->m_object;
78 owner->remove(key, obj);
81 QObjectRegistrySingleton *m_owner =
nullptr;
83 QObject *m_object =
nullptr;
86 QHash<QString, QHash<QObject *, ObjectGuard *>> m_objects;
87 QHash<QString, QSet<QAbstractObjectRegistryRefPrivate *>> m_refs;