refactor to use lambda

This commit is contained in:
RickyRister 2024-11-25 22:30:05 -08:00
parent b1911d13c8
commit db858e3140
2 changed files with 4 additions and 19 deletions

View file

@ -31,17 +31,9 @@ CardItem *CardList::findCard(const int cardId) const
return nullptr; return nullptr;
} }
class CardList::compareFunctor void CardList::sort(int flags)
{ {
private: auto comparator = [flags](CardItem *a, CardItem *b) {
int flags;
public:
explicit compareFunctor(int _flags) : flags(_flags)
{
}
inline bool operator()(CardItem *a, CardItem *b) const
{
if (flags & SortByType) { if (flags & SortByType) {
QString t1 = a->getInfo() ? a->getInfo()->getMainCardType() : QString(); QString t1 = a->getInfo() ? a->getInfo()->getMainCardType() : QString();
QString t2 = b->getInfo() ? b->getInfo()->getMainCardType() : QString(); QString t2 = b->getInfo() ? b->getInfo()->getMainCardType() : QString();
@ -50,11 +42,7 @@ public:
return t1 < t2; return t1 < t2;
} else } else
return a->getName() < b->getName(); return a->getName() < b->getName();
} };
};
void CardList::sort(int flags) std::sort(begin(), end(), comparator);
{
compareFunctor cf(flags);
std::sort(begin(), end(), cf);
} }

View file

@ -7,9 +7,6 @@ class CardItem;
class CardList : public QList<CardItem *> class CardList : public QList<CardItem *>
{ {
private:
class compareFunctor;
protected: protected:
bool contentsKnown; bool contentsKnown;