4 #include <QAbstractListModel>
5 #include <QGeoCoordinate>
7 class MarkerModel : public QAbstractListModel
12 using QAbstractListModel::QAbstractListModel;
13 enum MarkerRoles{positionRole = Qt::UserRole + 1};
15 Q_INVOKABLE void addMarker(const QGeoCoordinate &coordinate){
16 beginInsertRows(QModelIndex(), rowCount(), rowCount());
17 m_coordinates.append(coordinate);
21 Q_INVOKABLE void removeMarker(){
23 m_coordinates.clear();
27 int rowCount(const QModelIndex &parent = QModelIndex()) const override{
29 return m_coordinates.count();
32 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override{
33 if (index.row() < 0 || index.row() >= m_coordinates.count())
35 if(role== MarkerModel::positionRole)
36 return QVariant::fromValue(m_coordinates[index.row()]);
40 QHash<int, QByteArray> roleNames() const{
41 QHash<int, QByteArray> roles;
42 roles[positionRole] = "position";
47 QList<QGeoCoordinate> m_coordinates;
50 #endif // MARKERMODEL_H