From 867448d0fdd7436b9a0478abe7a46885fee7d94f Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Tue, 5 Feb 2019 23:25:18 +0300 Subject: [PATCH] Layout spacing property has been added to layouts --- limereport/items/lrabstractlayout.cpp | 18 +++++++++++++++++- limereport/items/lrabstractlayout.h | 5 +++++ limereport/items/lrhorizontallayout.cpp | 8 ++++++-- limereport/items/lrverticallayout.cpp | 8 ++++++-- limereport/lrscriptenginemanager.cpp | 18 ++++++++++-------- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/limereport/items/lrabstractlayout.cpp b/limereport/items/lrabstractlayout.cpp index 7529533..43e749e 100644 --- a/limereport/items/lrabstractlayout.cpp +++ b/limereport/items/lrabstractlayout.cpp @@ -4,7 +4,7 @@ namespace LimeReport { AbstractLayout::AbstractLayout(QString xmlTag, QObject* owner, QGraphicsItem* parent) : LayoutDesignIntf(xmlTag, owner, parent), m_isRelocating(false), m_layoutType(Layout), - m_hideEmptyItems(false) + m_hideEmptyItems(false), m_layoutSpacing(0) { setPossibleResizeDirectionFlags(AllDirections); m_layoutMarker = new LayoutMarker(this); @@ -336,6 +336,22 @@ void AbstractLayout::slotOnChildSelectionHasChanged(BaseDesignIntf* item, bool v item->setZValue(value ? item->zValue()+1 : item->zValue()-1); } +int AbstractLayout::layoutSpacing() const +{ + return m_layoutSpacing; +} + +void AbstractLayout::setLayoutSpacing(int layoutSpacing) +{ + if (m_layoutSpacing != layoutSpacing){ + int oldValue = m_layoutSpacing; + m_layoutSpacing = layoutSpacing; + int delta = (m_layoutSpacing - oldValue) * (m_children.count()-1); + notify("layoutSpacing", oldValue, m_layoutSpacing); + setWidth(width() + delta); + } +} + bool AbstractLayout::hideEmptyItems() const { return m_hideEmptyItems; diff --git a/limereport/items/lrabstractlayout.h b/limereport/items/lrabstractlayout.h index 2c88abe..2067559 100644 --- a/limereport/items/lrabstractlayout.h +++ b/limereport/items/lrabstractlayout.h @@ -10,6 +10,7 @@ class AbstractLayout: public LayoutDesignIntf Q_OBJECT Q_ENUMS(LayoutType) Q_PROPERTY(bool hideEmptyItems READ hideEmptyItems WRITE setHideEmptyItems) + Q_PROPERTY(int layoutSpacing READ layoutSpacing WRITE setLayoutSpacing) public: enum LayoutType{Layout,Table}; AbstractLayout(QString xmlTag, QObject *owner = 0, QGraphicsItem *parent = 0); @@ -31,6 +32,9 @@ public: void setHideEmptyItems(bool hideEmptyItems); Q_INVOKABLE QObject* at(int index); int childrenCount(); + int layoutSpacing() const; + void setLayoutSpacing(int layoutSpacing); + protected: void beforeDelete(); void childAddedEvent(BaseDesignIntf *child); @@ -64,6 +68,7 @@ private: LayoutMarker* m_layoutMarker; LayoutType m_layoutType; bool m_hideEmptyItems; + int m_layoutSpacing; }; } // namespace LimeReport diff --git a/limereport/items/lrhorizontallayout.cpp b/limereport/items/lrhorizontallayout.cpp index c981e40..4e4ff3f 100644 --- a/limereport/items/lrhorizontallayout.cpp +++ b/limereport/items/lrhorizontallayout.cpp @@ -148,16 +148,18 @@ void HorizontalLayout::updateLayoutSize() int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0; qreal w = spaceBorder*2; qreal h = 0; + int visibleItemCount = 0; foreach(BaseDesignIntf* item, layoutsChildren()){ if (item->isEmpty() && hideEmptyItems()) item->setVisible(false); if (item->isVisible()){ if (hheight()) h=item->height(); w+=item->width(); + visibleItemCount++; } } if (h>0) setHeight(h+spaceBorder*2); if (layoutType() == Layout) - setWidth(w); + setWidth(w + layoutSpacing() * (visibleItemCount-1)); else{ relocateChildren(); if (!isRelocating()){ @@ -181,7 +183,7 @@ void HorizontalLayout::relocateChildren() foreach (BaseDesignIntf* item, layoutsChildren()) { if (item->isVisible() || itemMode() == DesignMode){ item->setPos(curX,spaceBorder); - curX+=item->width(); + curX += item->width() + layoutSpacing(); item->setHeight(height()-(spaceBorder * 2)); } } @@ -201,6 +203,8 @@ void HorizontalLayout::divideSpace(){ } } + itemsSumSize += layoutSpacing() * (visibleItemsCount-1); + if (itemMode() == DesignMode && !layoutsChildren().isEmpty()){ qreal delta = (width() - (itemsSumSize+spaceBorder*2)); layoutsChildren().last()->setWidth(layoutsChildren().last()->width()+delta); diff --git a/limereport/items/lrverticallayout.cpp b/limereport/items/lrverticallayout.cpp index 1958e0e..2e658b1 100644 --- a/limereport/items/lrverticallayout.cpp +++ b/limereport/items/lrverticallayout.cpp @@ -41,15 +41,17 @@ void VerticalLayout::updateLayoutSize() int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0; int h = spaceBorder*2; qreal w = 0; + int visibleItemCount = 0; foreach(BaseDesignIntf* item, layoutsChildren()){ if (item->isEmpty() && hideEmptyItems()) item->setVisible(false); if (item->isVisible()){ if (w < item->width()) w = item->width(); h+=item->height(); + visibleItemCount++; } } if (w>0) setWidth(w+spaceBorder*2); - setHeight(h); + setHeight(h + layoutSpacing() *(visibleItemCount-1)); } void VerticalLayout::relocateChildren() @@ -67,7 +69,7 @@ void VerticalLayout::relocateChildren() foreach (BaseDesignIntf* item, layoutsChildren()) { if (item->isVisible() || itemMode() == DesignMode){ item->setPos(spaceBorder, curY); - curY+=item->height(); + curY+=item->height() + layoutSpacing(); item->setWidth(width() - (spaceBorder * 2)); } } @@ -160,6 +162,8 @@ void VerticalLayout::divideSpace() visibleItemsCount++; } } + + itemsSumSize += layoutSpacing() * (visibleItemsCount - 1); qreal delta = (height() - (itemsSumSize+spaceBorder*2)) / (visibleItemsCount!=0 ? visibleItemsCount : 1); for (int i=0; ichildrenCount(); ++i){ - BaseDesignIntf* item = dynamic_cast(m_patternLayout->at(i)); - BaseDesignIntf* cloneItem = item->cloneItem(item->itemMode(), newRow, newRow); - newRow->addChild(cloneItem); - } - m_baseLayout->addChild(newRow); - return newRow; + if (m_baseLayout && m_patternLayout){ + HorizontalLayout* newRow = new HorizontalLayout(m_baseLayout, m_baseLayout); + for(int i = 0; i < m_horizontalLayout->childrenCount(); ++i){ + BaseDesignIntf* item = dynamic_cast(m_patternLayout->at(i)); + BaseDesignIntf* cloneItem = item->cloneItem(item->itemMode(), newRow, newRow); + newRow->addChild(cloneItem); + } + m_baseLayout->addChild(newRow); + return newRow; + } else return 0; } QObject* TableBuilder::currentRow()