diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-11 12:48:55 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-05-23 12:50:02 +0200 |
commit | 7fa03450cf68a02da6d6ff04fb5d568b3cca6efe (patch) | |
tree | b1bfefb08a9881f360c554ed5701fceb905294de /src/qml/compiler/qqmlirbuilder.cpp | |
parent | cfbc5ecf2af04e4c0ae6053081b2fa47e8ac5ca8 (diff) |
QML: Add an option to bind components to files
If a component is bound to a file context, we can be sure that the IDs
present in the same file will be accessible to bindings and functions
inside the component. We will need this to allow such bindings to be
compiled to C++.
[ChangeLog][QtQml] You can now bind components to a file scope. This way
you can make sure IDs in the file are accessible to the components.
Task-number: QTBUG-101012
Task-number: QTBUG-102806
Change-Id: I290a61752b4b02e13f0bb0213ba3f871bdb95260
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/compiler/qqmlirbuilder.cpp')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 6dcf07d66c..546394bcfd 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -807,6 +807,28 @@ bool IRBuilder::visit(QQmlJS::AST::UiPragma *node) pragma->type = Pragma::Singleton; } else if (node->name == QStringLiteral("Strict")) { pragma->type = Pragma::Strict; + } else if (node->name == QStringLiteral("ComponentBehavior")) { + for (const Pragma *prev : _pragmas) { + if (prev->type != Pragma::ComponentBehavior) + continue; + recordError(node->pragmaToken, + QCoreApplication::translate( + "QQmlParser", "Multiple component behavior pragmas found")); + return false; + } + + pragma->type = Pragma::ComponentBehavior; + if (node->value == QLatin1String("Bound")) { + pragma->componentBehavior = Pragma::Bound; + } else if (node->value == QLatin1String("Unbound")) { + pragma->componentBehavior = Pragma::Unbound; + } else { + recordError(node->pragmaToken, + QCoreApplication::translate( + "QQmlParser", "Unknown component behavior '%1' in pragma") + .arg(node->value)); + return false; + } } else if (node->name == QStringLiteral("ListPropertyAssignBehavior")) { for (const Pragma *prev : _pragmas) { if (prev->type != Pragma::ListPropertyAssignBehavior) @@ -1544,6 +1566,17 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen case Pragma::Strict: createdUnit->flags |= Unit::IsStrict; break; + case Pragma::ComponentBehavior: + // ### Qt7: Change the default to Bound by reverting the meaning of the flag. + switch (p->componentBehavior) { + case Pragma::Bound: + createdUnit->flags |= Unit::ComponentsBound; + break; + case Pragma::Unbound: + // this is the default + break; + } + break; case Pragma::ListPropertyAssignBehavior: switch (p->listPropertyAssignBehavior) { case Pragma::Replace: |