Implement new wxPGProperty::HasAnyChild() method

There are many checks in the code whether wxPGProperty has any child.
Doing so by checking if GetChildCount() is greater than zero doesn't
seem to express intent simply and clearly. With dedicated method this
could be done simpler and hopefully in a more optimal way.
This commit is contained in:
Artur Wieczorek 2022-12-03 17:10:55 +02:00
parent d0d43165c9
commit 1d85e22543
12 changed files with 69 additions and 56 deletions

View file

@ -221,7 +221,7 @@ wxVectorProperty::wxVectorProperty( const wxString& label,
void wxVectorProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
if ( !HasAnyChild() ) return;
const wxVector3f& vector = wxVector3fRefFromVariant(m_value);
Item(0)->SetValue( vector.x );
Item(1)->SetValue( vector.y );
@ -270,7 +270,7 @@ wxTriangleProperty::wxTriangleProperty( const wxString& label,
void wxTriangleProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
if ( !HasAnyChild() ) return;
const wxTriangle& triangle = wxTriangleRefFromVariant(m_value);
Item(0)->SetValue( WXVARIANT(triangle.a) );
Item(1)->SetValue( WXVARIANT(triangle.b) );
@ -2192,7 +2192,7 @@ void FormMain::OnInsertPropClick( wxCommandEvent& WXUNUSED(event) )
{
wxString propLabel;
if ( !m_pPropGridManager->GetGrid()->GetRoot()->GetChildCount() )
if ( !m_pPropGridManager->GetGrid()->GetRoot()->HasAnyChild() )
{
wxMessageBox("No items to relate - first add some with Append.");
return;
@ -2258,7 +2258,7 @@ void FormMain::OnInsertCatClick( wxCommandEvent& WXUNUSED(event) )
{
wxString propLabel;
if ( !m_pPropGridManager->GetGrid()->GetRoot()->GetChildCount() )
if ( !m_pPropGridManager->GetGrid()->GetRoot()->HasAnyChild() )
{
wxMessageBox("No items to relate - first add some with Append.");
return;
@ -2303,7 +2303,7 @@ void FormMain::OnDelPropRClick( wxCommandEvent& WXUNUSED(event) )
for (;;)
{
if ( p->GetChildCount() == 0 )
if ( !p->HasAnyChild() )
break;
unsigned int n = static_cast<unsigned int>(rand()) % p->GetChildCount();

View file

@ -203,7 +203,7 @@ wxSizeProperty::wxSizeProperty( const wxString& label, const wxString& name,
void wxSizeProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
if ( !HasAnyChild() ) return;
const wxSize& size = wxSizeRefFromVariant(m_value);
Item(0)->SetValue( (long)size.x );
Item(1)->SetValue( (long)size.y );
@ -241,7 +241,7 @@ wxPointProperty::wxPointProperty( const wxString& label, const wxString& name,
void wxPointProperty::RefreshChildren()
{
if ( !GetChildCount() ) return;
if ( !HasAnyChild() ) return;
const wxPoint& point = wxPointRefFromVariant(m_value);
Item(0)->SetValue( (long)point.x );
Item(1)->SetValue( (long)point.y );

View file

@ -1357,7 +1357,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
if ( pgman->GetPageCount() )
RT_FAILURE();
if ( pgman->GetGrid()->GetRoot()->GetChildCount() )
if ( pgman->GetGrid()->GetRoot()->HasAnyChild() )
RT_FAILURE();
// Recreate the original grid
@ -1368,7 +1368,7 @@ bool FormMain::RunTests( bool fullTest, bool interactive )
pgman->SelectProperty("Label");
pgman->GetGrid()->Clear();
if ( pgman->GetGrid()->GetRoot()->GetChildCount() )
if ( pgman->GetGrid()->GetRoot()->HasAnyChild() )
RT_FAILURE();
// Recreate the original grid