mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-23 20:22:58 +03:00
Fix undoing layout inside layout
This commit is contained in:
parent
02ee5864a3
commit
a94bedad06
@ -48,7 +48,6 @@ void AbstractLayout::setLayoutType(const LayoutType& layoutType)
|
|||||||
|
|
||||||
void AbstractLayout::addChild(BaseDesignIntf* item, bool updateSize)
|
void AbstractLayout::addChild(BaseDesignIntf* item, bool updateSize)
|
||||||
{
|
{
|
||||||
|
|
||||||
placeItemInLayout(item);
|
placeItemInLayout(item);
|
||||||
|
|
||||||
m_children.append(item);
|
m_children.append(item);
|
||||||
@ -57,7 +56,7 @@ void AbstractLayout::addChild(BaseDesignIntf* item, bool updateSize)
|
|||||||
item->setFixedPos(true);
|
item->setFixedPos(true);
|
||||||
item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom);
|
item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom);
|
||||||
|
|
||||||
connectTolayout(item);
|
connectToLayout(item);
|
||||||
|
|
||||||
if (updateSize){
|
if (updateSize){
|
||||||
relocateChildren();
|
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)
|
void AbstractLayout::restoreChild(BaseDesignIntf* item)
|
||||||
{
|
{
|
||||||
if (m_children.contains(item)) return;
|
if (m_children.contains(item)) return;
|
||||||
|
|
||||||
m_isRelocating=true;
|
m_isRelocating=true;
|
||||||
|
|
||||||
insertItemInLayout(item);
|
insertItemInLayout(item);
|
||||||
|
|
||||||
connect(item,SIGNAL(destroyed(QObject*)),this,SLOT(slotOnChildDestroy(QObject*)));
|
connectToLayout(item);
|
||||||
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)));
|
|
||||||
|
|
||||||
item->setFixedPos(true);
|
item->setFixedPos(true);
|
||||||
item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom);
|
item->setPossibleResizeDirectionFlags(ResizeRight | ResizeBottom);
|
||||||
@ -252,7 +255,7 @@ void AbstractLayout::rebuildChildrenIfNeeded(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractLayout::connectTolayout(BaseDesignIntf *item)
|
void AbstractLayout::connectToLayout(BaseDesignIntf *item)
|
||||||
{
|
{
|
||||||
connect(
|
connect(
|
||||||
item, SIGNAL(destroyed(QObject*)),
|
item, SIGNAL(destroyed(QObject*)),
|
||||||
@ -270,6 +273,30 @@ void AbstractLayout::connectTolayout(BaseDesignIntf *item)
|
|||||||
item, SIGNAL(itemSelectedHasBeenChanged(BaseDesignIntf*,bool)),
|
item, SIGNAL(itemSelectedHasBeenChanged(BaseDesignIntf*,bool)),
|
||||||
this, SLOT(slotOnChildSelectionHasChanged(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)
|
BaseDesignIntf *AbstractLayout::findNext(BaseDesignIntf *item)
|
||||||
|
@ -28,6 +28,7 @@ public:
|
|||||||
void setLayoutType(const LayoutType& layoutType);
|
void setLayoutType(const LayoutType& layoutType);
|
||||||
|
|
||||||
void addChild(BaseDesignIntf *item,bool updateSize=true);
|
void addChild(BaseDesignIntf *item,bool updateSize=true);
|
||||||
|
void removeChild(BaseDesignIntf *item);
|
||||||
void restoreChild(BaseDesignIntf *item);
|
void restoreChild(BaseDesignIntf *item);
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
void paintChild(BaseDesignIntf* child, QPointF parentPos, QPainter* painter);
|
void paintChild(BaseDesignIntf* child, QPointF parentPos, QPainter* painter);
|
||||||
@ -52,7 +53,8 @@ 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);
|
void connectToLayout(BaseDesignIntf* item);
|
||||||
|
void disconnectFromLayout(BaseDesignIntf* item);
|
||||||
private:
|
private:
|
||||||
virtual void sortChildren() = 0;
|
virtual void sortChildren() = 0;
|
||||||
virtual void divideSpace() = 0;
|
virtual void divideSpace() = 0;
|
||||||
|
@ -195,7 +195,7 @@ void HorizontalLayout::relocateChildren()
|
|||||||
setIsRelocating(false);
|
setIsRelocating(false);
|
||||||
|
|
||||||
for (BaseDesignIntf* item : newChildren) {
|
for (BaseDesignIntf* item : newChildren) {
|
||||||
connectTolayout(item);
|
connectToLayout(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ void VerticalLayout::relocateChildren()
|
|||||||
setIsRelocating(false);
|
setIsRelocating(false);
|
||||||
|
|
||||||
for (BaseDesignIntf* item : newChildren) {
|
for (BaseDesignIntf* item : newChildren) {
|
||||||
connectTolayout(item);
|
connectToLayout(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ public:
|
|||||||
LayoutDesignIntf(const QString& xmlTypeName, QObject* owner = 0,QGraphicsItem* parent = 0):
|
LayoutDesignIntf(const QString& xmlTypeName, QObject* owner = 0,QGraphicsItem* parent = 0):
|
||||||
ItemDesignIntf(xmlTypeName,owner,parent){}
|
ItemDesignIntf(xmlTypeName,owner,parent){}
|
||||||
virtual void addChild(BaseDesignIntf *item,bool updateSize=true) = 0;
|
virtual void addChild(BaseDesignIntf *item,bool updateSize=true) = 0;
|
||||||
|
virtual void removeChild(BaseDesignIntf *item) = 0;
|
||||||
virtual void restoreChild(BaseDesignIntf *item) = 0;
|
virtual void restoreChild(BaseDesignIntf *item) = 0;
|
||||||
virtual int childrenCount() = 0;
|
virtual int childrenCount() = 0;
|
||||||
friend class BaseDesignIntf;
|
friend class BaseDesignIntf;
|
||||||
|
@ -2007,6 +2007,9 @@ CommandIf::Ptr DeleteLayoutCommand::create(PageDesignIntf *page, LayoutDesignInt
|
|||||||
foreach (BaseDesignIntf* childItem, item->childBaseItems()){
|
foreach (BaseDesignIntf* childItem, item->childBaseItems()){
|
||||||
command->m_childItems.append(childItem->objectName());
|
command->m_childItems.append(childItem->objectName());
|
||||||
}
|
}
|
||||||
|
LayoutDesignIntf* layout = dynamic_cast<LayoutDesignIntf*>(item->parent());
|
||||||
|
if (layout)
|
||||||
|
command->m_layoutName = layout->objectName();
|
||||||
return CommandIf::Ptr(command);
|
return CommandIf::Ptr(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2031,9 +2034,20 @@ void DeleteLayoutCommand::undoIt()
|
|||||||
BaseDesignIntf *item = page()->addReportItem(m_itemType);
|
BaseDesignIntf *item = page()->addReportItem(m_itemType);
|
||||||
ItemsReaderIntf::Ptr reader = StringXMLreader::create(m_itemXML);
|
ItemsReaderIntf::Ptr reader = StringXMLreader::create(m_itemXML);
|
||||||
if (reader->first()) reader->readItem(item);
|
if (reader->first()) reader->readItem(item);
|
||||||
|
if (!m_layoutName.isEmpty()) {
|
||||||
|
LayoutDesignIntf* layout = dynamic_cast<LayoutDesignIntf*>(page()->reportItemByName(m_layoutName));
|
||||||
|
if (layout){
|
||||||
|
layout->restoreChild(item);
|
||||||
|
}
|
||||||
|
page()->emitRegisterdItem(item);
|
||||||
|
}
|
||||||
foreach(QString ci, m_childItems){
|
foreach(QString ci, m_childItems){
|
||||||
BaseDesignIntf* ri = page()->reportItemByName(ci);
|
BaseDesignIntf* ri = page()->reportItemByName(ci);
|
||||||
if (ri){
|
if (ri){
|
||||||
|
LayoutDesignIntf* parentLayout = dynamic_cast<LayoutDesignIntf*>(ri->parent());
|
||||||
|
if (parentLayout) {
|
||||||
|
parentLayout->removeChild(ri);
|
||||||
|
}
|
||||||
dynamic_cast<LayoutDesignIntf*>(item)->addChild(ri);
|
dynamic_cast<LayoutDesignIntf*>(item)->addChild(ri);
|
||||||
}
|
}
|
||||||
page()->emitRegisterdItem(item);
|
page()->emitRegisterdItem(item);
|
||||||
|
@ -415,6 +415,7 @@ namespace LimeReport {
|
|||||||
void setItem(BaseDesignIntf* item);
|
void setItem(BaseDesignIntf* item);
|
||||||
private:
|
private:
|
||||||
QStringList m_childItems;
|
QStringList m_childItems;
|
||||||
|
QString m_layoutName;
|
||||||
QString m_itemXML;
|
QString m_itemXML;
|
||||||
QString m_itemType;
|
QString m_itemType;
|
||||||
QString m_itemName;
|
QString m_itemName;
|
||||||
|
Loading…
Reference in New Issue
Block a user