summaryrefslogtreecommitdiffstats
path: root/qt-models/divelocationmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-09 12:26:58 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-09 21:00:44 -0700
commitd6010b5155e7c1b03d1872eb3ed75c39e070ad55 (patch)
treefb8a33c76b4e9a4afd0dafebefa16bd55f76c199 /qt-models/divelocationmodel.cpp
parent19d651a36b8f5c955ef3e147bbb3efa93028f959 (diff)
downloadsubsurface-d6010b5155e7c1b03d1872eb3ed75c39e070ad55.tar.gz
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>
Diffstat (limited to 'qt-models/divelocationmodel.cpp')
-rw-r--r--qt-models/divelocationmodel.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index ba9dede0d..4411f5d98 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -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();