Skip to content
Snippets Groups Projects
Commit d1751df1 authored by Sergei Litovchuk's avatar Sergei Litovchuk
Browse files

EXT-7610 FIXED Added sorting outfit tabs by name (case insensitive).

Reviewed by Neal Orman at https://codereview.productengine.com/secondlife/r/523/.

--HG--
branch : product-engine
parent 65f8d182
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,7 @@ LLAccordionCtrl::LLAccordionCtrl(const Params& params):LLPanel(params)
, mAutoScrolling( false )
, mAutoScrollRate( 0.f )
, mSelectedTab( NULL )
, mTabComparator( NULL )
, mNoVisibleTabsHelpText(NULL)
{
initNoTabsWidget(params.empty_accordion_text);
......@@ -799,6 +800,18 @@ void LLAccordionCtrl::reset ()
mScrollbar->setDocPos(0);
}
void LLAccordionCtrl::sort()
{
if (!mTabComparator)
{
llwarns << "No comparator specified for sorting accordion tabs." << llendl;
return;
}
std::sort(mAccordionTabs.begin(), mAccordionTabs.end(), LLComparatorAdaptor(*mTabComparator));
arrange();
}
void LLAccordionCtrl::setFilterSubString(const std::string& filter_string)
{
LLStringUtil::format_map_t args;
......
......@@ -57,6 +57,19 @@ class LLAccordionCtrl: public LLPanel
public:
/**
* Abstract comparator for accordion tabs.
*/
class LLTabComparator
{
public:
LLTabComparator() {};
virtual ~LLTabComparator() {};
/** Returns true if tab1 < tab2, false otherwise */
virtual bool compare(const LLAccordionCtrlTab* tab1, const LLAccordionCtrlTab* tab2) const = 0;
};
struct Params
: public LLInitParam::Block<Params, LLPanel::Params>
{
......@@ -108,6 +121,9 @@ class LLAccordionCtrl: public LLPanel
void reset ();
void setComparator(const LLTabComparator* comp) { mTabComparator = comp; }
void sort();
/**
* Sets filter substring as a search_term for help text when there are no any visible tabs.
*/
......@@ -134,6 +150,21 @@ class LLAccordionCtrl: public LLPanel
BOOL autoScroll (S32 x, S32 y);
/**
* An adaptor for LLTabComparator
*/
struct LLComparatorAdaptor
{
LLComparatorAdaptor(const LLTabComparator& comparator) : mComparator(comparator) {};
bool operator()(const LLAccordionCtrlTab* tab1, const LLAccordionCtrlTab* tab2)
{
return mComparator.compare(tab1, tab2);
}
const LLTabComparator& mComparator;
};
private:
LLRect mInnerRect;
LLScrollbar* mScrollbar;
......@@ -141,9 +172,11 @@ class LLAccordionCtrl: public LLPanel
bool mFitParent;
bool mAutoScrolling;
F32 mAutoScrollRate;
LLAccordionCtrlTab* mSelectedTab;
LLTextBox* mNoVisibleTabsHelpText;
std::string mNoVisibleTabsOrigString;
LLAccordionCtrlTab* mSelectedTab;
const LLTabComparator* mTabComparator;
};
......
......@@ -473,7 +473,7 @@ void LLAccordionCtrlTab::setAccordionView(LLView* panel)
addChild(panel,0);
}
std::string LLAccordionCtrlTab::getTitle()
std::string LLAccordionCtrlTab::getTitle() const
{
LLAccordionCtrlTabHeader* header = findChild<LLAccordionCtrlTabHeader>(DD_HEADER_NAME);
if (header)
......
......@@ -115,7 +115,7 @@ class LLAccordionCtrlTab : public LLUICtrl
void setAccordionView(LLView* panel);
LLView* getAccordionView() { return mContainerPanel; };
std::string getTitle();
std::string getTitle() const;
// Set text and highlight substring in LLAccordionCtrlTabHeader
void setTitle(const std::string& title, const std::string& hl = LLStringUtil::null);
......
......@@ -53,6 +53,20 @@
static bool is_tab_header_clicked(LLAccordionCtrlTab* tab, S32 y);
static const LLOutfitTabNameComparator OUTFIT_TAB_NAME_COMPARATOR;
/*virtual*/
bool LLOutfitTabNameComparator::compare(const LLAccordionCtrlTab* tab1, const LLAccordionCtrlTab* tab2) const
{
std::string name1 = tab1->getTitle();
std::string name2 = tab2->getTitle();
LLStringUtil::toUpper(name1);
LLStringUtil::toUpper(name2);
return name1 < name2;
}
//////////////////////////////////////////////////////////////////////////
class OutfitContextMenu : public LLListContextMenu
......@@ -158,6 +172,7 @@ LLOutfitsList::~LLOutfitsList()
BOOL LLOutfitsList::postBuild()
{
mAccordion = getChild<LLAccordionCtrl>("outfits_accordion");
mAccordion->setComparator(&OUTFIT_TAB_NAME_COMPARATOR);
return TRUE;
}
......@@ -328,7 +343,7 @@ void LLOutfitsList::refreshList(const LLUUID& category_id)
updateOutfitTab(*items_iter);
}
mAccordion->arrange();
mAccordion->sort();
}
void LLOutfitsList::onSelectionChange(LLUICtrl* ctrl)
......
......@@ -32,17 +32,33 @@
#ifndef LL_LLOUTFITSLIST_H
#define LL_LLOUTFITSLIST_H
#include "llaccordionctrl.h"
#include "llpanel.h"
// newview
#include "llinventorymodel.h"
#include "llinventoryobserver.h"
class LLAccordionCtrl;
class LLAccordionCtrlTab;
class LLWearableItemsList;
class LLListContextMenu;
/**
* @class LLOutfitTabNameComparator
*
* Comparator of outfit tabs.
*/
class LLOutfitTabNameComparator : public LLAccordionCtrl::LLTabComparator
{
LOG_CLASS(LLOutfitTabNameComparator);
public:
LLOutfitTabNameComparator() {};
virtual ~LLOutfitTabNameComparator() {};
/*virtual*/ bool compare(const LLAccordionCtrlTab* tab1, const LLAccordionCtrlTab* tab2) const;
};
/**
* @class LLOutfitsList
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment