From 11278201649527ae16c5870f0585e9483f432c44 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 31 Jan 2015 21:49:01 +0000 Subject: [PATCH] Encapsulate wxPGProperty::m_children member variable. Implement RemoveChild and SortChildren methods to perform operations on m_children member variable. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78428 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/property.h | 6 ++++++ src/propgrid/property.cpp | 15 +++++++++++++++ src/propgrid/propgridpagestate.cpp | 24 +++++------------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index d2657810e1..88558662bc 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -2427,6 +2427,12 @@ protected: // Removes child property with given pointer. Does not delete it. void RemoveChild( wxPGProperty* p ); + // Removes child property at given index. Does not delete it. + void RemoveChild(unsigned int index); + + // Sorts children using specified comparison function. + void SortChildren(int (*fCmp)(wxPGProperty**, wxPGProperty**)); + void DoEnable( bool enable ); void DoPreAddChild( int index, wxPGProperty* prop ); diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 62a6cae201..74f2caf8de 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -2359,6 +2359,21 @@ void wxPGProperty::RemoveChild( wxPGProperty* p ) } } +void wxPGProperty::RemoveChild(unsigned int index) +{ + m_children.erase(m_children.begin()+index); +} + +void wxPGProperty::SortChildren(int (*fCmp)(wxPGProperty**, wxPGProperty**)) +{ + m_children.Sort(fCmp); + +#if 0 + // For wxVector w/ wxUSE_STL=1, you would use code like this instead: + std::sort(m_children.begin(), m_children.end(), fCmp); +#endif +} + void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const { wxASSERT( GetChildCount() ); diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 3f002e9323..a47af453fd 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -711,21 +711,9 @@ void wxPropertyGridPageState::DoSortChildren( wxPGProperty* p, return; if ( GetGrid()->GetSortFunction() ) - p->m_children.Sort( wxPG_SortFunc_ByFunction ); + p->SortChildren(wxPG_SortFunc_ByFunction); else - p->m_children.Sort( wxPG_SortFunc_ByLabel ); - -#if 0 - // - // For wxVector w/ wxUSE_STL=1, you would use code like this instead: - // - if ( GetGrid()->GetSortFunction() ) - std::sort(p->m_children.begin(), p->m_children.end(), - wxPG_SortFunc_ByFunction); - else - std::sort(p->m_children.begin(), p->m_children.end(), - wxPG_SortFunc_ByLabel); -#endif + p->SortChildren(wxPG_SortFunc_ByLabel); // Fix indices p->FixIndicesOfChildren(); @@ -2075,8 +2063,7 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) } // categorized mode - categorized array - wxArrayPGProperty& parentsChildren = parent->m_children; - parentsChildren.erase( parentsChildren.begin() + indinparent ); + parent->RemoveChild(indinparent); item->m_parent->FixIndicesOfChildren(); } else @@ -2102,14 +2089,13 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) } } } - cat_parent->m_children.erase(cat_parent->m_children.begin()+cat_index); + cat_parent->RemoveChild(cat_index); // non-categorized mode - non-categorized array if ( !item->IsCategory() ) { wxASSERT( item->m_parent == m_abcArray ); - wxArrayPGProperty& parentsChildren = item->m_parent->m_children; - parentsChildren.erase(parentsChildren.begin() + indinparent); + item->m_parent->RemoveChild(indinparent); item->m_parent->FixIndicesOfChildren(indinparent); } }