mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Dive site: explicitly init displayed_dive_site on show widget
The global object "displayed_dive_site" is used to store the old dive site data for the edit-dive-site widget. The fields of the widget were initialized from this object in the show event. Therefore the object was updated in numerous parts of the code to make sure that it was up-to-date. Instead, move the initialization of the object to the function that also initiatlizes the fields. Call this function explicitly before showing the widget. This makes the data-fow distinctly easier to understand. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f0e349cdd6
commit
954820aa81
6 changed files with 11 additions and 17 deletions
|
@ -1677,7 +1677,6 @@ void clear_dive_file_data()
|
||||||
delete_dive_site(get_dive_site(0)->uuid);
|
delete_dive_site(get_dive_site(0)->uuid);
|
||||||
|
|
||||||
clear_dive(&displayed_dive);
|
clear_dive(&displayed_dive);
|
||||||
clear_dive_site(&displayed_dive_site);
|
|
||||||
|
|
||||||
reset_min_datafile_version();
|
reset_min_datafile_version();
|
||||||
saved_git_id = "";
|
saved_git_id = "";
|
||||||
|
|
|
@ -200,7 +200,6 @@ void LocationInformationWidget::acceptChanges()
|
||||||
LocationInformationModel::instance()->removeRow(get_divesite_idx(currentDs));
|
LocationInformationModel::instance()->removeRow(get_divesite_idx(currentDs));
|
||||||
displayed_dive.dive_site_uuid = 0;
|
displayed_dive.dive_site_uuid = 0;
|
||||||
}
|
}
|
||||||
copy_dive_site(currentDs, &displayed_dive_site);
|
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
resetState();
|
resetState();
|
||||||
}
|
}
|
||||||
|
@ -210,9 +209,10 @@ void LocationInformationWidget::rejectChanges()
|
||||||
resetState();
|
resetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationInformationWidget::showEvent(QShowEvent *ev)
|
void LocationInformationWidget::initFields(dive_site *ds)
|
||||||
{
|
{
|
||||||
if (displayed_dive_site.uuid) {
|
if (ds) {
|
||||||
|
copy_dive_site(ds, &displayed_dive_site);
|
||||||
filter_model.set(displayed_dive_site.uuid, displayed_dive_site.latitude, displayed_dive_site.longitude);
|
filter_model.set(displayed_dive_site.uuid, displayed_dive_site.latitude, displayed_dive_site.longitude);
|
||||||
updateLabels();
|
updateLabels();
|
||||||
enableLocationButtons(dive_site_has_gps_location(&displayed_dive_site));
|
enableLocationButtons(dive_site_has_gps_location(&displayed_dive_site));
|
||||||
|
@ -221,11 +221,11 @@ void LocationInformationWidget::showEvent(QShowEvent *ev)
|
||||||
if (m)
|
if (m)
|
||||||
m->invalidate();
|
m->invalidate();
|
||||||
} else {
|
} else {
|
||||||
|
clear_dive_site(&displayed_dive_site);
|
||||||
filter_model.set(0, degrees_t{ 0 }, degrees_t{ 0 });
|
filter_model.set(0, degrees_t{ 0 }, degrees_t{ 0 });
|
||||||
clearLabels();
|
clearLabels();
|
||||||
}
|
}
|
||||||
MapWidget::instance()->prepareForGetDiveCoordinates(displayed_dive_site.uuid);
|
MapWidget::instance()->prepareForGetDiveCoordinates(displayed_dive_site.uuid);
|
||||||
QGroupBox::showEvent(ev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationInformationWidget::markChangedWidget(QWidget *w)
|
void LocationInformationWidget::markChangedWidget(QWidget *w)
|
||||||
|
|
|
@ -14,9 +14,9 @@ Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LocationInformationWidget(QWidget *parent = 0);
|
LocationInformationWidget(QWidget *parent = 0);
|
||||||
bool eventFilter(QObject*, QEvent*) override;
|
bool eventFilter(QObject*, QEvent*) override;
|
||||||
|
void initFields(dive_site *ds);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *);
|
|
||||||
void enableLocationButtons(bool enable);
|
void enableLocationButtons(bool enable);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -173,7 +173,7 @@ MainWindow::MainWindow() : QMainWindow(),
|
||||||
profLayout->addWidget(profileWidget);
|
profLayout->addWidget(profileWidget);
|
||||||
profileContainer->setLayout(profLayout);
|
profileContainer->setLayout(profLayout);
|
||||||
|
|
||||||
LocationInformationWidget * diveSiteEdit = new LocationInformationWidget();
|
diveSiteEdit = new LocationInformationWidget(this);
|
||||||
connect(diveSiteEdit, &LocationInformationWidget::endEditDiveSite,
|
connect(diveSiteEdit, &LocationInformationWidget::endEditDiveSite,
|
||||||
this, &MainWindow::setDefaultState);
|
this, &MainWindow::setDefaultState);
|
||||||
connect(diveSiteEdit, SIGNAL(endEditDiveSite()), this, SLOT(refreshDisplay()));
|
connect(diveSiteEdit, SIGNAL(endEditDiveSite()), this, SLOT(refreshDisplay()));
|
||||||
|
@ -445,7 +445,9 @@ void MainWindow::setStateProperties(const QByteArray& state, const PropertyList&
|
||||||
stateProperties[state] = PropertiesForQuadrant(tl, tr, bl, br);
|
stateProperties[state] = PropertiesForQuadrant(tl, tr, bl, br);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionDiveSiteEdit_triggered() {
|
void MainWindow::on_actionDiveSiteEdit_triggered()
|
||||||
|
{
|
||||||
|
diveSiteEdit->initFields(get_dive_site_for_dive(&displayed_dive));
|
||||||
setApplicationState("EditDiveSite");
|
setApplicationState("EditDiveSite");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -957,7 +959,6 @@ void MainWindow::setupForAddAndPlan(const char *model)
|
||||||
{
|
{
|
||||||
// clean out the dive and give it an id and the correct dc model
|
// clean out the dive and give it an id and the correct dc model
|
||||||
clear_dive(&displayed_dive);
|
clear_dive(&displayed_dive);
|
||||||
clear_dive_site(&displayed_dive_site);
|
|
||||||
displayed_dive.id = dive_getUniqID();
|
displayed_dive.id = dive_getUniqID();
|
||||||
displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
|
displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
|
||||||
displayed_dive.dc.model = strdup(model); // don't translate! this is stored in the XML file
|
displayed_dive.dc.model = strdup(model); // don't translate! this is stored in the XML file
|
||||||
|
|
|
@ -214,6 +214,7 @@ private:
|
||||||
void enterState(CurrentState);
|
void enterState(CurrentState);
|
||||||
bool filesAsArguments;
|
bool filesAsArguments;
|
||||||
UpdateManager *updateManager;
|
UpdateManager *updateManager;
|
||||||
|
LocationInformationWidget *diveSiteEdit;
|
||||||
|
|
||||||
bool plannerStateClean();
|
bool plannerStateClean();
|
||||||
void setupForAddAndPlan(const char *model);
|
void setupForAddAndPlan(const char *model);
|
||||||
|
|
|
@ -419,11 +419,9 @@ void MainTab::updateDiveInfo(bool clear)
|
||||||
if (ds) {
|
if (ds) {
|
||||||
ui.location->setCurrentDiveSiteUuid(ds->uuid);
|
ui.location->setCurrentDiveSiteUuid(ds->uuid);
|
||||||
ui.locationTags->setText(constructLocationTags(ds, true));
|
ui.locationTags->setText(constructLocationTags(ds, true));
|
||||||
copy_dive_site(ds, &displayed_dive_site);
|
|
||||||
} else {
|
} else {
|
||||||
ui.location->clear();
|
ui.location->clear();
|
||||||
ui.locationTags->clear();
|
ui.locationTags->clear();
|
||||||
clear_dive_site(&displayed_dive_site);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subsurface always uses "local time" as in "whatever was the local time at the location"
|
// Subsurface always uses "local time" as in "whatever was the local time at the location"
|
||||||
|
@ -657,10 +655,8 @@ MainTab::EditMode MainTab::getEditMode() const
|
||||||
void MainTab::refreshDisplayedDiveSite()
|
void MainTab::refreshDisplayedDiveSite()
|
||||||
{
|
{
|
||||||
struct dive_site *ds = get_dive_site_for_dive(&displayed_dive);
|
struct dive_site *ds = get_dive_site_for_dive(&displayed_dive);
|
||||||
if (ds) {
|
if (ds)
|
||||||
copy_dive_site(ds, &displayed_dive_site);
|
|
||||||
ui.location->setCurrentDiveSiteUuid(ds->uuid);
|
ui.location->setCurrentDiveSiteUuid(ds->uuid);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// when this is called we already have updated the current_dive and know that it exists
|
// when this is called we already have updated the current_dive and know that it exists
|
||||||
|
@ -906,9 +902,6 @@ void MainTab::acceptChanges()
|
||||||
// so let's make sure here that our data is consistent now that we have handled the
|
// so let's make sure here that our data is consistent now that we have handled the
|
||||||
// dive sites
|
// dive sites
|
||||||
displayed_dive.dive_site_uuid = current_dive->dive_site_uuid;
|
displayed_dive.dive_site_uuid = current_dive->dive_site_uuid;
|
||||||
struct dive_site *ds = get_dive_site_by_uuid(displayed_dive.dive_site_uuid);
|
|
||||||
if (ds)
|
|
||||||
copy_dive_site(ds, &displayed_dive_site);
|
|
||||||
|
|
||||||
// each dive that was selected might have had the temperatures in its active divecomputer changed
|
// each dive that was selected might have had the temperatures in its active divecomputer changed
|
||||||
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive
|
// so re-populate the temperatures - easiest way to do this is by calling fixup_dive
|
||||||
|
|
Loading…
Add table
Reference in a new issue