Finished import cff and export to cff.

Import ubz works bad with groups.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent 82259683c4
commit 2666115b19
  1. 12
      plugins/cffadaptor/src/UBCFFAdaptor.cpp
  2. 7
      plugins/cffadaptor/src/UBCFFConstants.h
  3. 5
      src/adaptors/UBCFFSubsetAdaptor.cpp
  4. 96
      src/adaptors/UBSvgSubsetAdaptor.cpp
  5. 1
      src/domain/UBGraphicsScene.cpp
  6. 3
      src/domain/UBGraphicsScene.h

@ -1273,6 +1273,13 @@ bool UBCFFAdaptor::UBToCFFConverter::setCFFAttribute(const QString &attributeNam
{ {
setGeometryFromUBZ(ubzElement, svgElement); setGeometryFromUBZ(ubzElement, svgElement);
} }
else
if (attributeName.contains(aUBZUuid))
{
QString id = "{" +ubzElement.attribute(aUBZParent)+"}" + "{"+ubzElement.attribute(aUBZUuid)+"}";
svgElement.setAttribute(aID, id);
}
else else
if (attributeName.contains(aUBZHref)||attributeName.contains(aSrc)) if (attributeName.contains(aUBZHref)||attributeName.contains(aSrc))
{ {
@ -1822,7 +1829,10 @@ bool UBCFFAdaptor::UBToCFFConverter::parseUBZPolygon(const QDomElement &element,
if (0 < iwbElementPart.attributes().count()) if (0 < iwbElementPart.attributes().count())
{ {
QString id = QUuid::createUuid().toString(); QString id = svgElementPart.attribute(aUBZUuid);
if (id.isEmpty())
id = QUuid::createUuid().toString();
svgElementPart.setAttribute(aID, id); svgElementPart.setAttribute(aID, id);
iwbElementPart.setAttribute(aRef, id); iwbElementPart.setAttribute(aRef, id);

@ -68,6 +68,7 @@ const QString aBackground = "background";
const QString aCrossedBackground = "crossed-background"; const QString aCrossedBackground = "crossed-background";
const QString aUBZType = "type"; const QString aUBZType = "type";
const QString aUBZUuid = "uuid"; const QString aUBZUuid = "uuid";
const QString aUBZParent = "parent";
const QString aFill = "fill"; // IWB attribute contans color to fill const QString aFill = "fill"; // IWB attribute contans color to fill
const QString aID = "id"; // ID of any svg element can be placed in to iwb section const QString aID = "id"; // ID of any svg element can be placed in to iwb section
@ -335,8 +336,10 @@ stroke-lineshape-end \
const QString ubzElementAttributesToConvert(" \ const QString ubzElementAttributesToConvert(" \
xlink:href, \ xlink:href, \
src, \ src, \
transform \ transform, \
"); uuid \
"
);
// additional attributes. Have references in SVG section. // additional attributes. Have references in SVG section.
const QString svgElementAttributes(" \ const QString svgElementAttributes(" \

@ -379,9 +379,10 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolygon(const QDomElement &e
QUuid itemGroupUuid(element.attribute(aId).left(QUuid().toString().length()-1)); QUuid itemGroupUuid(element.attribute(aId).left(QUuid().toString().length()-1));
if (!itemUuid.isNull() && (itemGroupUuid!=itemUuid)) // reimported from UBZ if (!itemUuid.isNull() && (itemGroupUuid!=itemUuid)) // reimported from UBZ
{ {
UBGraphicsPolygonItem *graphicsPolygon = new UBGraphicsPolygonItem(polygon); UBGraphicsPolygonItem *graphicsPolygon = mCurrentScene->polygonToPolygonItem(polygon);
graphicsPolygon->setBrush(brush); graphicsPolygon->setBrush(brush);
//graphicsPolygon->setPen(pen);
QTransform transform; QTransform transform;
QString textTransform = element.attribute(aTransform); QString textTransform = element.attribute(aTransform);
@ -1131,7 +1132,7 @@ UBGraphicsGroupContainerItem *UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGro
{ {
if (uuid.size() > QUuid().toString().length()) // create stroke group if (uuid.size() > QUuid().toString().length()) // create stroke group
{ {
currentStrokeIdentifier = uuid.left(QUuid().toString().length()-1); currentStrokeIdentifier = uuid.left(QUuid().toString().length());
UBGraphicsPolygonItem *strokeByUuid = qgraphicsitem_cast<UBGraphicsPolygonItem *>(mCurrentScene->itemForUuid(QUuid(uuid.right(QUuid().toString().length())))); UBGraphicsPolygonItem *strokeByUuid = qgraphicsitem_cast<UBGraphicsPolygonItem *>(mCurrentScene->itemForUuid(QUuid(uuid.right(QUuid().toString().length()))));
if (strokeByUuid) if (strokeByUuid)

@ -555,6 +555,10 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
if (polygonItem) if (polygonItem)
{ {
mScene->addItem(polygonItem);
polygonItem->setUuid(uuidFromSvg);
if (annotationGroup) if (annotationGroup)
{ {
polygonItem->setStroke(annotationGroup); polygonItem->setStroke(annotationGroup);
@ -991,31 +995,42 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup() UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup()
{ {
UBGraphicsGroupContainerItem *result = new UBGraphicsGroupContainerItem(); UBGraphicsGroupContainerItem *group = new UBGraphicsGroupContainerItem();
QMultiMap<QString, UBGraphicsPolygonItem *> strokesGroupsContainer;
QList<QGraphicsItem *> groupContainer;
QString currentStrokeIdentifier;
QUuid groupUuid = QUuid(mXmlReader.attributes().value(aId).toString()); QUuid groupUuid = QUuid(mXmlReader.attributes().value(aId).toString());
mXmlReader.readNext(); mXmlReader.readNext();
while (!mXmlReader.atEnd()) { while (!mXmlReader.atEnd())
if (mXmlReader.isEndElement()) { {
mXmlReader.readNext(); if (mXmlReader.isStartElement())
result->setUuid(groupUuid); {
if (!result->childItems().count()) { if (mXmlReader.name() == tGroup)
delete result; {
result = 0;
}
break;
} else if (mXmlReader.isStartElement()) {
if (mXmlReader.name() == tGroup) {
qDebug() << "came across the group id is" << mXmlReader.attributes().value(aId); qDebug() << "came across the group id is" << mXmlReader.attributes().value(aId);
UBGraphicsGroupContainerItem *curGroup = readGroup(); UBGraphicsGroupContainerItem *curGroup = readGroup();
if (curGroup) { if (curGroup)
result->addToGroup(curGroup); group->addToGroup(curGroup);
} }
} else if (mXmlReader.name() == tElement) { else if (mXmlReader.name() == tElement)
{
QString id = mXmlReader.attributes().value(aId).toString();
QString itemId = id.right(QUuid().toString().size());
QString groupId = id.left(QUuid().toString().size());
QGraphicsItem *curItem = readElementFromGroup(); QGraphicsItem *curItem = readElementFromGroup();
if (curItem) {
result->addToGroup(curItem); UBGraphicsPolygonItem *curPolygon = qgraphicsitem_cast<UBGraphicsPolygonItem *>(curItem);
if (curPolygon && !groupId.isEmpty() && !itemId.isEmpty() && itemId != groupId)
{
strokesGroupsContainer.insert(groupId, curPolygon);
}
else // item
{
group->addToGroup(curItem);
} }
}else { }else {
mXmlReader.skipCurrentElement(); mXmlReader.skipCurrentElement();
@ -1025,7 +1040,47 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup()
} }
} }
return result;
foreach (QString key, strokesGroupsContainer.keys())
{
UBGraphicsStrokesGroup* pStrokesGroup = new UBGraphicsStrokesGroup();
UBGraphicsStroke *currentStroke = new UBGraphicsStroke();
foreach(UBGraphicsPolygonItem* poly, strokesGroupsContainer.values(key))
{
if (poly)
{
mScene->removeItem(poly);
mScene->removeItemFromDeletion(poly);
poly->setStrokesGroup(pStrokesGroup);
poly->setStroke(currentStroke);
pStrokesGroup->addToGroup(poly);
}
}
if (currentStroke->polygons().empty())
delete currentStroke;
if (pStrokesGroup->childItems().count())
mScene->addItem(pStrokesGroup);
else
delete pStrokesGroup;
if (pStrokesGroup)
group->addToGroup(pStrokesGroup);
}
foreach(QGraphicsItem* item, groupContainer)
group->addToGroup(item);
if (group->childItems().count())
{
mScene->addItem(group);
if (!groupContainer.count())
{
group->destroy(false);
}
}
return group;
} }
void UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroupRoot() void UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroupRoot()
@ -1053,8 +1108,9 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroupRoot()
QGraphicsItem *UBSvgSubsetAdaptor::UBSvgSubsetReader::readElementFromGroup() QGraphicsItem *UBSvgSubsetAdaptor::UBSvgSubsetReader::readElementFromGroup()
{ {
QGraphicsItem *result = 0; QGraphicsItem *result = 0;
QString id = mXmlReader.attributes().value(aId).toString();
result = mScene->itemForUuid(QUuid(mXmlReader.attributes().value(aId).toString())); QString uuid = id.right(QUuid().toString().size());
result = mScene->itemForUuid(QUuid(uuid));
mXmlReader.skipCurrentElement(); mXmlReader.skipCurrentElement();
mXmlReader.readNext(); mXmlReader.readNext();

@ -1713,6 +1713,7 @@ QRectF UBGraphicsScene::normalizedSceneRect(qreal ratio)
QGraphicsItem *UBGraphicsScene::itemForUuid(QUuid uuid) QGraphicsItem *UBGraphicsScene::itemForUuid(QUuid uuid)
{ {
QGraphicsItem *result = 0; QGraphicsItem *result = 0;
QString ui = uuid.toString();
//simple search before implementing container for fast access //simple search before implementing container for fast access
foreach (QGraphicsItem *item, items()) { foreach (QGraphicsItem *item, items()) {

@ -302,6 +302,8 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
static QUuid getPersonalUuid(QGraphicsItem *item); static QUuid getPersonalUuid(QGraphicsItem *item);
UBGraphicsPolygonItem* polygonToPolygonItem(const QPolygonF pPolygon);
public slots: public slots:
void initStroke(); void initStroke();
void hideEraser(); void hideEraser();
@ -338,7 +340,6 @@ public slots:
UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth); UBGraphicsPolygonItem* lineToPolygonItem(const QLineF& pLine, const qreal& pWidth);
UBGraphicsPolygonItem* arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth); UBGraphicsPolygonItem* arcToPolygonItem(const QLineF& pStartRadius, qreal pSpanAngle, qreal pWidth);
UBGraphicsPolygonItem* polygonToPolygonItem(const QPolygonF pPolygon);
void initPolygonItem(UBGraphicsPolygonItem*); void initPolygonItem(UBGraphicsPolygonItem*);

Loading…
Cancel
Save