Commit 41b538c7 authored by Craig Watson's avatar Craig Watson

Corrected a few minor duplication / zValue issues:

- zValue is correctly initialized when duplicating an object
- Duplicated objects are translated correctly
parent c956cb04
...@@ -690,7 +690,10 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item) ...@@ -690,7 +690,10 @@ UBGraphicsItem *UBBoardController::duplicateItem(UBItem *item)
if (gitem) if (gitem)
{ {
mActiveScene->addItem(gitem); mActiveScene->addItem(gitem);
gitem->setPos(itemPos);
// Translate the new object a bit
gitem->setPos(20, 20);
mLastCreatedItem = gitem; mLastCreatedItem = gitem;
gitem->setSelected(true); gitem->setSelected(true);
} }
......
...@@ -297,6 +297,19 @@ void UBZLayerController::shiftStoredZValue(QGraphicsItem *item, qreal zValue) ...@@ -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) UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoStack)
: UBCoreGraphicsScene(parent) : UBCoreGraphicsScene(parent)
, mEraser(0) , mEraser(0)
...@@ -322,7 +335,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta ...@@ -322,7 +335,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
, mSelectionFrame(0) , mSelectionFrame(0)
{ {
UBCoreGraphicsScene::setObjectName("BoardScene"); UBCoreGraphicsScene::setObjectName("BoardScene");
//setItemIndexMethod(NoIndex); setItemIndexMethod(BspTreeIndex);
setUuid(QUuid::createUuid()); setUuid(QUuid::createUuid());
setDocument(parent); setDocument(parent);
...@@ -1688,13 +1701,17 @@ void UBGraphicsScene::addItem(QGraphicsItem* item) ...@@ -1688,13 +1701,17 @@ void UBGraphicsScene::addItem(QGraphicsItem* item)
UBCoreGraphicsScene::addItem(item); UBCoreGraphicsScene::addItem(item);
// the default z value is already set. This is the case when a svg file is read // 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); qreal zvalue = mZLayerController->generateZLevel(item);
UBGraphicsItem::assignZValue(item, zvalue); UBGraphicsItem::assignZValue(item, zvalue);
} else {
notifyZChanged(item, item->zValue());
} }
else
notifyZChanged(item, item->zValue());
if (!mTools.contains(item)) if (!mTools.contains(item))
++mItemCount; ++mItemCount;
......
...@@ -102,6 +102,8 @@ public: ...@@ -102,6 +102,8 @@ public:
void setLayerType(QGraphicsItem *pItem, itemLayerType::Enum pNewType); void setLayerType(QGraphicsItem *pItem, itemLayerType::Enum pNewType);
void shiftStoredZValue(QGraphicsItem *item, qreal zValue); void shiftStoredZValue(QGraphicsItem *item, qreal zValue);
bool zLevelAvailable(qreal z);
private: private:
ScopeMap scopeMap; ScopeMap scopeMap;
static qreal errorNumber; static qreal errorNumber;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment