[vlc-devel] commit: qt4: remove model from PLItem, and do emitting signals from model ( Ilkka Ollakka )
git version control
git at videolan.org
Sun Aug 16 15:26:22 CEST 2009
vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sun Aug 16 16:23:56 2009 +0300| [5c8f39a1abdcf90767364741a54b7094b3c49453] | committer: Ilkka Ollakka
qt4: remove model from PLItem, and do emitting signals from model
Also emit layoutAboutToBeChanged/layoutChanged() more. Speeds up
playlist-view atleast for me
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5c8f39a1abdcf90767364741a54b7094b3c49453
---
.../gui/qt4/components/playlist/playlist_item.cpp | 27 ++++---------
.../gui/qt4/components/playlist/playlist_item.hpp | 11 ++---
.../gui/qt4/components/playlist/playlist_model.cpp | 41 +++++++++++++-------
3 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/playlist_item.cpp b/modules/gui/qt4/components/playlist/playlist_item.cpp
index 4faa53c..6330427 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.cpp
@@ -29,11 +29,9 @@
#include <assert.h>
#include "qt4.hpp"
-#include "components/playlist/playlist_model.hpp"
+#include "playlist_item.hpp"
#include <vlc_intf_strings.h>
-#include <QSettings>
-
#include "sorting.h"
/*************************************************************************
@@ -48,29 +46,27 @@
*/
-void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent, PLModel *m, QSettings *settings )
+void PLItem::init( playlist_item_t *_playlist_item, PLItem *parent )
{
parentItem = parent; /* Can be NULL, but only for the rootItem */
i_id = _playlist_item->i_id; /* Playlist item specific id */
- model = m; /* PLModel (QAbsmodel) */
p_input = _playlist_item->p_input;
vlc_gc_incref( p_input );
- assert( model ); /* We need a model */
}
/*
Constructors
Call the above function init
*/
-PLItem::PLItem( playlist_item_t *p_item, PLItem *parent, PLModel *m )
+PLItem::PLItem( playlist_item_t *p_item, PLItem *parent )
{
- init( p_item, parent, m, NULL );
+ init( p_item, parent );
}
-PLItem::PLItem( playlist_item_t * p_item, QSettings *settings, PLModel *m )
+PLItem::PLItem( playlist_item_t * p_item )
{
- init( p_item, NULL, m, settings );
+ init( p_item, NULL );
}
PLItem::~PLItem()
@@ -85,22 +81,15 @@ PLItem::~PLItem()
*/
void PLItem::insertChild( PLItem *item, int i_pos, bool signal )
{
- if( signal )
- model->beginInsertRows( model->index( this , 0 ), i_pos, i_pos );
children.insert( i_pos, item );
- if( signal )
- model->endInsertRows();
}
-void PLItem::remove( PLItem *removed )
+void PLItem::remove( PLItem *removed, int i_depth )
{
- if( model->i_depth == DEPTH_SEL || parentItem )
+ if( i_depth == DEPTH_SEL || parentItem )
{
int i_index = parentItem->children.indexOf( removed );
- model->beginRemoveRows( model->index( parentItem, 0 ),
- i_index, i_index );
parentItem->children.removeAt( i_index );
- model->endRemoveRows();
}
}
diff --git a/modules/gui/qt4/components/playlist/playlist_item.hpp b/modules/gui/qt4/components/playlist/playlist_item.hpp
index ef5cfe7..8ccfb09 100644
--- a/modules/gui/qt4/components/playlist/playlist_item.hpp
+++ b/modules/gui/qt4/components/playlist/playlist_item.hpp
@@ -40,8 +40,8 @@ class PLItem
{
friend class PLModel;
public:
- PLItem( playlist_item_t *, PLItem *parent, PLModel * );
- PLItem( playlist_item_t *, QSettings *, PLModel * );
+ PLItem( playlist_item_t *, PLItem *parent );
+ PLItem( playlist_item_t * );
~PLItem();
int row() const;
@@ -49,10 +49,10 @@ public:
void insertChild( PLItem *, int p, bool signal = true );
void appendChild( PLItem *item, bool signal = true )
{
- insertChild( item, children.count(), signal );
+ children.insert( children.count(), item );
};
- void remove( PLItem *removed );
+ void remove( PLItem *removed, int i_depth );
PLItem *child( int row ) { return children.value( row ); };
int childCount() const { return children.count(); };
@@ -67,9 +67,8 @@ protected:
input_item_t *p_input;
private:
- void init( playlist_item_t *, PLItem *, PLModel *, QSettings * );
+ void init( playlist_item_t *, PLItem * );
PLItem *parentItem;
- PLModel *model;
};
#endif
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 0b05aa2..1e64255 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -294,7 +294,7 @@ void PLModel::removeItem( int i_id )
{
PLItem *item = FindById( rootItem, i_id );
if( currentItem && item && currentItem->p_input == item->p_input ) currentItem = NULL;
- if( item ) item->remove( item );
+ if( item ) item->remove( item, i_depth );
}
/* callbacks and slots */
@@ -357,7 +357,7 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
int columncount = 0;
int metadata = 1;
- if( item->model->i_depth == DEPTH_SEL )
+ if( i_depth == DEPTH_SEL )
{
vlc_mutex_lock( &item->p_input->lock );
QString returninfo = QString( qfu( item->p_input->psz_name ) );
@@ -716,8 +716,12 @@ void PLModel::ProcessItemAppend( const playlist_add_t *p_add )
p_item->p_parent->i_id != rootItem->i_id )
goto end;
- newItem = new PLItem( p_item, nodeItem, this );
+ newItem = new PLItem( p_item, nodeItem );
+ emit layoutAboutToBeChanged();
+ emit beginInsertRows( index( newItem, 0 ), nodeItem->childCount(), nodeItem->childCount()+1 );
nodeItem->appendChild( newItem );
+ emit endInsertRows();
+ emit layoutChanged();
UpdateTreeItem( p_item, newItem, true );
end:
PL_UNLOCK;
@@ -738,23 +742,25 @@ void PLModel::rebuild( playlist_item_t *p_root )
/* Invalidate cache */
i_cached_id = i_cached_input_id = -1;
+ emit layoutAboutToBeChanged();
+
PL_LOCK;
/* Clear the tree */
if( rootItem )
{
if( rootItem->children.size() )
{
- beginRemoveRows( index( rootItem, 0 ), 0,
+ emit beginRemoveRows( index( rootItem, 0 ), 0,
rootItem->children.size() -1 );
qDeleteAll( rootItem->children );
rootItem->children.clear();
- endRemoveRows();
+ emit endRemoveRows();
}
}
if( p_root )
{
delete rootItem;
- rootItem = new PLItem( p_root, getSettings(), this );
+ rootItem = new PLItem( p_root );
}
assert( rootItem );
/* Recreate from root */
@@ -783,8 +789,10 @@ void PLModel::rebuild( playlist_item_t *p_root )
/* This function must be entered WITH the playlist lock */
void PLModel::UpdateNodeChildren( PLItem *root )
{
+ emit layoutAboutToBeChanged();
playlist_item_t *p_node = playlist_ItemGetById( p_playlist, root->i_id );
UpdateNodeChildren( p_node, root );
+ emit layoutChanged();
}
/* This function must be entered WITH the playlist lock */
@@ -793,9 +801,11 @@ void PLModel::UpdateNodeChildren( playlist_item_t *p_node, PLItem *root )
for( int i = 0; i < p_node->i_children ; i++ )
{
if( p_node->pp_children[i]->i_flags & PLAYLIST_DBL_FLAG ) continue;
- PLItem *newItem = new PLItem( p_node->pp_children[i], root, this );
- root->appendChild( newItem, false );
- UpdateTreeItem( newItem, false, true );
+ PLItem *newItem = new PLItem( p_node->pp_children[i], root );
+ emit beginInsertRows( index( newItem, 0 ), root->childCount(), root->childCount()+1 );
+ root->appendChild( newItem );
+ emit endInsertRows();
+ UpdateTreeItem( newItem, true, true );
if( i_depth == DEPTH_PL && p_node->pp_children[i]->i_children != -1 )
UpdateNodeChildren( p_node->pp_children[i], newItem );
}
@@ -875,7 +885,10 @@ void PLModel::doDeleteItem( PLItem *item, QModelIndexList *fullList )
else
playlist_NodeDelete( p_playlist, p_item, true, false );
/* And finally, remove it from the tree */
- item->remove( item );
+ emit beginRemoveRows( index( item->parentItem, 0), item->parentItem->children.indexOf( item ),
+ item->parentItem->children.indexOf( item )+1 );
+ item->remove( item, i_depth );
+ emit endRemoveRows();
PL_UNLOCK;
}
@@ -985,18 +998,18 @@ void PLModel::viewchanged( int meta )
if( i_showflags & meta )
/* Removing columns */
{
- beginRemoveColumns( parent, index, index+1 );
+ emit beginRemoveColumns( parent, index, index+1 );
i_showflags &= ~( meta );
getSettings()->setValue( "qt-pl-showflags", i_showflags );
- endRemoveColumns();
+ emit endRemoveColumns();
}
else
{
/* Adding columns */
- beginInsertColumns( parent, index, index+1 );
+ emit beginInsertColumns( parent, index, index+1 );
i_showflags |= meta;
getSettings()->setValue( "qt-pl-showflags", i_showflags );
- endInsertColumns();
+ emit endInsertColumns();
}
emit columnsChanged( meta );
rebuild();
More information about the vlc-devel
mailing list