From 828ae2272fb90b04dcb6d2bc51f2a0c9f1248114 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Thu, 4 Oct 2012 12:04:32 +0300 Subject: [PATCH] Deletion from library is more stable. Imported to library pictures has unique names. --- src/board/UBFeaturesController.cpp | 18 +++++++++++++++--- src/gui/UBFeaturesWidget.cpp | 15 +++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index afc6026e..33682bdb 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -641,19 +641,31 @@ void UBFeaturesController::importImage(const QImage &image, const QString &fileN void UBFeaturesController::importImage( const QImage &image, const UBFeature &destination, const QString &fileName ) { QString mFileName = fileName; + QString filePath; + UBFeature dest = destination; if (mFileName.isNull()) { QDateTime now = QDateTime::currentDateTime(); - mFileName = tr("ImportedImage") + "-" + now.toString("dd-MM-yyyy hh-mm-ss") + ".png"; + static int imageCounter = 0; + mFileName = tr("ImportedImage") + "-" + now.toString("dd-MM-yyyy hh-mm-ss"); + + filePath = dest.getFullPath().toLocalFile() + "/" + mFileName; + + if (QFile::exists(filePath+".png")) + mFileName += QString("-[%1]").arg(++imageCounter); + else + imageCounter = 0; + + mFileName += ".png"; } + - UBFeature dest = destination; if ( !destination.getFullVirtualPath().startsWith( picturesElement.getFullVirtualPath(), Qt::CaseInsensitive ) ) { dest = picturesElement; } - QString filePath = dest.getFullPath().toLocalFile() + "/" + mFileName; + filePath = dest.getFullPath().toLocalFile() + "/" + mFileName; image.save(filePath); QImage thumb = createThumbnail( filePath ); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 0709058f..20199a7c 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -169,9 +169,15 @@ void UBFeaturesWidget::deleteElements( const UBFeaturesMimeData * mimeData ) void UBFeaturesWidget::deleteSelectedElements() { QModelIndexList selected = centralWidget->listView()->selectionModel()->selectedIndexes(); - do + + QList featureasToMove; + for (int i = 0; i < selected.count(); i++) + { + featureasToMove.append(controller->getFeature(selected.at(i), objNameFeatureList)); + } + + foreach (UBFeature feature, featureasToMove) { - UBFeature feature = controller->getFeature(selected.at(0), objNameFeatureList); if (feature.isDeletable()) { if (feature.inTrash()) { controller->deleteItem(feature); @@ -179,10 +185,7 @@ void UBFeaturesWidget::deleteSelectedElements() controller->moveToTrash(feature, true); } } - selected = centralWidget->listView()->selectionModel()->selectedIndexes(); - if (!selected.isEmpty()) - centralWidget->listView()->selectionModel()->select(selected.at(0), QItemSelectionModel::Deselect); - }while (!selected.isEmpty()); + } controller->refreshModels(); }