Performance improvement for GetShownColumns.

(This needs to be fast as it's called from OnUpdateUI events.)
This commit is contained in:
Jeff Young 2023-04-13 13:45:22 +01:00
parent 18cebe3779
commit 8e29a054f3
14 changed files with 82 additions and 65 deletions

View File

@ -273,7 +273,7 @@ void WX_GRID::DestroyTable( wxGridTableBase* aTable )
}
wxString WX_GRID::GetShownColumns()
wxString WX_GRID::GetShownColumnsAsString()
{
wxString shownColumns;
@ -292,6 +292,17 @@ wxString WX_GRID::GetShownColumns()
}
std::bitset<64> WX_GRID::GetShownColumns()
{
std::bitset<64> shownColumns;
for( int ii = 0; ii < GetNumberCols(); ++ii )
shownColumns[ii] = IsColShown( ii );
return shownColumns;
}
void WX_GRID::ShowHideColumns( const wxString& shownColumns )
{
for( int i = 0; i < GetNumberCols(); ++i )
@ -310,6 +321,18 @@ void WX_GRID::ShowHideColumns( const wxString& shownColumns )
}
void WX_GRID::ShowHideColumns( const std::bitset<64>& aShownColumns )
{
for( int ii = 0; ii < GetNumberCols(); ++ ii )
{
if( aShownColumns[ii] )
ShowCol( ii );
else
HideCol( ii );
}
}
void WX_GRID::DrawCornerLabel( wxDC& dc )
{
if( m_nativeColumnLabels )

View File

@ -118,13 +118,10 @@ DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_L
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
// Show/hide columns according to user's preference
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxASSERT( cfg );
if( cfg )
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
{
m_shownColumns = cfg->m_Appearance.edit_label_visible_columns;
m_grid->ShowHideColumns( m_shownColumns );
m_grid->ShowHideColumns( cfg->m_Appearance.edit_label_visible_columns );
m_shownColumns = m_grid->GetShownColumns();
}
// Configure button logos
@ -221,19 +218,19 @@ DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_L
// Now all widgets have the size fixed, call FinishDialogSettings
finishDialogSettings();
if( cfg && cfg->m_Appearance.edit_label_width > 0 && cfg->m_Appearance.edit_label_height > 0 )
SetSize( cfg->m_Appearance.edit_label_width, cfg->m_Appearance.edit_label_height );
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
{
if( cfg->m_Appearance.edit_label_width > 0 && cfg->m_Appearance.edit_label_height > 0 )
SetSize( cfg->m_Appearance.edit_label_width, cfg->m_Appearance.edit_label_height );
}
}
DIALOG_LABEL_PROPERTIES::~DIALOG_LABEL_PROPERTIES()
{
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxASSERT( cfg );
if( cfg )
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
{
cfg->m_Appearance.edit_label_visible_columns = m_grid->GetShownColumns();
cfg->m_Appearance.edit_label_visible_columns = m_grid->GetShownColumnsAsString();
cfg->m_Appearance.edit_label_width = GetSize().x;
cfg->m_Appearance.edit_label_height = GetSize().y;
}
@ -776,7 +773,7 @@ void DIALOG_LABEL_PROPERTIES::AdjustGridColumns( int aWidth )
void DIALOG_LABEL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
{
wxString shownColumns = m_grid->GetShownColumns();
std::bitset<64> shownColumns = m_grid->GetShownColumns();
if( shownColumns != m_shownColumns )
{

View File

@ -71,7 +71,7 @@ private:
SCH_NETNAME_VALIDATOR m_netNameValidator;
FIELDS_GRID_TABLE<SCH_FIELD>* m_fields;
wxString m_shownColumns;
std::bitset<64> m_shownColumns;
UNIT_BINDER m_textSize;

View File

@ -723,10 +723,11 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent,
} ) );
// Show/hide columns according to the user's preference
SYMBOL_EDITOR_SETTINGS* cfg = parent->GetSettings();
m_columnsShown = cfg->m_PinTableVisibleColumns;
m_grid->ShowHideColumns( m_columnsShown );
if( SYMBOL_EDITOR_SETTINGS* cfg = parent->GetSettings() )
{
m_grid->ShowHideColumns( cfg->m_PinTableVisibleColumns );
m_columnsShown = m_grid->GetShownColumns();
}
// Set special attributes
wxGridCellAttr* attr;
@ -838,8 +839,8 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent,
DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE()
{
SYMBOL_EDITOR_SETTINGS* cfg = m_editFrame->GetSettings();
cfg->m_PinTableVisibleColumns = m_grid->GetShownColumns().ToStdString();
if( SYMBOL_EDITOR_SETTINGS* cfg = m_editFrame->GetSettings() )
cfg->m_PinTableVisibleColumns = m_grid->GetShownColumnsAsString();
// Disconnect Events
m_grid->Disconnect( wxEVT_GRID_COL_SORT,
@ -1130,7 +1131,7 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnSize( wxSizeEvent& event )
void DIALOG_LIB_EDIT_PIN_TABLE::OnUpdateUI( wxUpdateUIEvent& event )
{
wxString columnsShown = m_grid->GetShownColumns();
std::bitset<64> columnsShown = m_grid->GetShownColumns();
if( columnsShown != m_columnsShown )
{

View File

@ -84,7 +84,7 @@ protected:
SYMBOL_EDIT_FRAME* m_editFrame;
bool m_initialized = false;
int m_originalColWidths[ COL_COUNT ];
wxString m_columnsShown;
std::bitset<64> m_columnsShown;
LIB_SYMBOL* m_symbol;
LIB_PINS m_pins; // a copy of the pins owned by me
bool m_modified; ///< true when there are unsaved changes

View File

@ -127,8 +127,8 @@ DIALOG_LIB_SYMBOL_PROPERTIES::~DIALOG_LIB_SYMBOL_PROPERTIES()
{
m_lastOpenedPage = m_NoteBook->GetSelection( );
SYMBOL_EDITOR_SETTINGS* cfg = m_Parent->GetSettings();
cfg->m_EditSymbolVisibleColumns = m_grid->GetShownColumns();
if( SYMBOL_EDITOR_SETTINGS* cfg = m_Parent->GetSettings() )
cfg->m_EditSymbolVisibleColumns = m_grid->GetShownColumnsAsString();
// Prevents crash bug in wxGrid's d'tor
m_grid->DestroyTable( m_fields );
@ -839,7 +839,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
}
// Handle shown columns changes
wxString shownColumns = m_grid->GetShownColumns();
std::bitset<64> shownColumns = m_grid->GetShownColumns();
if( shownColumns != m_shownColumns )
{

View File

@ -90,7 +90,7 @@ public:
int m_delayedFocusPage;
wxString m_delayedErrorMessage;
wxString m_shownColumns;
std::bitset<64> m_shownColumns;
wxSize m_size;
private:

View File

@ -70,13 +70,10 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S
m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
// Show/hide columns according to user's preference
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxASSERT( cfg );
if( cfg )
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
{
m_shownColumns = cfg->m_Appearance.edit_sheet_visible_columns;
m_grid->ShowHideColumns( m_shownColumns );
m_grid->ShowHideColumns( cfg->m_Appearance.edit_sheet_visible_columns );
m_shownColumns = m_grid->GetShownColumns();
}
if( m_frame->GetColorSettings()->GetOverrideSchItemColors() )
@ -109,12 +106,9 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S
DIALOG_SHEET_PROPERTIES::~DIALOG_SHEET_PROPERTIES()
{
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxASSERT( cfg );
if( cfg )
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
{
cfg->m_Appearance.edit_sheet_visible_columns = m_grid->GetShownColumns();
cfg->m_Appearance.edit_sheet_visible_columns = m_grid->GetShownColumnsAsString();
cfg->m_Appearance.edit_sheet_width = GetSize().x;
cfg->m_Appearance.edit_sheet_height = GetSize().y;
}
@ -833,7 +827,7 @@ void DIALOG_SHEET_PROPERTIES::AdjustGridColumns()
void DIALOG_SHEET_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
{
wxString shownColumns = m_grid->GetShownColumns();
std::bitset<64> shownColumns = m_grid->GetShownColumns();
if( shownColumns != m_shownColumns )
{

View File

@ -70,7 +70,7 @@ private:
wxSize m_size;
int m_delayedFocusRow;
int m_delayedFocusColumn;
wxString m_shownColumns;
std::bitset<64> m_shownColumns;
FIELDS_GRID_TABLE<SCH_FIELD>* m_fields;
UNIT_BINDER m_borderWidth;

View File

@ -326,12 +326,10 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
// Show/hide columns according to user's preference
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
if( cfg )
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
{
m_shownColumns = cfg->m_Appearance.edit_symbol_visible_columns;
m_fieldsGrid->ShowHideColumns( m_shownColumns );
m_fieldsGrid->ShowHideColumns( cfg->m_Appearance.edit_symbol_visible_columns );
m_shownColumns = m_fieldsGrid->GetShownColumns();
}
if( m_part && m_part->HasConversion() )
@ -387,11 +385,9 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent,
DIALOG_SYMBOL_PROPERTIES::~DIALOG_SYMBOL_PROPERTIES()
{
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
if( cfg )
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
{
cfg->m_Appearance.edit_symbol_visible_columns = m_fieldsGrid->GetShownColumns();
cfg->m_Appearance.edit_symbol_visible_columns = m_fieldsGrid->GetShownColumnsAsString();
cfg->m_Appearance.edit_symbol_width = GetSize().x;
cfg->m_Appearance.edit_symbol_height = GetSize().y;
}
@ -1165,7 +1161,7 @@ void DIALOG_SYMBOL_PROPERTIES::AdjustPinsGridColumns()
void DIALOG_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
{
wxString shownColumns = m_fieldsGrid->GetShownColumns();
std::bitset<64> shownColumns = m_fieldsGrid->GetShownColumns();
if( shownColumns != m_shownColumns )
{

View File

@ -102,14 +102,14 @@ private:
void AdjustGridColumns( int aWidth );
private:
SCH_SYMBOL* m_symbol;
LIB_SYMBOL* m_part;
SCH_SYMBOL* m_symbol;
LIB_SYMBOL* m_part;
wxSize m_fieldsSize;
wxSize m_lastRequestedSize;
wxSize m_pinsSize;
bool m_editorShown;
wxString m_shownColumns;
wxSize m_fieldsSize;
wxSize m_lastRequestedSize;
wxSize m_pinsSize;
bool m_editorShown;
std::bitset<64> m_shownColumns;
FIELDS_GRID_TABLE<SCH_FIELD>* m_fields;
SCH_PIN_TABLE_DATA_MODEL* m_dataModel;

View File

@ -61,13 +61,19 @@ public:
* Get a tokenized string containing the shown column indexes.
* Tokens are separated by spaces.
*/
wxString GetShownColumns();
wxString GetShownColumnsAsString();
std::bitset<64> GetShownColumns();
/**
* Show/hide the grid columns based on a tokenized string of shown column indexes.
*/
void ShowHideColumns( const wxString& shownColumns );
/**
* A more performant version of ShowHideColumns (primarily for OnUpdateUI handlers).
*/
void ShowHideColumns( const std::bitset<64>& aShownColumns );
/**
* Hide wxGrid's SetTable() method with one which doesn't mess up the grid column
* widths when setting the table.

View File

@ -97,10 +97,9 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen
m_itemsGrid->SetTable( m_texts );
m_itemsGrid->PushEventHandler( new GRID_TRICKS( m_itemsGrid ) );
PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings();
// Show/hide text item columns according to the user's preference
m_itemsGrid->ShowHideColumns( cfg->m_FootprintTextShownColumns );
if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
m_itemsGrid->ShowHideColumns( cfg->m_FootprintTextShownColumns );
m_orientation.SetUnits( EDA_UNITS::DEGREES );
m_orientation.SetPrecision( 3 );
@ -175,7 +174,8 @@ DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES( PCB_EDIT_FRAME* aParen
DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES()
{
m_frame->GetPcbNewSettings()->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumns().ToStdString();
if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
cfg->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumnsAsString();
// Prevents crash bug in wxGrid's d'tor
m_itemsGrid->DestroyTable( m_texts );

View File

@ -229,8 +229,8 @@ DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(
DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR()
{
m_frame->GetSettings()->m_FootprintTextShownColumns =
m_itemsGrid->GetShownColumns().ToStdString();
if( FOOTPRINT_EDITOR_SETTINGS* cfg = m_frame->GetSettings() )
cfg->m_FootprintTextShownColumns = m_itemsGrid->GetShownColumnsAsString();
// Prevents crash bug in wxGrid's d'tor
m_itemsGrid->DestroyTable( m_texts );