From 568e55553dfb2a2bb01395614d45fcb422b9a302 Mon Sep 17 00:00:00 2001 From: Ilkka Ollakka Date: Thu, 24 Jun 2010 18:13:17 +0300 Subject: [PATCH] Qt4: constify currentIndex() and find* helpers, remove CACHE in findInner --- .../components/playlist/playlist_model.cpp | 43 ++++--------------- .../components/playlist/playlist_model.hpp | 8 ++-- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp index 38688672ae..55c308c2d9 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.cpp +++ b/modules/gui/qt4/components/playlist/playlist_model.cpp @@ -517,71 +517,46 @@ QStringList PLModel::selectedURIs() /************************* Lookups *****************************/ -PLItem *PLModel::findById( PLItem *root, int i_id ) +PLItem *PLModel::findById( PLItem *root, int i_id ) const { 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 ); return result; } -#define CACHE( i, p ) { i_cached_id = i; p_cached_item = p; } -#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 ) +PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input ) const { 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 ) - { - CACHE( i_id, root ); return root; - } + else if( b_input && root->p_input->i_id == i_id ) - { - ICACHE( i_id, root ); return root; - } QList::iterator it = root->children.begin(); while ( it != root->children.end() ) { if( !b_input && (*it)->i_id == i_id ) - { - CACHE( i_id, (*it) ); - return p_cached_item; - } + return (*it); + else if( b_input && (*it)->p_input->i_id == i_id ) - { - ICACHE( i_id, (*it) ); - return p_cached_item_bi; - } + return (*it); + if( (*it)->children.size() ) { PLItem *childFound = findInner( (*it), i_id, b_input ); if( childFound ) - { - if( b_input ) - ICACHE( i_id, childFound ) - else - CACHE( i_id, childFound ) - return childFound; - } + return childFound; } it++; } return NULL; } -#undef CACHE -#undef ICACHE int PLModel::columnToMeta( int _column ) { diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp index f6343dfeba..ca18f0f03c 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.hpp +++ b/modules/gui/qt4/components/playlist/playlist_model.hpp @@ -92,7 +92,7 @@ public: QStringList selectedURIs(); QModelIndex index( PLItem *, int c ) const; QModelIndex index( int i_id, int c ); - QModelIndex currentIndex(); + QModelIndex currentIndex() const; bool isParent( const QModelIndex &index, const QModelIndex ¤t) const; bool isCurrent( const QModelIndex &index ) const; int itemId( const QModelIndex &index ) const; @@ -154,9 +154,9 @@ private: QSignalMapper *sortingMapper; /* Lookups */ - PLItem *findById( PLItem *, int ); - PLItem *findByInput( PLItem *, int ); - PLItem *findInner( PLItem *, int , bool ); + PLItem *findById( PLItem *, int ) const; + PLItem *findByInput( PLItem *, int ) const; + PLItem *findInner(PLItem *, int , bool ) const; bool canEdit() const; PLItem *p_cached_item; -- 2.39.2