mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Map: make edit mode depend on dive-site-filtering
Since the dive-site-filter is active either on the dive-site-edit page or the dive-site-list page, use that as the flag for dive-site-edit mode. Moreover, when the filter is reset, the MapWidgetHelper::reloadMapLocations() function is called, so we can use that place to enter/exit edit mode. This makes it easier to keep everything consistent. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b6d830f004
commit
d29f82c52d
7 changed files with 29 additions and 34 deletions
|
@ -182,7 +182,6 @@ void LocationInformationWidget::acceptChanges()
|
||||||
MainWindow::instance()->diveList->setEnabled(true);
|
MainWindow::instance()->diveList->setEnabled(true);
|
||||||
MainWindow::instance()->setEnabledToolbar(true);
|
MainWindow::instance()->setEnabledToolbar(true);
|
||||||
MainWindow::instance()->setApplicationState("Default");
|
MainWindow::instance()->setApplicationState("Default");
|
||||||
MapWidget::instance()->endGetDiveCoordinates();
|
|
||||||
MapWidget::instance()->repopulateLabels();
|
MapWidget::instance()->repopulateLabels();
|
||||||
MultiFilterSortModel::instance()->stopFilterDiveSites();
|
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 } });
|
filter_model.set(0, location_t { degrees_t{ 0 }, degrees_t{ 0 } });
|
||||||
clearLabels();
|
clearLabels();
|
||||||
}
|
}
|
||||||
MapWidget::instance()->prepareForGetDiveCoordinates(ds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationInformationWidget::on_diveSiteCoordinates_editingFinished()
|
void LocationInformationWidget::on_diveSiteCoordinates_editingFinished()
|
||||||
|
|
|
@ -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<int> &list)
|
void MapWidget::selectedDivesChanged(const QList<int> &list)
|
||||||
{
|
{
|
||||||
CHECK_IS_READY_RETURN_VOID();
|
CHECK_IS_READY_RETURN_VOID();
|
||||||
|
|
|
@ -27,9 +27,7 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void centerOnDiveSite(struct dive_site *);
|
void centerOnDiveSite(struct dive_site *);
|
||||||
void centerOnIndex(const QModelIndex& idx);
|
void centerOnIndex(const QModelIndex& idx);
|
||||||
void endGetDiveCoordinates();
|
|
||||||
void repopulateLabels();
|
void repopulateLabels();
|
||||||
void prepareForGetDiveCoordinates(struct dive_site *ds);
|
|
||||||
void selectedDivesChanged(const QList<int> &);
|
void selectedDivesChanged(const QList<int> &);
|
||||||
void coordinatesChanged(struct dive_site *ds, const location_t &);
|
void coordinatesChanged(struct dive_site *ds, const location_t &);
|
||||||
void doneLoading(QQuickWidget::Status status);
|
void doneLoading(QQuickWidget::Status status);
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
#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 SMALL_CIRCLE_RADIUS_PX 26.0
|
#define SMALL_CIRCLE_RADIUS_PX 26.0
|
||||||
|
|
||||||
|
@ -103,6 +106,14 @@ void MapWidgetHelper::centerOnSelectedDiveSite()
|
||||||
|
|
||||||
void MapWidgetHelper::reloadMapLocations()
|
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();
|
m_mapLocationModel->reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,26 +241,26 @@ void MapWidgetHelper::updateDiveSiteCoordinates(struct dive_site *ds, const loca
|
||||||
|
|
||||||
void MapWidgetHelper::exitEditMode()
|
void MapWidgetHelper::exitEditMode()
|
||||||
{
|
{
|
||||||
|
if (!m_editMode)
|
||||||
|
return;
|
||||||
m_editMode = false;
|
m_editMode = false;
|
||||||
emit editModeChanged();
|
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 (m_editMode)
|
||||||
if (!ds)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_editMode = true;
|
m_editMode = true;
|
||||||
// if divesite doesn't exist in the model, add a new MapLocation.
|
// if divesite of the first selected dive doesn't exist in the model, add a new MapLocation.
|
||||||
MapLocation *exists = m_mapLocationModel->getMapLocation(ds);
|
const QVector<dive_site *> selDs = m_mapLocationModel->selectedDs();
|
||||||
if (!exists) {
|
if (!selDs.isEmpty() && ! m_mapLocationModel->getMapLocation(selDs[0])) {
|
||||||
// If the dive site doesn't have a GPS location, use the centre of the map
|
// If the dive site doesn't have a GPS location, use the centre of the map
|
||||||
QGeoCoordinate coord = has_location(&ds->location) ? getCoordinates(ds)
|
QGeoCoordinate coord = has_location(&selDs[0]->location) ? getCoordinates(selDs[0])
|
||||||
: m_map->property("center").value<QGeoCoordinate>();
|
: m_map->property("center").value<QGeoCoordinate>();
|
||||||
m_mapLocationModel->add(new MapLocation(ds, coord, QString(ds->name)));
|
m_mapLocationModel->add(new MapLocation(selDs[0], coord, QString(selDs[0]->name)));
|
||||||
}
|
}
|
||||||
centerOnDiveSite(ds);
|
|
||||||
emit editModeChanged();
|
emit editModeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,11 @@ public:
|
||||||
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();
|
||||||
void updateDiveSiteCoordinates(struct dive_site *ds, const location_t &);
|
void updateDiveSiteCoordinates(struct dive_site *ds, const location_t &);
|
||||||
void enterEditMode(struct dive_site *ds);
|
|
||||||
void exitEditMode();
|
|
||||||
QString pluginObject();
|
QString pluginObject();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void enterEditMode();
|
||||||
|
void exitEditMode();
|
||||||
QObject *m_map;
|
QObject *m_map;
|
||||||
MapLocationModel *m_mapLocationModel;
|
MapLocationModel *m_mapLocationModel;
|
||||||
qreal m_smallCircleRadius;
|
qreal m_smallCircleRadius;
|
||||||
|
|
|
@ -110,6 +110,11 @@ void MapLocationModel::add(MapLocation *location)
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QVector<dive_site *> &MapLocationModel::selectedDs() const
|
||||||
|
{
|
||||||
|
return m_selectedDs;
|
||||||
|
}
|
||||||
|
|
||||||
void MapLocationModel::reload()
|
void MapLocationModel::reload()
|
||||||
{
|
{
|
||||||
int idx;
|
int idx;
|
||||||
|
|
|
@ -62,6 +62,7 @@ public:
|
||||||
void add(MapLocation *);
|
void add(MapLocation *);
|
||||||
void reload();
|
void reload();
|
||||||
MapLocation *getMapLocation(const struct dive_site *ds);
|
MapLocation *getMapLocation(const struct dive_site *ds);
|
||||||
|
const QVector<dive_site *> &selectedDs() const;
|
||||||
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);
|
||||||
// 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
|
||||||
|
|
Loading…
Reference in a new issue