mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-22 10:22:15 -07:00
distinguish between groupBy and sortBy options
This commit is contained in:
parent
b92047bc3f
commit
aa0c5032ee
3 changed files with 26 additions and 6 deletions
|
|
@ -69,13 +69,25 @@ std::function<QString(CardItem *)> CardList::getExtractorFor(SortOption option)
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case NoSort:
|
case NoSort:
|
||||||
return [](CardItem *) { return ""; };
|
return [](CardItem *) { return ""; };
|
||||||
case SortByName:
|
case SortByMainType:
|
||||||
return [](CardItem *c) { return c->getName(); };
|
|
||||||
case SortByType:
|
|
||||||
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getMainCardType() : ""; };
|
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getMainCardType() : ""; };
|
||||||
case SortByManaValue:
|
case SortByManaValue:
|
||||||
// getCmc returns the int as a string. We pad with 0's so that string comp also works on it
|
// getCmc returns the int as a string. We pad with 0's so that string comp also works on it
|
||||||
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getCmc().rightJustified(4, '0') : ""; };
|
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getCmc().rightJustified(4, '0') : ""; };
|
||||||
|
case SortByName:
|
||||||
|
return [](CardItem *c) { return c->getName(); };
|
||||||
|
case SortByType:
|
||||||
|
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getCardType() : ""; };
|
||||||
|
case SortByManaCost:
|
||||||
|
return [](CardItem *c) {
|
||||||
|
auto info = c->getInfo();
|
||||||
|
if (!info)
|
||||||
|
return QString("");
|
||||||
|
|
||||||
|
// calculation copied from CardDatabaseModel.
|
||||||
|
// we pad the cmc and also append the mana cost to the end so same cmc cards still have a sort order
|
||||||
|
return QString("%1%2").arg(info->getCmc(), 4, QChar('0')).arg(info->getManaCost());
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// this line should never be reached
|
// this line should never be reached
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,17 @@ public:
|
||||||
enum SortOption
|
enum SortOption
|
||||||
{
|
{
|
||||||
NoSort,
|
NoSort,
|
||||||
|
|
||||||
|
// Options that are used by groupBy
|
||||||
|
// Should partition all cards into a reasonable number of buckets
|
||||||
|
SortByMainType,
|
||||||
|
SortByManaValue,
|
||||||
|
|
||||||
|
// Options that are used by sortBy
|
||||||
|
// We don't care about buckets; we want as many distinct values as possible.
|
||||||
SortByName,
|
SortByName,
|
||||||
SortByType,
|
SortByType,
|
||||||
SortByManaValue
|
SortByManaCost,
|
||||||
};
|
};
|
||||||
CardList(bool _contentsKnown);
|
CardList(bool _contentsKnown);
|
||||||
CardItem *findCard(const int cardId) const;
|
CardItem *findCard(const int cardId) const;
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ void ZoneViewWidget::retranslateUi()
|
||||||
int oldIndex = groupBySelector.currentIndex();
|
int oldIndex = groupBySelector.currentIndex();
|
||||||
groupBySelector.clear();
|
groupBySelector.clear();
|
||||||
groupBySelector.addItem(tr("Group by ---"), CardList::NoSort);
|
groupBySelector.addItem(tr("Group by ---"), CardList::NoSort);
|
||||||
groupBySelector.addItem(tr("Group by Type"), CardList::SortByType);
|
groupBySelector.addItem(tr("Group by Type"), CardList::SortByMainType);
|
||||||
groupBySelector.addItem(tr("Group by Mana Value"), CardList::SortByManaValue);
|
groupBySelector.addItem(tr("Group by Mana Value"), CardList::SortByManaValue);
|
||||||
groupBySelector.setCurrentIndex(oldIndex);
|
groupBySelector.setCurrentIndex(oldIndex);
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +204,7 @@ void ZoneViewWidget::retranslateUi()
|
||||||
sortBySelector.addItem(tr("Sort by ---"), CardList::NoSort);
|
sortBySelector.addItem(tr("Sort by ---"), CardList::NoSort);
|
||||||
sortBySelector.addItem(tr("Sort by Name"), CardList::SortByName);
|
sortBySelector.addItem(tr("Sort by Name"), CardList::SortByName);
|
||||||
sortBySelector.addItem(tr("Sort by Type"), CardList::SortByType);
|
sortBySelector.addItem(tr("Sort by Type"), CardList::SortByType);
|
||||||
sortBySelector.addItem(tr("Sort by Mana Value"), CardList::SortByManaValue);
|
sortBySelector.addItem(tr("Sort by Mana Cost"), CardList::SortByManaCost);
|
||||||
sortBySelector.setCurrentIndex(oldIndex);
|
sortBySelector.setCurrentIndex(oldIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue