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.

BUG: 433247
FIXED-IN: 21.08
This commit is contained in:
Christian Muehlhaeuser 2021-07-10 19:35:26 +02:00 committed by Elvis Angelaccio
parent 7e0d3e04ce
commit baaf0c29b8

View file

@ -1798,17 +1798,25 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
auto valueB = b->values.value("count"); auto valueB = b->values.value("count");
if (valueA.isNull()) { if (valueA.isNull()) {
if (valueB.isNull()) { if (valueB.isNull()) {
return 0; result = 0;
break;
} else { } else {
return -1; result = -1;
break;
} }
} else if (valueB.isNull()) { } else if (valueB.isNull()) {
return +1; result = +1;
break;
} else { } else {
if (valueA.toLongLong() < valueB.toLongLong()) { if (valueA.toLongLong() < valueB.toLongLong()) {
return -1; result = -1;
break;
} else if (valueA.toLongLong() > valueB.toLongLong()) {
result = +1;
break;
} else { } else {
return +1; result = 0;
break;
} }
} }
} }