From 457aef5b0f56f33c18d33d3453dec3e83a03a22b Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Sun, 21 May 2017 20:33:23 -0400 Subject: [PATCH] Allow cut-and-pasting items between pages Previously, items such as audio, video, and widget items could not be cut and pasted because when the page was saved, any item that had been deleted was permanently removed (including its source file, in the case of these mulitmedia items). This commit prevents the deletion any item in the undoStack (i.e, items that have been deleted) when the document is persisted, meaning the source file is still available when pasting the item on another page (or document). Note that this can lead to cases where the source file is kept in the document even when no item is present. This should be a relatively rare occurence, however. --- src/board/UBBoardController.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 3d25bba1..6464d01b 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1609,6 +1609,23 @@ void UBBoardController::ClearUndoStack() findUniquesItems(UBApplication::undoStack->command(i), uniqueItems); } + // Get items from clipboard in order not to delete an item that was cut + // (using source URL of graphics items as a surrogate for equality testing) + // This ensures that we can cut and paste a media item, widget, etc. from one page to the next. + QClipboard *clipboard = QApplication::clipboard(); + const QMimeData* data = clipboard->mimeData(); + QList sourceURLs; + + if (data && data->hasFormat(UBApplication::mimeTypeUniboardPageItem)) { + const UBMimeDataGraphicsItem* mimeDataGI = qobject_cast (data); + + if (mimeDataGI) { + foreach (UBItem* sourceItem, mimeDataGI->items()) { + sourceURLs << sourceItem->sourceUrl(); + } + } + } + // go through all unique items, and check, if they are on scene, or not. // if not on scene, than item can be deleted QSetIterator itUniq(uniqueItems); @@ -1620,7 +1637,12 @@ void UBBoardController::ClearUndoStack() scene = dynamic_cast(item->scene()); } - if(!scene) + bool inClipboard = false; + UBItem* ubi = dynamic_cast(item); + if (ubi && sourceURLs.contains(ubi->sourceUrl())) + inClipboard = true; + + if(!scene && !inClipboard) { if (!mActiveScene->deleteItem(item)){ delete item;