QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCDynamicObjectManager.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5
6/// Provides a standard set of tools for dynamically create/adding/removing Qml objects
7Item {
8 visible: false
9
10 property var rgDynamicObjects: [ ]
11 property bool empty: rgDynamicObjects.length === 0
12
13 Component.onDestruction: destroyObjects()
14
15 function createObject(sourceComponent, parentObject, addMapItem) {
16 var obj = sourceComponent.createObject(parentObject)
17 if (obj.status === Component.Error) {
18 console.log(obj.errorString())
19 }
20 rgDynamicObjects.push(obj)
21 if (arguments.length < 3) {
22 addMapItem = false
23 }
24 if (addMapItem) {
25 parentObject.addMapItem(obj)
26 }
27 return obj
28 }
29
30 function createObjects(rgSourceComponents, parentObject, addMapItem) {
31 if (arguments.length < 3) {
32 addMapItem = false
33 }
34 for (var i=0; i<rgSourceComponents.length; i++) {
35 createObject(rgSourceComponents[i], parentObject, addMapItem)
36 }
37 }
38
39 /// Adds the object to the list. If mapControl is specified it will aso be added to the map.
40 function addObject(object, mapControl) {
41 rgDynamicObjects.push(object)
42 if (arguments.length == 2) {
43 mapControl.addMapItem(object)
44 }
45 return object
46 }
47
48 function destroyObjects() {
49 for (var i=0; i<rgDynamicObjects.length; i++) {
50 rgDynamicObjects[i].destroy()
51 }
52 rgDynamicObjects = [ ]
53 }
54}