From 6fe82983ed76ad85ea5d57485860aa500a28d199 Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 8 Jan 2009 18:51:12 +0000 Subject: [PATCH] sort card list by identifying column if value in selected column is equal git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1308 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/control/card_list.cpp | 18 ++++++++++++++++-- src/gui/control/card_list.hpp | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index fe0ffe96..101d5892 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -199,12 +199,17 @@ bool CardListBase::compareItems(void* a, void* b) const { FieldP sort_field = column_fields[sort_by_column]; ValueP va = reinterpret_cast(a)->data[sort_field]; ValueP vb = reinterpret_cast(b)->data[sort_field]; - if (!va || !vb) return va < vb; // got to do something, compare pointers + assert(va && vb); // compare sort keys int cmp = smart_compare( va->getSortKey(), vb->getSortKey() ); if (cmp != 0) return cmp < 0; // equal values, compare alternate sort key - // TODO: sort by a second column + if (alternate_sort_field) { + ValueP va = reinterpret_cast(a)->data[alternate_sort_field]; + ValueP vb = reinterpret_cast(b)->data[alternate_sort_field]; + int cmp = smart_compare( va->getSortKey(), vb->getSortKey() ); + if (cmp != 0) return cmp < 0; + } return false; } @@ -250,6 +255,15 @@ void CardListBase::rebuild() { } ++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(); } diff --git a/src/gui/control/card_list.hpp b/src/gui/control/card_list.hpp index b71ee048..69291687 100644 --- a/src/gui/control/card_list.hpp +++ b/src/gui/control/card_list.hpp @@ -125,7 +125,8 @@ class CardListBase : public ItemList, public SetView { private: // display stuff vector 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 public: