diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index d1a11c03d..825f440ba 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -182,7 +182,6 @@ void LocationInformationWidget::acceptChanges() MainWindow::instance()->diveList->setEnabled(true); MainWindow::instance()->setEnabledToolbar(true); MainWindow::instance()->setApplicationState("Default"); - MapWidget::instance()->endGetDiveCoordinates(); MapWidget::instance()->repopulateLabels(); MultiFilterSortModel::instance()->stopFilterDiveSites(); } @@ -200,7 +199,6 @@ void LocationInformationWidget::initFields(dive_site *ds) filter_model.set(0, location_t { degrees_t{ 0 }, degrees_t{ 0 } }); clearLabels(); } - MapWidget::instance()->prepareForGetDiveCoordinates(ds); } void LocationInformationWidget::on_diveSiteCoordinates_editingFinished() diff --git a/desktop-widgets/mapwidget.cpp b/desktop-widgets/mapwidget.cpp index 11e6425b1..8bc0b175c 100644 --- a/desktop-widgets/mapwidget.cpp +++ b/desktop-widgets/mapwidget.cpp @@ -84,24 +84,6 @@ void MapWidget::reload() } } -void MapWidget::endGetDiveCoordinates() -{ - CHECK_IS_READY_RETURN_VOID(); - - skipReload = false; - m_mapHelper->exitEditMode(); -} - -void MapWidget::prepareForGetDiveCoordinates(struct dive_site *ds) -{ - CHECK_IS_READY_RETURN_VOID(); - m_mapHelper->enterEditMode(ds); - - // Ignore any reload signals during edit mode to avoid showing all flags when in edit mode. - // This can happen for example when the filter is reset. - skipReload = true; -} - void MapWidget::selectedDivesChanged(const QList &list) { CHECK_IS_READY_RETURN_VOID(); diff --git a/desktop-widgets/mapwidget.h b/desktop-widgets/mapwidget.h index 033e448d5..430dd1668 100644 --- a/desktop-widgets/mapwidget.h +++ b/desktop-widgets/mapwidget.h @@ -27,9 +27,7 @@ public: public slots: void centerOnDiveSite(struct dive_site *); void centerOnIndex(const QModelIndex& idx); - void endGetDiveCoordinates(); void repopulateLabels(); - void prepareForGetDiveCoordinates(struct dive_site *ds); void selectedDivesChanged(const QList &); void coordinatesChanged(struct dive_site *ds, const location_t &); void doneLoading(QQuickWidget::Status status); diff --git a/map-widget/qmlmapwidgethelper.cpp b/map-widget/qmlmapwidgethelper.cpp index 1e8199adf..6f5f1804e 100644 --- a/map-widget/qmlmapwidgethelper.cpp +++ b/map-widget/qmlmapwidgethelper.cpp @@ -8,6 +8,9 @@ #include "core/divesite.h" #include "core/qthelper.h" #include "qt-models/maplocationmodel.h" +#ifndef SUBSURFACE_MOBILE +#include "qt-models/filtermodels.h" +#endif #define SMALL_CIRCLE_RADIUS_PX 26.0 @@ -103,6 +106,14 @@ void MapWidgetHelper::centerOnSelectedDiveSite() void MapWidgetHelper::reloadMapLocations() { +#ifndef SUBSURFACE_MOBILE + // The filter being set to dive site is the signal that we are in dive site edit mode. + // This is the case when either the dive site edit tab or the dive site list tab are active. + if (MultiFilterSortModel::instance()->diveSiteMode()) + enterEditMode(); + else + exitEditMode(); +#endif m_mapLocationModel->reload(); } @@ -230,26 +241,26 @@ void MapWidgetHelper::updateDiveSiteCoordinates(struct dive_site *ds, const loca void MapWidgetHelper::exitEditMode() { + if (!m_editMode) + return; m_editMode = false; emit editModeChanged(); } -void MapWidgetHelper::enterEditMode(struct dive_site *ds) +void MapWidgetHelper::enterEditMode() { - // We don't support editing of a dive site that doesn't exist - if (!ds) + if (m_editMode) return; m_editMode = true; - // if divesite doesn't exist in the model, add a new MapLocation. - MapLocation *exists = m_mapLocationModel->getMapLocation(ds); - if (!exists) { + // if divesite of the first selected dive doesn't exist in the model, add a new MapLocation. + const QVector selDs = m_mapLocationModel->selectedDs(); + if (!selDs.isEmpty() && ! m_mapLocationModel->getMapLocation(selDs[0])) { // If the dive site doesn't have a GPS location, use the centre of the map - QGeoCoordinate coord = has_location(&ds->location) ? getCoordinates(ds) - : m_map->property("center").value(); - m_mapLocationModel->add(new MapLocation(ds, coord, QString(ds->name))); + QGeoCoordinate coord = has_location(&selDs[0]->location) ? getCoordinates(selDs[0]) + : m_map->property("center").value(); + m_mapLocationModel->add(new MapLocation(selDs[0], coord, QString(selDs[0]->name))); } - centerOnDiveSite(ds); emit editModeChanged(); } diff --git a/map-widget/qmlmapwidgethelper.h b/map-widget/qmlmapwidgethelper.h index d6dfa17a1..d6348c346 100644 --- a/map-widget/qmlmapwidgethelper.h +++ b/map-widget/qmlmapwidgethelper.h @@ -35,11 +35,11 @@ public: Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *ds, QGeoCoordinate coord); Q_INVOKABLE void selectVisibleLocations(); void updateDiveSiteCoordinates(struct dive_site *ds, const location_t &); - void enterEditMode(struct dive_site *ds); - void exitEditMode(); QString pluginObject(); private: + void enterEditMode(); + void exitEditMode(); QObject *m_map; MapLocationModel *m_mapLocationModel; qreal m_smallCircleRadius; diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index 90d7209f7..1e0fd9c81 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -110,6 +110,11 @@ void MapLocationModel::add(MapLocation *location) endInsertRows(); } +const QVector &MapLocationModel::selectedDs() const +{ + return m_selectedDs; +} + void MapLocationModel::reload() { int idx; diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h index 6f075cc84..b1b13896a 100644 --- a/qt-models/maplocationmodel.h +++ b/qt-models/maplocationmodel.h @@ -62,6 +62,7 @@ public: void add(MapLocation *); void reload(); MapLocation *getMapLocation(const struct dive_site *ds); + const QVector &selectedDs() const; void updateMapLocationCoordinates(const struct dive_site *ds, QGeoCoordinate coord); Q_INVOKABLE void setSelected(struct dive_site *ds, bool fromClick = true); // The dive site is passed as a QVariant, because a null-QVariant is not automatically