fixed issue for stroke copying

preferencesAboutTextFull
Claudio Valerio 11 years ago
parent 998e074ea7
commit 9b8235ed5c
  1. 2
      src/domain/UBGraphicsPolygonItem.cpp
  2. 12
      src/domain/UBGraphicsScene.cpp
  3. 8
      src/domain/UBGraphicsStrokesGroup.cpp

@ -185,6 +185,7 @@ void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const
UBGraphicsPolygonItem *cp = dynamic_cast<UBGraphicsPolygonItem*>(copy); UBGraphicsPolygonItem *cp = dynamic_cast<UBGraphicsPolygonItem*>(copy);
if (cp) if (cp)
{ {
cp->setPolygon(polygon());
cp->mOriginalLine = this->mOriginalLine; cp->mOriginalLine = this->mOriginalLine;
cp->mOriginalWidth = this->mOriginalWidth; cp->mOriginalWidth = this->mOriginalWidth;
cp->mIsNominalLine = this->mIsNominalLine; cp->mIsNominalLine = this->mIsNominalLine;
@ -198,7 +199,6 @@ void UBGraphicsPolygonItem::copyItemParameters(UBItem *copy) const
cp->setColorOnLightBackground(this->colorOnLightBackground()); cp->setColorOnLightBackground(this->colorOnLightBackground());
cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); cp->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType));
cp->setPolygon(polygon());
} }
} }

@ -1104,6 +1104,8 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const
QMap<UBGraphicsStroke*, UBGraphicsStroke*> groupClone; QMap<UBGraphicsStroke*, UBGraphicsStroke*> groupClone;
QList<QUuid> groupAlreadyCloned;
while (itItems.hasNext()) while (itItems.hasNext())
{ {
QGraphicsItem* item = itItems.next(); QGraphicsItem* item = itItems.next();
@ -1111,10 +1113,18 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const
UBItem* ubItem = dynamic_cast<UBItem*>(item); UBItem* ubItem = dynamic_cast<UBItem*>(item);
UBGraphicsStroke* stroke = dynamic_cast<UBGraphicsStroke*>(item); UBGraphicsStroke* stroke = dynamic_cast<UBGraphicsStroke*>(item);
UBGraphicsGroupContainerItem* group = dynamic_cast<UBGraphicsGroupContainerItem*>(item);
if (ubItem && !stroke) if (ubItem && !stroke)
{ {
cloneItem = dynamic_cast<QGraphicsItem*>(ubItem->deepCopy()); //horrible hack
if(group && !groupAlreadyCloned.contains(group->uuid())){
cloneItem = dynamic_cast<QGraphicsItem*>(ubItem->deepCopy());
groupAlreadyCloned.append(group->uuid());
}
if(!group)
cloneItem = dynamic_cast<QGraphicsItem*>(ubItem->deepCopy());
} }
if (cloneItem) if (cloneItem)

@ -26,6 +26,7 @@
#include "UBGraphicsStrokesGroup.h" #include "UBGraphicsStrokesGroup.h"
#include "UBGraphicsStroke.h"
#include "domain/UBGraphicsPolygonItem.h" #include "domain/UBGraphicsPolygonItem.h"
@ -140,12 +141,15 @@ void UBGraphicsStrokesGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
UBItem* UBGraphicsStrokesGroup::deepCopy() const UBItem* UBGraphicsStrokesGroup::deepCopy() const
{ {
UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup(); UBGraphicsStrokesGroup* copy = new UBGraphicsStrokesGroup();
copyItemParameters(copy);
QTransform groupTransform = transform(); QTransform groupTransform = transform();
const_cast<UBGraphicsStrokesGroup*>(this)->resetTransform(); const_cast<UBGraphicsStrokesGroup*>(this)->resetTransform();
QList<QGraphicsItem*> chl = childItems(); QList<QGraphicsItem*> chl = childItems();
UBGraphicsStroke* newStroke = new UBGraphicsStroke;
foreach(QGraphicsItem *child, chl) foreach(QGraphicsItem *child, chl)
{ {
UBGraphicsPolygonItem *polygon = dynamic_cast<UBGraphicsPolygonItem*>(child); UBGraphicsPolygonItem *polygon = dynamic_cast<UBGraphicsPolygonItem*>(child);
@ -155,14 +159,14 @@ UBItem* UBGraphicsStrokesGroup::deepCopy() const
if (polygonCopy) if (polygonCopy)
{ {
QGraphicsItem* pItem = dynamic_cast<QGraphicsItem*>(polygonCopy); QGraphicsItem* pItem = dynamic_cast<QGraphicsItem*>(polygonCopy);
polygonCopy->setTransform(groupTransform);
copy->addToGroup(pItem); copy->addToGroup(pItem);
polygonCopy->setStrokesGroup(copy); polygonCopy->setStrokesGroup(copy);
polygonCopy->setStroke(newStroke);
} }
} }
} }
const_cast<UBGraphicsStrokesGroup*>(this)->setTransform(groupTransform); const_cast<UBGraphicsStrokesGroup*>(this)->setTransform(groupTransform);
copyItemParameters(copy);
return copy; return copy;
} }

Loading…
Cancel
Save