From 753f2f3e4c4da39a23cdfaa1a7493f55974f59e5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 28 Jul 2022 14:51:13 +0100 Subject: [PATCH] Display descriptions in second column of library trees. Also fixes some bugs in how the columns are sized. Fixes https://gitlab.com/kicad/code/kicad/issues/12090 --- common/lib_tree_model_adapter.cpp | 37 ++++++++++++------- common/widgets/lib_tree.cpp | 7 ++++ eeschema/symbol_tree_model_adapter.cpp | 18 +++++++-- .../symbol_tree_synchronizing_adapter.cpp | 6 +-- include/lib_tree_model_adapter.h | 5 ++- include/widgets/lib_tree.h | 1 + pcbnew/fp_tree_model_adapter.cpp | 15 ++++++++ pcbnew/fp_tree_synchronizing_adapter.cpp | 4 +- 8 files changed, 68 insertions(+), 25 deletions(-) diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index bc90cf7529..dfdd3997c2 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -79,11 +79,11 @@ LIB_TREE_MODEL_ADAPTER::LIB_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent, m_widget( nullptr ) { // Default column widths - m_colWidths[PART_COL] = 360; + m_colWidths[NAME_COL] = 300; m_colWidths[DESC_COL] = 2000; APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings(); - m_colWidths[PART_COL] = cfg->m_LibTree.column_width; + m_colWidths[NAME_COL] = cfg->m_LibTree.column_width; } @@ -96,7 +96,7 @@ void LIB_TREE_MODEL_ADAPTER::SaveColWidths() if( m_widget ) { APP_SETTINGS_BASE* cfg = Kiface().KifaceSettings(); - cfg->m_LibTree.column_width = m_widget->GetColumn( PART_COL )->GetWidth(); + cfg->m_LibTree.column_width = m_widget->GetColumn( NAME_COL )->GetWidth(); } } @@ -236,28 +236,30 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a void LIB_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl ) { - wxString partHead = _( "Item" ); + wxString itemHead = _( "Item" ); wxString descHead = _( "Description" ); // The extent of the text doesn't take into account the space on either side // in the header, so artificially pad it - wxSize partHeadMinWidth = KIUI::GetTextSize( partHead + "MMM", aDataViewCtrl ); + wxSize itemHeadMinWidth = KIUI::GetTextSize( itemHead + wxT( "MMM" ), aDataViewCtrl ); + wxSize descHeadMinWidth = KIUI::GetTextSize( descHead + wxT( "MMM" ), aDataViewCtrl ); // Ensure the part column is wider than the smallest allowable width - if( m_colWidths[PART_COL] < partHeadMinWidth.x ) - m_colWidths[PART_COL] = partHeadMinWidth.x; + if( m_colWidths[NAME_COL] < itemHeadMinWidth.x ) + m_colWidths[NAME_COL] = itemHeadMinWidth.x; m_widget = aDataViewCtrl; aDataViewCtrl->SetIndent( kDataViewIndent ); aDataViewCtrl->AssociateModel( this ); aDataViewCtrl->ClearColumns(); - m_col_part = aDataViewCtrl->AppendTextColumn( partHead, PART_COL, wxDATAVIEW_CELL_INERT, - m_colWidths[PART_COL] ); + m_col_part = aDataViewCtrl->AppendTextColumn( itemHead, NAME_COL, wxDATAVIEW_CELL_INERT, + m_colWidths[NAME_COL] ); m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT, m_colWidths[DESC_COL] ); - m_col_part->SetMinWidth( partHeadMinWidth.x ); + m_col_part->SetMinWidth( itemHeadMinWidth.x ); + m_col_desc->SetMinWidth( descHeadMinWidth.x ); } @@ -350,7 +352,14 @@ unsigned int LIB_TREE_MODEL_ADAPTER::GetChildren( const wxDataViewItem& aItem, void LIB_TREE_MODEL_ADAPTER::FinishTreeInitialization() { - m_col_part->SetWidth( m_colWidths[PART_COL] ); + m_col_part->SetWidth( m_colWidths[NAME_COL] ); + m_col_desc->SetWidth( m_colWidths[DESC_COL] ); +} + + +void LIB_TREE_MODEL_ADAPTER::OnSize( wxSizeEvent& aEvent ) +{ + m_colWidths[NAME_COL] = m_col_part->GetWidth(); m_col_desc->SetWidth( m_colWidths[DESC_COL] ); } @@ -369,14 +378,14 @@ void LIB_TREE_MODEL_ADAPTER::RefreshTree() // GTK returns the displayed width of the column, which is not calculated immediately if( descWidth > 0 ) { - m_colWidths[PART_COL] = partWidth; + m_colWidths[NAME_COL] = partWidth; m_colWidths[DESC_COL] = descWidth; } - m_colWidths[PART_COL] += walk; + m_colWidths[NAME_COL] += walk; m_colWidths[DESC_COL] -= walk; - m_col_part->SetWidth( m_colWidths[PART_COL] ); + m_col_part->SetWidth( m_colWidths[NAME_COL] ); m_col_desc->SetWidth( m_colWidths[DESC_COL] ); walk = -walk; } diff --git a/common/widgets/lib_tree.cpp b/common/widgets/lib_tree.cpp index e83e2979b7..b6a104051e 100644 --- a/common/widgets/lib_tree.cpp +++ b/common/widgets/lib_tree.cpp @@ -112,6 +112,7 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, SetSizer( sizer ); + m_tree_ctrl->Bind( wxEVT_SIZE, &LIB_TREE::onSize, this ); m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &LIB_TREE::onTreeActivate, this ); m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &LIB_TREE::onTreeSelect, this ); m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &LIB_TREE::onContextMenu, this ); @@ -472,6 +473,12 @@ void LIB_TREE::onTreeActivate( wxDataViewEvent& aEvent ) } +void LIB_TREE::onSize( wxSizeEvent& aEvent ) +{ + m_adapter->OnSize( aEvent ); +} + + void LIB_TREE::onDetailsLink( wxHtmlLinkEvent& aEvent ) { const wxHtmlLinkInfo& info = aEvent.GetLinkInfo(); diff --git a/eeschema/symbol_tree_model_adapter.cpp b/eeschema/symbol_tree_model_adapter.cpp index 093fee6a6e..aa7c585094 100644 --- a/eeschema/symbol_tree_model_adapter.cpp +++ b/eeschema/symbol_tree_model_adapter.cpp @@ -194,10 +194,20 @@ void SYMBOL_TREE_MODEL_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem co LIB_TREE_NODE* node = ToNode( aItem ); wxASSERT( node ); - if( aCol == 0 && node->m_Pinned ) - aVariant = GetPinningSymbol() + UnescapeString( node->m_Name ); - else - aVariant = UnescapeString( node->m_Name ); + switch( aCol ) + { + case NAME_COL: + if( node->m_Pinned ) + aVariant = GetPinningSymbol() + UnescapeString( node->m_Name ); + else + aVariant = UnescapeString( node->m_Name ); + + break; + + case DESC_COL: + aVariant = node->m_Desc; + break; + } } diff --git a/eeschema/symbol_tree_synchronizing_adapter.cpp b/eeschema/symbol_tree_synchronizing_adapter.cpp index 223fbafe08..ba1701de55 100644 --- a/eeschema/symbol_tree_synchronizing_adapter.cpp +++ b/eeschema/symbol_tree_synchronizing_adapter.cpp @@ -222,7 +222,7 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataVie switch( aCol ) { - case 0: + case NAME_COL: if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId ) node->m_Name = m_frame->GetCurSymbol()->GetLibId().GetLibItemName(); @@ -245,7 +245,7 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataVie break; - case 1: + case DESC_COL: if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId ) { node->m_Desc = m_frame->GetCurSymbol()->GetDescription(); @@ -294,7 +294,7 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un } // The remaining attributes are only for the name column - if( aCol != 0 ) + if( aCol != NAME_COL ) return false; LIB_SYMBOL* curSymbol = m_frame->GetCurSymbol(); diff --git a/include/lib_tree_model_adapter.h b/include/lib_tree_model_adapter.h index d70cfcf168..704f3a01ed 100644 --- a/include/lib_tree_model_adapter.h +++ b/include/lib_tree_model_adapter.h @@ -127,8 +127,8 @@ public: */ enum TREE_COLS { - PART_COL = 0, ///< Part name column - DESC_COL, ///< Part description column + NAME_COL = 0, ///< Library or library item name column + DESC_COL, ///< Library or library description column NUM_COLS ///< The number of tree columns }; @@ -207,6 +207,7 @@ public: */ void FinishTreeInitialization(); + void OnSize( wxSizeEvent& aEvent ); /** * Return the alias for the given item. * diff --git a/include/widgets/lib_tree.h b/include/widgets/lib_tree.h index ead6edd4a0..31bdb591c9 100644 --- a/include/widgets/lib_tree.h +++ b/include/widgets/lib_tree.h @@ -171,6 +171,7 @@ protected: void onTreeSelect( wxDataViewEvent& aEvent ); void onTreeActivate( wxDataViewEvent& aEvent ); + void onSize( wxSizeEvent& aEvent ); void onDetailsLink( wxHtmlLinkEvent& aEvent ); void onPreselect( wxCommandEvent& aEvent ); diff --git a/pcbnew/fp_tree_model_adapter.cpp b/pcbnew/fp_tree_model_adapter.cpp index fa257989f4..449d6d7130 100644 --- a/pcbnew/fp_tree_model_adapter.cpp +++ b/pcbnew/fp_tree_model_adapter.cpp @@ -110,6 +110,21 @@ void FP_TREE_MODEL_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& aVariant = GetPinningSymbol() + node->m_Name; else aVariant = node->m_Name; + + switch( aCol ) + { + case NAME_COL: + if( node->m_Pinned ) + aVariant = GetPinningSymbol() + UnescapeString( node->m_Name ); + else + aVariant = UnescapeString( node->m_Name ); + + break; + + case DESC_COL: + aVariant = node->m_Desc; + break; + } } diff --git a/pcbnew/fp_tree_synchronizing_adapter.cpp b/pcbnew/fp_tree_synchronizing_adapter.cpp index 2bb93d2624..7b9ab9d214 100644 --- a/pcbnew/fp_tree_synchronizing_adapter.cpp +++ b/pcbnew/fp_tree_synchronizing_adapter.cpp @@ -180,7 +180,7 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewIte switch( aCol ) { - case 0: + case NAME_COL: if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() ) { // Do not use GetLoadedFPID(); it returns m_footprintNameWhenLoaded. @@ -203,7 +203,7 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewIte break; - case 1: + case DESC_COL: if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() ) { node->m_Desc = m_frame->GetBoard()->GetFirstFootprint()->GetDescription();