mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-13 05:20:00 -08:00
Add sortable Identity Attack Armour Health columns and rename P/T to ATK/HP
This commit is contained in:
parent
c69c0854fb
commit
ea0ff5c8df
1 changed files with 16 additions and 9 deletions
|
|
@ -70,11 +70,18 @@ bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelInd
|
||||||
if (isRightType && (!isLeftType || rightString.size() == cardName.size())) {
|
if (isRightType && (!isLeftType || rightString.size() == cardName.size())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (right.column() == CardDatabaseModel::PTColumn && left.column() == CardDatabaseModel::PTColumn) {
|
} else if (left.column() == right.column() &&
|
||||||
// The comparator runs O(n log n) times while the view is sorted, so
|
(left.column() == CardDatabaseModel::AttackColumn ||
|
||||||
// splitting every power/toughness string into a QStringList allocates
|
left.column() == CardDatabaseModel::ArmourColumn ||
|
||||||
// a lot for data that has exactly one separator. Work on views and
|
left.column() == CardDatabaseModel::HealthColumn)) {
|
||||||
// only split the two halves out when both strings are well formed.
|
// Compare numeric card statistics as numbers: 9 sorts before 10.
|
||||||
|
// Values containing expressions retain the existing numeric-prefix
|
||||||
|
// comparator instead of being forced into an integer type.
|
||||||
|
return lessThanNumerically(leftString, rightString) < 0;
|
||||||
|
} else if (right.column() == CardDatabaseModel::AtkHpColumn &&
|
||||||
|
left.column() == CardDatabaseModel::AtkHpColumn) {
|
||||||
|
// ATK/HP sorts by Attack first, then Health, both numerically.
|
||||||
|
// Operate on views to avoid allocations during large database sorts.
|
||||||
const QStringView leftPT = leftString;
|
const QStringView leftPT = leftString;
|
||||||
const QStringView rightPT = rightString;
|
const QStringView rightPT = rightString;
|
||||||
const qsizetype leftSlash = leftPT.indexOf(u'/');
|
const qsizetype leftSlash = leftPT.indexOf(u'/');
|
||||||
|
|
@ -83,11 +90,11 @@ bool CardDatabaseDisplayModel::lessThan(const QModelIndex &left, const QModelInd
|
||||||
const bool rightIsWellFormed = rightSlash >= 0 && rightPT.indexOf(u'/', rightSlash + 1) < 0;
|
const bool rightIsWellFormed = rightSlash >= 0 && rightPT.indexOf(u'/', rightSlash + 1) < 0;
|
||||||
|
|
||||||
if (leftIsWellFormed && rightIsWellFormed) {
|
if (leftIsWellFormed && rightIsWellFormed) {
|
||||||
const int powerComparison = lessThanNumerically(leftPT.left(leftSlash), rightPT.left(rightSlash));
|
const int attackComparison = lessThanNumerically(leftPT.left(leftSlash), rightPT.left(rightSlash));
|
||||||
if (powerComparison != 0) {
|
if (attackComparison != 0) {
|
||||||
return powerComparison < 0;
|
return attackComparison < 0;
|
||||||
}
|
}
|
||||||
// power equal, check toughness
|
// Attack equal, compare Health
|
||||||
return lessThanNumerically(leftPT.mid(leftSlash + 1), rightPT.mid(rightSlash + 1)) < 0;
|
return lessThanNumerically(leftPT.mid(leftSlash + 1), rightPT.mid(rightSlash + 1)) < 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue