aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlpropertycache_p.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-03-10 11:44:27 +0100
committerUlf Hermann <ulf.hermann@qt.io>2022-03-14 16:44:35 +0100
commite5246cafffb93f69a49c133210390c253fcb71f2 (patch)
tree9e820afecc52b7ced9c98979f4e90b7892d024be /src/qml/qml/qqmlpropertycache_p.h
parent4015665bbd1e0f9d5af5dc6618275f1170b55bec (diff)
Use const QQmlPropertyCache wherever possible
We're not supposed to modify property caches after they've been created. Task-number: QTBUG-73271 Change-Id: I0ab8ed6750508fa4e28931995142f56cd5fa3061 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlpropertycache_p.h')
-rw-r--r--src/qml/qml/qqmlpropertycache_p.h34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h
index 9762cdef5a..1f52d9abba 100644
--- a/src/qml/qml/qqmlpropertycache_p.h
+++ b/src/qml/qml/qqmlpropertycache_p.h
@@ -147,6 +147,18 @@ private:
class Q_QML_PRIVATE_EXPORT QQmlPropertyCache : public QQmlRefCount
{
public:
+ using Ptr = QQmlRefPointer<QQmlPropertyCache>;
+
+ struct ConstPtr : public QQmlRefPointer<const QQmlPropertyCache>
+ {
+ using QQmlRefPointer<const QQmlPropertyCache>::QQmlRefPointer;
+
+ ConstPtr(const Ptr &ptr) : ConstPtr(ptr.data(), AddRef) {}
+ ConstPtr(Ptr &&ptr) : ConstPtr(ptr.take(), Adopt) {}
+ ConstPtr &operator=(const Ptr &ptr) { return operator=(ConstPtr(ptr)); }
+ ConstPtr &operator=(Ptr &&ptr) { return operator=(ConstPtr(std::move(ptr))); }
+ };
+
QQmlPropertyCache() = default;
QQmlPropertyCache(const QMetaObject *, QTypeRevision metaObjectRevision = QTypeRevision::zero());
~QQmlPropertyCache() override;
@@ -154,16 +166,16 @@ public:
void update(const QMetaObject *);
void invalidate(const QMetaObject *);
- QQmlRefPointer<QQmlPropertyCache> copy();
+ QQmlPropertyCache::Ptr copy() const;
- QQmlRefPointer<QQmlPropertyCache> copyAndAppend(
+ QQmlPropertyCache::Ptr copyAndAppend(
const QMetaObject *, QTypeRevision typeVersion,
QQmlPropertyData::Flags propertyFlags = QQmlPropertyData::Flags(),
QQmlPropertyData::Flags methodFlags = QQmlPropertyData::Flags(),
- QQmlPropertyData::Flags signalFlags = QQmlPropertyData::Flags());
+ QQmlPropertyData::Flags signalFlags = QQmlPropertyData::Flags()) const;
- QQmlRefPointer<QQmlPropertyCache> copyAndReserve(
- int propertyCount, int methodCount, int signalCount, int enumCount);
+ QQmlPropertyCache::Ptr copyAndReserve(
+ int propertyCount, int methodCount, int signalCount, int enumCount) const;
void appendProperty(const QString &, QQmlPropertyData::Flags flags, int coreIndex,
QMetaType propType, QTypeRevision revision, int notifyIndex);
void appendSignal(const QString &, QQmlPropertyData::Flags, int coreIndex,
@@ -196,10 +208,10 @@ public:
QQmlPropertyData *defaultProperty() const;
// Return a reference here so that we don't have to addref/release all the time
- inline const QQmlRefPointer<QQmlPropertyCache> &parent() const;
+ inline const QQmlPropertyCache::ConstPtr &parent() const;
// is used by the Qml Designer
- void setParent(QQmlRefPointer<QQmlPropertyCache> newParent);
+ void setParent(QQmlPropertyCache::ConstPtr newParent);
inline QQmlPropertyData *overrideData(QQmlPropertyData *) const;
inline bool isAllowedInRevision(QQmlPropertyData *) const;
@@ -215,7 +227,7 @@ public:
QQmlPropertyData *);
//see QMetaObjectPrivate::originalClone
- int originalClone(int index);
+ int originalClone(int index) const;
static int originalClone(const QObject *, int index);
QList<QByteArray> signalParameterNames(int index) const;
@@ -253,7 +265,7 @@ private:
QQmlPropertyCache(const QQmlMetaObjectPointer &metaObject) : _metaObject(metaObject) {}
- inline QQmlRefPointer<QQmlPropertyCache> copy(const QQmlMetaObjectPointer &mo, int reserve);
+ inline QQmlPropertyCache::Ptr copy(const QQmlMetaObjectPointer &mo, int reserve) const;
void append(const QMetaObject *, QTypeRevision typeVersion,
QQmlPropertyData::Flags propertyFlags = QQmlPropertyData::Flags(),
@@ -311,7 +323,7 @@ private:
}
int propertyIndexCacheStart = 0; // placed here to avoid gap between QQmlRefCount and _parent
- QQmlRefPointer<QQmlPropertyCache> _parent;
+ QQmlPropertyCache::ConstPtr _parent;
IndexCache propertyIndexCache;
IndexCache methodIndexCache;
@@ -412,7 +424,7 @@ inline QString QQmlPropertyCache::defaultPropertyName() const
return _defaultPropertyName;
}
-inline const QQmlRefPointer<QQmlPropertyCache> &QQmlPropertyCache::parent() const
+inline const QQmlPropertyCache::ConstPtr &QQmlPropertyCache::parent() const
{
return _parent;
}