subsurface/qt-models/divelocationmodel.h
Berthold Stoeger 8dcc33d8ab Undo: keep frontend informed of changes to dive site count
Add a new signal to DiveListNotifier. Send signal if dives are
added or removed and therefore the dive count of a dive site
changes. The dive sites are collected and the signal is sent
at the end of the command.

Add code to update the table view.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00

62 lines
2.2 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef DIVELOCATIONMODEL_H
#define DIVELOCATIONMODEL_H
#include <QAbstractTableModel>
#include <QStringListModel>
#include <QSortFilterProxyModel>
#include "core/units.h"
#define RECENTLY_ADDED_DIVESITE ((struct dive_site *)~0)
struct dive;
struct dive_trip;
class LocationInformationModel : public QAbstractTableModel {
Q_OBJECT
public:
// Common columns, roles and accessor function for all dive-site models.
// Thus, different views can connect to different models.
enum Columns { REMOVE, NAME, DESCRIPTION, NUM_DIVES, COORDS, NOTES, LATITUDE, LONGITUDE, DIVESITE, TAXONOMY_1, TAXONOMY_2, TAXONOMY_3, COLUMNS};
enum Roles { DIVESITE_ROLE = Qt::UserRole + 1 };
static QVariant getDiveSiteData(const struct dive_site *ds, int column, int role);
LocationInformationModel(QObject *obj = 0);
static LocationInformationModel *instance();
int columnCount(const QModelIndex &parent) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const;
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
public slots:
void update();
QStringList allSiteNames() const;
void diveSiteDiveCountChanged(struct dive_site *ds);
private:
QStringList locationNames;
};
// To access only divesites at the given GPS coordinates with the exception of a given dive site
class GPSLocationInformationModel : public QSortFilterProxyModel {
Q_OBJECT
private:
const struct dive_site *ignoreDs;
location_t location;
bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override;
public:
GPSLocationInformationModel(QObject *parent = nullptr);
void set(const struct dive_site *ignoreDs, const location_t &);
void setCoordinates(const location_t &);
};
class GeoReferencingOptionsModel : public QStringListModel {
Q_OBJECT
public:
static GeoReferencingOptionsModel *instance();
private:
GeoReferencingOptionsModel(QObject *parent = 0);
};
#endif