mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
b9b1b3146b
Replace UUIDs from LocationInformationModel and fix the fallout. Notably, replace the UUID "column" by a DIVESITE "column". Getting pointers through Qt's QVariant is horrible, we'll have to think about a better solution. RECENTLY_ADDED_DIVESITE now defines to a special pointer to struct dive_site (defined as ~0). This fixes an interesting logic bug: The old code checked the uuid of the LocationInformationModel (currUuid) for the value "1", which corresponded to RECENTLY_ADDED_DIVESITE. If equal, currType would be set to NEW_DIVE_SITE. Later, _currType_ was compared against _RECENTLY_ADDED_DIVESITE_. This would only work because NEW_DIVE_SITE and RECENTLY_ADDED_DIVESITE both were defined as 1. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef DIVELOCATIONMODEL_H
|
|
#define DIVELOCATIONMODEL_H
|
|
|
|
#include <QAbstractTableModel>
|
|
#include <QStringListModel>
|
|
#include <QSortFilterProxyModel>
|
|
#include <stdint.h>
|
|
#include "core/units.h"
|
|
|
|
#define RECENTLY_ADDED_DIVESITE ((struct dive_site *)~0)
|
|
|
|
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 { DIVESITE, NAME, LATITUDE, LONGITUDE, COORDS, DESCRIPTION, NOTES, 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());
|
|
|
|
public slots:
|
|
void update();
|
|
QStringList allSiteNames() const;
|
|
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
|