AbstractItemModel到QML路由

时间:2017-09-02 18:54:40

标签: qt qml qtquick2 qtlocation

我在QPointF中有一组MarkerModel,其中AbstractListModel的子类。每个这样的标记具有状态,取决于它们被着色的状态。我想在地图上绘制所有这些标记以及连接具有特定状态的所有点的折线。我将从C ++方面更新模型。这是我的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
        }
    }
}

我实际上想要场景中的点和折线。然而,由于我不知道如何将它们放在场景中,所以我首先尝试使用markerDelegate显示模型中的点,这是有效的。现在我想将这些点视为带有routeDelegate的折线。但它抱怨

  

无法将MarkerModel指定给QDeclarativeGeoRoute

1 个答案:

答案 0 :(得分:0)

如果您通过MapItemView从RouteModel中获取MapRoute,则始终将 routeData 分配给路由。 routeData 是RouteModel公开的role,允许您访问Route元素。

现在,根据您的具体情况,似乎MapRoute不合适。 在我看来,最好的方法是有两个独立的模型:一个暴露每行一个js数组,一个暴露给一个MapPolyline委托的路径属性,一个暴露一个QGeoCoordinate每行(这么多行),你将使用使用MapCircle或MapQuickItem委托

相关问题