From 536469107d94f265a03e44fcc755b92b9016cbca Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 14 Jul 2015 19:09:37 -0300 Subject: 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 in which we are dealing with completion - trying to complete for something that's not inside the model yet). So I hooked up 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 Signed-off-by: Dirk Hohndel --- qt-ui/locationinformation.cpp | 6 ++++++ qt-ui/locationinformation.h | 2 ++ qt-ui/maintab.cpp | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'qt-ui') diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp index 47ceb654e..39a8341cd 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 b37731969..b55a1b42c 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 05196254a..53d8e30b6 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); -- cgit v1.2.3-70-g09d2