From 02e94de062dc2c776ee37e8f642f0ec0ae8ad9e7 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 30 Jun 2019 23:08:02 +0200 Subject: Desktop: enable clearing of dive site Clearing dive site did not work for two reasons: 1) We didn't get a signal when editing was finished. 2) When clearing the dive site, the "add new dive site" site was set. Thus, connect to the editingFinished signal and in DiveLocationLineEdit::currDiveSite() return a null pointer if the string is empty. This means that it is not possible to have a dive site with an empty string, but that shouldn't be a problem, right? Fixes #2148 Signed-off-by: Berthold Stoeger --- desktop-widgets/locationinformation.cpp | 6 +++--- desktop-widgets/tab-widgets/maintab.cpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 03ebbc9b4..1c8c79aef 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -432,9 +432,8 @@ bool DiveLocationLineEdit::eventFilter(QObject *, QEvent *e) void DiveLocationLineEdit::focusOutEvent(QFocusEvent *ev) { - if (!view->isVisible()) { + if (!view->isVisible()) QLineEdit::focusOutEvent(ev); - } } void DiveLocationLineEdit::itemActivated(const QModelIndex &index) @@ -601,7 +600,8 @@ DiveLocationLineEdit::DiveSiteType DiveLocationLineEdit::currDiveSiteType() cons struct dive_site *DiveLocationLineEdit::currDiveSite() const { - return currDs; + // If there is no text, this corresponds to the empty dive site + return text().trimmed().isEmpty() ? nullptr : currDs; } DiveLocationListView::DiveLocationListView(QWidget*) diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 7e8279a0b..927864fb5 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -86,6 +86,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(ui.editDiveSiteButton, &QToolButton::clicked, MainWindow::instance(), &MainWindow::startDiveSiteEdit); connect(ui.location, &DiveLocationLineEdit::entered, MapWidget::instance(), &MapWidget::centerOnIndex); connect(ui.location, &DiveLocationLineEdit::currentChanged, MapWidget::instance(), &MapWidget::centerOnIndex); + connect(ui.location, &DiveLocationLineEdit::editingFinished, this, &MainTab::on_location_diveSiteSelected); QAction *action = new QAction(tr("Apply changes"), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges())); -- cgit v1.2.3-70-g09d2