From fe5c7a60ab25a57f4206720eece564b031f6296e Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Fri, 9 Jun 2023 09:06:11 -0400 Subject: [PATCH] Net Inspector: clear sort ordering during rebuild Fixes https://gitlab.com/kicad/code/kicad/-/issues/14697 (cherry picked from commit 3a2cc8f56f05d0616f7c55c566e1e642a63c4502) --- pcbnew/dialogs/dialog_net_inspector.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pcbnew/dialogs/dialog_net_inspector.cpp b/pcbnew/dialogs/dialog_net_inspector.cpp index b9715b5df6..8676608eb9 100644 --- a/pcbnew/dialogs/dialog_net_inspector.cpp +++ b/pcbnew/dialogs/dialog_net_inspector.cpp @@ -126,6 +126,7 @@ public: LIST_ITEM( NETINFO_ITEM* aNet ) : m_net( aNet ) { + wxASSERT( aNet ); m_net_name = UnescapeString( aNet->GetNetname() ); m_column_changed.resize( COLUMN_NUM_STATIC_COL + MAX_CU_LAYERS, 0 ); } @@ -811,8 +812,11 @@ protected: else if( aCol == COLUMN_TOTAL_LENGTH ) aOutValue = m_parent.formatLength( i->GetTotalLength() ); - else if( aCol > COLUMN_NUM_STATIC_COL ) + else if( aCol > COLUMN_NUM_STATIC_COL && aCol <= m_parent.m_columns.size() ) aOutValue = m_parent.formatLength( i->GetLayerWireLength( m_parent.m_columns[aCol].layer ) ); + + else + aOutValue = ""; } } @@ -1680,6 +1684,14 @@ void DIALOG_NET_INSPECTOR::buildNetsList() prev_selected_netcodes.push_back( item->GetNetCode() ); } + // At least on GTK, wxDVC will crash if you rebuild with a sorting column set. + if( wxDataViewColumn* sorting_column = m_netsList->GetSortingColumn() ) + { + g_settings.sorting_column = static_cast( sorting_column->GetModelColumn() ) ; + g_settings.sort_order_asc = sorting_column->IsSortOrderAscending(); + sorting_column->UnsetAsSortKey(); + } + m_data_model->deleteAllItems(); std::vector> new_items; @@ -1760,6 +1772,15 @@ void DIALOG_NET_INSPECTOR::buildNetsList() m_data_model->addItems( std::move( new_items ) ); + if( g_settings.sorting_column != -1 ) + { + if( wxDataViewColumn* c = m_netsList->GetColumn( g_settings.sorting_column ) ) + { + c->SetSortOrder( g_settings.sort_order_asc ); + m_data_model->Resort(); + } + } + // try to restore the selected rows. set the ones that we can't find anymore to -1. sel.Clear();