Commit 71d9a71a authored by Anatoly Mihalchenko's avatar Anatoly Mihalchenko

Fix for losing content mentioned in the ticket 228. The problem was actually...

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.
parent 0d2565c2
......@@ -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<UBDocumentProxy>(doc));
......@@ -369,7 +369,7 @@ UBDocumentProxy* UBPersistenceManager::duplicateDocument(UBDocumentProxy* pDocum
void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QList<int>& 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();
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment