Dive site: remove edit mode from dive location widget

Since no dive site field editing enters edit mode anymore,
the whole edit mode state and code can be removed from the
widget.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-03-14 23:28:45 +01:00 committed by Dirk Hohndel
parent 0b851d723e
commit b5d4d88fe5
10 changed files with 30 additions and 113 deletions

View file

@ -103,7 +103,7 @@ void editDiveSiteCountry(dive_site *ds, const QString &value)
execute(new EditDiveSiteCountry(ds, value)); execute(new EditDiveSiteCountry(ds, value));
} }
void editDiveSiteLocation(dive_site *ds, const QString &value) void editDiveSiteLocation(dive_site *ds, location_t value)
{ {
execute(new EditDiveSiteLocation(ds, value)); execute(new EditDiveSiteLocation(ds, value));
} }

View file

@ -45,7 +45,7 @@ void editDiveSiteName(dive_site *ds, const QString &value);
void editDiveSiteDescription(dive_site *ds, const QString &value); void editDiveSiteDescription(dive_site *ds, const QString &value);
void editDiveSiteNotes(dive_site *ds, const QString &value); void editDiveSiteNotes(dive_site *ds, const QString &value);
void editDiveSiteCountry(dive_site *ds, const QString &value); void editDiveSiteCountry(dive_site *ds, const QString &value);
void editDiveSiteLocation(dive_site *ds, const QString &value); void editDiveSiteLocation(dive_site *ds, location_t value);
void addDiveSite(const QString &name); void addDiveSite(const QString &name);
} // namespace Command } // namespace Command

View file

@ -208,17 +208,8 @@ void EditDiveSiteCountry::undo()
redo(); redo();
} }
// Parse GPS text into location_t EditDiveSiteLocation::EditDiveSiteLocation(dive_site *dsIn, const location_t location) : ds(dsIn),
static location_t parseGpsText(const QString &text) value(location)
{
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")); setText(tr("Edit dive site location"));
} }

View file

@ -94,7 +94,7 @@ private:
class EditDiveSiteLocation : public Base { class EditDiveSiteLocation : public Base {
public: public:
EditDiveSiteLocation(dive_site *ds, const QString &location); EditDiveSiteLocation(dive_site *ds, location_t location);
private: private:
bool workToBeDone() override; bool workToBeDone() override;
void undo() override; void undo() override;

View file

@ -19,21 +19,17 @@
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QScrollBar> #include <QScrollBar>
LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), modified(false), diveSite(nullptr) LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBox(parent), diveSite(nullptr)
{ {
memset(&taxonomy, 0, sizeof(taxonomy)); memset(&taxonomy, 0, sizeof(taxonomy));
ui.setupUi(this); ui.setupUi(this);
ui.diveSiteMessage->setCloseButtonVisible(false); ui.diveSiteMessage->setCloseButtonVisible(false);
acceptAction = new QAction(tr("Apply changes"), this); QAction *acceptAction = new QAction(tr("Done"), this);
connect(acceptAction, SIGNAL(triggered(bool)), this, SLOT(acceptChanges())); connect(acceptAction, &QAction::triggered, this, &LocationInformationWidget::acceptChanges);
rejectAction = new QAction(tr("Discard changes"), this);
connect(rejectAction, SIGNAL(triggered(bool)), this, SLOT(rejectChanges()));
ui.diveSiteMessage->setText(tr("Dive site management")); ui.diveSiteMessage->setText(tr("Dive site management"));
ui.diveSiteMessage->addAction(acceptAction); ui.diveSiteMessage->addAction(acceptAction);
ui.diveSiteMessage->addAction(rejectAction);
connect(ui.geoCodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode())); connect(ui.geoCodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode()));
ui.diveSiteCoordinates->installEventFilter(this); ui.diveSiteCoordinates->installEventFilter(this);
@ -43,9 +39,6 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo
ui.diveSiteListView->setModel(&filter_model); ui.diveSiteListView->setModel(&filter_model);
ui.diveSiteListView->setModelColumn(LocationInformationModel::NAME); ui.diveSiteListView->setModelColumn(LocationInformationModel::NAME);
ui.diveSiteListView->installEventFilter(this); ui.diveSiteListView->installEventFilter(this);
// Map Management Code.
connect(MapWidget::instance(), &MapWidget::coordinatesChanged,
this, &LocationInformationWidget::updateGpsCoordinates);
} }
bool LocationInformationWidget::eventFilter(QObject *object, QEvent *ev) bool LocationInformationWidget::eventFilter(QObject *object, QEvent *ev)
@ -161,36 +154,24 @@ void LocationInformationWidget::clearLabels()
ui.locationTags->clear(); ui.locationTags->clear();
} }
void LocationInformationWidget::updateGpsCoordinates(const location_t &location) // Parse GPS text into location_t
{ static location_t parseGpsText(const QString &text)
QString oldText = ui.diveSiteCoordinates->text();
ui.diveSiteCoordinates->setText(printGPSCoords(&location));
enableLocationButtons(has_location(&location));
if (oldText != ui.diveSiteCoordinates->text())
markChangedWidget(ui.diveSiteCoordinates);
}
// Parse GPS text into latitude and longitude.
// On error, false is returned and the output parameters are left unmodified.
bool parseGpsText(const QString &text, location_t &location)
{ {
double lat, lon; double lat, lon;
if (parseGpsText(text, &lat, &lon)) { if (parseGpsText(text, &lat, &lon))
location = create_location(lat, lon); return create_location(lat, lon);
return true; return { {0}, {0} };
}
return false;
} }
void LocationInformationWidget::acceptChanges() void LocationInformationWidget::acceptChanges()
{ {
resetState(); MainWindow::instance()->diveList->setEnabled(true);
} MainWindow::instance()->setEnabledToolbar(true);
MainWindow::instance()->setApplicationState("Default");
void LocationInformationWidget::rejectChanges() MapWidget::instance()->endGetDiveCoordinates();
{ MapWidget::instance()->repopulateLabels();
resetState(); MultiFilterSortModel::instance()->stopFilterDiveSite();
emit endEditDiveSite();
} }
void LocationInformationWidget::initFields(dive_site *ds) void LocationInformationWidget::initFields(dive_site *ds)
@ -213,43 +194,11 @@ void LocationInformationWidget::initFields(dive_site *ds)
MapWidget::instance()->prepareForGetDiveCoordinates(ds); MapWidget::instance()->prepareForGetDiveCoordinates(ds);
} }
void LocationInformationWidget::markChangedWidget(QWidget *w)
{
QPalette p;
qreal h, s, l, a;
if (!modified)
enableEdition();
qApp->palette().color(QPalette::Text).getHslF(&h, &s, &l, &a);
p.setBrush(QPalette::Base, (l <= 0.3) ? QColor(Qt::yellow).lighter() : (l <= 0.6) ? QColor(Qt::yellow).light() : /* else */ QColor(Qt::yellow).darker(300));
w->setPalette(p);
modified = true;
}
void LocationInformationWidget::resetState()
{
modified = false;
resetPallete();
MainWindow::instance()->diveList->setEnabled(true);
MainWindow::instance()->setEnabledToolbar(true);
ui.diveSiteMessage->setText(tr("Dive site management"));
MapWidget::instance()->endGetDiveCoordinates();
MapWidget::instance()->repopulateLabels();
MultiFilterSortModel::instance()->stopFilterDiveSite();
emit endEditDiveSite();
}
void LocationInformationWidget::enableEdition()
{
MainWindow::instance()->diveList->setEnabled(false);
MainWindow::instance()->setEnabledToolbar(false);
ui.diveSiteMessage->setText(tr("You are editing a dive site"));
}
void LocationInformationWidget::on_diveSiteCoordinates_editingFinished() void LocationInformationWidget::on_diveSiteCoordinates_editingFinished()
{ {
if (!diveSite) if (!diveSite)
return; return;
Command::editDiveSiteLocation(diveSite, ui.diveSiteCoordinates->text()); Command::editDiveSiteLocation(diveSite, parseGpsText(ui.diveSiteCoordinates->text()));
} }
void LocationInformationWidget::on_diveSiteCountry_editingFinished() void LocationInformationWidget::on_diveSiteCountry_editingFinished()
@ -276,20 +225,10 @@ void LocationInformationWidget::on_diveSiteNotes_editingFinished()
Command::editDiveSiteNotes(diveSite, ui.diveSiteNotes->toPlainText()); Command::editDiveSiteNotes(diveSite, ui.diveSiteNotes->toPlainText());
} }
void LocationInformationWidget::resetPallete()
{
QPalette p;
ui.diveSiteCoordinates->setPalette(p);
ui.diveSiteDescription->setPalette(p);
ui.diveSiteCountry->setPalette(p);
ui.diveSiteName->setPalette(p);
ui.diveSiteNotes->setPalette(p);
}
void LocationInformationWidget::reverseGeocode() void LocationInformationWidget::reverseGeocode()
{ {
location_t location; location_t location = parseGpsText(ui.diveSiteCoordinates->text());
if (!parseGpsText(ui.diveSiteCoordinates->text(), location)) if (!has_location(&location))
return; return;
reverseGeoLookup(location.lat, location.lon, &taxonomy); reverseGeoLookup(location.lat, location.lon, &taxonomy);
ui.locationTags->setText(constructLocationTags(&taxonomy, false)); ui.locationTags->setText(constructLocationTags(&taxonomy, false));

View file

@ -23,12 +23,6 @@ protected:
public slots: public slots:
void acceptChanges(); void acceptChanges();
void rejectChanges();
void updateGpsCoordinates(const location_t &);
void markChangedWidget(QWidget *w);
void enableEdition();
void resetState();
void resetPallete();
void on_diveSiteCountry_editingFinished(); void on_diveSiteCountry_editingFinished();
void on_diveSiteCoordinates_editingFinished(); void on_diveSiteCoordinates_editingFinished();
void on_diveSiteDescription_editingFinished(); void on_diveSiteDescription_editingFinished();
@ -45,8 +39,6 @@ signals:
private: private:
void clearLabels(); void clearLabels();
Ui::LocationInformation ui; Ui::LocationInformation ui;
bool modified;
QAction *acceptAction, *rejectAction;
GPSLocationInformationModel filter_model; GPSLocationInformationModel filter_model;
dive_site *diveSite; dive_site *diveSite;
taxonomy_data taxonomy; taxonomy_data taxonomy;

View file

@ -12,6 +12,7 @@
#include "qt-models/divelocationmodel.h" #include "qt-models/divelocationmodel.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "divelistview.h" #include "divelistview.h"
#include "command.h"
static const QUrl urlMapWidget = QUrl(QStringLiteral("qrc:/qml/MapWidget.qml")); static const QUrl urlMapWidget = QUrl(QStringLiteral("qrc:/qml/MapWidget.qml"));
static const QUrl urlMapWidgetError = QUrl(QStringLiteral("qrc:/qml/MapWidgetError.qml")); static const QUrl urlMapWidgetError = QUrl(QStringLiteral("qrc:/qml/MapWidgetError.qml"));
@ -49,7 +50,7 @@ void MapWidget::doneLoading(QQuickWidget::Status status)
m_mapHelper = rootObject()->findChild<MapWidgetHelper *>(); m_mapHelper = rootObject()->findChild<MapWidgetHelper *>();
connect(m_mapHelper, SIGNAL(selectedDivesChanged(QList<int>)), connect(m_mapHelper, SIGNAL(selectedDivesChanged(QList<int>)),
this, SLOT(selectedDivesChanged(QList<int>))); this, SLOT(selectedDivesChanged(QList<int>)));
connect(m_mapHelper, &MapWidgetHelper::coordinatesChanged, this, &MapWidget::coordinatesChangedLocal); connect(m_mapHelper, &MapWidgetHelper::coordinatesChanged, this, &MapWidget::coordinatesChanged);
} }
void MapWidget::centerOnSelectedDiveSite() void MapWidget::centerOnSelectedDiveSite()
@ -112,10 +113,9 @@ void MapWidget::selectedDivesChanged(QList<int> list)
skipReload = false; skipReload = false;
} }
void MapWidget::coordinatesChangedLocal(const location_t &location) void MapWidget::coordinatesChanged(struct dive_site *ds, const location_t &location)
{ {
CHECK_IS_READY_RETURN_VOID(); Command::editDiveSiteLocation(ds, location);
emit coordinatesChanged(location);
} }
void MapWidget::diveSiteChanged(struct dive_site *ds, int field) void MapWidget::diveSiteChanged(struct dive_site *ds, int field)

View file

@ -24,9 +24,6 @@ public:
static MapWidget *instance(); static MapWidget *instance();
void reload(); void reload();
signals:
void coordinatesChanged(const location_t &);
public slots: public slots:
void centerOnSelectedDiveSite(); void centerOnSelectedDiveSite();
void centerOnDiveSite(struct dive_site *); void centerOnDiveSite(struct dive_site *);
@ -35,7 +32,7 @@ public slots:
void repopulateLabels(); void repopulateLabels();
void prepareForGetDiveCoordinates(struct dive_site *ds); void prepareForGetDiveCoordinates(struct dive_site *ds);
void selectedDivesChanged(QList<int>); void selectedDivesChanged(QList<int>);
void coordinatesChangedLocal(const location_t &); void coordinatesChanged(struct dive_site *ds, const location_t &);
void doneLoading(QQuickWidget::Status status); void doneLoading(QQuickWidget::Status status);
void diveSiteChanged(struct dive_site *ds, int field); void diveSiteChanged(struct dive_site *ds, int field);

View file

@ -257,7 +257,7 @@ void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *
if (loc) if (loc)
loc->setCoordinate(coord); loc->setCoordinate(coord);
location_t location = mk_location(coord); location_t location = mk_location(coord);
emit coordinatesChanged(location); emit coordinatesChanged(ds, location);
} }
void MapWidgetHelper::updateDiveSiteCoordinates(struct dive_site *ds, const location_t &location) void MapWidgetHelper::updateDiveSiteCoordinates(struct dive_site *ds, const location_t &location)
@ -294,8 +294,6 @@ void MapWidgetHelper::enterEditMode(struct dive_site *ds)
coord = exists->coordinate(); coord = exists->coordinate();
} }
centerOnDiveSite(ds); centerOnDiveSite(ds);
location_t location = mk_location(coord);
emit coordinatesChanged(location);
emit editModeChanged(); emit editModeChanged();
} }

View file

@ -53,7 +53,7 @@ signals:
void modelChanged(); void modelChanged();
void editModeChanged(); void editModeChanged();
void selectedDivesChanged(QList<int> list); void selectedDivesChanged(QList<int> list);
void coordinatesChanged(const location_t &); void coordinatesChanged(struct dive_site *ds, const location_t &);
void pluginObjectChanged(); void pluginObjectChanged();
}; };