From 1a1ecd8ce1bad13fd566a1eba4ecf865912e8709 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 10 May 2020 19:41:29 +0100 Subject: [PATCH] Rearrange some code to keep from hitting a wxGrid d'tor bug. Fixes https://gitlab.com/kicad/code/kicad/issues/4384 --- .../dialog_edit_component_in_schematic.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 9fea5b5d20..e11d61f20c 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -481,30 +481,33 @@ bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::TransferDataFromWindow() if( entry && entry->IsPower() ) 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(); + 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 ); + 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 ); - - // grid needs to be notified about the size change, - // as it still accesses the data on close (size event) - wxGridTableMessage gridMsg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, i, 1 ); - m_grid->ProcessTableMessage( gridMsg ); - i--; - break; + if( field.GetName() == fieldname.m_Name && field.GetText().IsEmpty() ) + { + emptyTemplateField = true; + break; + } } } - } - m_cmp->SetFields( *m_fields ); + if( !emptyTemplateField ) + fields.push_back( field ); + } // 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