Don't have decklist sort behavior rely on column order

This commit is contained in:
Daenyth 2014-06-22 08:36:35 -04:00
parent e99c1bbe6d
commit 68c0932a2f
3 changed files with 26 additions and 13 deletions

View file

@ -330,7 +330,18 @@ void DeckListModel::sort(int column, Qt::SortOrder order)
lastKnownOrder = order;
emit layoutAboutToBeChanged();
root->setSortMethod(column);
DeckSortMethod sortMethod;
switch(column) {
case 0:
sortMethod = ByNumber;
break;
case 1:
sortMethod = ByName;
break;
case 2:
sortMethod = ByPrice;
}
root->setSortMethod(sortMethod);
sortHelper(root, order);
emit layoutChanged();
}

View file

@ -104,7 +104,7 @@ QString InnerDecklistNode::visibleNameFromName(const QString &_name)
return _name;
}
void InnerDecklistNode::setSortMethod(int method)
void InnerDecklistNode::setSortMethod(DeckSortMethod method)
{
sortMethod = method;
for (int i = 0; i < size(); i++)
@ -218,11 +218,11 @@ bool InnerDecklistNode::comparePrice(AbstractDecklistNode *other) const
bool AbstractDecklistCardNode::compare(AbstractDecklistNode *other) const
{
switch (sortMethod) {
case 0:
case ByNumber:
return compareNumber(other);
case 1:
case ByName:
return compareName(other);
case 2:
case ByPrice:
return compareTotalPrice(other);
}
}

View file

@ -35,14 +35,16 @@ public:
void setMoveList(const QList<MoveCard_ToZone> &_moveList);
};
enum DeckSortMethod { ByNumber, ByName, ByPrice };
class AbstractDecklistNode {
protected:
InnerDecklistNode *parent;
int sortMethod;
DeckSortMethod sortMethod;
public:
AbstractDecklistNode(InnerDecklistNode *_parent = 0);
virtual ~AbstractDecklistNode() { }
virtual void setSortMethod(int method) { sortMethod = method; }
virtual void setSortMethod(DeckSortMethod method) { sortMethod = method; }
virtual QString getName() const = 0;
InnerDecklistNode *getParent() const { return parent; }
int depth() const;
@ -61,7 +63,7 @@ public:
InnerDecklistNode(const QString &_name = QString(), InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent), name(_name) { }
InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent = 0);
virtual ~InnerDecklistNode();
void setSortMethod(int method);
void setSortMethod(DeckSortMethod method);
QString getName() const { return name; }
void setName(const QString &_name) { name = _name; }
static QString visibleNameFromName(const QString &_name);