summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-09-01 00:18:15 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-09-06 11:48:47 -0700
commit4eaf6b20bece25516d6ba29e372ac84de690cde7 (patch)
treeecabf091bf6166fd5f67b4acc6f83fae817891da
parentfe07a47989fbcf4b95989d6d32e51da07a5cc211 (diff)
downloadsubsurface-4eaf6b20bece25516d6ba29e372ac84de690cde7.tar.gz
Cleanup: remove accessor functions from MapLocation
Let's face it: this is a value type. No point in having Java-style getters and setters. Replace by plain old and boring member variables. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--map-widget/qmlmapwidgethelper.cpp6
-rw-r--r--qt-models/maplocationmodel.cpp47
-rw-r--r--qt-models/maplocationmodel.h13
3 files changed, 23 insertions, 43 deletions
diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp
index fe43c6fce..9dba8bfd3 100644
--- a/map-widget/qmlmapwidgethelper.cpp
+++ b/map-widget/qmlmapwidgethelper.cpp
@@ -135,7 +135,7 @@ void MapWidgetHelper::selectedLocationChanged(struct dive_site *ds_in)
MapLocation *location = m_mapLocationModel->getMapLocation(ds_in);
if (!location)
return;
- QGeoCoordinate locationCoord = location->coordinate();
+ QGeoCoordinate locationCoord = location->coordinate;
for_each_dive (idx, dive) {
struct dive_site *ds = get_dive_site_for_dive(dive);
@@ -149,7 +149,7 @@ void MapWidgetHelper::selectedLocationChanged(struct dive_site *ds_in)
selectedDiveIds.append(idx);
}
#else // the mobile version doesn't support multi-dive selection
- if (ds == location->divesite())
+ if (ds == location->divesite)
selectedDiveIds.append(dive->id); // use id here instead of index
}
int last; // get latest dive chronologically
@@ -237,7 +237,7 @@ void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *
{
MapLocation *loc = m_mapLocationModel->getMapLocation(ds);
if (loc)
- loc->setCoordinate(coord);
+ loc->coordinate = coord;
location_t location = mk_location(coord);
emit coordinatesChanged(ds, location);
}
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp
index 6b4ab03ad..5ee55069c 100644
--- a/qt-models/maplocationmodel.cpp
+++ b/qt-models/maplocationmodel.cpp
@@ -12,12 +12,12 @@
#define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0
-MapLocation::MapLocation() : m_ds(nullptr), m_selected(false)
+MapLocation::MapLocation() : divesite(nullptr), selected(false)
{
}
-MapLocation::MapLocation(struct dive_site *ds, QGeoCoordinate coord, QString name, bool selected) :
- m_ds(ds), m_coordinate(coord), m_name(name), m_selected(selected)
+MapLocation::MapLocation(struct dive_site *dsIn, QGeoCoordinate coordIn, QString nameIn, bool selectedIn) :
+ divesite(dsIn), coordinate(coordIn), name(nameIn), selected(selectedIn)
{
}
@@ -37,39 +37,24 @@ QVariant MapLocation::getRole(int role) const
{
switch (role) {
case Roles::RoleDivesite:
- return QVariant::fromValue((dive_site *)m_ds);
+ return QVariant::fromValue(divesite);
case Roles::RoleCoordinate:
- return QVariant::fromValue(m_coordinate);
+ return QVariant::fromValue(coordinate);
case Roles::RoleName:
- return QVariant::fromValue(m_name);
+ return QVariant::fromValue(name);
case Roles::RolePixmap:
- return m_selected ? QString("qrc:///dive-location-marker-selected-icon") :
+ return selected ? QString("qrc:///dive-location-marker-selected-icon") :
inEditMode() ? QString("qrc:///dive-location-marker-inactive-icon") :
QString("qrc:///dive-location-marker-icon");
case Roles::RoleZ:
- return m_selected ? 1 : 0;
+ return selected ? 1 : 0;
case Roles::RoleIsSelected:
- return QVariant::fromValue(m_selected);
+ return QVariant::fromValue(selected);
default:
return QVariant();
}
}
-QGeoCoordinate MapLocation::coordinate()
-{
- return m_coordinate;
-}
-
-void MapLocation::setCoordinate(QGeoCoordinate coord)
-{
- m_coordinate = coord;
-}
-
-struct dive_site *MapLocation::divesite()
-{
- return m_ds;
-}
-
MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
{
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapLocationModel::diveSiteChanged);
@@ -134,7 +119,7 @@ void MapLocationModel::selectionChanged()
if (m_mapLocations.isEmpty())
return;
for(MapLocation *m: m_mapLocations)
- m->m_selected = m_selectedDs.contains(m->divesite());
+ m->selected = m_selectedDs.contains(m->divesite);
emit dataChanged(createIndex(0, 0), createIndex(m_mapLocations.size() - 1, 0));
}
@@ -186,7 +171,7 @@ void MapLocationModel::reload(QObject *map)
// at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart
if (locationNameMap.contains(name)) {
MapLocation *existingLocation = locationNameMap[name];
- QGeoCoordinate coord = existingLocation->coordinate();
+ QGeoCoordinate coord = existingLocation->coordinate;
if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
continue;
}
@@ -217,7 +202,7 @@ MapLocation *MapLocationModel::getMapLocation(const struct dive_site *ds)
{
MapLocation *location;
foreach(location, m_mapLocations) {
- if (ds == location->divesite())
+ if (ds == location->divesite)
return location;
}
return NULL;
@@ -228,10 +213,10 @@ void MapLocationModel::diveSiteChanged(struct dive_site *ds, int field)
// Find dive site
int row;
for (row = 0; row < m_mapLocations.size(); ++row) {
- if (m_mapLocations[row]->divesite() == ds)
+ if (m_mapLocations[row]->divesite == ds)
break;
}
- if (row == m_mapLocations.size())
+ if (row == m_mapLocations.size())
return;
switch (field) {
@@ -240,11 +225,11 @@ void MapLocationModel::diveSiteChanged(struct dive_site *ds, int field)
const qreal latitude_r = ds->location.lat.udeg * 0.000001;
const qreal longitude_r = ds->location.lon.udeg * 0.000001;
QGeoCoordinate coord(latitude_r, longitude_r);
- m_mapLocations[row]->setCoordinate(coord);
+ m_mapLocations[row]->coordinate = coord;
}
break;
case LocationInformationModel::NAME:
- m_mapLocations[row]->setProperty("name", ds->name);
+ m_mapLocations[row]->name = ds->name;
break;
default:
break;
diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h
index 5fdddf0f2..afb7e92ec 100644
--- a/qt-models/maplocationmodel.h
+++ b/qt-models/maplocationmodel.h
@@ -19,9 +19,6 @@ public:
explicit MapLocation(struct dive_site *ds, QGeoCoordinate coord, QString name, bool selected);
QVariant getRole(int role) const;
- QGeoCoordinate coordinate();
- void setCoordinate(QGeoCoordinate coord);
- struct dive_site *divesite();
enum Roles {
RoleDivesite = Qt::UserRole + 1,
@@ -32,12 +29,10 @@ public:
RoleIsSelected
};
-private:
- struct dive_site *m_ds;
- QGeoCoordinate m_coordinate;
- QString m_name;
-public:
- bool m_selected = false;
+ struct dive_site *divesite;
+ QGeoCoordinate coordinate;
+ QString name;
+ bool selected = false;
};
class MapLocationModel : public QAbstractListModel