aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-16 15:51:34 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-16 21:56:12 +0200
commit7feab1fb95317b924fe39c49dd9907ca3df61a40 (patch)
tree41db3b22d74c9971b7549c76d1f9a29af40fa14a
parent813796b303af168045d43574321b48d82b41d48d (diff)
QmlCompiler: Read the "bindable" attribute from plugins.qmltypes
And refactor QQmlJSMetaProperty to use setters rather than a gigantic constructor. Also, notice that we don't have to construct the same property twice just to update its type. Change-Id: Ia6c195fa7088f6ecdff868daae17d4284c1edb22 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp33
-rw-r--r--src/qmlcompiler/qqmljsmetatypes_p.h27
-rw-r--r--src/qmlcompiler/qqmljstypedescriptionreader.cpp27
3 files changed, 44 insertions, 43 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index f62b27fd35..8f30631b22 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -173,15 +173,12 @@ bool QQmlJSImportVisitor::visit(UiPublicMember *publicMember)
if (const auto idExpression = cast<IdentifierExpression *>(expression->expression))
typeName = idExpression->name;
}
- QQmlJSMetaProperty prop {
- publicMember->name.toString(),
- typeName.toString(),
- publicMember->typeModifier == QLatin1String("list"),
- !publicMember->isReadonlyMember,
- false,
- isAlias,
- 0
- };
+ QQmlJSMetaProperty prop;
+ prop.setPropertyName(publicMember->name.toString());
+ prop.setTypeName(typeName.toString());
+ prop.setIsList(publicMember->typeModifier == QLatin1String("list"));
+ prop.setIsWritable(!publicMember->isReadonlyMember);
+ prop.setIsAlias(isAlias);
prop.setType(m_rootScopeImports.value(prop.typeName()));
m_currentScope->insertPropertyIdentifier(prop);
break;
@@ -242,7 +239,8 @@ void QQmlJSImportVisitor::endVisit(QQmlJS::AST::FunctionDeclaration *)
bool QQmlJSImportVisitor::visit(QQmlJS::AST::ClassExpression *ast)
{
- QQmlJSMetaProperty prop { ast->name.toString(), QString(), false, false, false, false, 1 };
+ QQmlJSMetaProperty prop;
+ prop.setPropertyName(ast->name.toString());
m_currentScope->addProperty(prop);
enterEnvironment(QQmlJSScope::JSFunctionScope, ast->name.toString(),
ast->firstSourceLocation());
@@ -453,8 +451,12 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob)
name.chop(1);
- QQmlJSMetaProperty prop(uiob->qualifiedId->name.toString(), name, false, true, true,
- name == QLatin1String("alias"), 0);
+ QQmlJSMetaProperty prop;
+ prop.setPropertyName(uiob->qualifiedId->name.toString());
+ prop.setTypeName(name);
+ prop.setIsWritable(true);
+ prop.setIsPointer(true);
+ prop.setIsAlias(name == QLatin1String("alias"));
prop.setType(m_rootScopeImports.value(uiob->qualifiedTypeNameId->name.toString()));
m_currentScope->addProperty(prop);
@@ -468,11 +470,8 @@ void QQmlJSImportVisitor::endVisit(QQmlJS::AST::UiObjectBinding *uiob)
{
const QQmlJSScope::ConstPtr childScope = m_currentScope;
leaveEnvironment();
- QQmlJSMetaProperty property(uiob->qualifiedId->name.toString(),
- uiob->qualifiedTypeNameId->name.toString(),
- false, true, true,
- uiob->qualifiedTypeNameId->name == QLatin1String("alias"),
- 0);
+
+ QQmlJSMetaProperty property = m_currentScope->property(uiob->qualifiedId->name.toString());
property.setType(childScope);
m_currentScope->addProperty(property);
}
diff --git a/src/qmlcompiler/qqmljsmetatypes_p.h b/src/qmlcompiler/qqmljsmetatypes_p.h
index 89fdd7cd1b..dcb388abfb 100644
--- a/src/qmlcompiler/qqmljsmetatypes_p.h
+++ b/src/qmlcompiler/qqmljsmetatypes_p.h
@@ -166,6 +166,7 @@ class QQmlJSMetaProperty
{
QString m_propertyName;
QString m_typeName;
+ QString m_bindable;
QWeakPointer<const QQmlJSScope> m_type;
bool m_isList = false;
bool m_isWritable = false;
@@ -175,28 +176,32 @@ class QQmlJSMetaProperty
public:
QQmlJSMetaProperty() = default;
- QQmlJSMetaProperty(QString propertyName, QString typeName,
- bool isList, bool isWritable, bool isPointer, bool isAlias,
- int revision)
- : m_propertyName(std::move(propertyName))
- , m_typeName(std::move(typeName))
- , m_isList(isList)
- , m_isWritable(isWritable)
- , m_isPointer(isPointer)
- , m_isAlias(isAlias)
- , m_revision(revision)
- {}
+ void setPropertyName(const QString &propertyName) { m_propertyName = propertyName; }
QString propertyName() const { return m_propertyName; }
+
+ void setTypeName(const QString &typeName) { m_typeName = typeName; }
QString typeName() const { return m_typeName; }
+ void setBindable(const QString &bindable) { m_bindable = bindable; }
+ QString bindable() const { return m_bindable; }
+
void setType(const QSharedPointer<const QQmlJSScope> &type) { m_type = type; }
QSharedPointer<const QQmlJSScope> type() const { return m_type.toStrongRef(); }
+ void setIsList(bool isList) { m_isList = isList; }
bool isList() const { return m_isList; }
+
+ void setIsWritable(bool isWritable) { m_isWritable = isWritable; }
bool isWritable() const { return m_isWritable; }
+
+ void setIsPointer(bool isPointer) { m_isPointer = isPointer; }
bool isPointer() const { return m_isPointer; }
+
+ void setIsAlias(bool isAlias) { m_isAlias = isAlias; }
bool isAlias() const { return m_isAlias; }
+
+ void setRevision(int revision) { m_revision = revision; }
int revision() const { return m_revision; }
};
diff --git a/src/qmlcompiler/qqmljstypedescriptionreader.cpp b/src/qmlcompiler/qqmljstypedescriptionreader.cpp
index 3d3084a724..f0b011cc7e 100644
--- a/src/qmlcompiler/qqmljstypedescriptionreader.cpp
+++ b/src/qmlcompiler/qqmljstypedescriptionreader.cpp
@@ -313,12 +313,7 @@ void QQmlJSTypeDescriptionReader::readSignalOrMethod(UiObjectDefinition *ast, bo
void QQmlJSTypeDescriptionReader::readProperty(UiObjectDefinition *ast, const QQmlJSScope::Ptr &scope)
{
- QString name;
- QString type;
- bool isPointer = false;
- bool isReadonly = false;
- bool isList = false;
- int revision = 0;
+ QQmlJSMetaProperty property;
for (UiObjectMemberList *it = ast->initializer->members; it; it = it->next) {
UiObjectMember *member = it->member;
@@ -330,31 +325,33 @@ void QQmlJSTypeDescriptionReader::readProperty(UiObjectDefinition *ast, const QQ
QString id = toString(script->qualifiedId);
if (id == QLatin1String("name")) {
- name = readStringBinding(script);
+ property.setPropertyName(readStringBinding(script));
} else if (id == QLatin1String("type")) {
- type = readStringBinding(script);
+ property.setTypeName(readStringBinding(script));
} else if (id == QLatin1String("isPointer")) {
- isPointer = readBoolBinding(script);
+ property.setIsPointer(readBoolBinding(script));
} else if (id == QLatin1String("isReadonly")) {
- isReadonly = readBoolBinding(script);
+ property.setIsWritable(!readBoolBinding(script));
} else if (id == QLatin1String("isList")) {
- isList = readBoolBinding(script);
+ property.setIsList(readBoolBinding(script));
} else if (id == QLatin1String("revision")) {
- revision = readIntBinding(script);
+ property.setRevision(readIntBinding(script));
+ } else if (id == QLatin1String("bindable")) {
+ property.setBindable(readStringBinding(script));
} else {
addWarning(script->firstSourceLocation(),
- tr("Expected only type, name, revision, isPointer, isReadonly and"
+ tr("Expected only type, name, revision, isPointer, isReadonly, bindable, and"
" isList script bindings."));
}
}
- if (name.isEmpty() || type.isEmpty()) {
+ if (property.propertyName().isEmpty() || property.typeName().isEmpty()) {
addError(ast->firstSourceLocation(),
tr("Property object is missing a name or type script binding."));
return;
}
- scope->addProperty(QQmlJSMetaProperty(name, type, isList, !isReadonly, isPointer, false, revision));
+ scope->addProperty(property);
}
void QQmlJSTypeDescriptionReader::readEnum(UiObjectDefinition *ast, const QQmlJSScope::Ptr &scope)