mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Map: pass down dive site in prepareForGetDiveCoordinates()
Instead of reading out the global object "displayed_dive_site", pass the dive site to be edited in arguments to prepareForGetDiveCoordinates() and enter edit mode. Simplify the code in LocationInformationWidget by not using signals to call the prepareForGetDiveCoordinates() function. While doing this, collect common code in accept() and reject() in the already existing resetState() function. This is another entry in a series of commits that makes data-flow more clear by removing access to the global "displayed_dive_site" object. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8091497745
commit
dd44dc4ab8
6 changed files with 19 additions and 27 deletions
|
@ -49,14 +49,8 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo
|
|||
ui.diveSiteListView->setModelColumn(LocationInformationModel::NAME);
|
||||
ui.diveSiteListView->installEventFilter(this);
|
||||
// Map Management Code.
|
||||
connect(this, &LocationInformationWidget::requestCoordinates,
|
||||
MapWidget::instance(), &MapWidget::prepareForGetDiveCoordinates);
|
||||
connect(this, &LocationInformationWidget::endRequestCoordinates,
|
||||
MapWidget::instance(), &MapWidget::endGetDiveCoordinates);
|
||||
connect(MapWidget::instance(), &MapWidget::coordinatesChanged,
|
||||
this, &LocationInformationWidget::updateGpsCoordinates);
|
||||
connect(this, &LocationInformationWidget::endEditDiveSite,
|
||||
MapWidget::instance(), &MapWidget::repopulateLabels);
|
||||
}
|
||||
|
||||
bool LocationInformationWidget::eventFilter(QObject *object, QEvent *ev)
|
||||
|
@ -213,19 +207,11 @@ void LocationInformationWidget::acceptChanges()
|
|||
copy_dive_site(currentDs, &displayed_dive_site);
|
||||
mark_divelist_changed(true);
|
||||
resetState();
|
||||
emit endRequestCoordinates();
|
||||
emit endEditDiveSite();
|
||||
emit stopFilterDiveSite();
|
||||
updateLocationOnMap();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::rejectChanges()
|
||||
{
|
||||
resetState();
|
||||
emit endRequestCoordinates();
|
||||
emit stopFilterDiveSite();
|
||||
emit endEditDiveSite();
|
||||
updateLocationOnMap();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::showEvent(QShowEvent *ev)
|
||||
|
@ -240,8 +226,7 @@ void LocationInformationWidget::showEvent(QShowEvent *ev)
|
|||
} else {
|
||||
clearLabels();
|
||||
}
|
||||
emit requestCoordinates();
|
||||
|
||||
MapWidget::instance()->prepareForGetDiveCoordinates(displayed_dive_site.uuid);
|
||||
QGroupBox::showEvent(ev);
|
||||
}
|
||||
|
||||
|
@ -264,6 +249,11 @@ void LocationInformationWidget::resetState()
|
|||
MainWindow::instance()->dive_list()->setEnabled(true);
|
||||
MainWindow::instance()->setEnabledToolbar(true);
|
||||
ui.diveSiteMessage->setText(tr("Dive site management"));
|
||||
MapWidget::instance()->endGetDiveCoordinates();
|
||||
MapWidget::instance()->repopulateLabels();
|
||||
emit stopFilterDiveSite();
|
||||
emit endEditDiveSite();
|
||||
updateLocationOnMap();
|
||||
}
|
||||
|
||||
void LocationInformationWidget::enableEdition()
|
||||
|
|
|
@ -41,8 +41,6 @@ signals:
|
|||
void endEditDiveSite();
|
||||
void startFilterDiveSite(uint32_t uuid);
|
||||
void stopFilterDiveSite();
|
||||
void requestCoordinates();
|
||||
void endRequestCoordinates();
|
||||
void nameChanged(const QString &oldName, const QString &newName);
|
||||
|
||||
private:
|
||||
|
|
|
@ -93,10 +93,10 @@ void MapWidget::endGetDiveCoordinates()
|
|||
m_mapHelper->exitEditMode();
|
||||
}
|
||||
|
||||
void MapWidget::prepareForGetDiveCoordinates()
|
||||
void MapWidget::prepareForGetDiveCoordinates(uint32_t uuid)
|
||||
{
|
||||
CHECK_IS_READY_RETURN_VOID();
|
||||
m_mapHelper->enterEditMode();
|
||||
m_mapHelper->enterEditMode(uuid);
|
||||
}
|
||||
|
||||
void MapWidget::selectedDivesChanged(QList<int> list)
|
||||
|
|
|
@ -33,7 +33,7 @@ public slots:
|
|||
void centerOnIndex(const QModelIndex& idx);
|
||||
void endGetDiveCoordinates();
|
||||
void repopulateLabels();
|
||||
void prepareForGetDiveCoordinates();
|
||||
void prepareForGetDiveCoordinates(uint32_t uuid);
|
||||
void selectedDivesChanged(QList<int>);
|
||||
void coordinatesChangedLocal(degrees_t latitude, degrees_t longitude);
|
||||
void doneLoading(QQuickWidget::Status status);
|
||||
|
|
|
@ -291,16 +291,20 @@ void MapWidgetHelper::exitEditMode()
|
|||
emit editModeChanged();
|
||||
}
|
||||
|
||||
void MapWidgetHelper::enterEditMode()
|
||||
void MapWidgetHelper::enterEditMode(quint32 uuid)
|
||||
{
|
||||
// We don't support editing of a dive site that doesn't exist
|
||||
struct dive_site *ds = get_dive_site_by_uuid(uuid);
|
||||
if (!ds)
|
||||
return;
|
||||
|
||||
m_editMode = true;
|
||||
MapLocation *exists = m_mapLocationModel->getMapLocationForUuid(displayed_dive_site.uuid);
|
||||
MapLocation *exists = m_mapLocationModel->getMapLocationForUuid(uuid);
|
||||
QGeoCoordinate coord;
|
||||
// if divesite uuid doesn't exist in the model, add a new MapLocation.
|
||||
// if divesite doesn't exist in the model, add a new MapLocation.
|
||||
if (!exists) {
|
||||
coord = m_map->property("center").value<QGeoCoordinate>();
|
||||
m_mapLocationModel->add(new MapLocation(displayed_dive_site.uuid, coord,
|
||||
QString(displayed_dive_site.name)));
|
||||
m_mapLocationModel->add(new MapLocation(uuid, coord, QString(ds->name)));
|
||||
} else {
|
||||
coord = exists->coordinate();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
Q_INVOKABLE void updateCurrentDiveSiteCoordinatesFromMap(quint32 uuid, QGeoCoordinate coord);
|
||||
Q_INVOKABLE void selectVisibleLocations();
|
||||
void updateDiveSiteCoordinates(uint32_t uuid, degrees_t latitude, degrees_t longitude);
|
||||
void enterEditMode();
|
||||
void enterEditMode(uint32_t uuid);
|
||||
void exitEditMode();
|
||||
QString pluginObject();
|
||||
|
||||
|
|
Loading…
Reference in a new issue