0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 16:44:39 +03:00

Reassign children from child layout to parent layout

This commit is contained in:
Emil Sawicki 2022-01-31 19:47:03 +01:00
parent d081955bc3
commit ee07abb6c5
5 changed files with 46 additions and 23 deletions

View File

@ -57,22 +57,7 @@ void AbstractLayout::addChild(BaseDesignIntf* item, bool updateSize)
item->setFixedPos(true); item->setFixedPos(true);
item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom); item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom);
connect( connectTolayout(item);
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))
);
if (updateSize){ if (updateSize){
relocateChildren(); 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) BaseDesignIntf *AbstractLayout::findNext(BaseDesignIntf *item)
{ {
rebuildChildrenIfNeeded(); rebuildChildrenIfNeeded();

View File

@ -52,6 +52,7 @@ protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight); void updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight);
void rebuildChildrenIfNeeded(); void rebuildChildrenIfNeeded();
void connectTolayout(BaseDesignIntf* item);
private: private:
virtual void sortChildren() = 0; virtual void sortChildren() = 0;
virtual void divideSpace() = 0; virtual void divideSpace() = 0;

View File

@ -171,9 +171,14 @@ void HorizontalLayout::updateLayoutSize()
void HorizontalLayout::relocateChildren() void HorizontalLayout::relocateChildren()
{ {
int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0; int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0;
QList<BaseDesignIntf*> newChildren;
if (layoutsChildren().count() < childItems().size()-1){ if (layoutsChildren().count() < childItems().size()-1){
auto oldChildren = layoutsChildren();
layoutsChildren().clear(); layoutsChildren().clear();
foreach (BaseDesignIntf* item, childBaseItems()) { foreach (BaseDesignIntf* item, childBaseItems()) {
if (!oldChildren.contains(item)) {
newChildren.append(item);
}
layoutsChildren().append(item); layoutsChildren().append(item);
} }
} }
@ -188,6 +193,10 @@ void HorizontalLayout::relocateChildren()
} }
} }
setIsRelocating(false); setIsRelocating(false);
for (BaseDesignIntf* item : newChildren) {
connectTolayout(item);
}
} }
void HorizontalLayout::divideSpace(){ void HorizontalLayout::divideSpace(){

View File

@ -57,9 +57,14 @@ void VerticalLayout::updateLayoutSize()
void VerticalLayout::relocateChildren() void VerticalLayout::relocateChildren()
{ {
int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0; int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0;
QList<BaseDesignIntf*> newChildren;
if (layoutsChildren().count() < childItems().size() - 1){ if (layoutsChildren().count() < childItems().size() - 1){
auto oldChildren = layoutsChildren();
layoutsChildren().clear(); layoutsChildren().clear();
foreach (BaseDesignIntf* item, childBaseItems()) { foreach (BaseDesignIntf* item, childBaseItems()) {
if (!oldChildren.contains(item)) {
newChildren.append(item);
}
layoutsChildren().append(item); layoutsChildren().append(item);
} }
} }
@ -74,6 +79,10 @@ void VerticalLayout::relocateChildren()
} }
} }
setIsRelocating(false); setIsRelocating(false);
for (BaseDesignIntf* item : newChildren) {
connectTolayout(item);
}
} }
bool VerticalLayout::canBeSplitted(int height) const bool VerticalLayout::canBeSplitted(int height) const

View File

@ -554,17 +554,16 @@ CommandIf::Ptr PageDesignIntf::removeReportItemCommand(BaseDesignIntf *item){
CommandIf::Ptr command = createBandDeleteCommand(this,band); CommandIf::Ptr command = createBandDeleteCommand(this,band);
return command; return command;
} else { } else {
LayoutDesignIntf* layout = dynamic_cast<LayoutDesignIntf*>(item->parent()); LayoutDesignIntf* parentLayout = dynamic_cast<LayoutDesignIntf*>(item->parent());
if (layout && (layout->childrenCount()==2)){ LayoutDesignIntf* layout = dynamic_cast<LayoutDesignIntf*>(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::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); commandGroup->addCommand(DeleteItemCommand::create(this,item),false);
return commandGroup; return commandGroup;
} else { } else {
CommandIf::Ptr command = (dynamic_cast<LayoutDesignIntf*>(item))? return layout ? DeleteLayoutCommand::create(this, layout) : DeleteItemCommand::create(this, item) ;
DeleteLayoutCommand::create(this, dynamic_cast<LayoutDesignIntf*>(item)) :
DeleteItemCommand::create(this, item) ;
return command;
} }
} }
} }