diff --git a/limereport/items/lrabstractlayout.cpp b/limereport/items/lrabstractlayout.cpp index eabd0fa..31cd87a 100644 --- a/limereport/items/lrabstractlayout.cpp +++ b/limereport/items/lrabstractlayout.cpp @@ -48,7 +48,6 @@ void AbstractLayout::setLayoutType(const LayoutType& layoutType) void AbstractLayout::addChild(BaseDesignIntf* item, bool updateSize) { - placeItemInLayout(item); m_children.append(item); @@ -57,7 +56,7 @@ void AbstractLayout::addChild(BaseDesignIntf* item, bool updateSize) item->setFixedPos(true); item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom); - connectTolayout(item); + connectToLayout(item); if (updateSize){ relocateChildren(); @@ -65,19 +64,23 @@ void AbstractLayout::addChild(BaseDesignIntf* item, bool updateSize) } } +void AbstractLayout::removeChild(BaseDesignIntf *item) +{ + if (!item) { + return; + } + m_children.removeAll(item); + disconnectFromLayout(item); +} + void AbstractLayout::restoreChild(BaseDesignIntf* item) { if (m_children.contains(item)) return; - m_isRelocating=true; insertItemInLayout(item); - connect(item,SIGNAL(destroyed(QObject*)),this,SLOT(slotOnChildDestroy(QObject*))); - connect(item,SIGNAL(geometryChanged(QObject*,QRectF,QRectF)), - this,SLOT(slotOnChildGeometryChanged(QObject*,QRectF,QRectF))); - connect(item, SIGNAL(itemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign)), - this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign))); + connectToLayout(item); item->setFixedPos(true); item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom); @@ -252,7 +255,7 @@ void AbstractLayout::rebuildChildrenIfNeeded(){ } } -void AbstractLayout::connectTolayout(BaseDesignIntf *item) +void AbstractLayout::connectToLayout(BaseDesignIntf *item) { connect( item, SIGNAL(destroyed(QObject*)), @@ -270,6 +273,30 @@ void AbstractLayout::connectTolayout(BaseDesignIntf *item) item, SIGNAL(itemSelectedHasBeenChanged(BaseDesignIntf*,bool)), this, SLOT(slotOnChildSelectionHasChanged(BaseDesignIntf*,bool)) ); + connect(item, SIGNAL(itemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign)), + this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign))); +} + +void AbstractLayout::disconnectFromLayout(BaseDesignIntf *item) +{ + disconnect( + item, SIGNAL(destroyed(QObject*)), + this, SLOT(slotOnChildDestroy(QObject*)) + ); + disconnect( + item,SIGNAL(geometryChanged(QObject*,QRectF,QRectF)), + this,SLOT(slotOnChildGeometryChanged(QObject*,QRectF,QRectF)) + ); + disconnect( + item, SIGNAL(itemVisibleHasChanged(BaseDesignIntf*)), + this, SLOT(slotOnChildVisibleHasChanged(BaseDesignIntf*)) + ); + disconnect( + item, SIGNAL(itemSelectedHasBeenChanged(BaseDesignIntf*,bool)), + this, SLOT(slotOnChildSelectionHasChanged(BaseDesignIntf*,bool)) + ); + disconnect(item, SIGNAL(itemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign)), + this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign))); } BaseDesignIntf *AbstractLayout::findNext(BaseDesignIntf *item) diff --git a/limereport/items/lrabstractlayout.h b/limereport/items/lrabstractlayout.h index 1ee535a..84e8807 100644 --- a/limereport/items/lrabstractlayout.h +++ b/limereport/items/lrabstractlayout.h @@ -28,6 +28,7 @@ public: void setLayoutType(const LayoutType& layoutType); void addChild(BaseDesignIntf *item,bool updateSize=true); + void removeChild(BaseDesignIntf *item); void restoreChild(BaseDesignIntf *item); bool isEmpty() const; void paintChild(BaseDesignIntf* child, QPointF parentPos, QPainter* painter); @@ -52,7 +53,8 @@ protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); void updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight); void rebuildChildrenIfNeeded(); - void connectTolayout(BaseDesignIntf* item); + void connectToLayout(BaseDesignIntf* item); + void disconnectFromLayout(BaseDesignIntf* item); private: virtual void sortChildren() = 0; virtual void divideSpace() = 0; diff --git a/limereport/items/lrhorizontallayout.cpp b/limereport/items/lrhorizontallayout.cpp index 7aa4826..5326070 100644 --- a/limereport/items/lrhorizontallayout.cpp +++ b/limereport/items/lrhorizontallayout.cpp @@ -195,7 +195,7 @@ void HorizontalLayout::relocateChildren() setIsRelocating(false); for (BaseDesignIntf* item : newChildren) { - connectTolayout(item); + connectToLayout(item); } } diff --git a/limereport/items/lrverticallayout.cpp b/limereport/items/lrverticallayout.cpp index a3b07f1..f4a6325 100644 --- a/limereport/items/lrverticallayout.cpp +++ b/limereport/items/lrverticallayout.cpp @@ -81,7 +81,7 @@ void VerticalLayout::relocateChildren() setIsRelocating(false); for (BaseDesignIntf* item : newChildren) { - connectTolayout(item); + connectToLayout(item); } } diff --git a/limereport/lritemdesignintf.h b/limereport/lritemdesignintf.h index 0687651..55ebe5a 100644 --- a/limereport/lritemdesignintf.h +++ b/limereport/lritemdesignintf.h @@ -97,6 +97,7 @@ public: LayoutDesignIntf(const QString& xmlTypeName, QObject* owner = 0,QGraphicsItem* parent = 0): ItemDesignIntf(xmlTypeName,owner,parent){} virtual void addChild(BaseDesignIntf *item,bool updateSize=true) = 0; + virtual void removeChild(BaseDesignIntf *item) = 0; virtual void restoreChild(BaseDesignIntf *item) = 0; virtual int childrenCount() = 0; friend class BaseDesignIntf; diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index db2689e..6e7477b 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -2007,6 +2007,9 @@ CommandIf::Ptr DeleteLayoutCommand::create(PageDesignIntf *page, LayoutDesignInt foreach (BaseDesignIntf* childItem, item->childBaseItems()){ command->m_childItems.append(childItem->objectName()); } + LayoutDesignIntf* layout = dynamic_cast(item->parent()); + if (layout) + command->m_layoutName = layout->objectName(); return CommandIf::Ptr(command); } @@ -2031,9 +2034,20 @@ void DeleteLayoutCommand::undoIt() BaseDesignIntf *item = page()->addReportItem(m_itemType); ItemsReaderIntf::Ptr reader = StringXMLreader::create(m_itemXML); if (reader->first()) reader->readItem(item); + if (!m_layoutName.isEmpty()) { + LayoutDesignIntf* layout = dynamic_cast(page()->reportItemByName(m_layoutName)); + if (layout){ + layout->restoreChild(item); + } + page()->emitRegisterdItem(item); + } foreach(QString ci, m_childItems){ BaseDesignIntf* ri = page()->reportItemByName(ci); if (ri){ + LayoutDesignIntf* parentLayout = dynamic_cast(ri->parent()); + if (parentLayout) { + parentLayout->removeChild(ri); + } dynamic_cast(item)->addChild(ri); } page()->emitRegisterdItem(item); diff --git a/limereport/lrpagedesignintf.h b/limereport/lrpagedesignintf.h index 4d8fd19..0a49b4d 100644 --- a/limereport/lrpagedesignintf.h +++ b/limereport/lrpagedesignintf.h @@ -415,6 +415,7 @@ namespace LimeReport { void setItem(BaseDesignIntf* item); private: QStringList m_childItems; + QString m_layoutName; QString m_itemXML; QString m_itemType; QString m_itemName;