From fa65eafefeeca7fa22f2b4ecc17b4c292691b70a Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Tue, 23 Jul 2013 15:01:36 +0200 Subject: [PATCH 1/7] bugs of persistance of unwanted media on disk. First step fixed the undo manager --- src/board/UBBoardController.cpp | 12 ++++----- src/board/UBBoardController.h | 2 +- src/core/UB.h | 9 +++++++ src/domain/UBGraphicsItemGroupUndoCommand.cpp | 7 ++--- src/domain/UBGraphicsItemGroupUndoCommand.h | 6 ++--- .../UBGraphicsItemTransformUndoCommand.cpp | 2 +- .../UBGraphicsItemTransformUndoCommand.h | 6 ++--- src/domain/UBGraphicsItemUndoCommand.cpp | 10 +++---- src/domain/UBGraphicsItemUndoCommand.h | 6 ++--- src/domain/UBGraphicsTextItemUndoCommand.h | 6 ++--- src/domain/UBPageSizeUndoCommand.h | 6 ++--- ...tractUndoCommand.cpp => UBUndoCommand.cpp} | 19 +++----------- ...BAbstractUndoCommand.h => UBUndoCommand.h} | 26 +++++-------------- src/domain/domain.pri | 8 +++--- 14 files changed, 53 insertions(+), 72 deletions(-) rename src/domain/{UBAbstractUndoCommand.cpp => UBUndoCommand.cpp} (76%) rename src/domain/{UBAbstractUndoCommand.h => UBUndoCommand.h} (62%) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index ac5e2398..e830958e 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1550,11 +1550,11 @@ void UBBoardController::moveSceneToIndex(int source, int target) } } -void UBBoardController::fitUniqIems(const QUndoCommand *parent, QSet &itms) +void UBBoardController::findUniquesItems(const QUndoCommand *parent, QSet &itms) { if (parent->childCount()) { for (int i = 0; i < parent->childCount(); i++) { - fitUniqIems(parent->child(i), itms); + findUniquesItems(parent->child(i), itms); } } @@ -1563,11 +1563,11 @@ void UBBoardController::fitUniqIems(const QUndoCommand *parent, QSet(parent); - if(abstractCmd->getType() != UBAbstractUndoCommand::undotype_GRAPHICITEM) + const UBUndoCommand *undoCmd = static_cast(parent); + if(undoCmd->getType() != UBUndoType::undotype_GRAPHICITEM) return; - const UBGraphicsItemUndoCommand *cmd = static_cast(parent); + const UBGraphicsItemUndoCommand *cmd = dynamic_cast(parent); // go through all added and removed objects, for create list of unique objects // grouped items will be deleted by groups, so we don't need do delete that items. @@ -1593,7 +1593,7 @@ void UBBoardController::ClearUndoStack() QSet uniqueItems; // go through all stack command for (int i = 0; i < UBApplication::undoStack->count(); i++) { - fitUniqIems(UBApplication::undoStack->command(i), uniqueItems); + findUniquesItems(UBApplication::undoStack->command(i), uniqueItems); } // go through all unique items, and check, if they are on scene, or not. diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index 8ab9b27e..93f92419 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -160,7 +160,7 @@ class UBBoardController : public UBDocumentContainer void notifyPageChanged(); void displayMetaData(QMap metadatas); - void fitUniqIems(const QUndoCommand *parent, QSet &itms); + void findUniquesItems(const QUndoCommand *parent, QSet &itms); void ClearUndoStack(); void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0, bool forceReload = false); diff --git a/src/core/UB.h b/src/core/UB.h index 493590c8..ab42fb7f 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -195,4 +195,13 @@ struct DocumentSizeRatio }; }; + +struct UBUndoType +{ + enum Enum + { + undotype_UNKNOWN = 0, undotype_DOCUMENT, undotype_GRAPHICITEMTRANSFORM, undotype_GRAPHICITEM, undotype_GRAPHICTEXTITEM, undotype_PAGESIZE, undotype_GRAPHICSGROUPITEM + }; +}; + #endif /* UB_H_ */ diff --git a/src/domain/UBGraphicsItemGroupUndoCommand.cpp b/src/domain/UBGraphicsItemGroupUndoCommand.cpp index 25a3ebed..ea1df298 100644 --- a/src/domain/UBGraphicsItemGroupUndoCommand.cpp +++ b/src/domain/UBGraphicsItemGroupUndoCommand.cpp @@ -28,9 +28,10 @@ #include "core/memcheck.h" -UBGraphicsItemGroupUndoCommand::UBGraphicsItemGroupUndoCommand(UBGraphicsScene *pScene, UBGraphicsGroupContainerItem *pGroupCreated) : - mScene (pScene), mGroup(pGroupCreated), mFirstRedo(true) - +UBGraphicsItemGroupUndoCommand::UBGraphicsItemGroupUndoCommand(UBGraphicsScene *pScene, UBGraphicsGroupContainerItem *pGroupCreated) : UBUndoCommand() + , mScene (pScene) + , mGroup(pGroupCreated) + , mFirstRedo(true) { if (pGroupCreated->childItems().count()) { foreach (QGraphicsItem *item, pGroupCreated->childItems()) { diff --git a/src/domain/UBGraphicsItemGroupUndoCommand.h b/src/domain/UBGraphicsItemGroupUndoCommand.h index 981ebb33..c280af0e 100644 --- a/src/domain/UBGraphicsItemGroupUndoCommand.h +++ b/src/domain/UBGraphicsItemGroupUndoCommand.h @@ -25,18 +25,18 @@ #define UBGRAPHICSITEMGROUPUNDOCOMMAND_H #include -#include "UBAbstractUndoCommand.h" +#include "UBUndoCommand.h" class UBGraphicsScene; class UBGraphicsGroupContainerItem; -class UBGraphicsItemGroupUndoCommand : public UBAbstractUndoCommand +class UBGraphicsItemGroupUndoCommand : public UBUndoCommand { public: UBGraphicsItemGroupUndoCommand(UBGraphicsScene *pScene, UBGraphicsGroupContainerItem *pGroupCreated); virtual ~UBGraphicsItemGroupUndoCommand(); - virtual UndoType getType() { return undotype_GRAPHICSGROUPITEM; } + virtual int getType() const { return UBUndoType::undotype_GRAPHICSGROUPITEM; } protected: virtual void undo(); diff --git a/src/domain/UBGraphicsItemTransformUndoCommand.cpp b/src/domain/UBGraphicsItemTransformUndoCommand.cpp index 316eb703..5ea77630 100644 --- a/src/domain/UBGraphicsItemTransformUndoCommand.cpp +++ b/src/domain/UBGraphicsItemTransformUndoCommand.cpp @@ -29,7 +29,7 @@ UBGraphicsItemTransformUndoCommand::UBGraphicsItemTransformUndoCommand(QGraphicsItem* pItem, const QPointF& prevPos, const QTransform& prevTransform, const qreal& prevZValue, - const QSizeF& prevSize) + const QSizeF& prevSize):UBUndoCommand() { mItem = pItem; mPreviousTransform = prevTransform; diff --git a/src/domain/UBGraphicsItemTransformUndoCommand.h b/src/domain/UBGraphicsItemTransformUndoCommand.h index aa586ec2..07e0aede 100644 --- a/src/domain/UBGraphicsItemTransformUndoCommand.h +++ b/src/domain/UBGraphicsItemTransformUndoCommand.h @@ -27,10 +27,10 @@ #include #include "UBResizableGraphicsItem.h" -#include "UBAbstractUndoCommand.h" +#include "UBUndoCommand.h" -class UBGraphicsItemTransformUndoCommand : public UBAbstractUndoCommand +class UBGraphicsItemTransformUndoCommand : public UBUndoCommand { public: UBGraphicsItemTransformUndoCommand(QGraphicsItem* pItem, @@ -40,7 +40,7 @@ class UBGraphicsItemTransformUndoCommand : public UBAbstractUndoCommand const QSizeF& prevSize = QSizeF()); virtual ~UBGraphicsItemTransformUndoCommand(); - virtual UndoType getType() { return undotype_GRAPHICITEMTRANSFORM; } + virtual int getType() const { return UBUndoType::undotype_GRAPHICITEMTRANSFORM; } protected: virtual void undo(); diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index 36cb74d6..b047d6a5 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -35,9 +35,8 @@ #include "domain/UBGraphicsGroupContainerItem.h" #include "domain/UBGraphicsPolygonItem.h" -UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems, const GroupDataTable &groupsMap) - : mScene(pScene) +UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, const QSet& pAddedItems, const GroupDataTable &groupsMap): UBUndoCommand() + , mScene(pScene) , mRemovedItems(pRemovedItems - pAddedItems) , mAddedItems(pAddedItems - pRemovedItems) , mExcludedFromGroup(groupsMap) @@ -57,9 +56,8 @@ UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, co } } -UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem, - QGraphicsItem* pAddedItem) : - mScene(pScene) +UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem, QGraphicsItem* pAddedItem) : UBUndoCommand() + , mScene(pScene) { if (pRemovedItem) diff --git a/src/domain/UBGraphicsItemUndoCommand.h b/src/domain/UBGraphicsItemUndoCommand.h index 4e288f37..86cde9aa 100644 --- a/src/domain/UBGraphicsItemUndoCommand.h +++ b/src/domain/UBGraphicsItemUndoCommand.h @@ -25,14 +25,14 @@ #define UBGRAPHICSITEMUNDOCOMMAND_H_ #include -#include "UBAbstractUndoCommand.h" +#include "UBUndoCommand.h" #include "UBGraphicsGroupContainerItem.h" class UBGraphicsScene; -class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand +class UBGraphicsItemUndoCommand : public UBUndoCommand { public: typedef QMultiMap GroupDataTable; @@ -48,7 +48,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand QSet GetAddedList() const { return mAddedItems; } QSet GetRemovedList() const { return mRemovedItems; } - virtual UndoType getType() { return undotype_GRAPHICITEM; } + virtual int getType() const { return UBUndoType::undotype_GRAPHICITEM; } protected: virtual void undo(); diff --git a/src/domain/UBGraphicsTextItemUndoCommand.h b/src/domain/UBGraphicsTextItemUndoCommand.h index 5b1d8c53..85e54714 100644 --- a/src/domain/UBGraphicsTextItemUndoCommand.h +++ b/src/domain/UBGraphicsTextItemUndoCommand.h @@ -25,18 +25,18 @@ #define UBGRAPHICSTEXTITEMUNDOCOMMAND_H_ #include -#include "UBAbstractUndoCommand.h" +#include "UBUndoCommand.h" #include "UBGraphicsTextItem.h" -class UBGraphicsTextItemUndoCommand : public UBAbstractUndoCommand +class UBGraphicsTextItemUndoCommand : public UBUndoCommand { public: UBGraphicsTextItemUndoCommand(UBGraphicsTextItem *textItem); virtual ~UBGraphicsTextItemUndoCommand(); - virtual UndoType getType() { return undotype_GRAPHICTEXTITEM; }; + virtual int getType() const { return UBUndoType::undotype_GRAPHICTEXTITEM; }; protected: virtual void undo(); diff --git a/src/domain/UBPageSizeUndoCommand.h b/src/domain/UBPageSizeUndoCommand.h index 35e46bda..1abbe7a2 100644 --- a/src/domain/UBPageSizeUndoCommand.h +++ b/src/domain/UBPageSizeUndoCommand.h @@ -25,18 +25,18 @@ #define UBPageSizeUndoCommand_H_ #include -#include "UBAbstractUndoCommand.h" +#include "UBUndoCommand.h" class UBGraphicsScene; -class UBPageSizeUndoCommand : public UBAbstractUndoCommand +class UBPageSizeUndoCommand : public UBUndoCommand { public: UBPageSizeUndoCommand(UBGraphicsScene* pScene, const QSize& previousSize, const QSize& newSize); virtual ~UBPageSizeUndoCommand(); - virtual UndoType getType() { return undotype_PAGESIZE; }; + virtual int getType() { return UBUndoType::undotype_PAGESIZE; }; protected: virtual void undo(); diff --git a/src/domain/UBAbstractUndoCommand.cpp b/src/domain/UBUndoCommand.cpp similarity index 76% rename from src/domain/UBAbstractUndoCommand.cpp rename to src/domain/UBUndoCommand.cpp index 54083211..9d641258 100644 --- a/src/domain/UBAbstractUndoCommand.cpp +++ b/src/domain/UBUndoCommand.cpp @@ -21,30 +21,17 @@ -#include "UBAbstractUndoCommand.h" +#include "UBUndoCommand.h" #include "core/memcheck.h" -UBAbstractUndoCommand::UBAbstractUndoCommand() +UBUndoCommand::UBUndoCommand(QUndoCommand* parent):QUndoCommand(parent) { // NOOP } -UBAbstractUndoCommand::~UBAbstractUndoCommand() +UBUndoCommand::~UBUndoCommand() { // NOOP } - -void UBAbstractUndoCommand::undo() -{ - // NOOP -} - -void UBAbstractUndoCommand::redo() -{ - // NOOP -} - -//void UBAbstractUndoCommand::UndoType getType(UndoType type); - diff --git a/src/domain/UBAbstractUndoCommand.h b/src/domain/UBUndoCommand.h similarity index 62% rename from src/domain/UBAbstractUndoCommand.h rename to src/domain/UBUndoCommand.h index a544c52b..80a989ae 100644 --- a/src/domain/UBAbstractUndoCommand.h +++ b/src/domain/UBUndoCommand.h @@ -25,30 +25,16 @@ #define UBABSTRACTUNDOCOMMAND_H_ #include +#include -class UBAbstractUndoCommand : public QUndoCommand +class UBUndoCommand : public QUndoCommand { public: - UBAbstractUndoCommand(); - ~UBAbstractUndoCommand(); - - enum UndoType - { - undotype_UNKNOWN = 0, - undotype_DOCUMENT = 1, - undotype_GRAPHICITEMTRANSFORM = 2, - undotype_GRAPHICITEM = 3, - undotype_GRAPHICTEXTITEM = 4, - undotype_PAGESIZE = 5, - undotype_GRAPHICSGROUPITEM = 6 - }; - - virtual UndoType getType() const { return undotype_UNKNOWN; } - - protected: - virtual void undo(); - virtual void redo(); + UBUndoCommand(QUndoCommand *parent = 0); + ~UBUndoCommand(); + + virtual int getType() const { return UBUndoType::undotype_UNKNOWN; } }; diff --git a/src/domain/domain.pri b/src/domain/domain.pri index 93172f49..b525dfd6 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -14,7 +14,6 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBResizableGraphicsItem.h \ src/domain/UBGraphicsStroke.h \ src/domain/UBGraphicsMediaItem.h \ - src/domain/UBAbstractUndoCommand.h \ src/domain/UBGraphicsGroupContainerItem.h \ src/domain/UBGraphicsGroupContainerItemDelegate.h \ src/domain/UBGraphicsStrokesGroup.h \ @@ -24,7 +23,8 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBGraphicsDelegateFrame.h \ src/domain/UBGraphicsWidgetItemDelegate.h \ src/domain/UBGraphicsMediaItemDelegate.h \ - src/domain/UBSelectionFrame.h + src/domain/UBSelectionFrame.h \ + src/domain/UBUndoCommand.h SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsItemUndoCommand.cpp \ @@ -42,7 +42,6 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBResizableGraphicsItem.cpp \ src/domain/UBGraphicsStroke.cpp \ src/domain/UBGraphicsMediaItem.cpp \ - src/domain/UBAbstractUndoCommand.cpp \ src/domain/UBGraphicsGroupContainerItem.cpp \ src/domain/UBGraphicsGroupContainerItemDelegate.cpp \ src/domain/UBGraphicsStrokesGroup.cpp \ @@ -52,4 +51,5 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsMediaItemDelegate.cpp \ src/domain/UBGraphicsDelegateFrame.cpp \ src/domain/UBGraphicsWidgetItemDelegate.cpp \ - src/domain/UBSelectionFrame.cpp + src/domain/UBSelectionFrame.cpp \ + src/domain/UBUndoCommand.cpp From eb5bebbca3fbd294f5a1adc79de92f9c27efed41 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Tue, 23 Jul 2013 16:12:37 +0200 Subject: [PATCH 2/7] removed temp flash file stored into the root document directory --- src/board/UBBoardController.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index e830958e..6135423d 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1317,6 +1317,7 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl Q_UNUSED(internalData) QString widgetUrl = UBGraphicsW3CWidgetItem::createNPAPIWrapper(sUrl, mimeType, size); + UBFileSystemUtils::deleteFile(sourceUrl.toLocalFile()); emit npapiWidgetCreated(widgetUrl); if (widgetUrl.length() > 0) From 0428f938d25b513fd95c67397dca50b59fb4d38a Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Tue, 23 Jul 2013 17:03:06 +0200 Subject: [PATCH 3/7] persistence of not required media on disk. Second step updated the cleanSource methods in classes that handle files on disk --- src/board/UBBoardController.cpp | 10 ++++++++-- src/core/UBPersistenceManager.cpp | 2 +- src/core/UBPersistenceManager.h | 2 +- src/domain/UBGraphicsPixmapItem.cpp | 15 +++++++++++++++ src/domain/UBGraphicsPixmapItem.h | 2 +- src/domain/UBGraphicsProxyWidget.cpp | 9 +++++++-- src/domain/UBGraphicsProxyWidget.h | 1 - src/domain/UBGraphicsSvgItem.cpp | 15 +++++++++++++++ src/domain/UBGraphicsSvgItem.h | 4 ++-- src/domain/UBGraphicsWidgetItem.cpp | 3 ++- 10 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 6135423d..b9f3a502 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -51,7 +51,6 @@ #include "domain/UBGraphicsPixmapItem.h" #include "domain/UBGraphicsItemUndoCommand.h" -#include "domain/UBGraphicsProxyWidget.h" #include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsWidgetItem.h" #include "domain/UBGraphicsMediaItem.h" @@ -1325,6 +1324,13 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl UBGraphicsWidgetItem *widgetItem = mActiveScene->addW3CWidget(QUrl::fromLocalFile(widgetUrl), pPos); widgetItem->setUuid(QUuid::createUuid()); widgetItem->setSourceUrl(QUrl::fromLocalFile(widgetUrl)); + qDebug() << widgetItem->getOwnFolder(); + qDebug() << widgetItem->getSnapshotPath(); + QString ownFolder = selectedDocument()->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + widgetItem->uuid().toString() + ".wgt"; + widgetItem->setOwnFolder(ownFolder); + QString adaptedUUid = widgetItem->uuid().toString().replace("{","").replace("}",""); + ownFolder = ownFolder.replace(widgetItem->uuid().toString() + ".wgt", adaptedUUid + ".png"); + widgetItem->setSnapshotPath(ownFolder); UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); @@ -2143,7 +2149,7 @@ UBGraphicsWidgetItem *UBBoardController::addW3cWidget(const QUrl &pUrl, const QP QUuid uuid = QUuid::createUuid(); QString destPath; - if (!UBPersistenceManager::persistenceManager()->addGraphicsWidgteToDocument(selectedDocument(), pUrl.toLocalFile(), uuid, destPath)) + if (!UBPersistenceManager::persistenceManager()->addGraphicsWidgetToDocument(selectedDocument(), pUrl.toLocalFile(), uuid, destPath)) return NULL; QUrl newUrl = QUrl::fromLocalFile(destPath); diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index a9ec444e..ccb6d859 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -859,7 +859,7 @@ bool UBPersistenceManager::addFileToDocument(UBDocumentProxy* pDocumentProxy, } } -bool UBPersistenceManager::addGraphicsWidgteToDocument(UBDocumentProxy *pDocumentProxy, +bool UBPersistenceManager::addGraphicsWidgetToDocument(UBDocumentProxy *pDocumentProxy, QString path, QUuid objectUuid, QString& destinationPath) diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 77708cee..6710c29e 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -103,7 +103,7 @@ class UBPersistenceManager : public QObject virtual bool isEmpty(UBDocumentProxy* pDocumentProxy); virtual void purgeEmptyDocuments(); - bool addGraphicsWidgteToDocument(UBDocumentProxy *mDocumentProxy, QString path, QUuid objectUuid, QString& destinationPath); + bool addGraphicsWidgetToDocument(UBDocumentProxy *mDocumentProxy, QString path, QUuid objectUuid, QString& destinationPath); bool addFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, const QString& subdir, QUuid objectUuid, QString& destinationPath, QByteArray* data = NULL); signals: diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index adf96f0b..9bffb41c 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -31,6 +31,13 @@ #include "UBGraphicsItemDelegate.h" +#include "frameworks/UBFileSystemUtils.h" + +#include "core/UBApplication.h" +#include "core/UBPersistenceManager.h" + +#include "board/UBBoardController.h" + #include "core/memcheck.h" UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) @@ -164,3 +171,11 @@ qreal UBGraphicsPixmapItem::opacity() const { return QGraphicsPixmapItem::opacity(); } + + +void UBGraphicsPixmapItem::clearSource() +{ + QString fileName = UBPersistenceManager::imageDirectory + "/" + uuid().toString() + ".png"; + QString diskPath = UBApplication::boardController->selectedDocument()->persistencePath() + "/" + fileName; + UBFileSystemUtils::deleteFile(diskPath); +} diff --git a/src/domain/UBGraphicsPixmapItem.h b/src/domain/UBGraphicsPixmapItem.h index 3ef6b846..e00efc1a 100644 --- a/src/domain/UBGraphicsPixmapItem.h +++ b/src/domain/UBGraphicsPixmapItem.h @@ -57,7 +57,7 @@ class UBGraphicsPixmapItem : public QObject, public QGraphicsPixmapItem, public void setOpacity(qreal op); qreal opacity() const; - virtual void clearSource(){;} + virtual void clearSource(); virtual void setUuid(const QUuid &pUuid); diff --git a/src/domain/UBGraphicsProxyWidget.cpp b/src/domain/UBGraphicsProxyWidget.cpp index 24f3b6c7..3740b5cc 100644 --- a/src/domain/UBGraphicsProxyWidget.cpp +++ b/src/domain/UBGraphicsProxyWidget.cpp @@ -30,6 +30,13 @@ #include "UBGraphicsDelegateFrame.h" +#include "core/UBApplication.h" +#include "core/UBPersistenceManager.h" + +#include "board/UBBoardController.h" + +#include "frameworks/UBFileSystemUtils.h" + #include "core/memcheck.h" UBGraphicsProxyWidget::UBGraphicsProxyWidget(QGraphicsItem* parent) @@ -198,5 +205,3 @@ UBGraphicsScene* UBGraphicsProxyWidget::scene() { return static_cast(QGraphicsItem::scene()); } - - diff --git a/src/domain/UBGraphicsProxyWidget.h b/src/domain/UBGraphicsProxyWidget.h index 61d75538..d9686b20 100644 --- a/src/domain/UBGraphicsProxyWidget.h +++ b/src/domain/UBGraphicsProxyWidget.h @@ -44,7 +44,6 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public virtual UBGraphicsScene* scene(); - virtual void clearSource(){;} virtual void setUuid(const QUuid &pUuid); protected: diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index 00bcdaae..7344514e 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -29,6 +29,13 @@ #include "UBGraphicsItemDelegate.h" #include "UBGraphicsPixmapItem.h" +#include "core/UBApplication.h" +#include "core/UBPersistenceManager.h" + +#include "board/UBBoardController.h" + +#include "frameworks/UBFileSystemUtils.h" + #include "core/memcheck.h" UBGraphicsSvgItem::UBGraphicsSvgItem(const QString& pFilePath, QGraphicsItem* parent) @@ -217,3 +224,11 @@ void UBGraphicsSvgItem::setUuid(const QUuid &pUuid) UBItem::setUuid(pUuid); setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene } + + +void UBGraphicsSvgItem::clearSource() +{ + QString fileName = UBPersistenceManager::imageDirectory + "/" + uuid().toString() + ".svg"; + QString diskPath = UBApplication::boardController->selectedDocument()->persistencePath() + "/" + fileName; + UBFileSystemUtils::deleteFile(diskPath); +} diff --git a/src/domain/UBGraphicsSvgItem.h b/src/domain/UBGraphicsSvgItem.h index ef805bd6..2d9a4dc8 100644 --- a/src/domain/UBGraphicsSvgItem.h +++ b/src/domain/UBGraphicsSvgItem.h @@ -70,6 +70,8 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi virtual void setUuid(const QUuid &pUuid); + virtual void clearSource(); + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -80,8 +82,6 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); -// UBGraphicsItemDelegate* mDelegate; - QByteArray mFileData; }; diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index dcaf3a18..5d3a9929 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -272,7 +272,8 @@ bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const return mUniboardAPI->isDropableData(data); } -QUrl UBGraphicsWidgetItem::getOwnFolder() const { +QUrl UBGraphicsWidgetItem::getOwnFolder() const +{ return ownFolder; } From ea9ddcff3f401295faaec86b97bf9b095fee2970 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 24 Jul 2013 17:12:22 +0200 Subject: [PATCH 4/7] the initial vertical position is adapted to match the middle of the screen --- src/gui/UBStylusPalette.cpp | 53 ++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/gui/UBStylusPalette.cpp b/src/gui/UBStylusPalette.cpp index 1cf47b63..b64f604c 100644 --- a/src/gui/UBStylusPalette.cpp +++ b/src/gui/UBStylusPalette.cpp @@ -66,17 +66,17 @@ UBStylusPalette::UBStylusPalette(QWidget *parent, Qt::Orientation orient) if(!UBPlatformUtils::hasVirtualKeyboard()) { - groupActions(); + groupActions(); } else { - // VirtualKeyboard action is not in group - // So, groupping all buttons, except last - mButtonGroup = new QButtonGroup(this); - for(int i=0; i < mButtons.size()-1; i++) - { - mButtonGroup->addButton(mButtons[i], i); - } + // VirtualKeyboard action is not in group + // So, groupping all buttons, except last + mButtonGroup = new QButtonGroup(this); + for(int i=0; i < mButtons.size()-1; i++) + { + mButtonGroup->addButton(mButtons[i], i); + } connect(mButtonGroup, SIGNAL(buttonClicked(int)), this, SIGNAL(buttonGroupClicked(int))); } @@ -93,23 +93,28 @@ UBStylusPalette::UBStylusPalette(QWidget *parent, Qt::Orientation orient) void UBStylusPalette::initPosition() { - if(!UBSettings::settings()->appToolBarOrientationVertical->get().toBool()) - { - QWidget* pParentW = parentWidget(); - if(NULL != pParentW) - { - mCustomPosition = true; - QPoint pos; - int parentWidth = pParentW->width(); - int parentHeight = pParentW->height(); - int posX = (parentWidth / 2) - (width() / 2); - int posY = parentHeight - border() - height(); - - pos.setX(posX); - pos.setY(posY); - moveInsideParent(pos); - } + QWidget* pParentW = parentWidget(); + if(!pParentW) return ; + + mCustomPosition = true; + + QPoint pos; + int parentWidth = pParentW->width(); + int parentHeight = pParentW->height(); + + if(UBSettings::settings()->appToolBarOrientationVertical->get().toBool()){ + int posX = border(); + int posY = (parentHeight / 2) - (height() / 2); + pos.setX(posX); + pos.setY(posY); + } + else { + int posX = (parentWidth / 2) - (width() / 2); + int posY = parentHeight - border() - height(); + pos.setX(posX); + pos.setY(posY); } + moveInsideParent(pos); } UBStylusPalette::~UBStylusPalette() From fdc9e7ca6fd1340c70a425fd7533d71173803c2f Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 25 Jul 2013 12:12:48 +0200 Subject: [PATCH 5/7] Third step to fix the bug 27 --- src/adaptors/UBImportAdaptor.cpp | 24 --------------------- src/core/UBPersistenceManager.cpp | 6 ++++-- src/domain/UBGraphicsScene.cpp | 36 +++++++++++++++++++++++++++---- src/domain/UBGraphicsWidgetItem.h | 2 +- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/adaptors/UBImportAdaptor.cpp b/src/adaptors/UBImportAdaptor.cpp index 0a842f3e..790c809a 100644 --- a/src/adaptors/UBImportAdaptor.cpp +++ b/src/adaptors/UBImportAdaptor.cpp @@ -53,27 +53,3 @@ UBDocumentBasedImportAdaptor::UBDocumentBasedImportAdaptor(QObject *parent) { // NOOP } - - -/* -UBDocumentProxy* UBImportAdaptor::importFile(const QFile& pFile, const QString& pGroup) -{ - QString documentName = QFileInfo(pFile.fileName()).completeBaseName(); - - UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocument(pGroup, documentName); - - bool result = addFileToDocument(newDocument, pFile); - - if (result) - { - UBPersistenceManager::persistenceManager()->persistDocumentMetadata(newDocument); - } - else - { - UBPersistenceManager::persistenceManager()->deleteDocument(newDocument); - newDocument = 0; - } - - return newDocument; -} -*/ \ No newline at end of file diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index ccb6d859..f36b657c 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -255,7 +255,7 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName, } doc->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion); - QString currentDate = UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()); + QString currentDate = UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()); doc->setMetaData(UBSettings::documentUpdatedAt,currentDate); doc->setMetaData(UBSettings::documentDate,currentDate); @@ -396,12 +396,14 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL foreach(int index, compactedIndexes) { + // trig the reload of the thumbnails emit documentSceneWillBeDeleted(proxy, index); } QString sourceGroupName = proxy->metaData(UBSettings::documentGroupName).toString(); QString sourceName = proxy->metaData(UBSettings::documentName).toString(); UBDocumentProxy *trashDocProxy = createDocument(UBSettings::trashedDocumentGroupNamePrefix + sourceGroupName, sourceName, false); + generatePathIfNeeded(trashDocProxy); foreach(int index, compactedIndexes) { @@ -418,7 +420,7 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL QDir d = fi.dir(); d.mkpath(d.absolutePath()); - QFile::copy(source, target); + Q_ASSERT(QFile::rename(source, target)); } insertDocumentSceneAt(trashDocProxy, scene, trashDocProxy->pageCount()); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index e80a8561..b0d0b158 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -2088,11 +2088,39 @@ QList UBGraphicsScene::relativeDependencies() const while (itItems.hasNext()) { - UBGraphicsMediaItem *videoItem = qgraphicsitem_cast (itItems.next()); + QGraphicsItem* item = itItems.next(); + UBGraphicsMediaItem *mediaItem = qgraphicsitem_cast (item); - if (videoItem && videoItem->mediaFileUrl().isRelative()) - { - relativePathes << videoItem->mediaFileUrl(); + if (mediaItem){ + QString completeFileName = QFileInfo(mediaItem->mediaFileUrl().toLocalFile()).fileName(); + QString path; + if(mediaItem->getMediaType() == UBGraphicsMediaItem::mediaType_Video) + path = UBPersistenceManager::videoDirectory + "/"; + else + 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; } } diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 65da2bd7..344f05cf 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -130,7 +130,7 @@ class UBGraphicsWidgetItem : public QGraphicsWebView, public UBItem, public UBRe type_WIN = 1, // 0001 type_MAC = 2, // 0010 type_UNIX = 4, // 0100 - type_ALL = 7, // 0111 + type_ALL = 7 // 0111 }; bool mFirstReleaseAfterMove; From 8d4be60b9ed5f42cfe4fda50606d7b6de009af36 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 25 Jul 2013 16:48:10 +0200 Subject: [PATCH 6/7] good behavior horror code --- src/core/UBPersistenceManager.cpp | 74 +++++++++++++++++++++++++++++ src/domain/UBGraphicsMediaItem.h | 2 + src/domain/UBGraphicsWidgetItem.cpp | 1 + src/domain/UBGraphicsWidgetItem.h | 1 + 4 files changed, 78 insertions(+) diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index f36b657c..8d432d80 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -40,6 +40,11 @@ #include "adaptors/UBThumbnailAdaptor.h" #include "adaptors/UBMetadataDcSubsetAdaptor.h" +#include "domain/UBGraphicsMediaItem.h" +#include "domain/UBGraphicsWidgetItem.h" +#include "domain/UBGraphicsPixmapItem.h" +#include "domain/UBGraphicsSvgItem.h" + #include "board/UBBoardController.h" #include "board/UBBoardPaletteManager.h" @@ -469,6 +474,8 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL } + + void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int index) { checkIfDocumentRepositoryExists(); @@ -485,6 +492,73 @@ void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int in copyPage(proxy, index , index + 1); + + //TODO: write a proper way to handle object on disk + UBGraphicsScene *scene = loadDocumentScene(proxy, index + 1); + + foreach(QGraphicsItem* item, scene->items()) + { + UBGraphicsMediaItem *mediaItem = qgraphicsitem_cast (item); + + if (mediaItem){ + QString source = mediaItem->mediaFileUrl().toLocalFile(); + QString destination = source; + QUuid newUuid = QUuid::createUuid(); + QString fileName = QFileInfo(source).completeBaseName(); + destination = destination.replace(fileName,newUuid.toString()); + Q_ASSERT(QFile::copy(source,destination)); + mediaItem->mediaFileUrl(QUrl::fromLocalFile(destination)); + continue; + } + + UBGraphicsWidgetItem* widget = qgraphicsitem_cast(item); + if(widget){ + QUuid newUUid = QUuid::createUuid(); + QString newUUidString = newUUid.toString().remove("{").remove("}"); + QString actualUuidString = widget->uuid().toString().remove("{").remove("}"); + qDebug() << actualUuidString; + + QString widgetSourcePath = proxy->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/{" + actualUuidString + "}.wgt"; + QString screenshotSourcePath = proxy->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + actualUuidString + ".png"; + + QString widgetDestinationPath = widgetSourcePath; + widgetDestinationPath = widgetDestinationPath.replace(actualUuidString,newUUidString); + QString screenshotDestinationPath = screenshotSourcePath; + screenshotDestinationPath = screenshotDestinationPath.replace(actualUuidString,newUUidString); + + + qDebug() << "widgetSourcePath " << widgetSourcePath; + qDebug() << "widgetDestinationPath " << widgetDestinationPath; + qDebug() << "screenshotSourcePath " << screenshotSourcePath; + qDebug() << "screenshotDestinationPath " << screenshotDestinationPath; + + Q_ASSERT(UBFileSystemUtils::copyDir(widgetSourcePath,widgetDestinationPath)); + Q_ASSERT(QFile::copy(screenshotSourcePath,screenshotDestinationPath)); + + widget->setUuid(newUUid); + + widget->widgetUrl(QUrl::fromLocalFile(widgetDestinationPath)); + + continue; + } + + UBGraphicsPixmapItem* pixmapItem = qgraphicsitem_cast(item); + if(pixmapItem){ + pixmapItem->setUuid(QUuid::createUuid()); + continue; + } + + UBGraphicsSvgItem* svgItem = qgraphicsitem_cast(item); + if(svgItem){ + svgItem->setUuid(QUuid::createUuid()); + continue; + } + + } + scene->setModified(true); + + persistDocumentScene(proxy,scene, index + 1); + proxy->incPageCount(); emit documentSceneCreated(proxy, index + 1); diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index f69516fe..2ab8b9c7 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -57,6 +57,8 @@ public: return mMediaFileUrl; } + virtual void mediaFileUrl(QUrl url){mMediaFileUrl=url;} + Phonon::MediaObject* mediaObject() const { return mMediaObject; diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 5d3a9929..204def5f 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -149,6 +149,7 @@ QUrl UBGraphicsWidgetItem::widgetUrl() { return mWidgetUrl; } + QString UBGraphicsWidgetItem::mainHtmlFileName() { return mMainHtmlFileName; diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 344f05cf..502d2aa2 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -69,6 +69,7 @@ class UBGraphicsWidgetItem : public QGraphicsWebView, public UBItem, public UBRe QUrl mainHtml(); void loadMainHtml(); QUrl widgetUrl(); + void widgetUrl(QUrl url) { mWidgetUrl = url; } QString mainHtmlFileName(); bool canBeContent(); From d6768f35ede1658db7b97e188e59e8ad0a14f544 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 26 Jul 2013 09:08:00 +0200 Subject: [PATCH 7/7] removed debug log --- src/core/UBPersistenceManager.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 8d432d80..ab267208 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -516,7 +516,6 @@ void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int in QUuid newUUid = QUuid::createUuid(); QString newUUidString = newUUid.toString().remove("{").remove("}"); QString actualUuidString = widget->uuid().toString().remove("{").remove("}"); - qDebug() << actualUuidString; QString widgetSourcePath = proxy->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/{" + actualUuidString + "}.wgt"; QString screenshotSourcePath = proxy->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + actualUuidString + ".png"; @@ -526,12 +525,6 @@ void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int in QString screenshotDestinationPath = screenshotSourcePath; screenshotDestinationPath = screenshotDestinationPath.replace(actualUuidString,newUUidString); - - qDebug() << "widgetSourcePath " << widgetSourcePath; - qDebug() << "widgetDestinationPath " << widgetDestinationPath; - qDebug() << "screenshotSourcePath " << screenshotSourcePath; - qDebug() << "screenshotDestinationPath " << screenshotDestinationPath; - Q_ASSERT(UBFileSystemUtils::copyDir(widgetSourcePath,widgetDestinationPath)); Q_ASSERT(QFile::copy(screenshotSourcePath,screenshotDestinationPath));