Cleanup: GPv3: Remove unnecessary layer group API functions

The `LayerGroup` class had an API to add layers and layer groups.
The only thing these did was allocate a new layer/group and then
call the `add_node` API.

This removes these functions (they were only used in a single
place anyway) and does the allocation of the new layer/group
directly in the grease pencil API. This removes a few lines of
code and makes everything a bit easier to read.
This commit is contained in:
Falk David
2024-05-13 17:59:14 +02:00
parent 7006eb4805
commit 65f05f4284
2 changed files with 11 additions and 36 deletions

View File

@@ -636,18 +636,6 @@ class LayerGroup : public ::GreasePencilLayerTreeGroup {
void update_from_dna_read();
protected:
/**
* Adds a new layer named \a name at the end of this group and returns it.
*/
Layer &add_layer(StringRefNull name);
/**
* Duplicates the \a duplicate_layer, adds it at the end of this group and returns it.
*/
Layer &duplicate_layer(const Layer &duplicate_layer);
/**
* Adds a new group named \a name at the end of this group and returns it.
*/
LayerGroup &add_group(StringRefNull name);
/**
* Adds an existing \a node at the end of this group.
*/

View File

@@ -1371,24 +1371,6 @@ LayerGroup &LayerGroup::operator=(const LayerGroup &other)
return *this;
}
Layer &LayerGroup::add_layer(StringRefNull name)
{
Layer *new_layer = MEM_new<Layer>(__func__, name);
return this->add_node(new_layer->as_node()).as_layer();
}
Layer &LayerGroup::duplicate_layer(const Layer &duplicate_layer)
{
Layer *new_layer = MEM_new<Layer>(__func__, duplicate_layer);
return this->add_node(new_layer->as_node()).as_layer();
}
LayerGroup &LayerGroup::add_group(StringRefNull name)
{
LayerGroup *new_group = MEM_new<LayerGroup>(__func__, name);
return this->add_node(new_group->as_node()).as_group();
}
TreeNode &LayerGroup::add_node(TreeNode &node)
{
BLI_addtail(&this->children, &node);
@@ -2737,7 +2719,8 @@ blender::bke::greasepencil::Layer &GreasePencil::add_layer(const blender::String
std::string unique_name = unique_layer_name(*this, name);
const int numLayers = layers().size();
CustomData_realloc(&layers_data, numLayers, numLayers + 1);
return root_group().add_layer(unique_name);
bke::greasepencil::Layer *new_layer = MEM_new<bke::greasepencil::Layer>(__func__, unique_name);
return root_group().add_node(new_layer->as_node()).as_layer();
}
blender::bke::greasepencil::Layer &GreasePencil::add_layer(
@@ -2756,10 +2739,12 @@ blender::bke::greasepencil::Layer &GreasePencil::duplicate_layer(
std::string unique_name = unique_layer_name(*this, duplicate_layer.name());
const int numLayers = layers().size();
CustomData_realloc(&layers_data, numLayers, numLayers + 1);
bke::greasepencil::Layer &new_layer = root_group().duplicate_layer(duplicate_layer);
this->update_drawing_users_for_layer(new_layer);
new_layer.set_name(unique_name);
return new_layer;
bke::greasepencil::Layer *new_layer = MEM_new<bke::greasepencil::Layer>(__func__,
duplicate_layer);
root_group().add_node(new_layer->as_node());
this->update_drawing_users_for_layer(*new_layer);
new_layer->set_name(unique_name);
return *new_layer;
}
blender::bke::greasepencil::Layer &GreasePencil::duplicate_layer(
@@ -2777,7 +2762,9 @@ blender::bke::greasepencil::LayerGroup &GreasePencil::add_layer_group(
{
using namespace blender;
std::string unique_name = unique_layer_group_name(*this, name);
return parent_group.add_group(unique_name);
bke::greasepencil::LayerGroup *new_group = MEM_new<bke::greasepencil::LayerGroup>(__func__,
unique_name);
return parent_group.add_node(new_group->as_node()).as_group();
}
static void reorder_customdata(CustomData &data, const Span<int> new_by_old_map)