From f4047a1b95af9cbb549655d4405301589cebd06f Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Mon, 18 May 2015 17:24:18 +0200
Subject: [PATCH] Modification in ProjectDocument to adjust names of *.int
 files to current JobItem name

---
 GUI/coregui/Models/JobItem.cpp             | 16 ++++----
 GUI/coregui/Models/JobItem.h               |  2 +-
 GUI/coregui/mainwindow/projectdocument.cpp | 48 +++++++++++-----------
 GUI/coregui/mainwindow/projectdocument.h   |  1 +
 GUI/coregui/utils/GUIHelpers.cpp           | 14 +++----
 5 files changed, 40 insertions(+), 41 deletions(-)

diff --git a/GUI/coregui/Models/JobItem.cpp b/GUI/coregui/Models/JobItem.cpp
index e461e060e23..acfd93e8ce9 100644
--- a/GUI/coregui/Models/JobItem.cpp
+++ b/GUI/coregui/Models/JobItem.cpp
@@ -256,12 +256,12 @@ InstrumentItem *JobItem::getInstrumentItem(bool from_backup)
     return 0;
 }
 
-void JobItem::onPropertyChange(const QString &name)
-{
-    if(name == ParameterizedItem::P_NAME) {
-        if(IntensityDataItem *intensityDataItem = getIntensityDataItem()) {
-            intensityDataItem->setNameFromProposed(itemName());
-        }
-    }
-}
+//void JobItem::onPropertyChange(const QString &name)
+//{
+//    if(name == ParameterizedItem::P_NAME) {
+//        if(IntensityDataItem *intensityDataItem = getIntensityDataItem()) {
+//            intensityDataItem->setNameFromProposed(itemName());
+//        }
+//    }
+//}
 
diff --git a/GUI/coregui/Models/JobItem.h b/GUI/coregui/Models/JobItem.h
index 28a236c3a7c..3e5ec92ad6b 100644
--- a/GUI/coregui/Models/JobItem.h
+++ b/GUI/coregui/Models/JobItem.h
@@ -79,7 +79,7 @@ public:
 
     InstrumentItem *getInstrumentItem(bool from_backup = false);
 
-    void onPropertyChange(const QString &name);
+//    void onPropertyChange(const QString &name);
 
 private:
     static QMap<QString, QString> m_run_policies; // run policy, policy description
diff --git a/GUI/coregui/mainwindow/projectdocument.cpp b/GUI/coregui/mainwindow/projectdocument.cpp
index 141758fb220..7fdabdc9b7a 100644
--- a/GUI/coregui/mainwindow/projectdocument.cpp
+++ b/GUI/coregui/mainwindow/projectdocument.cpp
@@ -138,6 +138,8 @@ bool ProjectDocument::save()
 {
     qDebug() << "ProjectDocument::save() -> " << getProjectName() << getProjectPath() << getProjectFileName();
 
+    reviseOutputData();
+
     QString filename = getProjectFileName();
 
     QFile file(filename);
@@ -253,7 +255,6 @@ bool ProjectDocument::readFrom(QIODevice *device)
     return true;
 }
 
-
 bool ProjectDocument::writeTo(QIODevice *device)
 {
     QXmlStreamWriter writer(device);
@@ -303,23 +304,32 @@ QString ProjectDocument::getProjectDir()
     return result;
 }
 
+//! Adjusts name of IntensityData item to possibly changed name of JobItem. Take care of old
+//! *.int files in project directory
+void ProjectDocument::reviseOutputData()
+{
+    for(int i=0; i<m_jobModel->rowCount(QModelIndex()); ++i) {
+        JobItem *jobItem = m_jobModel->getJobItemForIndex(m_jobModel->index(i,0, QModelIndex()));
+        IntensityDataItem *dataItem = jobItem->getIntensityDataItem();
+        if(dataItem) {
+            // handling case when user has renamed jobItem and we have to clean previous
+            // *.int file
+            QString filename = getProjectDir() + "/" + dataItem->itemName();
+            QFile fin(filename);
+            if(fin.exists()) {
+                fin.remove();
+            }
+
+            // making new name of *.int file from jobItem name
+            dataItem->setNameFromProposed(jobItem->itemName());
+        }
+    }
+}
 
 //! saves OutputData into project directory
 void ProjectDocument::saveOutputData()
 {
     Q_ASSERT(m_jobModel);
-
-//    for(int i=0; i<m_jobQueueModel->rowCount(); ++i) {
-//        JobItem *jobItem = m_jobQueueModel->getJobItemForIndex(m_jobQueueModel->index(i,0));
-//        OutputDataItem *dataItem = jobItem->getOutputDataItem();
-//        if(dataItem) {
-//            QString filename = getProjectDir() + "/" + dataItem->getName();
-//            const OutputData<double> *data = dataItem->getOutputData();
-//            if(data) {
-//                IntensityDataIOFactory::writeIntensityData(*data, filename.toStdString());
-//            }
-//        }
-//    }
     for(int i=0; i<m_jobModel->rowCount(QModelIndex()); ++i) {
         JobItem *jobItem = m_jobModel->getJobItemForIndex(m_jobModel->index(i,0, QModelIndex()));
         IntensityDataItem *dataItem = jobItem->getIntensityDataItem();
@@ -331,7 +341,6 @@ void ProjectDocument::saveOutputData()
             }
         }
     }
-
 }
 
 
@@ -340,17 +349,6 @@ void ProjectDocument::loadOutputData()
 {
     Q_ASSERT(m_jobModel);
 
-//    for(int i=0; i<m_jobQueueModel->rowCount(); ++i) {
-//        JobItem *jobItem = m_jobQueueModel->getJobItemForIndex(m_jobQueueModel->index(i,0));
-//        OutputDataItem *dataItem = jobItem->getOutputDataItem();
-//        if(dataItem) {
-//            QString filename = getProjectDir() + "/" + dataItem->getName();
-//            QFileInfo info(filename);
-//            if(info.exists()) {
-//                jobItem->getOutputDataItem()->setOutputData(IntensityDataIOFactory::readIntensityData(filename.toStdString()));
-//            }
-//        }
-//    }
     for(int i=0; i<m_jobModel->rowCount(QModelIndex()); ++i) {
         JobItem *jobItem = m_jobModel->getJobItemForIndex(m_jobModel->index(i,0, QModelIndex()));
         IntensityDataItem *dataItem = jobItem->getIntensityDataItem();
diff --git a/GUI/coregui/mainwindow/projectdocument.h b/GUI/coregui/mainwindow/projectdocument.h
index 5feab146145..fb27252917b 100644
--- a/GUI/coregui/mainwindow/projectdocument.h
+++ b/GUI/coregui/mainwindow/projectdocument.h
@@ -88,6 +88,7 @@ private:
     bool writeTo(QIODevice *device);
     bool readFrom(QIODevice *device);
 
+    void reviseOutputData();
     void saveOutputData();
     void loadOutputData();
 
diff --git a/GUI/coregui/utils/GUIHelpers.cpp b/GUI/coregui/utils/GUIHelpers.cpp
index 2b001c19aa9..d709952a9a7 100644
--- a/GUI/coregui/utils/GUIHelpers.cpp
+++ b/GUI/coregui/utils/GUIHelpers.cpp
@@ -25,13 +25,13 @@ namespace {
 QMap<QString, QString> initializeCharacterMap()
 {
     QMap<QString, QString> result;
-    result["\\"]= QString("backslash");
-    result["/"] = QString("slash");
-    result["\""] = QString("quote");
-    result["<"] = QString("lessthan");
-    result[">"] = QString("greaterthan");
-    result["|"] = QString("pipe");
-    result["?"] = QString("questionmark");
+    result["\\"]= QString("_backslash_");
+    result["/"] = QString("_slash_");
+    result["\""] = QString("_quote_");
+    result["<"] = QString("_lessthan_");
+    result[">"] = QString("_greaterthan_");
+    result["|"] = QString("_pipe_");
+    result["?"] = QString("_questionmark_");
     return result;
 }
 
-- 
GitLab