summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-07-14 19:09:37 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-14 15:22:00 -0700
commit536469107d94f265a03e44fcc755b92b9016cbca (patch)
tree1ff37a3fc654724fc917e71e5134329f256f03ea
parentcd3f10d5ad4124960b66112074797a16517117e9 (diff)
downloadsubsurface-536469107d94f265a03e44fcc755b92b9016cbca.tar.gz
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 <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/locationinformation.cpp6
-rw-r--r--qt-ui/locationinformation.h2
-rw-r--r--qt-ui/maintab.cpp3
3 files changed, 10 insertions, 1 deletions
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);