From d1781362a43be609b351fce39e1c8aaa38cdb769 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Thu, 16 Oct 2008 11:51:15 +0000 Subject: [PATCH] heavily improved performance when adding items to file browser tree-widget (closes #2146218) git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1759 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 7 +++++++ include/file_browser.h | 7 +++---- src/gui/file_browser.cpp | 36 ++++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index e410beba1..769ebf5b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-10-16 Tobias Doerffel + + * include/file_browser.h: + * src/gui/file_browser.cpp: + heavily improved performance when adding items to file browser + tree-widget (closes #2146218) + 2008-10-15 dieEasy * data/locale/it.qm: diff --git a/include/file_browser.h b/include/file_browser.h index 2619e8219..02d628d6e 100644 --- a/include/file_browser.h +++ b/include/file_browser.h @@ -142,7 +142,7 @@ public: private: - void initPixmapStuff( void ); + void initPixmaps( void ); bool addItems( const QString & _path ); @@ -186,8 +186,7 @@ public: fileItem( QTreeWidget * _parent, const QString & _name, const QString & _path ); - fileItem( QTreeWidgetItem * _parent, const QString & _name, - const QString & _path ); + fileItem( const QString & _name, const QString & _path ); inline QString fullName( void ) const { @@ -210,7 +209,7 @@ public: private: - void initPixmapStuff( void ); + void initPixmaps( void ); void determineFileType( void ); static QPixmap * s_projectFilePixmap; diff --git a/src/gui/file_browser.cpp b/src/gui/file_browser.cpp index 0317965f7..c0e0ec05d 100644 --- a/src/gui/file_browser.cpp +++ b/src/gui/file_browser.cpp @@ -47,6 +47,12 @@ #include "string_pair_drag.h" #include "text_float.h" +enum TreeWidgetItemTypes +{ + TypeFileItem = QTreeWidgetItem::UserType, + TypeDirectoryItem +} ; + fileBrowser::fileBrowser( const QString & _directories, const QString & _filter, const QString & _title, const QPixmap & _pm, @@ -536,12 +542,12 @@ QPixmap * directory::s_folderLockedPixmap = NULL; directory::directory( const QString & _name, const QString & _path, const QString & _filter ) : + QTreeWidgetItem( QStringList( _name ), TypeDirectoryItem ), m_directories( _path ), m_filter( _filter ) { - initPixmapStuff(); + initPixmaps(); - setText( 0, _name ); setChildIndicatorPolicy( QTreeWidgetItem::ShowIndicator ); if( !QDir( fullName() ).isReadable() ) @@ -557,7 +563,7 @@ directory::directory( const QString & _name, const QString & _path, -void directory::initPixmapStuff( void ) +void directory::initPixmaps( void ) { if( s_folderPixmap == NULL ) { @@ -662,19 +668,20 @@ bool directory::addItems( const QString & _path ) } } + QList items; files = thisDir.entryList( QDir::Files, QDir::Name ); for( QStringList::const_iterator it = files.constBegin(); it != files.constEnd(); ++it ) { QString cur_file = *it; - if( cur_file[0] != '.' - && thisDir.match( m_filter, cur_file.toLower() ) - /*QDir::match( FILE_FILTER, cur_file )*/ ) + if( cur_file[0] != '.' && + thisDir.match( m_filter, cur_file.toLower() ) ) { - (void) new fileItem( this, cur_file, _path ); + items << new fileItem( cur_file, _path ); added_something = true; } } + addChildren( items ); treeWidget()->setUpdatesEnabled( true ); @@ -694,31 +701,28 @@ QPixmap * fileItem::s_unknownFilePixmap = NULL; fileItem::fileItem( QTreeWidget * _parent, const QString & _name, const QString & _path ) : - QTreeWidgetItem( _parent ), + QTreeWidgetItem( _parent, QStringList( _name) , TypeFileItem ), m_path( _path ) { - setText( 0, _name ); determineFileType(); - initPixmapStuff(); + initPixmaps(); } -fileItem::fileItem( QTreeWidgetItem * _parent, const QString & _name, - const QString & _path ) : - QTreeWidgetItem( _parent ), +fileItem::fileItem( const QString & _name, const QString & _path ) : + QTreeWidgetItem( QStringList( _name ), TypeFileItem ), m_path( _path ) { - setText( 0, _name ); determineFileType(); - initPixmapStuff(); + initPixmaps(); } -void fileItem::initPixmapStuff( void ) +void fileItem::initPixmaps( void ) { if( s_projectFilePixmap == NULL ) {