Bug 433247

Summary: Folder expanded incorrectly when sorted by ascending size
Product: [Applications] dolphin Reporter: GreggB <sequalsoft>
Component: view-engine: details modeAssignee: Dolphin Bug Assignee <dolphin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: kfm-devel, kordikmarek, muesli
Priority: NOR    
Version: 20.12.2   
Target Milestone: ---   
Platform: Manjaro   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=473999
Latest Commit: Version Fixed In: 21.08
Attachments: Screen capture showing folder expansion

Description GreggB 2021-02-19 13:24:04 UTC
Created attachment 135903 [details]
Screen capture showing folder expansion

SUMMARY
When in Detail view sorted by ascending size: clicking on the arrow to expand a folder will sometimes show the folders files under a folder further down the list.

STEPS TO REPRODUCE
1. Set Dolphin to detail view
2. Navigate to a folder with many sub-folders
3. Sort by ascending size
4. Click on an arrow to expand a folder
5. If the folder expands normally, click again to collapse, then click the arrow on the following folder.

OBSERVED RESULT
For some folders the files will show as the contents of another folder further down the list. (please see attached screen cap)

EXPECTED RESULT
Every expanded folder should show it contents directly below it.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 
KDE Plasma Version: 5.20.5
KDE Frameworks Version: 5.78.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION
This seems to happen more in folders with lots of sub-folders.
Comment 1 marek 2021-02-28 21:28:00 UTC
I can also reproduce it but I can reproduce the same behaviour both for ascending and descending ordering according to size. The number of folders/files does not need to be high. It can be reproduced with three folders with three files in each. Furthermore sometimes (when are folders ordered by size) it happens that seemingly random folders swap their places - for example:

.
├── a
├── b
├── c
├── d
└── e

after expanding of "c":

.
├── b
├── a
├── c
│   ├── c1
│   ├── c2
│   ├── c3
│   └── c4
├── d
└── e

System info:
Operating System: Manjaro Linux
KDE Plasma Version: 5.21.1
KDE Frameworks Version: 5.79.0
Qt Version: 5.15.2
Kernel Version: 5.10.18-1-MANJARO
OS Type: 64-bit
Graphics Platform: X11
Comment 2 Christian Muehlhaeuser 2021-07-10 17:01:55 UTC
Can you reproduce this on Arch as well.
Comment 3 Christian Muehlhaeuser 2021-07-10 17:02:49 UTC
(In reply to Christian Muehlhaeuser from comment #2)
> Can you reproduce this on Arch as well.

Sorry, I meant to say: "I can reproduce this on Arch as well."
Comment 4 Christian Muehlhaeuser 2021-07-10 17:43:06 UTC
Quickly fixed this and posted a PR ready for review: https://invent.kde.org/system/dolphin/-/merge_requests/232
Comment 5 Elvis Angelaccio 2021-07-13 19:51:41 UTC
Git commit baaf0c29b857997720b9cb0d584a44306963fb97 by Elvis Angelaccio, on behalf of Christian Muehlhaeuser.
Committed on 13/07/2021 at 19:48.
Pushed by elvisangelaccio into branch 'release/21.08'.

Ensure stable sort order when sorting by size

Folders with equal size caused the sort operation to become unstable,
as the result of lessThan was non-deterministic.

We need the fallback mechanisms at the bottom of the function to
resovle the situation and provide a stable sort order.

This also fixes expanding the contents of a folder into the wrong
parent.
FIXED-IN: 21.08

M  +13   -5    src/kitemviews/kfileitemmodel.cpp

https://invent.kde.org/system/dolphin/commit/baaf0c29b857997720b9cb0d584a44306963fb97