From bbf134d1fe22c7e395e06c3bb72d117611bdf824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Fri, 4 Mar 2022 13:55:21 +0100 Subject: [PATCH] fixed a bug where grouped items with file dependencies would not be properly copied when copying a page from a document to another --- src/domain/UBGraphicsScene.cpp | 92 ++++++++++++++++++++-------------- src/domain/UBGraphicsScene.h | 1 + 2 files changed, 56 insertions(+), 37 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 816ef1ee..5cb2808b 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -2473,9 +2473,53 @@ void UBGraphicsScene::setRenderingQuality(UBItem::RenderingQuality pRenderingQua } } +QList UBGraphicsScene::relativeDependenciesOfItem(QGraphicsItem* item) const +{ + QList relativePaths; + + UBGraphicsVideoItem *videoItem = dynamic_cast (item); + if (videoItem){ + QString completeFileName = QFileInfo(videoItem->mediaFileUrl().toLocalFile()).fileName(); + QString path = UBPersistenceManager::videoDirectory + "/"; + relativePaths << QUrl(path + completeFileName); + return relativePaths; + } + + UBGraphicsAudioItem *audioItem = dynamic_cast (item); + if (audioItem){ + QString completeFileName = QFileInfo(audioItem->mediaFileUrl().toLocalFile()).fileName(); + QString path = UBPersistenceManager::audioDirectory + "/"; + relativePaths << QUrl(path + completeFileName); + return relativePaths; + } + + UBGraphicsWidgetItem* widget = dynamic_cast(item); + if(widget){ + QString widgetPath = UBPersistenceManager::widgetDirectory + "/" + widget->uuid().toString() + ".wgt"; + QString screenshotPath = UBPersistenceManager::widgetDirectory + "/" + widget->uuid().toString().remove("{").remove("}") + ".png"; + relativePaths << QUrl(widgetPath); + relativePaths << QUrl(screenshotPath); + return relativePaths; + } + + UBGraphicsPixmapItem* pixmapItem = dynamic_cast(item); + if(pixmapItem){ + relativePaths << QUrl(UBPersistenceManager::imageDirectory + "/" + pixmapItem->uuid().toString() + ".png"); + return relativePaths; + } + + UBGraphicsSvgItem* svgItem = dynamic_cast(item); + if(svgItem){ + relativePaths << QUrl(UBPersistenceManager::imageDirectory + "/" + svgItem->uuid().toString() + ".svg"); + return relativePaths; + } + + return relativePaths; +} + QList UBGraphicsScene::relativeDependencies() const { - QList relativePathes; + QList relativePaths; QListIterator itItems(mFastAccessItems); @@ -2483,45 +2527,19 @@ QList UBGraphicsScene::relativeDependencies() const { QGraphicsItem* item = itItems.next(); - UBGraphicsVideoItem *videoItem = qgraphicsitem_cast (item); - if (videoItem){ - QString completeFileName = QFileInfo(videoItem->mediaFileUrl().toLocalFile()).fileName(); - QString path = UBPersistenceManager::videoDirectory + "/"; - relativePathes << QUrl(path + completeFileName); - continue; - } - - UBGraphicsAudioItem *audioItem = qgraphicsitem_cast (item); - if (audioItem){ - QString completeFileName = QFileInfo(audioItem->mediaFileUrl().toLocalFile()).fileName(); - QString path = UBPersistenceManager::audioDirectory + "/"; - relativePathes << QUrl(path + completeFileName); - continue; - } - - UBGraphicsWidgetItem* widget = qgraphicsitem_cast(item); - if(widget){ - QString widgetPath = UBPersistenceManager::widgetDirectory + "/" + widget->uuid().toString() + ".wgt"; - QString screenshotPath = UBPersistenceManager::widgetDirectory + "/" + widget->uuid().toString().remove("{").remove("}") + ".png"; - relativePathes << QUrl(widgetPath); - relativePathes << QUrl(screenshotPath); - continue; - } - - UBGraphicsPixmapItem* pixmapItem = qgraphicsitem_cast(item); - if(pixmapItem){ - relativePathes << QUrl(UBPersistenceManager::imageDirectory + "/" + pixmapItem->uuid().toString() + ".png"); - continue; - } - - UBGraphicsSvgItem* svgItem = qgraphicsitem_cast(item); - if(svgItem){ - relativePathes << QUrl(UBPersistenceManager::imageDirectory + "/" + svgItem->uuid().toString() + ".svg"); - continue; + UBGraphicsGroupContainerItem* groupItem = dynamic_cast(item); + if(groupItem) + { + for (auto child : groupItem->childItems()) + { + relativePaths << relativeDependenciesOfItem(child); + } } + else + relativePaths << relativeDependenciesOfItem(item); } - return relativePathes; + return relativePaths; } QSize UBGraphicsScene::nominalSize() diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 6a22f14f..82e3a982 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -303,6 +303,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem virtual void setRenderingQuality(UBItem::RenderingQuality pRenderingQuality, UBItem::CacheBehavior cacheBehavior); + QList relativeDependenciesOfItem(QGraphicsItem* item) const; QList relativeDependencies() const; QSize nominalSize();