2017-04-27 18:25:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-05-30 00:19:44 +00:00
|
|
|
#ifndef DIVELOCATIONMODEL_H
|
|
|
|
#define DIVELOCATIONMODEL_H
|
|
|
|
|
2015-07-01 21:46:27 +00:00
|
|
|
#include <QAbstractTableModel>
|
2015-06-22 20:24:15 +00:00
|
|
|
#include <QStringListModel>
|
2018-10-08 17:29:47 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/units.h"
|
2015-08-31 23:37:49 +00:00
|
|
|
|
2018-10-25 06:02:06 +00:00
|
|
|
#define RECENTLY_ADDED_DIVESITE ((struct dive_site *)~0)
|
2015-08-26 00:03:20 +00:00
|
|
|
|
2019-03-10 15:03:39 +00:00
|
|
|
struct dive;
|
|
|
|
struct dive_trip;
|
|
|
|
|
2015-07-01 21:46:27 +00:00
|
|
|
class LocationInformationModel : public QAbstractTableModel {
|
2019-03-12 06:24:54 +00:00
|
|
|
Q_OBJECT
|
2015-05-30 00:19:44 +00:00
|
|
|
public:
|
2018-10-09 10:26:58 +00:00
|
|
|
// Common columns, roles and accessor function for all dive-site models.
|
|
|
|
// Thus, different views can connect to different models.
|
2019-03-16 10:35:44 +00:00
|
|
|
enum Columns { EDIT, REMOVE, NAME, DESCRIPTION, NUM_DIVES, LOCATION, NOTES, DIVESITE, TAXONOMY, COLUMNS };
|
2018-10-24 14:34:43 +00:00
|
|
|
enum Roles { DIVESITE_ROLE = Qt::UserRole + 1 };
|
2018-10-09 10:26:58 +00:00
|
|
|
static QVariant getDiveSiteData(const struct dive_site *ds, int column, int role);
|
|
|
|
|
|
|
|
LocationInformationModel(QObject *obj = 0);
|
2015-05-30 01:22:24 +00:00
|
|
|
static LocationInformationModel *instance();
|
2015-07-01 21:46:27 +00:00
|
|
|
int columnCount(const QModelIndex &parent) const;
|
2015-05-30 00:19:44 +00:00
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const;
|
2019-03-09 21:32:16 +00:00
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2015-06-02 02:13:51 +00:00
|
|
|
|
2015-05-30 01:22:24 +00:00
|
|
|
public slots:
|
2015-05-30 00:19:44 +00:00
|
|
|
void update();
|
cleanup: invert control-flow when resetting the core structures
To reset the core data structures, the mobile and desktop UIs
were calling into the dive-list models, which then reset the
core data structures, themselves and the unrelated
locationinformation model. The UI code then reset various other
things, such as the TankInformation model or the map. . This was
unsatisfying from a control-flow perspective, as the models should
display the core data, not act on it. Moreover, this meant lots
of intricate intermodule-dependencies.
Thus, straighten up the control flow: give the C core the
possibility to send a "all data reset" event. And do that
in those functions that reset the core data structures.
Let each module react to this event by itself. This removes
inter-module dependencies. For example, the MainWindow now
doesn't have to reset the TankInfoModel or the MapWidget.
Then, to reset the core data structures, let the UI code
simply directly call the respective core functions.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-04 22:12:36 +00:00
|
|
|
private slots:
|
2019-03-10 15:03:39 +00:00
|
|
|
void diveSiteDiveCountChanged(struct dive_site *ds);
|
2019-03-11 23:25:31 +00:00
|
|
|
void diveSiteAdded(struct dive_site *ds, int idx);
|
|
|
|
void diveSiteDeleted(struct dive_site *ds, int idx);
|
2019-03-12 22:51:39 +00:00
|
|
|
void diveSiteChanged(struct dive_site *ds, int field);
|
2019-03-20 20:46:58 +00:00
|
|
|
void diveSiteDivesChanged(struct dive_site *ds);
|
2019-03-12 16:28:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DiveSiteSortedModel : public QSortFilterProxyModel {
|
|
|
|
Q_OBJECT
|
2015-05-30 00:19:44 +00:00
|
|
|
private:
|
2019-03-12 16:28:43 +00:00
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override;
|
|
|
|
bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
|
2019-03-24 16:11:29 +00:00
|
|
|
QString fullText;
|
2019-03-12 22:51:39 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
|
|
|
#endif // SUBSURFACE_MOBILE
|
2019-03-12 16:28:43 +00:00
|
|
|
public:
|
|
|
|
DiveSiteSortedModel();
|
|
|
|
QStringList allSiteNames() const;
|
2019-03-24 16:11:29 +00:00
|
|
|
void setFilter(const QString &text);
|
2019-04-12 14:12:15 +00:00
|
|
|
struct dive_site *getDiveSite(const QModelIndex &idx);
|
2015-05-30 00:19:44 +00:00
|
|
|
};
|
|
|
|
|
2018-10-08 17:01:45 +00: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 06:24:54 +00:00
|
|
|
Q_OBJECT
|
2018-10-08 17:01:45 +00:00
|
|
|
private:
|
2018-10-25 06:02:06 +00:00
|
|
|
const struct dive_site *ignoreDs;
|
2018-10-20 18:12:15 +00:00
|
|
|
location_t location;
|
2019-03-25 21:18:32 +00:00
|
|
|
int64_t distance;
|
2018-10-08 17:01:45 +00:00
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override;
|
|
|
|
public:
|
|
|
|
GPSLocationInformationModel(QObject *parent = nullptr);
|
2018-10-25 06:02:06 +00:00
|
|
|
void set(const struct dive_site *ignoreDs, const location_t &);
|
2018-10-20 18:12:15 +00:00
|
|
|
void setCoordinates(const location_t &);
|
2019-03-25 21:18:32 +00:00
|
|
|
void setDistance(int64_t dist); // Distance from coordinates in mm
|
2018-10-08 17:01:45 +00:00
|
|
|
};
|
|
|
|
|
2015-06-22 20:24:15 +00:00
|
|
|
class GeoReferencingOptionsModel : public QStringListModel {
|
2019-03-12 06:24:54 +00:00
|
|
|
Q_OBJECT
|
2015-06-22 20:24:15 +00:00
|
|
|
public:
|
|
|
|
static GeoReferencingOptionsModel *instance();
|
|
|
|
private:
|
|
|
|
GeoReferencingOptionsModel(QObject *parent = 0);
|
|
|
|
};
|
|
|
|
|
2015-05-30 00:19:44 +00:00
|
|
|
#endif
|