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

192 lines
7.0 KiB
C
Raw Normal View History

2016-02-17 10:11:00 +03:00
/***************************************************************************
* This file is part of the Lime Report project *
2021-08-18 20:21:36 +03:00
* Copyright (C) 2021 by Alexander Arin *
2016-02-17 10:11:00 +03:00
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#ifndef LRGROUPFUNCTIONS_H
#define LRGROUPFUNCTIONS_H
#include <QString>
#include <QVariant>
#include <QVector>
namespace LimeReport {
2016-02-17 10:11:00 +03:00
class DataSourceManager;
class BandDesignIntf;
2018-03-14 11:22:03 +03:00
class PageItemDesignIntf;
2016-02-17 10:11:00 +03:00
class GroupFunction: public QObject {
2016-02-17 10:11:00 +03:00
Q_OBJECT
public:
enum DataType {
Variable,
Field,
Script,
ContentItem
};
GroupFunction(const QString& expression, const QString& dataBandName,
DataSourceManager* dataManager);
bool isValid() { return m_isValid; }
void setInvalid(QString message) { m_isValid = false, m_errorMessage = message; }
const QString& name() { return m_name; }
const QString& data() { return m_data; }
const QString& error() { return m_errorMessage; }
QVector<QVariant>& values() { return m_values; }
2018-03-14 11:22:03 +03:00
QHash<BandDesignIntf*, QVariant> m_valuesByBand;
const QString& dataBandName() { return m_dataBandName; }
virtual QVariant calculate(PageItemDesignIntf* page = 0) = 0;
2016-02-17 10:11:00 +03:00
public slots:
void slotBandRendered(BandDesignIntf* band);
void slotBandReRendered(BandDesignIntf* oldBand, BandDesignIntf* newBand);
2016-02-17 10:11:00 +03:00
protected:
void setName(const QString& value) { m_name = value; }
2016-02-17 10:11:00 +03:00
QVariant addition(QVariant value1, QVariant value2);
QVariant subtraction(QVariant value1, QVariant value2);
QVariant division(QVariant value1, QVariant value2);
QVariant multiplication(QVariant value1, QVariant value2);
2016-02-17 10:11:00 +03:00
private:
QString m_data;
QString m_name;
DataType m_dataType;
QString m_dataBandName;
QVector<QVariant> m_values;
DataSourceManager* m_dataManager;
bool m_isValid;
QString m_errorMessage;
};
class GroupFunctionCreator {
2016-02-17 10:11:00 +03:00
public:
virtual GroupFunction* createFunction(const QString&, const QString&, DataSourceManager*) = 0;
virtual ~GroupFunctionCreator() { }
2016-02-17 10:11:00 +03:00
};
class GroupFunctionFactory {
2016-02-17 10:11:00 +03:00
public:
void registerFunctionCreator(const QString& functionName, GroupFunctionCreator* creator)
{
m_creators.insert(functionName, creator);
2016-02-17 10:11:00 +03:00
}
QList<QString> functionNames() { return m_creators.keys(); }
GroupFunction* createGroupFunction(const QString& functionName, const QString& expression,
const QString& dataBandName, DataSourceManager* dataManager);
2016-02-17 10:11:00 +03:00
~GroupFunctionFactory();
2016-02-17 10:11:00 +03:00
private:
QMap<QString, GroupFunctionCreator*> m_creators;
2016-02-17 10:11:00 +03:00
};
class CountGroupFunction: public GroupFunction {
2016-02-17 10:11:00 +03:00
Q_OBJECT
public:
CountGroupFunction(const QString& expression, const QString& dataBandName,
DataSourceManager* dataManager):
GroupFunction(expression, dataBandName, dataManager)
{
setName("COUNT");
}
2016-02-17 10:11:00 +03:00
protected:
2018-03-14 11:22:03 +03:00
virtual QVariant calculate(PageItemDesignIntf* page = 0);
2016-02-17 10:11:00 +03:00
};
class SumGroupFunction: public GroupFunction {
2016-02-17 10:11:00 +03:00
Q_OBJECT
public:
SumGroupFunction(const QString& expression, const QString& dataBandName,
DataSourceManager* dataManager):
GroupFunction(expression, dataBandName, dataManager)
{
setName("SUM");
}
2016-02-17 10:11:00 +03:00
protected:
2018-03-14 11:22:03 +03:00
virtual QVariant calculate(PageItemDesignIntf* page = 0);
2016-02-17 10:11:00 +03:00
};
class AvgGroupFunction: public GroupFunction {
2016-02-17 10:11:00 +03:00
Q_OBJECT
public:
AvgGroupFunction(const QString& expression, const QString& dataBandName,
DataSourceManager* dataManager):
GroupFunction(expression, dataBandName, dataManager)
{
setName("AVG");
}
2016-02-17 10:11:00 +03:00
protected:
2018-03-14 11:22:03 +03:00
virtual QVariant calculate(PageItemDesignIntf* page = 0);
2016-02-17 10:11:00 +03:00
};
class MinGroupFunction: public GroupFunction {
2016-02-17 10:11:00 +03:00
Q_OBJECT
public:
MinGroupFunction(const QString& expression, const QString& dataBandName,
DataSourceManager* dataManager):
GroupFunction(expression, dataBandName, dataManager)
{
setName("MIN");
}
2016-02-17 10:11:00 +03:00
protected:
2018-03-14 11:22:03 +03:00
virtual QVariant calculate(PageItemDesignIntf* page = 0);
2016-02-17 10:11:00 +03:00
};
class MaxGroupFunction: public GroupFunction {
2016-02-17 10:11:00 +03:00
Q_OBJECT
public:
MaxGroupFunction(const QString& expression, const QString& dataBandName,
DataSourceManager* dataManager):
GroupFunction(expression, dataBandName, dataManager)
{
setName("MAX");
}
2016-02-17 10:11:00 +03:00
protected:
2018-03-14 11:22:03 +03:00
virtual QVariant calculate(PageItemDesignIntf* page = 0);
2016-02-17 10:11:00 +03:00
};
template <typename T> class ConstructorGroupFunctionCreator: public GroupFunctionCreator {
virtual GroupFunction* createFunction(const QString& expression, const QString& dataBandName,
DataSourceManager* dataManager);
2016-02-17 10:11:00 +03:00
};
template <typename T>
GroupFunction* ConstructorGroupFunctionCreator<T>::createFunction(const QString& expression,
const QString& dataBandName,
DataSourceManager* dataManager)
2016-02-17 10:11:00 +03:00
{
return new T(expression, dataBandName, dataManager);
}
} // namespace LimeReport
2016-02-17 10:11:00 +03:00
#endif // LRGROUPFUNCTIONS_H