Simplify sorting children of wxPGProperty

This commit is contained in:
Artur Wieczorek 2023-01-22 20:13:48 +02:00
parent 4c463c416d
commit b727e47df7
3 changed files with 13 additions and 27 deletions

View file

@ -1938,7 +1938,11 @@ protected:
void RemoveChild(unsigned int index);
// Sorts children using specified comparison function.
#if WXWIN_COMPATIBILITY_3_2
wxDEPRECATED_MSG("Don't use SortChildren function with argument of 'int (*)(wxPGProperty**, wxPGProperty**)' type. Use 'bool (*)(wxPGProperty*, wxPGProperty*)' argument instead")
void SortChildren(int (*fCmp)(wxPGProperty**, wxPGProperty**));
#endif // WXWIN_COMPATIBILITY_3_2
void SortChildren(bool (*fCmp)(wxPGProperty*, wxPGProperty*));
void DoEnable( bool enable );

View file

@ -2393,11 +2393,18 @@ void wxPGProperty::RemoveChild(unsigned int index)
m_children.erase(m_children.begin()+index);
}
#if WXWIN_COMPATIBILITY_3_2
void wxPGProperty::SortChildren(int (*fCmp)(wxPGProperty**, wxPGProperty**))
{
wxArray_SortFunction<wxPGProperty*> sf(fCmp);
std::sort(m_children.begin(), m_children.end(), sf);
}
#endif // WXWIN_COMPATIBILITY_3_2
void wxPGProperty::SortChildren(bool (*fCmp)(wxPGProperty*, wxPGProperty*))
{
std::sort(m_children.begin(), m_children.end(), fCmp);
}
void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
{

View file

@ -587,42 +587,17 @@ bool wxPropertyGridPageState::EnableCategories( bool enable )
}
// -----------------------------------------------------------------------
static int wxPG_SortFunc_ByFunction(wxPGProperty **pp1, wxPGProperty **pp2)
{
wxPGProperty *p1 = *pp1;
wxPGProperty *p2 = *pp2;
wxPropertyGrid* pg = p1->GetGrid();
wxPGSortCallback sortFunction = pg->GetSortFunction();
return sortFunction(pg, p1, p2);
}
static int wxPG_SortFunc_ByLabel(wxPGProperty **pp1, wxPGProperty **pp2)
{
wxPGProperty *p1 = *pp1;
wxPGProperty *p2 = *pp2;
return p1->GetLabel().CmpNoCase( p2->GetLabel() );
}
#if 0
//
// For wxVector w/ wxUSE_STL=1, you would use code like this instead:
//
#include <algorithm>
static bool wxPG_SortFunc_ByFunction(wxPGProperty *p1, wxPGProperty *p2)
static bool wxPG_SortFunc_ByFunction(wxPGProperty* p1, wxPGProperty* p2)
{
wxPropertyGrid* pg = p1->GetGrid();
wxPGSortCallback sortFunction = pg->GetSortFunction();
return sortFunction(pg, p1, p2) < 0;
}
static bool wxPG_SortFunc_ByLabel(wxPGProperty *p1, wxPGProperty *p2)
static bool wxPG_SortFunc_ByLabel(wxPGProperty* p1, wxPGProperty* p2)
{
return p1->GetLabel().CmpNoCase( p2->GetLabel() ) < 0;
}
#endif
void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p,
int flags )