Commit 568e5555 authored by Ilkka Ollakka's avatar Ilkka Ollakka

Qt4: constify currentIndex() and find* helpers, remove CACHE in findInner

parent eb2da50b
...@@ -517,71 +517,46 @@ QStringList PLModel::selectedURIs() ...@@ -517,71 +517,46 @@ QStringList PLModel::selectedURIs()
/************************* Lookups *****************************/ /************************* Lookups *****************************/
PLItem *PLModel::findById( PLItem *root, int i_id ) PLItem *PLModel::findById( PLItem *root, int i_id ) const
{ {
return findInner( root, i_id, false ); return findInner( root, i_id, false );
} }
PLItem *PLModel::findByInput( PLItem *root, int i_id ) PLItem *PLModel::findByInput( PLItem *root, int i_id ) const
{ {
PLItem *result = findInner( root, i_id, true ); PLItem *result = findInner( root, i_id, true );
return result; return result;
} }
#define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; } PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const
#define ICACHE( i, p ) { i_cached_input_id = i; p_cached_item_bi = p; }
PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
{ {
if( !root ) return NULL; if( !root ) return NULL;
if( ( !b_input && i_cached_id == i_id) ||
( b_input && i_cached_input_id ==i_id ) )
{
return b_input ? p_cached_item_bi : p_cached_item;
}
if( !b_input && root->i_id == i_id ) if( !b_input && root->i_id == i_id )
{
CACHE( i_id, root );
return root; return root;
}
else if( b_input && root->p_input->i_id == i_id ) else if( b_input && root->p_input->i_id == i_id )
{
ICACHE( i_id, root );
return root; return root;
}
QList<PLItem *>::iterator it = root->children.begin(); QList<PLItem *>::iterator it = root->children.begin();
while ( it != root->children.end() ) while ( it != root->children.end() )
{ {
if( !b_input && (*it)->i_id == i_id ) if( !b_input && (*it)->i_id == i_id )
{ return (*it);
CACHE( i_id, (*it) );
return p_cached_item;
}
else if( b_input && (*it)->p_input->i_id == i_id ) else if( b_input && (*it)->p_input->i_id == i_id )
{ return (*it);
ICACHE( i_id, (*it) );
return p_cached_item_bi;
}
if( (*it)->children.size() ) if( (*it)->children.size() )
{ {
PLItem *childFound = findInner( (*it), i_id, b_input ); PLItem *childFound = findInner( (*it), i_id, b_input );
if( childFound ) if( childFound )
{
if( b_input )
ICACHE( i_id, childFound )
else
CACHE( i_id, childFound )
return childFound; return childFound;
} }
}
it++; it++;
} }
return NULL; return NULL;
} }
#undef CACHE
#undef ICACHE
int PLModel::columnToMeta( int _column ) int PLModel::columnToMeta( int _column )
{ {
......
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
QStringList selectedURIs(); QStringList selectedURIs();
QModelIndex index( PLItem *, int c ) const; QModelIndex index( PLItem *, int c ) const;
QModelIndex index( int i_id, int c ); QModelIndex index( int i_id, int c );
QModelIndex currentIndex(); QModelIndex currentIndex() const;
bool isParent( const QModelIndex &index, const QModelIndex &current) const; bool isParent( const QModelIndex &index, const QModelIndex &current) const;
bool isCurrent( const QModelIndex &index ) const; bool isCurrent( const QModelIndex &index ) const;
int itemId( const QModelIndex &index ) const; int itemId( const QModelIndex &index ) const;
...@@ -154,9 +154,9 @@ private: ...@@ -154,9 +154,9 @@ private:
QSignalMapper *sortingMapper; QSignalMapper *sortingMapper;
/* Lookups */ /* Lookups */
PLItem *findById( PLItem *, int ); PLItem *findById( PLItem *, int ) const;
PLItem *findByInput( PLItem *, int ); PLItem *findByInput( PLItem *, int ) const;
PLItem *findInner( PLItem *, int , bool ); PLItem *findInner(PLItem *, int , bool ) const;
bool canEdit() const; bool canEdit() const;
PLItem *p_cached_item; PLItem *p_cached_item;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment