diff --git a/limereport/items/lrtextitemeditor.cpp b/limereport/items/lrtextitemeditor.cpp index 222d11a..4b33a04 100644 --- a/limereport/items/lrtextitemeditor.cpp +++ b/limereport/items/lrtextitemeditor.cpp @@ -119,6 +119,8 @@ void TextItemEditor::initUI() se.setDataManager(dm); if (dm){ + if (dm->isNeedUpdateDatasourceModel()) + dm->updateDatasourceModel(); ui->twData->setModel(dm->datasourcesModel()); ui->twScriptEngine->setModel(se.model()); diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 85bcc0e..943ad03 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -211,7 +211,7 @@ void DataSourceModel::updateModel() } DataSourceManager::DataSourceManager(QObject *parent) : - QObject(parent), m_lastError(""), m_designTime(true) + QObject(parent), m_lastError(""), m_designTime(true), m_needUpdate(false) { m_groupFunctionFactory.registerFunctionCreator(QLatin1String("COUNT"),new ConstructorGroupFunctionCreator); m_groupFunctionFactory.registerFunctionCreator(QLatin1String("SUM"),new ConstructorGroupFunctionCreator); @@ -281,6 +281,7 @@ ICallbackDatasource *DataSourceManager::createCallbackDatasouce(const QString& n IDataSourceHolder* holder = new CallbackDatasourceHolder(dynamic_cast(ds),true); putHolder(name,holder); emit datasourcesChanged(); + m_needUpdate = true; return ds; } @@ -333,6 +334,12 @@ QSharedPointerDataSourceManager::previewSQL(const QString &c return QSharedPointer(0); } +void DataSourceManager::updateDatasourceModel() +{ + m_datasourcesModel.updateModel(); + m_needUpdate = false; +} + QString DataSourceManager::extractField(QString source) { if (source.contains('.')) { diff --git a/limereport/lrdatasourcemanager.h b/limereport/lrdatasourcemanager.h index c167b8e..642757a 100644 --- a/limereport/lrdatasourcemanager.h +++ b/limereport/lrdatasourcemanager.h @@ -70,6 +70,7 @@ private: class DataSourceModel : public QAbstractItemModel{ Q_OBJECT + friend class DataSourceManager; public: DataSourceModel():m_rootNode(new DataNode()){} DataSourceModel(DataSourceManager* dataManager); @@ -184,7 +185,8 @@ public: QString replaceVariables(QString value); QString replaceFields(QString query, QMap &aliasesToParam, QString masterDatasource = ""); QSharedPointer previewSQL(const QString& connectionName, const QString& sqlText, QString masterDatasource=""); - + void updateDatasourceModel(); + bool isNeedUpdateDatasourceModel(){ return m_needUpdate;} signals: void loadCollectionFinished(const QString& collectionName); void cleared(); @@ -231,6 +233,7 @@ private: QString m_lastError; QStringList m_errorsList; bool m_designTime; + bool m_needUpdate; }; }