From 2777cbb744b6c19776b8ebdbb65a09edf7f83997 Mon Sep 17 00:00:00 2001
From: Arin Alexandex <arin_a@bk.ru>
Date: Sun, 16 Aug 2020 17:54:44 +0300
Subject: [PATCH] #289 Data source renaming has been fixed

---
 common.pri                               | 2 +-
 limereport/databrowser/lrdatabrowser.cpp | 4 ++--
 limereport/lrdatasourcemanager.cpp       | 7 +++----
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/common.pri b/common.pri
index 97b4d1d..b8d2840 100644
--- a/common.pri
+++ b/common.pri
@@ -133,7 +133,7 @@ RCC_DIR        = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
 
 LIMEREPORT_VERSION_MAJOR = 1
 LIMEREPORT_VERSION_MINOR = 5
-LIMEREPORT_VERSION_RELEASE = 66
+LIMEREPORT_VERSION_RELEASE = 67
 
 LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}'
 DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\"
diff --git a/limereport/databrowser/lrdatabrowser.cpp b/limereport/databrowser/lrdatabrowser.cpp
index d475826..32e9995 100644
--- a/limereport/databrowser/lrdatabrowser.cpp
+++ b/limereport/databrowser/lrdatabrowser.cpp
@@ -677,7 +677,7 @@ SQLEditResult::ResultMode DataBrowser::currentDatasourceType(const QString& data
 
 void DataBrowser::applyChanges(SQLEditResult result)
 {
-    if (result.resultMode == currentDatasourceType(result.datasourceName)){
+    if (result.resultMode == currentDatasourceType(result.oldDatasourceName)){
         switch(result.resultMode){
             case SQLEditResult::Query:
                 changeQuery(result);
@@ -694,7 +694,7 @@ void DataBrowser::applyChanges(SQLEditResult result)
             default: break;
         }
     } else {
-        removeDatasource(result.datasourceName);
+        removeDatasource(result.oldDatasourceName);
         addDatasource(result);
     }
     activateItem(result.datasourceName, DataBrowserTree::Table);
diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp
index f45bf4d..382a05c 100644
--- a/limereport/lrdatasourcemanager.cpp
+++ b/limereport/lrdatasourcemanager.cpp
@@ -675,8 +675,6 @@ CSVDesc *DataSourceManager::csvByName(const QString &datasourceName)
 
 void DataSourceManager::removeDatasource(const QString &name)
 {
-    invalidateLinkedDatasources(name);
-
     if (m_datasources.contains(name)){
         IDataSourceHolder *holder;
         holder=m_datasources.value(name);
@@ -703,6 +701,7 @@ void DataSourceManager::removeDatasource(const QString &name)
         delete m_csvs.at(csvIndex);
         m_csvs.removeAt(csvIndex);
     }
+    invalidateLinkedDatasources(name);
     m_hasChanges = true;
     emit datasourcesChanged();
 }
@@ -1348,12 +1347,12 @@ void DataSourceManager::invalidateLinkedDatasources(QString datasourceName)
 {
     foreach(QString name, dataSourceNames()){
         if (isSubQuery(name)){
-           if (subQueryByName(name)->master() == datasourceName)
+           if (subQueryByName(name)->master().compare(datasourceName) == 0)
                dataSourceHolder(name)->invalidate(designTime()?IDataSource::DESIGN_MODE:IDataSource::RENDER_MODE);
         }
         if (isProxy(name)){
             ProxyDesc* proxy = proxyByName(name);
-            if ((proxy->master() == datasourceName) || (proxy->child() == datasourceName))
+            if ((proxy->master().compare(datasourceName) == 0) || (proxy->child().compare(datasourceName) == 0))
                 dataSourceHolder(name)->invalidate(designTime()?IDataSource::DESIGN_MODE:IDataSource::RENDER_MODE);
 
         }