From f98ed790a1e4ae3b86ba0ad0b8c33f2f9494a3a6 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Tue, 12 Jul 2022 13:41:38 +0200 Subject: [PATCH] QmlDesigner: Start to Use NodeMetaInfo in ReadingContext We keep the old code path for now and throw an exception if there is a divergence. The old code path is supposed to be removed before the 3.6 release. Change-Id: Id5458cdb452341295c5901caf706d224e57837b0 Reviewed-by: Qt CI Bot Reviewed-by: Reviewed-by: Marco Bubke --- .../designercore/model/texttomodelmerger.cpp | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp index d7e215fcd53..652d9a90526 100644 --- a/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/texttomodelmerger.cpp @@ -40,6 +40,7 @@ #include "propertyparser.h" #include "rewriterview.h" #include "variantproperty.h" +#include #include @@ -434,13 +435,14 @@ class ReadingContext { public: ReadingContext(const Snapshot &snapshot, const Document::Ptr &doc, - const ViewerContext &vContext) + const ViewerContext &vContext, Model *model) : m_doc(doc) , m_context( Link(snapshot, vContext, ModelManagerInterface::instance()->builtins(doc)) (doc, &m_diagnosticLinkMessages)) , m_scopeChain(doc, m_context) , m_scopeBuilder(&m_scopeChain) + , m_model(model) { } @@ -506,6 +508,35 @@ public: typeName.prepend(name + QLatin1Char('.')); } } + + { + TypeName fullTypeName; + for (AST::UiQualifiedId *iter = astTypeNode; iter; iter = iter->next) + if (!iter->name.isEmpty()) + fullTypeName += iter->name.toUtf8() + '.'; + + if (fullTypeName.endsWith('.')) + fullTypeName.chop(1); + + NodeMetaInfo metaInfo = m_model->metaInfo(fullTypeName); + + bool ok = metaInfo.typeName() == typeName.toUtf8() + && metaInfo.majorVersion() == majorVersion + && metaInfo.minorVersion() == minorVersion; + + if (!ok) { + qDebug() << Q_FUNC_INFO; + qDebug() << astTypeNode->name.toString() << typeName; + qDebug() << metaInfo.isValid() << metaInfo.typeName(); + qDebug() << metaInfo.directSuperClass().typeName(); + + throw RewritingException(__LINE__, __FUNCTION__, __FILE__, "test", "test"); + } + + typeName = QString::fromUtf8(metaInfo.typeName()); + majorVersion = metaInfo.majorVersion(); + minorVersion = metaInfo.minorVersion(); + } } /// When something is changed here, also change Check::checkScopeObjectMember in @@ -758,6 +789,7 @@ private: ContextPtr m_context; ScopeChain m_scopeChain; ScopeBuilder m_scopeBuilder; + Model *m_model; }; } // namespace Internal @@ -1122,7 +1154,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH m_vContext = ModelManagerInterface::instance()->projectVContext(Dialect::Qml, m_document); - ReadingContext ctxt(snapshot, m_document, m_vContext); + ReadingContext ctxt(snapshot, m_document, m_vContext, m_rewriterView->model()); m_scopeChain = QSharedPointer( new ScopeChain(ctxt.scopeChain()));