fixed issue with teacher guide data persistance

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent 75b7fd5666
commit 76d5c99e21
  1. 104
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 2
      src/adaptors/UBSvgSubsetAdaptor.h
  3. 1
      src/board/UBBoardController.cpp
  4. 9
      src/core/UBPersistenceManager.cpp
  5. 2
      src/core/UBPersistenceManager.h
  6. 2
      src/document/UBDocumentProxy.cpp
  7. 6
      src/gui/UBTeacherGuideWidget.cpp
  8. 2
      src/interfaces/IDataStorage.h

@ -72,16 +72,6 @@ const QString UBSvgSubsetAdaptor::sFontStylePrefix = "font-style:";
const QString UBSvgSubsetAdaptor::sFormerUniboardDocumentNamespaceUri = "http://www.mnemis.com/uniboard";
QMap<QString,IDataStorage*> 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 += "<teacherGuide version=\"" + mXmlReader.attributes().value("version").toString() + "\">";
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 += "</teacherGuide>";
}
}
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 += "<teacherGuide version=\"" + mXmlReader.attributes().value("version").toString() + "\">";
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 += "<teacherGuide version=\"" + mXmlReader.attributes().value("version").toString() + "\">";
// 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 += "</teacherGuide>";
QMap<QString,IDataStorage*> elements = getAdditionalElementToStore();
IDataStorage* storageClass = elements.value("teacherGuide");
if(storageClass){
storageClass->load(sTeacherGuideNode);
}
}
// else if (mXmlReader.name() == "teacherBar" || mXmlReader.name() == "teacherGuide"){
// sTeacherGuideNode += "</teacherGuide>";
// qDebug() << sTeacherGuideNode;
// QMap<QString,IDataStorage*> 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;

@ -65,7 +65,6 @@ class UBSvgSubsetAdaptor
static void convertSvgImagesToImages(UBDocumentProxy* proxy);
static QMap<QString,IDataStorage*> 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);

@ -62,6 +62,7 @@
#include "podcast/UBPodcastController.h"
#include "adaptors/UBMetadataDcSubsetAdaptor.h"
#include "adaptors/UBSvgSubsetAdaptor.h"
#include "UBBoardPaletteManager.h"

@ -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);

@ -157,6 +157,8 @@ class UBPersistenceManager : public QObject
QString mDocumentRepositoryPath;
QHash<int,QString>teacherBarNodeString;
private slots:
void documentRepositoryChanged(const QString& path);

@ -209,8 +209,6 @@ void UBDocumentProxy::setUuid(const QUuid& uuid)
QDateTime UBDocumentProxy::documentDate()
{
qDebug()<< UBSettings::documentDate;
qDebug()<<mMetaDatas;
if(mMetaDatas.contains(UBSettings::documentDate))
return UBStringUtils::fromUtcIsoDate(metaData(UBSettings::documentDate).toString());
return QDateTime::currentDateTime();

@ -161,7 +161,9 @@ void UBTeacherGuideEditionWidget::showEvent(QShowEvent* event)
void UBTeacherGuideEditionWidget::onActiveDocumentChanged()
{
load(UBSvgSubsetAdaptor::sTeacherGuideNode);
int activeSceneIndex = UBApplication::boardController->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)

@ -36,7 +36,7 @@ typedef struct
class IDataStorage
{
public:
virtual void load(QString element) = 0;
//virtual void load(QString element) = 0;
virtual QVector<tIDataStorage*>save(int pageIndex) = 0 ;
};
#endif // IDATASTORAGE_H

Loading…
Cancel
Save