summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/locationinformation.cpp34
-rw-r--r--qt-ui/locationinformation.h11
-rw-r--r--qt-ui/maintab.cpp6
-rw-r--r--qt-ui/maintab.h2
4 files changed, 53 insertions, 0 deletions
diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index b3907a89a..0be4b1e65 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -324,3 +324,37 @@ void SimpleDiveSiteEditDialog::diveSiteNotes_editingFinished()
displayed_dive_site.notes = copy_string(qPrintable(ui->diveSiteNotes->toPlainText()));
changed_dive_site = true;
}
+
+bool LocationManagementEditHelper::eventFilter(QObject *obj, QEvent *ev)
+{
+ QListView *view = qobject_cast<QListView*>(obj);
+ if(!view)
+ return false;
+
+ if(ev->type() == QEvent::Show) {
+ last_uuid = displayed_dive_site.uuid;
+ }
+
+ if(ev->type() == QEvent::KeyPress) {
+ QKeyEvent *keyEv = (QKeyEvent*) ev;
+ if(keyEv->key() == Qt::Key_Space || keyEv->key() == Qt::Key_Return) {
+ handleActivation(view->currentIndex());
+ }
+
+ }
+ return false;
+}
+
+void LocationManagementEditHelper::handleActivation(const QModelIndex& activated)
+{
+ if (!activated.isValid())
+ return;
+ QModelIndex uuidIdx = activated.model()->index(
+ activated.row(), LocationInformationModel::UUID);
+ last_uuid = uuidIdx.data().toInt();
+ qDebug() << "Selected dive_site: " << last_uuid;
+}
+
+void LocationManagementEditHelper::resetDiveSiteUuid() {
+ last_uuid = displayed_dive_site.uuid;
+}
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index 42e4d5ace..7027cd8fa 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -64,4 +64,15 @@ private:
Ui::SimpleDiveSiteEditDialog *ui;
};
+
+class LocationManagementEditHelper : public QObject {
+Q_OBJECT
+public:
+ bool eventFilter(QObject *obj, QEvent *ev);
+ void handleActivation(const QModelIndex& activated);
+ void resetDiveSiteUuid();
+private:
+ uint32_t last_uuid;
+
+};
#endif
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 043fe0a6a..88b607d1b 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -67,6 +67,11 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
completer->setCaseSensitivity(Qt::CaseInsensitive);
completerListview->setItemDelegate(new LocationFilterDelegate());
+ locationManagementEditHelper = new LocationManagementEditHelper();
+ completerListview->installEventFilter(locationManagementEditHelper);
+ connect(completerListview, &QAbstractItemView::activated,
+ locationManagementEditHelper, &LocationManagementEditHelper::handleActivation);
+
ui.location->setCompleter(completer);
connect(ui.addDiveSite, SIGNAL(clicked()), this, SLOT(showDiveSiteSimpleEdit()));
connect(ui.geocodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode()));
@@ -386,6 +391,7 @@ void MainTab::enableEdition(EditMode newEditMode)
displayMessage(tr("Multiple dives are being edited."));
} else {
displayMessage(tr("This dive is being edited."));
+ locationManagementEditHelper->resetDiveSiteUuid();
}
editMode = newEditMode != NONE ? newEditMode : DIVE;
}
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 306aee66e..7f0ba1ca3 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -22,6 +22,7 @@ class CylindersModel;
class ExtraDataModel;
class DivePictureModel;
class QCompleter;
+class LocationManagementEditHelper;
struct Completers {
QCompleter *divemaster;
@@ -121,6 +122,7 @@ private:
dive_trip_t *currentTrip;
dive_trip_t displayedTrip;
bool acceptingEdit;
+ LocationManagementEditHelper *locationManagementEditHelper;
};
#endif // MAINTAB_H