Details
-
Task
-
Resolution: Done
-
P2: Important
-
None
Description
It should be possible to annotate nodes, properties,... to add extra metadata and behaviour to the existing QML model in an extensible way that would need minimal grammar changes.
The main drawback of an annotation with respect to a keyword is that typos will not be catched if we allow undeclared annotations.
If annotation have to be declared somewhere, than that limitation is not there.
I would go with @QmlLikeObject{} for the annotations, and attach all the annotations to the first non annotation line, be it a type, property, binding, assignment, Behaviour,... and make them available in the DOM API.
@Annotation1{}
@Annotation2{arg1:y}
Bla{
@Annotation1{}
property int x: 4
@Annotation3{}
y:4
@Annotation4{
arg1: 3
arg2: “bla”
}
function f(i){}
}
I would not put them in comments, and they should refer to the type, property, function,… immediately after all the annotations.
In the DOM model then every type, property,… would have a list annotations.
The reason to use this syntax are the following:
- minimal changes to the grammar
- flexible (can cover basically all use cases I can think of)
- The annotations can be declared without introducing new syntax (we could use @Annotation in declaring them, or they could have a separate file extension)
- we can provide tooling/typo detection,… by requiring all annotations to be declared
- documenting can be done in a similar way to QML
With it the example given by Thomas could become adding the following qml annotation declarations
'Extra' (Annotating node with extra arbitrary properties)
'Invisible' (Item is invisible in editor)
'Lock' (Item is locked in editor)
'InternalId' (internal id)
TimeLine { @Extra{ property color color: "blue" property bool expanded: true property bool locked: false property bool visible: false } @Invisible{} @Locked{} @InternalId{ value: 4234354656 } TimeLineGroupGroup { } @Extra{ property color color: "blue" property bool expanded: true property bool locked: false property bool visible: false } @Invisible{} @Locked{} @InternalId{ value: 4234354656 } TimeLineGroupGroup { Annotations.color: "blue" } }
Attachments
Issue Links
- depends on
-
QTBUG-81714 Add annotations to the QML parser
- Closed
-
QTBUG-81719 Define how annotations can be declared/documented
- Closed
-
QTBUG-68406 Create Language Server for QML
- Closed
- is required for
-
QTBUG-79857 qmllint: Warn about deprecated types/properties
- Closed