From d081955bc37f99f59c61a37f0f848f971943d0c0 Mon Sep 17 00:00:00 2001 From: Emil Sawicki Date: Mon, 31 Jan 2022 17:56:59 +0100 Subject: [PATCH 1/5] Fix accessing empty object list --- limereport/objectinspector/lrobjectitemmodel.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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); From ee07abb6c5b6ccc8272009a2c47c79e8e385c30c Mon Sep 17 00:00:00 2001 From: Emil Sawicki Date: Mon, 31 Jan 2022 19:47:03 +0100 Subject: [PATCH 2/5] Reassign children from child layout to parent layout --- limereport/items/lrabstractlayout.cpp | 37 ++++++++++++++----------- limereport/items/lrabstractlayout.h | 1 + limereport/items/lrhorizontallayout.cpp | 9 ++++++ limereport/items/lrverticallayout.cpp | 9 ++++++ limereport/lrpagedesignintf.cpp | 13 ++++----- 5 files changed, 46 insertions(+), 23 deletions(-) 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) ; } } } From 02ee5864a3bad0c6b8a7eb30c0eacd25e6e02f1d Mon Sep 17 00:00:00 2001 From: Emil Sawicki Date: Sun, 6 Feb 2022 12:14:42 +0100 Subject: [PATCH 3/5] Fix removing layout in layout when removing item --- limereport/items/lrabstractlayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/limereport/items/lrabstractlayout.cpp b/limereport/items/lrabstractlayout.cpp index a122eb0..eabd0fa 100644 --- a/limereport/items/lrabstractlayout.cpp +++ b/limereport/items/lrabstractlayout.cpp @@ -293,7 +293,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(); From a94bedad066dda1f8783713ff6ac019f4e6cb840 Mon Sep 17 00:00:00 2001 From: Emil Sawicki Date: Sun, 6 Feb 2022 15:14:04 +0100 Subject: [PATCH 4/5] Fix undoing layout inside layout --- limereport/items/lrabstractlayout.cpp | 45 ++++++++++++++++++++----- limereport/items/lrabstractlayout.h | 4 ++- limereport/items/lrhorizontallayout.cpp | 2 +- limereport/items/lrverticallayout.cpp | 2 +- limereport/lritemdesignintf.h | 1 + limereport/lrpagedesignintf.cpp | 14 ++++++++ limereport/lrpagedesignintf.h | 1 + 7 files changed, 57 insertions(+), 12 deletions(-) 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; From e6b7e10fc86dc27bc875a63b13e207888ce20997 Mon Sep 17 00:00:00 2001 From: Emil Sawicki Date: Sun, 6 Feb 2022 15:22:46 +0100 Subject: [PATCH 5/5] Fix signal connections --- limereport/items/lrabstractlayout.cpp | 14 +++++++++----- limereport/lrbasedesignintf.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/limereport/items/lrabstractlayout.cpp b/limereport/items/lrabstractlayout.cpp index 31cd87a..1f59848 100644 --- a/limereport/items/lrabstractlayout.cpp +++ b/limereport/items/lrabstractlayout.cpp @@ -273,8 +273,10 @@ 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))); + connect( + item, SIGNAL(itemAlignChanged(BaseDesignIntf*, const ItemAlign&, const ItemAlign&)), + this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,const ItemAlign&,const ItemAlign&)) + ); } void AbstractLayout::disconnectFromLayout(BaseDesignIntf *item) @@ -295,8 +297,10 @@ void AbstractLayout::disconnectFromLayout(BaseDesignIntf *item) item, SIGNAL(itemSelectedHasBeenChanged(BaseDesignIntf*,bool)), this, SLOT(slotOnChildSelectionHasChanged(BaseDesignIntf*,bool)) ); - disconnect(item, SIGNAL(itemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign)), - this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,ItemAlign,ItemAlign))); + disconnect( + item, SIGNAL(itemAlignChanged(BaseDesignIntf*, const ItemAlign&, const ItemAlign&)), + this, SLOT(slotOnChildItemAlignChanged(BaseDesignIntf*,const ItemAlign&,const ItemAlign&)) + ); } BaseDesignIntf *AbstractLayout::findNext(BaseDesignIntf *item) @@ -348,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/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();