CFF export and strokes groups

preferencesAboutTextFull
Ilia Ryabokon 12 years ago
parent 57a2d14134
commit dfa872033f
  1. 33
      plugins/cffadaptor/src/UBCFFAdaptor.cpp
  2. 2
      plugins/cffadaptor/src/UBCFFAdaptor.h
  3. 1
      plugins/cffadaptor/src/UBCFFConstants.h
  4. 62
      src/adaptors/UBSvgSubsetAdaptor.cpp
  5. 1
      src/adaptors/UBSvgSubsetAdaptor.h
  6. 7
      src/domain/UBGraphicsPolygonItem.cpp
  7. 2
      src/domain/UBGraphicsPolygonItem.h

@ -550,8 +550,8 @@ QDomElement UBCFFAdaptor::UBToCFFConverter::parsePage(const QString &pageFileNam
pageFile.close(); pageFile.close();
return QDomElement(); return QDomElement();
} }
} else if (tagname == tUBZGroup) { } else if (tagname == tUBZGroups) {
group = parseGroupPageSection(nextTopElement); group = parseGroupsPageSection(nextTopElement);
if (group.isNull()) { if (group.isNull()) {
qDebug() << "Page doesn't contains any groups."; qDebug() << "Page doesn't contains any groups.";
pageFile.close(); pageFile.close();
@ -634,6 +634,7 @@ QDomElement UBCFFAdaptor::UBToCFFConverter::parseSvgPageSection(const QDomElemen
else if (tagName == tUBZLine) parseUBZLine(nextElement, svgElements); else if (tagName == tUBZLine) parseUBZLine(nextElement, svgElements);
else if (tagName == tUBZPolygon) parseUBZPolygon(nextElement, svgElements); else if (tagName == tUBZPolygon) parseUBZPolygon(nextElement, svgElements);
else if (tagName == tUBZPolyline) parseUBZPolyline(nextElement, svgElements); else if (tagName == tUBZPolyline) parseUBZPolyline(nextElement, svgElements);
else if (tagName == tUBZGroups) parseGroupsPageSection(nextElement);
nextElement = nextElement.nextSiblingElement(); nextElement = nextElement.nextSiblingElement();
} }
@ -694,12 +695,34 @@ bool UBCFFAdaptor::UBToCFFConverter::writeExtendedIwbSection()
// extended element options // extended element options
// editable, background, locked are supported for now // editable, background, locked are supported for now
QDomElement UBCFFAdaptor::UBToCFFConverter::parseGroupPageSection(const QDomElement &element) QDomElement UBCFFAdaptor::UBToCFFConverter::parseGroupsPageSection(const QDomElement &groupRoot)
{ {
// First sankore side implementation needed. TODO in Sankore 1.5 // First sankore side implementation needed. TODO in Sankore 1.5
Q_UNUSED(element) if (!groupRoot.hasChildNodes()) {
qDebug() << "parsing ubz group section"; qDebug() << "Group root is empty";
return QDomElement(); return QDomElement();
}
QDomElement groupElement = groupRoot.firstChildElement();
while (!groupElement.isNull()) {
QDomElement extendedElement = mDataModel->createElementNS(iwbNS, groupElement.tagName());
QDomElement groupChildElement = groupElement.firstChildElement();
while (!groupChildElement.isNull()) {
QDomElement extSubElement = mDataModel->createElementNS(iwbNS, groupChildElement.tagName());
extSubElement.setAttribute(aRef, groupChildElement.attribute(aID, QUuid().toString()));
extendedElement.appendChild(extSubElement);
groupChildElement = groupChildElement.nextSiblingElement();
}
mExtendedElements.append(extendedElement);
groupElement = groupElement.nextSiblingElement();
}
qDebug() << "parsing ubz group section";
return groupRoot;
} }
QString UBCFFAdaptor::UBToCFFConverter::getDstContentFolderName(const QString &elementType) QString UBCFFAdaptor::UBToCFFConverter::getDstContentFolderName(const QString &elementType)

@ -63,7 +63,7 @@ private:
QDomElement parseSvgPageSection(const QDomElement &element); QDomElement parseSvgPageSection(const QDomElement &element);
void writeQDomElementToXML(const QDomNode &node); void writeQDomElementToXML(const QDomNode &node);
bool writeExtendedIwbSection(); bool writeExtendedIwbSection();
QDomElement parseGroupPageSection(const QDomElement &element); QDomElement parseGroupsPageSection(const QDomElement &groupRoot);
bool createBackground(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList); bool createBackground(const QDomElement &element, QMultiMap<int, QDomElement> &dstSvgList);
QString createBackgroundImage(const QDomElement &element, QSize size); QString createBackgroundImage(const QDomElement &element, QSize size);

@ -28,6 +28,7 @@ const QString tIWBPageSet = "pageset";
const QString tId = "id"; const QString tId = "id";
const QString tElement = "element"; const QString tElement = "element";
const QString tUBZGroup = "group"; const QString tUBZGroup = "group";
const QString tUBZGroups = "groups";
const QString tUBZG = "g"; const QString tUBZG = "g";
const QString tUBZPolygon = "polygon"; const QString tUBZPolygon = "polygon";
const QString tUBZPolyline = "polyline"; const QString tUBZPolyline = "polyline";

@ -48,6 +48,7 @@
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
#include "frameworks/UBStringUtils.h" #include "frameworks/UBStringUtils.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBSetting.h" #include "core/UBSetting.h"
@ -79,6 +80,7 @@ const QString UBSvgSubsetAdaptor::sFormerUniboardDocumentNamespaceUri = "http://
const QString tElement = "element"; const QString tElement = "element";
const QString tGroup = "group"; const QString tGroup = "group";
const QString tStrokeGroup = "strokeGroup";
const QString tGroups = "groups"; const QString tGroups = "groups";
const QString aId = "id"; const QString aId = "id";
@ -1152,10 +1154,20 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
QGraphicsItem *item = items.takeFirst(); QGraphicsItem *item = items.takeFirst();
// Is the item a strokes group? // Is the item a strokes group?
UBGraphicsStrokesGroup* strokesGroupItem = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item); UBGraphicsStrokesGroup* strokesGroupItem = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item);
if(strokesGroupItem && strokesGroupItem->isVisible()){ if(strokesGroupItem && strokesGroupItem->isVisible()){
mXmlWriter.writeStartElement("g"); QDomElement newGroupElement;
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "uuid", UBStringUtils::toCanonicalUuid(strokesGroupItem->uuid())); if (!strokesGroupItem->parentItem() && strokesGroupItem->childItems().count()) {
newGroupElement = groupDomDocument.createElement(tGroup);
newGroupElement.setAttribute(aId, strokesGroupItem->uuid().toString());
groupRoot.appendChild(newGroupElement);
}
//disabling g section parsing as a group of elements. Use groups refs instead
// mXmlWriter.writeStartElement("g");
// mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "uuid", UBStringUtils::toCanonicalUuid(strokesGroupItem->uuid()));
QMatrix matrix = item->sceneMatrix(); QMatrix matrix = item->sceneMatrix();
if (!matrix.isIdentity()){ if (!matrix.isIdentity()){
mXmlWriter.writeAttribute("transform", toSvgTransform(matrix)); mXmlWriter.writeAttribute("transform", toSvgTransform(matrix));
@ -1163,14 +1175,21 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
// Add the polygons // Add the polygons
foreach(QGraphicsItem* item, strokesGroupItem->childItems()){ foreach(QGraphicsItem* item, strokesGroupItem->childItems()){
UBGraphicsPolygonItem* poly = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item); UBGraphicsPolygonItem* poly = qgraphicsitem_cast<UBGraphicsPolygonItem*>(item);
if(NULL != poly){ if(NULL != poly){
polygonItemToSvgPolygon(poly, true); polygonItemToSvgPolygon(poly, true);
if (!newGroupElement.isNull()) {
QDomElement curPolygonElement = groupDomDocument.createElement(tElement);
curPolygonElement.setAttribute(aId, strokesGroupItem->uuid().toString()
+ poly->uuid().toString());
newGroupElement.appendChild(curPolygonElement);
}
items.removeOne(poly); items.removeOne(poly);
} }
} }
mXmlWriter.writeEndElement(); //g // mXmlWriter.writeEndElement(); //g
} }
// Is the item a polygon? // Is the item a polygon?
@ -1401,12 +1420,12 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
QDomElement curElement = groupRoot.firstChildElement(); QDomElement curElement = groupRoot.firstChildElement();
while (!curElement.isNull()) { while (!curElement.isNull()) {
if (curElement.hasAttribute(aId)) { if (curElement.hasAttribute(aId)) {
mXmlWriter.writeStartElement(tGroup); mXmlWriter.writeStartElement(curElement.tagName());
mXmlWriter.writeAttribute(aId, curElement.attribute(aId)); mXmlWriter.writeAttribute(aId, curElement.attribute(aId));
QDomElement curSubElement = curElement.firstChildElement(); QDomElement curSubElement = curElement.firstChildElement();
while (!curSubElement.isNull()) { while (!curSubElement.isNull()) {
if (curSubElement.hasAttribute(aId)) { if (curSubElement.hasAttribute(aId)) {
mXmlWriter.writeStartElement(tElement); mXmlWriter.writeStartElement(curSubElement.tagName());
mXmlWriter.writeAttribute(aId, curSubElement.attribute(aId)); mXmlWriter.writeAttribute(aId, curSubElement.attribute(aId));
mXmlWriter.writeEndElement(); mXmlWriter.writeEndElement();
curSubElement = curSubElement.nextSiblingElement(); curSubElement = curSubElement.nextSiblingElement();
@ -1454,8 +1473,16 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistGroupToDom(QGraphicsItem *gro
if (!tmpUuid.isNull()) { if (!tmpUuid.isNull()) {
if (item->type() == UBGraphicsGroupContainerItem::Type && item->childItems().count()) { if (item->type() == UBGraphicsGroupContainerItem::Type && item->childItems().count()) {
persistGroupToDom(item, curParent, groupDomDocument); persistGroupToDom(item, curParent, groupDomDocument);
} else if (item->type() == UBGraphicsStrokesGroup::Type) {
foreach (QGraphicsItem *polygonItem, item->childItems()) {
QDomElement curPolygonElement = groupDomDocument->createElement(tElement);
curPolygonElement.setAttribute(aId, tmpUuid.toString()
+ UBGraphicsItem::getOwnUuid(polygonItem).toString());
curGroupElement.appendChild(curPolygonElement);
}
} else { } else {
QDomElement curSubElement = groupDomDocument->createElement(tGroup); QDomElement curSubElement = groupDomDocument->createElement(tElement);
curSubElement.setAttribute(aId, tmpUuid); curSubElement.setAttribute(aId, tmpUuid);
curGroupElement.appendChild(curSubElement); curGroupElement.appendChild(curSubElement);
} }
@ -1464,6 +1491,27 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistGroupToDom(QGraphicsItem *gro
} }
} }
void UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistStrokeToDom(QGraphicsItem *strokeItem, QDomElement *curParent, QDomDocument *curDomDocument)
{
QUuid uuid = UBGraphicsScene::getPersonalUuid(strokeItem);
if (!uuid.isNull()) {
QDomElement curStrokesGroupElement = curDomDocument->createElement(tStrokeGroup);
curStrokesGroupElement.setAttribute(aId, uuid);
curParent->appendChild(curStrokesGroupElement);
foreach (QGraphicsItem *item, strokeItem->childItems()) {
QUuid tmpUuid = UBGraphicsScene::getPersonalUuid(item);
if (!tmpUuid.isNull()) {
if (item->type() == UBGraphicsPolygonItem::Type && item->childItems().count()) {
QDomElement curSubElement = curDomDocument->createElement(tElement);
curSubElement.setAttribute(aId, tmpUuid);
curStrokesGroupElement.appendChild(curSubElement);
}
}
}
}
}
void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo) void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo)
{ {
mXmlWriter.writeStartElement("line"); mXmlWriter.writeStartElement("line");
@ -1615,6 +1663,8 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::polygonItemToSvgPolygon(UBGraphicsPo
, "fill-on-light-background", polygonItem->colorOnLightBackground().name()); , "fill-on-light-background", polygonItem->colorOnLightBackground().name());
} }
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "uuid", UBStringUtils::toCanonicalUuid(polygonItem->uuid()));
mXmlWriter.writeEndElement(); mXmlWriter.writeEndElement();
} }
} }

@ -179,6 +179,7 @@ class UBSvgSubsetAdaptor
private: private:
void persistGroupToDom(QGraphicsItem *groupItem, QDomElement *curParent, QDomDocument *curDomDocument); void persistGroupToDom(QGraphicsItem *groupItem, QDomElement *curParent, QDomDocument *curDomDocument);
void persistStrokeToDom(QGraphicsItem *strokeItem, QDomElement *curParent, QDomDocument *curDomDocument);
void polygonItemToSvgPolygon(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo); void polygonItemToSvgPolygon(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo);
void polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo); void polygonItemToSvgLine(UBGraphicsPolygonItem* polygonItem, bool groupHoldsInfo);
void strokeToSvgPolyline(UBGraphicsStroke* stroke, bool groupHoldsInfo); void strokeToSvgPolyline(UBGraphicsStroke* stroke, bool groupHoldsInfo);

@ -60,6 +60,13 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QLineF& pLine, qreal pWidth)
void UBGraphicsPolygonItem::initialize() void UBGraphicsPolygonItem::initialize()
{ {
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::DrawingItem)); //Necessary to set if we want z value to be assigned correctly
setUuid(QUuid::createUuid());
}
void UBGraphicsPolygonItem::setUuid(const QUuid &pUuid)
{
UBItem::setUuid(pUuid);
setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene
} }
void UBGraphicsPolygonItem::clearStroke() void UBGraphicsPolygonItem::clearStroke()

@ -39,6 +39,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
void initialize(); void initialize();
void setUuid(const QUuid &pUuid);
void setStrokesGroup(UBGraphicsStrokesGroup* group); void setStrokesGroup(UBGraphicsStrokesGroup* group);
UBGraphicsStrokesGroup* strokesGroup() const{return mpGroup;} UBGraphicsStrokesGroup* strokesGroup() const{return mpGroup;}
void setColor(const QColor& color); void setColor(const QColor& color);

Loading…
Cancel
Save