From 33c6e11732c94351e374217ce491a40b8fe2efb1 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 15 May 2013 09:46:49 +0200 Subject: [PATCH] some storage rework --- src/adaptors/UBSvgSubsetAdaptor.cpp | 125 +++++++--------------------- src/domain/UBGraphicsScene.cpp | 17 ++-- 2 files changed, 43 insertions(+), 99 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 435b6373..f61c918f 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -443,9 +443,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() QStringRef svgSceneUuid = mXmlReader.attributes().value(mNamespaceUri, "uuid"); if (!svgSceneUuid.isNull()) - { mScene->setUuid(QUuid(svgSceneUuid.toString())); - } // introduced in UB 4.0 @@ -475,9 +473,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() QStringRef pageDpi = mXmlReader.attributes().value("pageDpi"); if (!pageDpi.isNull()) - { UBSettings::settings()->pageDpi->set(pageDpi.toString()); - } bool darkBackground = false; bool crossedBackground = false; @@ -562,7 +558,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() { polygonItem->setUuid(uuidFromSvg); - polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); UBGraphicsStrokesGroup* group; @@ -589,8 +584,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() } else if (mXmlReader.name() == "polyline") { - QList polygonItems - = polygonItemsFromPolylineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black); + QList polygonItems = polygonItemsFromPolylineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black); QString parentId = QUuid::createUuid().toString(); @@ -639,17 +633,13 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() UBGraphicsPixmapItem* pixmapItem = pixmapItemFromSvg(); if (pixmapItem) { + UBGraphicsItem::assignZValue(pixmapItem, zFromSvg); + pixmapItem->setUuid(uuidFromSvg); pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); mScene->addItem(pixmapItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(pixmapItem, zFromSvg); - - if (!uuidFromSvg.isNull()) - pixmapItem->setUuid(uuidFromSvg); - if (isBackground) mScene->setAsBackgroundObject(pixmapItem); @@ -659,17 +649,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() else if (href.contains("svg")) { UBGraphicsSvgItem* svgItem = svgItemFromSvg(); - if (svgItem) { + UBGraphicsItem::assignZValue(svgItem, zFromSvg); + svgItem->setUuid(uuidFromSvg); svgItem->setFlag(QGraphicsItem::ItemIsMovable, true); svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true); mScene->addItem(svgItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(svgItem, zFromSvg); - if (isBackground) mScene->setAsBackgroundObject(svgItem); @@ -685,20 +673,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() else if (mXmlReader.name() == "audio") { UBGraphicsMediaItem* audioItem = audioItemFromSvg(); - if (audioItem) { + UBGraphicsItem::assignZValue(audioItem, zFromSvg); + audioItem->setUuid(uuidFromSvg); audioItem->setFlag(QGraphicsItem::ItemIsMovable, true); audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true); mScene->addItem(audioItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(audioItem, zFromSvg); - - if (!uuidFromSvg.isNull()) - audioItem->setUuid(uuidFromSvg); - audioItem->show(); //force start to load the video and display the first frame @@ -709,20 +692,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() else if (mXmlReader.name() == "video") { UBGraphicsMediaItem* videoItem = videoItemFromSvg(); - if (videoItem) { + UBGraphicsItem::assignZValue(videoItem, zFromSvg); + videoItem->setUuid(uuidFromSvg); videoItem->setFlag(QGraphicsItem::ItemIsMovable, true); videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); mScene->addItem(videoItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(videoItem, zFromSvg); - - if (!uuidFromSvg.isNull()) - videoItem->setUuid(uuidFromSvg); - videoItem->show(); //force start to load the video and display the first frame @@ -733,93 +711,73 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() else if (mXmlReader.name() == "text")//This is for backward compatibility with proto text field prior to version 4.3 { UBGraphicsTextItem* textItem = textItemFromSvg(); - if (textItem) { + UBGraphicsItem::assignZValue(textItem, zFromSvg); + textItem->setUuid(uuidFromSvg); textItem->setFlag(QGraphicsItem::ItemIsMovable, true); textItem->setFlag(QGraphicsItem::ItemIsSelectable, true); mScene->addItem(textItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(textItem, zFromSvg); - - if (!uuidFromSvg.isNull()) - textItem->setUuid(uuidFromSvg); - textItem->show(); } } else if (mXmlReader.name() == "curtain") { UBGraphicsCurtainItem* mask = curtainItemFromSvg(); - if (mask) { + UBGraphicsItem::assignZValue(mask, zFromSvg); + mask->setUuid(uuidFromSvg); mScene->addItem(mask); mScene->registerTool(mask); - - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(mask, zFromSvg); - - if (!uuidFromSvg.isNull()) - mask->setUuid(uuidFromSvg); } } else if (mXmlReader.name() == "ruler") { - QString ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString(); UBGraphicsRuler *ruler = rulerFromSvg(); - - ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString(); if (ruler) { + UBGraphicsItem::assignZValue(ruler, zFromSvg); + ruler->setUuid(uuidFromSvg); mScene->addItem(ruler); mScene->registerTool(ruler); - - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(ruler, zFromSvg); } } else if (mXmlReader.name() == "compass") { UBGraphicsCompass *compass = compassFromSvg(); - if (compass) { + UBGraphicsItem::assignZValue(compass, zFromSvg); + compass->setUuid(uuidFromSvg); mScene->addItem(compass); mScene->registerTool(compass); - - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(compass, zFromSvg); } } else if (mXmlReader.name() == "protractor") { UBGraphicsProtractor *protractor = protractorFromSvg(); - if (protractor) { + UBGraphicsItem::assignZValue(protractor, zFromSvg); + protractor->setUuid(uuidFromSvg); mScene->addItem(protractor); mScene->registerTool(protractor); - - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(protractor, zFromSvg); } } else if (mXmlReader.name() == "triangle") { UBGraphicsTriangle *triangle = triangleFromSvg(); - if (triangle) { + UBGraphicsItem::assignZValue(triangle, zFromSvg); + triangle->setUuid(uuidFromSvg); mScene->addItem(triangle); mScene->registerTool(triangle); - - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(triangle, zFromSvg); } } else if (mXmlReader.name() == "cache") @@ -827,12 +785,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() UBGraphicsCache* cache = cacheFromSvg(); if(cache) { + UBGraphicsItem::assignZValue(cache, zFromSvg); + cache->setUuid(uuidFromSvg); mScene->addItem(cache); mScene->registerTool(cache); UBApplication::boardController->notifyCache(true); - - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(cache, zFromSvg); } } else if (mXmlReader.name() == "foreignObject") @@ -850,6 +807,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() UBGraphicsPDFItem* pdfItem = pdfItemFromPDF(); if (pdfItem) { + UBGraphicsItem::assignZValue(pdfItem, zFromSvg); + pdfItem->setUuid(uuidFromSvg); QDesktopWidget* desktop = UBApplication::desktop(); qreal currentDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; qreal pdfScale = UBSettings::settings()->pageDpi->get().toReal()/currentDpi; @@ -859,9 +818,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() mScene->addItem(pdfItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(pdfItem, zFromSvg); - if (isBackground) mScene->setAsBackgroundObject(pdfItem); @@ -875,18 +831,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() UBGraphicsAppleWidgetItem* appleWidgetItem = graphicsAppleWidgetFromSvg(); if (appleWidgetItem) { + UBGraphicsItem::assignZValue(appleWidgetItem, zFromSvg); + appleWidgetItem->setUuid(uuidFromSvg); + appleWidgetItem->setFlag(QGraphicsItem::ItemIsSelectable, true); appleWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); mScene->addItem(appleWidgetItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(appleWidgetItem, zFromSvg); - - if (!uuidFromSvg.isNull()) - appleWidgetItem->setUuid(uuidFromSvg); - appleWidgetItem->show(); currentWidget = appleWidgetItem; @@ -895,21 +848,16 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() else if (src.contains(".wgt")) { UBGraphicsW3CWidgetItem* w3cWidgetItem = graphicsW3CWidgetFromSvg(); - if (w3cWidgetItem) { + UBGraphicsItem::assignZValue(w3cWidgetItem, zFromSvg); + w3cWidgetItem->setUuid(uuidFromSvg); w3cWidgetItem->setFlag(QGraphicsItem::ItemIsSelectable, true); w3cWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); mScene->addItem(w3cWidgetItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(w3cWidgetItem, zFromSvg); - - if (!uuidFromSvg.isNull()) - w3cWidgetItem->setUuid(uuidFromSvg); - w3cWidgetItem->show(); currentWidget = w3cWidgetItem; @@ -918,7 +866,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() else if (type == "text") { UBGraphicsTextItem* textItem = textItemFromSvg(); - UBGraphicsTextItemDelegate *textDelegate = 0; if (textItem) @@ -934,17 +881,13 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() if (textItem) { + UBGraphicsItem::assignZValue(textItem, zFromSvg); + textItem->setUuid(uuidFromSvg); textItem->setFlag(QGraphicsItem::ItemIsMovable, true); textItem->setFlag(QGraphicsItem::ItemIsSelectable, true); mScene->addItem(textItem); - if (zFromSvg != UBZLayerController::errorNum()) - UBGraphicsItem::assignZValue(textItem, zFromSvg); - - if (!uuidFromSvg.isNull()) - textItem->setUuid(uuidFromSvg); - textItem->show(); } } @@ -994,13 +937,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() qDebug() << "Number of detected strokes: " << mStrokesList.count(); QHashIterator iterator(mStrokesList); - qreal zValue = 0; while (iterator.hasNext()) { iterator.next(); - zValue = iterator.value()->zValue(); - qDebug() << "Number of polygons : " << (int)(((UBGraphicsStrokesGroup*)iterator.value())->childItems().count()); mScene->addItem(iterator.value()); - iterator.value()->setZValue(zValue); } if (mScene) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index d6d90363..7b973e30 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -73,6 +73,9 @@ #include "core/memcheck.h" + +#define DEFAULT_Z_VALUE 0.0 + qreal UBZLayerController::errorNumber = -20000001.0; UBZLayerController::UBZLayerController(QGraphicsScene *scene) : @@ -81,8 +84,9 @@ UBZLayerController::UBZLayerController(QGraphicsScene *scene) : { scopeMap.insert(itemLayerType::NoLayer, ItemLayerTypeData( errorNumber, errorNumber)); scopeMap.insert(itemLayerType::BackgroundItem, ItemLayerTypeData(-1000000.0, -1000000.0 )); - scopeMap.insert(itemLayerType::ObjectItem, ItemLayerTypeData(-1000000.0, 0.0 )); - scopeMap.insert(itemLayerType::DrawingItem, ItemLayerTypeData( 0.0, 1000000.0 )); + // DEFAULT_Z_VALUE isn't used because it allows to easily identify new objects + scopeMap.insert(itemLayerType::ObjectItem, ItemLayerTypeData(-1000000.0, DEFAULT_Z_VALUE - 1.0)); + scopeMap.insert(itemLayerType::DrawingItem, ItemLayerTypeData( DEFAULT_Z_VALUE + 1.0, 1000000.0 )); scopeMap.insert(itemLayerType::ToolItem, ItemLayerTypeData( 1000000.0, 1000100.0 )); scopeMap.insert(itemLayerType::CppTool, ItemLayerTypeData( 1000100.0, 1000200.0 )); scopeMap.insert(itemLayerType::Curtain, ItemLayerTypeData( 1000200.0, 1001000.0 )); @@ -1618,10 +1622,11 @@ void UBGraphicsScene::addItem(QGraphicsItem* item) { UBCoreGraphicsScene::addItem(item); - qDebug() << item->zValue(); - - qreal zvalue = mZLayerController->generateZLevel(item); - UBGraphicsItem::assignZValue(item, zvalue); + // the default z value is already set. This is the case when a svg file is read + if(item->zValue() == DEFAULT_Z_VALUE || item->zValue() == UBZLayerController::errorNum()){ + qreal zvalue = mZLayerController->generateZLevel(item); + UBGraphicsItem::assignZValue(item, zvalue); + } if (!mTools.contains(item)) ++mItemCount;