removed hack and correct duplication on a group

preferencesAboutTextFull
Claudio Valerio 10 years ago
parent aaa09c9921
commit f84d204226
  1. 2
      src/core/UBPersistenceManager.cpp
  2. 16
      src/domain/UBGraphicsGroupContainerItem.cpp
  3. 1
      src/domain/UBGraphicsGroupContainerItem.h
  4. 32
      src/domain/UBGraphicsScene.cpp
  5. 2
      src/domain/UBGraphicsScene.h

@ -757,7 +757,7 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
if (pScene->isModified())
{
UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex);
if(forceImmediateSaving || pScene->hasGroups())
if(forceImmediateSaving)
UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex);
else{
UBGraphicsScene* copiedScene = pScene->sceneDeepCopy();

@ -189,13 +189,23 @@ UBCoreGraphicsScene *UBGraphicsGroupContainerItem::corescene()
return castScene;
}
UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItem::deepCopy() const
UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItem::deepCopyNoChildDuplication() const
{
UBGraphicsGroupContainerItem *copy = new UBGraphicsGroupContainerItem();
copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable
copyItemParameters(copy);
return copy;
}
UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItem::deepCopy() const
{
UBGraphicsGroupContainerItem *copy = new UBGraphicsGroupContainerItem();
copy->setUuid(this->uuid()); // this is OK for now as long as Widgets are imutable
foreach (QGraphicsItem *it, childItems()) {
UBItem *childAsUBItem = dynamic_cast<UBItem*>(it);
@ -209,6 +219,8 @@ UBGraphicsGroupContainerItem *UBGraphicsGroupContainerItem::deepCopy() const
return copy;
}
void UBGraphicsGroupContainerItem::copyItemParameters(UBItem *copy) const
{
UBGraphicsGroupContainerItem *cp = dynamic_cast<UBGraphicsGroupContainerItem*>(copy);

@ -50,6 +50,7 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual UBCoreGraphicsScene *corescene();
UBGraphicsGroupContainerItem *deepCopyNoChildDuplication() const;
virtual UBGraphicsGroupContainerItem *deepCopy() const;
virtual void copyItemParameters(UBItem *copy) const;

@ -315,7 +315,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta
, mpLastPolygon(NULL)
, mCurrentPolygon(0)
, mSelectionFrame(0)
, mNumberOfGroups(0)
{
UBCoreGraphicsScene::setObjectName("BoardScene");
setItemIndexMethod(NoIndex);
@ -1110,12 +1109,25 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const
QGraphicsItem* cloneItem = 0;
UBItem* ubItem = dynamic_cast<UBItem*>(item);
UBGraphicsStroke* stroke = dynamic_cast<UBGraphicsStroke*>(item);
UBGraphicsGroupContainerItem* group = dynamic_cast<UBGraphicsGroupContainerItem*>(item);
if(group){
UBGraphicsGroupContainerItem* groupCloned = group->deepCopyNoChildDuplication();
groupCloned->resetMatrix();
groupCloned->resetTransform();
foreach(QGraphicsItem* eachItem ,group->childItems()){
QGraphicsItem* copiedChild = dynamic_cast<QGraphicsItem*>(dynamic_cast<UBItem*>(eachItem)->deepCopy());
copiedChild->resetTransform();
copiedChild->resetMatrix();
copiedChild->setMatrix(eachItem->sceneMatrix());
copy->addItem(copiedChild);
groupCloned->addToGroup(copiedChild);
}
copy->addItem(groupCloned);
}
if (ubItem && !stroke)
{
if (ubItem && !stroke && !group)
cloneItem = dynamic_cast<QGraphicsItem*>(ubItem->deepCopy());
}
if (cloneItem)
{
@ -1619,8 +1631,6 @@ 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()){
@ -1650,9 +1660,6 @@ void UBGraphicsScene::addItems(const QSet<QGraphicsItem*>& items)
void UBGraphicsScene::removeItem(QGraphicsItem* item)
{
if(item->type() == UBGraphicsItemType::groupContainerType)
mNumberOfGroups -= 1;
item->setSelected(false);
UBCoreGraphicsScene::removeItem(item);
UBApplication::boardController->freezeW3CWidget(item, true);
@ -1668,11 +1675,8 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item)
void UBGraphicsScene::removeItems(const QSet<QGraphicsItem*>& items)
{
foreach(QGraphicsItem* item, items) {
if(item->type() == UBGraphicsItemType::groupContainerType)
mNumberOfGroups -= 1;
foreach(QGraphicsItem* item, items)
UBCoreGraphicsScene::removeItem(item);
}
mItemCount -= items.size();

@ -348,7 +348,6 @@ public slots:
void zoomOutMagnifier();
void changeMagnifierMode(int mode);
void resizedMagnifier(qreal newPercent);
bool hasGroups() { return mNumberOfGroups != 0; }
protected:
@ -434,7 +433,6 @@ public slots:
bool mDrawWithCompass;
UBGraphicsPolygonItem *mCurrentPolygon;
UBSelectionFrame *mSelectionFrame;
int mNumberOfGroups;
};

Loading…
Cancel
Save