┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kfileitemmodel.cpp
diff options
context:
space:
mode:
authorElvis Angelaccio <[email protected]>2019-07-28 22:11:51 +0200
committerElvis Angelaccio <[email protected]>2019-07-28 22:14:18 +0200
commitb8849f74aab2e22cc1b891c7dcf4f759fb523ea9 (patch)
treeb5a63139217213eb45406dd7f8359bfa313eb5cc /src/kitemviews/kfileitemmodel.cpp
parent572d4e54bbe68c35df7de1f54ea8f6f81db6a21c (diff)
Revert "Fix name grouping feature for cyrillic names"
This reverts commit dc586ada63d1822fbbe38a0dd3449c73b03928e0. D22303 had a wrong diff. CCBUG: 406867
Diffstat (limited to 'src/kitemviews/kfileitemmodel.cpp')
-rw-r--r--src/kitemviews/kfileitemmodel.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index 3cc140701..8145a00f1 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -1905,8 +1905,30 @@ QList<QPair<int, QVariant> > KFileItemModel::nameRoleGroups() const
if (firstChar != newFirstChar) {
QString newGroupValue;
if (newFirstChar.isLetter()) {
- // Put together compatibility equivalent letters like latin 'A' and umlaut 'A' from the German locale
- newGroupValue = QString(newFirstChar).normalized(QString::NormalizationForm_KD).at(0);
+ // Try to find a matching group in the range 'A' to 'Z'.
+ static std::vector<QChar> lettersAtoZ;
+ lettersAtoZ.reserve('Z' - 'A' + 1);
+ if (lettersAtoZ.empty()) {
+ for (char c = 'A'; c <= 'Z'; ++c) {
+ lettersAtoZ.push_back(QLatin1Char(c));
+ }
+ }
+
+ auto localeAwareLessThan = [this](QChar c1, QChar c2) -> bool {
+ return m_collator.compare(c1, c2) < 0;
+ };
+
+ std::vector<QChar>::iterator it = std::lower_bound(lettersAtoZ.begin(), lettersAtoZ.end(), newFirstChar, localeAwareLessThan);
+ if (it != lettersAtoZ.end()) {
+ if (localeAwareLessThan(newFirstChar, *it) && it != lettersAtoZ.begin()) {
+ // newFirstChar belongs to the group preceding *it.
+ // Example: for an umlaut 'A' in the German locale, *it would be 'B' now.
+ --it;
+ }
+ newGroupValue = *it;
+ } else {
+ newGroupValue = newFirstChar;
+ }
} else if (newFirstChar >= QLatin1Char('0') && newFirstChar <= QLatin1Char('9')) {
// Apply group '0 - 9' for any name that starts with a digit
newGroupValue = i18nc("@title:group Groups that start with a digit", "0 - 9");