Symbol Fields Table: performance optimizations
Fixes: https://gitlab.com/kicad/code/kicad/-/issues/14972
This commit is contained in:
parent
9fbaa238a2
commit
f9d4b75726
|
@ -1509,6 +1509,10 @@ void DIALOG_SYMBOL_FIELDS_TABLE::onBomPresetChanged( wxCommandEvent& aEvent )
|
|||
|
||||
void DIALOG_SYMBOL_FIELDS_TABLE::doApplyBomPreset( const BOM_PRESET& aPreset )
|
||||
{
|
||||
// Disable rebuilds while we're applying the preset otherwise we'll be
|
||||
// rebuilding the model constantly while firing off wx events
|
||||
m_dataModel->DisableRebuilds();
|
||||
|
||||
// Basically, we apply the BOM preset to the data model and then
|
||||
// update our UI to reflect resulting the data model state, not the preset.
|
||||
m_dataModel->ApplyBomPreset( aPreset );
|
||||
|
@ -1580,6 +1584,7 @@ void DIALOG_SYMBOL_FIELDS_TABLE::doApplyBomPreset( const BOM_PRESET& aPreset )
|
|||
|
||||
// This will rebuild all rows and columns in the model such that the order
|
||||
// and labels are right, then we refresh the shown grid data to match
|
||||
m_dataModel->EnableRebuilds();
|
||||
m_dataModel->RebuildRows();
|
||||
m_grid->ForceRefresh();
|
||||
}
|
||||
|
@ -1900,6 +1905,9 @@ void DIALOG_SYMBOL_FIELDS_TABLE::doApplyBomFmtPreset( const BOM_FMT_PRESET& aPre
|
|||
m_checkKeepTabs->SetValue( aPreset.keepTabs );
|
||||
m_checkKeepLineBreaks->SetValue( aPreset.keepLineBreaks );
|
||||
|
||||
|
||||
// Refresh the preview if that's the current page
|
||||
if( m_nbPages->GetSelection() == 1 )
|
||||
PreviewRefresh();
|
||||
}
|
||||
|
||||
|
|
|
@ -350,8 +350,23 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::groupMatch( const SCH_REFERENCE& lhRef,
|
|||
}
|
||||
|
||||
|
||||
void FIELDS_EDITOR_GRID_DATA_MODEL::EnableRebuilds()
|
||||
{
|
||||
m_rebuildsEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
void FIELDS_EDITOR_GRID_DATA_MODEL::DisableRebuilds()
|
||||
{
|
||||
m_rebuildsEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
void FIELDS_EDITOR_GRID_DATA_MODEL::RebuildRows()
|
||||
{
|
||||
if( !m_rebuildsEnabled )
|
||||
return;
|
||||
|
||||
if( GetView() )
|
||||
{
|
||||
// Commit any pending in-place edits before the row gets moved out from under
|
||||
|
@ -379,6 +394,13 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::RebuildRows()
|
|||
|
||||
bool matchFound = false;
|
||||
|
||||
// Performance optimization for ungrouped case to skip the N^2 for loop
|
||||
if( !m_groupingEnabled && !ref.IsMultiUnit() )
|
||||
{
|
||||
m_rows.emplace_back( DATA_MODEL_ROW( ref, GROUP_SINGLETON ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
// See if we already have a row which this symbol fits into
|
||||
for( DATA_MODEL_ROW& row : m_rows )
|
||||
{
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
FIELDS_EDITOR_GRID_DATA_MODEL( SCH_REFERENCE_LIST& aSymbolsList ) :
|
||||
m_symbolsList( aSymbolsList ), m_edited( false ), m_sortColumn( 0 ),
|
||||
m_sortAscending( false ), m_groupingEnabled( false ), m_excludeDNP( false ),
|
||||
m_includeExcluded( false )
|
||||
m_includeExcluded( false ), m_rebuildsEnabled( true )
|
||||
{
|
||||
m_symbolsList.SplitReferences();
|
||||
}
|
||||
|
@ -131,7 +131,12 @@ public:
|
|||
int GetSortCol() { return m_sortColumn; }
|
||||
bool GetSortAsc() { return m_sortAscending; }
|
||||
|
||||
// These are used to disable the RebuildRows functionality while we're generating
|
||||
// lots of events in the UI, e.g. applying a BOM preset, that would thrash the grid.
|
||||
void EnableRebuilds();
|
||||
void DisableRebuilds();
|
||||
void RebuildRows();
|
||||
|
||||
void ExpandRow( int aRow );
|
||||
void CollapseRow( int aRow );
|
||||
void ExpandCollapseRow( int aRow );
|
||||
|
@ -204,6 +209,7 @@ protected:
|
|||
bool m_groupingEnabled;
|
||||
bool m_excludeDNP;
|
||||
bool m_includeExcluded;
|
||||
bool m_rebuildsEnabled;
|
||||
|
||||
std::vector<DATA_MODEL_COL> m_cols;
|
||||
std::vector<DATA_MODEL_ROW> m_rows;
|
||||
|
|
|
@ -100,6 +100,7 @@ public:
|
|||
|
||||
int GetUnit() const { return m_unit; }
|
||||
void SetUnit( int aUnit ) { m_unit = aUnit; }
|
||||
bool IsMultiUnit() const { return GetLibPart()->GetUnitCount() > 1; }
|
||||
|
||||
const wxString GetValue() const { return m_value; }
|
||||
void SetValue( const wxString& aValue ) { m_value = aValue; }
|
||||
|
|
Loading…
Reference in New Issue