diff options
Diffstat (limited to 'src/qml/qml/qqmlengine_p.h')
-rw-r--r-- | src/qml/qml/qqmlengine_p.h | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index 26969467b8..7c820679ba 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -39,6 +39,7 @@ #include <QtCore/qmetaobject.h> #include <QtCore/qmutex.h> #include <QtCore/qpair.h> +#include <QtCore/qpointer.h> #include <QtCore/qproperty.h> #include <QtCore/qstack.h> #include <QtCore/qstring.h> @@ -57,14 +58,6 @@ class QQmlObjectCreator; class QQmlProfiler; class QQmlPropertyCapture; -struct QObjectForeign { - Q_GADGET - QML_FOREIGN(QObject) - QML_NAMED_ELEMENT(QtObject) - QML_ADDED_IN_VERSION(2, 0) - Q_CLASSINFO("QML.OmitFromQmlTypes", "true") -}; - // This needs to be declared here so that the pool for it can live in QQmlEnginePrivate. // The inline method definitions are in qqmljavascriptexpression_p.h class QQmlJavaScriptExpressionGuard : public QQmlNotifierEndpoint @@ -81,9 +74,16 @@ public: }; struct QPropertyChangeTrigger : QPropertyObserver { - QPropertyChangeTrigger(QQmlJavaScriptExpression *expression) : QPropertyObserver(&QPropertyChangeTrigger::trigger), m_expression(expression) {} - QQmlJavaScriptExpression * m_expression; - QObject *target = nullptr; + Q_DISABLE_COPY_MOVE(QPropertyChangeTrigger) + + QPropertyChangeTrigger(QQmlJavaScriptExpression *expression) + : QPropertyObserver(&QPropertyChangeTrigger::trigger) + , m_expression(expression) + { + } + + QPointer<QObject> target; + QQmlJavaScriptExpression *m_expression; int propertyIndex = 0; static void trigger(QPropertyObserver *, QUntypedPropertyData *); @@ -97,7 +97,7 @@ struct TriggerList : QPropertyChangeTrigger { TriggerList *next = nullptr; }; -class Q_QML_PRIVATE_EXPORT QQmlEnginePrivate : public QJSEnginePrivate +class Q_QML_EXPORT QQmlEnginePrivate : public QJSEnginePrivate { Q_DECLARE_PUBLIC(QQmlEngine) public: @@ -207,8 +207,8 @@ public: QQmlGadgetPtrWrapper *valueTypeInstance(QMetaType type) { int typeIndex = type.id(); - auto it = cachedValueTypeInstances.find(typeIndex); - if (it != cachedValueTypeInstances.end()) + auto it = cachedValueTypeInstances.constFind(typeIndex); + if (it != cachedValueTypeInstances.cend()) return *it; if (QQmlValueType *valueType = QQmlMetaType::valueType(type)) { @@ -245,35 +245,48 @@ public: } private: - class SingletonInstances : private QHash<QQmlType, QJSValue> + class SingletonInstances : private QHash<QQmlType::SingletonInstanceInfo::ConstPtr, QJSValue> { public: - void convertAndInsert(QV4::ExecutionEngine *engine, const QQmlType &type, QJSValue *value) + void convertAndInsert( + QV4::ExecutionEngine *engine, const QQmlType::SingletonInstanceInfo::ConstPtr &type, + QJSValue *value) { QJSValuePrivate::manageStringOnV4Heap(engine, value); insert(type, *value); } - void clear() { - for (auto it = constBegin(), end = constEnd(); it != end; ++it) { - QObject *instance = it.value().toQObject(); + void clear() + { + const auto canDelete = [](QObject *instance, const auto &siinfo) -> bool { if (!instance) - continue; + return false; + + if (!siinfo->url.isEmpty()) + return true; + + const auto *ddata = QQmlData::get(instance, false); + return !(ddata && ddata->indestructible && ddata->explicitIndestructibleSet); + }; + + for (auto it = constBegin(), end = constEnd(); it != end; ++it) { + auto *instance = it.value().toQObject(); + if (canDelete(instance, it.key())) + QQmlData::markAsDeleted(instance); + } - if (it.key().singletonInstanceInfo()->url.isEmpty()) { - const QQmlData *ddata = QQmlData::get(instance, false); - if (ddata && ddata->indestructible && ddata->explicitIndestructibleSet) - continue; - } + for (auto it = constBegin(), end = constEnd(); it != end; ++it) { + QObject *instance = it.value().toQObject(); - delete instance; + if (canDelete(instance, it.key())) + delete instance; } - QHash<QQmlType, QJSValue>::clear(); + QHash<QQmlType::SingletonInstanceInfo::ConstPtr, QJSValue>::clear(); } - using QHash<QQmlType, QJSValue>::value; - using QHash<QQmlType, QJSValue>::take; + using QHash<QQmlType::SingletonInstanceInfo::ConstPtr, QJSValue>::value; + using QHash<QQmlType::SingletonInstanceInfo::ConstPtr, QJSValue>::take; }; SingletonInstances singletonInstances; @@ -371,7 +384,7 @@ QQmlEnginePrivate *QQmlEnginePrivate::get(QV4::ExecutionEngine *e) } template<> -Q_QML_PRIVATE_EXPORT QJSValue QQmlEnginePrivate::singletonInstance<QJSValue>(const QQmlType &type); +Q_QML_EXPORT QJSValue QQmlEnginePrivate::singletonInstance<QJSValue>(const QQmlType &type); template<typename T> T QQmlEnginePrivate::singletonInstance(const QQmlType &type) { |