Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kfileitemmodel.cpp
Show First 20 Lines • Show All 1899 Lines • ▼ Show 20 Line(s) | 1892 | for (int i = 0; i <= maxIndex; ++i) { | |||
---|---|---|---|---|---|
1900 | QChar newFirstChar = name.at(0).toUpper(); | 1900 | QChar newFirstChar = name.at(0).toUpper(); | ||
1901 | if (newFirstChar == QLatin1Char('~') && name.length() > 1) { | 1901 | if (newFirstChar == QLatin1Char('~') && name.length() > 1) { | ||
1902 | newFirstChar = name.at(1).toUpper(); | 1902 | newFirstChar = name.at(1).toUpper(); | ||
1903 | } | 1903 | } | ||
1904 | 1904 | | |||
1905 | if (firstChar != newFirstChar) { | 1905 | if (firstChar != newFirstChar) { | ||
1906 | QString newGroupValue; | 1906 | QString newGroupValue; | ||
1907 | if (newFirstChar.isLetter()) { | 1907 | if (newFirstChar.isLetter()) { | ||
1908 | // Try to find a matching group in the range 'A' to 'Z'. | 1908 | // Put together compatibility equivalent letters like latin 'A' and umlaut 'A' from the German locale | ||
1909 | static std::vector<QChar> lettersAtoZ; | 1909 | newGroupValue = QString(newFirstChar).normalized(QString::NormalizationForm_KD).at(0); | ||
1910 | lettersAtoZ.reserve('Z' - 'A' + 1); | | |||
1911 | if (lettersAtoZ.empty()) { | | |||
1912 | for (char c = 'A'; c <= 'Z'; ++c) { | | |||
1913 | lettersAtoZ.push_back(QLatin1Char(c)); | | |||
1914 | } | | |||
1915 | } | | |||
1916 | | ||||
1917 | auto localeAwareLessThan = [this](QChar c1, QChar c2) -> bool { | | |||
1918 | return m_collator.compare(c1, c2) < 0; | | |||
1919 | }; | | |||
1920 | | ||||
1921 | std::vector<QChar>::iterator it = std::lower_bound(lettersAtoZ.begin(), lettersAtoZ.end(), newFirstChar, localeAwareLessThan); | | |||
1922 | if (it != lettersAtoZ.end()) { | | |||
1923 | if (localeAwareLessThan(newFirstChar, *it) && it != lettersAtoZ.begin()) { | | |||
1924 | // newFirstChar belongs to the group preceding *it. | | |||
1925 | // Example: for an umlaut 'A' in the German locale, *it would be 'B' now. | | |||
1926 | --it; | | |||
1927 | } | | |||
1928 | newGroupValue = *it; | | |||
1929 | } else { | | |||
1930 | newGroupValue = newFirstChar; | | |||
1931 | } | | |||
1932 | } else if (newFirstChar >= QLatin1Char('0') && newFirstChar <= QLatin1Char('9')) { | 1910 | } else if (newFirstChar >= QLatin1Char('0') && newFirstChar <= QLatin1Char('9')) { | ||
1933 | // Apply group '0 - 9' for any name that starts with a digit | 1911 | // Apply group '0 - 9' for any name that starts with a digit | ||
1934 | newGroupValue = i18nc("@title:group Groups that start with a digit", "0 - 9"); | 1912 | newGroupValue = i18nc("@title:group Groups that start with a digit", "0 - 9"); | ||
1935 | } else { | 1913 | } else { | ||
1936 | newGroupValue = i18nc("@title:group", "Others"); | 1914 | newGroupValue = i18nc("@title:group", "Others"); | ||
1937 | } | 1915 | } | ||
1938 | 1916 | | |||
1939 | if (newGroupValue != groupValue) { | 1917 | if (newGroupValue != groupValue) { | ||
▲ Show 20 Lines • Show All 483 Lines • Show Last 20 Lines |