2017-04-27 20:25:32 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-05-29 21:19:44 -03:00
|
|
|
#ifndef DIVELOCATIONMODEL_H
|
|
|
|
#define DIVELOCATIONMODEL_H
|
|
|
|
|
2015-07-01 18:46:27 -03:00
|
|
|
#include <QAbstractTableModel>
|
2015-06-22 17:24:15 -03:00
|
|
|
#include <QStringListModel>
|
2018-10-08 19:29:47 +02:00
|
|
|
#include <QSortFilterProxyModel>
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "core/units.h"
|
2015-08-31 20:37:49 -03:00
|
|
|
|
2018-10-25 08:02:06 +02:00
|
|
|
#define RECENTLY_ADDED_DIVESITE ((struct dive_site *)~0)
|
2015-08-25 21:03:20 -03:00
|
|
|
|
2019-03-10 16:03:39 +01:00
|
|
|
struct dive;
|
|
|
|
struct dive_trip;
|
|
|
|
|
2015-07-01 18:46:27 -03:00
|
|
|
class LocationInformationModel : public QAbstractTableModel {
|
2019-03-12 07:24:54 +01:00
|
|
|
Q_OBJECT
|
2015-05-29 21:19:44 -03:00
|
|
|
public:
|
2018-10-09 12:26:58 +02:00
|
|
|
// Common columns, roles and accessor function for all dive-site models.
|
|
|
|
// Thus, different views can connect to different models.
|
2019-03-16 11:35:44 +01:00
|
|
|
enum Columns { EDIT, REMOVE, NAME, DESCRIPTION, NUM_DIVES, LOCATION, NOTES, DIVESITE, TAXONOMY, COLUMNS };
|
2018-10-24 16:34:43 +02:00
|
|
|
enum Roles { DIVESITE_ROLE = Qt::UserRole + 1 };
|
2018-10-09 12:26:58 +02:00
|
|
|
static QVariant getDiveSiteData(const struct dive_site *ds, int column, int role);
|
|
|
|
|
|
|
|
LocationInformationModel(QObject *obj = 0);
|
2015-05-29 22:22:24 -03:00
|
|
|
static LocationInformationModel *instance();
|
2015-07-01 18:46:27 -03:00
|
|
|
int columnCount(const QModelIndex &parent) const;
|
2015-05-29 21:19:44 -03:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const;
|
2019-03-09 22:32:16 +01:00
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2015-06-01 23:13:51 -03:00
|
|
|
|
2015-05-29 22:22:24 -03:00
|
|
|
public slots:
|
2015-05-29 21:19:44 -03:00
|
|
|
void update();
|
2019-03-10 16:03:39 +01:00
|
|
|
void diveSiteDiveCountChanged(struct dive_site *ds);
|
2019-03-12 00:25:31 +01:00
|
|
|
void diveSiteAdded(struct dive_site *ds, int idx);
|
|
|
|
void diveSiteDeleted(struct dive_site *ds, int idx);
|
2019-03-12 23:51:39 +01:00
|
|
|
void diveSiteChanged(struct dive_site *ds, int field);
|
2019-03-20 21:46:58 +01:00
|
|
|
void diveSiteDivesChanged(struct dive_site *ds);
|
2019-03-12 17:28:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class DiveSiteSortedModel : public QSortFilterProxyModel {
|
|
|
|
Q_OBJECT
|
2015-05-29 21:19:44 -03:00
|
|
|
private:
|
2019-03-12 17:28:43 +01:00
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override;
|
|
|
|
bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
|
2019-03-24 17:11:29 +01:00
|
|
|
QString fullText;
|
2019-03-12 23:51:39 +01:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
2019-03-12 22:35:43 +01:00
|
|
|
public slots:
|
|
|
|
void remove(const QModelIndex &index);
|
2019-03-12 23:51:39 +01:00
|
|
|
#endif // SUBSURFACE_MOBILE
|
2019-03-12 17:28:43 +01:00
|
|
|
public:
|
|
|
|
DiveSiteSortedModel();
|
|
|
|
QStringList allSiteNames() const;
|
2019-03-24 17:11:29 +01:00
|
|
|
void setFilter(const QString &text);
|
2019-04-12 16:12:15 +02:00
|
|
|
struct dive_site *getDiveSite(const QModelIndex &idx);
|
2015-05-29 21:19:44 -03:00
|
|
|
};
|
|
|
|
|
2018-10-08 19:01:45 +02:00
|
|
|
// To access only divesites at the given GPS coordinates with the exception of a given dive site
|
|
|
|
class GPSLocationInformationModel : public QSortFilterProxyModel {
|
2019-03-12 07:24:54 +01:00
|
|
|
Q_OBJECT
|
2018-10-08 19:01:45 +02:00
|
|
|
private:
|
2018-10-25 08:02:06 +02:00
|
|
|
const struct dive_site *ignoreDs;
|
2018-10-20 14:12:15 -04:00
|
|
|
location_t location;
|
2019-03-25 22:18:32 +01:00
|
|
|
int64_t distance;
|
2018-10-08 19:01:45 +02:00
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override;
|
|
|
|
public:
|
|
|
|
GPSLocationInformationModel(QObject *parent = nullptr);
|
2018-10-25 08:02:06 +02:00
|
|
|
void set(const struct dive_site *ignoreDs, const location_t &);
|
2018-10-20 14:12:15 -04:00
|
|
|
void setCoordinates(const location_t &);
|
2019-03-25 22:18:32 +01:00
|
|
|
void setDistance(int64_t dist); // Distance from coordinates in mm
|
2018-10-08 19:01:45 +02:00
|
|
|
};
|
|
|
|
|
2015-06-22 17:24:15 -03:00
|
|
|
class GeoReferencingOptionsModel : public QStringListModel {
|
2019-03-12 07:24:54 +01:00
|
|
|
Q_OBJECT
|
2015-06-22 17:24:15 -03:00
|
|
|
public:
|
|
|
|
static GeoReferencingOptionsModel *instance();
|
|
|
|
private:
|
|
|
|
GeoReferencingOptionsModel(QObject *parent = 0);
|
|
|
|
};
|
|
|
|
|
2015-05-29 21:19:44 -03:00
|
|
|
#endif
|