From fc271d6a3b602a7aa7df921f9fee42bbfb093b97 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 28 Sep 2016 02:24:55 +0400 Subject: [PATCH] Nested group bands render has been fixed --- limereport/bands/lrgroupbands.cpp | 25 +++++++++++++------ limereport/bands/lrgroupbands.h | 1 + limereport/lrreportrender.cpp | 21 ++++++++++------ limereport/lrreportrender.h | 2 +- .../propertyItems/lrgroupfieldpropitem.cpp | 16 ++++++++---- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/limereport/bands/lrgroupbands.cpp b/limereport/bands/lrgroupbands.cpp index 752189b..57624eb 100644 --- a/limereport/bands/lrgroupbands.cpp +++ b/limereport/bands/lrgroupbands.cpp @@ -92,8 +92,9 @@ void GroupBandHeader::startGroup(DataSourceManager* dataManager) QString lineVar = QLatin1String("line_")+objectName().toLower(); dataManager->setReportVariable(lineVar,1); - if ((dataManager->dataSource(parentBand()->datasourceName()))){ - IDataSource* ds = dataManager->dataSource(parentBand()->datasourceName()); + QString datasourceName = findDataSourceName(parentBand()); + if (dataManager->containsDatasource(datasourceName)){ + IDataSource* ds = dataManager->dataSource(datasourceName); if (ds->columnIndexByName(m_groupFiledName)!=-1) m_groupFieldValue=ds->data(m_groupFiledName); } @@ -104,17 +105,27 @@ QColor GroupBandHeader::bandColor() const return QColor(Qt::darkBlue); } +QString GroupBandHeader::findDataSourceName(BandDesignIntf* parentBand){ + if (!parentBand) return ""; + if (!parentBand->datasourceName().isEmpty()) + return parentBand->datasourceName(); + else + return findDataSourceName(parentBand->parentBand()); + +} + bool GroupBandHeader::isNeedToClose(DataSourceManager* dataManager) { - //if (m_groupFieldValue.isNull()) return false; - if (!m_groupStarted) return false; if (m_groupFiledName.isNull() || m_groupFiledName.isEmpty()) - dataManager->putError("Group Field Not found"); - if ((dataManager->dataSource(parentBand()->datasourceName()))){ - IDataSource* ds = dataManager->dataSource(parentBand()->datasourceName()); + dataManager->putError(tr("Group field not found")); + QString datasourceName = findDataSourceName(parentBand()); + if (dataManager->containsDatasource(datasourceName)){ + IDataSource* ds = dataManager->dataSource(datasourceName); if (ds->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull()) return false; return ds->data(m_groupFiledName)!=m_groupFieldValue; + } else { + dataManager->putError(tr("Datasource \"%1\" not found !!!").arg(datasourceName)); } return false; diff --git a/limereport/bands/lrgroupbands.h b/limereport/bands/lrgroupbands.h index 53a8098..9fa3eaa 100644 --- a/limereport/bands/lrgroupbands.h +++ b/limereport/bands/lrgroupbands.h @@ -64,6 +64,7 @@ private: bool isStarted(); void closeGroup(); int index(); + QString findDataSourceName(BandDesignIntf *parentBand); private: QVariant m_groupFieldValue; QString m_groupFiledName; diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 57d28ed..777286c 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -190,7 +190,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage) m_reportFooterHeight = reportFooter->height(); initVariables(); - initGroupFunctions(); + initGroups(); clearPageMap(); resetPageNumber(); @@ -545,20 +545,22 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da if (gb&&gb->isNeedToClose(m_datasources)){ if (band->childBands().count()>0){ dataSource->prior(); - foreach (BandDesignIntf* subBand, parentBand->childrenByType(BandDesignIntf::GroupHeader)) { - if ( (subBand->bandIndex() > band->bandIndex()) && - (subBand->childBands().count()>0) - ){ - renderBand(subBand->childBands().at(0)); + foreach (BandDesignIntf* subBand, band->childrenByType(BandDesignIntf::GroupHeader)) { + foreach(BandDesignIntf* footer, subBand->childrenByType(BandDesignIntf::GroupFooter)){ + renderBand(footer); closeDataGroup(subBand); } } - renderBand(band->childBands().at(0),StartNewPageAsNeeded); + foreach (BandDesignIntf* footer, band->childrenByType(BandDesignIntf::GroupFooter)) { + renderBand(footer,StartNewPageAsNeeded); + } + dataSource->next(); } closeDataGroup(band); } + if (!gb->isStarted()){ if (band->reprintOnEachPage()) m_reprintableBands.append(band); @@ -571,6 +573,8 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da renderBand(band,StartNewPageAsNeeded); } } + + renderGroupHeader(band, dataSource, firstTime); } } @@ -588,11 +592,12 @@ void ReportRender::renderGroupFooter(BandDesignIntf *parentBand) } } -void ReportRender::initGroupFunctions() +void ReportRender::initGroups() { m_datasources->clearGroupFunction(); foreach(BandDesignIntf* band, m_patternPageItem->childBands()){ if (band->isFooter()) extractGroupsFunction(band); + if (band->isHeader()) dynamic_cast(band)->closeGroup(); } } diff --git a/limereport/lrreportrender.h b/limereport/lrreportrender.h index 8ea6dc6..74bc011 100644 --- a/limereport/lrreportrender.h +++ b/limereport/lrreportrender.h @@ -102,7 +102,7 @@ private: void renderGroupHeader(BandDesignIntf* parentBand, IDataSource* dataSource, bool firstTime); void renderGroupFooter(BandDesignIntf* parentBand); - void initGroupFunctions(); + void initGroups(); void extractGroupsFunction(BandDesignIntf* band); void replaceGroupsFunction(BandDesignIntf* band); diff --git a/limereport/objectinspector/propertyItems/lrgroupfieldpropitem.cpp b/limereport/objectinspector/propertyItems/lrgroupfieldpropitem.cpp index e77614d..aba8fef 100644 --- a/limereport/objectinspector/propertyItems/lrgroupfieldpropitem.cpp +++ b/limereport/objectinspector/propertyItems/lrgroupfieldpropitem.cpp @@ -42,18 +42,24 @@ namespace { } namespace LimeReport { + +QString findDatasourceName(BandDesignIntf* band){ + if (!band) return ""; + if (!band->datasourceName().isEmpty()) return band->datasourceName(); + else return findDatasourceName(band->parentBand()); +} + QWidget *GroupFieldPropItem::createProperyEditor(QWidget *parent) const { ComboBoxEditor *editor = new ComboBoxEditor(parent,true); editor->setEditable(true); GroupBandHeader *item=dynamic_cast(object()); if (item){ - DataBandDesignIntf* dataBand = dynamic_cast(item->parentBand()); + BandDesignIntf* dataBand = dynamic_cast(item->parentBand()); if (dataBand){ - int propertyIndex = dataBand->metaObject()->indexOfProperty("datasource"); - - if (item && propertyIndex>0){ - editor->addItems(item->reportEditor()->dataManager()->fieldNames(dataBand->property("datasource").toString())); + QString datasourceName = findDatasourceName(dataBand); + if (!datasourceName.isEmpty()){ + editor->addItems(item->reportEditor()->dataManager()->fieldNames(datasourceName)); } } }