diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 8ee1f7b..4e5d707 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -289,43 +289,7 @@ void ReportRender::clearPageMap() m_renderedPages.clear(); } -void ReportRender::extractGroupsFunction(BandDesignIntf *band) -{ - foreach(BaseDesignIntf* item,band->childBaseItems()){ - ContentItemDesignIntf* contentItem = dynamic_cast(item); - if (contentItem&&(contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}")))){ - foreach(const QString &functionName, m_datasources->groupFunctionNames()){ - QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); - QRegExp rxName(QString(Const::GROUP_FUNCTION_NAME_RX).arg(functionName)); - if (rx.indexIn(contentItem->content())>=0){ - int pos = 0; - while ( (pos = rx.indexIn(contentItem->content(),pos)) != -1){ - QVector captures = normalizeCaptures(rx); - if (captures.size()>=3){ - int dsIndex = captures.size() == 3 ? Const::DATASOURCE_INDEX - 1 : Const::DATASOURCE_INDEX; - BandDesignIntf* dataBand = m_patternPageItem->bandByName(captures.at(dsIndex)); - if (dataBand){ - GroupFunction* gf = datasources()->addGroupFunction(functionName,captures.at(Const::VALUE_INDEX),band->objectName(),dataBand->objectName()); - if (gf){ - connect(dataBand,SIGNAL(bandRendered(BandDesignIntf*)),gf,SLOT(slotBandRendered(BandDesignIntf*))); - } - } else { - GroupFunction* gf = datasources()->addGroupFunction(functionName,captures.at(Const::VALUE_INDEX),band->objectName(),captures.at(dsIndex)); - gf->setInvalid(tr("Databand \"%1\" not found").arg(captures.at(dsIndex))); - } - } - pos += rx.matchedLength(); - } - } else if (rxName.indexIn(contentItem->content())>=0){ - GroupFunction* gf = datasources()->addGroupFunction(functionName,rxName.cap(1),band->objectName(),""); - gf->setInvalid(tr("Wrong using function %1").arg(functionName)); - } - } - } - } -} - -bool ReportRender::containsGroupsFunction(BandDesignIntf *band){ +bool ReportRender::containsGroupFunctions(BandDesignIntf *band){ foreach(BaseDesignIntf* item,band->childBaseItems()){ ContentItemDesignIntf* contentItem = dynamic_cast(item); if (contentItem){ @@ -341,31 +305,88 @@ bool ReportRender::containsGroupsFunction(BandDesignIntf *band){ return false; } -void ReportRender::replaceGroupsFunction(BandDesignIntf *band) -{ - foreach(BaseDesignIntf* item,band->childBaseItems()){ - ContentItemDesignIntf* contentItem = dynamic_cast(item); - if (contentItem){ - QString content = contentItem->content(); - foreach(const QString &functionName, m_datasources->groupFunctionNames()){ - QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); - if (rx.indexIn(content)>=0){ - int pos = 0; - while ( (pos = rx.indexIn(content,pos))!= -1 ){ - QVector captures = normalizeCaptures(rx); - if (captures.size() >= 3){ - QString expressionIndex = datasources()->putGroupFunctionsExpressions(captures.at(Const::VALUE_INDEX)); - content.replace(captures.at(0),QString("%1(%2,%3)").arg(functionName).arg('"'+expressionIndex+'"').arg('"'+band->objectName()+'"')); +void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){ + if ( contentItem && contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}"))){ + foreach(const QString &functionName, m_datasources->groupFunctionNames()){ + QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); + QRegExp rxName(QString(Const::GROUP_FUNCTION_NAME_RX).arg(functionName)); + if (rx.indexIn(contentItem->content())>=0){ + int pos = 0; + while ( (pos = rx.indexIn(contentItem->content(),pos)) != -1){ + QVector captures = normalizeCaptures(rx); + if (captures.size()>=3){ + int dsIndex = captures.size() == 3 ? Const::DATASOURCE_INDEX - 1 : Const::DATASOURCE_INDEX; + BandDesignIntf* dataBand = m_patternPageItem->bandByName(captures.at(dsIndex)); + if (dataBand){ + GroupFunction* gf = datasources()->addGroupFunction(functionName,captures.at(Const::VALUE_INDEX),band->objectName(),dataBand->objectName()); + if (gf){ + connect(dataBand,SIGNAL(bandRendered(BandDesignIntf*)),gf,SLOT(slotBandRendered(BandDesignIntf*))); + } + } else { + GroupFunction* gf = datasources()->addGroupFunction(functionName,captures.at(Const::VALUE_INDEX),band->objectName(),captures.at(dsIndex)); + gf->setInvalid(tr("Databand \"%1\" not found").arg(captures.at(dsIndex))); } - pos += rx.matchedLength(); } - contentItem->setContent(content); + pos += rx.matchedLength(); } + } else if (rxName.indexIn(contentItem->content())>=0){ + GroupFunction* gf = datasources()->addGroupFunction(functionName,rxName.cap(1),band->objectName(),""); + gf->setInvalid(tr("Wrong using function %1").arg(functionName)); } } } } +void ReportRender::extractGroupFunctionsFromContainer(BaseDesignIntf* baseItem, BandDesignIntf* band){ + foreach (BaseDesignIntf* item, baseItem->childBaseItems()) { + ContentItemDesignIntf* contentItem = dynamic_cast(item); + if (contentItem) extractGroupFuntionsFromItem(contentItem, band); + else extractGroupFunctionsFromContainer(item, band); + } + +} + +void ReportRender::extractGroupFunctions(BandDesignIntf *band) +{ + extractGroupFunctionsFromContainer(band, band); +} + + +void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){ + if (contentItem){ + QString content = contentItem->content(); + foreach(const QString &functionName, m_datasources->groupFunctionNames()){ + QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); + if (rx.indexIn(content)>=0){ + int pos = 0; + while ( (pos = rx.indexIn(content,pos))!= -1 ){ + QVector captures = normalizeCaptures(rx); + if (captures.size() >= 3){ + QString expressionIndex = datasources()->putGroupFunctionsExpressions(captures.at(Const::VALUE_INDEX)); + content.replace(captures.at(0),QString("%1(%2,%3)").arg(functionName).arg('"'+expressionIndex+'"').arg('"'+band->objectName()+'"')); + } + pos += rx.matchedLength(); + } + contentItem->setContent(content); + } + } + } +} + +void ReportRender::replaceGroupFunctionsInContainer(BaseDesignIntf* baseItem, BandDesignIntf* band) +{ + foreach(BaseDesignIntf* item, baseItem->childBaseItems()){ + ContentItemDesignIntf* contentItem = dynamic_cast(item); + if (contentItem) replaceGroupFunctionsInItem(contentItem, band); + else replaceGroupFunctionsInContainer(item, band); + } +} + +void ReportRender::replaceGroupsFunction(BandDesignIntf *band) +{ + replaceGroupFunctionsInContainer(band, band); +} + BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesignIntf* bandData, ReportRender::DataRenderMode mode, bool isLast) { QApplication::processEvents(); @@ -681,7 +702,7 @@ void ReportRender::renderDataHeader(BandDesignIntf *header) { recalcIfNeeded(header); BandDesignIntf* renderedHeader = renderBand(header, 0); - if (containsGroupsFunction(header)) + if (containsGroupFunctions(header)) m_recalcBands.append(renderedHeader); } @@ -725,7 +746,7 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da } else { renderedHeader = renderBand(band, 0, StartNewPageAsNeeded); } - if (containsGroupsFunction(band)) + if (containsGroupFunctions(band)) m_recalcBands.append(renderedHeader); } @@ -764,11 +785,11 @@ void ReportRender::initGroups() { m_datasources->clearGroupFunction(); foreach(BandDesignIntf* band, m_patternPageItem->childBands()){ - if (band->isFooter()) extractGroupsFunction(band); + if (band->isFooter()) extractGroupFunctions(band); if (band->isHeader()){ IGroupBand* gb = dynamic_cast(band); if (gb) gb->closeGroup(); - extractGroupsFunction(band); + extractGroupFunctions(band); } } } diff --git a/limereport/lrreportrender.h b/limereport/lrreportrender.h index cb3bca1..8f60dca 100644 --- a/limereport/lrreportrender.h +++ b/limereport/lrreportrender.h @@ -40,6 +40,7 @@ namespace LimeReport{ class PageDesignIntf; class BandDesignIntf; +class ContentItemDesignIntf; class GroupBandsHolder: public QList{ public: @@ -112,8 +113,12 @@ private: qreal calcPageFooterHeight(PageItemDesignIntf* patternPage); qreal calcSlicePercent(qreal height); - bool containsGroupsFunction(BandDesignIntf* band); - void extractGroupsFunction(BandDesignIntf* band); + bool containsGroupFunctions(BandDesignIntf* band); + void extractGroupFuntionsFromItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band); + void extractGroupFunctionsFromContainer(BaseDesignIntf* baseItem, BandDesignIntf* band); + void extractGroupFunctions(BandDesignIntf* band); + void replaceGroupFunctionsInItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band); + void replaceGroupFunctionsInContainer(BaseDesignIntf* baseItem, BandDesignIntf* band); void replaceGroupsFunction(BandDesignIntf* band); BandDesignIntf *findRecalcableBand(BandDesignIntf *patternBand); @@ -183,6 +188,7 @@ private: QVector m_columnedBandItems; unsigned long long m_curentNameIndex; + }; } // namespace LimeReport #endif // LRREPORTRENDER_H