6#include <private/qobjectregistrysingleton_p.h>
11
12
13
14
15
16
17
18
19
20
21
22
23
26
27
28
29
30
31
32
33
34
35
36
37
38
41
42
43
44
47
48
49
50
53
54
55
56
59QAbstractObjectRegistryRef::QAbstractObjectRegistryRef(QAbstractObjectRegistryRefPrivate &dd,
64QAbstractObjectRegistryRef::~QAbstractObjectRegistryRef()
66 Q_D(QAbstractObjectRegistryRef);
69 d->m_registry->deregisterRef(d);
72QString QAbstractObjectRegistryRef::key()
const
74 Q_D(
const QAbstractObjectRegistryRef);
79void QAbstractObjectRegistryRef::setKey(
const QString &key)
81 Q_D(QAbstractObjectRegistryRef);
87 d->m_registry = QObjectRegistrySingleton::registryForObject(
this);
89 qWarning() <<
"Object registry could not be resolved for ("
91 <<
") when setting key to QAbstractObjectRegistryRef."
92 <<
" Most likely reason for this is that QML engine could not be resolved.";
94 emit keyChanged(d->m_key);
99 if (!d->m_key.isEmpty() && d->m_registry)
100 d->m_registry->deregisterRef(d);
104 if (!d->m_key.isEmpty() && d->m_registry)
105 d->m_registry->registerRef(d);
107 d->handleInitialObjects();
109 emit keyChanged(d->m_key);
112QQmlListProperty<QObject> QAbstractObjectRegistryRef::data()
114 return {
this,
nullptr,
115 &QAbstractObjectRegistryRefPrivate::dataAppend,
116 &QAbstractObjectRegistryRefPrivate::dataCount,
117 &QAbstractObjectRegistryRefPrivate::dataAt,
118 &QAbstractObjectRegistryRefPrivate::dataClear,
119 &QAbstractObjectRegistryRefPrivate::dataReplace,
120 &QAbstractObjectRegistryRefPrivate::dataRemoveLast };
124
125
126bool QAbstractObjectRegistryRef::event(QEvent *event)
128 return QObject::event(event);
131QAbstractObjectRegistryRefPrivate::QAbstractObjectRegistryRefPrivate(QQmlEngine *engine)
133 m_registry = QObjectRegistrySingleton::registryForEngine(engine);
136QString QAbstractObjectRegistryRefPrivate::key()
const
141QObjectRegistrySingleton *QAbstractObjectRegistryRefPrivate::registry()
const
146void QAbstractObjectRegistryRefPrivate::dataAppend(QQmlListProperty<QObject> *l, QObject *o)
148 auto *self =
static_cast<QAbstractObjectRegistryRef *>(l->object);
149 self->d_func()->m_data.append(o);
151 emit self->dataChanged();
154qsizetype QAbstractObjectRegistryRefPrivate::dataCount(QQmlListProperty<QObject> *l)
156 return static_cast<QAbstractObjectRegistryRef *>(l->object)->d_func()->m_data.size();
159QObject *QAbstractObjectRegistryRefPrivate::dataAt(QQmlListProperty<QObject> *l, qsizetype i)
161 return static_cast<QAbstractObjectRegistryRef *>(l->object)->d_func()->m_data.at(i);
164void QAbstractObjectRegistryRefPrivate::dataClear(QQmlListProperty<QObject> *l)
166 auto *self =
static_cast<QAbstractObjectRegistryRef *>(l->object);
168 if (self->d_func()->m_data.isEmpty())
171 self->d_func()->m_data.clear();
173 emit self->dataChanged();
176void QAbstractObjectRegistryRefPrivate::dataReplace(QQmlListProperty<QObject> *l, qsizetype i, QObject *o)
178 auto *self =
static_cast<QAbstractObjectRegistryRef *>(l->object);
180 if (o == self->d_func()->m_data.at(i))
183 self->d_func()->m_data.replace(i, o);
185 emit self->dataChanged();
188void QAbstractObjectRegistryRefPrivate::dataRemoveLast(QQmlListProperty<QObject> *l)
190 auto *self =
static_cast<QAbstractObjectRegistryRef *>(l->object);
192 if (self->d_func()->m_data.isEmpty())
195 self->d_func()->m_data.removeLast();
197 emit self->dataChanged();
Combined button and popup list for selecting options.