aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlmetatype.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2017-06-23 17:19:26 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2017-08-02 16:32:53 +0000
commitaa6120cc3524b8d603e92e952aece7494a5d8f02 (patch)
treec391e271f232d4174f6ef1c22e4a0442f8f57ba9 /src/qml/qml/qqmlmetatype.cpp
parentc6b2dd879d02b21b18f80faab541f8f04286685a (diff)
Remove QQmlEnginePrivate::typePropertyCache
Instead of maintaining a hash per QQmlType and minor version, move the version specific property caches into QQmlType. Task-number: QTBUG-61536 Change-Id: I72f3990cb93e64ac5074060b4ff327043eab7966 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r--src/qml/qml/qqmlmetatype.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index a2b6913943..9dd0c14723 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -113,6 +113,7 @@ struct QQmlMetaTypeData
QHash<const QMetaObject *, QQmlPropertyCache *> propertyCaches;
QQmlPropertyCache *propertyCache(const QMetaObject *metaObject);
+ QQmlPropertyCache *propertyCache(const QQmlType &type, int minorVersion);
};
class QQmlTypeModulePrivate
@@ -226,6 +227,17 @@ public:
mutable QStringHash<int> enums;
static QHash<const QMetaObject *, int> attachedPropertyIds;
+
+ struct PropertyCacheByMinorVersion
+ {
+ PropertyCacheByMinorVersion() : cache(nullptr), minorVersion(-1) {}
+ explicit PropertyCacheByMinorVersion(QQmlPropertyCache *pc, int ver) : cache(pc), minorVersion(ver) {}
+ QQmlPropertyCachePtr cache;
+ int minorVersion;
+ };
+ QVector<PropertyCacheByMinorVersion> propertyCaches;
+ QQmlPropertyCache *propertyCacheForMinorVersion(int minorVersion) const;
+ void setPropertyCacheForMinorVersion(int minorVersion, QQmlPropertyCache *cache);
};
void QQmlType::SingletonInstanceInfo::init(QQmlEngine *e)
@@ -780,6 +792,25 @@ void QQmlTypePrivate::insertEnums(const QMetaObject *metaObject) const
}
}
+QQmlPropertyCache *QQmlTypePrivate::propertyCacheForMinorVersion(int minorVersion) const
+{
+ for (int i = 0; i < propertyCaches.count(); ++i)
+ if (propertyCaches.at(i).minorVersion == minorVersion)
+ return propertyCaches.at(i).cache;
+ return nullptr;
+}
+
+void QQmlTypePrivate::setPropertyCacheForMinorVersion(int minorVersion, QQmlPropertyCache *cache)
+{
+ for (int i = 0; i < propertyCaches.count(); ++i) {
+ if (propertyCaches.at(i).minorVersion == minorVersion) {
+ propertyCaches[i].cache = cache;
+ return;
+ }
+ }
+ propertyCaches.append(PropertyCacheByMinorVersion(cache, minorVersion));
+}
+
QByteArray QQmlType::typeName() const
{
if (d) {
@@ -2010,6 +2041,118 @@ QQmlPropertyCache *QQmlMetaType::propertyCache(const QMetaObject *metaObject)
return data->propertyCache(metaObject);
}
+QQmlPropertyCache *QQmlMetaTypeData::propertyCache(const QQmlType &type, int minorVersion)
+{
+ Q_ASSERT(type.isValid());
+
+ if (QQmlPropertyCache *pc = type.key()->propertyCacheForMinorVersion(minorVersion))
+ return pc;
+
+ QVector<QQmlType> types;
+
+ int maxMinorVersion = 0;
+
+ const QMetaObject *metaObject = type.metaObject();
+
+ while (metaObject) {
+ QQmlType t = QQmlMetaType::qmlType(metaObject, type.module(), type.majorVersion(), minorVersion);
+ if (t.isValid()) {
+ maxMinorVersion = qMax(maxMinorVersion, t.minorVersion());
+ types << t;
+ } else {
+ types << 0;
+ }
+
+ metaObject = metaObject->superClass();
+ }
+
+ if (QQmlPropertyCache *pc = type.key()->propertyCacheForMinorVersion(maxMinorVersion)) {
+ const_cast<QQmlTypePrivate*>(type.key())->setPropertyCacheForMinorVersion(minorVersion, pc);
+ return pc;
+ }
+
+ QQmlPropertyCache *raw = propertyCache(type.metaObject());
+
+ bool hasCopied = false;
+
+ for (int ii = 0; ii < types.count(); ++ii) {
+ QQmlType currentType = types.at(ii);
+ if (!currentType.isValid())
+ continue;
+
+ int rev = currentType.metaObjectRevision();
+ int moIndex = types.count() - 1 - ii;
+
+ if (raw->allowedRevisionCache[moIndex] != rev) {
+ if (!hasCopied) {
+ raw = raw->copy();
+ hasCopied = true;
+ }
+ raw->allowedRevisionCache[moIndex] = rev;
+ }
+ }
+
+ // Test revision compatibility - the basic rule is:
+ // * Anything that is excluded, cannot overload something that is not excluded *
+
+ // Signals override:
+ // * other signals and methods of the same name.
+ // * properties named on<Signal Name>
+ // * automatic <property name>Changed notify signals
+
+ // Methods override:
+ // * other methods of the same name
+
+ // Properties override:
+ // * other elements of the same name
+
+#if 0
+ bool overloadError = false;
+ QString overloadName;
+
+ for (QQmlPropertyCache::StringCache::ConstIterator iter = raw->stringCache.begin();
+ !overloadError && iter != raw->stringCache.end();
+ ++iter) {
+
+ QQmlPropertyData *d = *iter;
+ if (raw->isAllowedInRevision(d))
+ continue; // Not excluded - no problems
+
+ // check that a regular "name" overload isn't happening
+ QQmlPropertyData *current = d;
+ while (!overloadError && current) {
+ current = d->overrideData(current);
+ if (current && raw->isAllowedInRevision(current))
+ overloadError = true;
+ }
+ }
+
+ if (overloadError) {
+ if (hasCopied) raw->release();
+
+ error.setDescription(QLatin1String("Type ") + type.qmlTypeName() + QLatin1Char(' ') + QString::number(type.majorVersion()) + QLatin1Char('.') + QString::number(minorVersion) + QLatin1String(" contains an illegal property \"") + overloadName + QLatin1String("\". This is an error in the type's implementation."));
+ return 0;
+ }
+#endif
+
+ const_cast<QQmlTypePrivate*>(type.key())->setPropertyCacheForMinorVersion(minorVersion, raw);
+
+ if (hasCopied)
+ raw->release();
+
+ if (minorVersion != maxMinorVersion)
+ const_cast<QQmlTypePrivate*>(type.key())->setPropertyCacheForMinorVersion(maxMinorVersion, raw);
+
+ return raw;
+}
+
+QQmlPropertyCache *QQmlMetaType::propertyCache(const QQmlType &type, int minorVersion)
+{
+ QMutexLocker lock(metaTypeDataLock());
+ QQmlMetaTypeData *data = metaTypeData();
+ return data->propertyCache(type, minorVersion);
+}
+
/*!
Returns the list of registered QML type names.
*/