some storage rework

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent a3881ce570
commit 33c6e11732
  1. 125
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 17
      src/domain/UBGraphicsScene.cpp

@ -443,9 +443,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
QStringRef svgSceneUuid = mXmlReader.attributes().value(mNamespaceUri, "uuid"); QStringRef svgSceneUuid = mXmlReader.attributes().value(mNamespaceUri, "uuid");
if (!svgSceneUuid.isNull()) if (!svgSceneUuid.isNull())
{
mScene->setUuid(QUuid(svgSceneUuid.toString())); mScene->setUuid(QUuid(svgSceneUuid.toString()));
}
// introduced in UB 4.0 // introduced in UB 4.0
@ -475,9 +473,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
QStringRef pageDpi = mXmlReader.attributes().value("pageDpi"); QStringRef pageDpi = mXmlReader.attributes().value("pageDpi");
if (!pageDpi.isNull()) if (!pageDpi.isNull())
{
UBSettings::settings()->pageDpi->set(pageDpi.toString()); UBSettings::settings()->pageDpi->set(pageDpi.toString());
}
bool darkBackground = false; bool darkBackground = false;
bool crossedBackground = false; bool crossedBackground = false;
@ -562,7 +558,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
{ {
polygonItem->setUuid(uuidFromSvg); polygonItem->setUuid(uuidFromSvg);
polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); polygonItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
UBGraphicsStrokesGroup* group; UBGraphicsStrokesGroup* group;
@ -589,8 +584,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
} }
else if (mXmlReader.name() == "polyline") else if (mXmlReader.name() == "polyline")
{ {
QList<UBGraphicsPolygonItem*> polygonItems QList<UBGraphicsPolygonItem*> polygonItems = polygonItemsFromPolylineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black);
= polygonItemsFromPolylineSvg(mScene->isDarkBackground() ? Qt::white : Qt::black);
QString parentId = QUuid::createUuid().toString(); QString parentId = QUuid::createUuid().toString();
@ -639,17 +633,13 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsPixmapItem* pixmapItem = pixmapItemFromSvg(); UBGraphicsPixmapItem* pixmapItem = pixmapItemFromSvg();
if (pixmapItem) if (pixmapItem)
{ {
UBGraphicsItem::assignZValue(pixmapItem, zFromSvg);
pixmapItem->setUuid(uuidFromSvg);
pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsMovable, true);
pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true); pixmapItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
mScene->addItem(pixmapItem); mScene->addItem(pixmapItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(pixmapItem, zFromSvg);
if (!uuidFromSvg.isNull())
pixmapItem->setUuid(uuidFromSvg);
if (isBackground) if (isBackground)
mScene->setAsBackgroundObject(pixmapItem); mScene->setAsBackgroundObject(pixmapItem);
@ -659,17 +649,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if (href.contains("svg")) else if (href.contains("svg"))
{ {
UBGraphicsSvgItem* svgItem = svgItemFromSvg(); UBGraphicsSvgItem* svgItem = svgItemFromSvg();
if (svgItem) if (svgItem)
{ {
UBGraphicsItem::assignZValue(svgItem, zFromSvg);
svgItem->setUuid(uuidFromSvg);
svgItem->setFlag(QGraphicsItem::ItemIsMovable, true); svgItem->setFlag(QGraphicsItem::ItemIsMovable, true);
svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true); svgItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
mScene->addItem(svgItem); mScene->addItem(svgItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(svgItem, zFromSvg);
if (isBackground) if (isBackground)
mScene->setAsBackgroundObject(svgItem); mScene->setAsBackgroundObject(svgItem);
@ -685,20 +673,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if (mXmlReader.name() == "audio") else if (mXmlReader.name() == "audio")
{ {
UBGraphicsMediaItem* audioItem = audioItemFromSvg(); UBGraphicsMediaItem* audioItem = audioItemFromSvg();
if (audioItem) if (audioItem)
{ {
UBGraphicsItem::assignZValue(audioItem, zFromSvg);
audioItem->setUuid(uuidFromSvg);
audioItem->setFlag(QGraphicsItem::ItemIsMovable, true); audioItem->setFlag(QGraphicsItem::ItemIsMovable, true);
audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true); audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
mScene->addItem(audioItem); mScene->addItem(audioItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(audioItem, zFromSvg);
if (!uuidFromSvg.isNull())
audioItem->setUuid(uuidFromSvg);
audioItem->show(); audioItem->show();
//force start to load the video and display the first frame //force start to load the video and display the first frame
@ -709,20 +692,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if (mXmlReader.name() == "video") else if (mXmlReader.name() == "video")
{ {
UBGraphicsMediaItem* videoItem = videoItemFromSvg(); UBGraphicsMediaItem* videoItem = videoItemFromSvg();
if (videoItem) if (videoItem)
{ {
UBGraphicsItem::assignZValue(videoItem, zFromSvg);
videoItem->setUuid(uuidFromSvg);
videoItem->setFlag(QGraphicsItem::ItemIsMovable, true); videoItem->setFlag(QGraphicsItem::ItemIsMovable, true);
videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
mScene->addItem(videoItem); mScene->addItem(videoItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(videoItem, zFromSvg);
if (!uuidFromSvg.isNull())
videoItem->setUuid(uuidFromSvg);
videoItem->show(); videoItem->show();
//force start to load the video and display the first frame //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 else if (mXmlReader.name() == "text")//This is for backward compatibility with proto text field prior to version 4.3
{ {
UBGraphicsTextItem* textItem = textItemFromSvg(); UBGraphicsTextItem* textItem = textItemFromSvg();
if (textItem) if (textItem)
{ {
UBGraphicsItem::assignZValue(textItem, zFromSvg);
textItem->setUuid(uuidFromSvg);
textItem->setFlag(QGraphicsItem::ItemIsMovable, true); textItem->setFlag(QGraphicsItem::ItemIsMovable, true);
textItem->setFlag(QGraphicsItem::ItemIsSelectable, true); textItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
mScene->addItem(textItem); mScene->addItem(textItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(textItem, zFromSvg);
if (!uuidFromSvg.isNull())
textItem->setUuid(uuidFromSvg);
textItem->show(); textItem->show();
} }
} }
else if (mXmlReader.name() == "curtain") else if (mXmlReader.name() == "curtain")
{ {
UBGraphicsCurtainItem* mask = curtainItemFromSvg(); UBGraphicsCurtainItem* mask = curtainItemFromSvg();
if (mask) if (mask)
{ {
UBGraphicsItem::assignZValue(mask, zFromSvg);
mask->setUuid(uuidFromSvg);
mScene->addItem(mask); mScene->addItem(mask);
mScene->registerTool(mask); mScene->registerTool(mask);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(mask, zFromSvg);
if (!uuidFromSvg.isNull())
mask->setUuid(uuidFromSvg);
} }
} }
else if (mXmlReader.name() == "ruler") else if (mXmlReader.name() == "ruler")
{ {
QString ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString();
UBGraphicsRuler *ruler = rulerFromSvg(); UBGraphicsRuler *ruler = rulerFromSvg();
ubZValue = mXmlReader.attributes().value(mNamespaceUri, "z-value").toString();
if (ruler) if (ruler)
{ {
UBGraphicsItem::assignZValue(ruler, zFromSvg);
ruler->setUuid(uuidFromSvg);
mScene->addItem(ruler); mScene->addItem(ruler);
mScene->registerTool(ruler); mScene->registerTool(ruler);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(ruler, zFromSvg);
} }
} }
else if (mXmlReader.name() == "compass") else if (mXmlReader.name() == "compass")
{ {
UBGraphicsCompass *compass = compassFromSvg(); UBGraphicsCompass *compass = compassFromSvg();
if (compass) if (compass)
{ {
UBGraphicsItem::assignZValue(compass, zFromSvg);
compass->setUuid(uuidFromSvg);
mScene->addItem(compass); mScene->addItem(compass);
mScene->registerTool(compass); mScene->registerTool(compass);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(compass, zFromSvg);
} }
} }
else if (mXmlReader.name() == "protractor") else if (mXmlReader.name() == "protractor")
{ {
UBGraphicsProtractor *protractor = protractorFromSvg(); UBGraphicsProtractor *protractor = protractorFromSvg();
if (protractor) if (protractor)
{ {
UBGraphicsItem::assignZValue(protractor, zFromSvg);
protractor->setUuid(uuidFromSvg);
mScene->addItem(protractor); mScene->addItem(protractor);
mScene->registerTool(protractor); mScene->registerTool(protractor);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(protractor, zFromSvg);
} }
} }
else if (mXmlReader.name() == "triangle") else if (mXmlReader.name() == "triangle")
{ {
UBGraphicsTriangle *triangle = triangleFromSvg(); UBGraphicsTriangle *triangle = triangleFromSvg();
if (triangle) if (triangle)
{ {
UBGraphicsItem::assignZValue(triangle, zFromSvg);
triangle->setUuid(uuidFromSvg);
mScene->addItem(triangle); mScene->addItem(triangle);
mScene->registerTool(triangle); mScene->registerTool(triangle);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(triangle, zFromSvg);
} }
} }
else if (mXmlReader.name() == "cache") else if (mXmlReader.name() == "cache")
@ -827,12 +785,11 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsCache* cache = cacheFromSvg(); UBGraphicsCache* cache = cacheFromSvg();
if(cache) if(cache)
{ {
UBGraphicsItem::assignZValue(cache, zFromSvg);
cache->setUuid(uuidFromSvg);
mScene->addItem(cache); mScene->addItem(cache);
mScene->registerTool(cache); mScene->registerTool(cache);
UBApplication::boardController->notifyCache(true); UBApplication::boardController->notifyCache(true);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(cache, zFromSvg);
} }
} }
else if (mXmlReader.name() == "foreignObject") else if (mXmlReader.name() == "foreignObject")
@ -850,6 +807,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsPDFItem* pdfItem = pdfItemFromPDF(); UBGraphicsPDFItem* pdfItem = pdfItemFromPDF();
if (pdfItem) if (pdfItem)
{ {
UBGraphicsItem::assignZValue(pdfItem, zFromSvg);
pdfItem->setUuid(uuidFromSvg);
QDesktopWidget* desktop = UBApplication::desktop(); QDesktopWidget* desktop = UBApplication::desktop();
qreal currentDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; qreal currentDpi = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2;
qreal pdfScale = UBSettings::settings()->pageDpi->get().toReal()/currentDpi; qreal pdfScale = UBSettings::settings()->pageDpi->get().toReal()/currentDpi;
@ -859,9 +818,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene->addItem(pdfItem); mScene->addItem(pdfItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(pdfItem, zFromSvg);
if (isBackground) if (isBackground)
mScene->setAsBackgroundObject(pdfItem); mScene->setAsBackgroundObject(pdfItem);
@ -875,18 +831,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
UBGraphicsAppleWidgetItem* appleWidgetItem = graphicsAppleWidgetFromSvg(); UBGraphicsAppleWidgetItem* appleWidgetItem = graphicsAppleWidgetFromSvg();
if (appleWidgetItem) if (appleWidgetItem)
{ {
UBGraphicsItem::assignZValue(appleWidgetItem, zFromSvg);
appleWidgetItem->setUuid(uuidFromSvg);
appleWidgetItem->setFlag(QGraphicsItem::ItemIsSelectable, true); appleWidgetItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
appleWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); appleWidgetItem->resize(foreignObjectWidth, foreignObjectHeight);
mScene->addItem(appleWidgetItem); mScene->addItem(appleWidgetItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(appleWidgetItem, zFromSvg);
if (!uuidFromSvg.isNull())
appleWidgetItem->setUuid(uuidFromSvg);
appleWidgetItem->show(); appleWidgetItem->show();
currentWidget = appleWidgetItem; currentWidget = appleWidgetItem;
@ -895,21 +848,16 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if (src.contains(".wgt")) else if (src.contains(".wgt"))
{ {
UBGraphicsW3CWidgetItem* w3cWidgetItem = graphicsW3CWidgetFromSvg(); UBGraphicsW3CWidgetItem* w3cWidgetItem = graphicsW3CWidgetFromSvg();
if (w3cWidgetItem) if (w3cWidgetItem)
{ {
UBGraphicsItem::assignZValue(w3cWidgetItem, zFromSvg);
w3cWidgetItem->setUuid(uuidFromSvg);
w3cWidgetItem->setFlag(QGraphicsItem::ItemIsSelectable, true); w3cWidgetItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
w3cWidgetItem->resize(foreignObjectWidth, foreignObjectHeight); w3cWidgetItem->resize(foreignObjectWidth, foreignObjectHeight);
mScene->addItem(w3cWidgetItem); mScene->addItem(w3cWidgetItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(w3cWidgetItem, zFromSvg);
if (!uuidFromSvg.isNull())
w3cWidgetItem->setUuid(uuidFromSvg);
w3cWidgetItem->show(); w3cWidgetItem->show();
currentWidget = w3cWidgetItem; currentWidget = w3cWidgetItem;
@ -918,7 +866,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if (type == "text") else if (type == "text")
{ {
UBGraphicsTextItem* textItem = textItemFromSvg(); UBGraphicsTextItem* textItem = textItemFromSvg();
UBGraphicsTextItemDelegate *textDelegate = 0; UBGraphicsTextItemDelegate *textDelegate = 0;
if (textItem) if (textItem)
@ -934,17 +881,13 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
if (textItem) if (textItem)
{ {
UBGraphicsItem::assignZValue(textItem, zFromSvg);
textItem->setUuid(uuidFromSvg);
textItem->setFlag(QGraphicsItem::ItemIsMovable, true); textItem->setFlag(QGraphicsItem::ItemIsMovable, true);
textItem->setFlag(QGraphicsItem::ItemIsSelectable, true); textItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
mScene->addItem(textItem); mScene->addItem(textItem);
if (zFromSvg != UBZLayerController::errorNum())
UBGraphicsItem::assignZValue(textItem, zFromSvg);
if (!uuidFromSvg.isNull())
textItem->setUuid(uuidFromSvg);
textItem->show(); textItem->show();
} }
} }
@ -994,13 +937,9 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
qDebug() << "Number of detected strokes: " << mStrokesList.count(); qDebug() << "Number of detected strokes: " << mStrokesList.count();
QHashIterator<QString, UBGraphicsStrokesGroup*> iterator(mStrokesList); QHashIterator<QString, UBGraphicsStrokesGroup*> iterator(mStrokesList);
qreal zValue = 0;
while (iterator.hasNext()) { while (iterator.hasNext()) {
iterator.next(); iterator.next();
zValue = iterator.value()->zValue();
qDebug() << "Number of polygons : " << (int)(((UBGraphicsStrokesGroup*)iterator.value())->childItems().count());
mScene->addItem(iterator.value()); mScene->addItem(iterator.value());
iterator.value()->setZValue(zValue);
} }
if (mScene) if (mScene)

@ -73,6 +73,9 @@
#include "core/memcheck.h" #include "core/memcheck.h"
#define DEFAULT_Z_VALUE 0.0
qreal UBZLayerController::errorNumber = -20000001.0; qreal UBZLayerController::errorNumber = -20000001.0;
UBZLayerController::UBZLayerController(QGraphicsScene *scene) : UBZLayerController::UBZLayerController(QGraphicsScene *scene) :
@ -81,8 +84,9 @@ UBZLayerController::UBZLayerController(QGraphicsScene *scene) :
{ {
scopeMap.insert(itemLayerType::NoLayer, ItemLayerTypeData( errorNumber, errorNumber)); scopeMap.insert(itemLayerType::NoLayer, ItemLayerTypeData( errorNumber, errorNumber));
scopeMap.insert(itemLayerType::BackgroundItem, ItemLayerTypeData(-1000000.0, -1000000.0 )); scopeMap.insert(itemLayerType::BackgroundItem, ItemLayerTypeData(-1000000.0, -1000000.0 ));
scopeMap.insert(itemLayerType::ObjectItem, ItemLayerTypeData(-1000000.0, 0.0 )); // DEFAULT_Z_VALUE isn't used because it allows to easily identify new objects
scopeMap.insert(itemLayerType::DrawingItem, ItemLayerTypeData( 0.0, 1000000.0 )); 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::ToolItem, ItemLayerTypeData( 1000000.0, 1000100.0 ));
scopeMap.insert(itemLayerType::CppTool, ItemLayerTypeData( 1000100.0, 1000200.0 )); scopeMap.insert(itemLayerType::CppTool, ItemLayerTypeData( 1000100.0, 1000200.0 ));
scopeMap.insert(itemLayerType::Curtain, ItemLayerTypeData( 1000200.0, 1001000.0 )); scopeMap.insert(itemLayerType::Curtain, ItemLayerTypeData( 1000200.0, 1001000.0 ));
@ -1618,10 +1622,11 @@ void UBGraphicsScene::addItem(QGraphicsItem* item)
{ {
UBCoreGraphicsScene::addItem(item); UBCoreGraphicsScene::addItem(item);
qDebug() << 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); qreal zvalue = mZLayerController->generateZLevel(item);
UBGraphicsItem::assignZValue(item, zvalue); UBGraphicsItem::assignZValue(item, zvalue);
}
if (!mTools.contains(item)) if (!mTools.contains(item))
++mItemCount; ++mItemCount;

Loading…
Cancel
Save