From 05b6bf87b3726fb876b899c96765811a7d0f59a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Wed, 23 Jun 2021 10:49:17 +0200 Subject: [PATCH] forbid deletion if all pages are selected --- src/document/UBDocumentContainer.h | 2 +- src/document/UBDocumentController.cpp | 25 ++++++++++++++++++++++--- src/document/UBDocumentController.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/document/UBDocumentContainer.h b/src/document/UBDocumentContainer.h index 497861b0..7be279e0 100644 --- a/src/document/UBDocumentContainer.h +++ b/src/document/UBDocumentContainer.h @@ -45,7 +45,7 @@ class UBDocumentContainer : public QObject void pureSetDocument(UBDocumentProxy *document) {mCurrentDocument = document;} UBDocumentProxy* selectedDocument(){return mCurrentDocument;} - int pageCount(){return mCurrentDocument->pageCount();} + int pageCount() const{return mCurrentDocument->pageCount();} const QPixmap* pageAt(int index) { if (index < mDocumentThumbs.size()) diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index c85410ce..19fc3e77 100644 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -3360,6 +3360,7 @@ void UBDocumentController::updateActions() updateExportSubActions(selectedIndex); bool firstSceneSelected = false; + bool everyPageSelected = false; if (docSelected) { mMainWindow->actionDuplicate->setEnabled(!trashSelected); @@ -3539,7 +3540,12 @@ UBDocumentController::deletionTypeForSelection(LastSelectedElementType pTypeSele , UBDocumentTreeModel *docModel) const { - if (pTypeSelection == Page) { + if (pTypeSelection == Page) + { + if (everySceneSelected()) + { + return NoDeletion; + } if (!firstAndOnlySceneSelected()) { return DeletePage; } @@ -3566,11 +3572,24 @@ UBDocumentController::deletionTypeForSelection(LastSelectedElementType pTypeSele return NoDeletion; } +bool UBDocumentController::everySceneSelected() const +{ + QList selection = mDocumentUI->thumbnailWidget->selectedItems(); + if (selection.count() > 0) + { + UBSceneThumbnailPixmap* p = dynamic_cast(selection.at(0)); + if (p) + { + return (selection.count() == p->proxy()->pageCount()); + } + } + return false; +} + bool UBDocumentController::firstAndOnlySceneSelected() const { - bool firstSceneSelected = false; QList selection = mDocumentUI->thumbnailWidget->selectedItems(); - for(int i = 0; i < selection.count() && !firstSceneSelected; i += 1) + for(int i = 0; i < selection.count(); i += 1) { UBSceneThumbnailPixmap* p = dynamic_cast(selection.at(i)); if (p) diff --git a/src/document/UBDocumentController.h b/src/document/UBDocumentController.h index a67908be..9999579d 100644 --- a/src/document/UBDocumentController.h +++ b/src/document/UBDocumentController.h @@ -401,6 +401,7 @@ class UBDocumentController : public UBDocumentContainer , const QModelIndex &selectedIndex , UBDocumentTreeModel *docModel) const; bool firstAndOnlySceneSelected() const; + bool everySceneSelected() const; QWidget *mainWidget() const {return mDocumentWidget;} //issue 1629 - NNE - 20131212