From: Frank Reininghaus Date: Mon, 15 Aug 2011 11:05:53 +0000 (+0200) Subject: Fix for KFileItemModel::expansionLevelsCompare X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/dd71994b6cea7730c126f0b68351a96a0c624634 Fix for KFileItemModel::expansionLevelsCompare Before this commit, expanding and collapsing folders in the details view would lead to strange results in a folder with the items "a", "a/a/", "a/a/1", "a/a-1/", and "a/a-1/1". The problem was that the comparison between "a/a/1" and "a/a-1/1" went wrong: the first character in which the paths differ is a "/" in one of the items, such that the code that reduces this 'index' in KFileItemModel::expansionLevelsCompare in order to find the 'common path' did nothing because it checked that only *one* of the two items does not have an "/" at the position 'index'. --- diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index ddc56209b..c54a982f6 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -831,7 +831,7 @@ int KFileItemModel::expansionLevelsCompare(const KFileItem& a, const KFileItem& if (index > maxIndex) { index = maxIndex; } - while (pathA.at(index) != QLatin1Char('/') && index > 0) { + while ((pathA.at(index) != QLatin1Char('/') || pathB.at(index) != QLatin1Char('/')) && index > 0) { --index; } diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index 74706d49a..0e40b3bc4 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -228,6 +228,7 @@ void KFileItemModelTest::testExpansionLevelsCompare_data() QTest::newRow("Equal") << "/a/b" << "/a/b" << 0; QTest::newRow("Sub path: A < B") << "/a/b" << "/a/b/c" << -1; QTest::newRow("Sub path: A > B") << "/a/b/c" << "/a/b" << +1; + QTest::newRow("Same level: /a/1 < /a-1/1") << "/a/1" << "/a-1/1" << -1; } void KFileItemModelTest::testExpansionLevelsCompare()