class QTreeView;
class PLModel;
class QPushButton;
-
+class QKeyEvent;
/**
* \todo Share a single model between views using a filterproxy
*/
StandardPLPanel( QWidget *, intf_thread_t *,
playlist_t *,playlist_item_t * );
virtual ~StandardPLPanel();
+protected:
+ virtual void keyPressEvent( QKeyEvent *e );
private:
PLModel *model;
QTreeView *view;
public slots:
virtual void setRoot( int );
private slots:
+ void deleteSelection();
void handleExpansion( const QModelIndex& );
void toggleRandom();
void toggleRepeat();
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QHeaderView>
+#include <QKeyEvent>
#include "qt4.hpp"
#include <assert.h>
+#include <QModelIndexList>
StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
playlist_t *p_playlist,
model->Rebuild();
}
+void StandardPLPanel::keyPressEvent( QKeyEvent *e )
+{
+ switch( e->key() )
+ {
+ case Qt::Key_Back:
+ case Qt::Key_Delete:
+ deleteSelection();
+ break;
+ }
+}
+
+void StandardPLPanel::deleteSelection()
+{
+ QItemSelectionModel *selection = view->selectionModel();
+ QModelIndexList list = selection->selectedIndexes();
+ model->doDelete( list );
+}
+
StandardPLPanel::~StandardPLPanel()
{}
emit dataChanged( index( item, 0 ) , index( item, 1 ) );
}
+/************************* 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?
+ */
+void PLModel::doDelete( QModelIndexList selected )
+{
+ for( int i = selected.size() -1 ; i >= 0; i-- )
+ {
+ QModelIndex index = selected[i];
+ if( index.column() != 0 ) continue;
+ PLItem *item = static_cast<PLItem*>(index.internalPointer());
+ if( item )
+ {
+ if( item->children.size() )
+ recurseDelete( item->children, &selected );
+ doDeleteItem( item, &selected );
+ }
+ }
+}
+
+void PLModel::recurseDelete( QList<PLItem*> children, QModelIndexList *fullList)
+{
+ for( int i = children.size() - 1; i >= 0 ; i-- )
+ {
+ PLItem *item = children[i];
+ if( item->children.size() )
+ recurseDelete( item->children, fullList );
+ doDeleteItem( item, fullList );
+ }
+}
+
+void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
+{
+ QModelIndex deleteIndex = index( item, 0 );
+ fullList->removeAll( deleteIndex );
+
+ PL_LOCK;
+ playlist_item_t *p_item = playlist_ItemGetById( p_playlist, item->i_id );
+ if( !p_item )
+ {
+ PL_UNLOCK; return;
+ }
+ if( p_item->i_children == -1 )
+ playlist_DeleteAllFromInput( p_playlist, item->i_input_id );
+ else
+ playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
+ /* And finally, remove it from the tree */
+ item->remove( item );
+ PL_UNLOCK;
+}
+
/**********************************************************************
* Playlist callbacks
**********************************************************************/
void Rebuild();
void rebuildRoot( playlist_item_t * );
bool hasRandom(); bool hasLoop(); bool hasRepeat();
+
+ void doDelete( QModelIndexList selected );
private:
void addCallbacks();
void delCallbacks();
void UpdateNodeChildren( PLItem * );
void UpdateNodeChildren( playlist_item_t *, PLItem * );
+ /* Actions */
+ void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList);
+ void doDeleteItem( PLItem *item, QModelIndexList *fullList );
+
/* Lookups */
PLItem *FindById( PLItem *, int );
PLItem *FindByInput( PLItem *, int );