Centralize multiple delegate for different graphical objects in MapItemView
-
Re: Delegate for different graphical objects in MapItemView
Hi
i'm reopening this old subject as i struggling with the exact same issue.To sum it up i'd like to have a qml file to centralise the delegates that will be used to print items in my MapItemView.
Here's where i'm at :
In my main map view :
MapItemView { id: mapMarkers model: MapMarkerModels{} delegate: MapMarkerMultiDelegate{} }
MapMarkerModels.qml
ListModel { id: someModels ListElement {type: "cursor"; lat: 43.778958; lon:3.812109} ListElement {type: "circle"; lat: 43.788958; lon:3.812109} ListElement {type: "circle"; lat: 43.798958; lon:3.812109} }
and MapMarkerMultiDelegate.qml
Loader { id: mapMarkerMultiDelegate sourceComponent: getDelegate(type) function getDelegate(t) { switch(t) { case "cursor": return cursorDelegate; case "circle": return circleDelegate; default: return circleDelegate; } } Component { id: cursorDelegate MapQuickItem { id: cursor anchorPoint.x: rect.width / 2 anchorPoint.y: rect.height / 2 coordinate { latitude: lat longitude: lon } sourceItem: Rectangle { id: rect width: 25 height: 25 color: "blue" } } } Component { id: circleDelegate MapCircle { center { latitude: lat longitude: lon } radius: 500.0 color: 'green' border.width: 3 } } }
It doesn't show anything on the map.
If y break in "getDelegate(type)" it seems to be returning the good component.
But I get a message in the output :
"addDelegateToMap called with a MapMarkerMultiDelegate_QMLTYPE_1"If i remove the Loader and simply put one of the Component in the MapMarkerMultiDelegate.qml file it works fine and print what i want.
I've only be playing with Qt for a few days so i might be doing everything wrong. Still this is tickeling me so if any of you have an idea =)
-
Re: Delegate for different graphical objects in MapItemView
Hi
i'm reopening this old subject as i struggling with the exact same issue.To sum it up i'd like to have a qml file to centralise the delegates that will be used to print items in my MapItemView.
Here's where i'm at :
In my main map view :
MapItemView { id: mapMarkers model: MapMarkerModels{} delegate: MapMarkerMultiDelegate{} }
MapMarkerModels.qml
ListModel { id: someModels ListElement {type: "cursor"; lat: 43.778958; lon:3.812109} ListElement {type: "circle"; lat: 43.788958; lon:3.812109} ListElement {type: "circle"; lat: 43.798958; lon:3.812109} }
and MapMarkerMultiDelegate.qml
Loader { id: mapMarkerMultiDelegate sourceComponent: getDelegate(type) function getDelegate(t) { switch(t) { case "cursor": return cursorDelegate; case "circle": return circleDelegate; default: return circleDelegate; } } Component { id: cursorDelegate MapQuickItem { id: cursor anchorPoint.x: rect.width / 2 anchorPoint.y: rect.height / 2 coordinate { latitude: lat longitude: lon } sourceItem: Rectangle { id: rect width: 25 height: 25 color: "blue" } } } Component { id: circleDelegate MapCircle { center { latitude: lat longitude: lon } radius: 500.0 color: 'green' border.width: 3 } } }
It doesn't show anything on the map.
If y break in "getDelegate(type)" it seems to be returning the good component.
But I get a message in the output :
"addDelegateToMap called with a MapMarkerMultiDelegate_QMLTYPE_1"If i remove the Loader and simply put one of the Component in the MapMarkerMultiDelegate.qml file it works fine and print what i want.
I've only be playing with Qt for a few days so i might be doing everything wrong. Still this is tickeling me so if any of you have an idea =)
-
@Coubz Use DelegateChooser instead of Loader.
A Loader is an Item but MapItemView needs a MapItem.@GrecKo said in Centralize multiple delegate for different graphical objects in MapItemView:
DelegateChooser
Well it works like a charm, thank you =)
Here the updated QML just for the next one that will have the same problem.
MapMarkerMultiDelegate.qml
DelegateChooser { id: mapMarkerDelegateChooser role: "type" DelegateChoice { id: cursorDelegate roleValue: "cursor" MapQuickItem { id: cursor anchorPoint.x: rect.width / 2 anchorPoint.y: rect.height / 2 coordinate { latitude: lat longitude: lon } sourceItem: Rectangle { id: rect width: 25 height: 25 color: "blue" } } } DelegateChoice { id: circleDelegate roleValue: "circle" MapCircle { center: markerCoordinate radius: 500.0 color: 'green' border.width: 3 } } }
And thx again !
-