[KPhotoAlbum] Improvements to delete

Jesper K. Pedersen blackie at blackie.dk
Sat Feb 11 17:25:02 GMT 2006


Thanks for the analysis. For your pleasure and information, I chose a sligtly 
different approach to solve the problem than you.

The real problem lay in the fact that we do lookup for all the images in a 
list, which gives us complexity O(n^2). I exchanged the list with a set (see 
set.h), and that gives us complexity O(n).

Cheers
Jesper.

On Thursday 09 February 2006 22:16, Robert L Krawitz wrote:
| This speeds up delete dramatically (particularly if you cancel out of
| the delete!)
|
| --- mainview.cpp~       2006-01-28 23:38:52.000000000 -0500
| +++ mainview.cpp        2006-02-09 22:08:10.000000000 -0500
| @@ -369,19 +369,21 @@
|
|  void MainView::slotDeleteSelected()
|  {
| +    QStringList selectedList = selected();
|      if ( ! _deleteDialog )
|          _deleteDialog = new DeleteDialog( this );
| -    if ( _deleteDialog->exec( selected() ) == QDialog::Accepted )
| +    if ( _deleteDialog->exec( selected() ) == QDialog::Accepted &&
| +        selectedList.count() > 0) {
|          setDirty( true );
|
| -    QStringList images = _thumbnailView->imageList();
| -    QStringList allImages = ImageDB::instance()->images();
| -    QStringList newSet;
| -    for( QStringList::Iterator it = images.begin(); it != images.end();
| ++it ) { -        if ( allImages.contains( *it ) )
| -            newSet.append(*it);
| +       QStringList images = _thumbnailView->imageList();
| +       QStringList newSet;
| +       for( QStringList::Iterator it = images.begin(); it != images.end();
| ++it ) { +           if ( ! selectedList.contains( *it ) )
| +                newSet.append(*it);
| +       }
| +       showThumbNails( newSet );
|      }
| -    showThumbNails( newSet );
|  }
|
|
| This gets rid of the silly warning if you try to delete a file that
| doesn't exist (there's no good reason for warning in that case -- if
| the file does already exist and the delete fails, the user certainly
| should be warned!)
|
| --- deletedialog.cpp~   2006-01-28 23:38:52.000000000 -0500
| +++ deletedialog.cpp    2006-02-09 22:12:44.000000000 -0500
| @@ -65,7 +65,7 @@
|          for( QStringList::ConstIterator it = _list.begin(); it !=
| _list.end(); ++it ) { Util::removeThumbNail( *it );
|              if ( ImageDB::instance()->info(*it)->imageOnDisk() ) { //
| PENDING(blackie) we don't need imageinfo for this -                bool ok
| = QFile( *it ).remove();
| +                bool ok = !(QFile( *it ).exists()) ||  QFile( *it
| ).remove(); if ( !ok ) {
|                      KMessageBox::error( this, i18n("Unable to delete file
| '%1'.").arg(*it), i18n("Error Deleting Files") );
|
| _______________________________________________
| KPhotoAlbum mailing list
| KPhotoAlbum at mail.kdab.net
| http://mail.kdab.net/mailman/listinfo/kphotoalbum

-- 
Jesper K. Pedersen          |  Klarälvdalens Datakonsult
Senior Software Engineer    |  www.klaralvdalens-datakonsult.se
Prinsensgade 4a st.         |
9800 Hjørring               |  Platform-independent
Denmark                     |  software solutions




More information about the Kphotoalbum mailing list