From 081b4224684756b26d9fad24390b2be169221cc6 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Sat, 24 Dec 2016 14:01:35 +0300 Subject: [PATCH] COUNT function can be called with only one databand argument --- include/lrglobal.h | 11 +++++++++-- limereport/lrglobal.h | 11 +++++++++-- limereport/lrgroupfunctions.cpp | 5 ++++- limereport/lrreportrender.cpp | 2 +- limereport/lrscriptenginemanager.cpp | 13 +++++++++++-- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/lrglobal.h b/include/lrglobal.h index e64cd43..3a01927 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -77,9 +77,16 @@ namespace Const{ const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}"; const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^{}]*)\\s*\\}"; const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}"; - const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(((?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))(\\w+\\.?\\w+)((?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,\\s*\\\"(\\w+)\\\"\\s*\\)"; - const int DATASOURCE_INDEX = 6; + + //const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(((?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))(\\w+\\.?\\w+)((?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,\\s*\\\"(\\w+)\\\"\\s*\\)"; + //const int DATASOURCE_INDEX = 6; + //const int VALUE_INDEX = 2; + + const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(?:(?:((?:(?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))((?:\\w+\\.?\\w+)|(?:\\w+))(?:(?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,)|(?:))\\s*\\\"(\\w+)\\\"\\s*\\)"; + const int DATASOURCE_INDEX = 4; const int VALUE_INDEX = 2; + const int EXPRESSION_ARGUMENT_INDEX = 3; + const QString GROUP_FUNCTION_RX = "(%1\\s*"+GROUP_FUNCTION_PARAM_RX+")"; const QString GROUP_FUNCTION_NAME_RX = "%1\\s*\\((.*[^\\)])\\)"; const int SCENE_MARGIN = 50; diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index e64cd43..3a01927 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -77,9 +77,16 @@ namespace Const{ const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}"; const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^{}]*)\\s*\\}"; const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}"; - const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(((?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))(\\w+\\.?\\w+)((?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,\\s*\\\"(\\w+)\\\"\\s*\\)"; - const int DATASOURCE_INDEX = 6; + + //const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(((?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))(\\w+\\.?\\w+)((?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,\\s*\\\"(\\w+)\\\"\\s*\\)"; + //const int DATASOURCE_INDEX = 6; + //const int VALUE_INDEX = 2; + + const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(?:(?:((?:(?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))((?:\\w+\\.?\\w+)|(?:\\w+))(?:(?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,)|(?:))\\s*\\\"(\\w+)\\\"\\s*\\)"; + const int DATASOURCE_INDEX = 4; const int VALUE_INDEX = 2; + const int EXPRESSION_ARGUMENT_INDEX = 3; + const QString GROUP_FUNCTION_RX = "(%1\\s*"+GROUP_FUNCTION_PARAM_RX+")"; const QString GROUP_FUNCTION_NAME_RX = "%1\\s*\\((.*[^\\)])\\)"; const int SCENE_MARGIN = 50; diff --git a/limereport/lrgroupfunctions.cpp b/limereport/lrgroupfunctions.cpp index 821b969..d21b4f8 100644 --- a/limereport/lrgroupfunctions.cpp +++ b/limereport/lrgroupfunctions.cpp @@ -57,7 +57,10 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band) ContentItemDesignIntf* item = dynamic_cast(band->childByName(m_data)); if (item) m_values.push_back(item->content()); - else setInvalid(tr("Item \"%1\" not found").arg(m_data)); + else if (m_name.compare("COUNT",Qt::CaseInsensitive) == 0) { + m_values.push_back(1); + } else setInvalid(tr("Item \"%1\" not found").arg(m_data)); + break; } default: diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index e768e10..4158f49 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -368,7 +368,7 @@ void ReportRender::replaceGroupsFunction(BandDesignIntf *band) if (rx.indexIn(content)>=0){ int pos = 0; while ( (pos = rx.indexIn(content,pos))!= -1 ){ - content.replace(rx.capturedTexts().at(0),QString("%1(%2,%3)").arg(functionName).arg('"'+rx.cap(4)+'"').arg('"'+band->objectName()+'"')); + content.replace(rx.capturedTexts().at(0),QString("%1(%2,%3)").arg(functionName).arg('"'+rx.cap(Const::EXPRESSION_ARGUMENT_INDEX)+'"').arg('"'+band->objectName()+'"')); pos += rx.matchedLength(); } contentItem->setContent(content); diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index d24de0e..aeca592 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -302,8 +302,17 @@ QScriptValue callGroupFunction(const QString& functionName, QScriptContext* pcon ScriptEngineManager* sm = qscriptvalue_cast(pcontext->callee().data()); DataSourceManager* dm = sm->dataManager(); - QString expression = pcontext->argument(0).toString(); - QString band = pcontext->argument(1).toString(); + QString expression; + QString band; + + if (functionName.compare("COUNT",Qt::CaseInsensitive) == 0 && pcontext->argumentCount()==1){ + expression = " "; + band = pcontext->argument(0).toString(); + } else { + expression = pcontext->argument(0).toString(); + band = pcontext->argument(1).toString(); + } + QScriptValue res; GroupFunction* gf = dm->groupFunction(functionName,expression,band); if (gf){