From 76d5c99e21b2df8c99a5041412a72ede5eae2873 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 9 May 2012 17:33:33 +0200 Subject: [PATCH] fixed issue with teacher guide data persistance --- src/adaptors/UBSvgSubsetAdaptor.cpp | 104 ++++++++++++++++++---------- src/adaptors/UBSvgSubsetAdaptor.h | 2 +- src/board/UBBoardController.cpp | 1 + src/core/UBPersistenceManager.cpp | 9 +-- src/core/UBPersistenceManager.h | 2 + src/document/UBDocumentProxy.cpp | 2 - src/gui/UBTeacherGuideWidget.cpp | 6 +- src/interfaces/IDataStorage.h | 2 +- 8 files changed, 79 insertions(+), 49 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index e028d143..23b3f408 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -72,16 +72,6 @@ const QString UBSvgSubsetAdaptor::sFontStylePrefix = "font-style:"; const QString UBSvgSubsetAdaptor::sFormerUniboardDocumentNamespaceUri = "http://www.mnemis.com/uniboard"; QMap UBSvgSubsetAdaptor::additionalElementToStore; -// Why using such a string? -// Media file path are relative to the current document. So if we are reading the -// first page of a document the document path has not been updated. -// Concatenate relative media path with the old document path leads to mess -// This string is so used only for activeDocumentChanged signal -QString UBSvgSubsetAdaptor::sTeacherGuideNode = ""; - - - - QString UBSvgSubsetAdaptor::toSvgTransform(const QMatrix& matrix) { return QString("matrix(%1, %2, %3, %4, %5, %6)") @@ -259,8 +249,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const int QUuid UBSvgSubsetAdaptor::sceneUuid(UBDocumentProxy* proxy, const int pageIndex) { - QString fileName = proxy->persistencePath() + - UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex); + QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", pageIndex); QFile file(fileName); @@ -312,6 +301,53 @@ UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const QBy } +QString UBSvgSubsetAdaptor::readTeacherGuideNode(int sceneIndex) +{ + QString result; + + QString fileName = UBApplication::boardController->activeDocument()->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", sceneIndex); + QFile file(fileName); + file.open(QIODevice::ReadOnly); + QByteArray fileByteArray=file.readAll(); + file.close(); + QXmlStreamReader mXmlReader(fileByteArray); + + while (!mXmlReader.atEnd()) + { + mXmlReader.readNext(); + if (mXmlReader.isStartElement()) + { + if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){ + result.clear(); + result += ""; + result += "\n"; + } + else if (mXmlReader.name() == "media" || mXmlReader.name() == "link" || mXmlReader.name() == "title" || mXmlReader.name() == "comment" || mXmlReader.name() == "action") + { + result += "<" + mXmlReader.name().toString() + " "; + foreach(QXmlStreamAttribute attribute, mXmlReader.attributes()) + result += attribute.name().toString() + "=\"" + attribute.value().toString() + "\" "; + result += " />\n"; + } + else + { + // NOOP + } + } + else if (mXmlReader.isEndElement() && (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide")){ + result += ""; + } + } + + if (mXmlReader.hasError()) + { + qWarning() << "error parsing Sankore file " << mXmlReader.errorString(); + } + + return result; +} + + UBSvgSubsetAdaptor::UBSvgSubsetReader::UBSvgSubsetReader(UBDocumentProxy* pProxy, const QByteArray& pXmlData) : mXmlReader(pXmlData) , mProxy(pProxy) @@ -333,8 +369,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() UBGraphicsStrokesGroup* strokesGroup = 0; UBDrawingController* dc = UBDrawingController::drawingController(); - sTeacherGuideNode = ""; - while (!mXmlReader.atEnd()) { @@ -851,18 +885,18 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() currentWidget->setDatastoreEntry(key, value); } - else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){ - sTeacherGuideNode.clear(); - sTeacherGuideNode += ""; - sTeacherGuideNode += "\n"; - } - else if (mXmlReader.name() == "media" || mXmlReader.name() == "link" || mXmlReader.name() == "title" || mXmlReader.name() == "comment" || mXmlReader.name() == "action") - { - sTeacherGuideNode += "<" + mXmlReader.name().toString() + " "; - foreach(QXmlStreamAttribute attribute, mXmlReader.attributes()) - sTeacherGuideNode += attribute.name().toString() + "=\"" + attribute.value().toString() + "\" "; - sTeacherGuideNode += " />\n"; - } +// else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){ +// sTeacherGuideNode.clear(); +// sTeacherGuideNode += ""; +// sTeacherGuideNode += "\n"; +// } +// else if (mXmlReader.name() == "media" || mXmlReader.name() == "link" || mXmlReader.name() == "title" || mXmlReader.name() == "comment" || mXmlReader.name() == "action") +// { +// sTeacherGuideNode += "<" + mXmlReader.name().toString() + " "; +// foreach(QXmlStreamAttribute attribute, mXmlReader.attributes()) +// sTeacherGuideNode += attribute.name().toString() + "=\"" + attribute.value().toString() + "\" "; +// sTeacherGuideNode += " />\n"; +// } else { // NOOP @@ -886,14 +920,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() mGroupDarkBackgroundColor = QColor(); mGroupLightBackgroundColor = QColor(); } - else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){ - sTeacherGuideNode += ""; - QMap elements = getAdditionalElementToStore(); - IDataStorage* storageClass = elements.value("teacherGuide"); - if(storageClass){ - storageClass->load(sTeacherGuideNode); - } - } +// else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){ +// sTeacherGuideNode += ""; +// qDebug() << sTeacherGuideNode; +// QMap elements = getAdditionalElementToStore(); +// IDataStorage* storageClass = elements.value("teacherGuide"); +// if(storageClass){ +// storageClass->load(sTeacherGuideNode); +// } +// } } } @@ -969,7 +1004,6 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement() bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) { - sTeacherGuideNode = ""; if (mScene->isModified()) { QBuffer buffer; diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index 8edb3389..d3b39c37 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -65,7 +65,6 @@ class UBSvgSubsetAdaptor static void convertSvgImagesToImages(UBDocumentProxy* proxy); static QMap getAdditionalElementToStore() { return additionalElementToStore;} - static QString sTeacherGuideNode; static const QString nsSvg; static const QString nsXLink; @@ -79,6 +78,7 @@ class UBSvgSubsetAdaptor static const QString sFontWeightPrefix; static const QString sFontStylePrefix; + static QString readTeacherGuideNode(int sceneIndex); private: static UBGraphicsScene* loadScene(UBDocumentProxy* proxy, const QByteArray& pArray); diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 25f54053..b78b829c 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -62,6 +62,7 @@ #include "podcast/UBPodcastController.h" #include "adaptors/UBMetadataDcSubsetAdaptor.h" +#include "adaptors/UBSvgSubsetAdaptor.h" #include "UBBoardPaletteManager.h" diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 84b2d242..91b1f478 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -580,15 +580,8 @@ void UBPersistenceManager::moveSceneToIndex(UBDocumentProxy* proxy, int source, UBGraphicsScene* UBPersistenceManager::loadDocumentScene(UBDocumentProxy* proxy, int sceneIndex) { if (mSceneCache.contains(proxy, sceneIndex)) - { - //qDebug() << "scene" << sceneIndex << "retrieved from cache ..."; - //updating teacher guide node - //TODO Claudio find a way to store extra information like teacher guid - UBSvgSubsetAdaptor::loadScene(proxy, sceneIndex); return mSceneCache.value(proxy, sceneIndex); - } - else - { + else { qDebug() << "scene" << sceneIndex << "retrieved from file ..."; UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, sceneIndex); diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h index 75af2390..e5e88114 100644 --- a/src/core/UBPersistenceManager.h +++ b/src/core/UBPersistenceManager.h @@ -157,6 +157,8 @@ class UBPersistenceManager : public QObject QString mDocumentRepositoryPath; + QHashteacherBarNodeString; + private slots: void documentRepositoryChanged(const QString& path); diff --git a/src/document/UBDocumentProxy.cpp b/src/document/UBDocumentProxy.cpp index dff6cf9a..6dac0203 100644 --- a/src/document/UBDocumentProxy.cpp +++ b/src/document/UBDocumentProxy.cpp @@ -209,8 +209,6 @@ void UBDocumentProxy::setUuid(const QUuid& uuid) QDateTime UBDocumentProxy::documentDate() { - qDebug()<< UBSettings::documentDate; - qDebug()<activeSceneIndex(); + if(UBApplication::boardController->pageFromSceneIndex(activeSceneIndex) != 0) + load(UBSvgSubsetAdaptor::readTeacherGuideNode(activeSceneIndex)); } void UBTeacherGuideEditionWidget::load(QString element) @@ -238,7 +240,7 @@ void UBTeacherGuideEditionWidget::onActiveSceneChanged() int currentPage = UBApplication::boardController->currentPage(); if(currentPage > 0){ cleanData(); - load(UBSvgSubsetAdaptor::sTeacherGuideNode); + load(UBSvgSubsetAdaptor::readTeacherGuideNode(UBApplication::boardController->activeSceneIndex())); mpPageNumberLabel->setText(tr("Page: %0").arg(currentPage)); UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); if(mpDocumentTitle) diff --git a/src/interfaces/IDataStorage.h b/src/interfaces/IDataStorage.h index 10e69c93..8de8a585 100644 --- a/src/interfaces/IDataStorage.h +++ b/src/interfaces/IDataStorage.h @@ -36,7 +36,7 @@ typedef struct class IDataStorage { public: - virtual void load(QString element) = 0; + //virtual void load(QString element) = 0; virtual QVectorsave(int pageIndex) = 0 ; }; #endif // IDATASTORAGE_H