From 93a70817efafdc3f97a26a56f7827cd5aad4fade Mon Sep 17 00:00:00 2001
From: David Li <dawei.li@gmx.net>
Date: Fri, 26 Feb 2016 14:09:40 +0100
Subject: [PATCH] more unit test for model mapper in items

---
 GUI/coregui/Models/BeamDistributionItem.cpp   | 84 +++++++++----------
 GUI/coregui/Models/BeamDistributionItem.h     |  8 +-
 GUI/coregui/Models/DetectorItems.cpp          | 27 +++---
 GUI/coregui/Models/DetectorItems.h            |  2 -
 GUI/coregui/Models/GroupProperty.cpp          |  2 +-
 .../Models/InterferenceFunctionItems.cpp      |  2 +-
 GUI/coregui/Models/ParameterizedItem.cpp      | 44 ----------
 GUI/coregui/Models/ParameterizedItem.h        | 21 +----
 .../Models/ParticleCompositionItem.cpp        |  1 -
 GUI/coregui/Models/ParticleItem.cpp           | 43 +++++-----
 GUI/coregui/Models/ParticleItem.h             |  4 +-
 Tests/UnitTests/TestGUI/TestMapper.h          | 62 ++++++++++++++
 12 files changed, 147 insertions(+), 153 deletions(-)

diff --git a/GUI/coregui/Models/BeamDistributionItem.cpp b/GUI/coregui/Models/BeamDistributionItem.cpp
index 6750b806d30..c0b96b877bb 100644
--- a/GUI/coregui/Models/BeamDistributionItem.cpp
+++ b/GUI/coregui/Models/BeamDistributionItem.cpp
@@ -33,24 +33,24 @@ BeamDistributionItem::BeamDistributionItem(const QString name)
     setGroupProperty(P_DISTRIBUTION, Constants::DistributionNoneType);
 }
 
-void BeamDistributionItem::onPropertyChange(const QString &name)
-{
-    if(name == P_CACHED_VALUE) {
-        DistributionItem *distribution = dynamic_cast<DistributionItem *>(getGroupItem(P_DISTRIBUTION));
-        if(distribution) {
-            double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble();
-            PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE);
-            cached_attribute.setVisible();
-            // do not propagate this change back to me, or I will enter an infinite
-            // signal-slot loop
-            disconnect(getGroupItem(P_DISTRIBUTION), SIGNAL(propertyChanged(QString)),
-                    this, SLOT(processSubItemPropertyChanged(QString)) );
-            distribution->init_parameters(cached_value, cached_attribute);
-            connect(getGroupItem(P_DISTRIBUTION), SIGNAL(propertyChanged(QString)),
-                    this, SLOT(processSubItemPropertyChanged(QString)), Qt::UniqueConnection);
-        }
-    }
-}
+//void BeamDistributionItem::onPropertyChange(const QString &name)
+//{
+//    if(name == P_CACHED_VALUE) {
+//        DistributionItem *distribution = dynamic_cast<DistributionItem *>(getGroupItem(P_DISTRIBUTION));
+//        if(distribution) {
+//            double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble();
+//            PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE);
+//            cached_attribute.setVisible();
+//            // do not propagate this change back to me, or I will enter an infinite
+//            // signal-slot loop
+//            disconnect(getGroupItem(P_DISTRIBUTION), SIGNAL(propertyChanged(QString)),
+//                    this, SLOT(processSubItemPropertyChanged(QString)) );
+//            distribution->init_parameters(cached_value, cached_attribute);
+//            connect(getGroupItem(P_DISTRIBUTION), SIGNAL(propertyChanged(QString)),
+//                    this, SLOT(processSubItemPropertyChanged(QString)), Qt::UniqueConnection);
+//        }
+//    }
+//}
 
 //! returns parameter distribution to add into the Simulation
 std::unique_ptr<ParameterDistribution>
@@ -88,31 +88,31 @@ BeamDistributionItem::getParameterDistributionForName(const std::string &paramet
     return P_par_distr;
 }
 
-//! updates new DistributionItem with cached_value
-void BeamDistributionItem::onSubItemChanged(const QString &propertyName)
-{
-    qDebug() << "BeamWavelengthItem::onSubItemChanged(const QString &propertyName)" << propertyName;
-    if(propertyName == P_DISTRIBUTION) {
-        DistributionItem *distribution = dynamic_cast<DistributionItem *>(getGroupItem(P_DISTRIBUTION));
-        Q_ASSERT(distribution);
-        double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble();
-        PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE);
-        cached_attribute.setVisible();
-        distribution->init_parameters(cached_value, cached_attribute);
-    }
-    ParameterizedItem::onSubItemChanged(propertyName);
-}
+////! updates new DistributionItem with cached_value
+//void BeamDistributionItem::onSubItemChanged(const QString &propertyName)
+//{
+//    qDebug() << "BeamWavelengthItem::onSubItemChanged(const QString &propertyName)" << propertyName;
+//    if(propertyName == P_DISTRIBUTION) {
+//        DistributionItem *distribution = dynamic_cast<DistributionItem *>(getGroupItem(P_DISTRIBUTION));
+//        Q_ASSERT(distribution);
+//        double cached_value = getRegisteredProperty(P_CACHED_VALUE).toDouble();
+//        PropertyAttribute cached_attribute = getPropertyAttribute(P_CACHED_VALUE);
+//        cached_attribute.setVisible();
+//        distribution->init_parameters(cached_value, cached_attribute);
+//    }
+//    ParameterizedItem::onSubItemChanged(propertyName);
+//}
 
-void BeamDistributionItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name)
-{
-    qDebug() << "BeamWavelengthItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name)" << property_group << property_name;
-    if(property_group == P_DISTRIBUTION && property_name == DistributionNoneItem::P_VALUE) {
-        double value_to_cache = getGroupItem(P_DISTRIBUTION)->
-                getRegisteredProperty(DistributionNoneItem::P_VALUE).toDouble();
-        setRegisteredProperty(P_CACHED_VALUE, value_to_cache);
-    }
-    ParameterizedItem::onSubItemPropertyChanged(property_group, property_name);
-}
+//void BeamDistributionItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name)
+//{
+//    qDebug() << "BeamWavelengthItem::onSubItemPropertyChanged(const QString &property_group, const QString &property_name)" << property_group << property_name;
+//    if(property_group == P_DISTRIBUTION && property_name == DistributionNoneItem::P_VALUE) {
+//        double value_to_cache = getGroupItem(P_DISTRIBUTION)->
+//                getRegisteredProperty(DistributionNoneItem::P_VALUE).toDouble();
+//        setRegisteredProperty(P_CACHED_VALUE, value_to_cache);
+//    }
+//    ParameterizedItem::onSubItemPropertyChanged(property_group, property_name);
+//}
 
 std::unique_ptr<IDistribution1D> BeamDistributionItem::createDistribution1D()
 {
diff --git a/GUI/coregui/Models/BeamDistributionItem.h b/GUI/coregui/Models/BeamDistributionItem.h
index 1b5b2b3f97e..6855d08c052 100644
--- a/GUI/coregui/Models/BeamDistributionItem.h
+++ b/GUI/coregui/Models/BeamDistributionItem.h
@@ -34,14 +34,14 @@ public:
     static const QString P_CACHED_VALUE;
     explicit BeamDistributionItem(const QString name = QString());
     virtual ~BeamDistributionItem(){}
-    virtual void onPropertyChange(const QString &name);
+//    virtual void onPropertyChange(const QString &name);
 
     std::unique_ptr<ParameterDistribution> getParameterDistributionForName(
             const std::string &parameter_name);
 
-protected slots:
-    virtual void onSubItemChanged(const QString &propertyName);
-    virtual void onSubItemPropertyChanged(const QString &property_group, const QString &property_name);
+//protected slots:
+//    virtual void onSubItemChanged(const QString &propertyName);
+//    virtual void onSubItemPropertyChanged(const QString &property_group, const QString &property_name);
 
 protected:
     virtual std::unique_ptr<IDistribution1D> createDistribution1D();
diff --git a/GUI/coregui/Models/DetectorItems.cpp b/GUI/coregui/Models/DetectorItems.cpp
index 883e6757b83..1624bff3359 100644
--- a/GUI/coregui/Models/DetectorItems.cpp
+++ b/GUI/coregui/Models/DetectorItems.cpp
@@ -16,6 +16,7 @@
 #include "DetectorItems.h"
 #include "AngleProperty.h"
 #include "MaskItems.h"
+#include "ModelMapper.h"
 #include <QDebug>
 
 const QString DetectorItem::P_DETECTOR = "DetectorType";
@@ -26,6 +27,18 @@ DetectorItem::DetectorItem()
     registerGroupProperty(P_DETECTOR, Constants::DetectorGroup);
     addToValidChildren(Constants::MaskContainerType);
     setGroupProperty(P_DETECTOR, Constants::SphericalDetectorType);
+    mapper()->setOnPropertyChange(
+                [this] (const QString &name)
+    {
+        if(name == P_DETECTOR) {
+            if(ParameterizedItem *maskContainer = getMaskContainerItem()) {
+                ParameterizedItem *item = takeChildItem(rowOfChild(maskContainer));
+                Q_ASSERT(item == maskContainer);
+                delete item;
+            }
+
+        }
+    });
 }
 
 MaskContainerItem *DetectorItem::getMaskContainerItem() const
@@ -38,17 +51,3 @@ MaskContainerItem *DetectorItem::getMaskContainerItem() const
     return 0;
 }
 
-void DetectorItem::onSubItemChanged(const QString &propertyName)
-{
-    if(propertyName == P_DETECTOR) {
-        if(ParameterizedItem *maskContainer = getMaskContainerItem()) {
-            ParameterizedItem *item = takeChildItem(rowOfChild(maskContainer));
-            Q_ASSERT(item == maskContainer);
-            delete item;
-        }
-
-    }
-    ParameterizedItem::onSubItemChanged(propertyName);
-}
-
-
diff --git a/GUI/coregui/Models/DetectorItems.h b/GUI/coregui/Models/DetectorItems.h
index 1dc63bb2d3f..6dc5be7748b 100644
--- a/GUI/coregui/Models/DetectorItems.h
+++ b/GUI/coregui/Models/DetectorItems.h
@@ -33,8 +33,6 @@ public:
 
     MaskContainerItem *getMaskContainerItem() const;
 
-protected slots:
-    virtual void onSubItemChanged(const QString &propertyName);
 
 };
 
diff --git a/GUI/coregui/Models/GroupProperty.cpp b/GUI/coregui/Models/GroupProperty.cpp
index d24c7ddf32d..764313c024a 100644
--- a/GUI/coregui/Models/GroupProperty.cpp
+++ b/GUI/coregui/Models/GroupProperty.cpp
@@ -104,7 +104,7 @@ void GroupProperty::setCurrentLabel(const QString &label)
 {
     if(type() == FIXED) {
         m_type_label_map[m_current_type] = label;
-        if(m_parent) emit m_parent->propertyChanged(getGroupName());
+        if(m_parent) m_parent->emitPropertyChanged(getGroupName());
     }
 }
 
diff --git a/GUI/coregui/Models/InterferenceFunctionItems.cpp b/GUI/coregui/Models/InterferenceFunctionItems.cpp
index eb89dbfcfb0..887de6a82fd 100644
--- a/GUI/coregui/Models/InterferenceFunctionItems.cpp
+++ b/GUI/coregui/Models/InterferenceFunctionItems.cpp
@@ -84,7 +84,7 @@ InterferenceFunction2DParaCrystalItem::InterferenceFunction2DParaCrystalItem(
                 if(getRegisteredProperty(P_XI_INTEGRATION).toBool()) {
                     getPropertyAttribute(P_ROTATION_ANGLE).setDisabled();
                 } else {
-                    getPropertyAttribute(P_ROTATION_ANGLE).setVisible();
+                    getPropertyAttribute(P_ROTATION_ANGLE).setEnabled();
                 }
                 getPropertyItem(P_ROTATION_ANGLE)->emitValueChanged();
             }
diff --git a/GUI/coregui/Models/ParameterizedItem.cpp b/GUI/coregui/Models/ParameterizedItem.cpp
index 76566181248..671edaf8792 100644
--- a/GUI/coregui/Models/ParameterizedItem.cpp
+++ b/GUI/coregui/Models/ParameterizedItem.cpp
@@ -659,47 +659,3 @@ void ParameterizedItem::print() const
 //    }
 //    qDebug() << " ";
 }
-
-
-////! called when new SubItem appeared
-void ParameterizedItem::onSubItemChanged(const QString &propertyName)
-{
-    Q_UNUSED(propertyName);
-//    connect(m_sub_items[propertyName], SIGNAL(propertyChanged(QString)), this,
-//            SLOT(processSubItemPropertyChanged(QString)), Qt::UniqueConnection);
-//    emit subItemChanged(propertyName);
-}
-
-void ParameterizedItem::onSubItemPropertyChanged(const QString &property_group,
-                                                 const QString &property_name)
-{
-    emit subItemPropertyChanged(property_group, property_name);
-    if (mp_parent)
-        mp_parent->onChildPropertyChange(this, property_group);
-}
-
-void ParameterizedItem::onSiblingsChanged()
-{
-    emit siblingsChanged();
-}
-
-////! called when SubItem change one of its properties
-void ParameterizedItem::processSubItemPropertyChanged(const QString &propertyName)
-{
-    Q_UNUSED(propertyName);
-    return;
-//    ParameterizedItem *propertyItem = qobject_cast<ParameterizedItem *>(sender());
-    /*for (QMap<QString, ParameterizedItem *>::iterator it = m_sub_items.begin();
-         it != m_sub_items.end(); ++it) {
-        if (it.value() == propertyItem) {
-            GroupProperty_t group_property
-                = getRegisteredProperty(it.key()).value<GroupProperty_t>();
-            group_property->setCurrentLabel(propertyItem->itemLabel());
-            onSubItemPropertyChanged(it.key(), propertyName);
-            return;
-        }
-    }*/
-//    throw -1; // NEW
-//    throw GUIHelpers::Error("ParameterizedItem::onSubItemPropertyChanged() ->"
-//                            " Error. No such propertyItem found");
-}
diff --git a/GUI/coregui/Models/ParameterizedItem.h b/GUI/coregui/Models/ParameterizedItem.h
index 8410394b683..ec817d45f5a 100644
--- a/GUI/coregui/Models/ParameterizedItem.h
+++ b/GUI/coregui/Models/ParameterizedItem.h
@@ -25,6 +25,7 @@
 #include <QObject>
 #include <QVector>
 #include <QVariant>
+#include <QMetaType>
 
 class SessionModel;
 
@@ -108,7 +109,7 @@ public:
     PortInfo::EPorts port() const;
 
     //! not quite sure how this works, leave it as it is
-    void setPort(PortInfo::EPorts nport);
+    virtual void setPort(PortInfo::EPorts nport);
 
 
     // navigation functions
@@ -304,24 +305,6 @@ signals:
     void subItemPropertyChanged(const QString &property_group, const QString &property_name);
     void siblingsChanged();
 
-protected slots:
-    virtual void onSubItemChanged(const QString &propertyName);
-    virtual void onSubItemPropertyChanged(const QString &property_group,
-                                          const QString &property_name);
-    virtual void onSiblingsChanged();
-
-private slots:
-    virtual void processSubItemPropertyChanged(const QString &propertyName);
-
-protected:
-
-
-
-
-
-
-    void notifySiblings();
-
 };
 
 #endif /* PARAMETERIZEDITEM_H_ */
diff --git a/GUI/coregui/Models/ParticleCompositionItem.cpp b/GUI/coregui/Models/ParticleCompositionItem.cpp
index 6f147c4dc1c..253b873a446 100644
--- a/GUI/coregui/Models/ParticleCompositionItem.cpp
+++ b/GUI/coregui/Models/ParticleCompositionItem.cpp
@@ -49,7 +49,6 @@ ParticleCompositionItem::ParticleCompositionItem()
 
 void ParticleCompositionItem::insertChildItem(int row, ParameterizedItem *item)
 {
-//    int port = item->getRegisteredProperty(ParameterizedItem::OBSOLETE_P_PORT).toInt();
     int port = int(item->port());
     ParameterizedItem::insertChildItem(row, item);
     if (item->modelType() == Constants::ParticleType
diff --git a/GUI/coregui/Models/ParticleItem.cpp b/GUI/coregui/Models/ParticleItem.cpp
index cec1753a123..5af0e8f1647 100644
--- a/GUI/coregui/Models/ParticleItem.cpp
+++ b/GUI/coregui/Models/ParticleItem.cpp
@@ -50,23 +50,38 @@ void ParticleItem::insertChildItem(int row, ParameterizedItem *item)
     ParameterizedItem::insertChildItem(row, item);
     if (item->modelType() == Constants::TransformationType) {
         int port = int(item->port());
-//        int port = item->getRegisteredProperty(ParameterizedItem::OBSOLETE_P_PORT).toInt();
         if (port == PortInfo::DEFAULT) {
             item->setPort(PortInfo::PORT_0);
         }
     }
 }
 
-void ParticleItem::onPropertyChange(const QString &name)
+std::unique_ptr<Particle> ParticleItem::createParticle() const
+{
+    auto P_material = TransformToDomain::createDomainMaterial(*this);
+    auto P_particle = GUIHelpers::make_unique<Particle>(*P_material);
+
+    double abundance = getRegisteredProperty(ParticleItem::P_ABUNDANCE).toDouble();
+    P_particle->setAbundance(abundance);
+
+    auto ffItem = static_cast<FormFactorItem*>(getGroupItem(ParticleItem::P_FORM_FACTOR));
+    Q_ASSERT(ffItem);
+    auto P_ff = ffItem->createFormFactor();
+    P_particle->setFormFactor(*P_ff);
+
+    TransformToDomain::setTransformationInfo(P_particle.get(), *this);
+
+    return P_particle;
+}
+
+void ParticleItem::setPort(ParameterizedItem::PortInfo::EPorts nport)
 {
-    ParameterizedItem::onPropertyChange(name);
-    if (name == "OBSOLETE_P_PORT" && parent()) {
+    if (parent()) {
         if (parent()->modelType() == Constants::ParticleCoreShellType
             || parent()->modelType() == Constants::ParticleCompositionType
             || parent()->modelType() == Constants::ParticleDistributionType) {
             setRegisteredProperty(ParticleItem::P_ABUNDANCE, 1.0);
             getPropertyAttribute(ParticleItem::P_ABUNDANCE).setDisabled();
-//            int port = getRegisteredProperty(ParameterizedItem::OBSOLETE_P_PORT).toInt();
             int port = int(this->port());
             if (parent()->modelType() == Constants::ParticleCoreShellType) {
                 auto p_coreshell = static_cast<ParticleCoreShellItem*>(parent());
@@ -82,21 +97,3 @@ void ParticleItem::onPropertyChange(const QString &name)
         }
     }
 }
-
-std::unique_ptr<Particle> ParticleItem::createParticle() const
-{
-    auto P_material = TransformToDomain::createDomainMaterial(*this);
-    auto P_particle = GUIHelpers::make_unique<Particle>(*P_material);
-
-    double abundance = getRegisteredProperty(ParticleItem::P_ABUNDANCE).toDouble();
-    P_particle->setAbundance(abundance);
-
-    auto ffItem = static_cast<FormFactorItem*>(getGroupItem(ParticleItem::P_FORM_FACTOR));
-    Q_ASSERT(ffItem);
-    auto P_ff = ffItem->createFormFactor();
-    P_particle->setFormFactor(*P_ff);
-
-    TransformToDomain::setTransformationInfo(P_particle.get(), *this);
-
-    return P_particle;
-}
diff --git a/GUI/coregui/Models/ParticleItem.h b/GUI/coregui/Models/ParticleItem.h
index 2bd0b3bf357..ccc69780887 100644
--- a/GUI/coregui/Models/ParticleItem.h
+++ b/GUI/coregui/Models/ParticleItem.h
@@ -31,9 +31,9 @@ public:
     static const QString P_POSITION;
     explicit ParticleItem();
     virtual ~ParticleItem() {}
-    virtual void insertChildItem(int row, ParameterizedItem *item);
-    virtual void onPropertyChange(const QString &name);
+    virtual void insertChildItem(int row, ParameterizedItem *item);
     std::unique_ptr<Particle> createParticle() const;
+    virtual void setPort(PortInfo::EPorts nport);
 };
 
 #endif // PARTICLEITEM_H
diff --git a/Tests/UnitTests/TestGUI/TestMapper.h b/Tests/UnitTests/TestGUI/TestMapper.h
index dc3951fab49..f151e60d780 100644
--- a/Tests/UnitTests/TestGUI/TestMapper.h
+++ b/Tests/UnitTests/TestGUI/TestMapper.h
@@ -3,10 +3,14 @@
 
 #include "ParameterizedItem.h"
 #include "SampleModel.h"
+#include "InstrumentModel.h"
 #include "item_constants.h"
 #include "ParticleItem.h"
 #include "ParticleCompositionItem.h"
 #include "ParticleDistributionItem.h"
+#include "InterferenceFunctionItems.h"
+#include "DetectorItems.h"
+#include "ComboProperty.h"
 #include <memory>
 #include <QtTest>
 
@@ -15,6 +19,9 @@ class TestMapper : public QObject {
 
 private slots:
     void test_ParticeleCompositionUpdate();
+    void test_Inference2DRotationAngleToggle();
+    void test_instrumentAlignmentPropertyVisibility();
+    void test_removeMaskOnDetectorChange();
 };
 
 inline void TestMapper::test_ParticeleCompositionUpdate()
@@ -38,5 +45,60 @@ inline void TestMapper::test_ParticeleCompositionUpdate()
 
 }
 
+inline void TestMapper::test_Inference2DRotationAngleToggle()
+{
+    SampleModel model;
+    ParameterizedItem *multilayer = model.insertNewItem(Constants::MultiLayerType);
+    ParameterizedItem *layer = model.insertNewItem(Constants::LayerType, multilayer->index());
+    ParameterizedItem *layout = model.insertNewItem(Constants::ParticleLayoutType, layer->index());
+
+    ParameterizedItem *inference = model.insertNewItem(Constants::InterferenceFunction2DParaCrystalType, layout->index());
+
+    // rotation (xi) should be disabled if integration is on
+    inference->setRegisteredProperty(InterferenceFunction2DParaCrystalItem::P_XI_INTEGRATION, true);
+    QVERIFY(inference->getPropertyAttribute(InterferenceFunction2DParaCrystalItem::P_ROTATION_ANGLE).isDisabled());
+
+    // rotation (xi) should be enabled if integration is off
+    inference->setRegisteredProperty(InterferenceFunction2DParaCrystalItem::P_XI_INTEGRATION, false);
+    QVERIFY(!inference->getPropertyAttribute(InterferenceFunction2DParaCrystalItem::P_ROTATION_ANGLE).isDisabled());
+
+}
+
+inline void TestMapper::test_instrumentAlignmentPropertyVisibility()
+{
+    InstrumentModel model;
+    ParameterizedItem *instrument = model.insertNewItem(Constants::InstrumentType);
+    ParameterizedItem *detector = model.insertNewItem(Constants::DetectorType, instrument->index());
+    detector->setGroupProperty(DetectorItem::P_DETECTOR, Constants::RectangularDetectorType);
+    ParameterizedItem *rectangular = detector->getGroupItem(DetectorItem::P_DETECTOR);
+
+
+    ComboProperty alignment = rectangular->getRegisteredProperty(RectangularDetectorItem::P_ALIGNMENT)
+            .value<ComboProperty>();
+    // generic has some more items visible
+    alignment.setValue(Constants::ALIGNMENT_GENERIC);
+    rectangular->setRegisteredProperty(RectangularDetectorItem::P_ALIGNMENT, QVariant::fromValue<ComboProperty>(alignment));
+    QVERIFY(rectangular->getPropertyAttribute(RectangularDetectorItem::P_NORMAL).isHidden() == false);
+
+    // should be disabled if we switch
+    alignment.setValue(Constants::ALIGNMENT_TO_REFLECTED_BEAM);
+    rectangular->setRegisteredProperty(RectangularDetectorItem::P_ALIGNMENT, QVariant::fromValue<ComboProperty>(alignment));
+    QVERIFY(rectangular->getPropertyAttribute(RectangularDetectorItem::P_NORMAL).isHidden() == true);
+
+}
+
+inline void TestMapper::test_removeMaskOnDetectorChange()
+{
+    InstrumentModel model;
+    ParameterizedItem *instrument = model.insertNewItem(Constants::InstrumentType);
+    ParameterizedItem *detector = model.insertNewItem(Constants::DetectorType, instrument->index());
+    detector->setGroupProperty(DetectorItem::P_DETECTOR, Constants::RectangularDetectorType);
+    model.insertNewItem(Constants::MaskContainerType, detector->index());
+    QVERIFY(detector->getUnregisteredChildren().size() == 1);
+    // after change the mask container should be removed
+    detector->setGroupProperty(DetectorItem::P_DETECTOR, Constants::SphericalDetectorType);
+    QVERIFY(detector->getUnregisteredChildren().size() == 0);
+
+}
 
 #endif
-- 
GitLab