LimeReport/limereport/lrvariablesholder.h

127 lines
5.9 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. *
****************************************************************************/
2017-09-27 13:04:56 +03:00
#ifndef LRVARIABLEHOLDER_H
#define LRVARIABLEHOLDER_H
2016-02-17 10:11:00 +03:00
#include <QObject>
#include <QMap>
#include <QVector>
#include <QVariant>
#include "lrglobal.h"
namespace LimeReport{
class VarDesc : public QObject{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QVariant value READ value WRITE setValue)
Q_PROPERTY(bool isMandatory READ isMandatory WRITE setMandatory)
Q_PROPERTY(int dataType READ readDataTypeProperty WRITE setDataTypeProperty)
2016-02-17 10:11:00 +03:00
public:
2017-12-11 16:48:00 +03:00
VarDesc() : m_dataType(Enums::Undefined), m_mandatory(false){}
2016-06-07 00:44:21 +03:00
enum VarType {System, User, Report};
2016-02-17 10:11:00 +03:00
void setVarType(VarType value){m_varType=value;}
VarType varType(){return m_varType;}
void setRenderPass(RenderPass value){m_varPass=value;}
RenderPass renderPass(){return m_varPass;}
void setName(QString value){m_name=value;}
QString name(){return m_name;}
void setValue(QVariant value){m_value=value;}
QVariant value(){return m_value;}
VariableDataType dataType() const;
void setDataType(const VariableDataType& dataType);
int readDataTypeProperty() const;
void setDataTypeProperty(int value);
bool isMandatory() const;
void setMandatory(bool isMandatory);
void initFrom(VarDesc* value);
2016-02-17 10:11:00 +03:00
private:
VarType m_varType;
RenderPass m_varPass;
QString m_name;
QVariant m_value;
VariableDataType m_dataType;
bool m_mandatory;
2016-02-17 10:11:00 +03:00
};
class IVariablesContainer
{
public:
virtual ~IVariablesContainer(){}
virtual void addVariable(const QString& name, const QVariant &value, VarDesc::VarType type=VarDesc::User, RenderPass pass=FirstPass) = 0;
virtual void deleteVariable(const QString& name) = 0;
virtual void changeVariable(const QString& name, const QVariant &value) = 0;
virtual void clearUserVariables() = 0;
virtual QVariant variable(const QString& name) = 0;
virtual VarDesc::VarType variableType(const QString& name) = 0;
virtual RenderPass variablePass(const QString& name) = 0;
virtual bool containsVariable(const QString& name) = 0;
virtual QStringList variableNames() = 0;
virtual bool variableIsMandatory(const QString& name) = 0;
virtual void setVarableMandatory(const QString& name, bool value) = 0;
virtual VariableDataType variableDataType(const QString& name) = 0;
virtual void setVariableDataType(const QString& name, VariableDataType value) = 0;
2016-02-17 10:11:00 +03:00
};
2016-06-07 00:44:21 +03:00
class VariablesHolder : public QObject, public IVariablesContainer
2016-02-17 10:11:00 +03:00
{
Q_OBJECT
public:
2016-06-07 00:44:21 +03:00
explicit VariablesHolder(QObject *parent = 0);
~VariablesHolder();
2016-02-17 10:11:00 +03:00
void addVariable(const QString &name, const QVariant &value, VarDesc::VarType type=VarDesc::User, RenderPass pass=FirstPass);
void deleteVariable(const QString &name);
void changeVariable(const QString &name, const QVariant &value);
void clearUserVariables();
QVariant variable(const QString &name);
VarDesc::VarType variableType(const QString& name);
RenderPass variablePass(const QString &name);
bool containsVariable(const QString &name);
QStringList variableNames();
int variablesCount();
VarDesc* variableByName(const QString& name);
VarDesc* variableAt(int index);
bool variableIsMandatory(const QString& name);
void setVarableMandatory(const QString &name, bool value);
VariableDataType variableDataType(const QString& name);
void setVariableDataType(const QString &name, VariableDataType value);
2016-02-17 10:11:00 +03:00
signals:
void variableHasBeenAdded(const QString& variableName);
void variableHasBeenChanged(const QString& variableName);
void variableHasBennDeleted(const QString& variableName);
2016-02-17 10:11:00 +03:00
private:
QMap<QString,VarDesc*> m_varNames;
QList<VarDesc*> m_userVariables;
};
}// namespace LimeReport
#endif // VARIABLEHOLDER_H