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>
This commit is contained in:
Berthold Stoeger 2019-09-01 00:18:15 +02:00 committed by Dirk Hohndel
parent fe07a47989
commit 4eaf6b20be
3 changed files with 23 additions and 43 deletions

View file

@ -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);
}

View file

@ -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,7 +213,7 @@ 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())
@ -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;

View file

@ -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