mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive locations: factor out common code of models
For increased maintainability, use the same columns, roles and the same accessor function for both dive-site models. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
19d651a36b
commit
d6010b5155
4 changed files with 28 additions and 45 deletions
|
@ -32,20 +32,15 @@ int LocationInformationModel::rowCount(const QModelIndex&) const
|
|||
return dive_site_table.nr;
|
||||
}
|
||||
|
||||
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
||||
QVariant LocationInformationModel::getDiveSiteData(const struct dive_site *ds, int column, int role)
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
struct dive_site *ds = get_dive_site(index.row());
|
||||
|
||||
if (!ds)
|
||||
return QVariant();
|
||||
|
||||
switch(role) {
|
||||
case Qt::EditRole:
|
||||
case Qt::DisplayRole :
|
||||
switch(index.column()) {
|
||||
switch(column) {
|
||||
case UUID: return ds->uuid;
|
||||
case NAME: return ds->name;
|
||||
case LATITUDE: return ds->latitude.udeg;
|
||||
|
@ -70,6 +65,15 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
struct dive_site *ds = get_dive_site(index.row());
|
||||
return getDiveSiteData(ds, index.column(), role);
|
||||
}
|
||||
|
||||
void LocationInformationModel::update()
|
||||
{
|
||||
beginResetModel();
|
||||
|
|
|
@ -8,18 +8,21 @@
|
|||
#include "core/units.h"
|
||||
#include "ssrfsortfilterproxymodel.h"
|
||||
|
||||
class QLineEdit;
|
||||
|
||||
#define RECENTLY_ADDED_DIVESITE 1
|
||||
|
||||
bool filter_same_gps_cb (QAbstractItemModel *m, int sourceRow, const QModelIndex& parent);
|
||||
|
||||
|
||||
class LocationInformationModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
LocationInformationModel(QObject *obj = 0);
|
||||
// Common columns, roles and accessor function for all dive-site models.
|
||||
// Thus, different views can connect to different models.
|
||||
enum Columns { UUID, NAME, LATITUDE, LONGITUDE, COORDS, DESCRIPTION, NOTES, TAXONOMY_1, TAXONOMY_2, TAXONOMY_3, COLUMNS};
|
||||
enum Roles { UUID_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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue