[KPhotoAlbum] Speeding up thumbnail view even more

Robert L Krawitz rlk at alum.mit.edu
Sun Feb 12 02:19:23 GMT 2006


Here's a prototype of a further improvement to the thumbnail code --
it's less aggressive about flushing the thumbnail cache whenever
anything changes.  This is surely not the final form something like
this will take.  It makes redrawing the thumbnail view much faster
when looking at a new selection.



Index: mainview.h
===================================================================
--- mainview.h  (revision 508519)
+++ mainview.h  (working copy)
@@ -112,7 +112,8 @@
     void slotConfigureKeyBindings();
     void slotSetFileName( const QString& );
     void slotThumbNailSelectionChanged();
-    void reloadThumbnails();
+    void reloadThumbnails(bool);
+    void reloadThumbnailsHard();
     void slotUpdateViewMenu( Category::ViewSize, Category::ViewType );
     void slotShowNotOnDisk();
     void markDirty();
Index: mainview.cpp
===================================================================
--- mainview.cpp        (revision 508519)
+++ mainview.cpp        (working copy)
@@ -282,7 +282,7 @@
 {
     if ( ! _optionsDialog ) {
         _optionsDialog = new OptionsDialog( this );
-        connect( _optionsDialog, SIGNAL( changed() ), this, SLOT( reloadThumbnails() ) );
+        connect( _optionsDialog, SIGNAL( changed() ), this, SLOT( reloadThumbnailsHard() ) );
         connect( _optionsDialog, SIGNAL( changed() ), this, SLOT( startAutoSaveTimer() ) );
     }
     _optionsDialog->show();
@@ -328,7 +328,7 @@
     createImageConfig();
     _imageConfigure->configure( list,  oneAtATime );
     if ( _imageConfigure->thumbnailShouldReload() )
-        reloadThumbnails();
+        reloadThumbnails(true);
 }
 
 
@@ -671,7 +671,7 @@
 
 void MainView::showThumbNails()
 {
-    reloadThumbnails();
+    reloadThumbnails(false);
     _stack->raiseWidget( _thumbnailView );
     _thumbnailView->setFocus();
     updateStates( true );
@@ -956,12 +956,17 @@
     _sortByDateAndTime->setEnabled(selection.count() > 1 );
 }
 
-void MainView::reloadThumbnails()
+void MainView::reloadThumbnails(bool hard)
 {
-    _thumbnailView->reload();
+    _thumbnailView->reload(hard);
     slotThumbNailSelectionChanged();
 }
 
+void MainView::reloadThumbnailsHard()
+{
+    reloadThumbnails(true);
+}
+
 void MainView::slotUpdateViewMenu( Category::ViewSize size, Category::ViewType type )
 {
     if ( size == Category::Small && type == Category::ListView )
@@ -1177,7 +1182,7 @@
     for( KURL::List::ConstIterator it = urls.begin(); it != urls.end(); ++it ) {
         ImageLoader::removeThumbnail( (*it).path() );
     }
-    reloadThumbnails();
+    reloadThumbnails(true);
 }
 
 ImageSearchInfo MainView::currentContext()
@@ -1255,14 +1260,14 @@
 {
     ImageDB::instance()->setDateRange( range, _dateBar->includeFuzzyCounts() );
     _browser->reload();
-    reloadThumbnails();
+    reloadThumbnails(false);
 }
 
 void MainView::clearDateRange()
 {
     ImageDB::instance()->clearDateRange();
     _browser->reload();
-    reloadThumbnails();
+    reloadThumbnails(false);
 }
 
 void MainView::runSurvey()
Index: ThumbnailView/ThumbnailView.cpp
===================================================================
--- ThumbnailView/ThumbnailView.cpp     (revision 508519)
+++ ThumbnailView/ThumbnailView.cpp     (working copy)
@@ -270,6 +270,12 @@
     updateCell( fileName );
 }
 
+void ThumbnailView::ThumbnailView::uncacheThumbnails( const QStringList& thumbnails )
+{
+    for( QStringList::ConstIterator imageIt = thumbnails.begin(); imageIt != thumbnails.end(); ++imageIt )
+        pixmapCache().remove( *imageIt );
+}
+
 /**
  * Request a repaint of the cell showing filename
  *
@@ -734,9 +740,10 @@
     repaintScreen();
 }
 
-void ThumbnailView::ThumbnailView::reload()
+void ThumbnailView::ThumbnailView::reload(bool hard)
 {
-    pixmapCache().clear();
+    if (hard)
+        pixmapCache().clear();
     _selectedFiles.clear();
     updateCellSize();
     repaintScreen();
Index: ThumbnailView/ThumbnailView.h
===================================================================
--- ThumbnailView/ThumbnailView.h       (revision 508519)
+++ ThumbnailView/ThumbnailView.h       (working copy)
@@ -37,12 +37,13 @@
 
     enum Order { ViewOrder, SortedOrder };
     QStringList imageList( Order ) const;
-    void reload();
+    void reload(bool hard=true);
     QString fileNameUnderCursor() const;
     QString currentItem() const;
     static ThumbnailView* theThumbnailView();
     void setCurrentItem( const QString& fileName );
     void setSortDirection( SortDirection );
+    void uncacheThumbnails(const QStringList &list);
 
 
 public slots:




More information about the Kphotoalbum mailing list