From 39a1284023cee31d839126356c231749efc7b5bd Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 10 Apr 2014 12:32:54 +0200 Subject: [PATCH] duplication fixed. Crash on closing the application after creating a new document fixed. --- src/board/UBBoardController.cpp | 12 ++++++------ src/board/UBBoardController.h | 2 +- src/core/UBPersistenceManager.cpp | 19 +++++++++++-------- src/core/UBPersistenceManager.h | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 1ea8c1e0..d9f6b8d3 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -481,7 +481,7 @@ void UBBoardController::stylusToolDoubleClicked(int tool) void UBBoardController::addScene() { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - persistCurrentScene(); + persistCurrentScene(false,true); UBDocumentContainer::addPage(mActiveSceneIndex + 1); @@ -523,7 +523,7 @@ void UBBoardController::addScene(UBGraphicsScene* scene, bool replaceActiveIfEmp } else { - persistCurrentScene(); + persistCurrentScene(false,true); UBPersistenceManager::persistenceManager()->insertDocumentSceneAt(selectedDocument(), clone, mActiveSceneIndex + 1); setActiveDocumentScene(mActiveSceneIndex + 1); } @@ -546,7 +546,7 @@ void UBBoardController::addScene(UBDocumentProxy* proxy, int sceneIndex, bool re void UBBoardController::duplicateScene(int nIndex) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - persistCurrentScene(); + persistCurrentScene(false,true); QList scIndexes; scIndexes << nIndex; @@ -1538,7 +1538,7 @@ void UBBoardController::moveSceneToIndex(int source, int target) if (selectedDocument()) { - persistCurrentScene(); + persistCurrentScene(false,true); UBDocumentContainer::movePageToIndex(source, target); @@ -1890,14 +1890,14 @@ void UBBoardController::show() UBApplication::mainWindow->actionLibrary->setChecked(false); } -void UBBoardController::persistCurrentScene(bool isAnAutomaticBackup) +void UBBoardController::persistCurrentScene(bool isAnAutomaticBackup, bool forceImmediateSave) { if(UBPersistenceManager::persistenceManager() && selectedDocument() && mActiveScene && mActiveSceneIndex != mDeletingSceneIndex && (mActiveSceneIndex >= 0) && mActiveSceneIndex != mMovingSceneIndex && (mActiveScene->isModified())) { - UBPersistenceManager::persistenceManager()->persistDocumentScene(selectedDocument(), mActiveScene, mActiveSceneIndex, isAnAutomaticBackup); + UBPersistenceManager::persistenceManager()->persistDocumentScene(selectedDocument(), mActiveScene, mActiveSceneIndex, isAnAutomaticBackup,forceImmediateSave); updatePage(mActiveSceneIndex); } } diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index d539eb88..970665e4 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -156,7 +156,7 @@ class UBBoardController : public UBDocumentContainer return mSystemScaleFactor; } qreal currentZoom(); - void persistCurrentScene(bool isAnAutomaticBackup = false); + void persistCurrentScene(bool isAnAutomaticBackup = false, bool forceImmediateSave = false); void showNewVersionAvailable(bool automatic, const UBVersion &installedVersion, const UBSoftwareUpdate &softwareUpdate); void setBoxing(QRect displayRect); void setToolbarTexts(); diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index cf4b9261..c8ca813f 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -725,7 +725,7 @@ UBGraphicsScene* UBPersistenceManager::loadDocumentScene(UBDocumentProxy* proxy, return scene; } -void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* pScene, const int pSceneIndex, bool isAnAutomaticBackup) +void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* pScene, const int pSceneIndex, bool isAnAutomaticBackup, bool forceImmediateSaving) { checkIfDocumentRepositoryExists(); @@ -745,12 +745,13 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, if (pScene->isModified()) { UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex); - QTime time; - time.start(); - UBGraphicsScene* copiedScene = pScene->sceneDeepCopy(); - qDebug() << "time to duplicate scene " << time.elapsed() << " ms"; - mWorker->saveScene(pDocumentProxy, copiedScene, pSceneIndex); - pScene->setModified(false); + if(forceImmediateSaving) + UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex); + else{ + UBGraphicsScene* copiedScene = pScene->sceneDeepCopy(); + mWorker->saveScene(pDocumentProxy, copiedScene, pSceneIndex); + pScene->setModified(false); + } } } @@ -909,8 +910,10 @@ bool UBPersistenceManager::isEmpty(UBDocumentProxy* pDocumentProxy) if (theSoleScene) { empty = theSoleScene->isEmpty(); - if(empty) + if(empty){ + mSceneCache.removeScene(pDocumentProxy,0); delete theSoleScene; + } } else { diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 9fa1a590..6a4de5bc 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -75,7 +75,7 @@ class UBPersistenceManager : public QObject virtual void duplicateDocumentScene(UBDocumentProxy* pDocumentProxy, int index); virtual void persistDocumentScene(UBDocumentProxy* pDocumentProxy, - UBGraphicsScene* pScene, const int pSceneIndex, bool isAnAutomaticBackup = false); + UBGraphicsScene* pScene, const int pSceneIndex, bool isAnAutomaticBackup = false, bool forceImmediateSaving = false); virtual UBGraphicsScene* createDocumentSceneAt(UBDocumentProxy* pDocumentProxy, int index, bool useUndoRedoStack = true);