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.

preferencesAboutTextFull
Anatoly Mihalchenko 13 years ago
parent 0d2565c25d
commit 71d9a71a26
  1. 24
      src/core/UBPersistenceManager.cpp
  2. 2
      src/core/UBPersistenceManager.h

@ -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(); checkIfDocumentRepositoryExists();
@ -259,7 +259,7 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName,
doc->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion); doc->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion);
doc->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); doc->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
createDocumentSceneAt(doc, 0); if (withEmptyPage) createDocumentSceneAt(doc, 0);
documentProxies.insert(0, QPointer<UBDocumentProxy>(doc)); documentProxies.insert(0, QPointer<UBDocumentProxy>(doc));
@ -369,7 +369,7 @@ UBDocumentProxy* UBPersistenceManager::duplicateDocument(UBDocumentProxy* pDocum
void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QList<int>& indexes) void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QList<int>& indexes)
{ {
checkIfDocumentRepositoryExists(); checkIfDocumentRepositoryExists();
int pageCount = UBPersistenceManager::persistenceManager()->sceneCount(proxy); 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 sourceGroupName = proxy->metaData(UBSettings::documentGroupName).toString();
QString sourceName = proxy->metaData(UBSettings::documentName).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) foreach(int index, compactedIndexes)
{ {
UBGraphicsScene *scene = loadDocumentScene(proxy, index); UBGraphicsScene *scene = loadDocumentScene(proxy, index);
if (scene) if (scene)
{ {
UBGraphicsScene* sceneClone = scene->sceneDeepCopy(); //scene is about to move into new document
foreach (QUrl relativeFile, scene->relativeDependencies()) foreach (QUrl relativeFile, scene->relativeDependencies())
{ {
QString source = scene->document()->persistencePath() + "/" + relativeFile.toString(); QString source = scene->document()->persistencePath() + "/" + relativeFile.toString();
@ -418,19 +417,10 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL
QFile::copy(source, target); 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++) for (int i = 1; i < pageCount; i++)
{ {
renamePage(trashDocProxy, i , i - 1); renamePage(trashDocProxy, i , i - 1);
@ -448,7 +438,7 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL
QFile::remove(thumbFileName); QFile::remove(thumbFileName);
mSceneCache.removeScene(proxy, index); mSceneCache.removeScene(proxy, index);
proxy->decPageCount(); proxy->decPageCount();

@ -60,7 +60,7 @@ class UBPersistenceManager : public QObject
static UBPersistenceManager* persistenceManager(); static UBPersistenceManager* persistenceManager();
static void destroy(); 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* createDocumentFromDir(const QString& pDocumentDirectory);
virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy); virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy);

Loading…
Cancel
Save