On Tue, Jul 14, 2015 at 6:51 PM, Tomaz Canabrava <[email protected]> wrote:

>
>
From 8ae0b10a7de447d3e34d071c8e0d0dc89fafe505 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Tue, 14 Jul 2015 19:09:37 -0300
Subject: [PATCH 8/8] Fix selecting the first index

The way a QCompleter works is that it grabs whatever
data it has in the completerRole and sets it back on
the line edit.

I Bypassed the QCompleter delegate to show something
other than the completerRole ( so, for instance, if
you write 'B', you could get 'Blue Hole' as the returned
text, but in fact the QCompleter has the 'B' as internal
string ( because of the weird - and wrong ) way we are
dealing with completion - trying to complete for something
that's not inside the model yet.

So I hooked a signal that will listen to the complete's
index, and if it's the first row() it's surely the special
case - then we bypass QCompleter return string and use
our own.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/locationinformation.cpp | 6 ++++++
 qt-ui/locationinformation.h   | 2 ++
 qt-ui/maintab.cpp             | 3 ++-
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index 47ceb65..39a8341 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -255,6 +255,12 @@ void LocationManagementEditHelper::handleActivation(const QModelIndex& activated
 	QModelIndex  uuidIdx = activated.model()->index(
 		activated.row(), LocationInformationModel::UUID);
 	last_uuid = uuidIdx.data().toInt();
+
+	// Special case: first option, add dive site.
+	if (activated.row() == 0) {
+		qDebug() << "Setting to " << activated.data().toString();
+		emit setLineEditText(activated.data().toString());
+	}
 	qDebug() << "Selected dive_site: " << last_uuid;
 }
 
diff --git a/qt-ui/locationinformation.h b/qt-ui/locationinformation.h
index b377319..b55a1b4 100644
--- a/qt-ui/locationinformation.h
+++ b/qt-ui/locationinformation.h
@@ -51,6 +51,8 @@ public:
 	void handleActivation(const QModelIndex& activated);
 	void resetDiveSiteUuid();
 	uint32_t diveSiteUuid() const;
+signals:
+	void setLineEditText(const QString& text);
 private:
 	uint32_t last_uuid;
 
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 0519625..53d8e30 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -62,7 +62,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	QCompleter *completer = new QCompleter();
 	QListView *completerListview = new QListView();
 	LocationInformationModel::instance()->setFirstRowTextField(ui.location);
-
 	completer->setPopup(completerListview);
 	completer->setModel(LocationInformationModel::instance());
 	completer->setCompletionColumn(LocationInformationModel::NAME);
@@ -70,6 +69,8 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	completerListview->setItemDelegate(new LocationFilterDelegate());
 
 	locationManagementEditHelper = new LocationManagementEditHelper();
+	connect(locationManagementEditHelper, &LocationManagementEditHelper::setLineEditText,
+		ui.location, &QLineEdit::setText);
 	completerListview->installEventFilter(locationManagementEditHelper);
 	connect(completerListview, &QAbstractItemView::activated,
 		locationManagementEditHelper, &LocationManagementEditHelper::handleActivation);
-- 
2.4.5

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to