From f7d8a5050a7d60b371348706e799a2c745ee1752 Mon Sep 17 00:00:00 2001 From: Arin Alex Date: Tue, 2 Aug 2016 01:33:26 +0300 Subject: [PATCH] Variables access has been fixed --- limereport/databrowser/lrdatabrowsertree.cpp | 3 ++ limereport/lrdatasourcemanager.cpp | 10 ++++-- limereport/lritemdesignintf.cpp | 34 ++++++++++++-------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/limereport/databrowser/lrdatabrowsertree.cpp b/limereport/databrowser/lrdatabrowsertree.cpp index e5d8d79..9128bf4 100644 --- a/limereport/databrowser/lrdatabrowsertree.cpp +++ b/limereport/databrowser/lrdatabrowsertree.cpp @@ -45,6 +45,9 @@ QMimeData *DataBrowserTree::mimeData(const QList items) const if (items.at(0)->type()==Variable){ result->setText("variable:$V{"+items.at(0)->text(0)+"}"); } + if (items.at(0)->type()==ExternalVariable){ + result->setText("variable:$V{"+items.at(0)->text(0)+"}"); + } return result; } diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 0c07121..1b228ea 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -208,6 +208,11 @@ void DataSourceModel::updateModel() foreach (QString name, m_dataManager->variableNames()){ vars->addChild(name,DataNode::Variable,QIcon(":/report/images/value")); } + + vars = m_rootNode->addChild(tr("External variables"),DataNode::Variables,QIcon(":/report/images/folder")); + foreach (QString name, m_dataManager->namesOfUserVariables()){ + vars->addChild(name,DataNode::Variable,QIcon(":/report/images/value")); + } } DataSourceManager::DataSourceManager(QObject *parent) : @@ -1217,8 +1222,9 @@ QVariant DataSourceManager::variable(const QString &variableName) RenderPass DataSourceManager::variablePass(const QString &name) { - - return (m_reportVariables.variablePass(name)==FirstPass)?FirstPass:SecondPass; + if (m_userVariables.containsVariable(name)) + return m_userVariables.variablePass(name); + return m_reportVariables.variablePass(name); } bool DataSourceManager::variableIsSystem(const QString &name) diff --git a/limereport/lritemdesignintf.cpp b/limereport/lritemdesignintf.cpp index 424c569..2a83bc3 100644 --- a/limereport/lritemdesignintf.cpp +++ b/limereport/lritemdesignintf.cpp @@ -172,20 +172,28 @@ QString ContentItemDesignIntf::expandUserVariables(QString context, RenderPass p QString variable=rx.cap(1); pos += rx.matchedLength(); if (dataManager->containsVariable(variable) ){ - if (pass==dataManager->variablePass(variable)){ - m_varValue = dataManager->variable(variable); - switch (expandType){ - case EscapeSymbols: - context.replace(rx.cap(0),escapeSimbols(m_varValue.toString())); - break; - case NoEscapeSymbols: - context.replace(rx.cap(0),m_varValue.toString()); - break; - case ReplaceHTMLSymbols: - context.replace(rx.cap(0),replaceHTMLSymbols(m_varValue.toString())); - break; + try { + if (pass==dataManager->variablePass(variable)){ + m_varValue = dataManager->variable(variable); + switch (expandType){ + case EscapeSymbols: + context.replace(rx.cap(0),escapeSimbols(m_varValue.toString())); + break; + case NoEscapeSymbols: + context.replace(rx.cap(0),m_varValue.toString()); + break; + case ReplaceHTMLSymbols: + context.replace(rx.cap(0),replaceHTMLSymbols(m_varValue.toString())); + break; + } + pos=0; } - pos=0; + } catch (ReportError e){ + dataManager->putError(e.what()); + if (!reportSettings() || reportSettings()->suppressAbsentFieldsAndVarsWarnings()) + context.replace(rx.cap(0),e.what()); + else + context.replace(rx.cap(0),""); } } else { QString error;