Skip to content
Snippets Groups Projects
Commit ae0746d1 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

rm SessionItem signaling from MultiLayer (functionality changed to signal-free by the last commits)

rm obsolete unit tests
parent f4683b9f
No related branches found
No related tags found
1 merge request!532Reduce SessionItem signaling
......@@ -21,6 +21,7 @@
#include "GUI/Model/Material/MaterialItem.h"
#include "GUI/Model/Sample/InterferenceItems.h"
#include "GUI/Model/Sample/Lattice2DItems.h"
#include "GUI/Model/Sample/LayerItem.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/Model/Sample/ParticleCoreShellItem.h"
#include "GUI/Model/Sample/ParticleItem.h"
......@@ -134,7 +135,18 @@ void GUI::Model::ParameterTreeUtils::createParameterTree(JobItem* jobItem,
}
}
// add sample
// add sample.
// #baMigration To ignore thickness/roughness, they are disabled. This has to be changed after
// SessionModel migration. Compare also to handling in
// LayerForm::updateLayerPositionDependentElements()
for (auto* layer : jobItem->sampleItem()->layers()) {
const bool isFirstLayer = jobItem->sampleItem()->layers().first() == layer;
const bool isLastLayer = jobItem->sampleItem()->layers().last() == layer;
layer->setRoughnessEnabled(!isFirstLayer);
layer->setThicknessEnabled(!isFirstLayer && !isLastLayer);
}
populateParameterContainer(container, jobItem->sampleItem(), recreateBackupValues);
// add instrument
......
......@@ -36,8 +36,6 @@ MultiLayerItem::MultiLayerItem() : SessionItem(M_TYPE)
registerTag(T_LAYERS, 0, -1, {LayerItem::M_TYPE});
setDefaultTag(T_LAYERS);
mapper()->setOnChildrenChange([this](SessionItem*) { updateLayers(); });
}
QVector<ItemWithMaterial*> MultiLayerItem::itemsWithMaterial() const
......@@ -120,7 +118,6 @@ void MultiLayerItem::removeLayer(LayerItem* item)
model()->removeItem(item);
}
void MultiLayerItem::moveLayer(LayerItem* item, LayerItem* beforeThisLayer)
{
int index = -1; // move to end
......@@ -129,17 +126,3 @@ void MultiLayerItem::moveLayer(LayerItem* item, LayerItem* beforeThisLayer)
model()->moveItem(item, this, index);
}
void MultiLayerItem::updateLayers()
{
QVector<LayerItem*> list = childrenOfType<LayerItem>();
for (auto* it = list.begin(); it != list.end(); ++it) {
(*it)->setRoughnessEnabled(it != list.begin());
if (it == list.begin() || it == (list.end() - 1)) {
(*it)->setThicknessEnabled(false);
(*it)->thickness().set(0.0);
} else
(*it)->setThicknessEnabled(true);
}
}
......@@ -62,9 +62,6 @@ public:
void removeLayer(LayerItem* item);
void moveLayer(LayerItem* item, LayerItem* beforeThisLayer);
private:
void updateLayers();
};
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_MULTILAYERITEM_H
......@@ -176,25 +176,6 @@ TEST_F(TestMapperForItem, onPropertyChange)
&& MultiLayerItem::isCrossCorrLengthPropertyName(w.m_reported_names[0]));
}
TEST_F(TestMapperForItem, onChildrenChange)
{
Widget w;
SampleModel model;
auto* multilayer = model.insertItem<MultiLayerItem>();
// Mapper is looking on parent; adding new child to parent
setItem(multilayer, &w);
EXPECT_TRUE(m_mapped_item == multilayer);
model.insertItem<LayerItem>(multilayer);
EXPECT_EQ(w.m_onPropertyChangeCount, 0);
EXPECT_EQ(w.m_onChildPropertyChangeCount, 2);
EXPECT_EQ(w.m_onParentChangeCount, 0);
EXPECT_EQ(w.m_onChildrenChangeCount, 1);
EXPECT_EQ(w.m_reported_items.size(), 2);
EXPECT_EQ(w.m_reported_names.size(), 2);
}
TEST_F(TestMapperForItem, onSiblingsChange)
{
Widget w;
......
#include "GUI/Model/Sample/LayerItem.h"
#include "GUI/Model/Sample/LayerRoughnessItems.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/Model/Sample/SampleModel.h"
#include "GUI/Model/Types/DoubleDescriptor.h"
#include "Tests/GTestWrapper/google_test.h"
class TestMultiLayerItem : public ::testing::Test {
};
//! Testing layer appearance (enabled, disabled) in a MultiLayer made of two default layers.
//!
//! In two layer system top and bottom layers should have disabled thickness and roughness.
TEST_F(TestMultiLayerItem, twoLayerSystem)
{
SampleModel model;
auto* multilayer = model.addMultiLayer();
auto* top = multilayer->addLayer();
auto* bottom = multilayer->addLayer();
// Thickness property should be disabled for top and bottom layers
EXPECT_FALSE(top->thicknessItem()->isEnabled());
EXPECT_FALSE(bottom->thicknessItem()->isEnabled());
// Thickness value should be 0.0 for top and bottom layers
EXPECT_EQ(top->thickness(), 0.0);
EXPECT_EQ(bottom->thickness(), 0.0);
// Roughness group property should be disabled for top, and enabled for bottom layers
EXPECT_FALSE(top->roughnessItem()->isEnabled());
EXPECT_TRUE(bottom->roughnessItem()->isEnabled());
// Default roughness should be "LayerZeroRoughness"
EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(top->roughness().currentItem()));
EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(bottom->roughness().currentItem()));
}
//! Testing layer appearance (enabled, disabled) in a MultiLayer made of three default layers.
//!
//! In three layer system middle layer's thickness/roughness should be enabled.
TEST_F(TestMultiLayerItem, threeLayerSystem)
{
SampleModel model;
auto* multilayer = model.addMultiLayer();
auto* top = multilayer->addLayer();
auto* middle = multilayer->addLayer();
auto* bottom = multilayer->addLayer();
// Thickness property should be disabled for top and bottom layers and enabled for middle
EXPECT_FALSE(top->thicknessItem()->isEnabled());
EXPECT_TRUE(middle->thicknessItem()->isEnabled());
EXPECT_FALSE(bottom->thicknessItem()->isEnabled());
// Thickness value should be 0.0 for top and bottom layers
EXPECT_EQ(top->thickness(), 0.0);
EXPECT_EQ(middle->thickness(), 0.0);
EXPECT_EQ(bottom->thickness(), 0.0);
// Roughness group property should be disabled for top, and enabled for other layers
EXPECT_FALSE(top->roughnessItem()->isEnabled());
EXPECT_TRUE(middle->roughnessItem()->isEnabled());
EXPECT_TRUE(bottom->roughnessItem()->isEnabled());
// Default roughness should be "LayerZeroRoughness"
EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(top->roughness().currentItem()));
EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(middle->roughness().currentItem()));
EXPECT_TRUE(std::holds_alternative<LayerZeroRoughnessItem*>(bottom->roughness().currentItem()));
}
//! Testing middle layer appearance when it is moved to the top.
//!
//! In three layer system, the moving of middle layer on top should lead to the disabling
//! of roughness/thickness.
TEST_F(TestMultiLayerItem, movingMiddleLayerOnTop)
{
SampleModel model;
auto* multilayer = model.addMultiLayer();
auto* top = multilayer->addLayer();
auto* middle = multilayer->addLayer();
auto* bottom = multilayer->addLayer();
const double thickness = 10.0;
middle->thickness().set(thickness);
// Thickness property should be disabled for top and bottom layers and enabled for middle
EXPECT_FALSE(top->thicknessItem()->isEnabled());
EXPECT_TRUE(middle->thicknessItem()->isEnabled());
EXPECT_FALSE(bottom->thicknessItem()->isEnabled());
// Roughness group property should be disabled for top, and enabled for other layers
EXPECT_FALSE(top->roughnessItem()->isEnabled());
EXPECT_TRUE(middle->roughnessItem()->isEnabled());
EXPECT_TRUE(bottom->roughnessItem()->isEnabled());
// Thickness value should be 0.0 for top and bottom layers
EXPECT_EQ(top->thickness(), 0.0);
EXPECT_EQ(middle->thickness(), thickness);
EXPECT_EQ(bottom->thickness(), 0.0);
// Moving middle layer to top
multilayer->moveLayer(middle, top);
// checking that middle is top now, and top layer is middle now
EXPECT_EQ(middle, multilayer->layers().at(0));
EXPECT_EQ(top, multilayer->layers().at(1));
// Thickness and roughness of middle layer should be disabled now
EXPECT_FALSE(middle->thicknessItem()->isEnabled());
EXPECT_FALSE(middle->roughnessItem()->isEnabled());
// And, thickness of middle should become 0 to stress the fact that it become top
EXPECT_EQ(middle->thickness(), 0.0);
// Thickness and roughness of former top layer should be enabled now, since it is in the middle
EXPECT_TRUE(top->thicknessItem()->isEnabled());
EXPECT_TRUE(top->roughnessItem()->isEnabled());
}
//! Testing layer appearance when it is moved from a MultiLayer to canvas.
//!
//! If top layer was moved to canvas, its thickness and roughness should be reenabled.
TEST_F(TestMultiLayerItem, movingLayerOnCanvas)
{
SampleModel model;
auto* multilayer = model.addMultiLayer();
auto* top = model.insertItem<LayerItem>(multilayer);
model.insertItem<LayerItem>(multilayer);
// Moving top layer to canvas
model.moveItem(top, nullptr);
// checking that it was moved
EXPECT_EQ(top->parent(), model.rootItem());
// thickness should be reenabled
// EXPECT_TRUE(top->getItem(LayerItem::P_THICKNESS)->isEnabled());
// EXPECT_TRUE(top->getItem(LayerItem::P_THICKNESS)->isEnabled());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment