diff options
| author | Francois Ferrand <thetypz@gmail.com> | 2012-06-21 11:29:39 +0200 |
|---|---|---|
| committer | Leandro Melo <leandro.melo@nokia.com> | 2012-06-28 16:09:20 +0200 |
| commit | 0b12ed143e1a247fa34b2fffbf7262d104c97b9d (patch) | |
| tree | d68c3743b98b2f66eabf63a8280543aaddbad988 /src | |
| parent | ded2dd12b84e67712e2bc5e0c8c0f392fa2479a6 (diff) | |
| download | qt-creator-0b12ed143e1a247fa34b2fffbf7262d104c97b9d.tar.gz | |
[CodeAssist] Logical sort of proposals.
Improve the sorting of proposals, so that "logical" sort is used: if there are
numeric parts in the strings, these are compared as numbers instead of purely
lexicographically.
Thus, the list: [item1, item10, item1b, item2]
gets sorted as: [item1, item1b, item2, item10]
Change-Id: I16a0106d9dc9bb27731f96c3f180ad20cd9a44f5
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/texteditor/codeassist/basicproposalitemlistmodel.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/plugins/texteditor/codeassist/basicproposalitemlistmodel.cpp b/src/plugins/texteditor/codeassist/basicproposalitemlistmodel.cpp index 350a6567c3..566f00daa7 100644 --- a/src/plugins/texteditor/codeassist/basicproposalitemlistmodel.cpp +++ b/src/plugins/texteditor/codeassist/basicproposalitemlistmodel.cpp @@ -74,7 +74,34 @@ struct ContentLessThan bool lessThan(const QString &a, const QString &b) { - return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), CharLessThan()); + QString::const_iterator pa = a.begin(); + QString::const_iterator pb = b.begin(); + + CharLessThan charLessThan; + enum { Letter, SmallerNumber, BiggerNumber } state = Letter; + for (; pa != a.end() && pb != b.end(); ++pa, ++pb) { + if (*pa == *pb) + continue; + if (state != Letter) { + if (!pa->isDigit() || !pb->isDigit()) + break; + } else if (pa->isDigit() && pb->isDigit()) { + if (charLessThan(*pa, *pb)) + state = SmallerNumber; + else + state = BiggerNumber; + } else { + return charLessThan(*pa, *pb); + } + } + + if (state == Letter) + return pa == a.end() && pb != b.end(); + if (pa != a.end() && pa->isDigit()) + return false; //more digits + if (pb != b.end() && pb->isDigit()) + return true; //fewer digits + return state == SmallerNumber; //same length, compare first different digit in the sequence } struct CharLessThan |
