[Development] QAction-like API for QML

Alan Alpert 416365416c at gmail.com
Tue Dec 11 21:59:41 CET 2012


On Tue, Dec 11, 2012 at 10:49 AM, Shawn Rutledge
<shawn.rutledge at digia.com> wrote:
> On Tue, Dec 11, 2012 at 09:48:22AM -0800, Alan Alpert wrote:
>> Why can't this be QML-only? For the set of controls exposed in
>> C++-only we have a C++-only Action API. When we add a set of controls
>> exposed in QML-only we can have a QML-only Action API. We don't
>
> Because it seems likely that the business logic of an application would
> be written in C++, so why not export the actions that the logic can
> support at the same time?

The way I see it, the actions are UI logic, not business logic, and
belong on the QML side of the divide (although they are right on the
edge). I expect it would be far better to do
Action {
    imageSource: "gfx/activate.png"
    text: "Activate"
    detailedText: "Activates the business logic portion"
    onTriggered: AppLogic.activate();
}

Than to just pass in AppLogic.actions to your menu. The primary
content of the Action is UI logic and UI content, and the business
logic is what it triggers. This makes even more sense when you have
generic business logic functions and create actions that call the
functions with arguments when clicked.

> Some future version of QML designer might
> even be able to discover the exported actions and make it easy to
> build parts of the UI, or even suggest a complete implementation.
> (The whole action tree goes into the menubar, and each menu goes
> into an optional toolbar fragment which can be turned on and off
> by the user, and the state of those fragments needs to be stored
> in settings.  The best practice is very predictable.)

The old widget UI is very predictable, and that's why QMainWindow was
so brilliant. But I like your idea, I just think it should be applied
on the business logic -> ui logic level instead of the ui logic -> ui
level. A future version of the designer might be able to take your
application logic singleton class and automatically generate a QML
file containing the Action{}s for it with default guessed text and
such. Then you can tweak the text and pass that Action list into your
menus/toolbars or however you want your UI (which could also be
generated from a template).

--
Alan Alpert



More information about the Development mailing list