Save metadata.rdf less often

The documents' metadata.rdf file is now persisted only when a scene in
the document is also persisted; as well as when the document is modified
(trashed / path changed) in the the Documents pane.

Code was cleaned-up a bit too (added a forgotten return value, etc)
preferencesAboutTextFull
Craig Watson 9 years ago
parent 59207cbbf2
commit 11b9bf74fb
  1. 2
      src/adaptors/UBMetadataDcSubsetAdaptor.cpp
  2. 21
      src/core/UBPersistenceManager.cpp
  3. 17
      src/document/UBDocumentController.cpp
  4. 11
      src/document/UBDocumentProxy.cpp
  5. 4
      src/document/UBDocumentProxy.h

@ -86,7 +86,7 @@ void UBMetadataDcSubsetAdaptor::persist(UBDocumentProxy* proxy)
return;
}
QString fileName = proxy->persistencePath() + "/" + metadataFilename;
qWarning() << "Persisting document path is" << fileName;
qWarning() << "Persisting document; path is" << fileName;
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{

@ -211,13 +211,6 @@ QList<QPointer<UBDocumentProxy> > UBPersistenceManager::allDocumentProxies()
{
UBDocumentProxy* proxy = new UBDocumentProxy(fullPath); // deleted in UBPersistenceManager::destructor
QMap<QString, QVariant> metadatas = UBMetadataDcSubsetAdaptor::load(fullPath);
foreach(QString key, metadatas.keys())
{
proxy->setMetaData(key, metadatas.value(key));
}
proxy->setPageCount(sceneCount(proxy));
proxies << QPointer<UBDocumentProxy>(proxy);
@ -376,13 +369,6 @@ UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDoc
doc->setMetaData(UBSettings::documentName, pName);
}
QMap<QString, QVariant> metadatas = UBMetadataDcSubsetAdaptor::load(pDocumentDirectory);
foreach(QString key, metadatas.keys())
{
doc->setMetaData(key, metadatas.value(key));
}
doc->setUuid(QUuid::createUuid());
doc->setPageCount(sceneCount(doc));
@ -775,11 +761,12 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene);
if (pDocumentProxy->isModified())
persistDocumentMetadata(pDocumentProxy, forceImmediateSaving);
if (pScene->isModified())
{
//qDebug() << "Persisting scene";
if (pDocumentProxy->isModified())
persistDocumentMetadata(pDocumentProxy, forceImmediateSaving);
UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex);
if(forceImmediateSaving)
UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex);

@ -517,7 +517,6 @@ void UBDocumentController::duplicateSelectedItem()
duplicatePages(selectedSceneIndexes);
emit documentThumbnailsUpdated(this);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument());
mDocumentUI->thumbnailWidget->selectItemAt(selectedSceneIndexes.last() + selectedSceneIndexes.size());
}
}
@ -534,7 +533,6 @@ void UBDocumentController::duplicateSelectedItem()
UBDocumentProxy* duplicatedDoc = UBPersistenceManager::persistenceManager()->duplicateDocument(source);
duplicatedDoc->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(duplicatedDoc);
selectDocument(duplicatedDoc, false);
@ -995,13 +993,7 @@ void UBDocumentController::itemChanged(QTreeWidgetItem * item, int column)
, this, SLOT(updateDocumentInTree(UBDocumentProxy*)));
if (proxyItem)
{
if (proxyItem->proxy()->metaData(UBSettings::documentName).toString() != item->text(column))
{
proxyItem->proxy()->setMetaData(UBSettings::documentName, item->text(column));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyItem->proxy());
}
}
proxyItem->proxy()->setMetaData(UBSettings::documentName, item->text(column));
else
{
// it is a group
@ -1017,7 +1009,6 @@ void UBDocumentController::itemChanged(QTreeWidgetItem * item, int column)
if (0 != (item->flags() & Qt::ItemIsEditable))
{
childItem->proxy()->setMetaData(UBSettings::documentGroupName, item->text(column));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(childItem->proxy());
}
}
}
@ -1104,7 +1095,6 @@ void UBDocumentController::addFolderOfImages()
else
{
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
reloadThumbnails();
}
}
@ -1150,7 +1140,6 @@ bool UBDocumentController::addFileToDocument(UBDocumentProxy* document)
if (success)
{
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
}
else
{
@ -1169,7 +1158,6 @@ void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source,
if (UBDocumentContainer::movePageToIndex(source, target))
{
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxy);
mDocumentUI->thumbnailWidget->hightlightItem(target);
}
@ -1497,7 +1485,6 @@ void UBDocumentController::addToDocument()
mDocumentUI->thumbnailWidget->selectItemAt(newActiveSceneIndex, false);
selectDocument(mBoardController->selectedDocument());
mBoardController->selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mBoardController->selectedDocument());
UBApplication::applicationController->showBoard();
}
@ -1678,7 +1665,6 @@ void UBDocumentController::addImages()
else
{
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
reloadThumbnails();
}
}
@ -1791,7 +1777,6 @@ void UBDocumentController::deletePages(QList<QGraphicsItem *> itemsToDelete)
UBDocumentContainer::deletePages(sceneIndexes);
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxy);
int minIndex = proxy->pageCount() - 1;
foreach (int i, sceneIndexes)

@ -33,9 +33,10 @@
#include "core/UBPersistenceManager.h"
#include "core/UBSettings.h"
#include "core/UBDocumentManager.h"
#include "core/memcheck.h"
#include "adaptors/UBMetadataDcSubsetAdaptor.h"
UBDocumentProxy::UBDocumentProxy()
: mPageCount(0)
{
@ -48,6 +49,8 @@ UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath)
{
init();
setPersistencePath(pPersistancePath);
mMetaDatas = UBMetadataDcSubsetAdaptor::load(pPersistancePath);
}
@ -74,9 +77,11 @@ UBDocumentProxy* UBDocumentProxy::deepCopy() const
UBDocumentProxy* copy = new UBDocumentProxy();
copy->mPersistencePath = QString(mPersistencePath);
copy->mMetaDatas = QHash<QString, QVariant>(mMetaDatas);
copy->mMetaDatas = QMap<QString, QVariant>(mMetaDatas);
copy->mIsModified = mIsModified;
copy->mPageCount = mPageCount;
return copy;
}
@ -164,7 +169,7 @@ QVariant UBDocumentProxy::metaData(const QString& pKey) const
}
}
QHash<QString, QVariant> UBDocumentProxy::metaDatas() const
QMap<QString, QVariant> UBDocumentProxy::metaDatas() const
{
return mMetaDatas;
}

@ -57,7 +57,7 @@ class UBDocumentProxy : public QObject
void setMetaData(const QString& pKey , const QVariant& pValue);
QVariant metaData(const QString& pKey) const;
QHash<QString, QVariant> metaDatas() const;
QMap<QString, QVariant> metaDatas() const;
QString name() const;
QString groupName() const;
@ -88,7 +88,7 @@ class UBDocumentProxy : public QObject
QString mPersistencePath;
QHash<QString, QVariant> mMetaDatas;
QMap<QString, QVariant> mMetaDatas;
bool mIsModified;

Loading…
Cancel
Save