Library Manager: alternative way to manage dynamic fixes
Tree nodes now have an additional field 'InTree' to determine if the view is aware of its existence. This way, there is no need to rebuild the data structures from scratch when they need to be filtered.
This commit is contained in:
parent
db4bd0c2db
commit
e0e4e5f1be
|
@ -105,6 +105,7 @@ int CMP_TREE_NODE::Compare( CMP_TREE_NODE const& aNode1, CMP_TREE_NODE const& aN
|
||||||
CMP_TREE_NODE::CMP_TREE_NODE()
|
CMP_TREE_NODE::CMP_TREE_NODE()
|
||||||
: Parent( nullptr ),
|
: Parent( nullptr ),
|
||||||
Type( INVALID ),
|
Type( INVALID ),
|
||||||
|
InTree( false ),
|
||||||
IntrinsicRank( 0 ),
|
IntrinsicRank( 0 ),
|
||||||
Score( kLowestDefaultScore ),
|
Score( kLowestDefaultScore ),
|
||||||
Unit( 0 )
|
Unit( 0 )
|
||||||
|
@ -177,6 +178,7 @@ CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* a
|
||||||
CMP_TREE_NODE_UNIT& CMP_TREE_NODE_LIB_ID::AddUnit( int aUnit )
|
CMP_TREE_NODE_UNIT& CMP_TREE_NODE_LIB_ID::AddUnit( int aUnit )
|
||||||
{
|
{
|
||||||
CMP_TREE_NODE_UNIT* unit = new CMP_TREE_NODE_UNIT( this, aUnit );
|
CMP_TREE_NODE_UNIT* unit = new CMP_TREE_NODE_UNIT( this, aUnit );
|
||||||
|
unit->InTree = true;
|
||||||
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( unit ) );
|
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( unit ) );
|
||||||
return *unit;
|
return *unit;
|
||||||
}
|
}
|
||||||
|
@ -243,6 +245,7 @@ CMP_TREE_NODE_LIB::CMP_TREE_NODE_LIB( CMP_TREE_NODE* aParent, wxString const& aN
|
||||||
CMP_TREE_NODE_LIB_ID& CMP_TREE_NODE_LIB::AddAlias( LIB_ALIAS* aAlias )
|
CMP_TREE_NODE_LIB_ID& CMP_TREE_NODE_LIB::AddAlias( LIB_ALIAS* aAlias )
|
||||||
{
|
{
|
||||||
CMP_TREE_NODE_LIB_ID* alias = new CMP_TREE_NODE_LIB_ID( this, aAlias );
|
CMP_TREE_NODE_LIB_ID* alias = new CMP_TREE_NODE_LIB_ID( this, aAlias );
|
||||||
|
alias->InTree = true;
|
||||||
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( alias ) );
|
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( alias ) );
|
||||||
return *alias;
|
return *alias;
|
||||||
}
|
}
|
||||||
|
@ -269,6 +272,7 @@ CMP_TREE_NODE_ROOT::CMP_TREE_NODE_ROOT()
|
||||||
CMP_TREE_NODE_LIB& CMP_TREE_NODE_ROOT::AddLib( wxString const& aName )
|
CMP_TREE_NODE_LIB& CMP_TREE_NODE_ROOT::AddLib( wxString const& aName )
|
||||||
{
|
{
|
||||||
CMP_TREE_NODE_LIB* lib = new CMP_TREE_NODE_LIB( this, aName );
|
CMP_TREE_NODE_LIB* lib = new CMP_TREE_NODE_LIB( this, aName );
|
||||||
|
lib->InTree = true;
|
||||||
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( lib ) );
|
Children.push_back( std::unique_ptr<CMP_TREE_NODE>( lib ) );
|
||||||
return *lib;
|
return *lib;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,7 @@ public:
|
||||||
CMP_TREE_NODE* Parent; ///< Parent node or null
|
CMP_TREE_NODE* Parent; ///< Parent node or null
|
||||||
PTR_VECTOR Children; ///< List of child nodes
|
PTR_VECTOR Children; ///< List of child nodes
|
||||||
enum TYPE Type; ///< Node type
|
enum TYPE Type; ///< Node type
|
||||||
|
bool InTree; ///< Flag indicating whether the node is added to the tree
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rank of the item before any search terms are applied. This is
|
* The rank of the item before any search terms are applied. This is
|
||||||
|
|
|
@ -61,7 +61,7 @@ unsigned int CMP_TREE_MODEL_ADAPTER_BASE::IntoArray(
|
||||||
|
|
||||||
for( auto const& child: aNode.Children )
|
for( auto const& child: aNode.Children )
|
||||||
{
|
{
|
||||||
if( child->Score > 0 )
|
if( child->Score > 0 && child->InTree )
|
||||||
{
|
{
|
||||||
aChildren.Add( ToItem( &*child ) );
|
aChildren.Add( ToItem( &*child ) );
|
||||||
++n;
|
++n;
|
||||||
|
@ -156,9 +156,7 @@ void CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString( wxString const& aSearch )
|
||||||
m_tree.UpdateScore( matcher );
|
m_tree.UpdateScore( matcher );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tree.SortNodes();
|
filterContents();
|
||||||
Cleared();
|
|
||||||
|
|
||||||
ShowResults() || ShowPreselect() || ShowSingleLibrary();
|
ShowResults() || ShowPreselect() || ShowSingleLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +287,7 @@ unsigned int CMP_TREE_MODEL_ADAPTER_BASE::GetChildren(
|
||||||
auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
|
auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
|
||||||
|
|
||||||
if( node->Type != CMP_TREE_NODE::TYPE::LIBID
|
if( node->Type != CMP_TREE_NODE::TYPE::LIBID
|
||||||
|| ( m_show_units && node->Type == CMP_TREE_NODE::TYPE::UNIT ) )
|
|| ( m_show_units && node->Type == CMP_TREE_NODE::TYPE::LIBID ) )
|
||||||
return IntoArray( *node, aChildren );
|
return IntoArray( *node, aChildren );
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -464,3 +462,57 @@ bool CMP_TREE_MODEL_ADAPTER_BASE::ShowSingleLibrary()
|
||||||
n->Parent->Parent->Children.size() == 1;
|
n->Parent->Parent->Children.size() == 1;
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CMP_TREE_MODEL_ADAPTER_BASE::filterContents()
|
||||||
|
{
|
||||||
|
// Rebuild the tree using only the filtered nodes
|
||||||
|
for( auto& lib : m_tree.Children )
|
||||||
|
{
|
||||||
|
lib->InTree = false;
|
||||||
|
|
||||||
|
for( auto& alias : lib->Children )
|
||||||
|
{
|
||||||
|
alias->InTree = false;
|
||||||
|
|
||||||
|
for( auto& unit : lib->Children )
|
||||||
|
unit->InTree = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tree.SortNodes();
|
||||||
|
Cleared();
|
||||||
|
|
||||||
|
for( auto& lib : m_tree.Children )
|
||||||
|
{
|
||||||
|
if( lib->Score <= 0 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
wxDataViewItem libItem = ToItem( lib.get() );
|
||||||
|
|
||||||
|
for( auto& alias : lib->Children )
|
||||||
|
{
|
||||||
|
if( !lib->InTree )
|
||||||
|
{
|
||||||
|
lib->InTree = true;
|
||||||
|
ItemAdded( wxDataViewItem( nullptr ), libItem );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( alias->Score > 0 )
|
||||||
|
{
|
||||||
|
alias->InTree = true;
|
||||||
|
ItemAdded( libItem, ToItem( alias.get() ) );
|
||||||
|
wxDataViewItem aliasItem = ToItem( alias.get() );
|
||||||
|
|
||||||
|
if( !m_show_units )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for( auto& unit : alias->Children )
|
||||||
|
{
|
||||||
|
unit->InTree = true;
|
||||||
|
ItemAdded( aliasItem, ToItem( unit.get() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -387,6 +387,11 @@ private:
|
||||||
* Find and expand a library if there is only one
|
* Find and expand a library if there is only one
|
||||||
*/
|
*/
|
||||||
bool ShowSingleLibrary();
|
bool ShowSingleLibrary();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the items shown in the view according to the score.
|
||||||
|
*/
|
||||||
|
void filterContents();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _CMP_TREE_MODEL_ADAPTER_BASE_H
|
#endif // _CMP_TREE_MODEL_ADAPTER_BASE_H
|
||||||
|
|
|
@ -186,16 +186,9 @@ CMP_TREE_NODE::PTR_VECTOR::iterator LIB_MANAGER_ADAPTER::deleteLibrary(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LIB_MANAGER_ADAPTER::addAliases( CMP_TREE_NODE_LIB& aLibNode )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LIB_MANAGER_ADAPTER::finishUpdate()
|
void LIB_MANAGER_ADAPTER::finishUpdate()
|
||||||
{
|
{
|
||||||
m_tree.AssignIntrinsicRanks();
|
m_tree.AssignIntrinsicRanks();
|
||||||
m_tree.SortNodes();
|
|
||||||
Resort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,6 @@ protected:
|
||||||
CMP_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(
|
CMP_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(
|
||||||
CMP_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt );
|
CMP_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt );
|
||||||
|
|
||||||
void addAliases( CMP_TREE_NODE_LIB& aLibNode );
|
|
||||||
|
|
||||||
void finishUpdate();
|
void finishUpdate();
|
||||||
|
|
||||||
CMP_TREE_NODE* findLibrary( const wxString& aLibNickName );
|
CMP_TREE_NODE* findLibrary( const wxString& aLibNickName );
|
||||||
|
|
Loading…
Reference in New Issue