KiCad PCB EDA Suite
Loading...
Searching...
No Matches
LIB_TREE Class Reference

Widget displaying a tree of symbols with optional search text control and description panel. More...

#include <lib_tree.h>

Inheritance diagram for LIB_TREE:

Classes

struct  STATE
 Structure storing state of the symbol tree widget. More...
 

Public Types

enum  FLAGS {
  FLAGS_NONE = 0x00 , SEARCH = 0x01 , FILTERS = 0x02 , DETAILS = 0x04 ,
  ALL_WIDGETS = 0x0F , MULTISELECT = 0x10
}
 Flags to select extra widgets and options. More...
 

Public Member Functions

 LIB_TREE (wxWindow *aParent, const wxString &aRecentSearchesKey, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, int aFlags=ALL_WIDGETS, HTML_WINDOW *aDetails=nullptr)
 Construct a symbol tree.
 
 ~LIB_TREE () override
 
LIB_ID GetSelectedLibId (int *aUnit=nullptr) const
 For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit, 0 will be returned in aUnit.
 
int GetSelectionCount () const
 
int GetSelectedLibIds (std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
 Retrieve a list of selections for trees that allow multi-selection.
 
LIB_TREE_NODE * GetCurrentTreeNode () const
 Retrieve the tree node for the first selected item.
 
int GetSelectedTreeNodes (std::vector< LIB_TREE_NODE * > &aSelection) const
 Retrieve a list of pointers to selected tree nodes for trees that allow multi-selection.
 
void SelectLibId (const LIB_ID &aLibId)
 Select an item in the tree widget.
 
void CenterLibId (const LIB_ID &aLibId)
 Ensure that an item is visible (preferably centered).
 
void Unselect ()
 Unselect currently selected item in wxDataViewCtrl.
 
void ExpandLibId (const LIB_ID &aLibId)
 Expand and item i the tree widget.
 
std::vector< LIB_ID > GetExpandedLibraries () const
 
void ExpandAll ()
 
void CollapseAll ()
 
void SetSearchString (const wxString &aSearchString)
 Save/restore search string.
 
wxString GetSearchString () const
 
void SetSortMode (LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
 Save/restore the sorting mode.
 
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode () const
 
void Regenerate (bool aKeepState)
 Regenerate the tree.
 
void RefreshLibTree ()
 Refresh the tree (mainly to update highlighting and asterisking)
 
wxWindow * GetFocusTarget ()
 
wxSizer * GetFiltersSizer ()
 
void FocusSearchFieldIfExists ()
 Focus the search widget if it exists.
 
void ShowChangedLanguage ()
 
void BlockPreview (bool aBlock)
 
void ShutdownPreviews ()
 

Protected Member Functions

void toggleExpand (const wxDataViewItem &aTreeId)
 Expand or collapse a node, switching it to the opposite state.
 
void selectIfValid (const wxDataViewItem &aTreeId)
 If a wxDataViewitem is valid, select it and post a selection event.
 
void centerIfValid (const wxDataViewItem &aTreeId)
 
void expandIfValid (const wxDataViewItem &aTreeId)
 
void postPreselectEvent ()
 Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been preselected.
 
void postSelectEvent ()
 Post EVT_LIBITEM_CHOSEN event to notify the selection handler that a part has been selected.
 
STATE getState () const
 Return the symbol tree widget state.
 
void setState (const STATE &aState)
 Restore the symbol tree widget state from an object.
 
void updateRecentSearchMenu ()
 
void showPreview (wxDataViewItem aItem)
 
void hidePreview ()
 
void onQueryText (wxCommandEvent &aEvent)
 
void onQueryCharHook (wxKeyEvent &aEvent)
 
void onQueryMouseMoved (wxMouseEvent &aEvent)
 
void onTreeSelect (wxDataViewEvent &aEvent)
 
void onTreeActivate (wxDataViewEvent &aEvent)
 
void onTreeCharHook (wxKeyEvent &aEvent)
 
void onIdle (wxIdleEvent &aEvent)
 
void onDetailsLink (wxHtmlLinkEvent &aEvent)
 
void onPreselect (wxCommandEvent &aEvent)
 
void onItemContextMenu (wxDataViewEvent &aEvent)
 
void onHeaderContextMenu (wxDataViewEvent &aEvent)
 
void onQueryDebounce ()
 Regenerate the tree from the search text once typing pauses.
 
void onHoverPreview ()
 Show the hovered item's preview once the mouse stops moving.
 

Protected Attributes

wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
 
wxSearchCtrl * m_query_ctrl
 
BITMAP_BUTTON * m_sort_ctrl
 
WX_DATAVIEWCTRL * m_tree_ctrl
 
HTML_WINDOW * m_details_ctrl
 
bool m_inTimerEvent
 
wxString m_recentSearchesKey
 
wxBoxSizer * m_filtersSizer
 
bool m_skipNextRightClick
 
wxPoint m_hoverPos
 
wxDataViewItem m_hoverItem
 
wxRect m_hoverItemRect
 
WX_DEBOUNCED_ACTION m_queryDebounce
 Debounces the query typed in the search control.
 
WX_DEBOUNCED_ACTION m_hoverDebounce
 Debounces the item preview shown on hover.
 
wxDataViewItem m_previewItem
 
wxRect m_previewItemRect
 
wxPopupWindow * m_previewWindow
 
bool m_previewDisabled
 

Detailed Description

Widget displaying a tree of symbols with optional search text control and description panel.

Definition at line 43 of file lib_tree.h.

Member Enumeration Documentation

◆ FLAGS

Flags to select extra widgets and options.

Enumerator
FLAGS_NONE 
SEARCH 
FILTERS 
DETAILS 
ALL_WIDGETS 
MULTISELECT 

Definition at line 47 of file lib_tree.h.

Constructor & Destructor Documentation

◆ LIB_TREE()

LIB_TREE::LIB_TREE ( wxWindow * aParent,
const wxString & aRecentSearchesKey,
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & aAdapter,
int aFlags = ALL_WIDGETS,
HTML_WINDOW * aDetails = nullptr )

Construct a symbol tree.

Parameters
aParentparent window containing this tree widget.
aRecentSearchesKeya key into a global map storing recent searches (usually "power", "symbols", or "footprints", but could be further differentiated).
aAdaptera LIB_TREE_MODEL_ADAPTER instance to use.
aFlagsselection of sub-widgets to include and other options.
aDetailsif not null, a custom HTML_WINDOW to hold symbol details. If null this will be created inside the LIB_TREE.

Definition at line 50 of file lib_tree.cpp.

References m_adapter, m_details_ctrl, m_filtersSizer, m_inTimerEvent, m_query_ctrl, m_queryDebounce, m_recentSearchesKey, m_skipNextRightClick, m_sort_ctrl, and onQueryDebounce().

◆ ~LIB_TREE()

Member Function Documentation

◆ BlockPreview()

void LIB_TREE::BlockPreview ( bool aBlock)
inline

Definition at line 174 of file lib_tree.h.

References m_previewDisabled.

◆ centerIfValid()

void LIB_TREE::centerIfValid ( const wxDataViewItem & aTreeId)
protected

Definition at line 538 of file lib_tree.cpp.

References EnsureVisibleIfEnabled(), m_adapter, LIB_TREE_NODE::m_Parent, and m_tree_ctrl.

Referenced by CenterLibId().

◆ CenterLibId()

void LIB_TREE::CenterLibId ( const LIB_ID & aLibId)

Ensure that an item is visible (preferably centered).

Definition at line 382 of file lib_tree.cpp.

References centerIfValid(), and m_adapter.

Referenced by SYMBOL_EDIT_FRAME::AddLibraryFile(), SYMBOL_EDIT_FRAME::KiwayMailIn(), LIBRARY_EDITOR_CONTROL::regenerateLibraryTree(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ CollapseAll()

void LIB_TREE::CollapseAll ( )

Definition at line 427 of file lib_tree.cpp.

References m_tree_ctrl.

◆ ExpandAll()

void LIB_TREE::ExpandAll ( )

Definition at line 421 of file lib_tree.cpp.

References m_tree_ctrl.

◆ expandIfValid()

void LIB_TREE::expandIfValid ( const wxDataViewItem & aTreeId)
protected

Definition at line 586 of file lib_tree.cpp.

References m_tree_ctrl.

Referenced by ExpandLibId().

◆ ExpandLibId()

void LIB_TREE::ExpandLibId ( const LIB_ID & aLibId)

Expand and item i the tree widget.

Definition at line 396 of file lib_tree.cpp.

References expandIfValid(), and m_adapter.

Referenced by SYMBOL_EDIT_FRAME::KiwayMailIn(), SYMBOL_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ FocusSearchFieldIfExists()

void LIB_TREE::FocusSearchFieldIfExists ( )

Focus the search widget if it exists.

Definition at line 507 of file lib_tree.cpp.

References m_query_ctrl.

Referenced by SYMBOL_EDIT_FRAME::FocusLibraryTreeInput().

◆ GetCurrentTreeNode()

LIB_TREE_NODE * LIB_TREE::GetCurrentTreeNode ( ) const

Retrieve the tree node for the first selected item.

Returns
the tree node for the first selected item.

Definition at line 346 of file lib_tree.cpp.

References m_adapter, and m_tree_ctrl.

Referenced by DESIGN_BLOCK_CONTROL::getCurrentTreeNode(), and onItemContextMenu().

◆ GetExpandedLibraries()

std::vector< LIB_ID > LIB_TREE::GetExpandedLibraries ( ) const

Definition at line 402 of file lib_tree.cpp.

References m_adapter, and m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ GetFiltersSizer()

wxSizer * LIB_TREE::GetFiltersSizer ( )
inline

Definition at line 165 of file lib_tree.h.

References m_filtersSizer.

◆ GetFocusTarget()

wxWindow * LIB_TREE::GetFocusTarget ( )

Definition at line 498 of file lib_tree.cpp.

References m_query_ctrl, and m_tree_ctrl.

◆ GetSearchString()

wxString LIB_TREE::GetSearchString ( ) const

Definition at line 439 of file lib_tree.cpp.

References m_query_ctrl.

Referenced by updateRecentSearchMenu().

◆ GetSelectedLibId()

LIB_ID LIB_TREE::GetSelectedLibId ( int * aUnit = nullptr) const

For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit, 0 will be returned in aUnit.

Beware that this is an invalid unit number - this should be replaced with whatever default is desired (usually 1).

Parameters
aUnitif not NULL, the selected unit is filled in here.
Returns
the library id of the symbol that has been selected.

Definition at line 309 of file lib_tree.cpp.

References m_adapter, and m_tree_ctrl.

Referenced by getState(), FOOTPRINT_EDIT_FRAME::GetTargetFPID(), SYMBOL_EDIT_FRAME::GetTreeLIBID(), onPreselect(), onQueryCharHook(), onTreeActivate(), FOOTPRINT_EDIT_FRAME::setupUIConditions(), SYMBOL_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ GetSelectedLibIds()

int LIB_TREE::GetSelectedLibIds ( std::vector< LIB_ID > & aSelection,
std::vector< int > * aUnit = nullptr ) const

Retrieve a list of selections for trees that allow multi-selection.

See also
GetSelectedLibId for details on how aUnit will be filled.
Parameters
aSelectionwill be filled with a list of selected LIB_IDs.
aUnitis an optional pointer to a list to fill with unit numbers.
Returns
the number of selected items.

Definition at line 329 of file lib_tree.cpp.

References m_adapter, and m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::GetTreeLIBIDs().

◆ GetSelectedTreeNodes()

int LIB_TREE::GetSelectedTreeNodes ( std::vector< LIB_TREE_NODE * > & aSelection) const

Retrieve a list of pointers to selected tree nodes for trees that allow multi-selection.

Parameters
aSelectionwill be filled with a list of pointers of selected tree nodes.
Returns
the number of selected items.

Definition at line 356 of file lib_tree.cpp.

References m_adapter, and m_tree_ctrl.

Referenced by LIBRARY_EDITOR_CONTROL::AddContextMenuItems(), and LIBRARY_EDITOR_CONTROL::changeSelectedPinStatus().

◆ GetSelectionCount()

int LIB_TREE::GetSelectionCount ( ) const
inline

Definition at line 85 of file lib_tree.h.

References m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::GetTreeSelectionCount().

◆ GetSortMode()

LIB_TREE_MODEL_ADAPTER::SORT_MODE LIB_TREE::GetSortMode ( ) const
inline

Definition at line 151 of file lib_tree.h.

References m_adapter.

Referenced by FOOTPRINT_EDIT_FRAME::SaveSettings(), and SYMBOL_EDIT_FRAME::SaveSettings().

◆ getState()

LIB_TREE::STATE LIB_TREE::getState ( ) const
protected

Return the symbol tree widget state.

Definition at line 607 of file lib_tree.cpp.

References LIB_TREE::STATE::expanded, GetSelectedLibId(), m_adapter, m_tree_ctrl, LIB_TREE::STATE::scrollpos, and LIB_TREE::STATE::selection.

Referenced by Regenerate().

◆ hidePreview()

void LIB_TREE::hidePreview ( )
protected

◆ onDetailsLink()

void LIB_TREE::onDetailsLink ( wxHtmlLinkEvent & aEvent)
protected

◆ onHeaderContextMenu()

void LIB_TREE::onHeaderContextMenu ( wxDataViewEvent & aEvent)
protected

◆ onHoverPreview()

void LIB_TREE::onHoverPreview ( )
protected

Show the hovered item's preview once the mouse stops moving.

Definition at line 877 of file lib_tree.cpp.

References hidePreview(), m_hoverDebounce, m_hoverItem, m_hoverItemRect, m_hoverPos, m_previewDisabled, m_tree_ctrl, and showPreview().

◆ onIdle()

void LIB_TREE::onIdle ( wxIdleEvent & aEvent)
protected

◆ onItemContextMenu()

◆ onPreselect()

void LIB_TREE::onPreselect ( wxCommandEvent & aEvent)
protected

Definition at line 1003 of file lib_tree.cpp.

References GetSelectedLibId(), hidePreview(), m_adapter, and m_details_ctrl.

Referenced by ~LIB_TREE().

◆ onQueryCharHook()

void LIB_TREE::onQueryCharHook ( wxKeyEvent & aEvent)
protected

◆ onQueryDebounce()

void LIB_TREE::onQueryDebounce ( )
protected

Regenerate the tree from the search text once typing pauses.

Definition at line 660 of file lib_tree.cpp.

References m_inTimerEvent, and Regenerate().

Referenced by LIB_TREE().

◆ onQueryMouseMoved()

void LIB_TREE::onQueryMouseMoved ( wxMouseEvent & aEvent)
protected

Definition at line 769 of file lib_tree.cpp.

References m_query_ctrl.

Referenced by ~LIB_TREE().

◆ onQueryText()

void LIB_TREE::onQueryText ( wxCommandEvent & aEvent)
protected

Definition at line 650 of file lib_tree.cpp.

References m_queryDebounce.

Referenced by ~LIB_TREE().

◆ onTreeActivate()

void LIB_TREE::onTreeActivate ( wxDataViewEvent & aEvent)
protected

◆ onTreeCharHook()

void LIB_TREE::onTreeCharHook ( wxKeyEvent & aEvent)
protected

Definition at line 902 of file lib_tree.cpp.

References m_adapter, m_tree_ctrl, MD_ALT, MD_ALTGR, MD_CTRL, MD_META, MD_SHIFT, MD_SUPER, and onQueryCharHook().

Referenced by ~LIB_TREE().

◆ onTreeSelect()

void LIB_TREE::onTreeSelect ( wxDataViewEvent & aEvent)
protected

Definition at line 967 of file lib_tree.cpp.

References m_inTimerEvent, m_tree_ctrl, postPreselectEvent(), and updateRecentSearchMenu().

Referenced by ~LIB_TREE().

◆ postPreselectEvent()

void LIB_TREE::postPreselectEvent ( )
protected

Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been preselected.

Definition at line 593 of file lib_tree.cpp.

Referenced by onTreeSelect(), Regenerate(), and selectIfValid().

◆ postSelectEvent()

void LIB_TREE::postSelectEvent ( )
protected

Post EVT_LIBITEM_CHOSEN event to notify the selection handler that a part has been selected.

Definition at line 600 of file lib_tree.cpp.

Referenced by onQueryCharHook(), and onTreeActivate().

◆ RefreshLibTree()

void LIB_TREE::RefreshLibTree ( )

Refresh the tree (mainly to update highlighting and asterisking)

Definition at line 492 of file lib_tree.cpp.

References m_adapter.

Referenced by FOOTPRINT_EDIT_FRAME::OnModify(), SYMBOL_EDIT_FRAME::OnModify(), FOOTPRINT_EDIT_FRAME::RefreshLibraryTree(), SYMBOL_EDIT_FRAME::RefreshLibraryTree(), and SYMBOL_EDIT_FRAME::UpdateLibraryTree().

◆ Regenerate()

◆ selectIfValid()

void LIB_TREE::selectIfValid ( const wxDataViewItem & aTreeId)
protected

If a wxDataViewitem is valid, select it and post a selection event.

Definition at line 526 of file lib_tree.cpp.

References EnsureVisibleIfEnabled(), m_tree_ctrl, and postPreselectEvent().

Referenced by onQueryCharHook(), and SelectLibId().

◆ SelectLibId()

◆ SetSearchString()

void LIB_TREE::SetSearchString ( const wxString & aSearchString)

Save/restore search string.

Definition at line 433 of file lib_tree.cpp.

References m_query_ctrl.

◆ SetSortMode()

void LIB_TREE::SetSortMode ( LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
inline

Save/restore the sorting mode.

Definition at line 150 of file lib_tree.h.

References m_adapter.

Referenced by FOOTPRINT_EDIT_FRAME::LoadSettings().

◆ setState()

void LIB_TREE::setState ( const STATE & aState)
protected

Restore the symbol tree widget state from an object.

Definition at line 630 of file lib_tree.cpp.

References UTF8::empty(), LIB_TREE::STATE::expanded, LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), m_tree_ctrl, LIB_TREE::STATE::selection, and SelectLibId().

Referenced by Regenerate().

◆ ShowChangedLanguage()

void LIB_TREE::ShowChangedLanguage ( )

◆ showPreview()

void LIB_TREE::showPreview ( wxDataViewItem aItem)
protected

Definition at line 789 of file lib_tree.cpp.

References m_adapter, m_previewItem, m_previewItemRect, m_previewWindow, m_tree_ctrl, and PREVIEW_SIZE.

Referenced by onHoverPreview(), and onIdle().

◆ ShutdownPreviews()

void LIB_TREE::ShutdownPreviews ( )

◆ toggleExpand()

void LIB_TREE::toggleExpand ( const wxDataViewItem & aTreeId)
protected

Expand or collapse a node, switching it to the opposite state.

Definition at line 514 of file lib_tree.cpp.

References m_tree_ctrl.

Referenced by onQueryCharHook(), and onTreeActivate().

◆ Unselect()

void LIB_TREE::Unselect ( )

Unselect currently selected item in wxDataViewCtrl.

Definition at line 388 of file lib_tree.cpp.

References m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::emptyScreen(), SYMBOL_EDIT_FRAME::SetCurSymbol(), SYMBOL_EDIT_FRAME::SyncLibraries(), and FOOTPRINT_EDIT_FRAME::SyncLibraryTree().

◆ updateRecentSearchMenu()

void LIB_TREE::updateRecentSearchMenu ( )
protected

Member Data Documentation

◆ m_adapter

◆ m_details_ctrl

HTML_WINDOW* LIB_TREE::m_details_ctrl
protected

Definition at line 263 of file lib_tree.h.

Referenced by LIB_TREE(), onPreselect(), and ~LIB_TREE().

◆ m_filtersSizer

wxBoxSizer* LIB_TREE::m_filtersSizer
protected

Definition at line 268 of file lib_tree.h.

Referenced by GetFiltersSizer(), and LIB_TREE().

◆ m_hoverDebounce

WX_DEBOUNCED_ACTION LIB_TREE::m_hoverDebounce
protected

Debounces the item preview shown on hover.

Definition at line 280 of file lib_tree.h.

Referenced by onHoverPreview(), onIdle(), ShutdownPreviews(), and ~LIB_TREE().

◆ m_hoverItem

wxDataViewItem LIB_TREE::m_hoverItem
protected

Definition at line 273 of file lib_tree.h.

Referenced by onHoverPreview(), and onIdle().

◆ m_hoverItemRect

wxRect LIB_TREE::m_hoverItemRect
protected

Definition at line 274 of file lib_tree.h.

Referenced by onHoverPreview(), and onIdle().

◆ m_hoverPos

wxPoint LIB_TREE::m_hoverPos
protected

Definition at line 272 of file lib_tree.h.

Referenced by onHoverPreview(), and onIdle().

◆ m_inTimerEvent

bool LIB_TREE::m_inTimerEvent
protected

Definition at line 264 of file lib_tree.h.

Referenced by LIB_TREE(), onQueryDebounce(), onTreeActivate(), and onTreeSelect().

◆ m_previewDisabled

bool LIB_TREE::m_previewDisabled
protected

◆ m_previewItem

wxDataViewItem LIB_TREE::m_previewItem
protected

Definition at line 282 of file lib_tree.h.

Referenced by hidePreview(), onIdle(), and showPreview().

◆ m_previewItemRect

wxRect LIB_TREE::m_previewItemRect
protected

Definition at line 283 of file lib_tree.h.

Referenced by showPreview().

◆ m_previewWindow

wxPopupWindow* LIB_TREE::m_previewWindow
protected

Definition at line 284 of file lib_tree.h.

Referenced by hidePreview(), showPreview(), and ShutdownPreviews().

◆ m_query_ctrl

◆ m_queryDebounce

WX_DEBOUNCED_ACTION LIB_TREE::m_queryDebounce
protected

Debounces the query typed in the search control.

Definition at line 277 of file lib_tree.h.

Referenced by LIB_TREE(), onQueryText(), and ~LIB_TREE().

◆ m_recentSearchesKey

wxString LIB_TREE::m_recentSearchesKey
protected

Definition at line 266 of file lib_tree.h.

Referenced by LIB_TREE(), and updateRecentSearchMenu().

◆ m_skipNextRightClick

bool LIB_TREE::m_skipNextRightClick
protected

Definition at line 270 of file lib_tree.h.

Referenced by LIB_TREE(), and onItemContextMenu().

◆ m_sort_ctrl

BITMAP_BUTTON* LIB_TREE::m_sort_ctrl
protected

Definition at line 261 of file lib_tree.h.

Referenced by LIB_TREE().

◆ m_tree_ctrl


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