aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlmetatype.cpp2
-rw-r--r--src/qml/qml/qqmlmetatypedata.cpp2
-rw-r--r--src/qml/qml/qqmltype.cpp68
-rw-r--r--src/qml/qml/qqmltype_p.h26
-rw-r--r--src/qml/qml/qqmltype_p_p.h8
-rw-r--r--src/qml/qml/qqmltypewrapper_p.h4
6 files changed, 43 insertions, 67 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index a034d72221..0da96f61e4 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -1220,7 +1220,7 @@ void QQmlMetaType::freeUnusedTypesAndCaches()
QList<QQmlType>::Iterator it = data->types.begin();
while (it != data->types.end()) {
const QQmlTypePrivate *d = (*it).priv();
- if (d && d->refCount == 1) {
+ if (d && d->count() == 1) {
deletedAtLeastOneType = true;
removeQQmlTypePrivate(data->idToType, d);
diff --git a/src/qml/qml/qqmlmetatypedata.cpp b/src/qml/qml/qqmlmetatypedata.cpp
index da5b4ec075..13c46e4911 100644
--- a/src/qml/qml/qqmlmetatypedata.cpp
+++ b/src/qml/qml/qqmlmetatypedata.cpp
@@ -74,7 +74,7 @@ void QQmlMetaTypeData::registerType(QQmlTypePrivate *priv)
}
types.append(QQmlType(priv));
priv->index = types.count() - 1;
- priv->refCount.deref();
+ priv->release();
}
QQmlPropertyCache *QQmlMetaTypeData::propertyCache(const QMetaObject *metaObject, int minorVersion)
diff --git a/src/qml/qml/qqmltype.cpp b/src/qml/qml/qqmltype.cpp
index a4adb18f76..efe190cbcf 100644
--- a/src/qml/qml/qqmltype.cpp
+++ b/src/qml/qml/qqmltype.cpp
@@ -116,7 +116,7 @@ QJSValue QQmlType::SingletonInstanceInfo::scriptApi(QQmlEngine *e) const
}
QQmlTypePrivate::QQmlTypePrivate(QQmlType::RegistrationType type)
- : refCount(1), regType(type), iid(nullptr), typeId(0), listId(0), revision(0),
+ : regType(type), iid(nullptr), typeId(0), listId(0), revision(0),
containsRevisionedAttributes(false), baseMetaObject(nullptr),
index(-1), isSetup(false), isEnumSetup(false), haveSuperType(false)
{
@@ -155,6 +155,10 @@ QQmlTypePrivate::~QQmlTypePrivate()
qDeleteAll(scopedEnums);
switch (regType) {
case QQmlType::CppType:
+ // If attached properties were successfully registered, deregister them.
+ // (They may not have been registered if some other type used the same baseMetaObject)
+ if (extraData.cd->attachedPropertiesType)
+ QQmlMetaType::unregisterAttachedPropertyId(baseMetaObject, index);
delete extraData.cd->customParser;
delete extraData.cd;
break;
@@ -171,47 +175,13 @@ QQmlTypePrivate::~QQmlTypePrivate()
}
}
-QQmlType::QQmlType()
- : d(nullptr)
-{
-}
-
-QQmlType::QQmlType(const QQmlType &other)
- : d(other.d)
-{
- if (d)
- d->refCount.ref();
-}
-
-QQmlType &QQmlType::operator =(const QQmlType &other)
-{
- if (d != other.d) {
- if (d && !d->refCount.deref())
- delete d;
- d = other.d;
- if (d)
- d->refCount.ref();
- }
- return *this;
-}
-
-QQmlType::QQmlType(QQmlTypePrivate *priv)
- : d(priv)
-{
- if (d)
- d->refCount.ref();
-}
-
-QQmlType::~QQmlType()
-{
- if (d && !d->refCount.deref()) {
- // If attached properties were successfully registered, deregister them.
- // (They may not have been registered if some other type used the same baseMetaObject)
- if (d->regType == CppType && d->extraData.cd->attachedPropertiesType)
- QQmlMetaType::unregisterAttachedPropertyId(d->baseMetaObject, d->index);
- delete d;
- }
-}
+QQmlType::QQmlType() = default;
+QQmlType::QQmlType(const QQmlType &other) = default;
+QQmlType::QQmlType(QQmlType &&other) = default;
+QQmlType &QQmlType::operator =(const QQmlType &other) = default;
+QQmlType &QQmlType::operator =(QQmlType &&other) = default;
+QQmlType::QQmlType(const QQmlTypePrivate *priv) : d(priv) {}
+QQmlType::~QQmlType() = default;
QHashedString QQmlType::module() const
{
@@ -985,22 +955,22 @@ int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, const QStringRef &scope
return -1;
}
-void QQmlType::refHandle(QQmlTypePrivate *priv)
+void QQmlType::refHandle(const QQmlTypePrivate *priv)
{
if (priv)
- priv->refCount.ref();
+ priv->addref();
}
-void QQmlType::derefHandle(QQmlTypePrivate *priv)
+void QQmlType::derefHandle(const QQmlTypePrivate *priv)
{
- if (priv && !priv->refCount.deref())
- delete priv;
+ if (priv)
+ priv->release();
}
-int QQmlType::refCount(QQmlTypePrivate *priv)
+int QQmlType::refCount(const QQmlTypePrivate *priv)
{
if (priv)
- return priv->refCount;
+ return priv->count();
return -1;
}
diff --git a/src/qml/qml/qqmltype_p.h b/src/qml/qml/qqmltype_p.h
index 969c096aeb..1d1345a0cb 100644
--- a/src/qml/qml/qqmltype_p.h
+++ b/src/qml/qml/qqmltype_p.h
@@ -52,6 +52,7 @@
//
#include <private/qtqmlglobal_p.h>
+#include <private/qqmlrefcount_p.h>
#include <QtQml/qqmlprivate.h>
#include <QtQml/qjsvalue.h>
@@ -77,16 +78,18 @@ class Q_QML_PRIVATE_EXPORT QQmlType
public:
QQmlType();
QQmlType(const QQmlType &other);
+ QQmlType(QQmlType &&other);
QQmlType &operator =(const QQmlType &other);
- explicit QQmlType(QQmlTypePrivate *priv);
+ QQmlType &operator =(QQmlType &&other);
+ explicit QQmlType(const QQmlTypePrivate *priv);
~QQmlType();
bool operator ==(const QQmlType &other) const {
- return d == other.d;
+ return d.data() == other.d.data();
}
- bool isValid() const { return d != nullptr; }
- const QQmlTypePrivate *key() const { return d; }
+ bool isValid() const { return !d.isNull(); }
+ const QQmlTypePrivate *key() const { return d.data(); }
QByteArray typeName() const;
QString qmlTypeName() const;
@@ -174,10 +177,10 @@ public:
int scopedEnumValue(QQmlEnginePrivate *engine, const QByteArray &, const QByteArray &, bool *ok) const;
int scopedEnumValue(QQmlEnginePrivate *engine, const QStringRef &, const QStringRef &, bool *ok) const;
- QQmlTypePrivate *priv() const { return d; }
- static void refHandle(QQmlTypePrivate *priv);
- static void derefHandle(QQmlTypePrivate *priv);
- static int refCount(QQmlTypePrivate *priv);
+ const QQmlTypePrivate *priv() const { return d.data(); }
+ static void refHandle(const QQmlTypePrivate *priv);
+ static void derefHandle(const QQmlTypePrivate *priv);
+ static int refCount(const QQmlTypePrivate *priv);
enum RegistrationType {
CppType = 0,
@@ -195,10 +198,13 @@ private:
QQmlPropertyCache *compositePropertyCache(QQmlEnginePrivate *engine) const;
friend uint qHash(const QQmlType &t, uint seed);
- QQmlTypePrivate *d;
+ QQmlRefPointer<const QQmlTypePrivate> d;
};
-inline uint qHash(const QQmlType &t, uint seed = 0) { return qHash(reinterpret_cast<quintptr>(t.d), seed); }
+inline uint qHash(const QQmlType &t, uint seed = 0)
+{
+ return qHash(reinterpret_cast<quintptr>(t.d.data()), seed);
+}
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmltype_p_p.h b/src/qml/qml/qqmltype_p_p.h
index 51984dd360..380139f385 100644
--- a/src/qml/qml/qqmltype_p_p.h
+++ b/src/qml/qml/qqmltype_p_p.h
@@ -59,19 +59,17 @@
QT_BEGIN_NAMESPACE
-class QQmlTypePrivate
+class QQmlTypePrivate : public QQmlRefCount
{
- Q_DISABLE_COPY(QQmlTypePrivate)
+ Q_DISABLE_COPY_MOVE(QQmlTypePrivate)
public:
QQmlTypePrivate(QQmlType::RegistrationType type);
- ~QQmlTypePrivate();
void init() const;
void initEnums(const QQmlPropertyCache *cache = nullptr) const;
void insertEnums(const QMetaObject *metaObject) const;
void insertEnumsFromPropertyCache(const QQmlPropertyCache *cache) const;
- QAtomicInt refCount;
QQmlType::RegistrationType regType;
struct QQmlCppTypeData
@@ -143,6 +141,8 @@ public:
void setName(const QString &uri, const QString &element);
private:
+ ~QQmlTypePrivate() override;
+
struct EnumInfo {
QStringList path;
QString metaObjectName;
diff --git a/src/qml/qml/qqmltypewrapper_p.h b/src/qml/qml/qqmltypewrapper_p.h
index fa1ad56902..bc615e0f6c 100644
--- a/src/qml/qml/qqmltypewrapper_p.h
+++ b/src/qml/qml/qqmltypewrapper_p.h
@@ -81,7 +81,7 @@ struct QQmlTypeWrapper : Object {
QQmlType type() const;
- QQmlTypePrivate *typePrivate;
+ const QQmlTypePrivate *typePrivate;
QQmlTypeNameCache *typeNamespace;
const QQmlImportRef *importNamespace;
};
@@ -90,7 +90,7 @@ struct QQmlScopedEnumWrapper : Object {
void init() { Object::init(); }
void destroy();
int scopeEnumIndex;
- QQmlTypePrivate *typePrivate;
+ const QQmlTypePrivate *typePrivate;
QQmlType type() const;
};