mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Map: explicitly reload selected map on click
When clicking on a flag 1) The QML would call MapLocationModel::setSelected() with fromClick = true 2) MapLocationModel::setSelected() would emit a signal selectedLocationChanged() 3) MapWidgetHelper would catch that signal and do the actual processing. Other functions would call MapLocationModel::setSelected() with fromClick = false, which would not emit the selectedLocationChanged() signal. Detangle this a bit by calling the selectedLocationChanged() function directly from QML and remove the fromClick parameter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f818ac3352
commit
28cb75b73d
5 changed files with 19 additions and 16 deletions
|
@ -69,8 +69,10 @@ Item {
|
||||||
drag.target: (mapHelper.editMode && mapHelper.model.isSelected(model.divesite)) ? mapItem : undefined
|
drag.target: (mapHelper.editMode && mapHelper.model.isSelected(model.divesite)) ? mapItem : undefined
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!mapHelper.editMode && model.divesite)
|
if (!mapHelper.editMode && model.divesite) {
|
||||||
mapHelper.model.setSelected(model.divesite, true)
|
mapHelper.model.setSelected(model.divesite)
|
||||||
|
mapHelper.selectedLocationChanged(model.divesite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onDoubleClicked: map.doubleClickHandler(mapItem.coordinate)
|
onDoubleClicked: map.doubleClickHandler(mapItem.coordinate)
|
||||||
onReleased: {
|
onReleased: {
|
||||||
|
|
|
@ -21,8 +21,6 @@ MapWidgetHelper::MapWidgetHelper(QObject *parent) : QObject(parent)
|
||||||
m_smallCircleRadius = SMALL_CIRCLE_RADIUS_PX;
|
m_smallCircleRadius = SMALL_CIRCLE_RADIUS_PX;
|
||||||
m_map = nullptr;
|
m_map = nullptr;
|
||||||
m_editMode = false;
|
m_editMode = false;
|
||||||
connect(m_mapLocationModel, SIGNAL(selectedLocationChanged(MapLocation *)),
|
|
||||||
this, SLOT(selectedLocationChanged(MapLocation *)));
|
|
||||||
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapWidgetHelper::diveSiteChanged);
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MapWidgetHelper::diveSiteChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,11 +35,11 @@ void MapWidgetHelper::centerOnDiveSite(struct dive_site *ds)
|
||||||
{
|
{
|
||||||
if (!dive_site_has_gps_location(ds)) {
|
if (!dive_site_has_gps_location(ds)) {
|
||||||
// dive site with no GPS
|
// dive site with no GPS
|
||||||
m_mapLocationModel->setSelected(ds, false);
|
m_mapLocationModel->setSelected(ds);
|
||||||
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
|
QMetaObject::invokeMethod(m_map, "deselectMapLocation");
|
||||||
} else {
|
} else {
|
||||||
// dive site with GPS
|
// dive site with GPS
|
||||||
m_mapLocationModel->setSelected(ds, false);
|
m_mapLocationModel->setSelected(ds);
|
||||||
QGeoCoordinate dsCoord (ds->location.lat.udeg * 0.000001, ds->location.lon.udeg * 0.000001);
|
QGeoCoordinate dsCoord (ds->location.lat.udeg * 0.000001, ds->location.lon.udeg * 0.000001);
|
||||||
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
|
QMetaObject::invokeMethod(m_map, "centerOnCoordinate", Q_ARG(QVariant, QVariant::fromValue(dsCoord)));
|
||||||
}
|
}
|
||||||
|
@ -114,12 +112,19 @@ void MapWidgetHelper::reloadMapLocations()
|
||||||
m_mapLocationModel->reload(m_map);
|
m_mapLocationModel->reload(m_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapWidgetHelper::selectedLocationChanged(MapLocation *location)
|
void MapWidgetHelper::selectedLocationChanged(struct dive_site *ds_in)
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
struct dive *dive;
|
struct dive *dive;
|
||||||
QList<int> selectedDiveIds;
|
QList<int> selectedDiveIds;
|
||||||
|
|
||||||
|
if (!ds_in)
|
||||||
|
return;
|
||||||
|
MapLocation *location = m_mapLocationModel->getMapLocation(ds_in);
|
||||||
|
if (!location)
|
||||||
|
return;
|
||||||
QGeoCoordinate locationCoord = location->coordinate();
|
QGeoCoordinate locationCoord = location->coordinate();
|
||||||
|
|
||||||
for_each_dive (idx, dive) {
|
for_each_dive (idx, dive) {
|
||||||
struct dive_site *ds = get_dive_site_for_dive(dive);
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
||||||
if (!dive_site_has_gps_location(ds))
|
if (!dive_site_has_gps_location(ds))
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
|
Q_INVOKABLE void calculateSmallCircleRadius(QGeoCoordinate coord);
|
||||||
Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord);
|
Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord);
|
||||||
Q_INVOKABLE void selectVisibleLocations();
|
Q_INVOKABLE void selectVisibleLocations();
|
||||||
|
Q_INVOKABLE void selectedLocationChanged(struct dive_site *ds);
|
||||||
QString pluginObject();
|
QString pluginObject();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -45,7 +46,6 @@ private:
|
||||||
bool m_editMode;
|
bool m_editMode;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selectedLocationChanged(MapLocation *);
|
|
||||||
void diveSiteChanged(struct dive_site *ds, int field);
|
void diveSiteChanged(struct dive_site *ds, int field);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -193,14 +193,11 @@ void MapLocationModel::reload(QObject *map)
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapLocationModel::setSelected(struct dive_site *ds, bool fromClick)
|
void MapLocationModel::setSelected(struct dive_site *ds)
|
||||||
{
|
{
|
||||||
m_selectedDs.clear();
|
m_selectedDs.clear();
|
||||||
if (!ds)
|
if (ds)
|
||||||
return;
|
|
||||||
m_selectedDs.append(ds);
|
m_selectedDs.append(ds);
|
||||||
if (fromClick)
|
|
||||||
emit selectedLocationChanged(getMapLocation(ds));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapLocationModel::isSelected(const QVariant &dsVariant) const
|
bool MapLocationModel::isSelected(const QVariant &dsVariant) const
|
||||||
|
|
|
@ -65,7 +65,7 @@ public:
|
||||||
void reload(QObject *map);
|
void reload(QObject *map);
|
||||||
MapLocation *getMapLocation(const struct dive_site *ds);
|
MapLocation *getMapLocation(const struct dive_site *ds);
|
||||||
const QVector<dive_site *> &selectedDs() const;
|
const QVector<dive_site *> &selectedDs() const;
|
||||||
Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true);
|
Q_INVOKABLE void setSelected(struct dive_site *ds);
|
||||||
// The dive site is passed as a QVariant, because a null-QVariant is not automatically
|
// The dive site is passed as a QVariant, because a null-QVariant is not automatically
|
||||||
// transformed into a null pointer and warning messages are spewed onto the console.
|
// transformed into a null pointer and warning messages are spewed onto the console.
|
||||||
Q_INVOKABLE bool isSelected(const QVariant &ds) const;
|
Q_INVOKABLE bool isSelected(const QVariant &ds) const;
|
||||||
|
@ -83,7 +83,6 @@ private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void countChanged(int c);
|
void countChanged(int c);
|
||||||
void selectedLocationChanged(MapLocation *);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue