GeoAreaVisualLoader.qml 1.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3

import QGroundControl.ScreenTools   1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
18
import QGroundControl               1.0
19 20 21 22 23


Item {
    id: _root

Valentin Platzgummer's avatar
Valentin Platzgummer committed
24 25
    property var map: undefined        ///< Map control to place item in
    property var geoArea: undefined    ///< GeoArea derived class
26 27 28

    signal clicked(int sequenceNumber)

Valentin Platzgummer's avatar
Valentin Platzgummer committed
29
    property var _visualItem: undefined
30 31

    Component.onCompleted: {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
32 33 34 35 36
        console.assert(map !== undefined, "please set the map property")
        console.assert(geoArea !== undefined, "please set the geoArea property")

        if (_root.geoArea.mapVisualQML && !_visualItem) {
            var component = Qt.createComponent(_root.geoArea.mapVisualQML)
37
            if (component.status === Component.Error) {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
38
                console.log("Error loading Qml: ", _root.geoArea.mapVisualQML, component.errorString())
39 40 41
            } else {
                _root._visualItem = component.createObject(_root.map, { map: _root.map, geoArea: _root.geoArea})
                _root._visualItem.clicked.connect(_root.clicked)
42 43 44 45 46 47 48 49 50 51
            }
        }
    }

    Component.onDestruction: {
        if (_visualItem) {
            _visualItem.destroy()
        }
    }
}