From ae900677bd98b35df30ac7f4b4346f53e33f9a79 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Fri, 28 Sep 2012 13:55:00 +0300 Subject: [PATCH] Reimported cff reads fine. Groups reads fine for strokes. --- src/adaptors/UBCFFSubsetAdaptor.cpp | 18 ++++++++++++------ src/adaptors/UBSvgSubsetAdaptor.cpp | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index 7b17f0b0..e0584b4d 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -249,6 +249,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem painter.end(); UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); + svgItem->setUuid(QUuid::createUuid()); QTransform transform; QString textTransform = element.attribute(aTransform); @@ -299,6 +300,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e painter.end(); UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); + svgItem->setUuid(QUuid::createUuid()); QTransform transform; QString textTransform = element.attribute(aTransform); @@ -382,7 +384,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolygon(const QDomElement &e UBGraphicsPolygonItem *graphicsPolygon = mCurrentScene->polygonToPolygonItem(polygon); graphicsPolygon->setBrush(brush); - //graphicsPolygon->setPen(pen); QTransform transform; QString textTransform = element.attribute(aTransform); @@ -414,7 +415,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolygon(const QDomElement &e UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); QTransform transform; QString textTransform = element.attribute(aTransform); - + svgItem->setUuid(QUuid::createUuid()); svgItem->resetTransform(); if (!textTransform.isNull()) { transform = transformFromString(textTransform, svgItem); @@ -524,6 +525,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolyline(const QDomElement & //add resulting svg file to scene UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); + svgItem->setUuid(QUuid::createUuid()); QTransform transform; QString textTransform = element.attribute(aTransform); @@ -1132,7 +1134,7 @@ UBGraphicsGroupContainerItem *UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGro { if (uuid.size() > QUuid().toString().length()) // create stroke group { - currentStrokeIdentifier = uuid.left(QUuid().toString().length()); + currentStrokeIdentifier = uuid.left(QUuid().toString().length()-1); UBGraphicsPolygonItem *strokeByUuid = qgraphicsitem_cast(mCurrentScene->itemForUuid(QUuid(uuid.right(QUuid().toString().length())))); if (strokeByUuid) @@ -1147,7 +1149,7 @@ UBGraphicsGroupContainerItem *UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGro - foreach (QString key, strokesGroupsContainer.keys()) + foreach (QString key, strokesGroupsContainer.keys().toSet()) { UBGraphicsStrokesGroup* pStrokesGroup = new UBGraphicsStrokesGroup(); UBGraphicsStroke *currentStroke = new UBGraphicsStroke(); @@ -1164,13 +1166,17 @@ UBGraphicsGroupContainerItem *UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGro } if (currentStroke->polygons().empty()) delete currentStroke; + if (pStrokesGroup->childItems().count()) mCurrentScene->addItem(pStrokesGroup); else delete pStrokesGroup; if (pStrokesGroup) - group->addToGroup(pStrokesGroup); + { + QGraphicsItem *strokeGroup = qgraphicsitem_cast(pStrokesGroup); + groupContainer.append(strokeGroup); + } } foreach(QGraphicsItem* item, groupContainer) @@ -1180,7 +1186,7 @@ UBGraphicsGroupContainerItem *UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGro { mCurrentScene->addItem(group); - if (!groupContainer.count()) + if (1 == group->childItems().count()) { group->destroy(false); } diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 3eaf2335..8f0efe67 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1005,7 +1005,10 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup() mXmlReader.readNext(); while (!mXmlReader.atEnd()) { - if (mXmlReader.isStartElement()) + if (mXmlReader.isEndElement()) { + mXmlReader.readNext(); + break; + } else if (mXmlReader.isStartElement()) { if (mXmlReader.name() == tGroup) { @@ -1030,7 +1033,7 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup() } else // item { - group->addToGroup(curItem); + groupContainer.append(curItem); } }else { mXmlReader.skipCurrentElement(); @@ -1040,8 +1043,7 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup() } } - - foreach (QString key, strokesGroupsContainer.keys()) + foreach (QString key, strokesGroupsContainer.keys().toSet()) { UBGraphicsStrokesGroup* pStrokesGroup = new UBGraphicsStrokesGroup(); UBGraphicsStroke *currentStroke = new UBGraphicsStroke(); @@ -1058,13 +1060,17 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup() } if (currentStroke->polygons().empty()) delete currentStroke; + if (pStrokesGroup->childItems().count()) mScene->addItem(pStrokesGroup); else delete pStrokesGroup; if (pStrokesGroup) - group->addToGroup(pStrokesGroup); + { + QGraphicsItem *strokeGroup = qgraphicsitem_cast(pStrokesGroup); + groupContainer.append(strokeGroup); + } } foreach(QGraphicsItem* item, groupContainer) @@ -1074,12 +1080,11 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup() { mScene->addItem(group); - if (!groupContainer.count()) + if (1 == group->childItems().count()) { group->destroy(false); } } - return group; }