2017-07-17 17:58:34 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef MAPLOCATIONMODEL_H
|
|
|
|
#define MAPLOCATIONMODEL_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2017-07-17 23:04:00 +03:00
|
|
|
#include <QVector>
|
2017-07-17 17:58:34 +03:00
|
|
|
#include <QHash>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QAbstractListModel>
|
2017-07-17 22:36:55 +03:00
|
|
|
#include <QGeoCoordinate>
|
2017-07-17 17:58:34 +03:00
|
|
|
|
|
|
|
class MapLocation : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2017-07-27 22:43:10 +03:00
|
|
|
Q_PROPERTY(quint32 uuid READ uuid)
|
|
|
|
Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged)
|
2017-07-25 23:15:28 +03:00
|
|
|
Q_PROPERTY(QString name MEMBER m_name)
|
2017-07-17 17:58:34 +03:00
|
|
|
|
|
|
|
public:
|
2017-07-19 02:02:43 +03:00
|
|
|
static const char *PROPERTY_NAME_COORDINATE;
|
|
|
|
static const char *PROPERTY_NAME_UUID;
|
2017-07-25 23:15:28 +03:00
|
|
|
static const char *PROPERTY_NAME_NAME;
|
2017-07-19 02:02:43 +03:00
|
|
|
|
2017-07-17 17:58:34 +03:00
|
|
|
explicit MapLocation();
|
2017-07-25 23:15:28 +03:00
|
|
|
explicit MapLocation(quint32 uuid, QGeoCoordinate coord, QString name);
|
2017-07-17 17:58:34 +03:00
|
|
|
|
|
|
|
QVariant getRole(int role) const;
|
2017-07-27 22:43:10 +03:00
|
|
|
QGeoCoordinate coordinate();
|
|
|
|
void setCoordinate(QGeoCoordinate coord);
|
2017-11-09 18:43:21 +02:00
|
|
|
void setCoordinateNoEmit(QGeoCoordinate coord);
|
2017-07-27 22:43:10 +03:00
|
|
|
quint32 uuid();
|
2017-07-17 17:58:34 +03:00
|
|
|
|
|
|
|
enum Roles {
|
2017-07-19 02:02:43 +03:00
|
|
|
RoleUuid = Qt::UserRole + 1,
|
2017-07-25 23:15:28 +03:00
|
|
|
RoleCoordinate,
|
|
|
|
RoleName
|
2017-07-17 17:58:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2017-07-19 02:02:43 +03:00
|
|
|
quint32 m_uuid;
|
2017-07-17 22:36:55 +03:00
|
|
|
QGeoCoordinate m_coordinate;
|
2017-07-25 23:15:28 +03:00
|
|
|
QString m_name;
|
2017-07-27 22:43:10 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void coordinateChanged();
|
2017-07-17 17:58:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class MapLocationModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
2017-07-27 23:07:37 +03:00
|
|
|
Q_PROPERTY(quint32 selectedUuid READ selectedUuid NOTIFY selectedUuidChanged)
|
2017-07-17 17:58:34 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
MapLocationModel(QObject *parent = NULL);
|
|
|
|
~MapLocationModel();
|
|
|
|
|
|
|
|
Q_INVOKABLE MapLocation *get(int row);
|
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
|
|
|
int count();
|
2017-07-17 22:12:04 +03:00
|
|
|
void add(MapLocation *);
|
2017-07-17 23:04:00 +03:00
|
|
|
void addList(QVector<MapLocation *>);
|
2017-07-17 22:12:04 +03:00
|
|
|
void clear();
|
2017-07-19 03:02:34 +03:00
|
|
|
MapLocation *getMapLocationForUuid(quint32 uuid);
|
2017-11-09 18:43:21 +02:00
|
|
|
void updateMapLocationCoordinates(quint32 uuid, QGeoCoordinate coord);
|
2017-07-24 21:17:11 +03:00
|
|
|
Q_INVOKABLE void setSelectedUuid(QVariant uuid, QVariant fromClick = true);
|
2017-07-27 23:07:37 +03:00
|
|
|
quint32 selectedUuid();
|
2017-07-17 17:58:34 +03:00
|
|
|
|
|
|
|
protected:
|
2017-07-28 21:18:38 -07:00
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
2017-07-17 17:58:34 +03:00
|
|
|
|
2017-07-24 21:17:11 +03:00
|
|
|
private:
|
2017-07-17 23:04:00 +03:00
|
|
|
QVector<MapLocation *> m_mapLocations;
|
2017-07-17 17:58:34 +03:00
|
|
|
QHash<int, QByteArray> m_roles;
|
2017-07-19 02:27:30 +03:00
|
|
|
quint32 m_selectedUuid;
|
2017-07-17 17:58:34 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void countChanged(int c);
|
2017-07-27 23:07:37 +03:00
|
|
|
void selectedUuidChanged();
|
2017-07-19 02:27:30 +03:00
|
|
|
void selectedLocationChanged(MapLocation *);
|
2017-07-17 17:58:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|