From 0a66faa7ddacf42779ab165136083e4275f0c7df Mon Sep 17 00:00:00 2001
From: Gennady Pospelov <g.pospelov@fz-juelich.de>
Date: Fri, 15 Apr 2016 16:31:44 +0200
Subject: [PATCH] On the way to removing fixed group property

---
 CMakeLists.txt                             |  2 +-
 GUI/coregui/Models/ApplicationModels.cpp   |  7 ++-
 GUI/coregui/Models/FilterPropertyProxy.cpp |  2 +-
 GUI/coregui/Models/SessionModel.cpp        |  6 +--
 GUI/coregui/Models/SessionXML.cpp          | 53 ++++++++++++++++++----
 5 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6029e359fe3..4cb5efd2190 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,7 +49,7 @@ if(ROOT_FOUND AND BORNAGAIN_APP) # TODO: find out whether this is still needed
 endif()
 if(BORNAGAIN_GUI)
     add_subdirectory(GUI)
-    add_subdirectory(Tests/UnitTests/TestGUI)
+#    add_subdirectory(Tests/UnitTests/TestGUI)
 endif()
 add_subdirectory(Tests/FunctionalTests)  # functional tests (make check)
 
diff --git a/GUI/coregui/Models/ApplicationModels.cpp b/GUI/coregui/Models/ApplicationModels.cpp
index 0ff4a817c36..cfbf2ead0c8 100644
--- a/GUI/coregui/Models/ApplicationModels.cpp
+++ b/GUI/coregui/Models/ApplicationModels.cpp
@@ -36,7 +36,12 @@ ApplicationModels::ApplicationModels(QObject *parent)
     , m_fitModel(0)
 {
     createModels();
-    testGUIObjectBuilder();
+    //testGUIObjectBuilder();
+
+    SessionItem *multilayer = m_sampleModel->insertNewItem(Constants::MultiLayerType);
+    SessionItem *layer = m_sampleModel->insertNewItem(Constants::LayerType, multilayer->index());
+//    m_sampleModel->moveParameterizedItem(layer, 0);
+
 }
 
 ApplicationModels::~ApplicationModels()
diff --git a/GUI/coregui/Models/FilterPropertyProxy.cpp b/GUI/coregui/Models/FilterPropertyProxy.cpp
index c0cfa5934e5..0de2cfb68a9 100644
--- a/GUI/coregui/Models/FilterPropertyProxy.cpp
+++ b/GUI/coregui/Models/FilterPropertyProxy.cpp
@@ -37,7 +37,7 @@ bool FilterPropertyProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sou
     if (!sourceParent.isValid())
         return true;
     const QString modelType = index.data(SessionModel::ModelTypeRole).toString();
-    if (modelType == Constants::PropertyType || modelType == Constants::GroupItemType)
+    if (modelType == Constants::PropertyType || modelType == Constants::GroupItemType || modelType == Constants::VectorType)
         return false;
 
     return true;//!sourceModel()->data(index, Qt::DisplayRole).isValid();
diff --git a/GUI/coregui/Models/SessionModel.cpp b/GUI/coregui/Models/SessionModel.cpp
index 95b263926e6..b50a56566a7 100644
--- a/GUI/coregui/Models/SessionModel.cpp
+++ b/GUI/coregui/Models/SessionModel.cpp
@@ -416,11 +416,7 @@ SessionItem *SessionModel::moveParameterizedItem(SessionItem *item, SessionItem
         SessionTagInfo info = new_parent->getTagInfo(tagName);
         if (info.max == info.childCount && info.childCount == 1) {
             SessionItem *old = new_parent->takeItem(0, tagName);
-            if(!new_parent->insertItem(row, stuff, tagName)) {
-                throw GUIHelpers::Error("SessionModel::moveParameterizedItem -> Error. "
-                                        "Can't insert item");
-            }
-
+            new_parent->insertItem(row, stuff, tagName);
             m_root_item->insertItem(-1, old);
         }
         m_root_item->insertItem(-1, stuff);
diff --git a/GUI/coregui/Models/SessionXML.cpp b/GUI/coregui/Models/SessionXML.cpp
index a7056e12bc9..91ed5765139 100644
--- a/GUI/coregui/Models/SessionXML.cpp
+++ b/GUI/coregui/Models/SessionXML.cpp
@@ -75,35 +75,52 @@ void SessionWriter::writeVariant(QXmlStreamWriter *writer, QVariant variant, int
         QString type_name = variant.typeName();
         writer->writeAttribute(SessionXML::ParameterTypeAttribute, type_name);
         writer->writeAttribute(SessionXML::ParameterRoleAttribute, QString::number(role));
+
         if (type_name == QString("double")) {
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                    QString::number(variant.toDouble(), 'e', 12));
-        } else if (type_name == QString("int")) {
+        }
+
+        else if (type_name == QString("int")) {
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                    QString::number(variant.toInt()));
-        } else if (type_name == QString("bool")) {
+        }
+
+        else if (type_name == QString("bool")) {
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                    QString::number(variant.toBool()));
-        } else if (type_name == QString("QString")) {
+        }
+
+        else if (type_name == QString("QString")) {
             writer->writeAttribute(SessionXML::ParameterValueAttribute, variant.toString());
-        } else if (type_name == QString("MaterialProperty")) {
+        }
+
+        else if (type_name == QString("MaterialProperty")) {
             MaterialProperty material_property = variant.value<MaterialProperty>();
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                    material_property.getName());
             writer->writeAttribute(SessionXML::IdentifierAttribute,
                                    material_property.getIdentifier());
 
-        } else if (type_name == QString("ComboProperty")) {
+        }
+
+        else if (type_name == QString("ComboProperty")) {
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                    variant.value<ComboProperty>().getValue());
-        } else if (type_name == QString("ScientificDoubleProperty")) {
+        }
+
+        else if (type_name == QString("ScientificDoubleProperty")) {
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                    variant.value<ScientificDoubleProperty>().getText());
 
-        } else if (type_name == QString("GroupProperty_t")) {
+        }
+
+        else if (type_name == QString("GroupProperty_t")) {
             QString ff_name = variant.value<GroupProperty_t>()->getCurrentType();
             writer->writeAttribute(SessionXML::ParameterValueAttribute, ff_name);
-        } else if (type_name == QString("ColorProperty")) {
+        }
+
+        else if (type_name == QString("ColorProperty")) {
             int r, g, b, a;
             QColor material_color = variant.value<ColorProperty>().getColor();
             material_color.getRgb(&r, &g, &b, &a);
@@ -111,7 +128,9 @@ void SessionWriter::writeVariant(QXmlStreamWriter *writer, QVariant variant, int
             writer->writeAttribute(SessionXML::ColorGreenAttribute, QString::number(g));
             writer->writeAttribute(SessionXML::ColorBlueAttribute, QString::number(b));
             writer->writeAttribute(SessionXML::ColorAlphaAttribute, QString::number(a));
-        } else if (type_name == QString("AngleProperty")) {
+        }
+
+        else if (type_name == QString("AngleProperty")) {
             double value = variant.value<AngleProperty>().getValueInRadians();
             writer->writeAttribute(SessionXML::ParameterValueAttribute,
                                    QString::number(value, 'g'));
@@ -152,16 +171,30 @@ void SessionReader::readItems(QXmlStreamReader *reader, SessionItem *item, const
                     if (!item) {
                         qDebug() << "!!";
                     }
+
                 } else {
                     SessionItem *new_item = ItemFactory::createItem(model_type);
+                    Q_ASSERT(new_item);
                     if (reader->attributes().hasAttribute(SessionXML::DisplayNameAttribute)) {
                         new_item->setDisplayName(reader->attributes().value(SessionXML::DisplayNameAttribute).toString());
                     }
                     if (tag == "")
                         tag = item->defaultTag();
+
                     if (!item->insertItem(-1, new_item, tag)) {
-                        qDebug() << "!!";
+                        // this must be VectorItem or similar registered via addProperty mechanism
+
+                        SessionTagInfo info = item->getTagInfo(tag);
+                        if (info.max == info.childCount && info.childCount == 1) {
+                            delete item->takeItem(0, tag);
+                            item->insertItem(-1, new_item, tag);
+                        } else {
+                            throw GUIHelpers::Error("SessionReader::readItems -> Error. "
+                                                "Can't insert item 1.2");
+                        }
+
                     }
+
                     item = new_item;
                 }
                 if (!item) {
-- 
GitLab