mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-24 20:44:39 +03:00
Layout spacing property has been added to layouts
This commit is contained in:
parent
65a3a36770
commit
867448d0fd
@ -4,7 +4,7 @@ namespace LimeReport {
|
|||||||
|
|
||||||
AbstractLayout::AbstractLayout(QString xmlTag, QObject* owner, QGraphicsItem* parent)
|
AbstractLayout::AbstractLayout(QString xmlTag, QObject* owner, QGraphicsItem* parent)
|
||||||
: LayoutDesignIntf(xmlTag, owner, parent), m_isRelocating(false), m_layoutType(Layout),
|
: LayoutDesignIntf(xmlTag, owner, parent), m_isRelocating(false), m_layoutType(Layout),
|
||||||
m_hideEmptyItems(false)
|
m_hideEmptyItems(false), m_layoutSpacing(0)
|
||||||
{
|
{
|
||||||
setPossibleResizeDirectionFlags(AllDirections);
|
setPossibleResizeDirectionFlags(AllDirections);
|
||||||
m_layoutMarker = new LayoutMarker(this);
|
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);
|
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
|
bool AbstractLayout::hideEmptyItems() const
|
||||||
{
|
{
|
||||||
return m_hideEmptyItems;
|
return m_hideEmptyItems;
|
||||||
|
@ -10,6 +10,7 @@ class AbstractLayout: public LayoutDesignIntf
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_ENUMS(LayoutType)
|
Q_ENUMS(LayoutType)
|
||||||
Q_PROPERTY(bool hideEmptyItems READ hideEmptyItems WRITE setHideEmptyItems)
|
Q_PROPERTY(bool hideEmptyItems READ hideEmptyItems WRITE setHideEmptyItems)
|
||||||
|
Q_PROPERTY(int layoutSpacing READ layoutSpacing WRITE setLayoutSpacing)
|
||||||
public:
|
public:
|
||||||
enum LayoutType{Layout,Table};
|
enum LayoutType{Layout,Table};
|
||||||
AbstractLayout(QString xmlTag, QObject *owner = 0, QGraphicsItem *parent = 0);
|
AbstractLayout(QString xmlTag, QObject *owner = 0, QGraphicsItem *parent = 0);
|
||||||
@ -31,6 +32,9 @@ public:
|
|||||||
void setHideEmptyItems(bool hideEmptyItems);
|
void setHideEmptyItems(bool hideEmptyItems);
|
||||||
Q_INVOKABLE QObject* at(int index);
|
Q_INVOKABLE QObject* at(int index);
|
||||||
int childrenCount();
|
int childrenCount();
|
||||||
|
int layoutSpacing() const;
|
||||||
|
void setLayoutSpacing(int layoutSpacing);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void beforeDelete();
|
void beforeDelete();
|
||||||
void childAddedEvent(BaseDesignIntf *child);
|
void childAddedEvent(BaseDesignIntf *child);
|
||||||
@ -64,6 +68,7 @@ private:
|
|||||||
LayoutMarker* m_layoutMarker;
|
LayoutMarker* m_layoutMarker;
|
||||||
LayoutType m_layoutType;
|
LayoutType m_layoutType;
|
||||||
bool m_hideEmptyItems;
|
bool m_hideEmptyItems;
|
||||||
|
int m_layoutSpacing;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace LimeReport
|
} // namespace LimeReport
|
||||||
|
@ -148,16 +148,18 @@ void HorizontalLayout::updateLayoutSize()
|
|||||||
int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0;
|
int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0;
|
||||||
qreal w = spaceBorder*2;
|
qreal w = spaceBorder*2;
|
||||||
qreal h = 0;
|
qreal h = 0;
|
||||||
|
int visibleItemCount = 0;
|
||||||
foreach(BaseDesignIntf* item, layoutsChildren()){
|
foreach(BaseDesignIntf* item, layoutsChildren()){
|
||||||
if (item->isEmpty() && hideEmptyItems()) item->setVisible(false);
|
if (item->isEmpty() && hideEmptyItems()) item->setVisible(false);
|
||||||
if (item->isVisible()){
|
if (item->isVisible()){
|
||||||
if (h<item->height()) h=item->height();
|
if (h<item->height()) h=item->height();
|
||||||
w+=item->width();
|
w+=item->width();
|
||||||
|
visibleItemCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (h>0) setHeight(h+spaceBorder*2);
|
if (h>0) setHeight(h+spaceBorder*2);
|
||||||
if (layoutType() == Layout)
|
if (layoutType() == Layout)
|
||||||
setWidth(w);
|
setWidth(w + layoutSpacing() * (visibleItemCount-1));
|
||||||
else{
|
else{
|
||||||
relocateChildren();
|
relocateChildren();
|
||||||
if (!isRelocating()){
|
if (!isRelocating()){
|
||||||
@ -181,7 +183,7 @@ void HorizontalLayout::relocateChildren()
|
|||||||
foreach (BaseDesignIntf* item, layoutsChildren()) {
|
foreach (BaseDesignIntf* item, layoutsChildren()) {
|
||||||
if (item->isVisible() || itemMode() == DesignMode){
|
if (item->isVisible() || itemMode() == DesignMode){
|
||||||
item->setPos(curX,spaceBorder);
|
item->setPos(curX,spaceBorder);
|
||||||
curX+=item->width();
|
curX += item->width() + layoutSpacing();
|
||||||
item->setHeight(height()-(spaceBorder * 2));
|
item->setHeight(height()-(spaceBorder * 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,6 +203,8 @@ void HorizontalLayout::divideSpace(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemsSumSize += layoutSpacing() * (visibleItemsCount-1);
|
||||||
|
|
||||||
if (itemMode() == DesignMode && !layoutsChildren().isEmpty()){
|
if (itemMode() == DesignMode && !layoutsChildren().isEmpty()){
|
||||||
qreal delta = (width() - (itemsSumSize+spaceBorder*2));
|
qreal delta = (width() - (itemsSumSize+spaceBorder*2));
|
||||||
layoutsChildren().last()->setWidth(layoutsChildren().last()->width()+delta);
|
layoutsChildren().last()->setWidth(layoutsChildren().last()->width()+delta);
|
||||||
|
@ -41,15 +41,17 @@ void VerticalLayout::updateLayoutSize()
|
|||||||
int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0;
|
int spaceBorder = (borderLines() != 0) ? borderLineSize() : 0;
|
||||||
int h = spaceBorder*2;
|
int h = spaceBorder*2;
|
||||||
qreal w = 0;
|
qreal w = 0;
|
||||||
|
int visibleItemCount = 0;
|
||||||
foreach(BaseDesignIntf* item, layoutsChildren()){
|
foreach(BaseDesignIntf* item, layoutsChildren()){
|
||||||
if (item->isEmpty() && hideEmptyItems()) item->setVisible(false);
|
if (item->isEmpty() && hideEmptyItems()) item->setVisible(false);
|
||||||
if (item->isVisible()){
|
if (item->isVisible()){
|
||||||
if (w < item->width()) w = item->width();
|
if (w < item->width()) w = item->width();
|
||||||
h+=item->height();
|
h+=item->height();
|
||||||
|
visibleItemCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (w>0) setWidth(w+spaceBorder*2);
|
if (w>0) setWidth(w+spaceBorder*2);
|
||||||
setHeight(h);
|
setHeight(h + layoutSpacing() *(visibleItemCount-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VerticalLayout::relocateChildren()
|
void VerticalLayout::relocateChildren()
|
||||||
@ -67,7 +69,7 @@ void VerticalLayout::relocateChildren()
|
|||||||
foreach (BaseDesignIntf* item, layoutsChildren()) {
|
foreach (BaseDesignIntf* item, layoutsChildren()) {
|
||||||
if (item->isVisible() || itemMode() == DesignMode){
|
if (item->isVisible() || itemMode() == DesignMode){
|
||||||
item->setPos(spaceBorder, curY);
|
item->setPos(spaceBorder, curY);
|
||||||
curY+=item->height();
|
curY+=item->height() + layoutSpacing();
|
||||||
item->setWidth(width() - (spaceBorder * 2));
|
item->setWidth(width() - (spaceBorder * 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,6 +162,8 @@ void VerticalLayout::divideSpace()
|
|||||||
visibleItemsCount++;
|
visibleItemsCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemsSumSize += layoutSpacing() * (visibleItemsCount - 1);
|
||||||
qreal delta = (height() - (itemsSumSize+spaceBorder*2)) / (visibleItemsCount!=0 ? visibleItemsCount : 1);
|
qreal delta = (height() - (itemsSumSize+spaceBorder*2)) / (visibleItemsCount!=0 ? visibleItemsCount : 1);
|
||||||
|
|
||||||
for (int i=0; i<layoutsChildren().size(); ++i){
|
for (int i=0; i<layoutsChildren().size(); ++i){
|
||||||
|
@ -1854,6 +1854,7 @@ TableBuilder::TableBuilder(HorizontalLayout* layout, DataSourceManager* dataMana
|
|||||||
QObject* TableBuilder::addRow()
|
QObject* TableBuilder::addRow()
|
||||||
{
|
{
|
||||||
checkBaseLayout();
|
checkBaseLayout();
|
||||||
|
if (m_baseLayout && m_patternLayout){
|
||||||
HorizontalLayout* newRow = new HorizontalLayout(m_baseLayout, m_baseLayout);
|
HorizontalLayout* newRow = new HorizontalLayout(m_baseLayout, m_baseLayout);
|
||||||
for(int i = 0; i < m_horizontalLayout->childrenCount(); ++i){
|
for(int i = 0; i < m_horizontalLayout->childrenCount(); ++i){
|
||||||
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(m_patternLayout->at(i));
|
BaseDesignIntf* item = dynamic_cast<BaseDesignIntf*>(m_patternLayout->at(i));
|
||||||
@ -1862,6 +1863,7 @@ QObject* TableBuilder::addRow()
|
|||||||
}
|
}
|
||||||
m_baseLayout->addChild(newRow);
|
m_baseLayout->addChild(newRow);
|
||||||
return newRow;
|
return newRow;
|
||||||
|
} else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* TableBuilder::currentRow()
|
QObject* TableBuilder::currentRow()
|
||||||
|
Loading…
Reference in New Issue
Block a user