mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
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:
parent
0b851d723e
commit
b5d4d88fe5
10 changed files with 30 additions and 113 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ void MapWidgetHelper::updateCurrentDiveSiteCoordinatesFromMap(struct dive_site *
|
|||
if (loc)
|
||||
loc->setCoordinate(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)
|
||||
|
@ -294,8 +294,6 @@ void MapWidgetHelper::enterEditMode(struct dive_site *ds)
|
|||
coord = exists->coordinate();
|
||||
}
|
||||
centerOnDiveSite(ds);
|
||||
location_t location = mk_location(coord);
|
||||
emit coordinatesChanged(location);
|
||||
emit editModeChanged();
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ signals:
|
|||
void modelChanged();
|
||||
void editModeChanged();
|
||||
void selectedDivesChanged(QList<int> list);
|
||||
void coordinatesChanged(const location_t &);
|
||||
void coordinatesChanged(struct dive_site *ds, const location_t &);
|
||||
void pluginObjectChanged();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue