diff --git a/limereport/items/lrabstractlayout.cpp b/limereport/items/lrabstractlayout.cpp index 22d17a2..a122eb0 100644 --- a/limereport/items/lrabstractlayout.cpp +++ b/limereport/items/lrabstractlayout.cpp @@ -57,22 +57,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(); @@ -267,6 +252,26 @@ 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)) + ); +} + BaseDesignIntf *AbstractLayout::findNext(BaseDesignIntf *item) { rebuildChildrenIfNeeded(); diff --git a/limereport/items/lrabstractlayout.h b/limereport/items/lrabstractlayout.h index fcda489..1ee535a 100644 --- a/limereport/items/lrabstractlayout.h +++ b/limereport/items/lrabstractlayout.h @@ -52,6 +52,7 @@ protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value); void updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight); void rebuildChildrenIfNeeded(); + void connectTolayout(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..7aa4826 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..a3b07f1 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/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index 785b4a4..db2689e 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) ; } } }