Commit f5112afb authored by Jakob Leben's avatar Jakob Leben

qt4: cosmetics and consistence

for future generations
parent be54c4d2
...@@ -108,9 +108,9 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */ ...@@ -108,9 +108,9 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
rebuild( p_root ); rebuild( p_root );
CONNECT( THEMIM->getIM(), metaChanged( input_item_t *), CONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
this, ProcessInputItemUpdate( input_item_t *) ); this, processInputItemUpdate( input_item_t *) );
CONNECT( THEMIM, inputChanged( input_thread_t * ), CONNECT( THEMIM, inputChanged( input_thread_t * ),
this, ProcessInputItemUpdate( input_thread_t* ) ); this, processInputItemUpdate( input_thread_t* ) );
} }
PLModel::~PLModel() PLModel::~PLModel()
...@@ -285,7 +285,7 @@ void PLModel::dropMove( QByteArray& data, PLItem *target, int row ) ...@@ -285,7 +285,7 @@ void PLModel::dropMove( QByteArray& data, PLItem *target, int row )
ids.append( item->i_id ); ids.append( item->i_id );
model_items.append( item ); model_items.append( item );
TakeItem( item ); takeItem( item );
} }
int count = ids.size(); int count = ids.size();
if( count ) if( count )
...@@ -309,15 +309,15 @@ void PLModel::dropMove( QByteArray& data, PLItem *target, int row ) ...@@ -309,15 +309,15 @@ void PLModel::dropMove( QByteArray& data, PLItem *target, int row )
new_pos ); new_pos );
PL_UNLOCK; PL_UNLOCK;
InsertChildren( target, model_items, model_pos ); insertChildren( target, model_items, model_pos );
} }
} }
/* remove item with its id */ /* remove item with its id */
void PLModel::removeItem( int i_id ) void PLModel::removeItem( int i_id )
{ {
PLItem *item = FindById( rootItem, i_id ); PLItem *item = findById( rootItem, i_id );
RemoveItem( item ); removeItem( item );
} }
/* callbacks and slots */ /* callbacks and slots */
...@@ -501,11 +501,6 @@ int PLModel::columnCount( const QModelIndex &i) const ...@@ -501,11 +501,6 @@ int PLModel::columnCount( const QModelIndex &i) const
return columnCount; return columnCount;
} }
int PLModel::childrenCount( const QModelIndex &parent ) const
{
return rowCount( parent );
}
int PLModel::rowCount( const QModelIndex &parent ) const int PLModel::rowCount( const QModelIndex &parent ) const
{ {
PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem; PLItem *parentItem = parent.isValid() ? getItem( parent ) : rootItem;
...@@ -569,21 +564,21 @@ void PLModel::setRandom( bool on ) ...@@ -569,21 +564,21 @@ void PLModel::setRandom( bool on )
/************************* Lookups *****************************/ /************************* Lookups *****************************/
PLItem *PLModel::FindById( PLItem *root, int i_id ) PLItem *PLModel::findById( PLItem *root, int i_id )
{ {
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 )
{ {
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; } #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; } #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 )
{ {
if( ( !b_input && i_cached_id == i_id) || if( ( !b_input && i_cached_id == i_id) ||
( b_input && i_cached_input_id ==i_id ) ) ( b_input && i_cached_input_id ==i_id ) )
...@@ -617,7 +612,7 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input ) ...@@ -617,7 +612,7 @@ PLItem * PLModel::FindInner( PLItem *root, int i_id, bool b_input )
} }
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 ) if( b_input )
...@@ -670,21 +665,21 @@ void PLModel::customEvent( QEvent *event ) ...@@ -670,21 +665,21 @@ void PLModel::customEvent( QEvent *event )
PLEvent *ple = static_cast<PLEvent *>(event); PLEvent *ple = static_cast<PLEvent *>(event);
if( type == ItemAppend_Type ) if( type == ItemAppend_Type )
ProcessItemAppend( &ple->add ); processItemAppend( &ple->add );
else if( type == ItemDelete_Type ) else if( type == ItemDelete_Type )
ProcessItemRemoval( ple->i_id ); processItemRemoval( ple->i_id );
else else
rebuild(); rebuild();
} }
/**** Events processing ****/ /**** Events processing ****/
void PLModel::ProcessInputItemUpdate( input_thread_t *p_input ) void PLModel::processInputItemUpdate( input_thread_t *p_input )
{ {
if( !p_input ) return; if( !p_input ) return;
ProcessInputItemUpdate( input_GetItem( p_input ) ); processInputItemUpdate( input_GetItem( p_input ) );
if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) ) if( p_input && !( p_input->b_dead || !vlc_object_alive( p_input ) ) )
{ {
PLItem *item = FindByInput( rootItem, input_GetItem( p_input )->i_id ); PLItem *item = findByInput( rootItem, input_GetItem( p_input )->i_id );
currentItem = item; currentItem = item;
emit currentChanged( index( item, 0 ) ); emit currentChanged( index( item, 0 ) );
} }
...@@ -693,15 +688,15 @@ void PLModel::ProcessInputItemUpdate( input_thread_t *p_input ) ...@@ -693,15 +688,15 @@ void PLModel::ProcessInputItemUpdate( input_thread_t *p_input )
currentItem = NULL; currentItem = NULL;
} }
} }
void PLModel::ProcessInputItemUpdate( input_item_t *p_item ) void PLModel::processInputItemUpdate( input_item_t *p_item )
{ {
if( !p_item || p_item->i_id <= 0 ) return; if( !p_item || p_item->i_id <= 0 ) return;
PLItem *item = FindByInput( rootItem, p_item->i_id ); PLItem *item = findByInput( rootItem, p_item->i_id );
if( item ) if( item )
UpdateTreeItem( item, true, true); updateTreeItem( item, true, true);
} }
void PLModel::ProcessItemRemoval( int i_id ) void PLModel::processItemRemoval( int i_id )
{ {
if( i_id <= 0 ) return; if( i_id <= 0 ) return;
if( i_id == i_cached_id ) i_cached_id = -1; if( i_id == i_cached_id ) i_cached_id = -1;
...@@ -710,12 +705,12 @@ void PLModel::ProcessItemRemoval( int i_id ) ...@@ -710,12 +705,12 @@ void PLModel::ProcessItemRemoval( int i_id )
removeItem( i_id ); removeItem( i_id );
} }
void PLModel::ProcessItemAppend( const playlist_add_t *p_add ) void PLModel::processItemAppend( const playlist_add_t *p_add )
{ {
playlist_item_t *p_item = NULL; playlist_item_t *p_item = NULL;
PLItem *newItem = NULL; PLItem *newItem = NULL;
PLItem *nodeItem = FindById( rootItem, p_add->i_node ); PLItem *nodeItem = findById( rootItem, p_add->i_node );
if( !nodeItem ) return; if( !nodeItem ) return;
PL_LOCK; PL_LOCK;
...@@ -731,7 +726,7 @@ void PLModel::ProcessItemAppend( const playlist_add_t *p_add ) ...@@ -731,7 +726,7 @@ void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() ); beginInsertRows( index( nodeItem, 0 ), nodeItem->childCount(), nodeItem->childCount() );
nodeItem->appendChild( newItem ); nodeItem->appendChild( newItem );
endInsertRows(); endInsertRows();
UpdateTreeItem( newItem, true ); updateTreeItem( newItem, true );
return; return;
end: end:
PL_UNLOCK; PL_UNLOCK;
...@@ -762,9 +757,9 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -762,9 +757,9 @@ void PLModel::rebuild( playlist_item_t *p_root )
} }
assert( rootItem ); assert( rootItem );
/* Recreate from root */ /* Recreate from root */
UpdateChildren( rootItem ); updateChildren( rootItem );
if( (p_item = playlist_CurrentPlayingItem(p_playlist)) ) if( (p_item = playlist_CurrentPlayingItem(p_playlist)) )
currentItem = FindByInput( rootItem, p_item->p_input->i_id ); currentItem = findByInput( rootItem, p_item->p_input->i_id );
else else
currentItem = NULL; currentItem = NULL;
PL_UNLOCK; PL_UNLOCK;
...@@ -776,7 +771,7 @@ void PLModel::rebuild( playlist_item_t *p_root ) ...@@ -776,7 +771,7 @@ void PLModel::rebuild( playlist_item_t *p_root )
addCallbacks(); addCallbacks();
} }
void PLModel::TakeItem( PLItem *item ) void PLModel::takeItem( PLItem *item )
{ {
assert( item ); assert( item );
PLItem *parent = item->parentItem; PLItem *parent = item->parentItem;
...@@ -788,7 +783,7 @@ void PLModel::TakeItem( PLItem *item ) ...@@ -788,7 +783,7 @@ void PLModel::TakeItem( PLItem *item )
endRemoveRows(); endRemoveRows();
} }
void PLModel::InsertChildren( PLItem *node, QList<PLItem*>& items, int i_pos ) void PLModel::insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
{ {
assert( node ); assert( node );
int count = items.size(); int count = items.size();
...@@ -802,7 +797,7 @@ void PLModel::InsertChildren( PLItem *node, QList<PLItem*>& items, int i_pos ) ...@@ -802,7 +797,7 @@ void PLModel::InsertChildren( PLItem *node, QList<PLItem*>& items, int i_pos )
endInsertRows(); endInsertRows();
} }
void PLModel::RemoveItem( PLItem *item ) void PLModel::removeItem( PLItem *item )
{ {
if( !item ) return; if( !item ) return;
if( currentItem == item ) if( currentItem == item )
...@@ -816,14 +811,14 @@ void PLModel::RemoveItem( PLItem *item ) ...@@ -816,14 +811,14 @@ void PLModel::RemoveItem( PLItem *item )
} }
/* This function must be entered WITH the playlist lock */ /* This function must be entered WITH the playlist lock */
void PLModel::UpdateChildren( PLItem *root ) void PLModel::updateChildren( PLItem *root )
{ {
playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id ); playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
UpdateChildren( p_node, root ); updateChildren( p_node, root );
} }
/* This function must be entered WITH the playlist lock */ /* This function must be entered WITH the playlist lock */
void PLModel::UpdateChildren( playlist_item_t *p_node, PLItem *root ) void PLModel::updateChildren( playlist_item_t *p_node, PLItem *root )
{ {
playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist); playlist_item_t *p_item = playlist_CurrentPlayingItem(p_playlist);
for( int i = 0; i < p_node->i_children ; i++ ) for( int i = 0; i < p_node->i_children ; i++ )
...@@ -837,12 +832,12 @@ void PLModel::UpdateChildren( playlist_item_t *p_node, PLItem *root ) ...@@ -837,12 +832,12 @@ void PLModel::UpdateChildren( playlist_item_t *p_node, PLItem *root )
emit currentChanged( index( currentItem, 0 ) ); emit currentChanged( index( currentItem, 0 ) );
} }
if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 ) if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
UpdateChildren( p_node->pp_children[i], newItem ); updateChildren( p_node->pp_children[i], newItem );
} }
} }
/* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/ /* Function doesn't need playlist-lock, as we don't touch playlist_item_t stuff here*/
void PLModel::UpdateTreeItem( PLItem *item, bool signal, bool force ) void PLModel::updateTreeItem( PLItem *item, bool signal, bool force )
{ {
if ( !item || !item->p_input ) if ( !item || !item->p_input )
return; return;
...@@ -909,7 +904,7 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList ) ...@@ -909,7 +904,7 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
/* And finally, remove it from the tree */ /* And finally, remove it from the tree */
int itemIndex = item->parentItem->children.indexOf( item ); int itemIndex = item->parentItem->children.indexOf( item );
beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex ); beginRemoveRows( index( item->parentItem, 0), itemIndex, itemIndex );
RemoveItem( item ); removeItem( item );
endRemoveRows(); endRemoveRows();
} }
...@@ -936,7 +931,7 @@ void PLModel::sort( int i_root_id, int column, Qt::SortOrder order ) ...@@ -936,7 +931,7 @@ void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
} }
} }
PLItem *item = FindById( rootItem, i_root_id ); PLItem *item = findById( rootItem, i_root_id );
if( !item ) return; if( !item ) return;
QModelIndex qIndex = index( item, 0 ); QModelIndex qIndex = index( item, 0 );
int count = item->children.size(); int count = item->children.size();
...@@ -962,7 +957,7 @@ void PLModel::sort( int i_root_id, int column, Qt::SortOrder order ) ...@@ -962,7 +957,7 @@ void PLModel::sort( int i_root_id, int column, Qt::SortOrder order )
if( count ) if( count )
{ {
beginInsertRows( qIndex, 0, count - 1 ); beginInsertRows( qIndex, 0, count - 1 );
UpdateChildren( item ); updateChildren( item );
endInsertRows( ); endInsertRows( );
} }
PL_UNLOCK; PL_UNLOCK;
......
...@@ -90,49 +90,48 @@ public: ...@@ -90,49 +90,48 @@ public:
playlist_item_t *, int, QObject *parent = 0 ); playlist_item_t *, int, QObject *parent = 0 );
~PLModel(); ~PLModel();
/* All types of lookups / QModel stuff */ /*** QModel subclassing ***/
/* Data structure */
QVariant data( const QModelIndex &index, int role ) const; QVariant data( const QModelIndex &index, int role ) const;
Qt::ItemFlags flags( const QModelIndex &index ) const;
QVariant headerData( int section, Qt::Orientation orientation, QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const; int role = Qt::DisplayRole ) const;
QModelIndex index( int r, int c, const QModelIndex &parent ) const;
QModelIndex index( PLItem *, int c ) const;
QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
int itemId( const QModelIndex &index ) const;
bool isCurrent( const QModelIndex &index ) const;
QModelIndex parent( const QModelIndex &index ) const;
int childrenCount( const QModelIndex &parent = QModelIndex() ) const;
int rowCount( const QModelIndex &parent = QModelIndex() ) const; int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const; int columnCount( const QModelIndex &parent = QModelIndex() ) const;
Qt::ItemFlags flags( const QModelIndex &index ) const;
QModelIndex index( int r, int c, const QModelIndex &parent ) const;
QModelIndex parent( const QModelIndex &index ) const;
/* Get current selection */ /* Drag and Drop */
QStringList selectedURIs(); Qt::DropActions supportedDropActions() const;
QMimeData* mimeData( const QModelIndexList &indexes ) const;
bool dropMimeData( const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &target );
QStringList mimeTypes() const;
void rebuild(); void rebuild( playlist_item_t * ); /**** Custom ****/
/* Lookups */
QStringList selectedURIs();
bool hasRandom(); bool hasLoop(); bool hasRepeat(); bool hasRandom(); bool hasLoop(); bool hasRepeat();
int shownFlags() { return i_showflags; }
QModelIndex index( PLItem *, int c ) const;
QModelIndex currentIndex( ) { return index( currentItem, 0 ); };
bool isCurrent( const QModelIndex &index ) const;
int itemId( const QModelIndex &index ) const;
/* Actions made by the views */ /* Actions */
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 search( const QString& search_text ); void search( const QString& search_text );
void sort( int column, Qt::SortOrder order ); void sort( int column, Qt::SortOrder order );
void sort( int i_root_id, int column, Qt::SortOrder order ); void sort( int i_root_id, int column, Qt::SortOrder order );
void removeItem( int ); void removeItem( int );
void rebuild(); void rebuild( playlist_item_t * );
/* DnD handling */
Qt::DropActions supportedDropActions() const;
QMimeData* mimeData( const QModelIndexList &indexes ) const;
bool dropMimeData( const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &target );
QStringList mimeTypes() const;
int shownFlags() { return i_showflags; }
private: private:
void addCallbacks();
void delCallbacks();
void customEvent( QEvent * );
/* General */
PLItem *rootItem; PLItem *rootItem;
PLItem *currentItem; PLItem *currentItem;
...@@ -143,22 +142,25 @@ private: ...@@ -143,22 +142,25 @@ private:
static QIcon icons[ITEM_TYPE_NUMBER]; static QIcon icons[ITEM_TYPE_NUMBER];
/* Update processing */ /* Callbacks related */
void ProcessItemRemoval( int i_id ); void addCallbacks();
void ProcessItemAppend( const playlist_add_t *p_add ); void delCallbacks();
void customEvent( QEvent * );
void processItemRemoval( int i_id );
void processItemAppend( const playlist_add_t *p_add );
/* Actions */ /* Actions */
void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList ); void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
void doDeleteItem( PLItem *item, QModelIndexList *fullList ); void doDeleteItem( PLItem *item, QModelIndexList *fullList );
void UpdateTreeItem( PLItem *, bool, bool force = false ); void updateTreeItem( PLItem *, bool, bool force = false );
void takeItem( PLItem * ); //will not delete item
void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
void dropAppendCopy( QByteArray& data, PLItem *target ); void dropAppendCopy( QByteArray& data, PLItem *target );
void dropMove( QByteArray& data, PLItem *target, int new_pos ); void dropMove( QByteArray& data, PLItem *target, int new_pos );
void TakeItem( PLItem * );
void InsertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
/* The following actions will not signal the view! */ /* The following actions will not signal the view! */
void RemoveItem ( PLItem * ); void removeItem ( PLItem * );
void UpdateChildren( PLItem * ); void updateChildren( PLItem * );
void UpdateChildren( playlist_item_t *, PLItem * ); void updateChildren( playlist_item_t *, PLItem * );
/* Popup */ /* Popup */
int i_popup_item, i_popup_parent, i_popup_column; int i_popup_item, i_popup_parent, i_popup_column;
...@@ -166,15 +168,16 @@ private: ...@@ -166,15 +168,16 @@ private:
QSignalMapper *ContextUpdateMapper; QSignalMapper *ContextUpdateMapper;
/* Lookups */ /* Lookups */
PLItem *FindById( PLItem *, int ); PLItem *findById( PLItem *, int );
PLItem *FindByInput( PLItem *, int ); PLItem *findByInput( PLItem *, int );
PLItem *FindInner( PLItem *, int , bool ); PLItem *findInner( PLItem *, int , bool );
static inline PLItem *getItem( QModelIndex index ); static inline PLItem *getItem( QModelIndex index );
int metaColumn ( int column ) const; int metaColumn ( int column ) const;
PLItem *p_cached_item; PLItem *p_cached_item;
PLItem *p_cached_item_bi; PLItem *p_cached_item_bi;
int i_cached_id; int i_cached_id;
int i_cached_input_id; int i_cached_input_id;
signals: signals:
void shouldRemove( int ); void shouldRemove( int );
void currentChanged( const QModelIndex& ); void currentChanged( const QModelIndex& );
...@@ -199,8 +202,8 @@ private slots: ...@@ -199,8 +202,8 @@ private slots:
void popupSortAsc(); void popupSortAsc();
void popupSortDesc(); void popupSortDesc();
void viewchanged( int ); void viewchanged( int );
void ProcessInputItemUpdate( input_item_t *); void processInputItemUpdate( input_item_t *);
void ProcessInputItemUpdate( input_thread_t* p_input ); void processInputItemUpdate( input_thread_t* p_input );
}; };
#endif #endif
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