summaryrefslogtreecommitdiffstats
path: root/qt-ui/locationinformation.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-07-08 14:27:17 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-13 15:41:16 -0700
commit3b2a02dffaeaa788e08c7ba07af14df7ef055489 (patch)
tree0f261843f6cb8f1a0f7fd0bda69e003feecd2b70 /qt-ui/locationinformation.cpp
parente82f8ea565a68aa1fa980cb12c1f136b1d4a57f9 (diff)
downloadsubsurface-3b2a02dffaeaa788e08c7ba07af14df7ef055489.tar.gz
Get the selected dive site from the list
Hooked up an eventFilter on the QListView that displays our dive sites so it would filter the keys enter and space, storing the current dive_site uuid when that happens. Also it stores the uuid on clicks. Now we need to get that information when processing acceptedChanges() and check if the uuid stored there == displayed_dive_site.uuid and also if text != displayed_dive_site.name, because if the user didn't click on anything but only wrote stuff on the LineEdit no dive site would be selected and so uuid == displayed_dive_site.uuid (wich would mean 'no changes') Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/locationinformation.cpp')
-rw-r--r--qt-ui/locationinformation.cpp34
1 files changed, 34 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;
+}