diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 18f69bf2..87288625 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -690,7 +690,10 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) if (gitem) { mActiveScene->addItem(gitem); - gitem->setPos(itemPos); + + // Translate the new object a bit + gitem->setPos(20, 20); + mLastCreatedItem = gitem; gitem->setSelected(true); } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 53203eb1..ddb0a37a 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -297,6 +297,19 @@ void UBZLayerController::shiftStoredZValue(QGraphicsItem *item, qreal zValue) } } +/** + * @brief Returns true if the zLevel is not used by any item on the scene, or false if so. + */ +bool UBZLayerController::zLevelAvailable(qreal z) +{ + foreach(QGraphicsItem* it, mScene->items()) { + if (it->zValue() == z) + return false; + } + + return true; +} + UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoStack) : UBCoreGraphicsScene(parent) , mEraser(0) @@ -322,7 +335,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta , mSelectionFrame(0) { UBCoreGraphicsScene::setObjectName("BoardScene"); - //setItemIndexMethod(NoIndex); + setItemIndexMethod(BspTreeIndex); setUuid(QUuid::createUuid()); setDocument(parent); @@ -1688,13 +1701,17 @@ void UBGraphicsScene::addItem(QGraphicsItem* item) UBCoreGraphicsScene::addItem(item); // 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()){ + if(item->zValue() == DEFAULT_Z_VALUE + || item->zValue() == UBZLayerController::errorNum() + || !mZLayerController->zLevelAvailable(item->zValue())) + { qreal zvalue = mZLayerController->generateZLevel(item); UBGraphicsItem::assignZValue(item, zvalue); - } else { - notifyZChanged(item, item->zValue()); } + else + notifyZChanged(item, item->zValue()); + if (!mTools.contains(item)) ++mItemCount; diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 9a3f009d..1734df7e 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -102,6 +102,8 @@ public: void setLayerType(QGraphicsItem *pItem, itemLayerType::Enum pNewType); void shiftStoredZValue(QGraphicsItem *item, qreal zValue); + bool zLevelAvailable(qreal z); + private: ScopeMap scopeMap; static qreal errorNumber;