0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

Using group functions in the horizontal layout items has been fixed

This commit is contained in:
Arin Alexander 2017-06-13 17:48:22 +03:00
parent 67b0889c8d
commit b17aadb2bb
2 changed files with 72 additions and 50 deletions

View File

@ -330,68 +330,87 @@ void ReportRender::clearPageMap()
m_renderedPages.clear(); m_renderedPages.clear();
} }
void ReportRender::extractGroupsFunction(BandDesignIntf *band) void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){
{ if ( contentItem && contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}"))){
foreach(BaseDesignIntf* item,band->childBaseItems()){ foreach(const QString &functionName, m_datasources->groupFunctionNames()){
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item); QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
if (contentItem&&(contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}")))){ QRegExp rxName(QString(Const::GROUP_FUNCTION_NAME_RX).arg(functionName));
foreach(const QString &functionName, m_datasources->groupFunctionNames()){ if (rx.indexIn(contentItem->content())>=0){
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); int pos = 0;
QRegExp rxName(QString(Const::GROUP_FUNCTION_NAME_RX).arg(functionName)); while ( (pos = rx.indexIn(contentItem->content(),pos)) != -1){
if (rx.indexIn(contentItem->content())>=0){ QVector<QString> captures = normalizeCaptures(rx);
int pos = 0; if (captures.size()>=3){
while ( (pos = rx.indexIn(contentItem->content(),pos)) != -1){ int dsIndex = captures.size() == 3 ? Const::DATASOURCE_INDEX - 1 : Const::DATASOURCE_INDEX;
QVector<QString> captures = normalizeCaptures(rx); BandDesignIntf* dataBand = m_patternPageItem->bandByName(captures.at(dsIndex));
if (captures.size()>=3){ if (dataBand){
int dsIndex = captures.size() == 3 ? Const::DATASOURCE_INDEX - 1 : Const::DATASOURCE_INDEX; GroupFunction* gf = datasources()->addGroupFunction(functionName,captures.at(Const::VALUE_INDEX),band->objectName(),dataBand->objectName());
BandDesignIntf* dataBand = m_patternPageItem->bandByName(captures.at(dsIndex)); if (gf){
if (dataBand){ connect(dataBand,SIGNAL(bandRendered(BandDesignIntf*)),gf,SLOT(slotBandRendered(BandDesignIntf*)));
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)));
} }
} 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){ pos += rx.matchedLength();
GroupFunction* gf = datasources()->addGroupFunction(functionName,rxName.cap(1),band->objectName(),"");
gf->setInvalid(tr("Wrong using function %1").arg(functionName));
} }
} 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){
void ReportRender::replaceGroupsFunction(BandDesignIntf *band) foreach (BaseDesignIntf* item, baseItem->childBaseItems()) {
{
foreach(BaseDesignIntf* item,band->childBaseItems()){
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item); ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item);
if (contentItem){ if (contentItem) extractGroupFuntionsFromItem(contentItem, band);
QString content = contentItem->content(); else extractGroupFunctionsFromContainer(item, band);
foreach(const QString &functionName, m_datasources->groupFunctionNames()){ }
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); }
if (rx.indexIn(content)>=0){
int pos = 0; void ReportRender::extractGroupFunctions(BandDesignIntf *band)
while ( (pos = rx.indexIn(content,pos))!= -1 ){ {
QVector<QString> captures = normalizeCaptures(rx); extractGroupFunctionsFromContainer(band, band);
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::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){
pos += rx.matchedLength(); 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<QString> 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()+'"'));
} }
contentItem->setContent(content); pos += rx.matchedLength();
} }
contentItem->setContent(content);
} }
} }
} }
} }
void ReportRender::replaceGroupFunctionsInContainer(BaseDesignIntf* baseItem, BandDesignIntf* band)
{
foreach(BaseDesignIntf* item, baseItem->childBaseItems()){
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(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) BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesignIntf* bandData, ReportRender::DataRenderMode mode, bool isLast)
{ {
QApplication::processEvents(); QApplication::processEvents();
@ -748,7 +767,7 @@ void ReportRender::initGroups()
{ {
m_datasources->clearGroupFunction(); m_datasources->clearGroupFunction();
foreach(BandDesignIntf* band, m_patternPageItem->childBands()){ foreach(BandDesignIntf* band, m_patternPageItem->childBands()){
if (band->isFooter()) extractGroupsFunction(band); if (band->isFooter()) extractGroupFunctions(band);
if (band->isHeader()){ if (band->isHeader()){
IGroupBand* gb = dynamic_cast<IGroupBand*>(band); IGroupBand* gb = dynamic_cast<IGroupBand*>(band);
if (gb) gb->closeGroup(); if (gb) gb->closeGroup();

View File

@ -40,6 +40,7 @@ namespace LimeReport{
class PageDesignIntf; class PageDesignIntf;
class BandDesignIntf; class BandDesignIntf;
class ContentItemDesignIntf;
class GroupBandsHolder: public QList<BandDesignIntf*>{ class GroupBandsHolder: public QList<BandDesignIntf*>{
public: public:
@ -86,9 +87,7 @@ signals:
public slots: public slots:
void cancelRender(); void cancelRender();
private: private:
void baseDesignIntfToScript(BaseDesignIntf* item); void baseDesignIntfToScript(BaseDesignIntf* item);
void renderPage(PageDesignIntf *patternPage); void renderPage(PageDesignIntf *patternPage);
void initDatasources(); void initDatasources();
void initDatasource(const QString &name); void initDatasource(const QString &name);
@ -112,9 +111,12 @@ private:
void renderChildBands(BandDesignIntf* parentBand); void renderChildBands(BandDesignIntf* parentBand);
void renderGroupHeader(BandDesignIntf* parentBand, IDataSource* dataSource, bool firstTime); void renderGroupHeader(BandDesignIntf* parentBand, IDataSource* dataSource, bool firstTime);
void renderGroupFooter(BandDesignIntf* parentBand); void renderGroupFooter(BandDesignIntf* parentBand);
void initGroups(); void initGroups();
void extractGroupsFunction(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); void replaceGroupsFunction(BandDesignIntf* band);
void popPageFooterGroupValues(BandDesignIntf* dataBand); void popPageFooterGroupValues(BandDesignIntf* dataBand);
@ -184,6 +186,7 @@ private:
QVector<BandDesignIntf*> m_columnedBandItems; QVector<BandDesignIntf*> m_columnedBandItems;
unsigned long long m_curentNameIndex; unsigned long long m_curentNameIndex;
}; };
} // namespace LimeReport } // namespace LimeReport
#endif // LRREPORTRENDER_H #endif // LRREPORTRENDER_H