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)
if (gitem)
{
mActiveScene->addItem(gitem);
gitem->setPos(itemPos);
// Translate the new object a bit
gitem->setPos(20, 20);
mLastCreatedItem = gitem;
gitem->setSelected(true);
}
......
......@@ -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;
......
......@@ -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;
......
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