Commit 159fa24a authored by Clément Stenac's avatar Clément Stenac

* Sorting

* Fix a memory leak / crasher
parent 69204454
...@@ -46,8 +46,12 @@ StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, ...@@ -46,8 +46,12 @@ StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
view->setIconSize( QSize(20,20) ); view->setIconSize( QSize(20,20) );
view->setAlternatingRowColors( true ); view->setAlternatingRowColors( true );
view->header()->resizeSection( 0, 300 ); view->header()->resizeSection( 0, 300 );
view->header()->setSortIndicatorShown( true );
view->header()->setClickable( true );
view->setSelectionMode( QAbstractItemView::ExtendedSelection ); view->setSelectionMode( QAbstractItemView::ExtendedSelection );
// connect( view->header(), SIGNAL( sectionClicked( int)), view, SLOT( sortByColumn(int)));
connect( view, SIGNAL( activated( const QModelIndex& ) ), model, connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
SLOT( activateItem( const QModelIndex& ) ) ); SLOT( activateItem( const QModelIndex& ) ) );
......
...@@ -73,6 +73,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m) ...@@ -73,6 +73,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
strings.append( "" ); strings.append( "" );
strings.append( "" ); strings.append( "" );
strings.append( "" ); strings.append( "" );
strings.append( "" );
} }
PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m) PLItem::PLItem( int _i_id, int _i_input_id, PLItem *parent, PLModel *m)
...@@ -88,6 +89,7 @@ PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m ) ...@@ -88,6 +89,7 @@ PLItem::PLItem( playlist_item_t * p_item, PLItem *parent, PLModel *m )
PLItem::~PLItem() PLItem::~PLItem()
{ {
qDeleteAll(children); qDeleteAll(children);
children.clear();
} }
void PLItem::insertChild( PLItem *item, int i_pos, bool signal ) void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
...@@ -118,12 +120,15 @@ int PLItem::row() const ...@@ -118,12 +120,15 @@ int PLItem::row() const
void PLItem::update( playlist_item_t *p_item, bool iscurrent ) void PLItem::update( playlist_item_t *p_item, bool iscurrent )
{ {
char psz_duration[MSTRTIME_MAX_SIZE];
assert( p_item->p_input->i_id == i_input_id ); assert( p_item->p_input->i_id == i_input_id );
strings[0] = QString::fromUtf8( p_item->p_input->psz_name ); strings[0] = QString::fromUtf8( p_item->p_input->psz_name );
if( p_item->p_input->p_meta ) if( p_item->p_input->p_meta )
{ {
strings[1] = QString::fromUtf8( p_item->p_input->p_meta->psz_artist ); strings[1] = QString::fromUtf8( p_item->p_input->p_meta->psz_artist );
} }
secstotimestr( psz_duration, p_item->p_input->i_duration / 1000000 );
strings[2] = QString( psz_duration );
type = p_item->p_input->i_type; type = p_item->p_input->i_type;
current = iscurrent; current = iscurrent;
} }
...@@ -301,7 +306,8 @@ QModelIndex PLModel::parent(const QModelIndex &index) const ...@@ -301,7 +306,8 @@ QModelIndex PLModel::parent(const QModelIndex &index) const
if( !parentItem || parentItem == rootItem ) return QModelIndex(); if( !parentItem || parentItem == rootItem ) return QModelIndex();
if( ! parentItem->parentItem ) if( ! parentItem->parentItem )
{ {
msg_Err( p_playlist, "No parent parent, trying row 0 ----- PLEASE REPORT THIS ------" ); msg_Err( p_playlist, "No parent parent, trying row 0 " );
msg_Err( p_playlist, "----- PLEASE REPORT THIS ------" );
return createIndex( 0, 0, parentItem ); return createIndex( 0, 0, parentItem );
} }
QModelIndex ind = createIndex(parentItem->row(), 0, parentItem); QModelIndex ind = createIndex(parentItem->row(), 0, parentItem);
...@@ -311,7 +317,7 @@ QModelIndex PLModel::parent(const QModelIndex &index) const ...@@ -311,7 +317,7 @@ QModelIndex PLModel::parent(const QModelIndex &index) const
int PLModel::columnCount( const QModelIndex &i) const int PLModel::columnCount( const QModelIndex &i) const
{ {
if( i_depth == 1 ) return 1; if( i_depth == 1 ) return 1;
return 2; return 3;
} }
int PLModel::childrenCount(const QModelIndex &parent) const int PLModel::childrenCount(const QModelIndex &parent) const
...@@ -508,10 +514,10 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -508,10 +514,10 @@ void PLModel::rebuild( playlist_item_t *p_root )
/* Clear the tree */ /* Clear the tree */
if( rootItem ) if( rootItem )
{ {
PLItem *deleted;
beginRemoveRows( index( rootItem, 0 ), 0, beginRemoveRows( index( rootItem, 0 ), 0,
rootItem->children.size() -1 ); rootItem->children.size() -1 );
qDeleteAll( rootItem->children ); qDeleteAll( rootItem->children );
rootItem->children.clear();
endRemoveRows(); endRemoveRows();
} }
if( p_root ) if( p_root )
...@@ -635,6 +641,26 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList ) ...@@ -635,6 +641,26 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
PL_UNLOCK; PL_UNLOCK;
} }
/******* Volume III: Sorting and searching ********/
void PLModel::sort( int column, Qt::SortOrder order )
{
PL_LOCK;
playlist_item_t *p_root = playlist_ItemGetById( p_playlist, rootItem->i_id );
int i_mode;
switch( column )
{
case 0: i_mode = SORT_TITLE_NODES_FIRST;break;
case 1: i_mode = SORT_ARTIST;break;
case 2: i_mode = SORT_DURATION; break;
}
if( p_root )
playlist_RecursiveNodeSort( p_playlist, p_root, i_mode,
order == Qt::AscendingOrder ? ORDER_NORMAL :
ORDER_REVERSE );
PL_UNLOCK
rebuild();
}
/*********** Popup *********/ /*********** Popup *********/
void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list )
{ {
......
...@@ -118,6 +118,7 @@ public: ...@@ -118,6 +118,7 @@ public:
/* Actions made by the views */ /* Actions made by the views */
void popup( QModelIndex & index, QPoint &point, QModelIndexList list ); void popup( QModelIndex & index, QPoint &point, QModelIndexList list );
void doDelete( QModelIndexList selected ); void doDelete( QModelIndexList selected );
void sort( int column, Qt::SortOrder order );
private: private:
void addCallbacks(); void addCallbacks();
void delCallbacks(); void delCallbacks();
......
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