diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index c9af3e92..b7c94c18 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -120,7 +120,6 @@ QMatrix UBSvgSubsetAdaptor::fromSvgTransform(const QString& transform) static bool itemZIndexComp(const QGraphicsItem* item1, const QGraphicsItem* item2) { -// return item1->zValue() < item2->zValue(); return item1->data(UBGraphicsItemData::ItemOwnZValue).toReal() < item2->data(UBGraphicsItemData::ItemOwnZValue).toReal(); } @@ -1189,6 +1188,26 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene() openStroke = 0; } + QMap elements = getAdditionalElementToStore(); + QVector dataStorageItems = elements.value("teacherGuide")->save(); + foreach(tIDataStorage* eachItem, dataStorageItems){ + if(eachItem->type == eElementType_START){ + mXmlWriter.writeStartElement(eachItem->name); + foreach(QString key,eachItem->attributes.keys()) + mXmlWriter.writeAttribute(key,eachItem->attributes.value(key)); + } + else if (eachItem->type == eElementType_END) + mXmlWriter.writeEndElement(); + else if (eachItem->type == eElementType_UNIQUE){ + mXmlWriter.writeStartElement(eachItem->name); + foreach(QString key,eachItem->attributes.keys()) + mXmlWriter.writeAttribute(key,eachItem->attributes.value(key)); + mXmlWriter.writeEndElement(); + } + else + qWarning() << "unknown type"; + } + mXmlWriter.writeEndDocument(); QString fileName = mDocumentPath + UBFileSystemUtils::digitFileFormat("/page%1.svg", UBApplication::boardController->pageFromSceneIndex(mPageIndex)); QFile file(fileName); diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index df578d4b..7b9014dc 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -189,10 +189,49 @@ void UBTeacherGuideEditionWidget::load(QString element) -QDomElement* UBTeacherGuideEditionWidget::save(QDomElement* parentElement) +QVector UBTeacherGuideEditionWidget::save() { - qDebug() << parentElement; - return 0; + QVector result; + QMap attributes; + tIDataStorage* data = new tIDataStorage(); + data->name = "teacherBar"; + data->type = eElementType_START; + data->attributes.insert("version","1.50"); + result << data; + + data = new tIDataStorage(); + data->name = "title"; + data->type = eElementType_UNIQUE; + data->attributes.insert("value",mpPageTitle->text()); + result << data; + + data = new tIDataStorage(); + data->name = "comment"; + data->type = eElementType_UNIQUE; + data->attributes.insert("value",mpComment->text()); + result << data; + + QList children = getChildrenList(mpAddAnActionItem); + children << getChildrenList(mpAddAMediaItem); + children << getChildrenList(mpAddALinkItem); + + foreach(QTreeWidgetItem* widgetItem, children){ + tUBGEElementNode* node = dynamic_cast(mpTreeWidget->itemWidget(widgetItem,0))->saveData(); + if(node){ + data = new tIDataStorage(); + data->name = node->name; + data->type = eElementType_UNIQUE; + foreach(QString currentKey, node->attributes.keys()) + data->attributes.insert(currentKey,node->attributes.value(currentKey)); + result << data; + } + } + + data = new tIDataStorage(); + data->name = "teacherBar"; + data->type = eElementType_END; + result << data; + return result; } void UBTeacherGuideEditionWidget::onActiveSceneChanged() @@ -229,12 +268,12 @@ QVector UBTeacherGuideEditionWidget::getPageAndCommentData() { QVectorresult; tUBGEElementNode* pageTitle = new tUBGEElementNode(); - pageTitle->type = "pageTitle"; + pageTitle->name = "pageTitle"; pageTitle->attributes.insert("value",mpPageTitle->text()); result << pageTitle; tUBGEElementNode* comment = new tUBGEElementNode(); - comment->type = "comment"; + comment->name = "comment"; comment->attributes.insert("value",mpComment->text()); result << comment; return result; @@ -459,11 +498,11 @@ void UBTeacherGuidePresentationWidget::showData(QVector data) cleanData(); foreach(tUBGEElementNode* element, data){ - if(element->type == "pageTitle") + if(element->name == "pageTitle") mpPageTitle->showText(element->attributes.value("value")); - else if (element->type == "comment") + else if (element->name == "comment") mpComment->showText(element->attributes.value("value")); - else if(element->type == "action"){ + else if(element->name == "action"){ QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpRootWidgetItem); newWidgetItem->setText(0,element->attributes.value("task")); newWidgetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); @@ -477,14 +516,14 @@ void UBTeacherGuidePresentationWidget::showData(QVector data) mpRootWidgetItem->addChild(newWidgetItem); } - else if(element->type == "media"){ + else if(element->name == "media"){ createMediaButtonItem(); QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpMediaSwitchItem); newWidgetItem->setIcon(0,QIcon(":images/teacherGuide/"+ element->attributes.value("mediaType") +".png")); newWidgetItem->setText(0,element->attributes.value("title")); newWidgetItem->setData(0,tUBTGTreeWidgetItemRole_HasAnAction,tUBTGActionAssociateOnClickItem_MEDIA); newWidgetItem->setData(0,Qt::FontRole, QVariant(QFont(QApplication::font().family(),11))); - newWidgetItem->setData(0, TG_USER_ROLE_MIME_TYPE, element->attributes.value("relativePath")); + newWidgetItem->setData(0, TG_USER_ROLE_MIME_TYPE, UBApplication::boardController->activeDocument()->persistencePath()+ "/" + element->attributes.value("relativePath")); newWidgetItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsSelectable); mpRootWidgetItem->addChild(newWidgetItem); @@ -494,7 +533,7 @@ void UBTeacherGuidePresentationWidget::showData(QVector data) newWidgetItem->setExpanded(false); mpTreeWidget->setItemWidget(mediaItem,0,mediaWidget); } - else if(element->type == "link"){ + else if(element->name == "link"){ createMediaButtonItem(); QTreeWidgetItem* newWidgetItem = new QTreeWidgetItem(mpMediaSwitchItem); newWidgetItem->setIcon(0,QIcon(":images/teacherGuide/link.png")); @@ -954,52 +993,52 @@ QVector UBTeacherGuidePageZeroWidget::getData() { QVectorresult; tUBGEElementNode* elementNode = new tUBGEElementNode(); - elementNode->type = "sessionTitle"; + elementNode->name = "sessionTitle"; elementNode->attributes.insert("value",mpSessionTitle->text()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "authors"; + elementNode->name = "authors"; elementNode->attributes.insert("value",mpAuthors->text()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "creationDate"; + elementNode->name = "creationDate"; elementNode->attributes.insert("value",mpCreationLabel->text()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "lastModifiedDate"; + elementNode->name = "lastModifiedDate"; elementNode->attributes.insert("value",mpLastModifiedLabel->text()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "goals"; + elementNode->name = "goals"; elementNode->attributes.insert("value",mpGoals->text()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "keywords"; + elementNode->name = "keywords"; elementNode->attributes.insert("value",mpKeywords->text()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "schoolLevel"; + elementNode->name = "schoolLevel"; elementNode->attributes.insert("value",mpSchoolLevelBox->currentText()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "schoolBranch"; + elementNode->name = "schoolBranch"; elementNode->attributes.insert("value",mpSchoolBranchBox->currentText()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "schoolType"; + elementNode->name = "schoolType"; elementNode->attributes.insert("value",mpSchoolTypeBox->currentText()); result << elementNode; elementNode = new tUBGEElementNode(); - elementNode->type = "licence"; + elementNode->name = "licence"; elementNode->attributes.insert("value",mpLicenceBox->currentText()); result << elementNode; return result; diff --git a/src/gui/UBTeacherGuideWidget.h b/src/gui/UBTeacherGuideWidget.h index 81fb483f..387a7a64 100644 --- a/src/gui/UBTeacherGuideWidget.h +++ b/src/gui/UBTeacherGuideWidget.h @@ -48,7 +48,7 @@ public: QVector getData(); void load(QString element); - QDomElement* save(QDomElement* parentElement); + QVector save(); public slots: void onAddItemClicked(QTreeWidgetItem* widget, int column, QDomElement* element = 0); diff --git a/src/gui/UBTeacherGuideWidgetsTools.cpp b/src/gui/UBTeacherGuideWidgetsTools.cpp index 0a109813..eefb8714 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.cpp +++ b/src/gui/UBTeacherGuideWidgetsTools.cpp @@ -101,7 +101,7 @@ void UBTGActionWidget::initializeWithDom(QDomElement element) tUBGEElementNode* UBTGActionWidget::saveData() { tUBGEElementNode* result = new tUBGEElementNode(); - result->type = "action"; + result->name = "action"; result->attributes.insert("owner",QString("%0").arg(mpOwner->currentIndex())); result->attributes.insert("task",mpTask->text()); return result; @@ -306,12 +306,12 @@ UBTGMediaWidget::UBTGMediaWidget(QString mediaPath, QTreeWidgetItem* widget, QWi , mpMediaLabelWidget(NULL) , mpMediaWidget(NULL) , mpWebView(NULL) - , mMediaPath(mediaPath) , mIsPresentationMode(true) , mMediaType("") , mIsInitializationMode(false) { setObjectName(name); + mMediaPath = UBApplication::boardController->activeDocument()->persistencePath()+ "/" + mediaPath; setAcceptDrops(false); createWorkWidget(); setFixedHeight(200); @@ -361,9 +361,9 @@ tUBGEElementNode* UBTGMediaWidget::saveData() if(!mpTitle) return 0; tUBGEElementNode* result = new tUBGEElementNode(); - result->type = "media"; + result->name = "media"; result->attributes.insert("title",mpTitle->text()); - result->attributes.insert("relativePath",mMediaPath); + result->attributes.insert("relativePath",mMediaPath.replace(UBApplication::boardController->activeDocument()->persistencePath()+"/","")); result->attributes.insert("mediaType",mMediaType); return result; } @@ -534,7 +534,7 @@ void UBTGUrlWidget::initializeWithDom(QDomElement element) tUBGEElementNode* UBTGUrlWidget::saveData() { tUBGEElementNode* result = new tUBGEElementNode(); - result->type = "link"; + result->name = "link"; result->attributes.insert("title",mpTitle->text()); result->attributes.insert("url",mpUrl->text()); return result; diff --git a/src/gui/UBTeacherGuideWidgetsTools.h b/src/gui/UBTeacherGuideWidgetsTools.h index b15c2cfc..bb89add2 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.h +++ b/src/gui/UBTeacherGuideWidgetsTools.h @@ -42,7 +42,7 @@ class QDomElement; typedef struct { - QString type; + QString name; QMap attributes; }tUBGEElementNode; diff --git a/src/interfaces/IDataStorage.h b/src/interfaces/IDataStorage.h index 02695707..a703227d 100644 --- a/src/interfaces/IDataStorage.h +++ b/src/interfaces/IDataStorage.h @@ -16,12 +16,27 @@ #ifndef IDATASTORAGE_H #define IDATASTORAGE_H -class QDomElement; +#include +#include + +typedef enum +{ + eElementType_START, + eElementType_END, + eElementType_UNIQUE +}eElementType; + +typedef struct +{ + QString name; + QMap attributes; + eElementType type; +}tIDataStorage; class IDataStorage { public: virtual void load(QString element) = 0; - virtual QDomElement* save(QDomElement* parentElement) = 0 ; + virtual QVectorsave() = 0 ; }; #endif // IDATASTORAGE_H