diff --git a/AUTHORS.txt b/AUTHORS.txt index 8fbdfee6ac..3ac31a167b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -50,6 +50,7 @@ Ian McInerney Thomas Pointhuber Roberto Fernandez Bautista MikoĊ‚aj Wielgus +Mike Williams See git repo on GitLab for contributors at https://gitlab.com/kicad/code/kicad/-/graphs/master diff --git a/eeschema/dialogs/dialog_symbol_fields_table.cpp b/eeschema/dialogs/dialog_symbol_fields_table.cpp index 4e10276cb6..e7de951bb7 100644 --- a/eeschema/dialogs/dialog_symbol_fields_table.cpp +++ b/eeschema/dialogs/dialog_symbol_fields_table.cpp @@ -511,6 +511,9 @@ void DIALOG_SYMBOL_FIELDS_TABLE::AddField( const wxString& aFieldName, const wxS fieldsCtrlRow.push_back( wxVariant( aFieldName ) ); m_fieldsCtrl->AppendItem( fieldsCtrlRow ); + + wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_APPENDED, 1 ); + m_grid->ProcessTableMessage( msg ); } @@ -594,9 +597,6 @@ void DIALOG_SYMBOL_FIELDS_TABLE::OnAddField( wxCommandEvent& event ) AddField( fieldName, fieldName, true, false, true ); - wxGridTableMessage msg( m_dataModel, wxGRIDTABLE_NOTIFY_COLS_APPENDED, 1 ); - m_grid->ProcessTableMessage( msg ); - wxGridCellAttr* attr = new wxGridCellAttr; m_grid->SetColAttr( m_dataModel->GetColsCount() - 1, attr ); m_grid->SetColFormatCustom( m_dataModel->GetColsCount() - 1, wxGRID_VALUE_STRING ); @@ -1298,11 +1298,11 @@ void DIALOG_SYMBOL_FIELDS_TABLE::syncBomPresetSelection() // Only compare shown or grouped fields std::vector A, B; - for( auto field : preset.fieldsOrdered ) + for( const BOM_FIELD& field : preset.fieldsOrdered ) if( field.show || field.groupBy ) A.emplace_back( field ); - for( auto field : current.fieldsOrdered ) + for( const BOM_FIELD& field : current.fieldsOrdered ) if( field.show || field.groupBy ) B.emplace_back( field ); diff --git a/eeschema/fields_data_model.cpp b/eeschema/fields_data_model.cpp index 459462d9b0..1db140b79a 100644 --- a/eeschema/fields_data_model.cpp +++ b/eeschema/fields_data_model.cpp @@ -79,7 +79,7 @@ const std::vector FIELDS_EDITOR_GRID_DATA_MODEL::GetFieldsOrdered() { std::vector fields; - for( auto col : m_cols ) + for( const DATA_MODEL_COL& col : m_cols ) fields.push_back( { col.m_fieldName, col.m_label, col.m_show, col.m_group } ); return fields; @@ -303,6 +303,9 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::groupMatch( const SCH_REFERENCE& lhRef, int refCol = GetFieldNameCol( TEMPLATE_FIELDNAME::GetDefaultFieldName( REFERENCE_FIELD ) ); bool matchFound = false; + if( refCol == -1 ) + return false; + // First check the reference column. This can be done directly out of the // SCH_REFERENCEs as the references can't be edited in the grid. if( m_cols[refCol].m_group ) @@ -609,7 +612,10 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyBomPreset( const BOM_PRESET& aPreset ) // Add any missing fields, if the user doesn't add any data // they won't be saved to the symbols anywa if( col == -1 ) + { AddColumn( field.name, field.label, true ); + col = GetFieldNameCol( field.name ); + } else SetColLabelValue( col, field.label ); @@ -660,18 +666,19 @@ wxString FIELDS_EDITOR_GRID_DATA_MODEL::Export( const BOM_FMT_PRESET& settings ) if( m_cols.empty() ) return out; - size_t last_col = m_cols.size() - 1; + int last_col = -1; // Find the location for the line terminator - for( size_t col = m_cols.size() - 1; col >= 0; --col ) + for( size_t col = 0; col < m_cols.size(); col++ ) { if( m_cols[col].m_show ) - { - last_col = col; - break; - } + last_col = (int) col; } + // No shown columns + if( last_col == -1 ) + return out; + auto formatField = [&]( wxString field, bool last ) -> wxString { if( !settings.keepLineBreaks ) @@ -699,7 +706,7 @@ wxString FIELDS_EDITOR_GRID_DATA_MODEL::Export( const BOM_FMT_PRESET& settings ) if( !m_cols[col].m_show ) continue; - out.Append( formatField( m_cols[col].m_label, col == last_col ) ); + out.Append( formatField( m_cols[col].m_label, col == (size_t) last_col ) ); } // Data rows @@ -717,7 +724,7 @@ wxString FIELDS_EDITOR_GRID_DATA_MODEL::Export( const BOM_FMT_PRESET& settings ) // Get the unanottated version of the field, e.g. no "> " or "v " by out.Append( formatField( GetExportValue( (int) row, (int) col, settings.refDelimiter, settings.refRangeDelimiter ), - col == last_col ) ); + col == (size_t) last_col ) ); } }