0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +03:00

Merge branch 'develop' into feature/ScriptEditor

This commit is contained in:
Arin Alexander 2017-09-19 22:20:44 +03:00
commit 219b4ad678
6 changed files with 84 additions and 3 deletions

View File

@ -229,6 +229,17 @@ DataSourceManager::DataSourceManager(QObject *parent) :
setSystemVariable(QLatin1String("#IS_LAST_PAGEFOOTER"),false,FirstPass); setSystemVariable(QLatin1String("#IS_LAST_PAGEFOOTER"),false,FirstPass);
setSystemVariable(QLatin1String("#IS_FIRST_PAGEFOOTER"),false,FirstPass); setSystemVariable(QLatin1String("#IS_FIRST_PAGEFOOTER"),false,FirstPass);
m_datasourcesModel.setDataSourceManager(this); 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 QString DataSourceManager::defaultDatabasePath() const
@ -1188,6 +1199,7 @@ void DataSourceManager::changeVariable(const QString& name,const QVariant& value
if (m_reportVariables.containsVariable(name)){ if (m_reportVariables.containsVariable(name)){
m_reportVariables.changeVariable(name,value); m_reportVariables.changeVariable(name,value);
} }
} }
void DataSourceManager::setSystemVariable(const QString &name, const QVariant &value, RenderPass pass) void DataSourceManager::setSystemVariable(const QString &name, const QVariant &value, RenderPass pass)
@ -1236,6 +1248,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<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) void DataSourceManager::clear(ClearMethod method)
{ {
DataSourcesMap::iterator dit; DataSourcesMap::iterator dit;
@ -1386,6 +1424,15 @@ QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const
return QVariant(); 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) QVariant DataSourceManager::variable(const QString &variableName)
{ {
if (m_userVariables.containsVariable(variableName)) if (m_userVariables.containsVariable(variableName))

View File

@ -168,6 +168,7 @@ public:
const QString& keyFieldName, const QString& keyFieldName,
QVariant keyValue QVariant keyValue
); );
void reopenDatasource(const QString& datasourceName);
QString extractDataSource(const QString& fieldName); QString extractDataSource(const QString& fieldName);
QString extractFieldName(const QString& fieldName); QString extractFieldName(const QString& fieldName);
@ -231,9 +232,12 @@ protected:
void setLastError(const QString& value); void setLastError(const QString& value);
void invalidateLinkedDatasources(QString datasourceName); void invalidateLinkedDatasources(QString datasourceName);
bool checkConnection(QSqlDatabase db); bool checkConnection(QSqlDatabase db);
void invalidateQueriesContainsVariable(const QString& variableName);
private slots: private slots:
void slotConnectionRenamed(const QString& oldName,const QString& newName); void slotConnectionRenamed(const QString& oldName,const QString& newName);
void slotQueryTextChanged(const QString& queryName, const QString& queryText); void slotQueryTextChanged(const QString& queryName, const QString& queryText);
void slotVariableHasBeenAdded(const QString& variableName);
void slotVariableHasBeenChanged(const QString& variableName);
private: private:
explicit DataSourceManager(QObject *parent = 0); explicit DataSourceManager(QObject *parent = 0);
bool initAndOpenDB(QSqlDatabase &db, ConnectionDesc &connectionDesc); bool initAndOpenDB(QSqlDatabase &db, ConnectionDesc &connectionDesc);

View File

@ -813,6 +813,21 @@ bool ScriptEngineManager::createClearTableOfContensFunction()
return addFunction(fd); 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() ScriptEngineManager::ScriptEngineManager()
:m_model(0), m_dataManager(0) :m_model(0), m_dataManager(0)
{ {
@ -850,6 +865,7 @@ ScriptEngineManager::ScriptEngineManager()
#endif #endif
createAddTableOfContensItemFunction(); createAddTableOfContensItemFunction();
createClearTableOfContensFunction(); createClearTableOfContensFunction();
createReopenDatasourceFunction();
m_model = new ScriptEngineModel(this); m_model = new ScriptEngineModel(this);
} }
@ -1516,6 +1532,12 @@ QVariant ScriptFunctionsManager::getFieldByKeyField(const QString& datasourceNam
return dm->fieldDataByKey(datasourceName, valueFieldName, keyFieldName, keyValue); 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) void ScriptFunctionsManager::addTableOfContensItem(const QString& uniqKey, const QString& content, int indent)
{ {
scriptEngineManager()->addTableOfContensItem(uniqKey, content, indent); scriptEngineManager()->addTableOfContensItem(uniqKey, content, indent);

View File

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

View File

@ -61,6 +61,7 @@ void VariablesHolder::addVariable(const QString& name, const QVariant& value, Va
m_varNames.insert(name,varValue); m_varNames.insert(name,varValue);
if (type==VarDesc::Report) if (type==VarDesc::Report)
m_userVariables.append(varValue); m_userVariables.append(varValue);
emit variableHasBeenAdded(name);
} else { } else {
throw ReportError(tr("variable with name ")+name+tr(" already exists!")); 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)); m_userVariables.removeOne(m_varNames.value(name));
delete m_varNames.value(name); delete m_varNames.value(name);
m_varNames.remove(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)) { if(m_varNames.contains(name)) {
m_varNames.value(name)->setValue(value); m_varNames.value(name)->setValue(value);
emit variableHasBeenChanged(name);
} else } else
throw ReportError(tr("variable with name ")+name+tr(" does not exists!")); throw ReportError(tr("variable with name ")+name+tr(" does not exists!"));
} }

View File

@ -92,6 +92,9 @@ public:
int userVariablesCount(); int userVariablesCount();
VarDesc* userVariableAt(int index); VarDesc* userVariableAt(int index);
signals: signals:
void variableHasBeenAdded(const QString& variableName);
void variableHasBeenChanged(const QString& variableName);
void variableHasBennDeleted(const QString& variableName);
private: private:
QMap<QString,VarDesc*> m_varNames; QMap<QString,VarDesc*> m_varNames;
QList<VarDesc*> m_userVariables; QList<VarDesc*> m_userVariables;