Cleanup: GPv3: Const parent functions for tree nodes

This resolves #120220.

The `parent_group()` and `parent_node()` functions would be
callable on `const` instances but return a non-`const` pointer/reference.

This introduces `const` and non-`const` variants of these
methods.

Pull Request: https://projects.blender.org/blender/blender/pulls/120261
This commit is contained in:
Falk David
2024-04-04 18:41:38 +02:00
committed by Falk David
parent 298c9276e9
commit 398c4471ec
2 changed files with 24 additions and 9 deletions

View File

@@ -245,20 +245,23 @@ class TreeNode : public ::GreasePencilLayerTreeNode {
/**
* \returns this node as a #Layer.
*/
Layer &as_layer();
const Layer &as_layer() const;
Layer &as_layer();
/**
* \returns this node as a #LayerGroup.
*/
LayerGroup &as_group();
const LayerGroup &as_group() const;
LayerGroup &as_group();
/**
* \returns the parent layer group or nullptr for the root group.
*/
LayerGroup *parent_group() const;
TreeNode *parent_node() const;
const LayerGroup *parent_group() const;
LayerGroup *parent_group();
const TreeNode *parent_node() const;
TreeNode *parent_node();
/**
* \returns the number of non-null parents of the node.
@@ -374,7 +377,8 @@ class Layer : public ::GreasePencilLayer {
/**
* \returns the parent #LayerGroup of this layer.
*/
LayerGroup &parent_group() const;
const LayerGroup &parent_group() const;
LayerGroup &parent_group();
/**
* \returns the frames mapping.
@@ -750,7 +754,11 @@ inline bool Layer::is_empty() const
{
return (this->frames().is_empty());
}
inline LayerGroup &Layer::parent_group() const
inline const LayerGroup &Layer::parent_group() const
{
return *this->as_node().parent_group();
}
inline LayerGroup &Layer::parent_group()
{
return *this->as_node().parent_group();
}

View File

@@ -823,12 +823,19 @@ Layer &TreeNode::as_layer()
return *reinterpret_cast<Layer *>(this);
}
LayerGroup *TreeNode::parent_group() const
const LayerGroup *TreeNode::parent_group() const
{
return (this->parent) ? &this->parent->wrap() : nullptr;
}
TreeNode *TreeNode::parent_node() const
LayerGroup *TreeNode::parent_group()
{
return (this->parent) ? &this->parent->wrap() : nullptr;
}
const TreeNode *TreeNode::parent_node() const
{
return this->parent_group() ? &this->parent->wrap().as_node() : nullptr;
}
TreeNode *TreeNode::parent_node()
{
return this->parent_group() ? &this->parent->wrap().as_node() : nullptr;
}