summaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-03-14 23:28:45 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commitb5d4d88fe596fa91a3f3491fe8acc220a0df7b72 (patch)
treee198af14ac0c2a72609aa66f0c644821c650650e /desktop-widgets
parent0b851d723e1b57fd2065c268977e023cfb364066 (diff)
downloadsubsurface-b5d4d88fe596fa91a3f3491fe8acc220a0df7b72.tar.gz
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>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/command.cpp2
-rw-r--r--desktop-widgets/command.h2
-rw-r--r--desktop-widgets/command_divesite.cpp13
-rw-r--r--desktop-widgets/command_divesite.h2
-rw-r--r--desktop-widgets/locationinformation.cpp97
-rw-r--r--desktop-widgets/locationinformation.h8
-rw-r--r--desktop-widgets/mapwidget.cpp8
-rw-r--r--desktop-widgets/mapwidget.h5
8 files changed, 28 insertions, 109 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp
index 36d9faf5a..4ba6c10e9 100644
--- a/desktop-widgets/command.cpp
+++ b/desktop-widgets/command.cpp
@@ -103,7 +103,7 @@ void editDiveSiteCountry(dive_site *ds, const QString &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));
}
diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h
index 782a46ea5..b41462ac9 100644
--- a/desktop-widgets/command.h
+++ b/desktop-widgets/command.h
@@ -45,7 +45,7 @@ void editDiveSiteName(dive_site *ds, const QString &value);
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, const QString &value);
+void editDiveSiteLocation(dive_site *ds, location_t value);
void addDiveSite(const QString &name);
} // namespace Command
diff --git a/desktop-widgets/command_divesite.cpp b/desktop-widgets/command_divesite.cpp
index 5e2a8b18a..91a6dbe81 100644
--- a/desktop-widgets/command_divesite.cpp
+++ b/desktop-widgets/command_divesite.cpp
@@ -208,17 +208,8 @@ 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))
+EditDiveSiteLocation::EditDiveSiteLocation(dive_site *dsIn, const location_t location) : ds(dsIn),
+ value(location)
{
setText(tr("Edit dive site location"));
}
diff --git a/desktop-widgets/command_divesite.h b/desktop-widgets/command_divesite.h
index 7ebc69ccb..bf6fb3dc4 100644
--- a/desktop-widgets/command_divesite.h
+++ b/desktop-widgets/command_divesite.h
@@ -94,7 +94,7 @@ private:
class EditDiveSiteLocation : public Base {
public:
- EditDiveSiteLocation(dive_site *ds, const QString &location);
+ EditDiveSiteLocation(dive_site *ds, location_t location);
private:
bool workToBeDone() override;
void undo() override;
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index 4c9414056..39bd6678f 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -19,21 +19,17 @@
#include <QDesktopWidget>
#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));
ui.setupUi(this);
ui.diveSiteMessage->setCloseButtonVisible(false);
- acceptAction = new QAction(tr("Apply changes"), this);
- connect(acceptAction, SIGNAL(triggered(bool)), this, SLOT(acceptChanges()));
-
- rejectAction = new QAction(tr("Discard changes"), this);
- connect(rejectAction, SIGNAL(triggered(bool)), this, SLOT(rejectChanges()));
+ QAction *acceptAction = new QAction(tr("Done"), this);
+ connect(acceptAction, &QAction::triggered, this, &LocationInformationWidget::acceptChanges);
ui.diveSiteMessage->setText(tr("Dive site management"));
ui.diveSiteMessage->addAction(acceptAction);
- ui.diveSiteMessage->addAction(rejectAction);
connect(ui.geoCodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode()));
ui.diveSiteCoordinates->installEventFilter(this);
@@ -43,9 +39,6 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo
ui.diveSiteListView->setModel(&filter_model);
ui.diveSiteListView->setModelColumn(LocationInformationModel::NAME);
ui.diveSiteListView->installEventFilter(this);
- // Map Management Code.
- connect(MapWidget::instance(), &MapWidget::coordinatesChanged,
- this, &LocationInformationWidget::updateGpsCoordinates);
}
bool LocationInformationWidget::eventFilter(QObject *object, QEvent *ev)
@@ -161,36 +154,24 @@ void LocationInformationWidget::clearLabels()
ui.locationTags->clear();
}
-void LocationInformationWidget::updateGpsCoordinates(const location_t &location)
-{
- 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)
+// Parse GPS text into location_t
+static location_t parseGpsText(const QString &text)
{
double lat, lon;
- if (parseGpsText(text, &lat, &lon)) {
- location = create_location(lat, lon);
- return true;
- }
- return false;
+ if (parseGpsText(text, &lat, &lon))
+ return create_location(lat, lon);
+ return { {0}, {0} };
}
void LocationInformationWidget::acceptChanges()
{
- resetState();
-}
-
-void LocationInformationWidget::rejectChanges()
-{
- resetState();
+ MainWindow::instance()->diveList->setEnabled(true);
+ MainWindow::instance()->setEnabledToolbar(true);
+ MainWindow::instance()->setApplicationState("Default");
+ MapWidget::instance()->endGetDiveCoordinates();
+ MapWidget::instance()->repopulateLabels();
+ MultiFilterSortModel::instance()->stopFilterDiveSite();
+ emit endEditDiveSite();
}
void LocationInformationWidget::initFields(dive_site *ds)
@@ -213,43 +194,11 @@ void LocationInformationWidget::initFields(dive_site *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()
{
if (!diveSite)
return;
- Command::editDiveSiteLocation(diveSite, ui.diveSiteCoordinates->text());
+ Command::editDiveSiteLocation(diveSite, parseGpsText(ui.diveSiteCoordinates->text()));
}
void LocationInformationWidget::on_diveSiteCountry_editingFinished()
@@ -276,20 +225,10 @@ void LocationInformationWidget::on_diveSiteNotes_editingFinished()
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()
{
- location_t location;
- if (!parseGpsText(ui.diveSiteCoordinates->text(), location))
+ location_t location = parseGpsText(ui.diveSiteCoordinates->text());
+ if (!has_location(&location))
return;
reverseGeoLookup(location.lat, location.lon, &taxonomy);
ui.locationTags->setText(constructLocationTags(&taxonomy, false));
diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h
index efa770774..550b8ba8e 100644
--- a/desktop-widgets/locationinformation.h
+++ b/desktop-widgets/locationinformation.h
@@ -23,12 +23,6 @@ protected:
public slots:
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_diveSiteCoordinates_editingFinished();
void on_diveSiteDescription_editingFinished();
@@ -45,8 +39,6 @@ signals:
private:
void clearLabels();
Ui::LocationInformation ui;
- bool modified;
- QAction *acceptAction, *rejectAction;
GPSLocationInformationModel filter_model;
dive_site *diveSite;
taxonomy_data taxonomy;
diff --git a/desktop-widgets/mapwidget.cpp b/desktop-widgets/mapwidget.cpp
index c7b4a08ad..5ae7451ee 100644
--- a/desktop-widgets/mapwidget.cpp
+++ b/desktop-widgets/mapwidget.cpp
@@ -12,6 +12,7 @@
#include "qt-models/divelocationmodel.h"
#include "mainwindow.h"
#include "divelistview.h"
+#include "command.h"
static const QUrl urlMapWidget = QUrl(QStringLiteral("qrc:/qml/MapWidget.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 *>();
connect(m_mapHelper, SIGNAL(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()
@@ -112,10 +113,9 @@ void MapWidget::selectedDivesChanged(QList<int> list)
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();
- emit coordinatesChanged(location);
+ Command::editDiveSiteLocation(ds, location);
}
void MapWidget::diveSiteChanged(struct dive_site *ds, int field)
diff --git a/desktop-widgets/mapwidget.h b/desktop-widgets/mapwidget.h
index bbdae80aa..9d31aa75a 100644
--- a/desktop-widgets/mapwidget.h
+++ b/desktop-widgets/mapwidget.h
@@ -24,9 +24,6 @@ public:
static MapWidget *instance();
void reload();
-signals:
- void coordinatesChanged(const location_t &);
-
public slots:
void centerOnSelectedDiveSite();
void centerOnDiveSite(struct dive_site *);
@@ -35,7 +32,7 @@ public slots:
void repopulateLabels();
void prepareForGetDiveCoordinates(struct dive_site *ds);
void selectedDivesChanged(QList<int>);
- void coordinatesChangedLocal(const location_t &);
+ void coordinatesChanged(struct dive_site *ds, const location_t &);
void doneLoading(QQuickWidget::Status status);
void diveSiteChanged(struct dive_site *ds, int field);