2017-07-17 14:58:34 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef MAPLOCATIONMODEL_H
|
|
|
|
#define MAPLOCATIONMODEL_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2017-07-17 20:04:00 +00:00
|
|
|
#include <QVector>
|
2017-07-17 14:58:34 +00:00
|
|
|
#include <QHash>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QAbstractListModel>
|
2017-07-17 19:36:55 +00:00
|
|
|
#include <QGeoCoordinate>
|
2017-07-17 14:58:34 +00:00
|
|
|
|
|
|
|
class MapLocation : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-10-26 15:03:54 +00:00
|
|
|
Q_PROPERTY(QVariant divesite READ divesiteVariant)
|
2017-07-27 19:43:10 +00:00
|
|
|
Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged)
|
2017-07-25 20:15:28 +00:00
|
|
|
Q_PROPERTY(QString name MEMBER m_name)
|
2017-07-17 14:58:34 +00:00
|
|
|
|
|
|
|
public:
|
2017-07-18 23:02:43 +00:00
|
|
|
static const char *PROPERTY_NAME_COORDINATE;
|
2018-10-26 15:03:54 +00:00
|
|
|
static const char *PROPERTY_NAME_DIVESITE;
|
2017-07-25 20:15:28 +00:00
|
|
|
static const char *PROPERTY_NAME_NAME;
|
2017-07-18 23:02:43 +00:00
|
|
|
|
2017-07-17 14:58:34 +00:00
|
|
|
explicit MapLocation();
|
2018-10-26 15:03:54 +00:00
|
|
|
explicit MapLocation(struct dive_site *ds, QGeoCoordinate coord, QString name);
|
2017-07-17 14:58:34 +00:00
|
|
|
|
|
|
|
QVariant getRole(int role) const;
|
2017-07-27 19:43:10 +00:00
|
|
|
QGeoCoordinate coordinate();
|
|
|
|
void setCoordinate(QGeoCoordinate coord);
|
2017-11-09 16:43:21 +00:00
|
|
|
void setCoordinateNoEmit(QGeoCoordinate coord);
|
2018-10-26 15:03:54 +00:00
|
|
|
QVariant divesiteVariant();
|
|
|
|
struct dive_site *divesite();
|
2017-07-17 14:58:34 +00:00
|
|
|
|
|
|
|
enum Roles {
|
2018-10-26 15:03:54 +00:00
|
|
|
RoleDivesite = Qt::UserRole + 1,
|
2017-07-25 20:15:28 +00:00
|
|
|
RoleCoordinate,
|
|
|
|
RoleName
|
2017-07-17 14:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2018-10-26 15:03:54 +00:00
|
|
|
struct dive_site *m_ds;
|
2017-07-17 19:36:55 +00:00
|
|
|
QGeoCoordinate m_coordinate;
|
2017-07-25 20:15:28 +00:00
|
|
|
QString m_name;
|
2017-07-27 19:43:10 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void coordinateChanged();
|
2017-07-17 14:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MapLocationModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
|
|
|
|
|
|
|
public:
|
|
|
|
MapLocationModel(QObject *parent = NULL);
|
|
|
|
~MapLocationModel();
|
|
|
|
|
|
|
|
Q_INVOKABLE MapLocation *get(int row);
|
2018-09-29 20:13:44 +00:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override;
|
|
|
|
int rowCount(const QModelIndex &parent) const override;
|
2017-07-17 14:58:34 +00:00
|
|
|
int count();
|
2017-07-17 19:12:04 +00:00
|
|
|
void add(MapLocation *);
|
2019-05-08 20:15:01 +00:00
|
|
|
// If map is not null, it will be used to place new dive sites without GPS location at the center of the map
|
|
|
|
void reload(QObject *map);
|
2018-10-26 15:03:54 +00:00
|
|
|
MapLocation *getMapLocation(const struct dive_site *ds);
|
2019-05-03 21:16:40 +00:00
|
|
|
const QVector<dive_site *> &selectedDs() const;
|
2018-10-26 15:03:54 +00:00
|
|
|
void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord);
|
2018-10-28 21:19:17 +00:00
|
|
|
Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true);
|
2019-05-01 22:09:59 +00:00
|
|
|
// The dive site is passed as a QVariant, because a null-QVariant is not automatically
|
|
|
|
// transformed into a null pointer and warning messages are spewed onto the console.
|
|
|
|
Q_INVOKABLE bool isSelected(const QVariant &ds) const;
|
2017-07-17 14:58:34 +00:00
|
|
|
|
|
|
|
protected:
|
2018-09-29 20:13:44 +00:00
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
2017-07-17 14:58:34 +00:00
|
|
|
|
2017-07-24 18:17:11 +00:00
|
|
|
private:
|
2017-07-17 20:04:00 +00:00
|
|
|
QVector<MapLocation *> m_mapLocations;
|
2017-07-17 14:58:34 +00:00
|
|
|
QHash<int, QByteArray> m_roles;
|
2019-05-01 22:09:59 +00:00
|
|
|
QVector<dive_site *> m_selectedDs;
|
2017-07-17 14:58:34 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void countChanged(int c);
|
2017-07-18 23:27:30 +00:00
|
|
|
void selectedLocationChanged(MapLocation *);
|
2017-07-17 14:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|