Using plasma enums from QML2
Marco Martin
notmart at gmail.com
Fri May 10 17:44:09 UTC 2013
Hi all,
After many experiments in varuious failing directions, i have the branch
PlasmaTypesClass of palsma-framework
The problem:
we need a way to expose the enums used in libplasma such as FormFactor,
Location, Constraints etc in some way accessible to QML, for applet bindings,
and any possible future qml plugin that needs to use them as properties.
we used to have a duplication of most of enums in AppletInterface in the
script engine, that works fine-ish but you still have to pass them by numeric
value (the name of the enum doesn't seem to be accessible, but at least the
parameters are assed when invoking methods or setting properties)
and of course you can use it only in plasmoids, and not within qml plugins.
In the branch, I have now in libplasma a class called Types that contains all
the enums, this makes possible to use them in qml, (or even in old qtscript if
one wants). Is exactly how is done for the global Qt namespace (Qt:: is
actually not a namespace, but a QObject)
in QML they would be accessed by name with something like
PlasmaCore.Types.TopEdge
(they weren't accessible byu name at all in qml1 so no mandatory porting
involved from qml part, accessing by number still works)
pros:
* used directly
* removes duplicate definitions
* typecasts--
cons:
* Types name (or any other for what matters) is not particularly pretty
* in c++ all Plasma::Foo must be changed in Plasma::Types::Foo
So.
I can't really get to like this approach, but i think is the only one that can
work in any way...
Cheers,
Marco Martin
More information about the Plasma-devel
mailing list