2016-09-23 100 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); 
     } 
     } 
    } 
}