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. *
|
|
|
|
****************************************************************************/
|
|
|
|
#include "lrvariablesholder.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
namespace LimeReport{
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
VariablesHolder::VariablesHolder(QObject *parent) :
|
2016-02-17 10:11:00 +03:00
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
VariablesHolder::~VariablesHolder()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
QMap<QString,VarDesc*>::iterator it = m_varNames.begin();
|
|
|
|
while(it!=m_varNames.end()){
|
|
|
|
delete *it;
|
2019-06-28 13:08:33 +03:00
|
|
|
++it;
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
m_varNames.clear();
|
|
|
|
m_userVariables.clear();
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
void VariablesHolder::addVariable(const QString& name, const QVariant& value, VarDesc::VarType type, RenderPass pass)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
if (!m_varNames.contains(name)){
|
|
|
|
VarDesc* varValue = new VarDesc;
|
|
|
|
varValue->setName(name);
|
|
|
|
varValue->setValue(value);
|
|
|
|
varValue->setVarType(type);
|
|
|
|
varValue->setRenderPass(pass);
|
|
|
|
m_varNames.insert(name,varValue);
|
2016-06-29 21:24:54 +03:00
|
|
|
if (type==VarDesc::Report)
|
2016-02-17 10:11:00 +03:00
|
|
|
m_userVariables.append(varValue);
|
2017-09-19 21:02:55 +03:00
|
|
|
emit variableHasBeenAdded(name);
|
2016-02-17 10:11:00 +03:00
|
|
|
} else {
|
2017-06-28 16:58:01 +03:00
|
|
|
throw ReportError(tr("variable with name ")+name+tr(" already exists!"));
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
QVariant VariablesHolder::variable(const QString &name)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
if (m_varNames.contains(name))
|
|
|
|
return m_varNames.value(name)->value();
|
|
|
|
else return QVariant();
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
VarDesc::VarType VariablesHolder::variableType(const QString &name)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
if (m_varNames.contains(name))
|
|
|
|
return m_varNames.value(name)->varType();
|
2017-06-28 16:58:01 +03:00
|
|
|
else throw ReportError(tr("variable with name ")+name+tr(" does not exists!"));
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
void VariablesHolder::deleteVariable(const QString &name)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
if (m_varNames.contains(name)) {
|
|
|
|
m_userVariables.removeOne(m_varNames.value(name));
|
|
|
|
delete m_varNames.value(name);
|
|
|
|
m_varNames.remove(name);
|
2017-09-19 21:02:55 +03:00
|
|
|
emit variableHasBennDeleted(name);
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
void VariablesHolder::changeVariable(const QString &name, const QVariant &value)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
if(m_varNames.contains(name)) {
|
|
|
|
m_varNames.value(name)->setValue(value);
|
2017-09-19 21:02:55 +03:00
|
|
|
emit variableHasBeenChanged(name);
|
2016-02-17 10:11:00 +03:00
|
|
|
} else
|
2017-06-28 16:58:01 +03:00
|
|
|
throw ReportError(tr("variable with name ")+name+tr(" does not exists!"));
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
void VariablesHolder::clearUserVariables()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
QMap<QString,VarDesc*>::iterator it = m_varNames.begin();
|
|
|
|
while (it != m_varNames.end()){
|
2016-06-07 00:44:21 +03:00
|
|
|
if (it.value()->varType()==VarDesc::User ||
|
|
|
|
it.value()->varType()==VarDesc::Report){
|
2016-02-17 10:11:00 +03:00
|
|
|
m_userVariables.removeAll(it.value());
|
|
|
|
delete it.value();
|
|
|
|
it = m_varNames.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
bool VariablesHolder::containsVariable(const QString &name)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
return m_varNames.contains(name);
|
|
|
|
}
|
|
|
|
|
2017-09-26 00:19:59 +03:00
|
|
|
int VariablesHolder::variablesCount()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
return m_userVariables.count();
|
|
|
|
}
|
|
|
|
|
2017-09-26 00:19:59 +03:00
|
|
|
VarDesc* VariablesHolder::variableByName(const QString& name)
|
|
|
|
{
|
|
|
|
if (m_varNames.contains(name))
|
|
|
|
return m_varNames.value(name);
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDesc *VariablesHolder::variableAt(int index)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
return m_userVariables.at(index);
|
|
|
|
}
|
|
|
|
|
2017-09-26 00:19:59 +03:00
|
|
|
bool VariablesHolder::variableIsMandatory(const QString& name)
|
|
|
|
{
|
|
|
|
if (m_varNames.contains(name))
|
|
|
|
return m_varNames.value(name)->isMandatory();
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VariablesHolder::setVarableMandatory(const QString& name, bool value)
|
|
|
|
{
|
|
|
|
if (m_varNames.contains(name))
|
|
|
|
m_varNames.value(name)->setMandatory(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableDataType VariablesHolder::variableDataType(const QString& name)
|
|
|
|
{
|
|
|
|
if (m_varNames.contains(name))
|
|
|
|
return m_varNames.value(name)->dataType();
|
|
|
|
else return Enums::Undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VariablesHolder::setVariableDataType(const QString& name, VariableDataType value)
|
|
|
|
{
|
|
|
|
if (m_varNames.contains(name))
|
|
|
|
m_varNames.value(name)->setDataType(value);
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
QStringList VariablesHolder::variableNames()
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
foreach(QString varName,m_varNames.keys()){
|
|
|
|
result<<varName;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-06-07 00:44:21 +03:00
|
|
|
RenderPass VariablesHolder::variablePass(const QString &name)
|
2016-02-17 10:11:00 +03:00
|
|
|
{
|
|
|
|
if (m_varNames.contains(name))
|
|
|
|
return m_varNames.value(name)->renderPass();
|
2017-06-28 16:58:01 +03:00
|
|
|
else throw ReportError(tr("variable with name ")+name+tr(" does not exists!"));
|
2016-02-17 10:11:00 +03:00
|
|
|
}
|
|
|
|
|
2017-09-26 00:19:59 +03:00
|
|
|
bool VarDesc::isMandatory() const
|
|
|
|
{
|
|
|
|
return m_mandatory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarDesc::setMandatory(bool mandatory)
|
|
|
|
{
|
|
|
|
m_mandatory = mandatory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarDesc::initFrom(VarDesc* value)
|
|
|
|
{
|
|
|
|
m_mandatory = value->isMandatory();
|
|
|
|
m_dataType = value->dataType();
|
|
|
|
}
|
|
|
|
|
|
|
|
VariableDataType VarDesc::dataType() const
|
|
|
|
{
|
|
|
|
return m_dataType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarDesc::setDataType(const VariableDataType& dataType)
|
|
|
|
{
|
|
|
|
m_dataType = dataType;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VarDesc::readDataTypeProperty() const
|
|
|
|
{
|
|
|
|
return static_cast<int>(m_dataType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VarDesc::setDataTypeProperty(int value)
|
|
|
|
{
|
|
|
|
m_dataType = static_cast<VariableDataType>(value);
|
|
|
|
}
|
|
|
|
|
2016-02-17 10:11:00 +03:00
|
|
|
}// namespace LimeReport
|