I have a set of QPointF
in MarkerModel
which subclasses from AbstractListModel
. Each such marker have a status, depending on which they are colored. I want to draw all these markers on the map along with a polyline that connects all the points that have a specific status. And I will update the model from C++ side. This is my QML
Map {
id: map
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(22.5726, 88.3639)
zoomLevel: 14
MapItemView {
model: markerModel
// delegate: markerDelegate // markerDelegate works
delegate: routeDelegate // routeDelegate does not work
}
Component {
id: markerDelegate
MapQuickItem{
anchorPoint: Qt.point(2.5, 2.5)
coordinate: QtPositioning.coordinate(position.x, position.y)
zoomLevel: 0
sourceItem: Rectangle{
width: settings.marker_size;
height: settings.marker_size;
radius: settings.marker_size/2;
color: settings.marker_colors[status]
border.color: "white"
border.width: 1
}
}
}
Component{
id: routeDelegate
MapRoute{
route: markerModel
line.color: "blue"
line.width: 5
smooth: true
opacity: 0.8
}
}
}
I actually want both, the points and the polyline on the scene. However as I don't know how to put both of them in the scene I was first trying to show the points from the model using markerDelegate
, which worked. Now I want to view these points as a polyline with routeDelegate
. But it complains
Unable to assign MarkerModel to QDeclarativeGeoRoute
If you source MapRoute from a RouteModel through a MapItemView, you always assign routeData to route. routeData is the role that RouteModel exposes, to let you access the Route elements.
Now, for your specific case, it seems that MapRoute is unsuitable. The best approach seems to me to have 2 separate models: one exposing one js array per row, that you assign to the path property of a MapPolyline delegate, and one exposing one QGeoCoordinate per row (so many more rows), that you will use with a MapCircle or a MapQuickItem delegate
来源:https://stackoverflow.com/questions/46017163/abstractitemmodel-to-qml-route