From a817eaa67f43633b5dee027009b59b13c70513c3 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 2 Dec 2023 22:05:56 +0000 Subject: [PATCH] Remove column auto-sizing and save user column widths. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16166 --- pcbnew/dialogs/dialog_net_inspector.cpp | 128 ++++++++----------- pcbnew/dialogs/dialog_net_inspector.h | 5 +- pcbnew/dialogs/dialog_net_inspector_base.cpp | 2 - pcbnew/dialogs/dialog_net_inspector_base.fbp | 1 - pcbnew/dialogs/dialog_net_inspector_base.h | 1 - 5 files changed, 59 insertions(+), 78 deletions(-) diff --git a/pcbnew/dialogs/dialog_net_inspector.cpp b/pcbnew/dialogs/dialog_net_inspector.cpp index c8efef9717..ed98292eb5 100644 --- a/pcbnew/dialogs/dialog_net_inspector.cpp +++ b/pcbnew/dialogs/dialog_net_inspector.cpp @@ -70,16 +70,20 @@ struct DIALOG_NET_INSPECTOR::COLUMN_DESC { COLUMN_DESC( unsigned aNum, PCB_LAYER_ID aLayer, const wxString& aDisp, const wxString& aCsv, CSV_COLUMN_DESC aFlags, bool aHasUnits ) : - num( aNum ), layer( aLayer ), display_name( aDisp ), csv_name( aCsv ), csv_flags( aFlags ), - has_units( aHasUnits ) + num( aNum ), + layer( aLayer ), + display_name( aDisp ), + csv_name( aCsv ), + csv_flags( aFlags ), + has_units( aHasUnits ) {} - unsigned int num; - PCB_LAYER_ID layer; - wxString display_name; - wxString csv_name; + unsigned int num; + PCB_LAYER_ID layer; + wxString display_name; + wxString csv_name; CSV_COLUMN_DESC csv_flags; - bool has_units; + bool has_units; operator unsigned int() const { @@ -1001,9 +1005,10 @@ DIALOG_NET_INSPECTOR::DIALOG_NET_INSPECTOR( PCB_EDIT_FRAME* aParent ) : std::vector> add_col{ [&]() { - m_netsList->AppendTextColumn( m_columns[COLUMN_NET].display_name, m_columns[COLUMN_NET], + m_netsList->AppendTextColumn( m_columns[COLUMN_NET].display_name, + m_columns[COLUMN_NET], wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT, - wxDATAVIEW_COL_SORTABLE ); + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE ); }, [&]() { @@ -1018,46 +1023,52 @@ DIALOG_NET_INSPECTOR::DIALOG_NET_INSPECTOR( PCB_EDIT_FRAME* aParent ) : m_netsList->AppendTextColumn( m_columns[COLUMN_PAD_COUNT].display_name, m_columns[COLUMN_PAD_COUNT], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, - wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE ); + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE | + wxDATAVIEW_COL_SORTABLE ); }, [&]() { m_netsList->AppendTextColumn( m_columns[COLUMN_VIA_COUNT].display_name, m_columns[COLUMN_VIA_COUNT], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, - wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE ); + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE | + wxDATAVIEW_COL_SORTABLE ); }, [&]() { m_netsList->AppendTextColumn( m_columns[COLUMN_VIA_LENGTH].display_name, m_columns[COLUMN_VIA_LENGTH], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, - wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE ); + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE | + wxDATAVIEW_COL_SORTABLE ); }, [&]() { m_netsList->AppendTextColumn( m_columns[COLUMN_BOARD_LENGTH].display_name, m_columns[COLUMN_BOARD_LENGTH], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, - wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE ); + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE | + wxDATAVIEW_COL_SORTABLE ); }, [&]() { m_netsList->AppendTextColumn( m_columns[COLUMN_CHIP_LENGTH].display_name, m_columns[COLUMN_CHIP_LENGTH], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, - wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE ); + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE | + wxDATAVIEW_COL_SORTABLE ); }, [&]() { m_netsList->AppendTextColumn( m_columns[COLUMN_TOTAL_LENGTH].display_name, m_columns[COLUMN_TOTAL_LENGTH], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, - wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE ); + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE | + wxDATAVIEW_COL_SORTABLE ); } }; - std::vector col_order = g_settings.column_order; + std::vector col_order = g_settings.col_order; if( col_order.size() != add_col.size() ) { @@ -1080,7 +1091,8 @@ DIALOG_NET_INSPECTOR::DIALOG_NET_INSPECTOR( PCB_EDIT_FRAME* aParent ) : m_netsList->AppendTextColumn( m_brd->GetLayerName( layer ), m_columns.back(), wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER, - wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_SORTABLE ); + wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE | + wxDATAVIEW_COL_SORTABLE ); } m_netsList->SetExpanderColumn( m_netsList->GetColumn( 0 ) ); @@ -1162,7 +1174,7 @@ DIALOG_NET_INSPECTOR::~DIALOG_NET_INSPECTOR() g_settings.sorting_column = sorting_column ? static_cast( sorting_column->GetModelColumn() ) : -1; g_settings.sort_order_asc = sorting_column ? sorting_column->IsSortOrderAscending() : true; - g_settings.column_order = column_order; + g_settings.col_order = column_order; SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); PCBNEW_SETTINGS* app_settings = mgr.GetAppSettings(); @@ -1964,50 +1976,36 @@ void DIALOG_NET_INSPECTOR::onSortingChanged( wxDataViewEvent& aEvent ) void DIALOG_NET_INSPECTOR::adjustListColumns() { wxWindowUpdateLocker locker( m_netsList ); - std::vector widths; - widths.reserve( m_columns.size() ); - - for( size_t ii = 0; ii < m_columns.size(); ++ii ) - widths.push_back( GetTextExtent( m_columns[ii].display_name ).x ); - - int minValueWidth = GetTextExtent( wxT( "00000,000 mm" ) ).x; - int minNumberWidth = GetTextExtent( wxT( "000" ) ).x; - int minNameWidth = GetTextExtent( wxT( "MMMMMM" ) ).x; - - // Considering left and right margins. - // For wxRenderGeneric it is 5px. - // Also account for the sorting arrow in the column header. - // Column 0 also needs space for any potential expander icons. - const int margins = 15; - const int extra_width = 30; - - widths[0] = std::max( widths[0], minNumberWidth ) + extra_width; - widths[1] = std::max( widths[1], minNameWidth ) + margins; - widths[2] = std::max( widths[2], minNumberWidth ) + margins; - widths[3] = std::max( widths[3], minNumberWidth ) + margins; - - for( size_t ii = 4; ii < widths.size(); ++ii ) + if( g_settings.col_widths.size() < m_columns.size() ) { - widths[ii] = std::max( widths[ii], minValueWidth ) + margins; + g_settings.col_widths.reserve( m_columns.size() ); + + for( DIALOG_NET_INSPECTOR::COLUMN_DESC& m_column : m_columns) + g_settings.col_widths.push_back( GetTextExtent( m_column.display_name ).x ); + + int minValueWidth = GetTextExtent( wxT( "00000,000 mm" ) ).x; + int minNumberWidth = GetTextExtent( wxT( "000" ) ).x; + int minNameWidth = GetTextExtent( wxT( "MMMMMM" ) ).x; + + // Considering left and right margins. + // For wxRenderGeneric it is 5px. + // Also account for the sorting arrow in the column header. + // Column 0 also needs space for any potential expander icons. + const int margins = 15; + const int extra_width = 30; + + g_settings.col_widths[0] = std::max( g_settings.col_widths[0], minNumberWidth ) + extra_width; + g_settings.col_widths[1] = std::max( g_settings.col_widths[1], minNameWidth ) + margins; + g_settings.col_widths[2] = std::max( g_settings.col_widths[2], minNumberWidth ) + margins; + g_settings.col_widths[3] = std::max( g_settings.col_widths[3], minNumberWidth ) + margins; + + for( size_t ii = 4; ii < g_settings.col_widths.size(); ++ii ) + g_settings.col_widths[ii] = std::max( g_settings.col_widths[ii], minValueWidth ) + margins; } - // the columns might have been reordered. we work on the column model numbers though. - std::vector column_order( m_data_model->columnCount() ); - - for( size_t i = 0; i < column_order.size(); ++i ) - { - column_order[m_netsList->GetColumn( i )->GetModelColumn()] = i; - m_netsList->GetColumn( column_order[i] )->SetMinWidth( widths[i] ); - m_netsList->GetColumn( column_order[i] )->SetWidth( widths[i] ); - } - - // At resizing of the list the width of middle column (Net Names) changes only. - int width = m_netsList->GetClientSize().x - 24; - int remaining = width - std::accumulate( widths.begin() + 2, widths.end(), widths[0] ); - - if( remaining > widths[1] ) - m_netsList->GetColumn( column_order[1] )->SetWidth( remaining ); + for( size_t ii = 0; ii < m_data_model->columnCount(); ++ii ) + m_netsList->GetColumn( ii )->SetWidth( g_settings.col_widths[ii] ); m_netsList->Refresh(); @@ -2020,20 +2018,6 @@ void DIALOG_NET_INSPECTOR::adjustListColumns() } -void DIALOG_NET_INSPECTOR::onListSize( wxSizeEvent& aEvent ) -{ - auto new_size = aEvent.GetSize(); - - if( new_size != m_size ) - { - m_size = new_size; - adjustListColumns(); - } - - aEvent.Skip(); -} - - void DIALOG_NET_INSPECTOR::onAddNet( wxCommandEvent& aEvent ) { wxString newNetName; diff --git a/pcbnew/dialogs/dialog_net_inspector.h b/pcbnew/dialogs/dialog_net_inspector.h index 1c3760c91c..316bc23efd 100644 --- a/pcbnew/dialogs/dialog_net_inspector.h +++ b/pcbnew/dialogs/dialog_net_inspector.h @@ -55,7 +55,8 @@ public: int sorting_column = -1; bool sort_order_asc = true; - std::vector column_order; + std::vector col_order; + std::vector col_widths; }; DIALOG_NET_INSPECTOR( PCB_EDIT_FRAME* aParent ); @@ -97,7 +98,6 @@ private: void onSelChanged(); void onSortingChanged( wxDataViewEvent& event ) override; void onFilterChange( wxCommandEvent& event ) override; - void onListSize( wxSizeEvent& event ) override; void onAddNet( wxCommandEvent& event ) override; void onRenameNet( wxCommandEvent& event ) override; void onDeleteNet( wxCommandEvent& event ) override; @@ -107,6 +107,7 @@ private: const std::vector& aCNItems ); void buildNetsList(); + void setColumnWidths(); void adjustListColumns(); void onUnitsChanged( wxCommandEvent& event ); diff --git a/pcbnew/dialogs/dialog_net_inspector_base.cpp b/pcbnew/dialogs/dialog_net_inspector_base.cpp index 3803d96567..a8ce1af937 100644 --- a/pcbnew/dialogs/dialog_net_inspector_base.cpp +++ b/pcbnew/dialogs/dialog_net_inspector_base.cpp @@ -116,7 +116,6 @@ DIALOG_NET_INSPECTOR_BASE::DIALOG_NET_INSPECTOR_BASE( wxWindow* parent, wxWindow m_groupByKind->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_NET_INSPECTOR_BASE::onFilterChange ), NULL, this ); m_netsList->Connect( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEventHandler( DIALOG_NET_INSPECTOR_BASE::onSortingChanged ), NULL, this ); m_netsList->Connect( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEventHandler( DIALOG_NET_INSPECTOR_BASE::onSelChanged ), NULL, this ); - m_netsList->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_NET_INSPECTOR_BASE::onListSize ), NULL, this ); m_addNet->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NET_INSPECTOR_BASE::onAddNet ), NULL, this ); m_renameNet->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NET_INSPECTOR_BASE::onRenameNet ), NULL, this ); m_deleteNet->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NET_INSPECTOR_BASE::onDeleteNet ), NULL, this ); @@ -134,7 +133,6 @@ DIALOG_NET_INSPECTOR_BASE::~DIALOG_NET_INSPECTOR_BASE() m_groupByKind->Disconnect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_NET_INSPECTOR_BASE::onFilterChange ), NULL, this ); m_netsList->Disconnect( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEventHandler( DIALOG_NET_INSPECTOR_BASE::onSortingChanged ), NULL, this ); m_netsList->Disconnect( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEventHandler( DIALOG_NET_INSPECTOR_BASE::onSelChanged ), NULL, this ); - m_netsList->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_NET_INSPECTOR_BASE::onListSize ), NULL, this ); m_addNet->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NET_INSPECTOR_BASE::onAddNet ), NULL, this ); m_renameNet->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NET_INSPECTOR_BASE::onRenameNet ), NULL, this ); m_deleteNet->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NET_INSPECTOR_BASE::onDeleteNet ), NULL, this ); diff --git a/pcbnew/dialogs/dialog_net_inspector_base.fbp b/pcbnew/dialogs/dialog_net_inspector_base.fbp index b357a8979a..8fb15288aa 100644 --- a/pcbnew/dialogs/dialog_net_inspector_base.fbp +++ b/pcbnew/dialogs/dialog_net_inspector_base.fbp @@ -516,7 +516,6 @@ onSortingChanged onSelChanged - onListSize diff --git a/pcbnew/dialogs/dialog_net_inspector_base.h b/pcbnew/dialogs/dialog_net_inspector_base.h index 731f04f5eb..d732bb13d5 100644 --- a/pcbnew/dialogs/dialog_net_inspector_base.h +++ b/pcbnew/dialogs/dialog_net_inspector_base.h @@ -61,7 +61,6 @@ class DIALOG_NET_INSPECTOR_BASE : public DIALOG_SHIM virtual void onFilterChange( wxCommandEvent& event ) { event.Skip(); } virtual void onSortingChanged( wxDataViewEvent& event ) { event.Skip(); } virtual void onSelChanged( wxDataViewEvent& event ) { event.Skip(); } - virtual void onListSize( wxSizeEvent& event ) { event.Skip(); } virtual void onAddNet( wxCommandEvent& event ) { event.Skip(); } virtual void onRenameNet( wxCommandEvent& event ) { event.Skip(); } virtual void onDeleteNet( wxCommandEvent& event ) { event.Skip(); }