]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix for KFileItemModel::expansionLevelsCompare
authorFrank Reininghaus <frank78ac@googlemail.com>
Mon, 15 Aug 2011 11:05:53 +0000 (13:05 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Mon, 15 Aug 2011 11:05:53 +0000 (13:05 +0200)
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'.

src/kitemviews/kfileitemmodel.cpp
src/tests/kfileitemmodeltest.cpp

index ddc56209b8df72e1f319838640cb2e17f0dfd6a0..c54a982f6fc6eb3b00e8be5a643364d5c2d35746 100644 (file)
@@ -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;
     }
 
index 74706d49ae7127d945eac0a2c02ca7a683605f69..0e40b3bc44343f1901ca2a22b997802cc1916ce7 100644 (file)
@@ -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()