mirror of
https://github.com/fralx/LimeReport.git
synced 2025-11-25 08:28:06 +03:00
Define code style and format all source file using clang-format-14
except those placed in 3rdparty directories.
This commit is contained in:
@@ -28,11 +28,12 @@
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "lrgroupfunctions.h"
|
||||
#include "lrdatasourcemanager.h"
|
||||
|
||||
#include "lrbanddesignintf.h"
|
||||
#include "lrdatasourcemanager.h"
|
||||
#include "lritemdesignintf.h"
|
||||
#include "lrscriptenginemanager.h"
|
||||
#include "lrpageitemdesignintf.h"
|
||||
#include "lrscriptenginemanager.h"
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
||||
#include <QRegExp>
|
||||
@@ -40,7 +41,7 @@
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
void GroupFunction::slotBandRendered(BandDesignIntf *band)
|
||||
void GroupFunction::slotBandRendered(BandDesignIntf* band)
|
||||
{
|
||||
ScriptEngineManager& sm = ScriptEngineManager::instance();
|
||||
|
||||
@@ -52,17 +53,17 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
|
||||
QRegularExpression rxVar = getVariableRegEx();
|
||||
#endif
|
||||
|
||||
switch (m_dataType){
|
||||
case Field:{
|
||||
switch (m_dataType) {
|
||||
case Field: {
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
||||
if (rxField.indexIn(m_data) != -1){
|
||||
if (rxField.indexIn(m_data) != -1) {
|
||||
QString field = rxField.cap(1);
|
||||
#else
|
||||
QRegularExpressionMatch matchField = rxField.match(m_data);
|
||||
if(matchField.hasMatch()){
|
||||
if (matchField.hasMatch()) {
|
||||
QString field = matchField.captured(1);
|
||||
#endif
|
||||
if (m_dataManager->containsField(field)){
|
||||
if (m_dataManager->containsField(field)) {
|
||||
m_values.push_back(m_dataManager->fieldData(field));
|
||||
m_valuesByBand.insert(band, m_dataManager->fieldData(field));
|
||||
} else {
|
||||
@@ -71,16 +72,16 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Variable:{
|
||||
case Variable: {
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
||||
if (rxVar.indexIn(m_data) != -1){
|
||||
if (rxVar.indexIn(m_data) != -1) {
|
||||
QString var = rxVar.cap(1);
|
||||
#else
|
||||
QRegularExpressionMatch matchVar = rxVar.match(m_data);
|
||||
if(matchVar.hasMatch()){
|
||||
if (matchVar.hasMatch()) {
|
||||
QString var = matchVar.captured(1);
|
||||
#endif
|
||||
if (m_dataManager->containsVariable(var)){
|
||||
if (m_dataManager->containsVariable(var)) {
|
||||
m_values.push_back(m_dataManager->variable(var));
|
||||
m_valuesByBand.insert(band, m_dataManager->variable(var));
|
||||
} else {
|
||||
@@ -89,10 +90,9 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Script:
|
||||
{
|
||||
case Script: {
|
||||
QVariant value = sm.evaluateScript(m_data);
|
||||
if (value.isValid()){
|
||||
if (value.isValid()) {
|
||||
m_values.push_back(value);
|
||||
m_valuesByBand.insert(band, value);
|
||||
} else {
|
||||
@@ -100,16 +100,18 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ContentItem:{
|
||||
case ContentItem: {
|
||||
QString itemName = m_data;
|
||||
ContentItemDesignIntf* item = dynamic_cast<ContentItemDesignIntf*>(band->childByName(itemName.remove('"')));
|
||||
if (item){
|
||||
ContentItemDesignIntf* item
|
||||
= dynamic_cast<ContentItemDesignIntf*>(band->childByName(itemName.remove('"')));
|
||||
if (item) {
|
||||
m_values.push_back(item->content());
|
||||
m_valuesByBand.insert(band, item->content());
|
||||
} else if (m_name.compare("COUNT",Qt::CaseInsensitive) == 0) {
|
||||
} else if (m_name.compare("COUNT", Qt::CaseInsensitive) == 0) {
|
||||
m_values.push_back(1);
|
||||
m_valuesByBand.insert(band, 1);
|
||||
} else setInvalid(tr("Item \"%1\" not found").arg(m_data));
|
||||
} else
|
||||
setInvalid(tr("Item \"%1\" not found").arg(m_data));
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -118,9 +120,9 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
|
||||
}
|
||||
}
|
||||
|
||||
void GroupFunction::slotBandReRendered(BandDesignIntf *oldBand, BandDesignIntf *newBand)
|
||||
void GroupFunction::slotBandReRendered(BandDesignIntf* oldBand, BandDesignIntf* newBand)
|
||||
{
|
||||
if (m_valuesByBand.contains(oldBand)){
|
||||
if (m_valuesByBand.contains(oldBand)) {
|
||||
m_valuesByBand.insert(newBand, m_valuesByBand.value(oldBand));
|
||||
m_valuesByBand.remove(oldBand);
|
||||
}
|
||||
@@ -128,12 +130,12 @@ void GroupFunction::slotBandReRendered(BandDesignIntf *oldBand, BandDesignIntf *
|
||||
|
||||
QVariant GroupFunction::addition(QVariant value1, QVariant value2)
|
||||
{
|
||||
return value1.toDouble()+value2.toDouble();
|
||||
return value1.toDouble() + value2.toDouble();
|
||||
}
|
||||
|
||||
QVariant GroupFunction::subtraction(QVariant value1, QVariant value2)
|
||||
{
|
||||
return value1.toDouble()-value2.toDouble();
|
||||
return value1.toDouble() - value2.toDouble();
|
||||
}
|
||||
|
||||
QVariant GroupFunction::division(QVariant value1, QVariant value2)
|
||||
@@ -146,43 +148,48 @@ QVariant GroupFunction::multiplication(QVariant value1, QVariant value2)
|
||||
return value1.toDouble() * value2.toDouble();
|
||||
}
|
||||
|
||||
GroupFunction::GroupFunction(const QString &expression, const QString &dataBandName, DataSourceManager* dataManager)
|
||||
:m_data(expression), m_dataBandName(dataBandName), m_dataManager(dataManager), m_isValid(true), m_errorMessage("")
|
||||
GroupFunction::GroupFunction(const QString& expression, const QString& dataBandName,
|
||||
DataSourceManager* dataManager):
|
||||
m_data(expression),
|
||||
m_dataBandName(dataBandName),
|
||||
m_dataManager(dataManager),
|
||||
m_isValid(true),
|
||||
m_errorMessage("")
|
||||
{
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
||||
QRegExp rxField(Const::FIELD_RX,Qt::CaseInsensitive);
|
||||
QRegExp rxVariable(Const::VARIABLE_RX,Qt::CaseInsensitive);
|
||||
QRegExp rxScript(Const::SCRIPT_RX,Qt::CaseInsensitive);
|
||||
QRegExp rxField(Const::FIELD_RX, Qt::CaseInsensitive);
|
||||
QRegExp rxVariable(Const::VARIABLE_RX, Qt::CaseInsensitive);
|
||||
QRegExp rxScript(Const::SCRIPT_RX, Qt::CaseInsensitive);
|
||||
#else
|
||||
QRegularExpression rxField = getFieldRegEx();
|
||||
QRegularExpression rxVariable = getVariableRegEx();
|
||||
QRegularExpression rxScript = getScriptRegEx();
|
||||
#endif
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
||||
if (rxScript.indexIn(expression) != -1){
|
||||
if (rxScript.indexIn(expression) != -1) {
|
||||
#else
|
||||
QRegularExpressionMatch matchScript = rxScript.match(expression);
|
||||
if(matchScript.hasMatch()){
|
||||
if (matchScript.hasMatch()) {
|
||||
#endif
|
||||
m_dataType = Script;
|
||||
return;
|
||||
}
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
||||
if (rxField.indexIn(expression) != -1){
|
||||
if (rxField.indexIn(expression) != -1) {
|
||||
#else
|
||||
QRegularExpressionMatch matchField = rxField.match(expression);
|
||||
if(matchField.hasMatch()){
|
||||
if (matchField.hasMatch()) {
|
||||
#endif
|
||||
m_dataType=Field;
|
||||
m_dataType = Field;
|
||||
return;
|
||||
}
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
|
||||
if (rxVariable.indexIn(expression) != -1){
|
||||
if (rxVariable.indexIn(expression) != -1) {
|
||||
#else
|
||||
QRegularExpressionMatch matchVariable = rxVariable.match(expression);
|
||||
if(matchVariable.hasMatch()){
|
||||
if (matchVariable.hasMatch()) {
|
||||
#endif
|
||||
m_dataType = Variable;
|
||||
return;
|
||||
@@ -191,28 +198,32 @@ GroupFunction::GroupFunction(const QString &expression, const QString &dataBandN
|
||||
m_dataType = ContentItem;
|
||||
}
|
||||
|
||||
GroupFunction *GroupFunctionFactory::createGroupFunction(const QString &functionName, const QString &expression, const QString& dataBandName, DataSourceManager *dataManager)
|
||||
GroupFunction* GroupFunctionFactory::createGroupFunction(const QString& functionName,
|
||||
const QString& expression,
|
||||
const QString& dataBandName,
|
||||
DataSourceManager* dataManager)
|
||||
{
|
||||
if (m_creators.contains(functionName)){
|
||||
return m_creators.value(functionName)->createFunction(expression, dataBandName, dataManager);
|
||||
if (m_creators.contains(functionName)) {
|
||||
return m_creators.value(functionName)
|
||||
->createFunction(expression, dataBandName, dataManager);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
GroupFunctionFactory::~GroupFunctionFactory()
|
||||
{
|
||||
foreach(GroupFunctionCreator* creator, m_creators.values()){
|
||||
foreach (GroupFunctionCreator* creator, m_creators.values()) {
|
||||
delete creator;
|
||||
}
|
||||
m_creators.clear();
|
||||
}
|
||||
|
||||
QVariant SumGroupFunction::calculate(PageItemDesignIntf *page)
|
||||
QVariant SumGroupFunction::calculate(PageItemDesignIntf* page)
|
||||
{
|
||||
QVariant res = 0;
|
||||
if (!page){
|
||||
foreach(QVariant value,values()){
|
||||
res = addition(res,value);
|
||||
if (!page) {
|
||||
foreach (QVariant value, values()) {
|
||||
res = addition(res, value);
|
||||
}
|
||||
} else {
|
||||
foreach (BandDesignIntf* band, page->bands()) {
|
||||
@@ -222,70 +233,79 @@ QVariant SumGroupFunction::calculate(PageItemDesignIntf *page)
|
||||
return res;
|
||||
}
|
||||
|
||||
QVariant AvgGroupFunction::calculate(PageItemDesignIntf *page)
|
||||
QVariant AvgGroupFunction::calculate(PageItemDesignIntf* page)
|
||||
{
|
||||
QVariant res = QVariant();
|
||||
if (!page){
|
||||
foreach(QVariant value,values()){
|
||||
res=addition(res,value);
|
||||
if (!page) {
|
||||
foreach (QVariant value, values()) {
|
||||
res = addition(res, value);
|
||||
}
|
||||
} else {
|
||||
foreach (BandDesignIntf* band, page->bands()) {
|
||||
res = addition(res, m_valuesByBand.value(band));
|
||||
}
|
||||
}
|
||||
if (!res.isNull()&&(values().count()>0)){
|
||||
res=division(res,values().count());
|
||||
if (!res.isNull() && (values().count() > 0)) {
|
||||
res = division(res, values().count());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
QVariant MinGroupFunction::calculate(PageItemDesignIntf *page)
|
||||
QVariant MinGroupFunction::calculate(PageItemDesignIntf* page)
|
||||
{
|
||||
//TODO: check variant type
|
||||
// TODO: check variant type
|
||||
QVariant res = QVariant();
|
||||
if (!page){
|
||||
if (!values().empty()) res = values().at(0);
|
||||
foreach(QVariant value, values()){
|
||||
if (res.toDouble() > value.toDouble()) res = value;
|
||||
if (!page) {
|
||||
if (!values().empty())
|
||||
res = values().at(0);
|
||||
foreach (QVariant value, values()) {
|
||||
if (res.toDouble() > value.toDouble())
|
||||
res = value;
|
||||
}
|
||||
} else {
|
||||
if (!page->bands().empty()) res = m_valuesByBand.value(page->bands().at(0));
|
||||
if (!page->bands().empty())
|
||||
res = m_valuesByBand.value(page->bands().at(0));
|
||||
foreach (BandDesignIntf* band, page->bands()) {
|
||||
if (res.toDouble() > m_valuesByBand.value(band).toDouble()) res = m_valuesByBand.value(band);
|
||||
if (res.toDouble() > m_valuesByBand.value(band).toDouble())
|
||||
res = m_valuesByBand.value(band);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
QVariant MaxGroupFunction::calculate(PageItemDesignIntf *page)
|
||||
QVariant MaxGroupFunction::calculate(PageItemDesignIntf* page)
|
||||
{
|
||||
//TODO: check variant type
|
||||
// TODO: check variant type
|
||||
QVariant res = QVariant();
|
||||
|
||||
if (!page){
|
||||
if (!values().empty()) res = values().at(0);
|
||||
foreach(QVariant value, values()){
|
||||
if (res.toDouble() < value.toDouble()) res = value;
|
||||
if (!page) {
|
||||
if (!values().empty())
|
||||
res = values().at(0);
|
||||
foreach (QVariant value, values()) {
|
||||
if (res.toDouble() < value.toDouble())
|
||||
res = value;
|
||||
}
|
||||
} else {
|
||||
if (!page->bands().empty()) res = m_valuesByBand.value(page->bands().at(0));
|
||||
if (!page->bands().empty())
|
||||
res = m_valuesByBand.value(page->bands().at(0));
|
||||
foreach (BandDesignIntf* band, page->bands()) {
|
||||
if (res.toDouble() < m_valuesByBand.value(band).toDouble()) res = m_valuesByBand.value(band);
|
||||
if (res.toDouble() < m_valuesByBand.value(band).toDouble())
|
||||
res = m_valuesByBand.value(band);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
QVariant CountGroupFunction::calculate(PageItemDesignIntf *page){
|
||||
if (!page){
|
||||
QVariant CountGroupFunction::calculate(PageItemDesignIntf* page)
|
||||
{
|
||||
if (!page) {
|
||||
return values().count();
|
||||
} else {
|
||||
int res = 0;
|
||||
foreach (BandDesignIntf* band, page->bands()) {
|
||||
if (!m_valuesByBand.value(band).isNull()){
|
||||
if (!m_valuesByBand.value(band).isNull()) {
|
||||
res++;
|
||||
}
|
||||
}
|
||||
@@ -293,5 +313,4 @@ QVariant CountGroupFunction::calculate(PageItemDesignIntf *page){
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
Reference in New Issue
Block a user