2017-07-17 14:58:34 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef MAPLOCATIONMODEL_H
|
|
|
|
#define MAPLOCATIONMODEL_H
|
|
|
|
|
2020-02-03 18:33:06 +00:00
|
|
|
#include "core/subsurface-qt/divelistnotifier.h"
|
2024-05-11 11:21:53 +00:00
|
|
|
#include <vector>
|
2017-07-17 14:58:34 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QAbstractListModel>
|
2017-07-17 19:36:55 +00:00
|
|
|
#include <QGeoCoordinate>
|
2017-07-17 14:58:34 +00:00
|
|
|
|
2019-08-31 22:24:18 +00:00
|
|
|
class MapLocation
|
2017-07-17 14:58:34 +00:00
|
|
|
{
|
|
|
|
public:
|
2024-05-11 11:21:53 +00:00
|
|
|
MapLocation(struct dive_site *ds, QGeoCoordinate coord, QString name, bool selected);
|
2017-07-17 14:58:34 +00:00
|
|
|
|
|
|
|
QVariant getRole(int role) const;
|
|
|
|
|
|
|
|
enum Roles {
|
2018-10-26 15:03:54 +00:00
|
|
|
RoleDivesite = Qt::UserRole + 1,
|
2017-07-25 20:15:28 +00:00
|
|
|
RoleCoordinate,
|
2019-08-30 13:25:59 +00:00
|
|
|
RoleName,
|
2019-08-30 16:09:37 +00:00
|
|
|
RolePixmap,
|
2019-08-31 21:24:21 +00:00
|
|
|
RoleZ,
|
|
|
|
RoleIsSelected
|
2017-07-17 14:58:34 +00:00
|
|
|
};
|
|
|
|
|
2019-08-31 22:18:15 +00:00
|
|
|
struct dive_site *divesite;
|
|
|
|
QGeoCoordinate coordinate;
|
|
|
|
QString name;
|
2019-08-31 22:26:51 +00:00
|
|
|
bool selected;
|
2017-07-17 14:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MapLocationModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
MapLocationModel(QObject *parent = NULL);
|
|
|
|
~MapLocationModel();
|
|
|
|
|
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 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);
|
2019-08-30 14:51:59 +00:00
|
|
|
void selectionChanged();
|
2024-05-11 11:21:53 +00:00
|
|
|
void setSelected(const std::vector<dive_site *> &divesites);
|
|
|
|
MapLocation *getMapLocation(const struct dive_site *ds); // Attention: not stable!
|
|
|
|
const std::vector<dive_site *> &selectedDs() const;
|
2019-08-31 21:34:17 +00:00
|
|
|
void setSelected(struct dive_site *ds);
|
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
|
|
|
|
2019-05-09 19:33:01 +00:00
|
|
|
private slots:
|
|
|
|
void diveSiteChanged(struct dive_site *ds, int field);
|
|
|
|
|
2017-07-24 18:17:11 +00:00
|
|
|
private:
|
2024-05-11 11:21:53 +00:00
|
|
|
std::vector<MapLocation> m_mapLocations;
|
|
|
|
std::vector<dive_site *> m_selectedDs;
|
2017-07-17 14:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|