mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 19:36:15 +00:00
Undo: implement undo of geo lookup
Simply copy code of the other edit dive site functions. Here though introduce a destructor in the undo command to free the taxonomy data. Remove the taxonomy member of the LocationInformationWidget class, because it is not needed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b5d4d88fe5
commit
7c63956ee4
6 changed files with 57 additions and 9 deletions
|
@ -108,6 +108,11 @@ void editDiveSiteLocation(dive_site *ds, location_t value)
|
|||
execute(new EditDiveSiteLocation(ds, value));
|
||||
}
|
||||
|
||||
void editDiveSiteTaxonomy(dive_site *ds, taxonomy_data &value)
|
||||
{
|
||||
execute(new EditDiveSiteTaxonomy(ds, value));
|
||||
}
|
||||
|
||||
void addDiveSite(const QString &name)
|
||||
{
|
||||
execute(new AddDiveSite(name));
|
||||
|
|
|
@ -46,6 +46,7 @@ void editDiveSiteDescription(dive_site *ds, const QString &value);
|
|||
void editDiveSiteNotes(dive_site *ds, const QString &value);
|
||||
void editDiveSiteCountry(dive_site *ds, const QString &value);
|
||||
void editDiveSiteLocation(dive_site *ds, location_t value);
|
||||
void editDiveSiteTaxonomy(dive_site *ds, taxonomy_data &value); // value is consumed (i.e. will be erased after call)!
|
||||
void addDiveSite(const QString &name);
|
||||
|
||||
} // namespace Command
|
||||
|
|
|
@ -235,4 +235,35 @@ void EditDiveSiteLocation::undo()
|
|||
redo();
|
||||
}
|
||||
|
||||
EditDiveSiteTaxonomy::EditDiveSiteTaxonomy(dive_site *dsIn, taxonomy_data &taxonomy) : ds(dsIn),
|
||||
value(taxonomy)
|
||||
{
|
||||
// We did a dumb copy. Erase the source to remove double references to strings.
|
||||
memset(&taxonomy, 0, sizeof(taxonomy));
|
||||
setText(tr("Edit dive site taxonomy"));
|
||||
}
|
||||
|
||||
EditDiveSiteTaxonomy::~EditDiveSiteTaxonomy()
|
||||
{
|
||||
free_taxonomy(&value);
|
||||
}
|
||||
|
||||
bool EditDiveSiteTaxonomy::workToBeDone()
|
||||
{
|
||||
// TODO: Apparently we have no way of comparing taxonomies?
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditDiveSiteTaxonomy::redo()
|
||||
{
|
||||
std::swap(value, ds->taxonomy);
|
||||
emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::TAXONOMY); // Inform frontend of changed dive site.
|
||||
}
|
||||
|
||||
void EditDiveSiteTaxonomy::undo()
|
||||
{
|
||||
// Undo and redo do the same
|
||||
redo();
|
||||
}
|
||||
|
||||
} // namespace Command
|
||||
|
|
|
@ -104,6 +104,19 @@ private:
|
|||
location_t value; // Value to be set
|
||||
};
|
||||
|
||||
class EditDiveSiteTaxonomy : public Base {
|
||||
public:
|
||||
EditDiveSiteTaxonomy(dive_site *ds, taxonomy_data &taxonomy);
|
||||
~EditDiveSiteTaxonomy(); // free taxonomy
|
||||
private:
|
||||
bool workToBeDone() override;
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
dive_site *ds;
|
||||
taxonomy_data value; // Value to be set
|
||||
};
|
||||
|
||||
} // namespace Command
|
||||
|
||||
#endif // COMMAND_DIVESITE_H
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "desktop-widgets/modeldelegates.h"
|
||||
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||
#include "command.h"
|
||||
#include "core/taxonomy.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QShowEvent>
|
||||
|
@ -21,7 +22,6 @@
|
|||
|
||||
LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), diveSite(nullptr)
|
||||
{
|
||||
memset(&taxonomy, 0, sizeof(taxonomy));
|
||||
ui.setupUi(this);
|
||||
ui.diveSiteMessage->setCloseButtonVisible(false);
|
||||
|
||||
|
@ -92,7 +92,7 @@ void LocationInformationWidget::updateLabels()
|
|||
ui.diveSiteName->setText(diveSite->name);
|
||||
else
|
||||
ui.diveSiteName->clear();
|
||||
const char *country = taxonomy_get_country(&taxonomy);
|
||||
const char *country = taxonomy_get_country(&diveSite->taxonomy);
|
||||
if (country)
|
||||
ui.diveSiteCountry->setText(country);
|
||||
else
|
||||
|
@ -110,7 +110,7 @@ void LocationInformationWidget::updateLabels()
|
|||
else
|
||||
ui.diveSiteCoordinates->clear();
|
||||
|
||||
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
|
||||
ui.locationTags->setText(constructLocationTags(&diveSite->taxonomy, false));
|
||||
}
|
||||
|
||||
void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field)
|
||||
|
@ -129,6 +129,7 @@ void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field)
|
|||
return;
|
||||
case LocationInformationModel::TAXONOMY:
|
||||
ui.diveSiteCountry->setText(taxonomy_get_country(&diveSite->taxonomy));
|
||||
ui.locationTags->setText(constructLocationTags(&diveSite->taxonomy, false));
|
||||
return;
|
||||
case LocationInformationModel::LOCATION:
|
||||
filter_model.setCoordinates(diveSite->location);
|
||||
|
@ -178,7 +179,6 @@ void LocationInformationWidget::initFields(dive_site *ds)
|
|||
{
|
||||
diveSite = ds;
|
||||
if (ds) {
|
||||
copy_taxonomy(&ds->taxonomy, &taxonomy);
|
||||
filter_model.set(ds, ds->location);
|
||||
updateLabels();
|
||||
enableLocationButtons(dive_site_has_gps_location(ds));
|
||||
|
@ -187,7 +187,6 @@ void LocationInformationWidget::initFields(dive_site *ds)
|
|||
if (m)
|
||||
m->invalidate();
|
||||
} else {
|
||||
free_taxonomy(&taxonomy);
|
||||
filter_model.set(0, location_t { degrees_t{ 0 }, degrees_t{ 0 } });
|
||||
clearLabels();
|
||||
}
|
||||
|
@ -228,10 +227,11 @@ void LocationInformationWidget::on_diveSiteNotes_editingFinished()
|
|||
void LocationInformationWidget::reverseGeocode()
|
||||
{
|
||||
location_t location = parseGpsText(ui.diveSiteCoordinates->text());
|
||||
if (!has_location(&location))
|
||||
if (!diveSite || !has_location(&location))
|
||||
return;
|
||||
taxonomy_data taxonomy = { 0 };
|
||||
reverseGeoLookup(location.lat, location.lon, &taxonomy);
|
||||
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
|
||||
Command::editDiveSiteTaxonomy(diveSite, taxonomy);
|
||||
}
|
||||
|
||||
DiveLocationFilterProxyModel::DiveLocationFilterProxyModel(QObject*)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "core/units.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/taxonomy.h"
|
||||
#include "ui_locationinformation.h"
|
||||
#include "qt-models/divelocationmodel.h"
|
||||
#include <stdint.h>
|
||||
|
@ -41,7 +40,6 @@ private:
|
|||
Ui::LocationInformation ui;
|
||||
GPSLocationInformationModel filter_model;
|
||||
dive_site *diveSite;
|
||||
taxonomy_data taxonomy;
|
||||
};
|
||||
|
||||
class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
|
||||
|
|
Loading…
Add table
Reference in a new issue