DbLib: Support showing field names

This commit is contained in:
Jon Evans 2022-09-04 13:00:28 -04:00
parent 04f65c6c5c
commit a5246a6df7
4 changed files with 27 additions and 6 deletions

View File

@ -81,13 +81,26 @@ DATABASE_LIB_SETTINGS::DATABASE_LIB_SETTINGS( const std::string& aFilename ) :
if( fieldJson.empty() || !fieldJson.is_object() ) if( fieldJson.empty() || !fieldJson.is_object() )
continue; continue;
std::string column = fieldJson.contains( "column" )
? fieldJson["column"].get<std::string>() : "";
std::string name = fieldJson.contains( "name" )
? fieldJson["name"].get<std::string>() : "";
bool visible_on_add = !fieldJson.contains( "visible_on_add" )
|| fieldJson["visible_on_add"].get<bool>();
bool visible_in_chooser =
!fieldJson.contains( "visible_in_chooser" )
|| fieldJson["visible_in_chooser"].get<bool>();
bool show_name = fieldJson.contains( "show_name" )
&& fieldJson["show_name"].get<bool>();
table.fields.emplace_back( table.fields.emplace_back(
DATABASE_FIELD_MAPPING( DATABASE_FIELD_MAPPING(
{ {
fieldJson["column"].get<std::string>(), column, name, visible_on_add, visible_in_chooser, show_name
fieldJson["name"].get<std::string>(),
fieldJson["visible_on_add"].get<bool>(),
fieldJson["visible_in_chooser"].get<bool>()
} ) ); } ) );
} }
} }

View File

@ -328,6 +328,7 @@ LIB_SYMBOL* SCH_DATABASE_PLUGIN::loadSymbolFromRow( const wxString& aSymbolName,
LIB_FIELD& field = symbol->GetValueField(); LIB_FIELD& field = symbol->GetValueField();
field.SetText( value ); field.SetText( value );
field.SetVisible( mapping.visible_on_add ); field.SetVisible( mapping.visible_on_add );
field.SetNameShown( mapping.show_name );
continue; continue;
} }
else if( mapping.name == wxT( "Datasheet" ) ) else if( mapping.name == wxT( "Datasheet" ) )
@ -335,6 +336,7 @@ LIB_SYMBOL* SCH_DATABASE_PLUGIN::loadSymbolFromRow( const wxString& aSymbolName,
LIB_FIELD& field = symbol->GetDatasheetField(); LIB_FIELD& field = symbol->GetDatasheetField();
field.SetText( value ); field.SetText( value );
field.SetVisible( mapping.visible_on_add ); field.SetVisible( mapping.visible_on_add );
field.SetNameShown( mapping.show_name );
if( mapping.visible_on_add ) if( mapping.visible_on_add )
field.SetAutoAdded( true ); field.SetAutoAdded( true );
@ -347,6 +349,7 @@ LIB_SYMBOL* SCH_DATABASE_PLUGIN::loadSymbolFromRow( const wxString& aSymbolName,
field->SetText( value ); field->SetText( value );
field->SetVisible( mapping.visible_on_add ); field->SetVisible( mapping.visible_on_add );
field->SetAutoAdded( true ); field->SetAutoAdded( true );
field->SetNameShown( mapping.show_name );
symbol->AddField( field ); symbol->AddField( field );
} }

View File

@ -48,6 +48,7 @@ struct DATABASE_FIELD_MAPPING
std::string name; ///< KiCad field name std::string name; ///< KiCad field name
bool visible_on_add; ///< Whether to show the field when placing the symbol bool visible_on_add; ///< Whether to show the field when placing the symbol
bool visible_in_chooser; ///< Whether the column is shown by default in the chooser bool visible_in_chooser; ///< Whether the column is shown by default in the chooser
bool show_name; ///< Whether or not to show the field name as well as its value
}; };

View File

@ -25,13 +25,16 @@
"column": "Manufacturer", "column": "Manufacturer",
"name": "Manufacturer", "name": "Manufacturer",
"visible_on_add": false, "visible_on_add": false,
"visible_in_chooser": false "visible_in_chooser": false,
"show_name": true
}, },
{ {
"column": "MPN", "column": "MPN",
"name": "MPN", "name": "MPN",
"visible_on_add": false, "visible_on_add": false,
"visible_in_chooser": true "visible_in_chooser": true
,
"show_name": true
}, },
{ {
"column": "Value", "column": "Value",
@ -55,7 +58,8 @@
"column": "Power Rating", "column": "Power Rating",
"name": "Power Rating", "name": "Power Rating",
"visible_on_add": true, "visible_on_add": true,
"visible_in_chooser": false "visible_in_chooser": false,
"show_name": true
}, },
{ {
"column": "Description", "column": "Description",