Debian Codegraph @

documentation/qml/pages/context.qdoc

raw
1 /*!
2 \page contexts.html Action Contexts
3 \title Action Contexts
4 \contentspage {Lomiri Action API}
5
6 \part Overview
7 Application which has different views needs to manage it actions based on the currently active view;
8 not all of the actions supported by the application might be relevant or applicable on all of the views.
9
10 Therefore Lomiri Action API provides action contexts; a context groups actions together and by providing multiple contexts
11 the developer is able to control the visibility of the actions. The ActionManager then exposes the actions from
12 these different contexts.
13
14 \image context_overview.png
15
16 Each application has one global context; the actions in this context are always available. The application may have one or more
17 additional local context of which only one can be active at a time. The ActionManager merges the global context and the active local
18 context together; the actions available at any given time is the union of the global context and the active local context.
19
20 \image multiple_contexts.png
21
22
23 \part Applications with Single Context
24 For applications that do not require multiple contexts using the API is straight forward as the
25 ActionManager provides the global context automatically.
26
27 \code
28 import QtQuick 2.0
29 import Lomiri.Action 1.0
30
31 Item {
32 ActionManager {
33 Action {
34 id: globalAction
35 text: "My Global Action"
36 }
37 }
38 }
39 \endcode
40
41 globalAction is now added to the global context.
42
43
44 \part Applications with Multiple Contexts
45 When multiple contexts are needed the developer creates suitable number of ActionContext objects,
46 adds the actions to the contexts, adds the contexts to the manager and sets the active one.
47
48 Setting the active context must be managed by the developer. The can only be one active
49 local context at a time.
50
51 \code
52 import QtQuick 2.0
53 import Lomiri.Action 1.0
54
55 Item {
56 ActionManager {
57 localContexts: [ctx1, ctx2]
58 Action {
59 id: globalAction
60 text: "My Global Action"
61 }
62 }
63
64 ActionContext {
65 id: ctx1
66 Action {
67 id: ctx1Action1
68 text: "Context1, Action 1"
69 }
70 Action {
71 id: ctx1Action2
72 text: "Context1, Action 2"
73 }
74 }
75
76 ActionContext {
77 id: ctx2
78 Action {
79 id: ctx2Action1
80 text: "Context2, Action 1"
81 }
82 Action {
83 id: ctx2Action2
84 text: "Context2, Action 2"
85 }
86 }
87
88 Component.onCompleted: {
89 ctx2.active = true;
90 // now the ActionManager has exported
91 // globalAction, ctx2Action1 and ctx2Action2
92 }
93 }
94 \endcode
95 */