diff options
author | Michael Brasser <mbrasser@ford.com> | 2017-09-21 16:29:39 -0500 |
---|---|---|
committer | Michael Brasser <michael.brasser@live.com> | 2017-10-24 14:35:53 +0000 |
commit | ecf6a2a3658fa17cd4c34f1dd5acc1904f8b4314 (patch) | |
tree | ca0d487899e9a38132260b0a27ee44f5421025c2 /src/qml/compiler | |
parent | f23ee3368ea62930587358d2dff9ec2cb70668f1 (diff) |
Allow assigning functions in ListElement
As an alternative to using eval with a string. This allows code
such as:
// model
ListElement {
action: function() { doSomething() }
}
// delegate
MouseArea {
onClicked: model.action()
}
[ChangeLog][ListModel] Support assignment of function declarations
in ListElement, to allow for models with actions.
Change-Id: I50d188ab30f43b2b8a47f48ceb4281d3ca55bd44
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 2 | ||||
-rw-r--r-- | src/qml/compiler/qv4compileddata_p.h | 3 |
2 files changed, 5 insertions, 0 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 57121e5460..02ff8947c4 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1067,6 +1067,8 @@ void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST } else if (QQmlJS::AST::NumericLiteral *lit = QQmlJS::AST::cast<QQmlJS::AST::NumericLiteral *>(expr)) { binding->type = QV4::CompiledData::Binding::Type_Number; binding->setNumberValueInternal(lit->value); + } else if (QQmlJS::AST::cast<QQmlJS::AST::FunctionExpression *>(expr)) { + binding->flags |= QV4::CompiledData::Binding::IsFunctionExpression; } else { if (QQmlJS::AST::UnaryMinusExpression *unaryMinus = QQmlJS::AST::cast<QQmlJS::AST::UnaryMinusExpression *>(expr)) { diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index a06b53e6e8..40fba51a75 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -300,6 +300,7 @@ struct Q_QML_PRIVATE_EXPORT Binding IsBindingToAlias = 0x40, IsDeferredBinding = 0x80, IsCustomParserBinding = 0x100, + IsFunctionExpression = 0x200 }; union { @@ -367,6 +368,8 @@ struct Q_QML_PRIVATE_EXPORT Binding return false; } + bool isFunctionExpression() const { return (flags & IsFunctionExpression); } + static QString escapedString(const QString &string); bool containsTranslations() const { return type == Type_Translation || type == Type_TranslationById; } |