diff --git a/include/lrglobal.h b/include/lrglobal.h index 3c9af32..1c501d5 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -76,6 +76,7 @@ namespace Const{ const qreal SELECTION_OPACITY = 0.3; const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}"; const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^{}]*)\\s*\\}"; + const QString NAMED_VARIABLE_RX = "\\$V\\s*\\{\\s*(%1)\\s*\\}"; const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}"; //const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(((?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))(\\w+\\.?\\w+)((?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,\\s*\\\"(\\w+)\\\"\\s*\\)"; diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 6ff7d9e..365455e 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -228,6 +228,16 @@ DataSourceManager::DataSourceManager(QObject *parent) : setSystemVariable(QLatin1String("#PAGE_COUNT"),0,SecondPass); setSystemVariable(QLatin1String("#IS_LAST_PAGEFOOTER"),false,FirstPass); setSystemVariable(QLatin1String("#IS_FIRST_PAGEFOOTER"),false,FirstPass); + + connect(&m_reportVariables, SIGNAL(variableHasBeenAdded(QString)), + this, SLOT(slotVariableHasBeenAdded(QString)) ); + connect(&m_reportVariables, SIGNAL(variableHasBeenChanged(QString)), + this, SLOT(slotVariableHasBeenChanged(QString))); + connect(&m_userVariables, SIGNAL(variableHasBeenAdded(QString)), + this, SLOT(slotVariableHasBeenAdded(QString)) ); + connect(&m_userVariables, SIGNAL(variableHasBeenChanged(QString)), + this, SLOT(slotVariableHasBeenChanged(QString))); + m_datasourcesModel.setDataSourceManager(this); } @@ -1235,6 +1245,32 @@ void DataSourceManager::slotQueryTextChanged(const QString &queryName, const QSt } } +void DataSourceManager::invalidateQueriesContainsVariable(const QString& variableName) +{ + if (!variableIsSystem(variableName)){ + foreach (const QString& datasourceName, dataSourceNames()){ + QueryHolder* holder = dynamic_cast(m_datasources.value(datasourceName)); + if (holder){ + QRegExp rx(QString(Const::NAMED_VARIABLE_RX).arg(variableName)); + if (holder->queryText().contains(rx)) + holder->invalidate(designTime()?IDataSource::DESIGN_MODE:IDataSource::RENDER_MODE); + } + } + } +} + +void DataSourceManager::slotVariableHasBeenAdded(const QString& variableName) +{ + //qDebug()<< "variable has been added"<< variableName; + invalidateQueriesContainsVariable(variableName); +} + +void DataSourceManager::slotVariableHasBeenChanged(const QString& variableName) +{ + //qDebug()<< "variable has been changed"<< variableName; + invalidateQueriesContainsVariable(variableName); +} + void DataSourceManager::clear(ClearMethod method) { DataSourcesMap::iterator dit; diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index ea77064..fabb694 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -224,9 +224,12 @@ protected: void setLastError(const QString& value); void invalidateLinkedDatasources(QString datasourceName); bool checkConnection(QSqlDatabase db); + void invalidateQueriesContainsVariable(const QString& variableName); private slots: void slotConnectionRenamed(const QString& oldName,const QString& newName); void slotQueryTextChanged(const QString& queryName, const QString& queryText); + void slotVariableHasBeenAdded(const QString& variableName); + void slotVariableHasBeenChanged(const QString& variableName); private: explicit DataSourceManager(QObject *parent = 0); bool initAndOpenDB(QSqlDatabase &db, ConnectionDesc &connectionDesc); diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index 3c9af32..1c501d5 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -76,6 +76,7 @@ namespace Const{ const qreal SELECTION_OPACITY = 0.3; const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}"; const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^{}]*)\\s*\\}"; + const QString NAMED_VARIABLE_RX = "\\$V\\s*\\{\\s*(%1)\\s*\\}"; const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}"; //const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(((?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))(\\w+\\.?\\w+)((?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,\\s*\\\"(\\w+)\\\"\\s*\\)"; diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 866c4c5..3845a54 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -216,7 +216,11 @@ QScriptValue setVariable(QScriptContext* pcontext, QScriptEngine* /*pengine*/){ ScriptEngineManager* sm = qscriptvalue_cast(pcontext->callee().data()); DataSourceManager* dm = sm->dataManager(); - dm->changeVariable(name,value); + if (dm->containsVariable(name)) + dm->changeVariable(name,value); + else + dm->addVariable(name, value); + return QScriptValue(); } diff --git a/limereport/lrvariablesholder.cpp b/limereport/lrvariablesholder.cpp index dd46b4e..9cdf630 100644 --- a/limereport/lrvariablesholder.cpp +++ b/limereport/lrvariablesholder.cpp @@ -61,6 +61,7 @@ void VariablesHolder::addVariable(const QString& name, const QVariant& value, Va m_varNames.insert(name,varValue); if (type==VarDesc::Report) m_userVariables.append(varValue); + emit variableHasBeenAdded(name); } else { throw ReportError(tr("variable with name ")+name+tr(" already exists!")); } @@ -86,6 +87,7 @@ void VariablesHolder::deleteVariable(const QString &name) m_userVariables.removeOne(m_varNames.value(name)); delete m_varNames.value(name); m_varNames.remove(name); + emit variableHasBennDeleted(name); } } @@ -93,6 +95,7 @@ void VariablesHolder::changeVariable(const QString &name, const QVariant &value) { if(m_varNames.contains(name)) { m_varNames.value(name)->setValue(value); + emit variableHasBeenChanged(name); } else throw ReportError(tr("variable with name ")+name+tr(" does not exists!")); } diff --git a/limereport/lrvariablesholder.h b/limereport/lrvariablesholder.h index ede1ac6..e375ea8 100644 --- a/limereport/lrvariablesholder.h +++ b/limereport/lrvariablesholder.h @@ -92,6 +92,9 @@ public: int userVariablesCount(); VarDesc* userVariableAt(int index); signals: + void variableHasBeenAdded(const QString& variableName); + void variableHasBeenChanged(const QString& variableName); + void variableHasBennDeleted(const QString& variableName); private: QMap m_varNames; QList m_userVariables;