summaryrefslogtreecommitdiffstats
path: root/doc/migration-guide-5.12.qdoc
blob: df2e38c8d3fddb1089672435116f6d68425d5013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/****************************************************************************
**
** Copyright (C) 2018 Pelagicore AG
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Pelagicore Application Manager.
**
** $QT_BEGIN_LICENSE:FDL-QTAS$
** Commercial License Usage
** Licensees holding valid commercial Qt Automotive Suite licenses may use
** this file in accordance with the commercial license agreement provided
** with the Software or, alternatively, in accordance with the terms
** contained in a written agreement between you and The Qt Company.  For
** licensing terms and conditions see https://www.qt.io/terms-conditions.
** For further information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!

\page migration-guide-5.12.html
\title Migrating code from 5.11 to 5.12

Qt Application Manager 5.12 is not API compatible with the 5.11 release. In this document we go through
the main API breaks and how to port affected code from the 5.11 to the new 5.12 API. The API breaks lie
solely on the System-UI side, therefore application code remains unchanged.

There are also cases where there's no API break but instead new, better, APIs for achieving the same
result in 5.12. This document also covers some of such situations.

\section1 Import statements

Most of the content of the QtApplicationManager QML module was moved into two new modules:
\l{QtApplicationManager.SystemUI QML module}{QtApplicationManager.SystemUI}
and \l{QtApplicationManager.Application QML module}{QtApplicationManager.Application}. The following
table briefly explains each of them:

\table
\header
    \li QML Module Name
    \li Content
\row
    \li \l{QtApplicationManager QML module}{QtApplicationManager}
    \li Components and types in common to applications and System-UI. Both
        System-UI and application code can import this module.
\row
    \li \l{QtApplicationManager.SystemUI QML module}{QtApplicationManager.SystemUI}
    \li Components and types that a System-UI can use. Applications should
        not import this module.
\row
    \li \l{QtApplicationManager.Application QML module}{QtApplicationManager.Application}
    \li Components and types that an application can use. System-UI code should
        not import this module.
\endtable

In order to avoid compatibility problems with old code expecting the old APIs, \b all imports have
been bumped up to version \c 2.0. Importing the \c 1.0 versions will just yield a QML error.


\section1 ApplicationManager and applications

\section2 Refactored ApplicationObject

In 5.11, the object type representing an application was named \c Application. But since Qt also has
an object type with the same name, in order to be able to reference enumerations defined in it you
had to import QtApplicationManager in a separate namespace. In 5.12, that object type was renamed to
ApplicationObject and thus it no longer clashes with Qt's own \c Application type.

\oldcode
import QtApplicationManager 1.0 as AppMan
...
if (application.state === AppMan.Application.Installed) {
    ...
}
\newcode
import QtApplicationManager.Application 2.0
...
if (application.state === ApplicationObject.Installed) {
    ...
}
\endcode

\section2 Starting and stopping applications

The ApplicationObject is smarter now, moving away from being mostly a plain-old-data structure to also
contain all actions pertaining to the application at hand, making for a more object oriented API. This
is reflected in the way you can start and stop applications in 5.12.

\oldcode
var application = ApplicationManager.fromId("com.example.music");
...
ApplicationManager.startApplication(application.id);
\newcode
var application = ApplicationManager.fromId("com.example.music");
...
application.start();
\endcode

\section1 WindowManager and windows

Windows are now represented by instances of the WindowObject type instead of being Item instances. WindowObjects
cannot be displayed directly and have to be assigned to a WindowItem to be rendered on the screen.

This is also reflected in WindowManager model roles, which are now fewer and different. The \c windowItem role
has been replaced with the \l{windowmanager-window-role}{window} role. The \c isFullscreen role has been removed
and there's no replacement for it. \c isMapped and \c isClosing were replaced with a single role named
\l{windowmanager-contentState-role}{contentState}.

\oldcode
Connections {
    target: WindowManager
    onWindowReady: {
        window.parent = windowContainer;
        window.width = Qt.binding(function() { return windowContainer.width; });
        window.height = Qt.binding(function() { return windowContainer.height; });
    }
    ...
}
...
Item {
    id: windowContainer
    ...
}
\newcode
Connections {
    target: WindowManager
    onWindowAdded: {
        windowItem.window = window;
    }
    ...
}
...
WindowItem {
    id: windowItem
    ...
}
\endcode

See the new \l{"Hello World!" System-UI Example}{Hello World} and \l{Animated Windows System-UI Example}{Animated Windows}
examples for further explanations on the new way of manipulating windows in your System-UI.

\section2 WindowManager signals

Signals in WindowManager related to the window lifecycle have all changed. \c windowReady is the only signal thas has an
equivalent in the new API, as seen in the previous code snippet. For others there's no exact match, although the new API
has similar signals.

\oldcode
Connections {
    target: WindowManager
    onWindowClosing: {
        ...
    }
    onWindowLost: {
        ...
    }
    ...
}
\newcode
Connections {
    target: WindowManager
    onWindowContentStateChanged: {
        if (window.contentState === WindowObject.SurfaceNoContent) {
            // code from onWindowClosing
            ...
        } else if (window.contentState === WindowObject.NoSurface) {
            // code from onWindowLost
            ...
        }
    }
    ...
}
\endcode

You can also check and track the content state of a window from its \l{WindowObject::contentState}{WindowObject.contentState}
property.

\section2 Releasing windows

In the new API there's no longer the concept of releasing windows. Thus the signal \c WindowManager.windowReleased and the
method \c WindowManager.releaseWindow() have been removed. Instead, a WindowObject is destroyed once it no longer has a
backing surface (ie, its contentState is \l{windowobject-nosurface}{WindowObject.NoSurface}) and it is not assigned to any
WindowItem.

\section2 Window properties

The window properties of a given window can now be set, queried and tracked from its WindowObject, without the need
to use the WindowManager singleton. That way code can be more readable and modular.

\oldcode
WindowManager.setWindowProperty(window, "type", "dialog");
...
Connections {
    target: WindowManager
    onWindowPropertyChanged: {
        if (window === fooWindow) {
            console.log("fooWindow's property " + name + " is now " + value);
        }
    }
}
\newcode
window.setWindowProperty("type", "dialog");
...
Connections {
    target: fooWindow
    onWindowPropertyChanged: {
        console.log("fooWindow's property " + name + " is now " + value);
    }
}
\endcode

\section2 Registering compositor views

In the new API, on the System UI side, there's no longer a need to explicitly call WindowManager.registerCompositorView
on a Window to be able to composite client application surfaces on them (ie. have WindowItems rendering WindowObjects).
This is now handled internally automatically and thus this function has been removed from the Qt Application Manager API.

\oldcode
QtObject {
    Window {
        id: someSysUIWindow
        visible: true
        ...
        Component.onCompleted: {
            WindowManager.registerCompositorView(someSysUIWindow);
        }
    }
}
\newcode
QtObject {
    Window {
        id: someSysUIWindow
        visible: true
        ...
    }
}
\endcode

\section1 SystemMonitor

The SystemMonitor singleton no longer exists. The functionality that it provided has been split into several new
components, namely: MonitorModel, CpuStatus, GpuStatus, MemoryStatus, FrameTimer and IoStatus.

\oldcode
Item {
    id: root
    ...
    Component.onCompleted: {
        SystemMonitor.reportingInterval = 1500;
        SystemMonitor.count = 20;
    }
    Binding { target: SystemMonitor; property: "cpuLoadReportingEnabled"; value: root.visible }

    // Draw a graph of CPU usage
    ListView {
        model: SystemMonitor
        ...
    }
}
\newcode
Item {
    id: root
    ...
    // Draw a graph of CPU usage
    ListView {
        model: MonitorModel {
            interval: 1500
            running: root.visible
            maximumCount: 20
            CpuStatus {}
        }
        ...
    }
}
\endcode

\section1 ProcessMonitor

The ProcessMonitor component no longer exists. The functionality that it provided has been split into a
couple of new components, namely: ProcessStatus, MonitorModel and FrameTimer.

\oldcode
Item {
    id: root
    ...
    // Draw a graph of CPU usage
    ListView {
        model: ProcessMonitor {
            count: 20
            cpuReportingEnabled: root.visible
            reportingInterval: 1500
            applicationId: "foo.app"
        }
        ...
    }
}
\newcode
Item {
    id: root
    ...
    // Draw a graph of CPU usage
    ListView {
        model: MonitorModel {
            maximumCount: 20
            running: root.visible
            interval: 1500
            ProcessStatus {
                applicationId: "foo.app"
            }
        }
        ...
    }
}
\endcode

 */