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.Custom event sent when an item is selected in the list. 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 {
  NONE = 0x00 , SEARCH = 0x01 , DETAILS = 0x02 , ALL_WIDGETS = 0x0F ,
  MULTISELECT = 0x10
}
 < Flags to select extra widgets and options More...
 

Public Member Functions

 LIB_TREE (wxWindow *aParent, const wxString &aRecentSearchesKey, LIB_TABLE *aLibTable, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, int aFlags=ALL_WIDGETS, HTML_WINDOW *aDetails=nullptr)
 Construct a symbol tree. More...
 
 ~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. More...
 
int GetSelectionCount () const
 
int GetSelectedLibIds (std::vector< LIB_ID > &aSelection, std::vector< int > *aUnit=nullptr) const
 Retrieves a list of selections for trees that allow multi-selection. More...
 
LIB_TREE_NODEGetCurrentTreeNode () const
 
void SelectLibId (const LIB_ID &aLibId)
 Select an item in the tree widget. More...
 
void CenterLibId (const LIB_ID &aLibId)
 Ensure that an item is visible (preferably centered). More...
 
void Unselect ()
 Unselect currently selected item in wxDataViewCtrl. More...
 
void ExpandLibId (const LIB_ID &aLibId)
 Expand and item i the tree widget. More...
 
void ExpandAll ()
 
void CollapseAll ()
 
void SetSearchString (const wxString &aSearchString)
 Save/restore search string. More...
 
wxString GetSearchString () const
 
void SetSortMode (LIB_TREE_MODEL_ADAPTER::SORT_MODE aMode)
 Save/restore the sorting mode. More...
 
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode () const
 
void Regenerate (bool aKeepState)
 Regenerate the tree. More...
 
void RefreshLibTree ()
 Refreshes the tree (mainly to update highlighting and asterisking) More...
 
wxWindow * GetFocusTarget ()
 
void FocusSearchFieldIfExists ()
 Focus the search widget if it exists. More...
 
void ShowChangedLanguage ()
 

Protected Member Functions

void toggleExpand (const wxDataViewItem &aTreeId)
 Expand or collapse a node, switching it to the opposite state. More...
 
void selectIfValid (const wxDataViewItem &aTreeId)
 If a wxDataViewitem is valid, select it and post a selection event. More...
 
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. More...
 
void postSelectEvent ()
 Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected. More...
 
STATE getState () const
 Return the symbol tree widget state. More...
 
void setState (const STATE &aState)
 Restore the symbol tree widget state from an object. More...
 
void updateRecentSearchMenu ()
 
void showPreview (wxDataViewItem aItem)
 
void hidePreview ()
 
void destroyPreview ()
 
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 onHoverTimer (wxTimerEvent &aEvent)
 
void onDetailsLink (wxHtmlLinkEvent &aEvent)
 
void onPreselect (wxCommandEvent &aEvent)
 
void onItemContextMenu (wxDataViewEvent &aEvent)
 
void onHeaderContextMenu (wxDataViewEvent &aEvent)
 
void onDebounceTimer (wxTimerEvent &aEvent)
 

Protected Attributes

wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERm_adapter
 
wxSearchCtrl * m_query_ctrl
 
STD_BITMAP_BUTTONm_sort_ctrl
 
WX_DATAVIEWCTRLm_tree_ctrl
 
HTML_WINDOWm_details_ctrl
 
wxTimer * m_debounceTimer
 
bool m_inTimerEvent
 
wxString m_recentSearchesKey
 
bool m_skipNextRightClick
 
wxPoint m_hoverPos
 
wxDataViewItem m_hoverItem
 
wxRect m_hoverItemRect
 
wxTimer m_hoverTimer
 
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.Custom event sent when an item is selected in the list.

Definition at line 48 of file lib_tree.h.

Member Enumeration Documentation

◆ FLAGS

< Flags to select extra widgets and options

Enumerator
NONE 
SEARCH 
DETAILS 
ALL_WIDGETS 
MULTISELECT 

Definition at line 52 of file lib_tree.h.

Constructor & Destructor Documentation

◆ LIB_TREE()

LIB_TREE::LIB_TREE ( wxWindow *  aParent,
const wxString &  aRecentSearchesKey,
LIB_TABLE aLibTable,
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)
aLibTabletable containing libraries and items to display
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 51 of file lib_tree.cpp.

References _, LIB_TREE_MODEL_ADAPTER::BEST_MATCH, ACTIONS::collapseAll, DETAILS, ACTIONS::expandAll, g_recentSearches, KiBitmapBundle(), m_adapter, m_debounceTimer, m_details_ctrl, m_hoverTimer, m_query_ctrl, m_recentSearchesKey, m_sort_ctrl, m_tree_ctrl, MULTISELECT, onDebounceTimer(), onDetailsLink(), onHeaderContextMenu(), onHoverTimer(), onIdle(), onItemContextMenu(), onPreselect(), onQueryCharHook(), onQueryMouseMoved(), onQueryText(), onTreeActivate(), onTreeCharHook(), onTreeSelect(), postPreselectEvent(), RECENT_SEARCHES_MAX, Regenerate(), SEARCH, STD_BITMAP_BUTTON::SetBitmap(), and updateRecentSearchMenu().

◆ ~LIB_TREE()

Member Function Documentation

◆ centerIfValid()

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

Definition at line 474 of file lib_tree.cpp.

References m_adapter, LIB_TREE_NODE::m_Parent, and m_tree_ctrl.

Referenced by CenterLibId().

◆ CenterLibId()

◆ CollapseAll()

void LIB_TREE::CollapseAll ( )

Definition at line 363 of file lib_tree.cpp.

References WX_DATAVIEWCTRL::CollapseAll(), and m_tree_ctrl.

◆ destroyPreview()

void LIB_TREE::destroyPreview ( )
protected

Definition at line 728 of file lib_tree.cpp.

References hidePreview(), and m_previewWindow.

Referenced by ~LIB_TREE().

◆ ExpandAll()

void LIB_TREE::ExpandAll ( )

Definition at line 357 of file lib_tree.cpp.

References WX_DATAVIEWCTRL::ExpandAll(), and m_tree_ctrl.

◆ expandIfValid()

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

Definition at line 522 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 351 of file lib_tree.cpp.

References expandIfValid(), and m_adapter.

Referenced by SYMBOL_EDIT_FRAME::KiwayMailIn(), FOOTPRINT_EDIT_FRAME::LoadFootprintFromLibrary(), and SYMBOL_EDIT_FRAME::LoadSymbol().

◆ FocusSearchFieldIfExists()

void LIB_TREE::FocusSearchFieldIfExists ( )

Focus the search widget if it exists.

Definition at line 443 of file lib_tree.cpp.

References m_query_ctrl.

Referenced by FOOTPRINT_TREE_PANE::FocusSearchFieldIfExists().

◆ GetCurrentTreeNode()

◆ GetFocusTarget()

wxWindow * LIB_TREE::GetFocusTarget ( )

◆ GetSearchString()

wxString LIB_TREE::GetSearchString ( ) const

◆ 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 291 of file lib_tree.cpp.

References m_adapter, and m_tree_ctrl.

Referenced by PANEL_FOOTPRINT_CHOOSER::GetSelectedLibId(), PANEL_SYMBOL_CHOOSER::GetSelectedLibId(), getState(), FOOTPRINT_EDIT_FRAME::GetTreeFPID(), SYMBOL_EDIT_FRAME::GetTreeLIBID(), PANEL_FOOTPRINT_CHOOSER::onFootprintChosen(), PANEL_FOOTPRINT_CHOOSER::onFootprintSelected(), onPreselect(), onQueryCharHook(), PANEL_SYMBOL_CHOOSER::onSymbolChosen(), onTreeActivate(), 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

Retrieves 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 305 of file lib_tree.cpp.

References m_adapter, and m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::GetTreeLIBIDs().

◆ GetSelectionCount()

int LIB_TREE::GetSelectionCount ( ) const
inline

Definition at line 90 of file lib_tree.h.

References m_tree_ctrl.

Referenced by SYMBOL_EDIT_FRAME::GetTreeSelectionCount().

◆ GetSortMode()

◆ getState()

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

Return the symbol tree widget state.

Definition at line 543 of file lib_tree.cpp.

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

Referenced by Regenerate().

◆ hidePreview()

void LIB_TREE::hidePreview ( )
protected

◆ onDebounceTimer()

void LIB_TREE::onDebounceTimer ( wxTimerEvent &  aEvent)
protected

Definition at line 587 of file lib_tree.cpp.

References m_inTimerEvent, and Regenerate().

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

◆ onDetailsLink()

void LIB_TREE::onDetailsLink ( wxHtmlLinkEvent &  aEvent)
protected

Definition at line 887 of file lib_tree.cpp.

References GetAssociatedDocument(), info, Pgm(), and KIWAY::Prj().

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

◆ onHeaderContextMenu()

void LIB_TREE::onHeaderContextMenu ( wxDataViewEvent &  aEvent)
protected

◆ onHoverTimer()

void LIB_TREE::onHoverTimer ( wxTimerEvent &  aEvent)
protected

◆ onIdle()

void LIB_TREE::onIdle ( wxIdleEvent &  aEvent)
protected

◆ onItemContextMenu()

◆ onPreselect()

void LIB_TREE::onPreselect ( wxCommandEvent &  aEvent)
protected

Definition at line 897 of file lib_tree.cpp.

References GetSelectedLibId(), hidePreview(), m_adapter, m_details_ctrl, and HTML_WINDOW::SetPage().

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

◆ onQueryCharHook()

◆ onQueryMouseMoved()

void LIB_TREE::onQueryMouseMoved ( wxMouseEvent &  aEvent)
protected

Definition at line 674 of file lib_tree.cpp.

References m_query_ctrl.

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

◆ onQueryText()

void LIB_TREE::onQueryText ( wxCommandEvent &  aEvent)
protected

Definition at line 577 of file lib_tree.cpp.

References m_debounceTimer.

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

◆ onTreeActivate()

void LIB_TREE::onTreeActivate ( wxDataViewEvent &  aEvent)
protected

◆ onTreeCharHook()

void LIB_TREE::onTreeCharHook ( wxKeyEvent &  aEvent)
protected

Definition at line 835 of file lib_tree.cpp.

References m_adapter, MD_ALT, MD_CTRL, MD_SHIFT, and onQueryCharHook().

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

◆ onTreeSelect()

void LIB_TREE::onTreeSelect ( wxDataViewEvent &  aEvent)
protected

Definition at line 861 of file lib_tree.cpp.

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

Referenced by LIB_TREE(), and ~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 529 of file lib_tree.cpp.

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

◆ postSelectEvent()

void LIB_TREE::postSelectEvent ( )
protected

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

Definition at line 536 of file lib_tree.cpp.

Referenced by onQueryCharHook(), and onTreeActivate().

◆ RefreshLibTree()

◆ 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 462 of file lib_tree.cpp.

References 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 369 of file lib_tree.cpp.

References m_query_ctrl.

Referenced by PANEL_SYMBOL_CHOOSER::OnChar(), and PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER().

◆ SetSortMode()

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

Save/restore the sorting mode.

Definition at line 139 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 561 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 693 of file lib_tree.cpp.

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

Referenced by onHoverTimer(), and onIdle().

◆ toggleExpand()

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

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

Definition at line 450 of file lib_tree.cpp.

References m_tree_ctrl.

Referenced by onQueryCharHook(), and onTreeActivate().

◆ Unselect()

◆ updateRecentSearchMenu()

void LIB_TREE::updateRecentSearchMenu ( )
protected

Member Data Documentation

◆ m_adapter

◆ m_debounceTimer

wxTimer* LIB_TREE::m_debounceTimer
protected

Definition at line 240 of file lib_tree.h.

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

◆ m_details_ctrl

HTML_WINDOW* LIB_TREE::m_details_ctrl
protected

Definition at line 239 of file lib_tree.h.

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

◆ m_hoverItem

wxDataViewItem LIB_TREE::m_hoverItem
protected

Definition at line 248 of file lib_tree.h.

Referenced by onHoverTimer(), and onIdle().

◆ m_hoverItemRect

wxRect LIB_TREE::m_hoverItemRect
protected

Definition at line 249 of file lib_tree.h.

Referenced by onHoverTimer(), and onIdle().

◆ m_hoverPos

wxPoint LIB_TREE::m_hoverPos
protected

Definition at line 247 of file lib_tree.h.

Referenced by onHoverTimer(), and onIdle().

◆ m_hoverTimer

wxTimer LIB_TREE::m_hoverTimer
protected

Definition at line 250 of file lib_tree.h.

Referenced by LIB_TREE(), onHoverTimer(), onIdle(), and ~LIB_TREE().

◆ m_inTimerEvent

bool LIB_TREE::m_inTimerEvent
protected

Definition at line 241 of file lib_tree.h.

Referenced by onDebounceTimer(), onTreeActivate(), and onTreeSelect().

◆ m_previewDisabled

bool LIB_TREE::m_previewDisabled
protected

Definition at line 254 of file lib_tree.h.

Referenced by onHeaderContextMenu(), onHoverTimer(), onIdle(), and onItemContextMenu().

◆ m_previewItem

wxDataViewItem LIB_TREE::m_previewItem
protected

Definition at line 251 of file lib_tree.h.

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

◆ m_previewItemRect

wxRect LIB_TREE::m_previewItemRect
protected

Definition at line 252 of file lib_tree.h.

Referenced by onIdle(), and showPreview().

◆ m_previewWindow

wxPopupWindow* LIB_TREE::m_previewWindow
protected

Definition at line 253 of file lib_tree.h.

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

◆ m_query_ctrl

◆ m_recentSearchesKey

wxString LIB_TREE::m_recentSearchesKey
protected

Definition at line 243 of file lib_tree.h.

Referenced by LIB_TREE(), and updateRecentSearchMenu().

◆ m_skipNextRightClick

bool LIB_TREE::m_skipNextRightClick
protected

Definition at line 245 of file lib_tree.h.

Referenced by onItemContextMenu().

◆ m_sort_ctrl

STD_BITMAP_BUTTON* LIB_TREE::m_sort_ctrl
protected

Definition at line 237 of file lib_tree.h.

Referenced by LIB_TREE().

◆ m_tree_ctrl


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