0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-23 16:22:58 +03:00

Multicolumn bands rendering has been fixed

This commit is contained in:
Arin Alexander 2018-06-07 20:43:05 +03:00
parent b1f73d9a1f
commit 846363708a
3 changed files with 87 additions and 60 deletions

View File

@ -880,8 +880,10 @@ void BandDesignIntf::setPrintIfEmpty(bool printIfEmpty)
BandDesignIntf *BandDesignIntf::bandHeader()
{
foreach (BandDesignIntf* band, childBands()) {
if (band->isHeader() && !band->isGroupHeader())
if (band->isHeader() && !band->isGroupHeader()){
if (band->columnsCount() > 1) band->setColumnsFillDirection(this->columnsFillDirection());
return band;
}
}
return 0;
}

View File

@ -48,6 +48,7 @@ void ReportRender::initColumns(){
m_currentStartDataPos.clear();
m_maxHeightByColumn.append(0);
m_currentStartDataPos.append(0);
m_currentColumn = 0;
}
bool ReportRender::isNeedToRearrangeColumnsItems()
@ -142,7 +143,7 @@ qreal ReportRender::maxColumnHeight()
void ReportRender::renameChildItems(BaseDesignIntf *item){
foreach(BaseDesignIntf* child, item->childBaseItems()){
if (!child->childBaseItems().isEmpty()) renameChildItems(child);
child->setObjectName(child->metaObject()->className()+QString::number(++m_curentNameIndex));
child->setObjectName(child->metaObject()->className()+QString::number(++m_currentNameIndex));
}
}
@ -207,7 +208,7 @@ void ReportRender::initDatasource(const QString& name){
void ReportRender::renderPage(PageDesignIntf* patternPage)
{
m_curentNameIndex = 0;
m_currentNameIndex = 0;
m_patternPageItem = patternPage->pageItem();
@ -250,11 +251,11 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
renderBand(m_patternPageItem->bandByType(BandDesignIntf::ReportHeader), 0, StartNewPageAsNeeded);
BandDesignIntf* lastRenderedBand = 0;
for (int i=0;i<m_patternPageItem->dataBandCount() && !m_renderCanceled;i++){
for (int i=0; i < m_patternPageItem->dataBandCount() && !m_renderCanceled; i++){
lastRenderedBand = m_patternPageItem->dataBandAt(i);
initDatasource(lastRenderedBand->datasourceName());
renderDataBand(lastRenderedBand);
if (i<m_patternPageItem->dataBandCount()-1) closeFooterGroup(lastRenderedBand);
if ( i < m_patternPageItem->dataBandCount()-1) closeFooterGroup(lastRenderedBand);
}
if (reportFooter)
@ -515,7 +516,7 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
BandDesignIntf* header = dataBand->bandHeader();
BandDesignIntf* footer = dataBand->bandFooter();
if (header && header->printAlways()) renderBand(header, 0);
if (header && header->printAlways()) renderBand(header, 0, StartNewPageAsNeeded);
if(bandDatasource && !bandDatasource->eof() && !m_renderCanceled){
@ -523,12 +524,11 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
datasources()->setReportVariable(varName,1);
if (header && !header->printAlways())
renderBand(header, 0);
renderBand(header, 0, StartNewPageAsNeeded);
if (dataBand->bandHeader() && dataBand->bandHeader()->reprintOnEachPage())
m_reprintableBands.append(dataBand->bandHeader());
//renderChildHeader(dataBand,PrintNotAlwaysPrintable);
renderGroupHeader(dataBand, bandDatasource, true);
bool firstTime = true;
@ -634,7 +634,6 @@ void ReportRender::renderPageItems(PageItemDesignIntf* patternPage)
m_renderPageItem,
m_renderPageItem);
pageItems.append(cloneItem);
//cloneItem->updateItemSize(m_datasources);
}
}
m_renderPageItem->restoreLinks();
@ -691,9 +690,7 @@ void ReportRender::renderChildBands(BandDesignIntf *parentBand)
if (!band->datasourceName().isEmpty())
ds = m_datasources->dataSource(band->datasourceName());
if (ds) ds->first();
//renderChildHeader(band,PrintAlwaysPrintable);
renderDataBand(band);
//renderChildFooter(band,PrintAlwaysPrintable);
closeFooterGroup(band);
}
}
@ -707,7 +704,7 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
bool didGoBack = dataSource->prior();
foreach (BandDesignIntf* subBand, band->childrenByType(BandDesignIntf::GroupHeader)) {
foreach(BandDesignIntf* footer, subBand->childrenByType(BandDesignIntf::GroupFooter)){
renderBand(footer, 0);
renderBand(footer, 0, StartNewPageAsNeeded);
}
closeDataGroup(subBand);
}
@ -721,10 +718,6 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
}
}
closeDataGroup(band);
// if (gb->isNeedToStartNewPage()){
// savePage();
// startNewPage();
// }
}
if (gb && !gb->isStarted()){
@ -887,10 +880,31 @@ qreal minVectorValue(QVector<qreal> vector){
return curValue;
}
void ReportRender::placeBandOnPage(BandDesignIntf* band, int columnIndex){
qreal bandPos = m_currentStartDataPos[columnIndex];
m_currentStartDataPos[columnIndex] += band->height();
m_maxHeightByColumn[columnIndex] -= band->height();
band->setPos(m_renderPageItem->pageRect().x()+band->width()*columnIndex, bandPos);
band->setBandIndex(++m_currentIndex);
band->setColumnIndex(columnIndex);
m_renderPageItem->registerBand(band);
m_currentColumn = columnIndex;
}
bool isMultiColumnHeader(BandDesignIntf* band){
return ( (band->columnsCount() > 1 ) &&
(band->isHeader() &&
((band->bandNestingLevel() == 0) || (band->columnsFillDirection() == BandDesignIntf::Horizontal))));
}
bool ReportRender::registerBand(BandDesignIntf *band, bool registerInChildren)
{
if (band->columnsCount()==1 && m_maxHeightByColumn.size()>1){
if (band->bandType()!=BandDesignIntf::PageFooter){
if (band->columnsCount() == 1 && m_maxHeightByColumn.size() > 1 ){
if (band->bandType() != BandDesignIntf::PageFooter){
rearrangeColumnsItems();
m_currentColumn = 0;
qreal minValue = minVectorValue(m_maxHeightByColumn);
@ -902,63 +916,62 @@ bool ReportRender::registerBand(BandDesignIntf *band, bool registerInChildren)
}
}
if ( (band->columnsCount()>1) &&
(!band->isHeader() || (band->bandNestingLevel()>0 && band->columnsFillDirection() != BandDesignIntf::Horizontal ))){
if (band->columnsCount() != m_maxHeightByColumn.size()){
for(int i=1;i<band->columnsCount();++i){
m_maxHeightByColumn.append(m_maxHeightByColumn[0]);
m_currentStartDataPos.append(m_currentStartDataPos[0]);
}
m_currentColumn = 0;
}
if (m_maxHeightByColumn.size()!=band->columnsCount()){
for(int i=1;i<band->columnsCount();++i){
m_maxHeightByColumn.append(m_maxHeightByColumn[0]);
m_currentStartDataPos.append(m_currentStartDataPos[0]);
}
m_currentColumn = 0;
if ( (band->columnsCount() > 1) &&
(!band->isHeader() || (band->bandNestingLevel() > 0 && band->columnsFillDirection() != BandDesignIntf::Horizontal ))){
if (band->columnsFillDirection() == BandDesignIntf::Horizontal){
if (m_currentColumn<band->columnsCount()-1)
m_currentColumn = m_currentColumn+1;
else
m_currentColumn = 0;
} else {
if (band->columnsFillDirection()==BandDesignIntf::Horizontal){
if (m_currentColumn<band->columnsCount()-1)
m_currentColumn = m_currentColumn+1;
else
m_currentColumn = 0;
if ( (m_maxHeightByColumn[0] == m_maxHeightByColumn[m_currentColumn]) && (m_maxHeightByColumn[0] >= band->height()) ){
m_currentColumn = 0;
}
}
}
if (band->height()<=m_maxHeightByColumn[m_currentColumn]){
if ( (isMultiColumnHeader(band) && band->height() <= m_maxHeightByColumn[0]) ||
(band->height() <= m_maxHeightByColumn[m_currentColumn])){
if (band->bandType()==BandDesignIntf::PageFooter){
for (int i=0;i<m_maxHeightByColumn.size();++i)
if ( (band->bandType() == BandDesignIntf::PageFooter) ){
for (int i=0; i < m_maxHeightByColumn.size(); ++i)
m_maxHeightByColumn[i]+=band->height();
} else {
m_maxHeightByColumn[m_currentColumn]-=band->height();
}
if ( (band->columnsCount()>1) &&
(band->isHeader() && (band->bandNestingLevel()==0 || band->columnsFillDirection()==BandDesignIntf::Horizontal))){
if ( isMultiColumnHeader(band)){
qreal bandPos = m_currentStartDataPos[m_currentColumn];
m_currentStartDataPos[m_currentColumn]+=band->height();
for (int i=0;i<band->columnsCount();++i){
if (i!=0) band = dynamic_cast<BandDesignIntf*>(band->cloneItem(PreviewMode));
band->setPos(m_renderPageItem->pageRect().x()+band->width()*i,bandPos);
band->setBandIndex(++m_currentIndex);
band->setColumnIndex(i);
m_renderPageItem->registerBand(band);
if (!band->parent()){
for (int i = 0; i < band->columnsCount(); ++i){
m_currentColumn = i;
if (i != 0) band = dynamic_cast<BandDesignIntf*>(band->cloneItem(PreviewMode));
placeBandOnPage(band, i);
}
} else {
placeBandOnPage(band, band->columnIndex());
}
} else {
if (band->bandType()!=BandDesignIntf::PageFooter){
band->setPos(m_renderPageItem->pageRect().x()+band->width()*m_currentColumn,
m_currentStartDataPos[m_currentColumn]);
m_currentStartDataPos[m_currentColumn]+=band->height();
band->setBandIndex(++m_currentIndex);
band->setColumnIndex(m_currentColumn);
if (band->bandType() != BandDesignIntf::PageFooter){
placeBandOnPage(band, m_currentColumn);
}
if (band->columnsCount()>1){
if (band->columnsCount() > 1){
m_columnedBandItems.append(band);
}
m_renderPageItem->registerBand(band);
}
foreach(QList<BandDesignIntf*>* list,m_childBands.values()){
@ -974,7 +987,7 @@ bool ReportRender::registerBand(BandDesignIntf *band, bool registerInChildren)
}
if (band->isData()) m_renderedDataBandCount++;
band->setObjectName(band->objectName()+QString::number(++m_curentNameIndex));
band->setObjectName(band->objectName()+QString::number(++m_currentNameIndex));
renameChildItems(band);
return true;
} else return false;
@ -1090,9 +1103,7 @@ void ReportRender::startNewColumn(){
void ReportRender::startNewPage()
{
m_renderPageItem = 0;
m_currentColumn = 0;
m_newPageStarted = true;
initColumns();
initRenderPage();
@ -1192,8 +1203,14 @@ void ReportRender::pasteGroups()
m_popupedValues.clear();
}
bool bandLessThen(BandDesignIntf* b1, BandDesignIntf* b2){
return b1->bandIndex() < b2->bandIndex();
}
void ReportRender::checkLostHeadersOnPrevPage()
{
QVector<BandDesignIntf*> lostHeaders;
if (m_renderedPages.isEmpty()) return;
PageItemDesignIntf::Ptr page = m_renderedPages.last();
if (page->bands().isEmpty()) return;
@ -1212,12 +1229,19 @@ void ReportRender::checkLostHeadersOnPrevPage()
if (it.value()->isHeader()){
if (it.value()->reprintOnEachPage()){
delete it.value();
} else { registerBand(it.value());}
} else { lostHeaders.append(it.value());}
it.remove();
it.previous();
} else break;
}
if (lostHeaders.size() > 0){
qSort(lostHeaders.begin(), lostHeaders.end(), bandLessThen);
foreach(BandDesignIntf* header, lostHeaders){
registerBand(header);
}
}
}
BandDesignIntf* ReportRender::findEnclosingGroup()

View File

@ -154,6 +154,8 @@ private:
qreal maxColumnHeight();
void renameChildItems(BaseDesignIntf *item);
void renderGroupFooterByHeader(BandDesignIntf *groupHeader);
void placeBandOnPage(BandDesignIntf *band, int columnIndex);
private:
DataSourceManager* m_datasources;
ScriptEngineContext* m_scriptEngineContext;
@ -184,10 +186,9 @@ private:
int m_currentColumn;
QList<PagesRange> m_ranges;
QVector<BandDesignIntf*> m_columnedBandItems;
unsigned long long m_curentNameIndex;
unsigned long long m_currentNameIndex;
bool m_newPageStarted;
};
} // namespace LimeReport
#endif // LRREPORTRENDER_H