Finish 1.4.41

This commit is contained in:
Arin Alexander 2017-09-19 22:00:59 +03:00
commit 2a6fae262b
7 changed files with 52 additions and 1 deletions

View File

@ -76,6 +76,7 @@ namespace Const{
const qreal SELECTION_OPACITY = 0.3; const qreal SELECTION_OPACITY = 0.3;
const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}"; const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}";
const QString VARIABLE_RX = "\\$V\\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 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*\\)"; //const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(((?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))(\\w+\\.?\\w+)((?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,\\s*\\\"(\\w+)\\\"\\s*\\)";

View File

@ -228,6 +228,16 @@ DataSourceManager::DataSourceManager(QObject *parent) :
setSystemVariable(QLatin1String("#PAGE_COUNT"),0,SecondPass); setSystemVariable(QLatin1String("#PAGE_COUNT"),0,SecondPass);
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);
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); 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<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;

View File

@ -224,9 +224,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

@ -76,6 +76,7 @@ namespace Const{
const qreal SELECTION_OPACITY = 0.3; const qreal SELECTION_OPACITY = 0.3;
const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}"; const QString FIELD_RX = "\\$D\\s*\\{\\s*([^{}]*)\\s*\\}";
const QString VARIABLE_RX = "\\$V\\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 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*\\)"; //const QString GROUP_FUNCTION_PARAM_RX = "\\(\\s*(((?:\\\"?\\$D\\s*\\{\\s*)|(?:\\\"?\\$V\\s*\\{\\s*)|(?:\\\"))(\\w+\\.?\\w+)((?:\\\")|(?:\\s*\\}\\\"?\\s*)))\\s*,\\s*\\\"(\\w+)\\\"\\s*\\)";

View File

@ -216,7 +216,11 @@ QScriptValue setVariable(QScriptContext* pcontext, QScriptEngine* /*pengine*/){
ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data()); ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
DataSourceManager* dm = sm->dataManager(); DataSourceManager* dm = sm->dataManager();
dm->changeVariable(name,value); if (dm->containsVariable(name))
dm->changeVariable(name,value);
else
dm->addVariable(name, value);
return QScriptValue(); return QScriptValue();
} }

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;