PDA

View Full Version : Loader - propery alias on loaded components



lqsa
15th September 2015, 03:50
I would like to load a Map component in background with a Loader only when the visible Map property is true. Moreover, I need to access the Map center property. How can create a property alias to the Map center property when the Map is loaded with a Loader?

Map2.qml:

import QtQuick 2.0
import QtQuick.Controls 1.3
import QtLocation 5.5
import QtPositioning 5.3

Item {
id: root

property alias center: ?????

Loader {
anchors.fill: parent
id: mapLoader
active: root.visible
sourceComponent: cMap
}
Component {
id: cMap
Item {
anchors.fill: parent
Slider {
id: zoomSlider;
z: map.z + 3
minimumValue: map.minimumZoomLevel;
maximumValue: map.maximumZoomLevel;
anchors.margins: 10
anchors.bottom: parent.bottom
anchors.top: parent.top
anchors.right: parent.right
orientation : Qt.Vertical
value: map.zoomLevel
onValueChanged: {
map.zoomLevel = value
}
}
Map {
id: map
anchors.fill: parent
plugin: osmPlugin
zoomLevel: 7
}
Plugin {
id: osmPlugin
name: "osm"
}

}
}
}

Using on another qml:
...


Map2 {
visible: cbMap.checked
center: QtPositioning.coordinate(1.759767, 1.864124)
}
...

anda_skoa
15th September 2015, 09:22
I don't think that is possible, the alias would "dangling" if the Loader's item is not there.

If you don't need the center property for reading, you could simply make it a normal property (instead of an alias) and then bind the Map's center property to it.

Cheers,
_