diff options
author | Rainer Keller <Rainer.Keller@qt.io> | 2018-09-07 13:17:32 +0200 |
---|---|---|
committer | Rainer Keller <Rainer.Keller@qt.io> | 2018-09-12 14:04:52 +0000 |
commit | 22a5630d3c97709b09412dc1037d7dae959bdae5 (patch) | |
tree | ce75f377ba451890bccd1a7e8fede2246f801f65 /src/qml/qml/qqmlmetatype.cpp | |
parent | 8de1177df9568ccd80541a8015d2cd47cf2d0af4 (diff) |
List possbile enum conflicts
When enums are overwritten a report is shown listing possible candidates
and their source locations.
Previously registered enum will be overwritten due to name clash: QQuickListView.Center
Possible conflicting items:
QQuickListView.TransformOrigin.Center from scope QQuickItem injected by QQuickListView
QQuickListView.PositionMode.Center from scope QQuickItemView injected by QQuickListView
Change-Id: I02217b1cf2c80a909ceb6f392083d76266cc622c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlmetatype.cpp')
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 2c22d255a4..12390f9c79 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -137,6 +137,15 @@ private: QStringList *typeRegistrationFailures = nullptr; }; +struct EnumInfo { + QStringList path; + QString metaObjectName; + QString enumName; + QString enumKey; + QString metaEnumScope; + bool scoped; +}; + class QQmlTypeModulePrivate { public: @@ -271,6 +280,9 @@ public: QVector<PropertyCacheByMinorVersion> propertyCaches; QQmlPropertyCache *propertyCacheForMinorVersion(int minorVersion) const; void setPropertyCacheForMinorVersion(int minorVersion, QQmlPropertyCache *cache); +private: + void createListOfPossibleConflictingItems(const QMetaObject *metaObject, QList<EnumInfo> &enumInfoList, QStringList path) const; + void createEnumConflictReport(const QMetaObject *metaObject, const QString &conflictingKey) const; }; void QQmlMetaTypeData::registerType(QQmlTypePrivate *priv) @@ -845,8 +857,10 @@ void QQmlTypePrivate::insertEnums(const QMetaObject *metaObject) const const QString key = QString::fromUtf8(e.key(jj)); const int value = e.value(jj); if (!isScoped || (regType == QQmlType::CppType && extraData.cd->registerEnumClassesUnscoped)) { - if (enums.contains(key)) + if (enums.contains(key)) { qWarning("Previously registered enum will be overwritten due to name clash: %s.%s", metaObject->className(), key.toUtf8().constData()); + createEnumConflictReport(metaObject, key); + } enums.insert(key, value); } if (isScoped) @@ -860,6 +874,51 @@ void QQmlTypePrivate::insertEnums(const QMetaObject *metaObject) const } } +void QQmlTypePrivate::createListOfPossibleConflictingItems(const QMetaObject *metaObject, QList<EnumInfo> &enumInfoList, QStringList path) const +{ + path.append(QString::fromUtf8(metaObject->className())); + + if (metaObject->d.relatedMetaObjects) { + const auto *related = metaObject->d.relatedMetaObjects; + if (related) { + while (*related) + createListOfPossibleConflictingItems(*related++, enumInfoList, path); + } + } + + for (int ii = 0; ii < metaObject->enumeratorCount(); ++ii) { + const auto e = metaObject->enumerator(ii); + + for (int jj = 0; jj < e.keyCount(); ++jj) { + const QString key = QString::fromUtf8(e.key(jj)); + + EnumInfo enumInfo; + enumInfo.metaObjectName = QString::fromUtf8(metaObject->className()); + enumInfo.enumName = QString::fromUtf8(e.name()); + enumInfo.enumKey = key; + enumInfo.scoped = e.isScoped(); + enumInfo.path = path; + enumInfo.metaEnumScope = QString::fromUtf8(e.scope()); + enumInfoList.append(enumInfo); + } + } +} + +void QQmlTypePrivate::createEnumConflictReport(const QMetaObject *metaObject, const QString &conflictingKey) const +{ + Q_UNUSED(metaObject); + QList<EnumInfo> enumInfoList; + createListOfPossibleConflictingItems(baseMetaObject, enumInfoList, QStringList()); //basePath); + + qWarning().noquote() << QLatin1String("Possible conflicting items:"); + // find items with conflicting key + for (const auto i : enumInfoList) { + if (i.enumKey == conflictingKey) + qWarning().noquote().nospace() << " " << i.metaObjectName << "." << i.enumName << "." << i.enumKey << " from scope " + << i.metaEnumScope << " injected by " << i.path.join(QLatin1String("->")); + } +} + void QQmlTypePrivate::insertEnumsFromPropertyCache(const QQmlPropertyCache *cache) const { const QMetaObject *cppMetaObject = cache->firstCppMetaObject(); |