mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Map: move calculation of list from map-helper to map-model
The map model keeps track of the dive site positions on the map. Therefore, it seems more logical to have the code calculating the map position in the model, not in the helper-class. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
3e05d61eb9
commit
446dfed6e7
3 changed files with 54 additions and 63 deletions
|
@ -8,11 +8,7 @@
|
||||||
#include "core/divesite.h"
|
#include "core/divesite.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
#include "qt-models/maplocationmodel.h"
|
#include "qt-models/maplocationmodel.h"
|
||||||
#ifndef SUBSURFACE_MOBILE
|
|
||||||
#include "qt-models/filtermodels.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0
|
|
||||||
#define SMALL_CIRCLE_RADIUS_PX 26.0
|
#define SMALL_CIRCLE_RADIUS_PX 26.0
|
||||||
|
|
||||||
MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
|
MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
|
||||||
|
@ -108,49 +104,7 @@ void MapWidgetHelper::centerOnSelectedDiveSite()
|
||||||
|
|
||||||
void MapWidgetHelper::reloadMapLocations()
|
void MapWidgetHelper::reloadMapLocations()
|
||||||
{
|
{
|
||||||
int idx;
|
m_mapLocationModel->reload();
|
||||||
struct dive *dive;
|
|
||||||
QMap<QString, MapLocation *> locationNameMap;
|
|
||||||
m_mapLocationModel->clear();
|
|
||||||
MapLocation *location;
|
|
||||||
QVector<MapLocation *> locationList;
|
|
||||||
QVector<struct dive_site *> locations;
|
|
||||||
qreal latitude, longitude;
|
|
||||||
|
|
||||||
#ifdef SUBSURFACE_MOBILE
|
|
||||||
bool diveSiteMode = false;
|
|
||||||
#else
|
|
||||||
// In dive site mode (that is when either editing a dive site or on
|
|
||||||
// the dive site tab), we want to show all dive sites, not only those
|
|
||||||
// of the non-hidden dives.
|
|
||||||
bool diveSiteMode = MultiFilterSortModel::instance()->diveSiteMode();
|
|
||||||
#endif
|
|
||||||
for_each_dive(idx, dive) {
|
|
||||||
// Don't show dive sites of hidden dives, unless this is the currently
|
|
||||||
// displayed (edited) dive or we're in dive site edit mode.
|
|
||||||
if (!diveSiteMode && dive->hidden_by_filter && dive != current_dive)
|
|
||||||
continue;
|
|
||||||
struct dive_site *ds = get_dive_site_for_dive(dive);
|
|
||||||
if (!dive_site_has_gps_location(ds) || locations.contains(ds))
|
|
||||||
continue;
|
|
||||||
latitude = ds->location.lat.udeg * 0.000001;
|
|
||||||
longitude = ds->location.lon.udeg * 0.000001;
|
|
||||||
QGeoCoordinate dsCoord(latitude, longitude);
|
|
||||||
QString name(ds->name);
|
|
||||||
// don't add dive locations with the same name, unless they are
|
|
||||||
// at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart
|
|
||||||
if (locationNameMap.contains(name)) {
|
|
||||||
MapLocation *existingLocation = locationNameMap[name];
|
|
||||||
QGeoCoordinate coord = existingLocation->coordinate();
|
|
||||||
if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
location = new MapLocation(ds, dsCoord, name);
|
|
||||||
locationList.append(location);
|
|
||||||
locations.append(ds);
|
|
||||||
locationNameMap[name] = location;
|
|
||||||
}
|
|
||||||
m_mapLocationModel->addList(locationList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
|
void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
|
||||||
|
|
|
@ -2,11 +2,16 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "maplocationmodel.h"
|
#include "maplocationmodel.h"
|
||||||
#include "core/divesite.h"
|
#include "core/divesite.h"
|
||||||
|
#ifndef SUBSURFACE_MOBILE
|
||||||
|
#include "qt-models/filtermodels.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *MapLocation::PROPERTY_NAME_COORDINATE = "coordinate";
|
const char *MapLocation::PROPERTY_NAME_COORDINATE = "coordinate";
|
||||||
const char *MapLocation::PROPERTY_NAME_DIVESITE = "divesite";
|
const char *MapLocation::PROPERTY_NAME_DIVESITE = "divesite";
|
||||||
const char *MapLocation::PROPERTY_NAME_NAME = "name";
|
const char *MapLocation::PROPERTY_NAME_NAME = "name";
|
||||||
|
|
||||||
|
#define MIN_DISTANCE_BETWEEN_DIVE_SITES_M 50.0
|
||||||
|
|
||||||
MapLocation::MapLocation() : m_ds(nullptr)
|
MapLocation::MapLocation() : m_ds(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -66,7 +71,7 @@ MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
|
|
||||||
MapLocationModel::~MapLocationModel()
|
MapLocationModel::~MapLocationModel()
|
||||||
{
|
{
|
||||||
clear();
|
qDeleteAll(m_mapLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MapLocationModel::data(const QModelIndex & index, int role) const
|
QVariant MapLocationModel::data(const QModelIndex & index, int role) const
|
||||||
|
@ -106,23 +111,56 @@ void MapLocationModel::add(MapLocation *location)
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationModel::addList(QVector<MapLocation *> list)
|
void MapLocationModel::reload()
|
||||||
{
|
{
|
||||||
if (!list.size())
|
int idx;
|
||||||
return;
|
struct dive *dive;
|
||||||
beginInsertRows(QModelIndex(), m_mapLocations.size(), m_mapLocations.size() + list.size() - 1);
|
|
||||||
m_mapLocations.append(list);
|
beginResetModel();
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapLocationModel::clear()
|
|
||||||
{
|
|
||||||
if (!m_mapLocations.size())
|
|
||||||
return;
|
|
||||||
beginRemoveRows(QModelIndex(), 0, m_mapLocations.size() - 1);
|
|
||||||
qDeleteAll(m_mapLocations);
|
qDeleteAll(m_mapLocations);
|
||||||
m_mapLocations.clear();
|
m_mapLocations.clear();
|
||||||
endRemoveRows();
|
|
||||||
|
QMap<QString, MapLocation *> locationNameMap;
|
||||||
|
MapLocation *location;
|
||||||
|
QVector<struct dive_site *> locations;
|
||||||
|
qreal latitude, longitude;
|
||||||
|
|
||||||
|
#ifdef SUBSURFACE_MOBILE
|
||||||
|
bool diveSiteMode = false;
|
||||||
|
#else
|
||||||
|
// In dive site mode (that is when either editing a dive site or on
|
||||||
|
// the dive site tab), we want to show all dive sites, not only those
|
||||||
|
// of the non-hidden dives.
|
||||||
|
bool diveSiteMode = MultiFilterSortModel::instance()->diveSiteMode();
|
||||||
|
#endif
|
||||||
|
for_each_dive(idx, dive) {
|
||||||
|
// Don't show dive sites of hidden dives, unless this is the currently
|
||||||
|
// displayed (edited) dive or we're in dive site edit mode.
|
||||||
|
if (!diveSiteMode && dive->hidden_by_filter && dive != current_dive)
|
||||||
|
continue;
|
||||||
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
||||||
|
if (!dive_site_has_gps_location(ds) || locations.contains(ds))
|
||||||
|
continue;
|
||||||
|
latitude = ds->location.lat.udeg * 0.000001;
|
||||||
|
longitude = ds->location.lon.udeg * 0.000001;
|
||||||
|
QGeoCoordinate dsCoord(latitude, longitude);
|
||||||
|
QString name(ds->name);
|
||||||
|
// don't add dive locations with the same name, unless they are
|
||||||
|
// at least MIN_DISTANCE_BETWEEN_DIVE_SITES_M apart
|
||||||
|
if (locationNameMap.contains(name)) {
|
||||||
|
MapLocation *existingLocation = locationNameMap[name];
|
||||||
|
QGeoCoordinate coord = existingLocation->coordinate();
|
||||||
|
if (dsCoord.distanceTo(coord) < MIN_DISTANCE_BETWEEN_DIVE_SITES_M)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
location = new MapLocation(ds, dsCoord, name);
|
||||||
|
m_mapLocations.append(location);
|
||||||
|
locations.append(ds);
|
||||||
|
locationNameMap[name] = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationModel::setSelected(struct dive_site *ds, bool fromClick)
|
void MapLocationModel::setSelected(struct dive_site *ds, bool fromClick)
|
||||||
|
|
|
@ -61,8 +61,7 @@ public:
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
int count();
|
int count();
|
||||||
void add(MapLocation *);
|
void add(MapLocation *);
|
||||||
void addList(QVector<MapLocation *>);
|
void reload();
|
||||||
void clear();
|
|
||||||
MapLocation *getMapLocation(const struct dive_site *ds);
|
MapLocation *getMapLocation(const struct dive_site *ds);
|
||||||
void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord);
|
void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord);
|
||||||
Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true);
|
Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true);
|
||||||
|
|
Loading…
Reference in a new issue