fixing previous bad commit

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent 84addd4dc3
commit 66f8d530d3
  1. 227
      src/adaptors/UBSvgSubsetAdaptor.cpp

@ -391,8 +391,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsStroke* annotationGroup = 0; UBGraphicsStroke* annotationGroup = 0;
UBGraphicsStrokesGroup* strokesGroup = 0; UBGraphicsStrokesGroup* strokesGroup = 0;
QMap<QString,UBGraphicsStrokesGroup*> strokesList;
while (!mXmlReader.atEnd()) while (!mXmlReader.atEnd())
{ {
mXmlReader.readNext(); mXmlReader.readNext();
@ -562,8 +560,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
polygonItem = polygonItemFromLineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black); polygonItem = polygonItemFromLineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black);
} }
if (polygonItem) if (polygonItem)
{ {
mScene->addItem(polygonItem);
polygonItem->setUuid(uuidFromSvg); polygonItem->setUuid(uuidFromSvg);
if (annotationGroup) if (annotationGroup)
@ -580,19 +581,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
QString parentId = mXmlReader.attributes().value(mNamespaceUri, "parent").toString();
Q_ASSERT(!parentId.isEmpty());
UBGraphicsStrokesGroup* group;
if(!strokesList.contains(parentId)){
group = new UBGraphicsStrokesGroup();
strokesList.insert(parentId,group);
}
else
group = strokesList.value(parentId);
polygonItem->show(); polygonItem->show();
group->addToGroup(polygonItem);
} }
} }
else if (mXmlReader.name() == "polyline") else if (mXmlReader.name() == "polyline")
@ -615,17 +604,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
} }
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
QString parentId = mXmlReader.attributes().value(mNamespaceUri, "parent").toString();
Q_ASSERT(!parentId.isEmpty());
UBGraphicsStrokesGroup* group;
if(!strokesList.contains(parentId)){
group = new UBGraphicsStrokesGroup();
strokesList.insert(parentId,group);
}
else
group = strokesList.value(parentId);
polygonItem->show(); polygonItem->show();
} }
} }
@ -883,6 +861,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsAppleWidgetItem* appleWidgetItem = graphicsAppleWidgetFromSvg(); UBGraphicsAppleWidgetItem* appleWidgetItem = graphicsAppleWidgetFromSvg();
if (appleWidgetItem) if (appleWidgetItem)
{ {
// appleWidgetItem->setFlag(QGraphicsItem::ItemIsMovable, true);
appleWidgetItem->setFlag(QGraphicsItem::ItemIsSelectable, true); appleWidgetItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
appleWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); appleWidgetItem->resize(foreignObjectWidth, foreignObjectHeight);
@ -978,12 +957,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
} else if (mXmlReader.name() == tGroups) { } else if (mXmlReader.name() == tGroups) {
//considering groups section at the end of the document //considering groups section at the end of the document
QMapIterator<QString, UBGraphicsStrokesGroup*> iterator(strokesList);
while (iterator.hasNext()) {
iterator.next();
mScene->addItem(iterator.value());
}
readGroupRoot(); readGroupRoot();
} }
else else
@ -997,6 +970,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
if(strokesGroup && mScene){ if(strokesGroup && mScene){
mScene->addItem(strokesGroup); mScene->addItem(strokesGroup);
//graphicsItemFromSvg(strokesGroup);
} }
if (annotationGroup) if (annotationGroup)
@ -1011,8 +985,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
} }
} }
qDebug() << "Number of detected strokes: " << strokesList.count();
if (mXmlReader.hasError()) if (mXmlReader.hasError())
{ {
qWarning() << "error parsing Sankore file " << mXmlReader.errorString(); qWarning() << "error parsing Sankore file " << mXmlReader.errorString();
@ -1036,7 +1008,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup() UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup()
{ {
UBGraphicsGroupContainerItem *group = new UBGraphicsGroupContainerItem(); UBGraphicsGroupContainerItem *group = new UBGraphicsGroupContainerItem();
// QMultiMap<QString, UBGraphicsPolygonItem *> strokesGroupsContainer; QMultiMap<QString, UBGraphicsPolygonItem *> strokesGroupsContainer;
QList<QGraphicsItem *> groupContainer; QList<QGraphicsItem *> groupContainer;
mXmlReader.readNext(); mXmlReader.readNext();
@ -1045,9 +1017,10 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup()
if (mXmlReader.isEndElement()) { if (mXmlReader.isEndElement()) {
mXmlReader.readNext(); mXmlReader.readNext();
break; break;
} } else if (mXmlReader.isStartElement())
else if (mXmlReader.isStartElement()) { {
if (mXmlReader.name() == tGroup) { 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)
@ -1055,69 +1028,67 @@ UBGraphicsGroupContainerItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroup()
else else
qDebug() << "this is an error"; qDebug() << "this is an error";
} }
else if (mXmlReader.name() == tElement) { else if (mXmlReader.name() == tElement)
{
QString id = mXmlReader.attributes().value(aId).toString(); QString id = mXmlReader.attributes().value(aId).toString();
// QString itemId = id.right(QUuid().toString().size()); QString itemId = id.right(QUuid().toString().size());
// QString groupId = id.left(QUuid().toString().size()); QString groupId = id.left(QUuid().toString().size());
QGraphicsItem *curItem = readElementFromGroup(); QGraphicsItem *curItem = readElementFromGroup();
// UBGraphicsPolygonItem *curPolygon = qgraphicsitem_cast<UBGraphicsPolygonItem *>(curItem); UBGraphicsPolygonItem *curPolygon = qgraphicsitem_cast<UBGraphicsPolygonItem *>(curItem);
//
// if (curPolygon && !groupId.isEmpty() && !itemId.isEmpty() && itemId != groupId) {
// strokesGroupsContainer.insert(groupId, curPolygon);
// }
// else {// item
// Explanation: the second condition discriminate the old storage version that should if (curPolygon && !groupId.isEmpty() && !itemId.isEmpty() && itemId != groupId)
// not be interpreted anymore {
if(curItem && id.count("{") < 2) strokesGroupsContainer.insert(groupId, curPolygon);
groupContainer.append(curItem); }
else else // item
qDebug() << "this is an error"; {
// } if(curItem)
} groupContainer.append(curItem);
else { else
qDebug() << "this is an error";
}
}else {
mXmlReader.skipCurrentElement(); mXmlReader.skipCurrentElement();
} }
} } else {
else {
mXmlReader.readNext(); mXmlReader.readNext();
} }
} }
// foreach (QString key, strokesGroupsContainer.keys().toSet()) foreach (QString key, strokesGroupsContainer.keys().toSet())
// { {
// UBGraphicsStrokesGroup* pStrokesGroup = new UBGraphicsStrokesGroup(); UBGraphicsStrokesGroup* pStrokesGroup = new UBGraphicsStrokesGroup();
// UBGraphicsStroke *currentStroke = new UBGraphicsStroke(); UBGraphicsStroke *currentStroke = new UBGraphicsStroke();
// foreach(UBGraphicsPolygonItem* poly, strokesGroupsContainer.values(key)) foreach(UBGraphicsPolygonItem* poly, strokesGroupsContainer.values(key))
// { {
// if (poly) if (poly)
// { {
// mScene->removeItem(poly); mScene->removeItem(poly);
// mScene->removeItemFromDeletion(poly); mScene->removeItemFromDeletion(poly);
// poly->setStrokesGroup(pStrokesGroup); poly->setStrokesGroup(pStrokesGroup);
// poly->setStroke(currentStroke); poly->setStroke(currentStroke);
// pStrokesGroup->addToGroup(poly); pStrokesGroup->addToGroup(poly);
// } }
// } }
// if (currentStroke->polygons().empty()) if (currentStroke->polygons().empty())
// delete currentStroke; delete currentStroke;
// if (pStrokesGroup->childItems().count()) if (pStrokesGroup->childItems().count())
// mScene->addItem(pStrokesGroup); mScene->addItem(pStrokesGroup);
// else else
// delete pStrokesGroup; delete pStrokesGroup;
// if (pStrokesGroup) if (pStrokesGroup)
// { {
// QGraphicsItem *strokeGroup = qgraphicsitem_cast<QGraphicsItem *>(pStrokesGroup); QGraphicsItem *strokeGroup = qgraphicsitem_cast<QGraphicsItem *>(pStrokesGroup);
// if(strokeGroup) if(strokeGroup)
// groupContainer.append(strokeGroup); groupContainer.append(strokeGroup);
// else else
// qDebug() << "this is an error"; qDebug() << "this is an error";
// } }
// } }
foreach(QGraphicsItem* item, groupContainer) foreach(QGraphicsItem* item, groupContainer)
group->addToGroup(item); group->addToGroup(item);
@ -1141,19 +1112,16 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroupRoot()
if (mXmlReader.isEndElement()) { if (mXmlReader.isEndElement()) {
mXmlReader.readNext(); mXmlReader.readNext();
break; break;
} } else if (mXmlReader.isStartElement()) {
else if (mXmlReader.isStartElement()) {
if (mXmlReader.name() == tGroup) { if (mXmlReader.name() == tGroup) {
UBGraphicsGroupContainerItem *curGroup = readGroup(); UBGraphicsGroupContainerItem *curGroup = readGroup();
if (curGroup) { if (curGroup) {
mScene->addGroup(curGroup); mScene->addGroup(curGroup);
} }
} }else {
else {
mXmlReader.skipCurrentElement(); mXmlReader.skipCurrentElement();
} }
} } else {
else {
mXmlReader.readNext(); mXmlReader.readNext();
} }
} }
@ -1166,9 +1134,8 @@ QGraphicsItem *UBSvgSubsetAdaptor::UBSvgSubsetReader::readElementFromGroup()
QString uuid = id.right(QUuid().toString().size()); QString uuid = id.right(QUuid().toString().size());
result = mScene->itemForUuid(QUuid(uuid)); result = mScene->itemForUuid(QUuid(uuid));
Q_ASSERT(result); if(!result)
// if(!result) qDebug() << "uuid " << uuid;
// qDebug() << "uuid " << uuid;
mXmlReader.skipCurrentElement(); mXmlReader.skipCurrentElement();
mXmlReader.readNext(); mXmlReader.readNext();
@ -1272,15 +1239,38 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
UBGraphicsStrokesGroup* strokesGroupItem = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item); UBGraphicsStrokesGroup* strokesGroupItem = qgraphicsitem_cast<UBGraphicsStrokesGroup*>(item);
if(strokesGroupItem && strokesGroupItem->isVisible()){ if(strokesGroupItem && strokesGroupItem->isVisible()){
QDomElement newGroupElement;
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();
// if (!matrix.isIdentity()){
// mXmlWriter.writeAttribute("transform", toSvgTransform(matrix));
// }
// 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
} }
// Is the item a polygon? // Is the item a polygon?
@ -1564,16 +1554,14 @@ 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) {
// else if (item->type() == UBGraphicsStrokesGroup::Type) { foreach (QGraphicsItem *polygonItem, item->childItems()) {
// foreach (QGraphicsItem *polygonItem, item->childItems()) { QDomElement curPolygonElement = groupDomDocument->createElement(tElement);
// QDomElement curPolygonElement = groupDomDocument->createElement(tElement); curPolygonElement.setAttribute(aId, tmpUuid.toString()
// curPolygonElement.setAttribute(aId, tmpUuid.toString() + UBGraphicsItem::getOwnUuid(polygonItem).toString());
// + UBGraphicsItem::getOwnUuid(polygonItem).toString()); curGroupElement.appendChild(curPolygonElement);
// curGroupElement.appendChild(curPolygonElement); }
// } } else {
// }
else {
QDomElement curSubElement = groupDomDocument->createElement(tElement); QDomElement curSubElement = groupDomDocument->createElement(tElement);
curSubElement.setAttribute(aId, tmpUuid); curSubElement.setAttribute(aId, tmpUuid);
@ -1584,6 +1572,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");

Loading…
Cancel
Save