From 2b4c9469f180093bd53b1c11be74e2716f57ad58 Mon Sep 17 00:00:00 2001 From: Igor Borovkov Date: Thu, 13 May 2010 17:20:29 +0300 Subject: EXT-7254 FIXED added a comparator for wearable items (panel outfit edit) added a flat list view comparator for names of wearable list items Reviewed by Vadim Savchuk at https://codereview.productengine.com/secondlife/r/384/ --HG-- branch : product-engine --- indra/newview/llcofwearables.cpp | 25 ++++++++++++++++--- indra/newview/llcofwearables.h | 47 ++++++++++++++++++++++++++++++++++++ indra/newview/llinventoryitemslist.h | 4 +++ 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/indra/newview/llcofwearables.cpp b/indra/newview/llcofwearables.cpp index 498aeec682..8d4430a9ea 100644 --- a/indra/newview/llcofwearables.cpp +++ b/indra/newview/llcofwearables.cpp @@ -46,6 +46,20 @@ static LLRegisterPanelClassWrapper t_cof_wearables("cof_wearable const LLSD REARRANGE = LLSD().with("rearrange", LLSD()); +static const LLWearableItemNameComparator WEARABLE_NAME_COMPARATOR; + + +bool LLWearableItemNameComparator::doCompare(const LLPanelWearableListItem* wearable_item1, const LLPanelWearableListItem* wearable_item2) const +{ + std::string name1 = wearable_item1->getItemName(); + std::string name2 = wearable_item2->getItemName(); + + LLStringUtil::toUpper(name1); + LLStringUtil::toUpper(name2); + + return name1 < name2; +} + LLCOFWearables::LLCOFWearables() : LLPanel(), mAttachments(NULL), @@ -73,6 +87,10 @@ BOOL LLCOFWearables::postBuild() mClothing->setCommitOnSelectionChange(true); mBodyParts->setCommitOnSelectionChange(true); + //clothing is sorted according to its position relatively to the body + mAttachments->setComparator(&WEARABLE_NAME_COMPARATOR); + mBodyParts->setComparator(&WEARABLE_NAME_COMPARATOR); + return LLPanel::postBuild(); } @@ -164,16 +182,15 @@ void LLCOFWearables::populateAttachmentsAndBodypartsLists(const LLInventoryModel if (mAttachments->size()) { - mAttachments->sort(); //*TODO by Name + mAttachments->sort(); mAttachments->notify(REARRANGE); //notifying the parent about the list's size change (cause items were added with rearrange=false) } if (mBodyParts->size()) { - mBodyParts->sort(); //*TODO by name + mBodyParts->sort(); + mBodyParts->notify(REARRANGE); } - - mBodyParts->notify(REARRANGE); } //create a clothing list item, update verbs and show/hide line separator diff --git a/indra/newview/llcofwearables.h b/indra/newview/llcofwearables.h index 32acba5a3e..612bb103d2 100644 --- a/indra/newview/llcofwearables.h +++ b/indra/newview/llcofwearables.h @@ -40,6 +40,53 @@ class LLFlatListView; + +/** Abstract comparator of wearable list items */ +class LLWearableListItemComparator : public LLFlatListView::ItemComparator +{ + LOG_CLASS(LLWearableListItemComparator); + +public: + LLWearableListItemComparator() {}; + virtual ~LLWearableListItemComparator() {}; + + virtual bool compare(const LLPanel* item1, const LLPanel* item2) const + { + const LLPanelWearableListItem* wearable_item1 = dynamic_cast(item1); + const LLPanelWearableListItem* wearable_item2 = dynamic_cast(item2); + + if (!wearable_item1 || !wearable_item2) + { + llwarning("item1 and item2 cannot be null", 0); + return true; + } + + return doCompare(wearable_item1, wearable_item2); + } + +protected: + + /** + * Returns true if wearable_item1 < wearable_item2, false otherwise + * Implement this method in your particular comparator. + */ + virtual bool doCompare(const LLPanelWearableListItem* wearable_item1, const LLPanelWearableListItem* wearable_item2) const = 0; +}; + + +class LLWearableItemNameComparator : public LLWearableListItemComparator +{ + LOG_CLASS(LLWearableItemNameComparator); + +public: + LLWearableItemNameComparator() {}; + virtual ~LLWearableItemNameComparator() {}; + +protected: + virtual bool doCompare(const LLPanelWearableListItem* wearable_item1, const LLPanelWearableListItem* wearable_item2) const; +}; + + /** * Adaptor between LLAccordionCtrlTab and LLFlatListView to facilitate communication between them * (notify, notifyParent) regarding size changes of a list and selection changes across accordion tabs. diff --git a/indra/newview/llinventoryitemslist.h b/indra/newview/llinventoryitemslist.h index bc04eb6f5b..6e74330df2 100644 --- a/indra/newview/llinventoryitemslist.h +++ b/indra/newview/llinventoryitemslist.h @@ -42,6 +42,7 @@ // newview #include "llflatlistview.h" +#include "llviewerinventory.h" class LLIconCtrl; class LLTextBox; @@ -120,6 +121,9 @@ public: /* Removes item highlight */ /*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask); + /** Get the name of a corresponding inventory item */ + const std::string& getItemName() const { return mItem->getName(); } + virtual ~LLPanelInventoryListItemBase(){} protected: -- cgit v1.2.3