qmltc: Set non-alias property methods in QmltcVisitor

Remove the prototype code bits in favor of QmltcVisitor logic

To make this work correctly, we have to use QmltcVisitor when
visiting imported scopes

Pick-to: 6.4
Change-Id: I6225fb672a020f7720fe29806c4ad6370c737568
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Andrei Golubev 2022-06-07 13:09:54 +02:00
parent 416df0858b
commit fa6074f654
4 changed files with 30 additions and 30 deletions

View File

@ -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());

View File

@ -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<QQmlJSScope::Ptr> &objects)

View File

@ -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

View File

@ -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());