mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
cd3f10d5ad
commit
536469107d
3 changed files with 10 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue