LimeReport/limereport/lritemscontainerdesignitf.cpp

132 lines
4.8 KiB
C++
Raw Normal View History

2017-04-05 00:58:04 +03:00
#include "lritemscontainerdesignitf.h"
#include "lritemdesignintf.h"
2020-06-20 10:10:53 +03:00
#include "lrbanddesignintf.h"
2017-04-05 00:58:04 +03:00
namespace LimeReport {
bool Segment::intersect(Segment value)
{
return (value.m_begin <= m_end) && (value.m_end >= m_begin);
2017-04-05 00:58:04 +03:00
}
qreal Segment::intersectValue(Segment value)
{
if (!intersect(value)) return 0;
if ((value.m_end >= m_begin) && (value.m_end <= m_end)){
2017-04-05 00:58:04 +03:00
return value.m_end-m_begin;
}
if ((value.m_begin>=m_begin)&&(value.m_end>=m_end)){
return m_end-value.m_begin;
}
if ((value.m_begin>=m_begin)&&(value.m_end<=m_end)){
return value.m_end-value.m_begin;
}
if ((value.m_begin<m_begin)&&(value.m_end>m_end)){
return m_end-m_begin;
}
return 0;
}
bool itemSortContainerLessThen(const PItemSortContainer c1, const PItemSortContainer c2)
{
VSegment vS1(c1->m_rect),vS2(c2->m_rect);
HSegment hS1(c1->m_rect),hS2(c2->m_rect);
if (vS1.intersectValue(vS2)>hS1.intersectValue(hS2))
return c1->m_rect.x()<c2->m_rect.x();
else return c1->m_rect.y()<c2->m_rect.y();
}
2020-06-20 10:10:53 +03:00
void ItemsContainerDesignInft::snapshotItemsLayout(SnapshotType type)
2017-04-05 00:58:04 +03:00
{
m_containerItems.clear();
2020-06-20 10:10:53 +03:00
foreach(BaseDesignIntf *childItem, childBaseItems()){
if (type == IgnoreBands){
if (!dynamic_cast<BandDesignIntf*>(childItem))
m_containerItems.append(PItemSortContainer(new ItemSortContainer(childItem)));
} else
m_containerItems.append(PItemSortContainer(new ItemSortContainer(childItem)));
2017-04-05 00:58:04 +03:00
}
2021-08-23 08:07:08 +03:00
std::sort(m_containerItems.begin(),m_containerItems.end(),itemSortContainerLessThen);
2017-04-05 00:58:04 +03:00
}
void ItemsContainerDesignInft::arrangeSubItems(RenderPass pass, DataSourceManager *dataManager, ArrangeType type)
{
bool needArrage=(type==Force);
foreach (PItemSortContainer item, m_containerItems) {
if (item->m_item->isNeedUpdateSize(pass)){
item->m_item->updateItemSize(dataManager, pass);
needArrage=true;
}
}
if (needArrage){
for (int i=0;i<m_containerItems.count();i++){
for (int j=i;j<m_containerItems.count();j++){
if ((i!=j) && (m_containerItems[i]->m_item->collidesWithItem(m_containerItems[j]->m_item))){
HSegment hS1(m_containerItems[j]->m_rect),hS2(m_containerItems[i]->m_rect);
VSegment vS1(m_containerItems[j]->m_rect),vS2(m_containerItems[i]->m_rect);
if (m_containerItems[i]->m_rect.bottom()<m_containerItems[i]->m_item->geometry().bottom()){
if (hS1.intersectValue(hS2)>vS1.intersectValue(vS2))
m_containerItems[j]->m_item->setY(m_containerItems[i]->m_item->y()+m_containerItems[i]->m_item->height()
+m_containerItems[j]->m_rect.top()-m_containerItems[i]->m_rect.bottom());
}
if (m_containerItems[i]->m_rect.right()<m_containerItems[i]->m_item->geometry().right()){
if (vS1.intersectValue(vS2)>hS1.intersectValue(hS2))
m_containerItems[j]->m_item->setX(m_containerItems[i]->m_item->geometry().right()+
(m_containerItems[j]->m_rect.x()-m_containerItems[i]->m_rect.right()));
}
}
}
}
}
if (needArrage||pass==FirstPass){
int maxBottom = findMaxBottom();
foreach(BaseDesignIntf* item,childBaseItems()){
ItemDesignIntf* childItem=dynamic_cast<ItemDesignIntf*>(item);
if (childItem){
if (childItem->stretchToMaxHeight())
childItem->setHeight(maxBottom-childItem->geometry().top());
}
}
}
}
2017-08-14 22:39:38 +03:00
qreal ItemsContainerDesignInft::findMaxBottom() const
2017-04-05 00:58:04 +03:00
{
2017-12-18 20:28:26 +03:00
qreal maxBottom = 0;
2017-04-05 00:58:04 +03:00
foreach(QGraphicsItem* item,childItems()){
BaseDesignIntf* subItem = dynamic_cast<BaseDesignIntf *>(item);
if(subItem)
if ( subItem->isVisible() && (subItem->geometry().bottom()>maxBottom) )
2017-12-18 20:28:26 +03:00
maxBottom = subItem->geometry().bottom();
2017-04-05 00:58:04 +03:00
}
return maxBottom;
}
2017-12-18 20:28:26 +03:00
qreal ItemsContainerDesignInft::findMinTop() const{
qreal minTop = height();
foreach(QGraphicsItem* item,childItems()){
BaseDesignIntf* subItem = dynamic_cast<BaseDesignIntf *>(item);
if(subItem)
if ( subItem->isVisible() && (subItem->geometry().top()<minTop) )
minTop = subItem->geometry().top();
}
return minTop > 0 ? minTop : 0;
}
2017-08-14 22:39:38 +03:00
qreal ItemsContainerDesignInft::findMaxHeight() const
2017-04-05 00:58:04 +03:00
{
qreal maxHeight=0;
foreach(QGraphicsItem* item,childItems()){
BaseDesignIntf* subItem = dynamic_cast<BaseDesignIntf *>(item);
if(subItem)
if (subItem->geometry().height()>maxHeight) maxHeight=subItem->geometry().height();
}
return maxHeight;
}
} // namespace LimeReport