0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

The update of data sources was added if they contain changed variables

This commit is contained in:
Arin Alexander 2017-09-19 21:02:55 +03:00
parent c9b6078fa8
commit 1af031f19c
6 changed files with 82 additions and 3 deletions

View File

@ -229,6 +229,17 @@ DataSourceManager::DataSourceManager(QObject *parent) :
setSystemVariable(QLatin1String("#IS_LAST_PAGEFOOTER"),false,FirstPass);
setSystemVariable(QLatin1String("#IS_FIRST_PAGEFOOTER"),false,FirstPass);
m_datasourcesModel.setDataSourceManager(this);
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)));
}
QString DataSourceManager::defaultDatabasePath() const
@ -1188,6 +1199,7 @@ void DataSourceManager::changeVariable(const QString& name,const QVariant& value
if (m_reportVariables.containsVariable(name)){
m_reportVariables.changeVariable(name,value);
}
}
void DataSourceManager::setSystemVariable(const QString &name, const QVariant &value, RenderPass pass)
@ -1236,6 +1248,30 @@ void DataSourceManager::slotQueryTextChanged(const QString &queryName, const QSt
}
}
void DataSourceManager::invalidateQueriesContainsVariable(const QString& variableName)
{
foreach (const QString& datasourceName, dataSourceNames()){
QueryHolder* holder = dynamic_cast<QueryHolder*>(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;
@ -1386,6 +1422,15 @@ QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const
return QVariant();
}
void DataSourceManager::reopenDatasource(const QString& datasourceName)
{
QueryHolder* qh = dynamic_cast<QueryHolder*>(dataSourceHolder(datasourceName));
if (qh){
qh->invalidate(designTime()?IDataSource::DESIGN_MODE:IDataSource::RENDER_MODE);
invalidateChildren(datasourceName);
}
}
QVariant DataSourceManager::variable(const QString &variableName)
{
if (m_userVariables.containsVariable(variableName))

View File

@ -168,6 +168,7 @@ public:
const QString& keyFieldName,
QVariant keyValue
);
void reopenDatasource(const QString& datasourceName);
QString extractDataSource(const QString& fieldName);
QString extractFieldName(const QString& fieldName);
@ -231,9 +232,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);

View File

@ -813,6 +813,21 @@ bool ScriptEngineManager::createClearTableOfContensFunction()
return addFunction(fd);
}
bool ScriptEngineManager::createReopenDatasourceFunction()
{
JSFunctionDesc fd;
fd.setManager(m_functionManager);
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
fd.setCategory(tr("GENERAL"));
fd.setName("reopenDatasource");
fd.setDescription("reopenDatasource(\""+tr("datasourceName")+"\")");
fd.setScriptWrapper(QString("function reopenDatasource(datasourceName){"
"return %1.reopenDatasource(datasourceName);}"
).arg(LimeReport::Const::FUNCTION_MANAGER_NAME)
);
return addFunction(fd);
}
ScriptEngineManager::ScriptEngineManager()
:m_model(0), m_dataManager(0)
{
@ -850,6 +865,7 @@ ScriptEngineManager::ScriptEngineManager()
#endif
createAddTableOfContensItemFunction();
createClearTableOfContensFunction();
createReopenDatasourceFunction();
m_model = new ScriptEngineModel(this);
}
@ -1516,6 +1532,12 @@ QVariant ScriptFunctionsManager::getFieldByKeyField(const QString& datasourceNam
return dm->fieldDataByKey(datasourceName, valueFieldName, keyFieldName, keyValue);
}
void ScriptFunctionsManager::reopenDatasource(const QString& datasourceName)
{
DataSourceManager* dm = scriptEngineManager()->dataManager();
return dm->reopenDatasource(datasourceName);
}
void ScriptFunctionsManager::addTableOfContensItem(const QString& uniqKey, const QString& content, int indent)
{
scriptEngineManager()->addTableOfContensItem(uniqKey, content, indent);

View File

@ -319,6 +319,7 @@ public:
Q_INVOKABLE QVariant getVariable(const QString& name);
Q_INVOKABLE QVariant getField(const QString& field);
Q_INVOKABLE QVariant getFieldByKeyField(const QString& datasourceName, const QString& valueFieldName, const QString& keyFieldName, QVariant keyValue);
Q_INVOKABLE void reopenDatasource(const QString& datasourceName);
Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);}
Q_INVOKABLE void addTableOfContensItem(const QString& uniqKey, const QString& content, int indent = 0);
Q_INVOKABLE void clearTableOfContens();
@ -390,6 +391,7 @@ private:
bool createGetFieldByKeyFunction();
bool createAddTableOfContensItemFunction();
bool createClearTableOfContensFunction();
bool createReopenDatasourceFunction();
private:
ScriptEngineManager();
ScriptEngineType* m_scriptEngine;

View File

@ -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!"));
}

View File

@ -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<QString,VarDesc*> m_varNames;
QList<VarDesc*> m_userVariables;