2017-07-24 48 views
0

我正在嘗試構建一個交互式地圖應用程序,允許我添加和修改地圖項目。我能夠添加新的地圖項目,但我仍然有問題來修改模型。在下面的代碼中,如果我有多個項目,remove函數總是刪除第一個項目,而不是當前選定的項目。我想修改模型不僅是模型的視圖,但我怎樣才能得到模型的currentIndex從MapItemView獲取模型索引

ListModel { 
    id: mapModel 
} 

Map { 
    id: map 
    //... 
    MapItemView { 
     model: mapModel 
     delegate: MapCircle { 
      radius: 80000 
      color: 'blue' 
      center { 
       latitude: lat 
       longitude: longi 
      } 
      MouseArea { 
       onClicked: { 
        mapModel.remove(model.index) 
       } 
      } 
     } 
    } 
    MouseArea { 
     anchors.fill: parent 
     onClicked: { 
      var coord = map.toCoordinate(Qt.point(mouse.x,mouse.y)) 
      mapModel.append({lat : coord.latitude, longi: coord.longitude}); 
     } 
    } 
} 

回答

1

自己找到答案。只需使用mapModel.remove(index)而不是mapModel.remove(model.index)