PL_UNLOCK;
return isLeaf;
}
+ else if( role == IsCurrentsParentNodeRole )
+ {
+ return QVariant( isParent( index, currentIndex() ) );
+ }
return QVariant();
}
+/* Seek from current index toward the top and see if index is one of parent nodes */
+bool PLModel::isParent( const QModelIndex &index, const QModelIndex ¤t ) const
+{
+ if( !index.isValid() )
+ return false;
+
+ if( index == current )
+ return true;
+
+ if( !current.isValid() || !current.parent().isValid() )
+ return false;
+
+ return isParent( index, current.parent() );
+}
+
bool PLModel::isCurrent( const QModelIndex &index ) const
{
return getItem( index )->p_input == THEMIM->currentInputItem();
return QModelIndex();
}
-QModelIndex PLModel::currentIndex()
+QModelIndex PLModel::currentIndex() const
{
input_thread_t *p_input_thread = THEMIM->getInput();
if( !p_input_thread ) return QModelIndex();
msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
return createIndex( 0, 0, parentItem );
}
- QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
- return ind;
+ return createIndex(parentItem->row(), 0, parentItem);
}
int PLModel::columnCount( const QModelIndex &i) const
/************************* 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<PLItem *>::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 )
{
/************************* Actions ******************************/
/**
- * Deletion, here we have to do a ugly slow hack as we retrieve the full
- * list of indexes to delete at once: when we delete a node and all of
- * its children, we need to update the list.
- * Todo: investigate whethere we can use ranges to be sure to delete all items?
+ * Deletion, don't delete items childrens if item is going to be
+ * delete allready, so we remove childrens from selection-list.
*/
void PLModel::doDelete( QModelIndexList selected )
{