[GUI] Implement stable sort (#7703)

* NaturalCompare now returns compare result instead of "less than" result
* Change to stable sort in GUI components
* Add Utils::String::naturalLessThan() helper function
* Use Qt::CaseSensitivity type
This commit is contained in:
Mike Tzou
2017-11-30 17:10:30 +08:00
committed by GitHub
parent 74d281526b
commit eac8838dc2
12 changed files with 184 additions and 154 deletions

View File

@@ -110,13 +110,20 @@ bool SearchSortModel::lessThan(const QModelIndex &left, const QModelIndex &right
switch (sortColumn()) {
case NAME:
case ENGINE_URL: {
QString vL = left.data().toString();
QString vR = right.data().toString();
return Utils::String::naturalCompareCaseInsensitive(vL, vR);
}
const QString strL = left.data().toString();
const QString strR = right.data().toString();
const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive);
if (result != 0)
return (result < 0);
return (mapFromSource(left) < mapFromSource(right));
}
break;
default:
return base::lessThan(left, right);
if (left.data() != right.data())
return base::lessThan(left, right);
return (mapFromSource(left) < mapFromSource(right));
};
}