2017-09-02 17 views
1

我有一套QPointFMarkerModel,它从AbstractListModel的子类。每个这样的标记都具有一个状态,这取决于它们被着色。我想在地图上绘制所有这些标记以及连接所有具有特定状态的点的多段线。我将从C++端更新模型。这是我的QMLAbstractItemModel到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

回答

0

如果从RouteModel通过MapItemView源图路线,你总是分配的RouteData路由。 routeData是RouteModel公开的role,让您访问Route元素。

现在,对于您的具体情况,似乎MapRoute是不适合的。 最好的方法似乎有2个独立的模型:一个暴露每行一个js数组,一个MapPolyline委托的路径属性,一个公开一个QGeoCoordinate每行(更多行),你会使用MapCircle或MapQuickItem代理

+0

对不起,我不明白,'markerModel'实际上是'AbstractListModel'的子类。我不知道如何在QT中创建'RouteModel'(C++) –

+0

好吧,对不起,我对这个例子感到困惑,也许你可以解决它只保留你使用的委托? 在任何情况下,如果您想要将MapRoute与不是RouteModel的模型一起使用,则必须在模型中通过您提供Route对象(QDeclarativeGeoRoute)来定义角色。 编辑:实际上,现在我再次读你的问题,你不能使用QPointF来创建MapRoute或MapPolyline。您首先必须将它们转换为QGeoCoordinates。 –

+0

如何从C++创建QDeclarativeGeoRoute对象?那个班在哪里? QML中的 –