From 6d7350445fe00ee507c00166afd79856f90c63b9 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 25 Apr 2014 18:07:31 +0200 Subject: [PATCH] workaround for issue related to the group duplication --- src/adaptors/UBSvgSubsetAdaptor.cpp | 10 ---------- src/core/UBPersistenceManager.cpp | 4 ++-- src/domain/UBGraphicsGroupContainerItem.cpp | 3 ++- src/domain/UBGraphicsScene.cpp | 21 +++++++++------------ src/domain/UBGraphicsScene.h | 3 +++ 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 40ceb988..b58eac6f 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1066,16 +1066,6 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) // Get the items from the scene QList items = mScene->items(); -// int strokes = 0; int polygons = 0; -// foreach(QGraphicsItem *item, items) { -// if (item->type() == UBGraphicsPolygonItem::Type) { -// polygons++; -// } else if (item->type() == UBGraphicsStrokesGroup::Type) { -// strokes++; -// } -// } -// qDebug() << "---Strokes count" << strokes << "Polygons count" << polygons; -// qDebug() << "---Number of scene items " << items.count(); qSort(items.begin(), items.end(), itemZIndexComp); UBGraphicsStroke *openStroke = 0; diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index e021ffde..94db4c2a 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -757,15 +757,15 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, if (pScene->isModified()) { UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex); - if(forceImmediateSaving) + if(forceImmediateSaving || pScene->hasGroups()) UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex); else{ UBGraphicsScene* copiedScene = pScene->sceneDeepCopy(); mWorker->saveScene(pDocumentProxy, copiedScene, pSceneIndex); pScene->setModified(false); + } } - } diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index cef3ca68..2181e6ea 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -188,10 +188,11 @@ UBCoreGraphicsScene *UBGraphicsGroupContainerItem::corescene() return castScene; } + UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItem::deepCopy() const { - UBGraphicsGroupContainerItem *copy = new UBGraphicsGroupContainerItem(parentItem()); + UBGraphicsGroupContainerItem *copy = new UBGraphicsGroupContainerItem(); copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index b5be1ad4..11d7564b 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -315,6 +315,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta , mpLastPolygon(NULL) , mCurrentPolygon(0) , mSelectionFrame(0) + , mNumberOfGroups(0) { UBCoreGraphicsScene::setObjectName("BoardScene"); setItemIndexMethod(NoIndex); @@ -1101,30 +1102,19 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const copy->setNominalSize(this->mNominalSize); QListIterator itItems(this->mFastAccessItems); - QMap groupClone; - QList groupAlreadyCloned; - while (itItems.hasNext()) { QGraphicsItem* item = itItems.next(); QGraphicsItem* cloneItem = 0; - UBItem* ubItem = dynamic_cast(item); UBGraphicsStroke* stroke = dynamic_cast(item); - UBGraphicsGroupContainerItem* group = dynamic_cast(item); if (ubItem && !stroke) { - //horrible hack - if(group && !groupAlreadyCloned.contains(group->uuid())){ - cloneItem = dynamic_cast(ubItem->deepCopy()); - groupAlreadyCloned.append(group->uuid()); - } - if(!group) - cloneItem = dynamic_cast(ubItem->deepCopy()); + cloneItem = dynamic_cast(ubItem->deepCopy()); } if (cloneItem) @@ -1629,6 +1619,8 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString, const Q void UBGraphicsScene::addItem(QGraphicsItem* item) { UBCoreGraphicsScene::addItem(item); + if(item->type() == UBGraphicsItemType::groupContainerType) + mNumberOfGroups += 1; // 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()){ @@ -1658,6 +1650,9 @@ void UBGraphicsScene::addItems(const QSet& items) void UBGraphicsScene::removeItem(QGraphicsItem* item) { + if(item->type() == UBGraphicsItemType::groupContainerType) + mNumberOfGroups -= 1; + item->setSelected(false); UBCoreGraphicsScene::removeItem(item); UBApplication::boardController->freezeW3CWidget(item, true); @@ -1674,6 +1669,8 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) void UBGraphicsScene::removeItems(const QSet& items) { foreach(QGraphicsItem* item, items) { + if(item->type() == UBGraphicsItemType::groupContainerType) + mNumberOfGroups -= 1; UBCoreGraphicsScene::removeItem(item); } diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 9d8b5caf..ef0c2b80 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -348,6 +348,7 @@ public slots: void zoomOutMagnifier(); void changeMagnifierMode(int mode); void resizedMagnifier(qreal newPercent); + bool hasGroups() { return mNumberOfGroups != 0; } protected: @@ -374,6 +375,7 @@ public slots: virtual void drawBackground(QPainter *painter, const QRectF &rect); + private: void setDocumentUpdated(); void createEraiser(); @@ -432,6 +434,7 @@ public slots: bool mDrawWithCompass; UBGraphicsPolygonItem *mCurrentPolygon; UBSelectionFrame *mSelectionFrame; + int mNumberOfGroups; };