Commit 41b7ae72 authored by twanvl's avatar twanvl

sort card list by identifying column if value in selected column is equal

parent 9a9b6e82
...@@ -199,12 +199,17 @@ bool CardListBase::compareItems(void* a, void* b) const { ...@@ -199,12 +199,17 @@ bool CardListBase::compareItems(void* a, void* b) const {
FieldP sort_field = column_fields[sort_by_column]; FieldP sort_field = column_fields[sort_by_column];
ValueP va = reinterpret_cast<Card*>(a)->data[sort_field]; ValueP va = reinterpret_cast<Card*>(a)->data[sort_field];
ValueP vb = reinterpret_cast<Card*>(b)->data[sort_field]; ValueP vb = reinterpret_cast<Card*>(b)->data[sort_field];
if (!va || !vb) return va < vb; // got to do something, compare pointers assert(va && vb);
// compare sort keys // compare sort keys
int cmp = smart_compare( va->getSortKey(), vb->getSortKey() ); int cmp = smart_compare( va->getSortKey(), vb->getSortKey() );
if (cmp != 0) return cmp < 0; if (cmp != 0) return cmp < 0;
// equal values, compare alternate sort key // equal values, compare alternate sort key
// TODO: sort by a second column if (alternate_sort_field) {
ValueP va = reinterpret_cast<Card*>(a)->data[alternate_sort_field];
ValueP vb = reinterpret_cast<Card*>(b)->data[alternate_sort_field];
int cmp = smart_compare( va->getSortKey(), vb->getSortKey() );
if (cmp != 0) return cmp < 0;
}
return false; return false;
} }
...@@ -250,6 +255,15 @@ void CardListBase::rebuild() { ...@@ -250,6 +255,15 @@ void CardListBase::rebuild() {
} }
++i; ++i;
} }
// determine alternate sortImageFieldP ImageCardList::findImageField() {
alternate_sort_field = FieldP();
FOR_EACH(f, set->game->card_fields) {
if (f->identifying) {
alternate_sort_field = f;
break;
}
}
// refresh
refreshList(); refreshList();
} }
......
...@@ -125,6 +125,7 @@ class CardListBase : public ItemList, public SetView { ...@@ -125,6 +125,7 @@ class CardListBase : public ItemList, public SetView {
private: private:
// display stuff // display stuff
vector<FieldP> column_fields; ///< The field to use for each column (by column index) vector<FieldP> column_fields; ///< The field to use for each column (by column index)
FieldP alternate_sort_field; ///< Second field to sort by, if the column doesn't suffice
mutable wxListItemAttr item_attr; // for OnGetItemAttr mutable wxListItemAttr item_attr; // for OnGetItemAttr
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment