From 71d9a71a26421d51fb89e77e8409302d35c05c80 Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Mon, 23 Jan 2012 15:25:19 +0300 Subject: [PATCH] Fix for losing content mentioned in the ticket 228. The problem was actually in page deletion algorithm which has been flooding cache with invalid data, and that data was a object to return when loadDocumentScene was called. --- src/core/UBPersistenceManager.cpp | 24 +++++++----------------- src/core/UBPersistenceManager.h | 2 +- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 34ec2e6f..cb58ace4 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -240,7 +240,7 @@ QStringList UBPersistenceManager::allWidgets(const QDir& dir) } -UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName, const QString& pName) +UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName, const QString& pName, bool withEmptyPage) { checkIfDocumentRepositoryExists(); @@ -259,7 +259,7 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName, doc->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion); doc->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); - createDocumentSceneAt(doc, 0); + if (withEmptyPage) createDocumentSceneAt(doc, 0); documentProxies.insert(0, QPointer(doc)); @@ -369,7 +369,7 @@ UBDocumentProxy* UBPersistenceManager::duplicateDocument(UBDocumentProxy* pDocum void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QList& indexes) { - checkIfDocumentRepositoryExists(); + checkIfDocumentRepositoryExists(); int pageCount = UBPersistenceManager::persistenceManager()->sceneCount(proxy); @@ -397,15 +397,14 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL QString sourceGroupName = proxy->metaData(UBSettings::documentGroupName).toString(); QString sourceName = proxy->metaData(UBSettings::documentName).toString(); - UBDocumentProxy *trashDocProxy = createDocument(UBSettings::trashedDocumentGroupNamePrefix + sourceGroupName, sourceName); + UBDocumentProxy *trashDocProxy = createDocument(UBSettings::trashedDocumentGroupNamePrefix + sourceGroupName, sourceName, false); foreach(int index, compactedIndexes) { UBGraphicsScene *scene = loadDocumentScene(proxy, index); if (scene) { - UBGraphicsScene* sceneClone = scene->sceneDeepCopy(); - + //scene is about to move into new document foreach (QUrl relativeFile, scene->relativeDependencies()) { QString source = scene->document()->persistencePath() + "/" + relativeFile.toString(); @@ -418,19 +417,10 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL QFile::copy(source, target); } - insertDocumentSceneAt(trashDocProxy, sceneClone, trashDocProxy->pageCount()); + insertDocumentSceneAt(trashDocProxy, scene, trashDocProxy->pageCount()); } } - // Delete empty first page - QString svgFileName = trashDocProxy->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", 1); - QFile::remove(svgFileName); - QString thumbFileName = trashDocProxy->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", 1); - QFile::remove(thumbFileName); - trashDocProxy->decPageCount(); - for (int i = 1; i < pageCount; i++) { renamePage(trashDocProxy, i , i - 1); @@ -448,7 +438,7 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL QFile::remove(thumbFileName); - mSceneCache.removeScene(proxy, index); + mSceneCache.removeScene(proxy, index); proxy->decPageCount(); diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 3891f186..ce24462c 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -60,7 +60,7 @@ class UBPersistenceManager : public QObject static UBPersistenceManager* persistenceManager(); static void destroy(); - virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = ""); + virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = true); virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory); virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy);