Fix deleting wxPGProperty from wxPropertyGridPageState in alphabetical mode

Categories of properties can be nested so we need to search on all category
levels for the the category wxPGProperty belongs to.
And wxPGProperty removed from the alphabetical list can be a subproperty
of another property so it's parent doesn't have to be the root of the list
and we don't have to check this with assertion.

Closed #19310.
This commit is contained in:
Artur Wieczorek
2021-11-07 22:35:22 +01:00
parent 5f0dc6cc0a
commit 789b39be81

View File

@@ -1836,6 +1836,36 @@ bool wxPropertyGridPageState::IsChildCategory(wxPGProperty* p,
return false;
}
namespace
{
static wxPGProperty* FindCategoryForProperty(wxPGProperty* cat, wxPGProperty* prop, int& foundAtIndex)
{
wxASSERT(cat->IsCategory() || cat->IsRoot());
int idx = cat->Index(prop);
if ( idx != wxNOT_FOUND )
{
foundAtIndex = idx;
return cat;
}
for ( unsigned int i = 0; i < cat->GetChildCount(); i++ )
{
wxPGProperty* p = cat->Item(i);
if ( p->IsCategory() )
{
wxPGProperty* foundCat = FindCategoryForProperty(p, prop, foundAtIndex);
if ( foundCat )
{
return foundCat;
}
}
}
return NULL;
}
};
void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete )
{
wxCHECK_RET(item != &m_regularArray && item != m_abcArray,
@@ -1945,38 +1975,25 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete )
// categorized mode - categorized array
parent->RemoveChild(indinparent);
item->m_parent->FixIndicesOfChildren();
parent->FixIndicesOfChildren();
}
else
{
// non-categorized mode - categorized array
// We need to find location of item.
wxPGProperty* cat_parent = &m_regularArray;
int cat_index = m_regularArray.GetChildCount();
for ( unsigned int i = 0; i < m_regularArray.GetChildCount(); i++ )
int cat_index;
wxPGProperty* cat_parent = FindCategoryForProperty(&m_regularArray, item, cat_index);
if ( cat_parent )
{
wxPGProperty* p = m_regularArray.Item(i);
if ( p == item ) { cat_index = i; break; }
if ( p->IsCategory() )
{
int subind = p->Index(item);
if ( subind != wxNOT_FOUND )
{
cat_parent = p;
cat_index = subind;
break;
}
}
cat_parent->RemoveChild(cat_index);
}
cat_parent->RemoveChild(cat_index);
// non-categorized mode - non-categorized array
if ( !item->IsCategory() )
{
wxASSERT( item->m_parent == m_abcArray );
item->m_parent->RemoveChild(indinparent);
item->m_parent->FixIndicesOfChildren(indinparent);
parent->RemoveChild(indinparent);
parent->FixIndicesOfChildren(indinparent);
}
}