2016-09-23 99 views

回答

0

基于QList的属性或QAbstractListModel派生类都可以工作。

在QML方面,你会使用或者作为模型使用的Plane类型作为其代表一个Repeater,采取从model手柄坐标

有点像这个

Map { 
    Repeater { 
     model: listOrModelFromCpp 

     delegate: Plane { 
      cooridinate: model.position // or model.modelData for a QList<QGeoCoordinate> as the listOrModelFromCpp 
     } 
    } 
} 

使用自定义QAbstractListModel派生模型的优点是Repeater可以单独创建和销毁Plane项目,而基本列表将要求它在列表的计数更改时重新创建所有项目

1

正确的答案是:使用MapItemView :)

MapItemView { 
    model: planeModel 
    delegate: Plane { } 
} 
0

有两种方法用于地图动态处理项目: void addMapItem(MapItem item)void clearMapItems()

这里是我的项目的代码片段(我猜的,而自我记录):

function clearTargets() 
{ 
    map.clearMapItems(); 
} 

function showPlaneItems(planeItemsToShow) 
{ 
    for (var idx = 0; idx < planeItemsToShow.length; idx++) { 
     var item = planeItemsToShow[idx]; 

     var itemComponent = Qt.createComponent("qrc:/components/Plane.qml"); 
     if (itemComponent.status == Component.Ready) { 
     var itemObject = itemComponent.createObject(map, 
             { 
             "planeName" : item["targetName"], 
             "coordinate" : QtPositioning.coordinate(item["targetLattitude"], 
                       item["targetLongitude"]) 
             } 
            ); 
     if (itemObject != null) { 
      map.addMapItem(itemObject); 
     } 
     } 
    } 
}