there, this clears the case of two identical strings would appear as
'create dive site'
From 045a0f0ca5db3d498ffcf55826064f08eb082bde Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Thu, 16 Jul 2015 18:08:08 -0300
Subject: [PATCH] Show only 1 possibility if string is unique

We should only show one possibility if the dive_site name
string is unique - we don't have that dive_site yet - so
we pass to the Completer filter a Dummy string that will
surelly not be a dive site - konami code.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-models/divelocationmodel.cpp | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index 778496a..bf52e13 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -32,6 +32,18 @@ int LocationInformationModel::rowCount(const QModelIndex &parent) const
 	return internalRowCount + 2;
 }
 
+static struct dive_site *get_dive_site_name_start_which_str(const QString& str) {
+	struct dive_site *ds;
+	int i;
+	for_each_dive_site(i,ds) {
+		QString dsName(ds->name);
+		if (dsName.startsWith(str)) {
+			return ds;
+		}
+	}
+	return NULL;
+}
+
 QVariant LocationInformationModel::data(const QModelIndex &index, int role) const
 {
 	if (!index.isValid())
@@ -44,20 +56,22 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
 		switch(role) {
 			case Qt::DisplayRole : {
 				if (index.row() == 1) {
-					struct dive_site *ds;
-					int i;
-					for_each_dive_site(i, ds) {
-						QString dsName(ds->name);
-						if (dsName.startsWith(textField->text()))
-							return dsName;
-					}
+					struct dive_site *ds = get_dive_site_name_start_which_str(textField->text());
+					if(ds)
+						return ds->name;
 				}
 				return textField->text();
 			}
 			case Qt::ToolTipRole : {
 				return QString(tr("Create dive site with this name"));
 			}
-			case Qt::EditRole : return textField->text();
+			case Qt::EditRole : {
+				if (index.row() == 1) {
+					struct dive_site *ds = get_dive_site_name_start_which_str(textField->text());
+					return ds ? textField->text() : QString("↑↑↓↓←→←→baSELECT"); // konami code makes sure to *not* display a dive site here.
+				}
+				return textField->text();
+			}
 			case Qt::DecorationRole : return QIcon(":plus");
 		}
 	}
-- 
2.4.6

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

Reply via email to