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

use DoubleDescriptors in LayerItem

parent b757f829
No related branches found
No related tags found
1 merge request!386Introduce value descriptors
......@@ -13,6 +13,7 @@
// ************************************************************************************************
#include "GUI/Models/LayerItem.h"
#include "GUI/Models/DoubleDescriptor.h"
#include "GUI/Models/GroupInfo.h"
#include "GUI/Models/LayerRoughnessItems.h"
#include "GUI/Models/MaterialItemUtils.h"
......@@ -57,19 +58,16 @@ QVector<ItemWithMaterial*> LayerItem::itemsWithMaterial()
return result;
}
double LayerItem::thickness() const
{
return getItemValue(P_THICKNESS).toDouble();
}
void LayerItem::setThickness(double thickness)
SessionItem* LayerItem::thicknessItem() const
{
setItemValue(P_THICKNESS, thickness);
return getItem(P_THICKNESS);
}
SessionItem* LayerItem::thicknessItem() const
DoubleDescriptor LayerItem::thickness() const
{
return getItem(P_THICKNESS);
DoubleDescriptor d(getItem(P_THICKNESS), Unit::nanometer);
d.tooltip = "Thickness of the layer";
return d;
}
bool LayerItem::isThicknessPropertyName(const QString& name)
......
......@@ -20,6 +20,7 @@
class LayerZeroRoughnessItem;
class LayerBasicRoughnessItem;
class ParticleLayoutItem;
class DoubleDescriptor;
class BA_CORE_API_ LayerItem : public ItemWithMaterial {
private:
......@@ -35,9 +36,8 @@ public:
QVector<ItemWithMaterial*> itemsWithMaterial();
double thickness() const;
void setThickness(double thickness);
SessionItem* thicknessItem() const;
DoubleDescriptor thickness() const;
static bool isThicknessPropertyName(const QString& name);
template <typename T> T* setRoughnessType();
......
......@@ -127,7 +127,7 @@ void MultiLayerItem::updateLayers()
if (it == list.begin() || it == (list.end() - 1)) {
(*it)->thicknessItem()->setEnabled(false);
(*it)->setThickness(0.0);
(*it)->thickness().set(0.0);
} else {
(*it)->thicknessItem()->setEnabled(true);
}
......
......@@ -13,6 +13,7 @@
// ************************************************************************************************
#include "GUI/Views/RealSpaceWidgets/TransformTo3D.h"
#include "GUI/Models/DoubleDescriptor.h"
#include "GUI/Models/FormFactorItems.h"
#include "GUI/Models/LayerItem.h"
#include "GUI/Models/MultiLayerItem.h"
......
......@@ -12,6 +12,7 @@
//
// ************************************************************************************************
#include "GUI/Models/DoubleDescriptor.h"
#include "GUI/Models/Error.h"
#include "GUI/Models/LayerItem.h"
#include "GUI/Models/SampleModel.h"
......
......@@ -139,7 +139,7 @@ TEST_F(TestMapperForItem, test_onPropertyChange)
setItem(layer, &w);
EXPECT_TRUE(m_mapped_item == layer);
layer->setThickness(1.0);
layer->thickness().set(1.0);
EXPECT_EQ(w.m_onPropertyChangeCount, 1);
EXPECT_EQ(w.m_onChildPropertyChangeCount, 0);
EXPECT_EQ(w.m_onParentChangeCount, 0);
......@@ -164,7 +164,7 @@ TEST_F(TestMapperForItem, test_onPropertyChange)
// Mapper is looking on parent; set property of child;
setItem(multilayer, &w);
EXPECT_TRUE(m_mapped_item == multilayer);
layer->setThickness(2.0);
layer->thickness().set(2.0);
EXPECT_EQ(w.m_onPropertyChangeCount, 0);
EXPECT_EQ(w.m_onChildPropertyChangeCount, 1);
EXPECT_EQ(w.m_onParentChangeCount, 0);
......@@ -260,7 +260,7 @@ TEST_F(TestMapperForItem, test_Subscription)
// Mapper is looking on child; set property of child
setItem(layer, &w, true);
EXPECT_TRUE(m_mapped_item == layer);
layer->setThickness(1.0);
layer->thickness().set(1.0);
EXPECT_EQ(w.m_onPropertyChangeCount, 1);
EXPECT_EQ(w.m_onChildPropertyChangeCount, 0);
EXPECT_EQ(w.m_onParentChangeCount, 0);
......@@ -270,12 +270,12 @@ TEST_F(TestMapperForItem, test_Subscription)
EXPECT_TRUE((w.m_reported_names.size() == 1)
&& LayerItem::isThicknessPropertyName(w.m_reported_names[0]));
layer->setThickness(2.0);
layer->thickness().set(2.0);
EXPECT_EQ(w.m_onPropertyChangeCount, 2);
// unsubscribe widget and check that it doesn't react on item value change
w.unsubscribe(m_mapper.get());
layer->setThickness(3.0);
layer->thickness().set(3.0);
EXPECT_EQ(w.m_onPropertyChangeCount, 2);
}
......@@ -293,12 +293,12 @@ TEST_F(TestMapperForItem, test_TwoWidgetsSubscription)
EXPECT_EQ(w1.m_onPropertyChangeCount, 0);
EXPECT_EQ(w2.m_onPropertyChangeCount, 0);
layer->setThickness(1.0);
layer->thickness().set(1.0);
EXPECT_EQ(w1.m_onPropertyChangeCount, 1);
EXPECT_EQ(w2.m_onPropertyChangeCount, 1);
w1.unsubscribe(m_mapper.get());
layer->setThickness(2.0);
layer->thickness().set(2.0);
EXPECT_EQ(w1.m_onPropertyChangeCount, 1);
EXPECT_EQ(w2.m_onPropertyChangeCount, 2);
}
......
#include "GUI/Models/DoubleDescriptor.h"
#include "GUI/Models/LayerItem.h"
#include "GUI/Models/LayerRoughnessItems.h"
#include "GUI/Models/MultiLayerItem.h"
......@@ -85,7 +86,7 @@ TEST_F(TestMultiLayerItem, test_movingMiddleLayerOnTop)
auto bottom = model.insertItem<LayerItem>(multilayer);
const double thickness = 10.0;
middle->setThickness(thickness);
middle->thickness().set(thickness);
// Thickness property should be disabled for top and bottom layers and enabled for middle
EXPECT_FALSE(top->thicknessItem()->isEnabled());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment