I want to populate a Qml Map with map elements (like MapCircle, ...) from a QAbstractListModel
. There seem to be two Qml tools suitable for this, MapItemView
[1] and Repeater
[2]. The Repeater
is more powerful (e.g. it allows nested models) - so is there any reason to use the MapItemView
instead of a Repeater
?
Regards,
[1] http://doc.qt.io/qt-5/qml-qtlocation-mapitemview.html
[2] http://doc.qt.io/qt-5/qml-qtquick-repeater.html
MapItemView source: http://code.qt.io/cgit/qt/qtlocation.git/tree/src/location/declarativemaps/qdeclarativegeomapitemview.cpp
Repeater source: http://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/quick/items/qquickrepeater.cpp
You should use
MapItemView
for that. UsingRepeater
works only when you create theMap
, if you add elements in your model afterwards, no delegate will be added to the Map.The fact that it works at first with
Repeater
but not afterwards is because:Repeater
parents his delegate to his parent which is theMap
Map
object then scans its child items once when it's created (in a c++ function equivalent toComponent.onCompleted
)MapItem
-derived objects are added to the map like when manually callingMap.addMapItem()
Repeater
are just parented to theMap
but not really "added" to it.Since
MapItemView
is aware of theMap
it can add the delegates to theMap
when it creates them.One of the limitation of
MapItemView
is that it only works withQAbstractItemModel
and derived. That means it can work with aListModel
or a c++ model, but not with a "dumb" model like a js array or an integer as a model.