field editor: Save checkbox states
This refactors the symbol field editor's checkbox state-saving code to deal with multiple projects with disjoint field sets more consistently. For instance, imagine I have a two projects * Proj1 has fields A, B, C * Proj2 has fields A, B, D Under the old scheme, when I switch from one project to the other the state of fields C and D will be forgotten. With the new approach, however, they are retained. Not to mention, the implementation is considerably simpler. Fixes
This commit is contained in:
parent
de7791cc8b
commit
da61285a29
|
@ -38,7 +38,6 @@
|
|||
#include <sch_edit_frame.h>
|
||||
#include <sch_reference_list.h>
|
||||
#include <kiface_i.h>
|
||||
#include <wx/tokenzr.h>
|
||||
|
||||
#include "dialog_fields_editor_global.h"
|
||||
|
||||
|
@ -78,10 +77,6 @@ struct DATA_MODEL_ROW
|
|||
#endif
|
||||
|
||||
|
||||
#define SHOWNFIELD_TOKENS wxT( "FieldsEditorShownFieldTokensKey" )
|
||||
#define GROUPBY_TOKENS wxT( "FieldsEditorGroupByTokensKey" )
|
||||
|
||||
|
||||
// Indicator that multiple values exist in child rows
|
||||
#define ROW_MULT_ITEMS wxString( "< ... >" )
|
||||
|
||||
|
@ -631,27 +626,6 @@ DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL( SCH_EDIT_FRAME* parent
|
|||
|
||||
DIALOG_FIELDS_EDITOR_GLOBAL::~DIALOG_FIELDS_EDITOR_GLOBAL()
|
||||
{
|
||||
// Update the config values for the show and group-by checkboxes
|
||||
wxString showTokens, groupTokens;
|
||||
|
||||
for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
|
||||
{
|
||||
if( m_fieldsCtrl->GetToggleValue( i, 1 ) )
|
||||
{
|
||||
if( showTokens.length() > 0 ) showTokens << wxT( " " );
|
||||
showTokens << m_fieldsCtrl->GetTextValue( i, 0 );
|
||||
}
|
||||
|
||||
if( m_fieldsCtrl->GetToggleValue( i, 2 ) )
|
||||
{
|
||||
if( groupTokens.length() > 0 ) groupTokens << wxT( " " );
|
||||
groupTokens << m_fieldsCtrl->GetTextValue( i, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
m_config->Write( SHOWNFIELD_TOKENS, showTokens );
|
||||
m_config->Write( GROUPBY_TOKENS, groupTokens );
|
||||
|
||||
// Disconnect Events
|
||||
m_grid->Disconnect( wxEVT_GRID_COL_SORT, wxGridEventHandler( DIALOG_FIELDS_EDITOR_GLOBAL::OnColSort ), NULL, this );
|
||||
|
||||
|
@ -684,15 +658,18 @@ bool DIALOG_FIELDS_EDITOR_GLOBAL::TransferDataFromWindow()
|
|||
|
||||
|
||||
void DIALOG_FIELDS_EDITOR_GLOBAL::AddField( const wxString& aName,
|
||||
std::set<wxString>& show, std::set<wxString>& group )
|
||||
bool defaultShow, bool defaultSortBy )
|
||||
{
|
||||
m_dataModel->AddColumn( aName );
|
||||
|
||||
wxVector<wxVariant> fieldsCtrlRow;
|
||||
|
||||
m_config->Read("SymbolFieldEditor/Show/" + aName, &defaultShow);
|
||||
m_config->Read("SymbolFieldEditor/GroupBy/" + aName, &defaultSortBy);
|
||||
|
||||
fieldsCtrlRow.push_back( wxVariant( aName ) );
|
||||
fieldsCtrlRow.push_back( wxVariant( show.count( "*" ) > 0 || show.count( aName ) > 0 ) );
|
||||
fieldsCtrlRow.push_back( wxVariant( group.count( "*" ) > 0 || group.count( aName ) > 0 ) );
|
||||
fieldsCtrlRow.push_back( wxVariant( defaultShow ) );
|
||||
fieldsCtrlRow.push_back( wxVariant( defaultSortBy ) );
|
||||
|
||||
m_fieldsCtrl->AppendItem( fieldsCtrlRow );
|
||||
}
|
||||
|
@ -704,54 +681,26 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::AddField( const wxString& aName,
|
|||
*/
|
||||
void DIALOG_FIELDS_EDITOR_GLOBAL::LoadFieldNames()
|
||||
{
|
||||
// Fetch the config checkbox values
|
||||
std::set<wxString> fieldsToShow, fieldsToGroupBy;
|
||||
wxString serializedShowTokens, serializedGroupTokens;
|
||||
|
||||
m_config->Read( SHOWNFIELD_TOKENS, &serializedShowTokens, "*" );
|
||||
wxStringTokenizer showTokens( serializedShowTokens );
|
||||
|
||||
while( showTokens.HasMoreTokens() )
|
||||
fieldsToShow.insert( showTokens.GetNextToken() );
|
||||
|
||||
m_config->Read( GROUPBY_TOKENS, &serializedGroupTokens, wxEmptyString );
|
||||
|
||||
if( serializedGroupTokens.IsEmpty() )
|
||||
{
|
||||
fieldsToGroupBy.insert( _( "Reference" ) );
|
||||
fieldsToGroupBy.insert( _( "Value" ) );
|
||||
fieldsToGroupBy.insert( _( "Footprint" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
wxStringTokenizer groupTokens( serializedGroupTokens );
|
||||
|
||||
while( groupTokens.HasMoreTokens() )
|
||||
fieldsToGroupBy.insert( groupTokens.GetNextToken() );
|
||||
}
|
||||
|
||||
// Add the mandatory fields
|
||||
AddField( _( "Reference" ), fieldsToShow, fieldsToGroupBy );
|
||||
AddField( _( "Value" ), fieldsToShow, fieldsToGroupBy );
|
||||
AddField( _( "Footprint" ), fieldsToShow, fieldsToGroupBy );
|
||||
AddField( _( "Datasheet" ), fieldsToShow, fieldsToGroupBy );
|
||||
|
||||
// Add the user and default fields
|
||||
std::set<wxString> userAndDefaultFieldnames;
|
||||
std::set<wxString> userFieldNames;
|
||||
|
||||
for( unsigned i = 0; i < m_componentRefs.GetCount(); ++i )
|
||||
{
|
||||
SCH_COMPONENT* comp = m_componentRefs[ i ].GetComp();
|
||||
|
||||
for( int j = MANDATORY_FIELDS; j < comp->GetFieldCount(); ++j )
|
||||
userAndDefaultFieldnames.insert( comp->GetField( j )->GetName() );
|
||||
userFieldNames.insert( comp->GetField( j )->GetName() );
|
||||
}
|
||||
|
||||
for( TEMPLATE_FIELDNAME defaultField : m_parent->GetTemplateFieldNames() )
|
||||
userAndDefaultFieldnames.insert( defaultField.m_Name );
|
||||
AddField( _( "Reference" ), true, true );
|
||||
AddField( _( "Value" ), true, true );
|
||||
AddField( _( "Footprint" ), true, true );
|
||||
AddField( _( "Datasheet" ), true, false );
|
||||
|
||||
for( auto fieldName : userAndDefaultFieldnames )
|
||||
AddField( fieldName, fieldsToShow, fieldsToGroupBy );
|
||||
for( auto fieldName : userFieldNames )
|
||||
AddField( fieldName, true, false );
|
||||
|
||||
for( auto templateFieldName : m_parent->GetTemplateFieldNames() )
|
||||
AddField( templateFieldName.m_Name, false, false );
|
||||
}
|
||||
|
||||
|
||||
|
@ -768,17 +717,29 @@ void DIALOG_FIELDS_EDITOR_GLOBAL::OnColumnItemToggled( wxDataViewEvent& event )
|
|||
break;
|
||||
|
||||
case SHOW_FIELD_COLUMN:
|
||||
if( m_fieldsCtrl->GetToggleValue( row, col ) )
|
||||
{
|
||||
bool value = m_fieldsCtrl->GetToggleValue( row, col );
|
||||
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
||||
m_config->Write( "SymbolFieldEditor/Show/" + fieldName, value );
|
||||
|
||||
if( value )
|
||||
m_grid->ShowCol( row );
|
||||
else
|
||||
m_grid->HideCol( row ); // grid's columns map to fieldsCtrl's rows
|
||||
break;
|
||||
}
|
||||
|
||||
case GROUP_BY_COLUMN:
|
||||
{
|
||||
bool value = m_fieldsCtrl->GetToggleValue( row, col );
|
||||
wxString fieldName = m_fieldsCtrl->GetTextValue( row, FIELD_NAME_COLUMN );
|
||||
m_config->Write( "SymbolFieldEditor/GroupBy/" + fieldName, value );
|
||||
m_dataModel->RebuildRows( m_groupComponentsBox, m_fieldsCtrl );
|
||||
m_dataModel->Sort( m_grid->GetSortingColumn(), m_grid->IsSortOrderAscending() );
|
||||
m_grid->ForceRefresh();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ private:
|
|||
SCH_REFERENCE_LIST m_componentRefs;
|
||||
FIELDS_EDITOR_GRID_DATA_MODEL* m_dataModel;
|
||||
|
||||
void AddField( const wxString& aName, std::set<wxString>& show, std::set<wxString>& group );
|
||||
void AddField( const wxString& aName, bool defaultShow, bool defaultSortBy );
|
||||
void LoadFieldNames();
|
||||
|
||||
void OnColSort( wxGridEvent& aEvent );
|
||||
|
|
Loading…
Reference in New Issue