diff --git a/limereport/lrdatadesignintf.cpp b/limereport/lrdatadesignintf.cpp index 9b8e86a..b9a15dd 100644 --- a/limereport/lrdatadesignintf.cpp +++ b/limereport/lrdatadesignintf.cpp @@ -158,6 +158,7 @@ void QueryHolder::fillParams(QSqlQuery *query) void QueryHolder::extractParams() { m_preparedSQL = replaceVariables(m_queryText); + m_prepared = true; } QString QueryHolder::replaceVariables(QString query) @@ -195,6 +196,11 @@ QString QueryHolder::queryText() void QueryHolder::setQueryText(QString queryText) { m_queryText=queryText; + m_prepared = false; + if (m_query) { + delete m_query; + m_query = 0; + } } IDataSource* QueryHolder::dataSource(IDataSource::DatasourceMode mode) @@ -364,7 +370,7 @@ void ConnectionDesc::setName(const QString &value) } QueryDesc::QueryDesc(QString queryName, QString queryText, QString connection) - :m_queryName(queryName), m_query(queryText), m_connectionName(connection) + :m_queryName(queryName), m_queryText(queryText), m_connectionName(connection) {} SubQueryHolder::SubQueryHolder(QString queryText, QString connectionName, QString masterDatasource, DataSourceManager* dataManager) diff --git a/limereport/lrdatadesignintf.h b/limereport/lrdatadesignintf.h index 1c7823a..e53056f 100644 --- a/limereport/lrdatadesignintf.h +++ b/limereport/lrdatadesignintf.h @@ -159,13 +159,15 @@ public: explicit QueryDesc(QObject* parent=0):QObject(parent){} void setQueryName(QString value){m_queryName=value;} QString queryName(){return m_queryName;} - void setQueryText(QString value){m_query=value;} - QString queryText(){return m_query;} + void setQueryText(QString value){m_queryText=value; emit queryTextChanged(m_queryName, m_queryText);} + QString queryText(){return m_queryText;} void setConnectionName(QString value){m_connectionName=value;} QString connectionName(){return m_connectionName;} +signals: + void queryTextChanged(const QString& queryName, const QString& queryText); private: QString m_queryName; - QString m_query; + QString m_queryText; QString m_connectionName; }; diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index d140a16..9cfa82e 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -620,13 +620,7 @@ bool DataSourceManager::checkConnectionDesc(ConnectionDesc *connection) return false; } -void DataSourceManager::addQueryDesc(QueryDesc *query) -{ - m_queries.append(query); - addQuery(query->queryName(), query->queryText(), query->connectionName()); -} - -void DataSourceManager::putHolder(QString name, IDataSourceHolder *dataSource) +void DataSourceManager::putHolder(const QString& name, IDataSourceHolder *dataSource) { if (!m_datasources.contains(name.toLower())){ m_datasources.insert( @@ -640,6 +634,8 @@ void DataSourceManager::putQueryDesc(QueryDesc* queryDesc) { if (!containsDatasource(queryDesc->queryName())){ m_queries.append(queryDesc); + connect(queryDesc, SIGNAL(queryTextChanged(QString,QString)), + this, SLOT(slotQueryTextChanged(QString,QString))); } else throw ReportError(tr("datasource with name \"%1\" already exists !").arg(queryDesc->queryName())); } @@ -647,6 +643,8 @@ void DataSourceManager::putSubQueryDesc(SubQueryDesc *subQueryDesc) { if (!containsDatasource(subQueryDesc->queryName())){ m_subqueries.append(subQueryDesc); + connect(subQueryDesc, SIGNAL(queryTextChanged(QString,QString)), + this, SLOT(slotQueryTextChanged(QString,QString))); } else throw ReportError(tr("datasource with name \"%1\" already exists !").arg(subQueryDesc->queryName())); } @@ -1058,6 +1056,14 @@ void DataSourceManager::slotConnectionRenamed(const QString &oldName, const QStr } } +void DataSourceManager::slotQueryTextChanged(const QString &queryName, const QString &queryText) +{ + QueryHolder* holder = dynamic_cast(m_datasources.value(queryName)); + if (holder){ + holder->setQueryText(queryText); + } +} + void DataSourceManager::clear(ClearMethod method) { DataSourcesMap::iterator dit; diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index aac8778..97fe6d1 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -195,8 +195,7 @@ signals: void cleared(); void datasourcesChanged(); protected: - void addQueryDesc(QueryDesc *); - void putHolder(QString name, LimeReport::IDataSourceHolder* dataSource); + void putHolder(const QString& name, LimeReport::IDataSourceHolder* dataSource); void putQueryDesc(QueryDesc *queryDesc); void putSubQueryDesc(SubQueryDesc *subQueryDesc); void putProxyDesc(ProxyDesc *proxyDesc); @@ -217,6 +216,7 @@ protected: private slots: void slotConnectionRenamed(const QString& oldName,const QString& newName); + void slotQueryTextChanged(const QString& queryName, const QString& queryText); private: explicit DataSourceManager(QObject *parent = 0); Q_DISABLE_COPY(DataSourceManager)