Cleanup: Remove RNA data from TreeElement, get via type specific class
The `TreeElement.rnaptr` was only needed for RNA tree-elements. Now it can be gotten through the new type specific classes, e.g. `TreeElementRNAProperty.getPointerRNA()`.
This commit is contained in:
@@ -1910,20 +1910,20 @@ static void outliner_draw_rnacols(ARegion *region, int sizex)
|
||||
static void outliner_draw_rnabuts(
|
||||
uiBlock *block, ARegion *region, SpaceOutliner *space_outliner, int sizex, ListBase *lb)
|
||||
{
|
||||
PointerRNA *ptr;
|
||||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
|
||||
LISTBASE_FOREACH (TreeElement *, te, lb) {
|
||||
TreeStoreElem *tselem = TREESTORE(te);
|
||||
if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
|
||||
if (TreeElementRNAProperty *te_rna_prop = tree_element_cast<TreeElementRNAProperty>(te)) {
|
||||
ptr = &te->rnaptr;
|
||||
ptr = te_rna_prop->getPointerRNA();
|
||||
prop = te_rna_prop->getPropertyRNA();
|
||||
|
||||
if (!TSELEM_OPEN(tselem, space_outliner)) {
|
||||
if (RNA_property_type(prop) == PROP_POINTER) {
|
||||
uiBut *but = uiDefAutoButR(block,
|
||||
ptr,
|
||||
&ptr,
|
||||
prop,
|
||||
-1,
|
||||
"",
|
||||
@@ -1936,7 +1936,7 @@ static void outliner_draw_rnabuts(
|
||||
}
|
||||
else if (RNA_property_type(prop) == PROP_ENUM) {
|
||||
uiDefAutoButR(block,
|
||||
ptr,
|
||||
&ptr,
|
||||
prop,
|
||||
-1,
|
||||
nullptr,
|
||||
@@ -1948,7 +1948,7 @@ static void outliner_draw_rnabuts(
|
||||
}
|
||||
else {
|
||||
uiDefAutoButR(block,
|
||||
ptr,
|
||||
&ptr,
|
||||
prop,
|
||||
-1,
|
||||
"",
|
||||
@@ -1962,11 +1962,11 @@ static void outliner_draw_rnabuts(
|
||||
}
|
||||
else if (TreeElementRNAArrayElement *te_rna_array_elem =
|
||||
tree_element_cast<TreeElementRNAArrayElement>(te)) {
|
||||
ptr = &te->rnaptr;
|
||||
ptr = te_rna_array_elem->getPointerRNA();
|
||||
prop = te_rna_array_elem->getPropertyRNA();
|
||||
|
||||
uiDefAutoButR(block,
|
||||
ptr,
|
||||
&ptr,
|
||||
prop,
|
||||
te->index,
|
||||
"",
|
||||
@@ -2556,15 +2556,19 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te)
|
||||
case TSE_SEQUENCE_DUP:
|
||||
data.icon = ICON_SEQ_STRIP_DUPLICATE;
|
||||
break;
|
||||
case TSE_RNA_STRUCT:
|
||||
if (RNA_struct_is_ID(te->rnaptr.type)) {
|
||||
data.drag_id = (ID *)te->rnaptr.data;
|
||||
data.icon = RNA_struct_ui_icon(te->rnaptr.type);
|
||||
case TSE_RNA_STRUCT: {
|
||||
const TreeElementRNAStruct *te_rna_struct = tree_element_cast<TreeElementRNAStruct>(te);
|
||||
const PointerRNA &ptr = te_rna_struct->getPointerRNA();
|
||||
|
||||
if (RNA_struct_is_ID(ptr.type)) {
|
||||
data.drag_id = reinterpret_cast<ID *>(ptr.data);
|
||||
data.icon = RNA_struct_ui_icon(ptr.type);
|
||||
}
|
||||
else {
|
||||
data.icon = RNA_struct_ui_icon(te->rnaptr.type);
|
||||
data.icon = RNA_struct_ui_icon(ptr.type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSE_LAYER_COLLECTION:
|
||||
case TSE_SCENE_COLLECTION_BASE:
|
||||
case TSE_VIEW_COLLECTION_BASE: {
|
||||
@@ -3321,8 +3325,9 @@ static void outliner_draw_tree_element(bContext *C,
|
||||
offsx += 2 * ufac;
|
||||
}
|
||||
|
||||
const TreeElementRNAStruct *te_rna_struct = tree_element_cast<TreeElementRNAStruct>(te);
|
||||
if (ELEM(tselem->type, TSE_SOME_ID, TSE_LAYER_COLLECTION) ||
|
||||
((tselem->type == TSE_RNA_STRUCT) && RNA_struct_is_ID(te->rnaptr.type))) {
|
||||
(te_rna_struct && RNA_struct_is_ID(te_rna_struct->getPointerRNA().type))) {
|
||||
const BIFIconID lib_icon = (BIFIconID)UI_icon_from_library(tselem->id);
|
||||
if (lib_icon != ICON_NONE) {
|
||||
UI_icon_draw_alpha(
|
||||
|
||||
@@ -1747,7 +1747,8 @@ static void tree_element_to_path(TreeElement *te,
|
||||
LISTBASE_FOREACH (LinkData *, ld, &hierarchy) {
|
||||
/* get data */
|
||||
TreeElement *tem = (TreeElement *)ld->data;
|
||||
PointerRNA *ptr = &tem->rnaptr;
|
||||
TreeElementRNACommon *tem_rna = tree_element_cast<TreeElementRNACommon>(tem);
|
||||
PointerRNA ptr = tem_rna->getPointerRNA();
|
||||
|
||||
/* check if we're looking for first ID, or appending to path */
|
||||
if (*id) {
|
||||
@@ -1760,15 +1761,14 @@ static void tree_element_to_path(TreeElement *te,
|
||||
|
||||
if (RNA_property_type(prop) == PROP_POINTER) {
|
||||
/* for pointer we just append property name */
|
||||
newpath = RNA_path_append(*path, ptr, prop, 0, nullptr);
|
||||
newpath = RNA_path_append(*path, &ptr, prop, 0, nullptr);
|
||||
}
|
||||
else if (RNA_property_type(prop) == PROP_COLLECTION) {
|
||||
char buf[128], *name;
|
||||
|
||||
TreeElement *temnext = (TreeElement *)(ld->next->data);
|
||||
|
||||
PointerRNA *nextptr = &temnext->rnaptr;
|
||||
name = RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf), nullptr);
|
||||
PointerRNA nextptr = tree_element_cast<TreeElementRNACommon>(temnext)->getPointerRNA();
|
||||
name = RNA_struct_name_get_alloc(&nextptr, buf, sizeof(buf), nullptr);
|
||||
|
||||
if (name) {
|
||||
/* if possible, use name as a key in the path */
|
||||
@@ -1809,8 +1809,8 @@ static void tree_element_to_path(TreeElement *te,
|
||||
if (tree_element_cast<TreeElementRNAStruct>(tem)) {
|
||||
/* ptr->data not ptr->owner_id seems to be the one we want,
|
||||
* since ptr->data is sometimes the owner of this ID? */
|
||||
if (RNA_struct_is_ID(ptr->type)) {
|
||||
*id = reinterpret_cast<ID *>(ptr->data);
|
||||
if (RNA_struct_is_ID(ptr.type)) {
|
||||
*id = reinterpret_cast<ID *>(ptr.data);
|
||||
|
||||
/* clear path */
|
||||
if (*path) {
|
||||
@@ -1884,10 +1884,11 @@ static void do_outliner_drivers_editop(SpaceOutliner *space_outliner,
|
||||
short groupmode = KSP_GROUP_KSNAME;
|
||||
|
||||
TreeElementRNACommon *te_rna = tree_element_cast<TreeElementRNACommon>(te);
|
||||
PointerRNA ptr = te_rna ? te_rna->getPointerRNA() : PointerRNA_NULL;
|
||||
PropertyRNA *prop = te_rna ? te_rna->getPropertyRNA() : nullptr;
|
||||
|
||||
/* check if RNA-property described by this selected element is an animatable prop */
|
||||
if (prop && RNA_property_animateable(&te->rnaptr, prop)) {
|
||||
if (prop && RNA_property_animateable(&ptr, prop)) {
|
||||
/* get id + path + index info from the selected element */
|
||||
tree_element_to_path(te, tselem, &id, &path, &array_index, &flag, &groupmode);
|
||||
}
|
||||
@@ -1900,7 +1901,7 @@ static void do_outliner_drivers_editop(SpaceOutliner *space_outliner,
|
||||
/* array checks */
|
||||
if (flag & KSP_FLAG_WHOLE_ARRAY) {
|
||||
/* entire array was selected, so add drivers for all */
|
||||
arraylen = RNA_property_array_length(&te->rnaptr, prop);
|
||||
arraylen = RNA_property_array_length(&ptr, prop);
|
||||
}
|
||||
else {
|
||||
arraylen = array_index;
|
||||
@@ -2082,9 +2083,10 @@ static void do_outliner_keyingset_editop(SpaceOutliner *space_outliner,
|
||||
short groupmode = KSP_GROUP_KSNAME;
|
||||
|
||||
/* check if RNA-property described by this selected element is an animatable prop */
|
||||
if (TreeElementRNACommon *te_rna = tree_element_cast<TreeElementRNACommon>(te);
|
||||
te_rna && te_rna->getPropertyRNA() &&
|
||||
RNA_property_animateable(&te->rnaptr, te_rna->getPropertyRNA())) {
|
||||
const TreeElementRNACommon *te_rna = tree_element_cast<TreeElementRNACommon>(te);
|
||||
PointerRNA ptr = te_rna->getPointerRNA();
|
||||
if (te_rna && te_rna->getPropertyRNA() &&
|
||||
RNA_property_animateable(&ptr, te_rna->getPropertyRNA())) {
|
||||
/* get id + path + index info from the selected element */
|
||||
tree_element_to_path(te, tselem, &id, &path, &array_index, &flag, &groupmode);
|
||||
}
|
||||
|
||||
@@ -107,8 +107,7 @@ typedef struct TreeElement {
|
||||
short idcode; /* From TreeStore id. */
|
||||
short xend; /* Width of item display, for select. */
|
||||
const char *name;
|
||||
void *directdata; /* Armature Bones, Base, ... */
|
||||
PointerRNA rnaptr; /* RNA Pointer. */
|
||||
void *directdata; /* Armature Bones, Base, ... */
|
||||
} TreeElement;
|
||||
|
||||
typedef struct TreeElementIcon {
|
||||
|
||||
@@ -96,6 +96,7 @@
|
||||
#include "SEQ_sequencer.h"
|
||||
|
||||
#include "outliner_intern.hh"
|
||||
#include "tree/tree_element_rna.hh"
|
||||
#include "tree/tree_element_seq.hh"
|
||||
|
||||
static CLG_LogRef LOG = {"ed.outliner.tools"};
|
||||
@@ -1340,10 +1341,16 @@ static void data_select_linked_fn(int event,
|
||||
TreeStoreElem *UNUSED(tselem),
|
||||
void *C_v)
|
||||
{
|
||||
const TreeElementRNAStruct *te_rna_struct = tree_element_cast<TreeElementRNAStruct>(te);
|
||||
if (!te_rna_struct) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event == OL_DOP_SELECT_LINKED) {
|
||||
if (RNA_struct_is_ID(te->rnaptr.type)) {
|
||||
const PointerRNA &ptr = te_rna_struct->getPointerRNA();
|
||||
if (RNA_struct_is_ID(ptr.type)) {
|
||||
bContext *C = (bContext *)C_v;
|
||||
ID *id = reinterpret_cast<ID *>(te->rnaptr.data);
|
||||
ID *id = reinterpret_cast<ID *>(ptr.data);
|
||||
|
||||
ED_object_select_linked_by_id(C, id);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,6 @@ TreeElementRNACommon::TreeElementRNACommon(TreeElement &legacy_te, PointerRNA &r
|
||||
legacy_te_.name = IFACE_("(empty)");
|
||||
return;
|
||||
}
|
||||
|
||||
legacy_te_.rnaptr = rna_ptr;
|
||||
}
|
||||
|
||||
bool TreeElementRNACommon::isExpandValid() const
|
||||
@@ -73,6 +71,11 @@ bool TreeElementRNACommon::expandPoll(const SpaceOutliner &) const
|
||||
return isRNAValid();
|
||||
}
|
||||
|
||||
const PointerRNA &TreeElementRNACommon::getPointerRNA() const
|
||||
{
|
||||
return rna_ptr_;
|
||||
}
|
||||
|
||||
PropertyRNA *TreeElementRNACommon::getPropertyRNA() const
|
||||
{
|
||||
return nullptr;
|
||||
@@ -102,15 +105,15 @@ TreeElementRNAStruct::TreeElementRNAStruct(TreeElement &legacy_te, PointerRNA &r
|
||||
void TreeElementRNAStruct::expand(SpaceOutliner &space_outliner) const
|
||||
{
|
||||
TreeStoreElem &tselem = *TREESTORE(&legacy_te_);
|
||||
PointerRNA *ptr = &legacy_te_.rnaptr;
|
||||
PointerRNA ptr = rna_ptr_;
|
||||
|
||||
/* If searching don't expand RNA entries */
|
||||
if (SEARCHING_OUTLINER(&space_outliner) && BLI_strcasecmp("RNA", legacy_te_.name) == 0) {
|
||||
tselem.flag &= ~TSE_CHILDSEARCH;
|
||||
}
|
||||
|
||||
PropertyRNA *iterprop = RNA_struct_iterator_property(ptr->type);
|
||||
int tot = RNA_property_collection_length(ptr, iterprop);
|
||||
PropertyRNA *iterprop = RNA_struct_iterator_property(ptr.type);
|
||||
int tot = RNA_property_collection_length(&ptr, iterprop);
|
||||
CLAMP_MAX(tot, max_index);
|
||||
|
||||
TreeElementRNAProperty *parent_prop_te = legacy_te_.parent ?
|
||||
@@ -127,14 +130,10 @@ void TreeElementRNAStruct::expand(SpaceOutliner &space_outliner) const
|
||||
if (TSELEM_OPEN(&tselem, &space_outliner)) {
|
||||
for (int index = 0; index < tot; index++) {
|
||||
PointerRNA propptr;
|
||||
RNA_property_collection_lookup_int(ptr, iterprop, index, &propptr);
|
||||
RNA_property_collection_lookup_int(&ptr, iterprop, index, &propptr);
|
||||
if (!(RNA_property_flag(reinterpret_cast<PropertyRNA *>(propptr.data)) & PROP_HIDDEN)) {
|
||||
outliner_add_element(&space_outliner,
|
||||
&legacy_te_.subtree,
|
||||
(void *)ptr,
|
||||
&legacy_te_,
|
||||
TSE_RNA_PROPERTY,
|
||||
index);
|
||||
outliner_add_element(
|
||||
&space_outliner, &legacy_te_.subtree, &ptr, &legacy_te_, TSE_RNA_PROPERTY, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,7 +183,7 @@ void TreeElementRNAProperty::expand(SpaceOutliner &space_outliner) const
|
||||
if (pptr.data) {
|
||||
if (TSELEM_OPEN(&tselem, &space_outliner)) {
|
||||
outliner_add_element(
|
||||
&space_outliner, &legacy_te_.subtree, (void *)&pptr, &legacy_te_, TSE_RNA_STRUCT, -1);
|
||||
&space_outliner, &legacy_te_.subtree, &pptr, &legacy_te_, TSE_RNA_STRUCT, -1);
|
||||
}
|
||||
else {
|
||||
legacy_te_.flag |= TE_LAZY_CLOSED;
|
||||
@@ -199,12 +198,8 @@ void TreeElementRNAProperty::expand(SpaceOutliner &space_outliner) const
|
||||
for (int index = 0; index < tot; index++) {
|
||||
PointerRNA pptr;
|
||||
RNA_property_collection_lookup_int(&rna_ptr, rna_prop_, index, &pptr);
|
||||
outliner_add_element(&space_outliner,
|
||||
&legacy_te_.subtree,
|
||||
(void *)&pptr,
|
||||
&legacy_te_,
|
||||
TSE_RNA_STRUCT,
|
||||
index);
|
||||
outliner_add_element(
|
||||
&space_outliner, &legacy_te_.subtree, &pptr, &legacy_te_, TSE_RNA_STRUCT, index);
|
||||
}
|
||||
}
|
||||
else if (tot) {
|
||||
|
||||
@@ -43,6 +43,7 @@ class TreeElementRNACommon : public AbstractTreeElement {
|
||||
bool isExpandValid() const override;
|
||||
bool expandPoll(const SpaceOutliner &) const override;
|
||||
|
||||
const PointerRNA &getPointerRNA() const;
|
||||
/**
|
||||
* If this element represents a property or is part of a property (array element), this returns
|
||||
* the property. Otherwise nullptr.
|
||||
|
||||
Reference in New Issue
Block a user