diff --git a/limereport/items/lrabstractlayout.cpp b/limereport/items/lrabstractlayout.cpp index 22d17a2..1f59848 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,22 +56,7 @@ void AbstractLayout::addChild(BaseDesignIntf* item, bool updateSize) item->setFixedPos(true); item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom); - 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(itemVisibleHasChanged(BaseDesignIntf*)), - this, SLOT(slotOnChildVisibleHasChanged(BaseDesignIntf*)) - ); - connect( - item, SIGNAL(itemSelectedHasBeenChanged(BaseDesignIntf*,bool)), - this, SLOT(slotOnChildSelectionHasChanged(BaseDesignIntf*,bool)) - ); + connectToLayout(item); if (updateSize){ relocateChildren(); @@ -80,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); @@ -267,6 +255,54 @@ void AbstractLayout::rebuildChildrenIfNeeded(){ } } +void AbstractLayout::connectToLayout(BaseDesignIntf *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(itemVisibleHasChanged(BaseDesignIntf*)), + this, SLOT(slotOnChildVisibleHasChanged(BaseDesignIntf*)) + ); + connect( + item, SIGNAL(itemSelectedHasBeenChanged(BaseDesignIntf*,bool)), + this, SLOT(slotOnChildSelectionHasChanged(BaseDesignIntf*,bool)) + ); + connect( + item, SIGNAL(itemAlignChanged(BaseDesignIntf*, const ItemAlign&, const ItemAlign&)), + this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,const ItemAlign&,const 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*, const ItemAlign&, const ItemAlign&)), + this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,const ItemAlign&,const ItemAlign&)) + ); +} + BaseDesignIntf *AbstractLayout::findNext(BaseDesignIntf *item) { rebuildChildrenIfNeeded(); @@ -288,7 +324,7 @@ BaseDesignIntf *AbstractLayout::findPrior(BaseDesignIntf *item) void AbstractLayout::slotOnChildDestroy(QObject* child) { m_children.removeAll(static_cast(child)); - if (m_children.count()<2){ + if (m_children.count() < 2 && !static_cast(child)){ beforeDelete(); } else { relocateChildren(); @@ -316,7 +352,7 @@ void AbstractLayout::slotOnChildGeometryChanged(QObject* item, QRectF newGeometr } } -void AbstractLayout::slotOnChildItemAlignChanged(BaseDesignIntf* item, const BaseDesignIntf::ItemAlign&, const BaseDesignIntf::ItemAlign&) +void AbstractLayout::slotOnChildItemAlignChanged(BaseDesignIntf* item, const ItemAlign&, const ItemAlign&) { item->setPossibleResizeDirectionFlags(ResizeBottom | ResizeRight); } diff --git a/limereport/items/lrabstractlayout.h b/limereport/items/lrabstractlayout.h index fcda489..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,6 +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 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 11a29d9..5326070 100644 --- a/limereport/items/lrhorizontallayout.cpp +++ b/limereport/items/lrhorizontallayout.cpp @@ -171,9 +171,14 @@ void HorizontalLayout::updateLayoutSize() void HorizontalLayout::relocateChildren() { int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0; + QList newChildren; if (layoutsChildren().count() < childItems().size()-1){ + auto oldChildren = layoutsChildren(); layoutsChildren().clear(); foreach (BaseDesignIntf* item, childBaseItems()) { + if (!oldChildren.contains(item)) { + newChildren.append(item); + } layoutsChildren().append(item); } } @@ -188,6 +193,10 @@ void HorizontalLayout::relocateChildren() } } setIsRelocating(false); + + for (BaseDesignIntf* item : newChildren) { + connectToLayout(item); + } } void HorizontalLayout::divideSpace(){ diff --git a/limereport/items/lrverticallayout.cpp b/limereport/items/lrverticallayout.cpp index 1b1971e..f4a6325 100644 --- a/limereport/items/lrverticallayout.cpp +++ b/limereport/items/lrverticallayout.cpp @@ -57,9 +57,14 @@ void VerticalLayout::updateLayoutSize() void VerticalLayout::relocateChildren() { int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0; + QList newChildren; if (layoutsChildren().count() < childItems().size() - 1){ + auto oldChildren = layoutsChildren(); layoutsChildren().clear(); foreach (BaseDesignIntf* item, childBaseItems()) { + if (!oldChildren.contains(item)) { + newChildren.append(item); + } layoutsChildren().append(item); } } @@ -74,6 +79,10 @@ void VerticalLayout::relocateChildren() } } setIsRelocating(false); + + for (BaseDesignIntf* item : newChildren) { + connectToLayout(item); + } } bool VerticalLayout::canBeSplitted(int height) const diff --git a/limereport/lrbasedesignintf.h b/limereport/lrbasedesignintf.h index 6a2b3ea..511afce 100644 --- a/limereport/lrbasedesignintf.h +++ b/limereport/lrbasedesignintf.h @@ -480,7 +480,7 @@ signals: void propertyChanged(const QString& propertName, const QVariant& oldValue,const QVariant& newValue); void propertyObjectNameChanged(const QString& oldValue, const QString& newValue); void propertyesChanged(QVector propertyNames); - void itemAlignChanged(BaseDesignIntf* item, const BaseDesignIntf::ItemAlign& oldValue, const BaseDesignIntf::ItemAlign& newValue); + void itemAlignChanged(BaseDesignIntf* item, const ItemAlign& oldValue, const ItemAlign& newValue); void itemVisibleHasChanged(BaseDesignIntf* item); void beforeRender(); void afterData(); 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 785b4a4..6e7477b 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -554,17 +554,16 @@ CommandIf::Ptr PageDesignIntf::removeReportItemCommand(BaseDesignIntf *item){ CommandIf::Ptr command = createBandDeleteCommand(this,band); return command; } else { - LayoutDesignIntf* layout = dynamic_cast(item->parent()); - if (layout && (layout->childrenCount()==2)){ + LayoutDesignIntf* parentLayout = dynamic_cast(item->parent()); + LayoutDesignIntf* layout = dynamic_cast(item); + // When removing layout child all his children will be assigned to parent + if (!layout && parentLayout && (parentLayout->childrenCount() == 2)) { CommandGroup::Ptr commandGroup = CommandGroup::create(); - commandGroup->addCommand(DeleteLayoutCommand::create(this, layout),false); + commandGroup->addCommand(DeleteLayoutCommand::create(this, parentLayout),false); commandGroup->addCommand(DeleteItemCommand::create(this,item),false); return commandGroup; } else { - CommandIf::Ptr command = (dynamic_cast(item))? - DeleteLayoutCommand::create(this, dynamic_cast(item)) : - DeleteItemCommand::create(this, item) ; - return command; + return layout ? DeleteLayoutCommand::create(this, layout) : DeleteItemCommand::create(this, item) ; } } } @@ -2008,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); } @@ -2032,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; diff --git a/limereport/objectinspector/lrobjectitemmodel.cpp b/limereport/objectinspector/lrobjectitemmodel.cpp index 122a921..c0e5398 100644 --- a/limereport/objectinspector/lrobjectitemmodel.cpp +++ b/limereport/objectinspector/lrobjectitemmodel.cpp @@ -222,6 +222,10 @@ void QObjectPropertyModel::setMultiObjects(QList* list) m_objects.clear(); submit(); + if (list->isEmpty()) { + return; + } + if (!list->contains(m_object)){ m_object=list->at(0); list->removeAt(0);