Rearrange some code to keep from hitting a wxGrid d'tor bug.

Fixes https://gitlab.com/kicad/code/kicad/issues/4384
This commit is contained in:
Jeff Young 2020-05-10 19:41:29 +01:00
parent df5b093fda
commit 1a1ecd8ce1
1 changed files with 17 additions and 14 deletions

View File

@ -481,30 +481,33 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow()
if( entry && entry->IsPower() ) if( entry && entry->IsPower() )
m_fields->at( VALUE ).SetText( m_cmp->GetLibId().GetLibItemName() ); m_fields->at( VALUE ).SetText( m_cmp->GetLibId().GetLibItemName() );
// Remove any TEMPLATE_FIELDNAMES which were not set (given values). // Push all fields to the component -except- for those which are TEMPLATE_FIELDNAMES
// with empty values.
TEMPLATE_FIELDNAMES templateFieldnames = GetParent()->GetTemplateFieldNames(); TEMPLATE_FIELDNAMES templateFieldnames = GetParent()->GetTemplateFieldNames();
SCH_FIELDS& fields = m_cmp->GetFields();
for( size_t i = MANDATORY_FIELDS; i < m_fields->size(); ++i ) fields.clear();
for( size_t i = 0; i < m_fields->size(); ++i )
{ {
SCH_FIELD& field = m_fields->at( i ); SCH_FIELD& field = m_fields->at( i );
bool emptyTemplateField = false;
for( const auto& fieldname : templateFieldnames ) if( i >= MANDATORY_FIELDS )
{ {
if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() ) for( const auto& fieldname : templateFieldnames )
{ {
m_fields->erase( m_fields->begin() + i ); if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() )
{
// grid needs to be notified about the size change, emptyTemplateField = true;
// as it still accesses the data on close (size event) break;
wxGridTableMessage gridMsg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, i, 1 ); }
m_grid->ProcessTableMessage( gridMsg );
i--;
break;
} }
} }
}
m_cmp->SetFields( *m_fields ); if( !emptyTemplateField )
fields.push_back( field );
}
// Reference has a specific initialization, depending on the current active sheet // Reference has a specific initialization, depending on the current active sheet
// because for a given component, in a complex hierarchy, there are more than one // because for a given component, in a complex hierarchy, there are more than one