De-templatify CMP_TREE_MODEL_ADAPTER::FindAndExpand

std::function lets this be a plain method instead of a template; this
cleans up the header a bit and possibly reduces a bit of bloat
This commit is contained in:
Chris Pavlina 2017-03-21 22:42:49 -04:00
parent b2f1d22bbf
commit 72cfd38979
2 changed files with 29 additions and 22 deletions

View File

@ -368,6 +368,31 @@ int CMP_TREE_MODEL_ADAPTER::WidthFor( wxString const& aHeading, int aCol )
}
bool CMP_TREE_MODEL_ADAPTER::FindAndExpand(
CMP_TREE_NODE& aNode,
std::function<bool( CMP_TREE_NODE const* )> aFunc )
{
for( auto& node: aNode.Children )
{
if( aFunc( &*node ) )
{
auto item = wxDataViewItem(
const_cast<void*>( static_cast<void const*>( &*node ) ) );
m_widget->ExpandAncestors( item );
m_widget->EnsureVisible( item );
m_widget->Select( item );
return true;
}
else if( FindAndExpand( *node, aFunc ) )
{
return true;
}
}
return false;
}
bool CMP_TREE_MODEL_ADAPTER::ShowResults()
{
return FindAndExpand( m_tree,

View File

@ -27,6 +27,7 @@
#include <wx/hashmap.h>
#include <wx/dataview.h>
#include <vector>
#include <functional>
class LIB_ALIAS;
class PART_LIB;
@ -333,28 +334,9 @@ private:
*
* @return whether a node was expanded
*/
template<typename Func>
bool FindAndExpand( CMP_TREE_NODE& aNode, Func f )
{
for( auto& node: aNode.Children )
{
if( f( &*node ) )
{
auto item = wxDataViewItem(
const_cast<void*>( static_cast<void const*>( &*node ) ) );
m_widget->ExpandAncestors( item );
m_widget->EnsureVisible( item );
m_widget->Select( item );
return true;
}
else if( FindAndExpand( *node, f ) )
{
return true;
}
}
return false;
}
bool FindAndExpand(
CMP_TREE_NODE& aNode,
std::function<bool( CMP_TREE_NODE const* )> aFunc );
/**
* Find and expand successful search results