Merge remote-tracking branch 'origin/issue-1240'

This commit is contained in:
Matthias Koefferlein 2023-01-01 22:23:26 +01:00
commit 6136e4f8a0
5 changed files with 26 additions and 24 deletions

View File

@ -1856,6 +1856,22 @@ Layout::delete_layer (unsigned int n)
layer_properties_changed ();
}
unsigned int
Layout::get_layer (const db::LayerProperties &props)
{
int li = get_layer_maybe (props);
if (li >= 0) {
return (unsigned int) li;
}
if (props.is_null ()) {
// for a null layer info always create a layer
return insert_layer ();
} else {
return insert_layer (props);
}
}
unsigned int
Layout::insert_layer (const LayerProperties &props)
{

View File

@ -1644,15 +1644,12 @@ public:
* If there already is a layer matching the given properties, it's index will be
* returned. Otherwise a new layer with these properties is created.
*/
unsigned int get_layer (const db::LayerProperties &props)
{
return m_layers.get_layer (props);
}
unsigned int get_layer (const db::LayerProperties &props);
/**
* @brief Gets the layer with the given properties or -1 if such a layer does not exist
*/
int get_layer_maybe (const db::LayerProperties &props)
int get_layer_maybe (const db::LayerProperties &props) const
{
return m_layers.get_layer_maybe (props);
}

View File

@ -157,25 +157,8 @@ LayoutLayers::insert_layer (unsigned int index, const LayerProperties &props)
set_properties (index, props);
}
unsigned int
LayoutLayers::get_layer (const db::LayerProperties &lp)
{
if (lp.is_null ()) {
// for a null layer info always create a layer
return insert_layer ();
} else {
auto i = m_layers_by_props.find (lp);
if (i != m_layers_by_props.end () && i->first.log_equal (lp)) {
return i->second;
} else {
// otherwise create a new layer
return insert_layer (lp);
}
}
}
int
LayoutLayers::get_layer_maybe (const db::LayerProperties &lp)
LayoutLayers::get_layer_maybe (const db::LayerProperties &lp) const
{
if (lp.is_null ()) {
return -1;

View File

@ -187,7 +187,7 @@ public:
/**
* @brief Gets the layer with the given properties or -1 if such a layer does not exist.
*/
int get_layer_maybe (const db::LayerProperties &props);
int get_layer_maybe (const db::LayerProperties &props) const;
/**
* @brief Insert a new special layer with the given properties

View File

@ -478,6 +478,12 @@ TEST(4)
ps.insert (std::make_pair (g.properties_repository ().prop_name_id (tl::Variant (1)), tl::Variant ("XXX")));
prop_id = g.properties_repository ().properties_id (ps);
EXPECT_EQ (el.property_ids_dirty, true);
el.layer_properties_dirty = false;
EXPECT_EQ (g.get_layer_maybe (db::LayerProperties (42, 17)), -1);
EXPECT_EQ (el.layer_properties_dirty, false);
EXPECT_EQ (g.get_layer (db::LayerProperties (42, 17)) >= 0, true);
EXPECT_EQ (el.layer_properties_dirty, true); // new layer got inserted
}
static std::string l2s (const db::Layout &layout)