mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-10-02 11:55:00 +03:00
Change to subforder project model.
This commit is contained in:
147
limereport/lrvariablesholder.cpp
Normal file
147
limereport/lrvariablesholder.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/***************************************************************************
|
||||
* This file is part of the Lime Report project *
|
||||
* Copyright (C) 2015 by Alexander Arin *
|
||||
* 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{
|
||||
|
||||
AVariablesHolder::AVariablesHolder(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
AVariablesHolder::~AVariablesHolder()
|
||||
{
|
||||
QMap<QString,VarDesc*>::iterator it = m_varNames.begin();
|
||||
while(it!=m_varNames.end()){
|
||||
delete *it;
|
||||
it++;
|
||||
}
|
||||
m_varNames.clear();
|
||||
m_userVariables.clear();
|
||||
}
|
||||
|
||||
void AVariablesHolder::addVariable(const QString& name, const QVariant& value, VarDesc::VarType type, RenderPass pass)
|
||||
{
|
||||
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);
|
||||
if (type==VarDesc::User)
|
||||
m_userVariables.append(varValue);
|
||||
} else {
|
||||
throw ReportError(tr("variable with name ")+name+tr(" already exists !!"));
|
||||
}
|
||||
}
|
||||
|
||||
QVariant AVariablesHolder::variable(const QString &name)
|
||||
{
|
||||
if (m_varNames.contains(name))
|
||||
return m_varNames.value(name)->value();
|
||||
else return QVariant();
|
||||
}
|
||||
|
||||
VarDesc::VarType AVariablesHolder::variableType(const QString &name)
|
||||
{
|
||||
if (m_varNames.contains(name))
|
||||
return m_varNames.value(name)->varType();
|
||||
else throw ReportError(tr("variable with name ")+name+tr(" does not exists !!"));
|
||||
}
|
||||
|
||||
void AVariablesHolder::deleteVariable(const QString &name)
|
||||
{
|
||||
if (m_varNames.contains(name)) {
|
||||
m_userVariables.removeOne(m_varNames.value(name));
|
||||
delete m_varNames.value(name);
|
||||
m_varNames.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
void AVariablesHolder::changeVariable(const QString &name, const QVariant &value)
|
||||
{
|
||||
if(m_varNames.contains(name)) {
|
||||
m_varNames.value(name)->setValue(value);
|
||||
} else
|
||||
throw ReportError(tr("variable with name ")+name+tr(" does not exists !!"));
|
||||
}
|
||||
|
||||
void AVariablesHolder::clearUserVariables()
|
||||
{
|
||||
QMap<QString,VarDesc*>::iterator it = m_varNames.begin();
|
||||
while (it != m_varNames.end()){
|
||||
if (it.value()->varType()==VarDesc::User){
|
||||
m_userVariables.removeAll(it.value());
|
||||
delete it.value();
|
||||
it = m_varNames.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool AVariablesHolder::containsVariable(const QString &name)
|
||||
{
|
||||
return m_varNames.contains(name);
|
||||
}
|
||||
|
||||
int AVariablesHolder::userVariablesCount()
|
||||
{
|
||||
return m_userVariables.count();
|
||||
}
|
||||
|
||||
VarDesc *AVariablesHolder::userVariableAt(int index)
|
||||
{
|
||||
return m_userVariables.at(index);
|
||||
}
|
||||
|
||||
QStringList AVariablesHolder::variableNames()
|
||||
{
|
||||
QStringList result;
|
||||
foreach(QString varName,m_varNames.keys()){
|
||||
result<<varName;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
RenderPass AVariablesHolder::variablePass(const QString &name)
|
||||
{
|
||||
if (m_varNames.contains(name))
|
||||
return m_varNames.value(name)->renderPass();
|
||||
else throw ReportError(tr("variable with name ")+name+tr(" does not exists !!"));
|
||||
}
|
||||
|
||||
}// namespace LimeReport
|
Reference in New Issue
Block a user