mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-22 10:22:15 -07:00
simplify sort function
This commit is contained in:
parent
2ba41e126c
commit
14a9b5f9b7
1 changed files with 6 additions and 12 deletions
|
|
@ -210,21 +210,15 @@ void SetList::guessSortKeys()
|
|||
|
||||
void SetList::defaultSort()
|
||||
{
|
||||
static const QDate distantPast = QDate(1970, 1, 1);
|
||||
std::sort(begin(), end(), [](const CardSetPtr &a, const CardSetPtr &b) {
|
||||
QDate aDate = a->getReleaseDate().isValid() ? a->getReleaseDate() : distantPast;
|
||||
QDate bDate = b->getReleaseDate().isValid() ? b->getReleaseDate() : distantPast;
|
||||
CardSet::Priority aPriority = a->getPriority() ? a->getPriority() : CardSet::PriorityFallback;
|
||||
CardSet::Priority bPriority = b->getPriority() ? b->getPriority() : CardSet::PriorityFallback;
|
||||
|
||||
// Sort by priority, then by release date, then by short name
|
||||
if (aPriority != bPriority) {
|
||||
return aPriority < bPriority;
|
||||
if (a->getPriority() != b->getPriority()) {
|
||||
return a->getPriority() < b->getPriority(); // lowest first
|
||||
} else if (a->getReleaseDate() != b->getReleaseDate()) {
|
||||
return a->getReleaseDate() > b->getReleaseDate(); // most recent first
|
||||
} else {
|
||||
return a->getShortName() < b->getShortName(); // alphabetically
|
||||
}
|
||||
if (aDate.daysTo(bDate) != 0) {
|
||||
return aDate.daysTo(bDate) < 0;
|
||||
}
|
||||
return a->getShortName().compare(b->getShortName()) < 0;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue