From a01c9c961b6cd666e8739aa916294c0b9da1615f Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Tue, 31 Mar 2009 15:43:39 +0200
Subject: [PATCH] cpptool: sort entry that start with a given string towards
 the top of the quickopenfilter

Reviewed-by: Roberto Raggi
---
 src/plugins/cpptools/cppquickopenfilter.cpp | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/plugins/cpptools/cppquickopenfilter.cpp b/src/plugins/cpptools/cppquickopenfilter.cpp
index 8c11a8b3585..a0f74cbbd08 100644
--- a/src/plugins/cpptools/cppquickopenfilter.cpp
+++ b/src/plugins/cpptools/cppquickopenfilter.cpp
@@ -80,11 +80,12 @@ static bool compareLexigraphically(const QuickOpen::FilterEntry &a,
 QList<QuickOpen::FilterEntry> CppQuickOpenFilter::matchesFor(const QString &origEntry)
 {
     QString entry = trimWildcards(origEntry);
-    QList<QuickOpen::FilterEntry> entries;
+    QList<QuickOpen::FilterEntry> goodEntries;
+    QList<QuickOpen::FilterEntry> betterEntries;
     QStringMatcher matcher(entry, Qt::CaseInsensitive);
     const QRegExp regexp("*"+entry+"*", Qt::CaseInsensitive, QRegExp::Wildcard);
     if (!regexp.isValid())
-        return entries;
+        return goodEntries;
     bool hasWildcard = (entry.contains('*') || entry.contains('?'));
 
     QMutableMapIterator<QString, Info> it(m_searchList);
@@ -106,15 +107,21 @@ QList<QuickOpen::FilterEntry> CppQuickOpenFilter::matchesFor(const QString &orig
                 QVariant id = qVariantFromValue(info);
                 QuickOpen::FilterEntry filterEntry(this, info.symbolName, id, info.icon);
                 filterEntry.extraInfo = info.symbolType;
-                entries.append(filterEntry);
+                if (info.symbolName.startsWith(entry))
+                    betterEntries.append(filterEntry);
+                else
+                    goodEntries.append(filterEntry);
             }
         }
     }
 
-    if (entries.size() < 1000)
-        qSort(entries.begin(), entries.end(), compareLexigraphically);
+    if (goodEntries.size() < 1000)
+        qSort(goodEntries.begin(), goodEntries.end(), compareLexigraphically);
+    if (betterEntries.size() < 1000)
+        qSort(betterEntries.begin(), betterEntries.end(), compareLexigraphically);
 
-    return entries;
+    betterEntries += goodEntries;
+    return betterEntries;
 }
 
 void CppQuickOpenFilter::accept(QuickOpen::FilterEntry selection) const
-- 
GitLab