Undo: implement undo of dive site location editing

Simply copy the code of note editing. It's a bit more complex,
since we have to parse the Gps coordinates. For consitency,
rename the COORD field to LOCATION (the field in the dive_site
struct is called LOCATION).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-03-14 22:07:48 +01:00 committed by Dirk Hohndel
parent 1deded7874
commit fa4fedbb48
9 changed files with 69 additions and 25 deletions

View file

@ -208,4 +208,40 @@ void EditDiveSiteCountry::undo()
redo();
}
// Parse GPS text into location_t
static location_t parseGpsText(const QString &text)
{
double lat, lon;
if (parseGpsText(text, &lat, &lon))
return create_location(lat, lon);
return { {0}, {0} };
}
EditDiveSiteLocation::EditDiveSiteLocation(dive_site *dsIn, const QString &location) : ds(dsIn),
value(parseGpsText(location))
{
setText(tr("Edit dive site location"));
}
bool EditDiveSiteLocation::workToBeDone()
{
bool ok = has_location(&value);
bool old_ok = has_location(&ds->location);
if (ok != old_ok)
return true;
return ok && !same_location(&value, &ds->location);
}
void EditDiveSiteLocation::redo()
{
std::swap(value, ds->location);
emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::LOCATION); // Inform frontend of changed dive site.
}
void EditDiveSiteLocation::undo()
{
// Undo and redo do the same
redo();
}
} // namespace Command