From 2f3b4ec528f48747a3b7e91e9a7254c25ce24c99 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 5 Sep 2019 13:03:59 +0200 Subject: Introduce required properties to QML [ChangeLog][QtQml] "required" is now a (contextual) keyword in QML, and users can mark properties with it to specify that those properties must be set when the component gets instantiated. This can be done either declaratively via standard property bindings from QML, or imperatively by using the functions to set initial properties (QQmlCompoent::setInitalProperties and related functions in C++, Qt.createObject, Loader.setSource,... in QML/JS). Logic has been added to QQmlComponent::create and the various QQmlIncubator classes to verify that the required properties were set. If properties marked as required are not set, a warning will be printed at runtime, and the component will not be created. Change-Id: I8e38227fc8f173b053b689c1597dc7fd40e835e7 Reviewed-by: Ulf Hermann Reviewed-by: Simon Hausmann --- src/qml/parser/qqmljsast_p.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/qml/parser/qqmljsast_p.h') diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index 6c28903066..4247785905 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -3308,6 +3308,8 @@ public: return defaultToken; else if (readonlyToken.isValid()) return readonlyToken; + else if (requiredToken.isValid()) + return requiredToken; return propertyToken; } @@ -3331,10 +3333,13 @@ public: UiObjectMember *binding; // initialized with a QML object or array. bool isDefaultMember; bool isReadonlyMember; + bool isRequired = false; UiParameterList *parameters; + // TODO: merge source locations SourceLocation defaultToken; SourceLocation readonlyToken; SourceLocation propertyToken; + SourceLocation requiredToken; SourceLocation typeModifierToken; SourceLocation typeToken; SourceLocation identifierToken; -- cgit v1.2.3