Commit 457aef5b authored by Craig Watson's avatar Craig Watson

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.
parent bec0dc00
...@@ -1609,6 +1609,23 @@ void UBBoardController::ClearUndoStack() ...@@ -1609,6 +1609,23 @@ void UBBoardController::ClearUndoStack()
findUniquesItems(UBApplication::undoStack->command(i), uniqueItems); 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<QUrl> sourceURLs;
if (data && data->hasFormat(UBApplication::mimeTypeUniboardPageItem)) {
const UBMimeDataGraphicsItem* mimeDataGI = qobject_cast <const UBMimeDataGraphicsItem*>(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. // go through all unique items, and check, if they are on scene, or not.
// if not on scene, than item can be deleted // if not on scene, than item can be deleted
QSetIterator<QGraphicsItem*> itUniq(uniqueItems); QSetIterator<QGraphicsItem*> itUniq(uniqueItems);
...@@ -1620,7 +1637,12 @@ void UBBoardController::ClearUndoStack() ...@@ -1620,7 +1637,12 @@ void UBBoardController::ClearUndoStack()
scene = dynamic_cast<UBGraphicsScene*>(item->scene()); scene = dynamic_cast<UBGraphicsScene*>(item->scene());
} }
if(!scene) bool inClipboard = false;
UBItem* ubi = dynamic_cast<UBItem*>(item);
if (ubi && sourceURLs.contains(ubi->sourceUrl()))
inClipboard = true;
if(!scene && !inClipboard)
{ {
if (!mActiveScene->deleteItem(item)){ if (!mActiveScene->deleteItem(item)){
delete item; delete item;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment