KiCad PCB EDA Suite
LIB_TREE_MODEL_ADAPTER Class Referenceabstract

#include <lib_tree_model_adapter.h>

Inheritance diagram for LIB_TREE_MODEL_ADAPTER:
FP_TREE_MODEL_ADAPTER SYMBOL_TREE_MODEL_ADAPTER SYMBOL_TREE_SYNCHRONIZING_ADAPTER FP_TREE_SYNCHRONIZING_ADAPTER

Public Types

enum  SYM_FILTER_TYPE { SYM_FILTER_NONE , SYM_FILTER_POWER }
 This enum allows a selective filtering of symbols to list. More...
 
enum  TREE_COLS { NAME_COL = 0 , DESC_COL , NUM_COLS }
 This enum defines the order of the default columns in the tree view. More...
 

Public Member Functions

 ~LIB_TREE_MODEL_ADAPTER ()
 Destructor. More...
 
void SaveSettings ()
 Save the column widths to the config file. More...
 
void SetFilter (SYM_FILTER_TYPE aFilter)
 Set the symbol filter type. More...
 
SYM_FILTER_TYPE GetFilter () const
 Return the active filter. More...
 
void ShowUnits (bool aShow)
 Whether or not to show units. More...
 
void SetPreselectNode (const LIB_ID &aLibId, int aUnit)
 Set the symbol name to be selected if there are no search results. More...
 
void DoAddLibrary (const wxString &aNodeName, const wxString &aDesc, const std::vector< LIB_TREE_ITEM * > &aItemList, bool pinned, bool presorted)
 Add the given list of symbols by alias. More...
 
void AddColumn (const wxString &aHeader)
 
std::vector< wxString > GetAvailableColumns () const
 
std::vector< wxString > GetShownColumns () const
 
void SetShownColumns (const std::vector< wxString > &aColumnNames)
 Sets which columns are shown in the widget. More...
 
void AssignIntrinsicRanks ()
 Sort the tree and assign ranks after adding libraries. More...
 
void UpdateSearchString (const wxString &aSearch, bool aState)
 Set the search string provided by the user. More...
 
void AttachTo (wxDataViewCtrl *aDataViewCtrl)
 Attach to a wxDataViewCtrl and initialize it. More...
 
void FinishTreeInitialization ()
 A final-stage initialization to be called after the window hierarchy has been realized and the window sizes set. More...
 
void OnSize (wxSizeEvent &aEvent)
 
LIB_ID GetAliasFor (const wxDataViewItem &aSelection) const
 Return the alias for the given item. More...
 
int GetUnitFor (const wxDataViewItem &aSelection) const
 Return the unit for the given item. More...
 
LIB_TREE_NODE::TYPE GetTypeFor (const wxDataViewItem &aSelection) const
 Return node type for the given item. More...
 
LIB_TREE_NODEGetTreeNodeFor (const wxDataViewItem &aSelection) const
 
virtual wxString GenerateInfo (const LIB_ID &aLibId, int aUnit)
 
int GetItemCount () const
 Return the number of symbols loaded in the tree. More...
 
virtual int GetLibrariesCount () const
 Return the number of libraries loaded in the tree. More...
 
wxDataViewItem FindItem (const LIB_ID &aLibId)
 Returns tree item corresponding to part. More...
 
unsigned int GetChildren (const wxDataViewItem &aItem, wxDataViewItemArray &aChildren) const override
 Populate a list of all the children of an item. More...
 
void Freeze ()
 
void Thaw ()
 
bool IsFrozen () const
 
void RefreshTree ()
 
virtual TOOL_INTERACTIVEGetContextMenuTool ()
 
void PinLibrary (LIB_TREE_NODE *aTreeNode)
 
void UnpinLibrary (LIB_TREE_NODE *aTreeNode)
 

Static Public Member Functions

static const wxString GetPinningSymbol ()
 

Protected Member Functions

 LIB_TREE_MODEL_ADAPTER (EDA_BASE_FRAME *aParent, const wxString &aPinnedKey)
 Create the adapter. More...
 
LIB_TREE_NODE_LIBDoAddLibraryNode (const wxString &aNodeName, const wxString &aDesc, bool pinned)
 
bool HasContainerColumns (const wxDataViewItem &aItem) const override
 Check whether a container has columns too. More...
 
bool IsContainer (const wxDataViewItem &aItem) const override
 Check whether an item can have children. More...
 
wxDataViewItem GetParent (const wxDataViewItem &aItem) const override
 Get the parent of an item. More...
 
unsigned int GetColumnCount () const override
 
wxString GetColumnType (unsigned int aCol) const override
 Return the type of data stored in the column as indicated by wxVariant::GetType() More...
 
void GetValue (wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) const override
 Get the value of an item. More...
 
bool SetValue (const wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) override
 Set the value of an item. More...
 
bool GetAttr (const wxDataViewItem &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
 Get any formatting for an item. More...
 
virtual bool isSymbolModel ()=0
 
void resortTree ()
 
void addColumnIfNecessary (const wxString &aHeader)
 
void recreateColumns ()
 

Static Protected Member Functions

static wxDataViewItem ToItem (const LIB_TREE_NODE *aNode)
 Convert #SYM_TREE_NODE -> wxDataViewItem. More...
 
static LIB_TREE_NODEToNode (wxDataViewItem aItem)
 Convert wxDataViewItem -> #SYM_TREE_NODE. More...
 
static unsigned int IntoArray (const LIB_TREE_NODE &aNode, wxDataViewItemArray &aChildren)
 Convert SYM_TREE_NODE's children to wxDataViewItemArray. More...
 

Protected Attributes

LIB_TREE_NODE_ROOT m_tree
 
std::map< unsigned, wxString > m_colIdxMap
 

Private Member Functions

void Find (LIB_TREE_NODE &aNode, std::function< bool(const LIB_TREE_NODE *)> aFunc, LIB_TREE_NODE **aHighScore)
 Find any results worth highlighting and expand them, according to given criteria The highest-scoring node is written to aHighScore. More...
 
LIB_TREE_NODEShowResults ()
 Find and expand successful search results. More...
 
LIB_TREE_NODEShowPreselect ()
 Find and expand preselected node. More...
 
LIB_TREE_NODEShowSingleLibrary ()
 Find and expand a library if there is only one. More...
 
wxDataViewColumn * doAddColumn (const wxString &aHeader, bool aTranslate=true)
 

Private Attributes

EDA_BASE_FRAMEm_parent
 
SYM_FILTER_TYPE m_filter
 
bool m_show_units
 
LIB_ID m_preselect_lib_id
 
int m_preselect_unit
 
int m_freeze
 
wxDataViewCtrl * m_widget
 
std::vector< wxDataViewColumn * > m_columns
 
std::map< wxString, wxDataViewColumn * > m_colNameMap
 
std::map< wxString, int > m_colWidths
 
std::vector< wxString > m_availableColumns
 
std::vector< wxString > m_shownColumns
 

Detailed Description

Definition at line 98 of file lib_tree_model_adapter.h.

Member Enumeration Documentation

◆ SYM_FILTER_TYPE

This enum allows a selective filtering of symbols to list.

Enumerator
SYM_FILTER_NONE 

no filtering

SYM_FILTER_POWER 

list symbols flagged PWR

Definition at line 120 of file lib_tree_model_adapter.h.

121 {
124 };
@ SYM_FILTER_POWER
list symbols flagged PWR

◆ TREE_COLS

This enum defines the order of the default columns in the tree view.

Enumerator
NAME_COL 

Library or library item name column.

DESC_COL 

Library or library description column.

NUM_COLS 

The number of default tree columns.

Definition at line 129 of file lib_tree_model_adapter.h.

130 {
131 NAME_COL = 0,
132 DESC_COL,
133 NUM_COLS
134 };
@ NUM_COLS
The number of default tree columns.
@ NAME_COL
Library or library item name column.
@ DESC_COL
Library or library description column.

Constructor & Destructor Documentation

◆ ~LIB_TREE_MODEL_ADAPTER()

LIB_TREE_MODEL_ADAPTER::~LIB_TREE_MODEL_ADAPTER ( )

Destructor.

Do NOT delete this class manually; it is reference-counted by wxObject.

Definition at line 97 of file lib_tree_model_adapter.cpp.

98{}

◆ LIB_TREE_MODEL_ADAPTER()

LIB_TREE_MODEL_ADAPTER::LIB_TREE_MODEL_ADAPTER ( EDA_BASE_FRAME aParent,
const wxString &  aPinnedKey 
)
protected

Create the adapter.

Parameters
aParentis the parent frame
aPinnedKeyis the key to load the pinned libraries list from the project file

Definition at line 67 of file lib_tree_model_adapter.cpp.

68 :
69 m_parent( aParent ),
71 m_show_units( true ),
73 m_freeze( 0 ),
74 m_widget( nullptr )
75{
76 // Default column widths. Do not translate these names.
77 m_colWidths[ wxT( "Item" ) ] = 300;
78 m_colWidths[ wxT( "Description" ) ] = 600;
79
80 m_availableColumns = { wxT( "Item" ), wxT( "Description" ) };
81
83
84 for( const std::pair<const wxString, int>& pair : cfg->m_LibTree.column_widths )
85 m_colWidths[pair.first] = pair.second;
86
88
89 if( m_shownColumns.empty() )
91
92 if( m_shownColumns[0] != wxT( "Item" ) )
93 m_shownColumns.insert( m_shownColumns.begin(), wxT( "Item" ) );
94}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:101
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:93
std::map< wxString, int > m_colWidths
std::vector< wxString > m_shownColumns
std::vector< wxString > m_availableColumns
std::vector< wxString > columns
Ordered list of visible columns in the tree.
Definition: app_settings.h:130
std::map< wxString, int > column_widths
Column widths, keyed by header name.
Definition: app_settings.h:131

References APP_SETTINGS_BASE::LIB_TREE::column_widths, APP_SETTINGS_BASE::LIB_TREE::columns, Kiface(), KIFACE_BASE::KifaceSettings(), m_availableColumns, m_colWidths, APP_SETTINGS_BASE::m_LibTree, and m_shownColumns.

Member Function Documentation

◆ AddColumn()

void LIB_TREE_MODEL_ADAPTER::AddColumn ( const wxString &  aHeader)
inline

Definition at line 184 of file lib_tree_model_adapter.h.

185 {
186 doAddColumn( aHeader, false );
187 }
wxDataViewColumn * doAddColumn(const wxString &aHeader, bool aTranslate=true)

References doAddColumn().

◆ addColumnIfNecessary()

void LIB_TREE_MODEL_ADAPTER::addColumnIfNecessary ( const wxString &  aHeader)
protected

Definition at line 335 of file lib_tree_model_adapter.cpp.

336{
337 if( m_colNameMap.count( aHeader ) )
338 return;
339
340 // Columns will be created later
341 m_colNameMap[aHeader] = nullptr;
342 m_availableColumns.emplace_back( aHeader );
343}
std::map< wxString, wxDataViewColumn * > m_colNameMap

References m_availableColumns, and m_colNameMap.

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries().

◆ AssignIntrinsicRanks()

void LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks ( )
inline

Sort the tree and assign ranks after adding libraries.

Definition at line 202 of file lib_tree_model_adapter.h.

void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.

References LIB_TREE_NODE::AssignIntrinsicRanks(), and m_tree.

Referenced by SCH_BASE_FRAME::PickSymbolFromLibTree().

◆ AttachTo()

void LIB_TREE_MODEL_ADAPTER::AttachTo ( wxDataViewCtrl *  aDataViewCtrl)

Attach to a wxDataViewCtrl and initialize it.

This will set up columns and associate the model via the adapter.

Parameters
aDataViewCtrlthe view symbol in the dialog

Definition at line 249 of file lib_tree_model_adapter.cpp.

250{
251 m_widget = aDataViewCtrl;
252 aDataViewCtrl->SetIndent( kDataViewIndent );
253 aDataViewCtrl->AssociateModel( this );
255}
static const int kDataViewIndent

References kDataViewIndent, m_widget, and recreateColumns().

◆ doAddColumn()

wxDataViewColumn * LIB_TREE_MODEL_ADAPTER::doAddColumn ( const wxString &  aHeader,
bool  aTranslate = true 
)
private

Definition at line 309 of file lib_tree_model_adapter.cpp.

310{
311 wxString translatedHeader = aTranslate ? wxGetTranslation( aHeader ) : aHeader;
312
313 // The extent of the text doesn't take into account the space on either side
314 // in the header, so artificially pad it
315 wxSize headerMinWidth = KIUI::GetTextSize( translatedHeader + wxT( "MMM" ), m_widget );
316
317 if( !m_colWidths.count( aHeader ) || m_colWidths[aHeader] < headerMinWidth.x )
318 m_colWidths[aHeader] = headerMinWidth.x;
319
320 int index = m_columns.size();
321
322 wxDataViewColumn* ret = m_widget->AppendTextColumn( translatedHeader, index,
323 wxDATAVIEW_CELL_INERT,
324 m_colWidths[aHeader] );
325 ret->SetMinWidth( headerMinWidth.x );
326
327 m_columns.emplace_back( ret );
328 m_colNameMap[aHeader] = ret;
329 m_colIdxMap[m_columns.size() - 1] = aHeader;
330
331 return ret;
332}
std::map< unsigned, wxString > m_colIdxMap
std::vector< wxDataViewColumn * > m_columns
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: ui_common.cpp:70

References KIUI::GetTextSize(), m_colIdxMap, m_colNameMap, m_columns, m_colWidths, and m_widget.

Referenced by AddColumn(), and recreateColumns().

◆ DoAddLibrary()

void LIB_TREE_MODEL_ADAPTER::DoAddLibrary ( const wxString &  aNodeName,
const wxString &  aDesc,
const std::vector< LIB_TREE_ITEM * > &  aItemList,
bool  pinned,
bool  presorted 
)

Add the given list of symbols by alias.

To be called in the setup phase.

Parameters
aNodeNamethe parent node the symbols will appear under
aDescthe description field of the parent node
aItemListlist of symbols

Definition at line 146 of file lib_tree_model_adapter.cpp.

149{
150 LIB_TREE_NODE_LIB& lib_node = DoAddLibraryNode( aNodeName, aDesc, pinned );
151
152 for( LIB_TREE_ITEM* item: aItemList )
153 lib_node.AddItem( item );
154
155 lib_node.AssignIntrinsicRanks( presorted );
156}
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:40
LIB_TREE_NODE_LIB & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc, bool pinned)
Node type: library.
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE::AssignIntrinsicRanks(), and DoAddLibraryNode().

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), FP_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), SCH_BASE_FRAME::PickSymbolFromLibTree(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ DoAddLibraryNode()

LIB_TREE_NODE_LIB & LIB_TREE_MODEL_ADAPTER::DoAddLibraryNode ( const wxString &  aNodeName,
const wxString &  aDesc,
bool  pinned 
)
protected

Definition at line 135 of file lib_tree_model_adapter.cpp.

137{
138 LIB_TREE_NODE_LIB& lib_node = m_tree.AddLib( aNodeName, aDesc );
139
140 lib_node.m_Pinned = pinned;
141
142 return lib_node;
143}
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.

References LIB_TREE_NODE_ROOT::AddLib(), LIB_TREE_NODE::m_Pinned, and m_tree.

Referenced by DoAddLibrary(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ Find()

void LIB_TREE_MODEL_ADAPTER::Find ( LIB_TREE_NODE aNode,
std::function< bool(const LIB_TREE_NODE *)>  aFunc,
LIB_TREE_NODE **  aHighScore 
)
private

Find any results worth highlighting and expand them, according to given criteria The highest-scoring node is written to aHighScore.

Definition at line 622 of file lib_tree_model_adapter.cpp.

625{
626 for( std::unique_ptr<LIB_TREE_NODE>& node: aNode.m_Children )
627 {
628 if( aFunc( &*node ) )
629 {
630 if( !(*aHighScore) || node->m_Score > (*aHighScore)->m_Score )
631 (*aHighScore) = &*node;
632 }
633
634 Find( *node, aFunc, aHighScore );
635 }
636}
void Find(LIB_TREE_NODE &aNode, std::function< bool(const LIB_TREE_NODE *)> aFunc, LIB_TREE_NODE **aHighScore)
Find any results worth highlighting and expand them, according to given criteria The highest-scoring ...
PTR_VECTOR m_Children

References Find(), and LIB_TREE_NODE::m_Children.

Referenced by Find(), ShowPreselect(), ShowResults(), and ShowSingleLibrary().

◆ FindItem()

wxDataViewItem LIB_TREE_MODEL_ADAPTER::FindItem ( const LIB_ID aLibId)

Returns tree item corresponding to part.

Parameters
aLibIdspecifies the part and library name to be searched for.
Returns
Tree data item representing the part. Might be invalid if nothings was found.

Definition at line 401 of file lib_tree_model_adapter.cpp.

402{
403 for( std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
404 {
405 if( lib->m_Name != aLibId.GetLibNickname() )
406 continue;
407
408 // if part name is not specified, return the library node
409 if( aLibId.GetLibItemName() == "" )
410 return ToItem( lib.get() );
411
412 for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
413 {
414 if( alias->m_Name == aLibId.GetLibItemName() )
415 return ToItem( alias.get() );
416 }
417
418 break; // could not find the part in the requested library
419 }
420
421 return wxDataViewItem();
422}
const UTF8 & GetLibItemName() const
Definition: lib_id.h:101
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.

References LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_TREE_NODE::m_Children, m_tree, and ToItem().

◆ FinishTreeInitialization()

void LIB_TREE_MODEL_ADAPTER::FinishTreeInitialization ( )

A final-stage initialization to be called after the window hierarchy has been realized and the window sizes set.

Definition at line 444 of file lib_tree_model_adapter.cpp.

445{
446 wxDataViewColumn* col = nullptr;
447 size_t idx = 0;
448 int totalWidth = 0;
449 wxString header;
450
451 for( ; idx < m_columns.size() - 1; idx++ )
452 {
453 wxASSERT( m_colIdxMap.count( idx ) );
454
455 col = m_columns[idx];
456 header = m_colIdxMap[idx];
457
458 wxASSERT( m_colWidths.count( header ) );
459
460 col->SetWidth( m_colWidths[header] );
461 totalWidth += col->GetWidth();
462 }
463
464 int remainingWidth = m_widget->GetSize().x - totalWidth;
465 header = m_columns[idx]->GetTitle();
466
467 m_columns[idx]->SetWidth( std::max( m_colWidths[header], remainingWidth ) );
468}

References m_colIdxMap, m_columns, m_colWidths, and m_widget.

◆ Freeze()

void LIB_TREE_MODEL_ADAPTER::Freeze ( )
inline

Definition at line 294 of file lib_tree_model_adapter.h.

294{ m_freeze++; }

References m_freeze.

Referenced by resortTree(), and UpdateSearchString().

◆ GenerateInfo()

virtual wxString LIB_TREE_MODEL_ADAPTER::GenerateInfo ( const LIB_ID aLibId,
int  aUnit 
)
inlinevirtual

Reimplemented in SYMBOL_TREE_MODEL_ADAPTER, and FP_TREE_MODEL_ADAPTER.

Definition at line 260 of file lib_tree_model_adapter.h.

260{ return wxEmptyString; };

◆ GetAliasFor()

LIB_ID LIB_TREE_MODEL_ADAPTER::GetAliasFor ( const wxDataViewItem &  aSelection) const

Return the alias for the given item.

Parameters
aSelectionitem from the wxDataViewCtrl (see wxDataViewCtrl::GetSelection())
Returns
alias, or nullptr if none is selected

Definition at line 357 of file lib_tree_model_adapter.cpp.

358{
359 const LIB_TREE_NODE* node = ToNode( aSelection );
360
361 LIB_ID emptyId;
362
363 if( !node )
364 return emptyId;
365
366 return node->m_LibId;
367}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.

References LIB_TREE_NODE::m_LibId, and ToNode().

◆ GetAttr()

bool LIB_TREE_MODEL_ADAPTER::GetAttr ( const wxDataViewItem &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotected

Get any formatting for an item.

Parameters
aItemitem to get formatting for
aColcolumn number of interest
aAttrreceiver for attributes
Returns
true if the item has non-default attributes

Definition at line 593 of file lib_tree_model_adapter.cpp.

596{
597 if( IsFrozen() )
598 return false;
599
600 LIB_TREE_NODE* node = ToNode( aItem );
601 wxASSERT( node );
602
603 if( node->m_Type != LIB_TREE_NODE::LIBID )
604 {
605 // Currently only aliases are formatted at all
606 return false;
607 }
608
609 if( !node->m_IsRoot && aCol == 0 )
610 {
611 // Names of non-root aliases are italicized
612 aAttr.SetItalic( true );
613 return true;
614 }
615 else
616 {
617 return false;
618 }
619}
enum TYPE m_Type

References IsFrozen(), LIB_TREE_NODE::LIBID, LIB_TREE_NODE::m_IsRoot, LIB_TREE_NODE::m_Type, and ToNode().

◆ GetAvailableColumns()

std::vector< wxString > LIB_TREE_MODEL_ADAPTER::GetAvailableColumns ( ) const
inline

Definition at line 189 of file lib_tree_model_adapter.h.

189{ return m_availableColumns; }

References m_availableColumns.

◆ GetChildren()

unsigned int LIB_TREE_MODEL_ADAPTER::GetChildren ( const wxDataViewItem &  aItem,
wxDataViewItemArray &  aChildren 
) const
override

Populate a list of all the children of an item.

Returns
number of children

Definition at line 425 of file lib_tree_model_adapter.cpp.

427{
428 const LIB_TREE_NODE* node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
429
430 if( node->m_Type == LIB_TREE_NODE::TYPE::ROOT
431 || node->m_Type == LIB_TREE_NODE::LIB
432 || ( m_show_units && node->m_Type == LIB_TREE_NODE::TYPE::LIBID ) )
433 {
434 return IntoArray( *node, aChildren );
435 }
436 else
437 {
438 return 0;
439 }
440
441}
static unsigned int IntoArray(const LIB_TREE_NODE &aNode, wxDataViewItemArray &aChildren)
Convert SYM_TREE_NODE's children to wxDataViewItemArray.

References IntoArray(), LIB_TREE_NODE::LIB, m_show_units, m_tree, LIB_TREE_NODE::m_Type, and ToNode().

◆ GetColumnCount()

unsigned int LIB_TREE_MODEL_ADAPTER::GetColumnCount ( ) const
inlineoverrideprotected

Definition at line 350 of file lib_tree_model_adapter.h.

350{ return m_columns.size(); }

References m_columns.

◆ GetColumnType()

wxString LIB_TREE_MODEL_ADAPTER::GetColumnType ( unsigned int  aCol) const
inlineoverrideprotected

Return the type of data stored in the column as indicated by wxVariant::GetType()

Definition at line 355 of file lib_tree_model_adapter.h.

355{ return "string"; }

◆ GetContextMenuTool()

virtual TOOL_INTERACTIVE * LIB_TREE_MODEL_ADAPTER::GetContextMenuTool ( )
inlinevirtual

Reimplemented in SYMBOL_TREE_SYNCHRONIZING_ADAPTER, and FP_TREE_SYNCHRONIZING_ADAPTER.

Definition at line 301 of file lib_tree_model_adapter.h.

301{ return nullptr; }

◆ GetFilter()

SYM_FILTER_TYPE LIB_TREE_MODEL_ADAPTER::GetFilter ( ) const
inline

Return the active filter.

Definition at line 153 of file lib_tree_model_adapter.h.

153{ return m_filter; }

References m_filter.

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), and SCH_BASE_FRAME::PickSymbolFromLibTree().

◆ GetItemCount()

int LIB_TREE_MODEL_ADAPTER::GetItemCount ( ) const

Return the number of symbols loaded in the tree.

Definition at line 390 of file lib_tree_model_adapter.cpp.

391{
392 int n = 0;
393
394 for( const std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
395 n += lib->m_Children.size();
396
397 return n;
398}

References LIB_TREE_NODE::m_Children, and m_tree.

Referenced by SYMBOL_VIEWER_FRAME::OnSelectSymbol(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ GetLibrariesCount()

virtual int LIB_TREE_MODEL_ADAPTER::GetLibrariesCount ( ) const
inlinevirtual

Return the number of libraries loaded in the tree.

Reimplemented in SYMBOL_TREE_SYNCHRONIZING_ADAPTER, and FP_TREE_SYNCHRONIZING_ADAPTER.

Definition at line 270 of file lib_tree_model_adapter.h.

271 {
272 return m_tree.m_Children.size();
273 }

References LIB_TREE_NODE::m_Children, and m_tree.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount().

◆ GetParent()

wxDataViewItem LIB_TREE_MODEL_ADAPTER::GetParent ( const wxDataViewItem &  aItem) const
overrideprotected

Get the parent of an item.

Returns
parent of aItem, or an invalid wxDataViewItem if parent is root

Definition at line 535 of file lib_tree_model_adapter.cpp.

536{
537 if( m_freeze )
538 return ToItem( nullptr );
539
540 LIB_TREE_NODE* node = ToNode( aItem );
541 LIB_TREE_NODE* parent = node ? node->m_Parent : nullptr;
542
543 // wxDataViewModel has no root node, but rather top-level elements have
544 // an invalid (null) parent.
545 if( !node || !parent || parent->m_Type == LIB_TREE_NODE::TYPE::ROOT )
546 return ToItem( nullptr );
547 else
548 return ToItem( parent );
549}
LIB_TREE_NODE * m_Parent

References m_freeze, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Type, ToItem(), and ToNode().

Referenced by UpdateSearchString().

◆ GetPinningSymbol()

◆ GetShownColumns()

std::vector< wxString > LIB_TREE_MODEL_ADAPTER::GetShownColumns ( ) const
inline

Definition at line 191 of file lib_tree_model_adapter.h.

191{ return m_shownColumns; }

References m_shownColumns.

Referenced by SaveSettings().

◆ GetTreeNodeFor()

LIB_TREE_NODE * LIB_TREE_MODEL_ADAPTER::GetTreeNodeFor ( const wxDataViewItem &  aSelection) const

Definition at line 384 of file lib_tree_model_adapter.cpp.

385{
386 return ToNode( aSelection );
387}

References ToNode().

◆ GetTypeFor()

LIB_TREE_NODE::TYPE LIB_TREE_MODEL_ADAPTER::GetTypeFor ( const wxDataViewItem &  aSelection) const

Return node type for the given item.

Parameters
aSelectionitem from the wxDataViewCtrl (see wxDataViewCtrl::GetSelection())
Returns
Type of the selected node, might be INVALID.

Definition at line 377 of file lib_tree_model_adapter.cpp.

378{
379 const LIB_TREE_NODE* node = ToNode( aSelection );
380 return node ? node->m_Type : LIB_TREE_NODE::INVALID;
381}

References LIB_TREE_NODE::INVALID, LIB_TREE_NODE::m_Type, and ToNode().

◆ GetUnitFor()

int LIB_TREE_MODEL_ADAPTER::GetUnitFor ( const wxDataViewItem &  aSelection) const

Return the unit for the given item.

Parameters
aSelectionitem from the wxDataViewCtrl (see wxDataViewCtrl::GetSelection())
Returns
Unit, or zero if the alias itself is selected. Return valid is invalid if GetAliasFor() returns nullptr.

Definition at line 370 of file lib_tree_model_adapter.cpp.

371{
372 const LIB_TREE_NODE* node = ToNode( aSelection );
373 return node ? node->m_Unit : 0;
374}

References LIB_TREE_NODE::m_Unit, and ToNode().

◆ GetValue()

void LIB_TREE_MODEL_ADAPTER::GetValue ( wxVariant &  aVariant,
const wxDataViewItem &  aItem,
unsigned int  aCol 
) const
overrideprotected

Get the value of an item.

Parameters
aVariantwxVariant to receive the data
aItemitem whose data will be placed into aVariant
aColcolumn number of the data

Definition at line 552 of file lib_tree_model_adapter.cpp.

555{
556 if( IsFrozen() )
557 {
558 aVariant = wxEmptyString;
559 return;
560 }
561
562 LIB_TREE_NODE* node = ToNode( aItem );
563 wxASSERT( node );
564
565 switch( aCol )
566 {
567 case NAME_COL:
568 if( node->m_Pinned )
569 aVariant = GetPinningSymbol() + UnescapeString( node->m_Name );
570 else
571 aVariant = UnescapeString( node->m_Name );
572
573 break;
574
575 default:
576 if( m_colIdxMap.count( aCol ) )
577 {
578 const wxString& key = m_colIdxMap.at( aCol );
579
580 if( node->m_Fields.count( key ) )
581 aVariant = node->m_Fields.at( key );
582 else if( key == wxT( "Description" ) )
583 aVariant = node->m_Desc;
584 else
585 aVariant = wxEmptyString;
586 }
587
588 break;
589 }
590}
static const wxString GetPinningSymbol()
std::map< wxString, wxString > m_Fields
wxString UnescapeString(const wxString &aSource)

References GetPinningSymbol(), IsFrozen(), m_colIdxMap, LIB_TREE_NODE::m_Desc, LIB_TREE_NODE::m_Fields, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Pinned, NAME_COL, ToNode(), and UnescapeString().

◆ HasContainerColumns()

bool LIB_TREE_MODEL_ADAPTER::HasContainerColumns ( const wxDataViewItem &  aItem) const
overrideprotected

Check whether a container has columns too.

Definition at line 522 of file lib_tree_model_adapter.cpp.

523{
524 return IsContainer( aItem );
525}
bool IsContainer(const wxDataViewItem &aItem) const override
Check whether an item can have children.

References IsContainer().

◆ IntoArray()

unsigned int LIB_TREE_MODEL_ADAPTER::IntoArray ( const LIB_TREE_NODE aNode,
wxDataViewItemArray &  aChildren 
)
staticprotected

Convert SYM_TREE_NODE's children to wxDataViewItemArray.

Definition at line 49 of file lib_tree_model_adapter.cpp.

51{
52 unsigned int n = 0;
53
54 for( std::unique_ptr<LIB_TREE_NODE> const& child: aNode.m_Children )
55 {
56 if( child->m_Score > 0 )
57 {
58 aChildren.Add( ToItem( &*child ) );
59 ++n;
60 }
61 }
62
63 return n;
64}

References LIB_TREE_NODE::m_Children, and ToItem().

Referenced by GetChildren().

◆ IsContainer()

bool LIB_TREE_MODEL_ADAPTER::IsContainer ( const wxDataViewItem &  aItem) const
overrideprotected

Check whether an item can have children.

Definition at line 528 of file lib_tree_model_adapter.cpp.

529{
530 LIB_TREE_NODE* node = ToNode( aItem );
531 return node ? node->m_Children.size() : true;
532}

References LIB_TREE_NODE::m_Children, and ToNode().

Referenced by HasContainerColumns().

◆ IsFrozen()

◆ isSymbolModel()

virtual bool LIB_TREE_MODEL_ADAPTER::isSymbolModel ( )
protectedpure virtual

◆ OnSize()

void LIB_TREE_MODEL_ADAPTER::OnSize ( wxSizeEvent &  aEvent)

Definition at line 471 of file lib_tree_model_adapter.cpp.

472{
473 aEvent.Skip();
474}

◆ PinLibrary()

void LIB_TREE_MODEL_ADAPTER::PinLibrary ( LIB_TREE_NODE aTreeNode)

Definition at line 289 of file lib_tree_model_adapter.cpp.

290{
292 aTreeNode->m_Pinned = true;
293
294 resortTree();
295 m_widget->EnsureVisible( ToItem( aTreeNode ) );
296}
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual bool isSymbolModel()=0
void PinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Definition: project.cpp:156

References LIB_ID::GetLibNickname(), isSymbolModel(), LIB_TREE_NODE::m_LibId, m_parent, LIB_TREE_NODE::m_Pinned, m_widget, PROJECT::PinLibrary(), KIWAY_HOLDER::Prj(), resortTree(), and ToItem().

◆ recreateColumns()

void LIB_TREE_MODEL_ADAPTER::recreateColumns ( )
protected

Definition at line 258 of file lib_tree_model_adapter.cpp.

259{
260 m_widget->ClearColumns();
261
262 m_columns.clear();
263 m_colIdxMap.clear();
264 m_colNameMap.clear();
265
266 // The Item column is always shown
267 doAddColumn( wxT( "Item" ) );
268
269 for( const wxString& colName : m_shownColumns )
270 {
271 if( !m_colNameMap.count( colName ) )
272 doAddColumn( colName, false );
273 }
274}

References doAddColumn(), m_colIdxMap, m_colNameMap, m_columns, m_shownColumns, and m_widget.

Referenced by AttachTo(), and SetShownColumns().

◆ RefreshTree()

void LIB_TREE_MODEL_ADAPTER::RefreshTree ( )

Definition at line 477 of file lib_tree_model_adapter.cpp.

478{
479 // Yes, this is an enormous hack. But it works on all platforms, it doesn't suffer
480 // the On^2 sorting issues that ItemChanged() does on OSX, and it doesn't lose the
481 // user's scroll position (which re-attaching or deleting/re-inserting columns does).
482 static int walk = 1;
483
484 std::vector<int> widths;
485
486 for( const wxDataViewColumn* col : m_columns )
487 widths.emplace_back( col->GetWidth() );
488
489 wxASSERT( widths.size() );
490
491 // Only use the widths read back if they are non-zero.
492 // GTK returns the displayed width of the column, which is not calculated immediately
493 if( widths[0] > 0 )
494 {
495 size_t i = 0;
496
497 for( const auto& [ colName, colPtr ] : m_colNameMap )
498 m_colWidths[ colName ] = widths[i++];
499 }
500
501 auto colIt = m_colWidths.begin();
502
503 colIt->second += walk;
504 colIt++;
505
506 if( colIt != m_colWidths.end() )
507 colIt->second -= walk;
508
509 for( const auto& [ colName, colPtr ] : m_colNameMap )
510 {
511 if( colPtr == m_columns[0] )
512 continue;
513
514 wxASSERT( m_colWidths.count( colName ) );
515 colPtr->SetWidth( m_colWidths[ colName ] );
516 }
517
518 walk = -walk;
519}

References m_colNameMap, m_columns, and m_colWidths.

◆ resortTree()

void LIB_TREE_MODEL_ADAPTER::resortTree ( )
protected

Definition at line 277 of file lib_tree_model_adapter.cpp.

278{
279 Freeze();
280 BeforeReset();
281
283
284 AfterReset();
285 Thaw();
286}
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).

References Freeze(), m_tree, LIB_TREE_NODE::SortNodes(), and Thaw().

Referenced by PinLibrary(), and UnpinLibrary().

◆ SaveSettings()

void LIB_TREE_MODEL_ADAPTER::SaveSettings ( )

Save the column widths to the config file.

This requires the tree view to still be valid.

Definition at line 101 of file lib_tree_model_adapter.cpp.

102{
103 if( m_widget )
104 {
106
108 cfg->m_LibTree.column_widths.clear();
109
110 for( const std::pair<const wxString, wxDataViewColumn*>& pair : m_colNameMap )
111 cfg->m_LibTree.column_widths[pair.first] = pair.second->GetWidth();
112 }
113}
std::vector< wxString > GetShownColumns() const

References APP_SETTINGS_BASE::LIB_TREE::column_widths, APP_SETTINGS_BASE::LIB_TREE::columns, GetShownColumns(), Kiface(), KIFACE_BASE::KifaceSettings(), m_colNameMap, APP_SETTINGS_BASE::m_LibTree, and m_widget.

Referenced by SYMBOL_VIEWER_FRAME::OnSelectSymbol(), SCH_BASE_FRAME::PickSymbolFromLibTree(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ SetFilter()

void LIB_TREE_MODEL_ADAPTER::SetFilter ( SYM_FILTER_TYPE  aFilter)

Set the symbol filter type.

Must be set before adding libraries

Parameters
aFilterif SYM_FILTER_POWER, only power parts are loaded

Definition at line 116 of file lib_tree_model_adapter.cpp.

117{
118 m_filter = aFilter;
119}

References m_filter.

Referenced by SCH_BASE_FRAME::PickSymbolFromLibTree().

◆ SetPreselectNode()

void LIB_TREE_MODEL_ADAPTER::SetPreselectNode ( const LIB_ID aLibId,
int  aUnit 
)

Set the symbol name to be selected if there are no search results.

May be set at any time; updates at the next UpdateSearchString().

Parameters
aLibIdsymbol LIB_ID to be selected
aUnitunit to be selected, if > 0 (0 selects the alias itself)

Definition at line 128 of file lib_tree_model_adapter.cpp.

129{
130 m_preselect_lib_id = aLibId;
131 m_preselect_unit = aUnit;
132}

References m_preselect_lib_id, and m_preselect_unit.

Referenced by SYMBOL_VIEWER_FRAME::OnSelectSymbol(), SCH_BASE_FRAME::PickSymbolFromLibTree(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ SetShownColumns()

void LIB_TREE_MODEL_ADAPTER::SetShownColumns ( const std::vector< wxString > &  aColumnNames)

Sets which columns are shown in the widget.

Invalid column names are discarded.

Parameters
aColumnNamesis an ordered list of column names to show

Definition at line 346 of file lib_tree_model_adapter.cpp.

347{
348 bool recreate = m_shownColumns != aColumnNames;
349
350 m_shownColumns = aColumnNames;
351
352 if( recreate && m_widget )
354}

References m_shownColumns, m_widget, and recreateColumns().

◆ SetValue()

bool LIB_TREE_MODEL_ADAPTER::SetValue ( const wxVariant &  aVariant,
const wxDataViewItem &  aItem,
unsigned int  aCol 
)
inlineoverrideprotected

Set the value of an item.

Does nothing - this model doesn't support editing.

Definition at line 372 of file lib_tree_model_adapter.h.

374 { return false; }

◆ ShowPreselect()

LIB_TREE_NODE * LIB_TREE_MODEL_ADAPTER::ShowPreselect ( )
private

Find and expand preselected node.

Return the best match (if any).

Definition at line 661 of file lib_tree_model_adapter.cpp.

662{
663 LIB_TREE_NODE* highScore = nullptr;
664
666 return highScore;
667
668 Find( m_tree,
669 [&]( LIB_TREE_NODE const* n )
670 {
671 if( n->m_Type == LIB_TREE_NODE::LIBID && ( n->m_Children.empty() ||
673 return m_preselect_lib_id == n->m_LibId;
675 return m_preselect_lib_id == n->m_Parent->m_LibId &&
677 else
678 return false;
679 },
680 &highScore );
681
682 if( highScore)
683 {
684 wxDataViewItem item = wxDataViewItem( highScore );
685 m_widget->ExpandAncestors( item );
686 }
687
688 return highScore;
689}
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:165

References Find(), LIB_ID::IsValid(), LIB_TREE_NODE::LIBID, LIB_TREE_NODE::m_Children, LIB_TREE_NODE::m_LibId, LIB_TREE_NODE::m_Parent, m_preselect_lib_id, m_preselect_unit, m_tree, LIB_TREE_NODE::m_Type, LIB_TREE_NODE::m_Unit, m_widget, and LIB_TREE_NODE::UNIT.

Referenced by UpdateSearchString().

◆ ShowResults()

LIB_TREE_NODE * LIB_TREE_MODEL_ADAPTER::ShowResults ( )
private

Find and expand successful search results.

Return the best match (if any).

Definition at line 639 of file lib_tree_model_adapter.cpp.

640{
641 LIB_TREE_NODE* highScore = nullptr;
642
643 Find( m_tree,
644 []( LIB_TREE_NODE const* n )
645 {
646 // return leaf nodes with some level of matching
647 return n->m_Type == LIB_TREE_NODE::TYPE::LIBID && n->m_Score > 1;
648 },
649 &highScore );
650
651 if( highScore)
652 {
653 wxDataViewItem item = wxDataViewItem( highScore );
654 m_widget->ExpandAncestors( item );
655 }
656
657 return highScore;
658}

References Find(), LIB_TREE_NODE::m_Score, m_tree, LIB_TREE_NODE::m_Type, and m_widget.

Referenced by UpdateSearchString().

◆ ShowSingleLibrary()

LIB_TREE_NODE * LIB_TREE_MODEL_ADAPTER::ShowSingleLibrary ( )
private

Find and expand a library if there is only one.

Return the best match (if any).

Definition at line 692 of file lib_tree_model_adapter.cpp.

693{
694 LIB_TREE_NODE* highScore = nullptr;
695
696 Find( m_tree,
697 []( LIB_TREE_NODE const* n )
698 {
699 return n->m_Type == LIB_TREE_NODE::TYPE::LIBID &&
700 n->m_Parent->m_Parent->m_Children.size() == 1;
701 },
702 &highScore );
703
704 if( highScore)
705 {
706 wxDataViewItem item = wxDataViewItem( highScore );
707 m_widget->ExpandAncestors( item );
708 }
709
710 return highScore;
711}

References Find(), LIB_TREE_NODE::m_Children, LIB_TREE_NODE::m_Parent, m_tree, LIB_TREE_NODE::m_Type, and m_widget.

Referenced by UpdateSearchString().

◆ ShowUnits()

void LIB_TREE_MODEL_ADAPTER::ShowUnits ( bool  aShow)

Whether or not to show units.

May be set at any time; updates at the next UpdateSearchString()

Parameters
aShowif true, units are displayed

Definition at line 122 of file lib_tree_model_adapter.cpp.

123{
124 m_show_units = aShow;
125}

References m_show_units.

◆ Thaw()

void LIB_TREE_MODEL_ADAPTER::Thaw ( )
inline

Definition at line 295 of file lib_tree_model_adapter.h.

295{ m_freeze--; }

References m_freeze.

Referenced by resortTree(), and UpdateSearchString().

◆ ToItem()

wxDataViewItem LIB_TREE_MODEL_ADAPTER::ToItem ( const LIB_TREE_NODE aNode)
staticprotected

Convert #SYM_TREE_NODE -> wxDataViewItem.

Definition at line 37 of file lib_tree_model_adapter.cpp.

38{
39 return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
40}

Referenced by FindItem(), GetParent(), IntoArray(), and PinLibrary().

◆ ToNode()

◆ UnpinLibrary()

void LIB_TREE_MODEL_ADAPTER::UnpinLibrary ( LIB_TREE_NODE aTreeNode)

Definition at line 299 of file lib_tree_model_adapter.cpp.

300{
302 aTreeNode->m_Pinned = false;
303
304 resortTree();
305 // Keep focus at top when unpinning
306}
void UnpinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Definition: project.cpp:177

References LIB_ID::GetLibNickname(), isSymbolModel(), LIB_TREE_NODE::m_LibId, m_parent, LIB_TREE_NODE::m_Pinned, KIWAY_HOLDER::Prj(), resortTree(), and PROJECT::UnpinLibrary().

◆ UpdateSearchString()

void LIB_TREE_MODEL_ADAPTER::UpdateSearchString ( const wxString &  aSearch,
bool  aState 
)

Set the search string provided by the user.

Parameters
aSearchfull, unprocessed search text
aStateif true, we are keeping the state and so we shouldn't collapse the tree

Definition at line 159 of file lib_tree_model_adapter.cpp.

160{
161 {
162 wxWindowUpdateLocker updateLock( m_widget );
163
164 // Even with the updateLock, wxWidgets sometimes ties its knickers in a knot trying to
165 // run a wxdataview_selection_changed_callback() on a row that has been deleted.
166 // https://bugs.launchpad.net/kicad/+bug/1756255
167 m_widget->UnselectAll();
168
169 // This collapse is required before the call to "Freeze()" below. Once Freeze()
170 // is called, GetParent() will return nullptr. While this works for some calls, it
171 // segfaults when we have any expanded elements b/c the sub units in the tree don't
172 // have explicit references that are maintained over a search
173 // The tree will be expanded again below when we get our matches
174 //
175 // Also note that this cannot happen when we have deleted a symbol as GTK will also
176 // iterate over the tree in this case and find a symbol that has an invalid link
177 // and crash https://gitlab.com/kicad/code/kicad/-/issues/6910
178 if( !aState && !aSearch.IsNull() && m_tree.m_Children.size() )
179 {
180 for( std::unique_ptr<LIB_TREE_NODE>& child: m_tree.m_Children )
181 m_widget->Collapse( wxDataViewItem( &*child ) );
182 }
183
184 // DO NOT REMOVE THE FREEZE/THAW. This freeze/thaw is a flag for this model adapter
185 // that tells it when it shouldn't trust any of the data in the model. When set, it will
186 // not return invalid data to the UI, since this invalid data can cause crashes.
187 // This is different than the update locker, which locks the UI aspects only.
188 Freeze();
189 BeforeReset();
190
192
193 wxStringTokenizer tokenizer( aSearch );
194
195 while( tokenizer.HasMoreTokens() )
196 {
197 wxString lib;
198 wxString term = tokenizer.GetNextToken().Lower();
199
200 if( term.Contains( ":" ) )
201 {
202 lib = term.BeforeFirst( ':' );
203 term = term.AfterFirst( ':' );
204 }
205
206 EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
207
208 m_tree.UpdateScore( matcher, lib );
209 }
210
212 AfterReset();
213 Thaw();
214 }
215
216 LIB_TREE_NODE* bestMatch = ShowResults();
217
218 if( !bestMatch )
219 bestMatch = ShowPreselect();
220
221 if( !bestMatch )
222 bestMatch = ShowSingleLibrary();
223
224 if( bestMatch )
225 {
226 wxDataViewItem item = wxDataViewItem( bestMatch );
227 m_widget->Select( item );
228
229 // Make sure the *parent* item is visible. The selected item is the
230 // first (shown) child of the parent. So it's always right below the parent,
231 // and this way the user can also see what library the selected part belongs to,
232 // without having a case where the selection is off the screen (unless the
233 // window is a single row high, which is unlikely)
234 //
235 // This also happens to circumvent https://bugs.launchpad.net/kicad/+bug/1804400
236 // which appears to be a GTK+3 bug.
237 {
238 wxDataViewItem parent = GetParent( item );
239
240 if( parent.IsOk() )
241 m_widget->EnsureVisible( parent );
242 }
243
244 m_widget->EnsureVisible( item );
245 }
246}
LIB_TREE_NODE * ShowPreselect()
Find and expand preselected node.
LIB_TREE_NODE * ShowSingleLibrary()
Find and expand a library if there is only one.
wxDataViewItem GetParent(const wxDataViewItem &aItem) const override
Get the parent of an item.
LIB_TREE_NODE * ShowResults()
Find and expand successful search results.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
Update the score for this part.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
@ CTX_LIBITEM

References CTX_LIBITEM, Freeze(), GetParent(), LIB_TREE_NODE::m_Children, m_tree, m_widget, LIB_TREE_NODE::ResetScore(), ShowPreselect(), ShowResults(), ShowSingleLibrary(), LIB_TREE_NODE::SortNodes(), Thaw(), and LIB_TREE_NODE_ROOT::UpdateScore().

Member Data Documentation

◆ m_availableColumns

std::vector<wxString> LIB_TREE_MODEL_ADAPTER::m_availableColumns
private

◆ m_colIdxMap

std::map<unsigned, wxString> LIB_TREE_MODEL_ADAPTER::m_colIdxMap
protected

◆ m_colNameMap

std::map<wxString, wxDataViewColumn*> LIB_TREE_MODEL_ADAPTER::m_colNameMap
private

◆ m_columns

std::vector<wxDataViewColumn*> LIB_TREE_MODEL_ADAPTER::m_columns
private

◆ m_colWidths

std::map<wxString, int> LIB_TREE_MODEL_ADAPTER::m_colWidths
private

◆ m_filter

SYM_FILTER_TYPE LIB_TREE_MODEL_ADAPTER::m_filter
private

Definition at line 428 of file lib_tree_model_adapter.h.

Referenced by GetFilter(), and SetFilter().

◆ m_freeze

int LIB_TREE_MODEL_ADAPTER::m_freeze
private

Definition at line 432 of file lib_tree_model_adapter.h.

Referenced by Freeze(), GetParent(), IsFrozen(), and Thaw().

◆ m_parent

EDA_BASE_FRAME* LIB_TREE_MODEL_ADAPTER::m_parent
private

Definition at line 426 of file lib_tree_model_adapter.h.

Referenced by PinLibrary(), and UnpinLibrary().

◆ m_preselect_lib_id

LIB_ID LIB_TREE_MODEL_ADAPTER::m_preselect_lib_id
private

Definition at line 430 of file lib_tree_model_adapter.h.

Referenced by SetPreselectNode(), and ShowPreselect().

◆ m_preselect_unit

int LIB_TREE_MODEL_ADAPTER::m_preselect_unit
private

Definition at line 431 of file lib_tree_model_adapter.h.

Referenced by SetPreselectNode(), and ShowPreselect().

◆ m_show_units

bool LIB_TREE_MODEL_ADAPTER::m_show_units
private

Definition at line 429 of file lib_tree_model_adapter.h.

Referenced by GetChildren(), and ShowUnits().

◆ m_shownColumns

std::vector<wxString> LIB_TREE_MODEL_ADAPTER::m_shownColumns
private

◆ m_tree

◆ m_widget


The documentation for this class was generated from the following files: