aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp12
-rw-r--r--src/qml/qml/qqmlpropertycache_p.h2
-rw-r--r--tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp21
3 files changed, 33 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index 95bdcf13e8..629717dd9f 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -252,12 +252,22 @@ QQmlPropertyCache::QQmlPropertyCache()
/*!
Creates a new QQmlPropertyCache of \a metaObject.
*/
-QQmlPropertyCache::QQmlPropertyCache(const QMetaObject *metaObject)
+QQmlPropertyCache::QQmlPropertyCache(const QMetaObject *metaObject, int metaObjectRevision)
: QQmlPropertyCache()
{
Q_ASSERT(metaObject);
update(metaObject);
+
+ if (metaObjectRevision > 0) {
+ // Set the revision of the meta object that this cache describes to be
+ // 'metaObjectRevision'. This is useful when constructing a property cache
+ // from a type that was created directly in C++, and not through QML. For such
+ // types, the revision for each recorded QMetaObject would normally be zero, which
+ // would exclude any revisioned properties.
+ for (int metaObjectOffset = 0; metaObjectOffset < allowedRevisionCache.size(); ++metaObjectOffset)
+ allowedRevisionCache[metaObjectOffset] = metaObjectRevision;
+ }
}
QQmlPropertyCache::~QQmlPropertyCache()
diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h
index 0785910cec..a7cbd506f9 100644
--- a/src/qml/qml/qqmlpropertycache_p.h
+++ b/src/qml/qml/qqmlpropertycache_p.h
@@ -394,7 +394,7 @@ class Q_QML_PRIVATE_EXPORT QQmlPropertyCache : public QQmlRefCount
{
public:
QQmlPropertyCache();
- QQmlPropertyCache(const QMetaObject *);
+ QQmlPropertyCache(const QMetaObject *, int metaObjectRevision = 0);
~QQmlPropertyCache() override;
void update(const QMetaObject *);
diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
index f577a091eb..69c6ce2d35 100644
--- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
+++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
@@ -45,6 +45,7 @@ public:
private slots:
void properties();
void propertiesDerived();
+ void revisionedProperties();
void methods();
void methodsDerived();
void signalHandlers();
@@ -84,11 +85,13 @@ class DerivedObject : public BaseObject
Q_OBJECT
Q_PROPERTY(int propertyC READ propertyC NOTIFY propertyCChanged)
Q_PROPERTY(QString propertyD READ propertyD NOTIFY propertyDChanged)
+ Q_PROPERTY(int propertyE READ propertyE NOTIFY propertyEChanged REVISION 1)
public:
DerivedObject(QObject *parent = nullptr) : BaseObject(parent) {}
int propertyC() const { return 0; }
QString propertyD() const { return QString(); }
+ int propertyE() const { return 0; }
public Q_SLOTS:
void slotB() {}
@@ -96,6 +99,7 @@ public Q_SLOTS:
Q_SIGNALS:
void propertyCChanged();
void propertyDChanged();
+ Q_REVISION(1) void propertyEChanged();
void signalB();
};
@@ -149,6 +153,23 @@ void tst_qqmlpropertycache::propertiesDerived()
QCOMPARE(data->coreIndex(), metaObject->indexOfProperty("propertyD"));
}
+void tst_qqmlpropertycache::revisionedProperties()
+{
+ // Check that if you create a QQmlPropertyCache from a QMetaObject together
+ // with an explicit revision, the cache will then, and only then, report a
+ // property with a matching revision as available.
+ DerivedObject object;
+ const QMetaObject *metaObject = object.metaObject();
+
+ QQmlRefPointer<QQmlPropertyCache> cacheWithoutVersion(new QQmlPropertyCache(metaObject));
+ QQmlRefPointer<QQmlPropertyCache> cacheWithVersion(new QQmlPropertyCache(metaObject, 1));
+ QQmlPropertyData *data;
+
+ QVERIFY((data = cacheProperty(cacheWithoutVersion, "propertyE")));
+ QCOMPARE(cacheWithoutVersion->isAllowedInRevision(data), false);
+ QCOMPARE(cacheWithVersion->isAllowedInRevision(data), true);
+}
+
void tst_qqmlpropertycache::methods()
{
QQmlEngine engine;