[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

@@ -50,13 +50,21 @@ protected:
switch (sortColumn()) {
case PeerListDelegate::IP:
case PeerListDelegate::CLIENT: {
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 QSortFilterProxyModel::lessThan(left, right);
return (mapFromSource(left) < mapFromSource(right));
}
break;
default:
if (left.data() != right.data())
return QSortFilterProxyModel::lessThan(left, right);
return (mapFromSource(left) < mapFromSource(right));
};
}
};