From 1f875de1d513c733550401ee40fa289fb2acb57e Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Wed, 24 Jul 2019 12:09:40 -0400 Subject: Initial import from github Import from http://github.com/YoshitoMomiyama/aglqtnavigation.git as of commit a6930c2, with the following minor changes: - .gitignore tweaked to remove itself - .gitreview updated Bug-AGL: SPEC-2667 Signed-off-by: Scott Murray Change-Id: I91fed0f6349bf1952e41132058929b70a2b0fe5b --- app/markermodel.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/markermodel.h (limited to 'app/markermodel.h') 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 +#include + +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 roleNames() const{ + QHash roles; + roles[positionRole] = "position"; + return roles; + } + +private: + QList m_coordinates; +}; + +#endif // MARKERMODEL_H -- cgit 1.2.3-korg