Cleanup: Better name for new Outliner tree element type

The name `type` was confusing, since we usually use that in other ways.

Also updated the relating comments.
This commit is contained in:
Julian Eisel 2022-01-31 18:35:49 +01:00
parent fc5ef2452d
commit 64359f8998
2 changed files with 18 additions and 17 deletions

View File

@ -95,11 +95,12 @@ typedef struct TreeElement {
struct TreeElement *next, *prev, *parent;
/**
* Handle to the new C++ object (a derived type of base #AbstractTreeElement) that should replace
* #TreeElement. Step by step, data should be moved to it and operations based on the type should
* become virtual methods of the class hierarchy.
* The new inheritance based representation of the element (a derived type of base
* #AbstractTreeElement) that should eventually replace #TreeElement. Step by step, data should
* be moved to it and operations based on the type should become virtual methods of the class
* hierarchy.
*/
std::unique_ptr<outliner::AbstractTreeElement> type;
std::unique_ptr<outliner::AbstractTreeElement> abstract_element;
ListBase subtree;
int xs, ys; /* Do selection. */
@ -702,7 +703,7 @@ template<typename TreeElementT> TreeElementT *tree_element_cast(const TreeElemen
{
static_assert(std::is_base_of_v<AbstractTreeElement, TreeElementT>,
"Requested tree-element type must be an AbstractTreeElement");
return dynamic_cast<TreeElementT *>(te->type.get());
return dynamic_cast<TreeElementT *>(te->abstract_element.get());
}
} // namespace blender::ed::outliner

View File

@ -217,7 +217,7 @@ void outliner_free_tree_element(TreeElement *element, ListBase *parent_subtree)
if (element->flag & TE_FREE_NAME) {
MEM_freeN((void *)element->name);
}
element->type = nullptr;
element->abstract_element = nullptr;
MEM_delete(element);
}
@ -860,10 +860,10 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
te->parent = parent;
te->index = index; /* For data arrays. */
/* New C++ based type handle. Only some support this, eventually this should replace
* `TreeElement` entirely. */
te->type = AbstractTreeElement::createFromType(type, *te, idv);
if (te->type) {
/* New inheritance based element representation. Not all element types support this yet,
* eventually it should replace #TreeElement entirely. */
te->abstract_element = AbstractTreeElement::createFromType(type, *te, idv);
if (te->abstract_element) {
/* Element types ported to the new design are expected to have their name set at this point! */
BLI_assert(te->name != nullptr);
}
@ -887,12 +887,12 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
/* pass */
}
else if (type == TSE_SOME_ID) {
if (!te->type) {
if (!te->abstract_element) {
BLI_assert_msg(0, "Expected this ID type to be ported to new Outliner tree-element design");
}
}
else if (ELEM(type, TSE_LIBRARY_OVERRIDE_BASE, TSE_LIBRARY_OVERRIDE)) {
if (!te->type) {
if (!te->abstract_element) {
BLI_assert_msg(0,
"Expected override types to be ported to new Outliner tree-element design");
}
@ -903,20 +903,20 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
/* The new type design sets the name already, don't override that here. We need to figure out
* how to deal with the idcode for non-TSE_SOME_ID types still. Some rely on it... */
if (!te->type) {
if (!te->abstract_element) {
te->name = id->name + 2; /* Default, can be overridden by Library or non-ID data. */
}
te->idcode = GS(id->name);
}
if (te->type && te->type->isExpandValid()) {
tree_element_expand(*te->type, *space_outliner);
if (te->abstract_element && te->abstract_element->isExpandValid()) {
tree_element_expand(*te->abstract_element, *space_outliner);
}
else if (type == TSE_SOME_ID) {
/* ID types not (fully) ported to new design yet. */
if (te->type->expandPoll(*space_outliner)) {
if (te->abstract_element->expandPoll(*space_outliner)) {
outliner_add_id_contents(space_outliner, te, tselem, id);
te->type->postExpand(*space_outliner);
te->abstract_element->postExpand(*space_outliner);
}
}
else if (ELEM(type,