diff --git a/tools/qmltc/main.cpp b/tools/qmltc/main.cpp index c714fb8d66..2c27d508d1 100644 --- a/tools/qmltc/main.cpp +++ b/tools/qmltc/main.cpp @@ -218,12 +218,19 @@ int main(int argc, char **argv) } QQmlJSImporter importer { importPaths, &mapper }; + auto createQmltcVisitor = [](const QQmlJSScope::Ptr &root, QQmlJSImporter *importer, + QQmlJSLogger *logger, const QString &implicitImportDirectory, + const QStringList &qmldirFiles) -> QQmlJSImportVisitor * { + return new QmltcVisitor(root, importer, logger, implicitImportDirectory, qmldirFiles); + }; + importer.setImportVisitorCreator(createQmltcVisitor); + QQmlJSLogger logger; logger.setFileName(url); logger.setCode(sourceCode); setupLogger(logger); - QmltcVisitor visitor(&importer, &logger, + QmltcVisitor visitor(QQmlJSScope::create(), &importer, &logger, QQmlJSImportVisitor::implicitImportDirectory(url, &mapper), qmldirFiles); QmltcTypeResolver typeResolver { &importer }; typeResolver.init(&visitor, qmlParser.rootNode()); diff --git a/tools/qmltc/prototype/qml2cppdefaultpasses.cpp b/tools/qmltc/prototype/qml2cppdefaultpasses.cpp index 843acd3bc0..484558e24b 100644 --- a/tools/qmltc/prototype/qml2cppdefaultpasses.cpp +++ b/tools/qmltc/prototype/qml2cppdefaultpasses.cpp @@ -323,25 +323,6 @@ static void setupQmlCppType(const Qml2CppContext &context, const QQmlJSScope::Pt // this file name will be discovered during findCppIncludes type->setFilePath(QFileInfo(filePath).baseName().toLower() + u".h"_s); } - - const auto properties = type->ownProperties(); - for (auto it = properties.cbegin(); it != properties.cend(); ++it) { - QQmlJSMetaProperty p = it.value(); - Q_ASSERT(it.key() == p.propertyName()); - - if (p.isAlias()) // we'll process aliases separately - continue; - - QmltcPropertyData compiledData(p); - if (p.read().isEmpty()) - p.setRead(compiledData.read); - if (p.write().isEmpty() && p.isWritable() && !p.isList()) - p.setWrite(compiledData.write); - if (p.bindable().isEmpty() && !p.isList()) - p.setBindable(compiledData.bindable); - // TODO: p.setNotify(compiledData.notify); - ? - type->addOwnProperty(p); - } } void setupQmlCppTypes(const Qml2CppContext &context, QList &objects) diff --git a/tools/qmltc/qmltcvisitor.cpp b/tools/qmltc/qmltcvisitor.cpp index 4fdc06ee40..6884a7860d 100644 --- a/tools/qmltc/qmltcvisitor.cpp +++ b/tools/qmltc/qmltcvisitor.cpp @@ -67,10 +67,10 @@ static bool isOrUnderComponent(QQmlJSScope::ConstPtr type) return false; } -QmltcVisitor::QmltcVisitor(QQmlJSImporter *importer, QQmlJSLogger *logger, - const QString &implicitImportDirectory, const QStringList &qmldirFiles) - : QQmlJSImportVisitor( - QQmlJSScope::create(), importer, logger, implicitImportDirectory, qmldirFiles) +QmltcVisitor::QmltcVisitor(const QQmlJSScope::Ptr &target, QQmlJSImporter *importer, + QQmlJSLogger *logger, const QString &implicitImportDirectory, + const QStringList &qmldirFiles) + : QQmlJSImportVisitor(target, importer, logger, implicitImportDirectory, qmldirFiles) { m_qmlTypeNames.append(QFileInfo(logger->fileName()).baseName()); // put document root } @@ -160,7 +160,6 @@ bool QmltcVisitor::visit(QQmlJS::AST::UiObjectDefinition *object) if (m_currentScope->scopeType() != QQmlJSScope::QMLScope) return true; - Q_ASSERT(m_currentScope->internalName().isEmpty()); Q_ASSERT(!m_currentScope->baseTypeName().isEmpty()); if (m_currentScope != m_exportedRootScope) // not document root m_qmlTypeNames.append(m_currentScope->baseTypeName()); @@ -188,7 +187,6 @@ bool QmltcVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob) return false; Q_ASSERT(m_currentScope->scopeType() == QQmlJSScope::QMLScope); - Q_ASSERT(m_currentScope->internalName().isEmpty()); Q_ASSERT(!m_currentScope->baseTypeName().isEmpty()); if (m_currentScope != m_exportedRootScope) // not document root m_qmlTypeNames.append(m_currentScope->baseTypeName()); @@ -218,9 +216,23 @@ bool QmltcVisitor::visit(QQmlJS::AST::UiPublicMember *publicMember) if (publicMember->type == QQmlJS::AST::UiPublicMember::Property) { const auto name = publicMember->name.toString(); - // TODO: we should set the composite type property methods here, but as - // of now this is done in the pass over the types after the ast - // traversal + QQmlJSScope::Ptr owner = + m_savedBindingOuterScope ? m_savedBindingOuterScope : m_currentScope; + QQmlJSMetaProperty property = owner->ownProperty(name); + Q_ASSERT(property.isValid()); + if (!property.isAlias()) { // aliases are covered separately + QmltcPropertyData compiledData(property); + if (property.read().isEmpty()) + property.setRead(compiledData.read); + if (!property.isList()) { + if (property.write().isEmpty() && property.isWritable()) + property.setWrite(compiledData.write); + // Note: prefer BINDABLE to NOTIFY + if (property.bindable().isEmpty()) + property.setBindable(compiledData.bindable); + } + owner->addOwnProperty(property); + } const QString notifyName = name + u"Changed"_s; // also check that notify is already a method of the scope diff --git a/tools/qmltc/qmltcvisitor.h b/tools/qmltc/qmltcvisitor.h index 03ba504a74..bdd08fb8ce 100644 --- a/tools/qmltc/qmltcvisitor.h +++ b/tools/qmltc/qmltcvisitor.h @@ -47,7 +47,7 @@ class QmltcVisitor : public QQmlJSImportVisitor void setupAliases(); public: - QmltcVisitor(QQmlJSImporter *importer, QQmlJSLogger *logger, + QmltcVisitor(const QQmlJSScope::Ptr &target, QQmlJSImporter *importer, QQmlJSLogger *logger, const QString &implicitImportDirectory, const QStringList &qmldirFiles = QStringList());