我想用来自 a 的地图元素(如 MapCircle,...)填充 Qml 地图QAbstractListModel
。似乎有两个 Qml 工具适合于此,MapItemView
[1] 和Repeater
[2]。这Repeater
更强大(例如,它允许嵌套模型) - 那么有什么理由使用MapItemView
代替Repeater
?
Regards,
[1] http://doc.qt.io/qt-5/qml-qtlocation-mapitemview.html http://doc.qt.io/qt-5/qml-qtlocation-mapitemview.html
[2] http://doc.qt.io/qt-5/qml-qtquick-repeater.html http://doc.qt.io/qt-5/qml-qtquick-repeater.html
MapItemView来源:http://code.qt.io/cgit/qt/qtlocation.git/tree/src/location/declarativemaps/qdeclarativegeomapitemview.cpp http://code.qt.io/cgit/qt/qtlocation.git/tree/src/location/declarativemaps/qdeclarativegeomapitemview.cpp
中继器来源:http://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/quick/items/qquickrepeater.cpp http://code.qt.io/cgit/qt/qtdeclarative.git/tree/src/quick/items/qquickrepeater.cpp
你应该使用MapItemView
为了那个原因。
使用Repeater
仅当您创建时才有效Map
,如果您随后在模型中添加元素,则不会将任何委托添加到 Map 中。
事实上,它首先适用于Repeater
但之后不是因为:
- the
Repeater
父母他的代表给他的父母,这是Map
- The
Map
然后,对象在创建时扫描其子项一次(在 C++ 函数中相当于Component.onCompleted
)
- 经过这次扫描,孩子们
MapItem
- 派生对象被添加到地图中,就像手动调用时一样Map.addMapItem() http://doc.qt.io/qt-5/qml-qtlocation-map.html#addMapItem-method
- 之后创建的代表由
Repeater
只是作为父级Map
但并没有真正“添加”到其中。
Since MapItemView
知道Map
它可以将代表添加到Map
当它创建它们时。
限制之一是MapItemView
是它只适用于QAbstractItemModel
并得出。这意味着它可以与ListModel
或 C++ 模型,但不能使用像 js 数组或整数这样的“哑”模型作为模型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)