diff options
author | 2018-11-30 13:23:46 +0900 | |
---|---|---|
committer | 2018-11-30 13:23:46 +0900 | |
commit | 9d57e5b16843759ca97d3cdc6f0310cf4527810a (patch) | |
tree | 7679864f22aa516de5af3f8b31a72bb4bbe85d71 /app/markermodel.h | |
parent | 819d06ad9d8c50ea1e0af26450ee79d2492fea9f (diff) |
add aw navigation
Diffstat (limited to 'app/markermodel.h')
-rw-r--r-- | app/markermodel.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/markermodel.h b/app/markermodel.h new file mode 100644 index 0000000..742dd39 --- /dev/null +++ b/app/markermodel.h @@ -0,0 +1,50 @@ +#ifndef MARKERMODEL_H +#define MARKERMODEL_H + +#include <QAbstractListModel> +#include <QGeoCoordinate> + +class MarkerModel : public QAbstractListModel +{ + Q_OBJECT + +public: + using QAbstractListModel::QAbstractListModel; + enum MarkerRoles{positionRole = Qt::UserRole + 1}; + + Q_INVOKABLE void addMarker(const QGeoCoordinate &coordinate){ + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_coordinates.append(coordinate); + endInsertRows(); + } + + Q_INVOKABLE void removeMarker(){ + beginResetModel(); + m_coordinates.clear(); + endResetModel(); + } + + int rowCount(const QModelIndex &parent = QModelIndex()) const override{ + Q_UNUSED(parent) + return m_coordinates.count(); + } + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override{ + if (index.row() < 0 || index.row() >= m_coordinates.count()) + return QVariant(); + if(role== MarkerModel::positionRole) + return QVariant::fromValue(m_coordinates[index.row()]); + return QVariant(); + } + + QHash<int, QByteArray> roleNames() const{ + QHash<int, QByteArray> roles; + roles[positionRole] = "position"; + return roles; + } + +private: + QList<QGeoCoordinate> m_coordinates; +}; + +#endif // MARKERMODEL_H |