[Bf-blender-cvs] [7b615ca186c] master: Cleanup: Remove RNA data from TreeElement, get via type specific class

Julian Eisel noreply at git.blender.org
Wed Jan 26 19:16:08 CET 2022


Commit: 7b615ca186cab53736fe656d894814c6f92de0e3
Author: Julian Eisel
Date:   Wed Jan 26 19:11:34 2022 +0100
Branches: master
https://developer.blender.org/rB7b615ca186cab53736fe656d894814c6f92de0e3

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()`.

===================================================================

M	source/blender/editors/space_outliner/outliner_draw.cc
M	source/blender/editors/space_outliner/outliner_edit.cc
M	source/blender/editors/space_outliner/outliner_intern.hh
M	source/blender/editors/space_outliner/outliner_tools.cc
M	source/blender/editors/space_outliner/tree/tree_element_rna.cc
M	source/blender/editors/space_outliner/tree/tree_element_rna.hh

===================================================================

diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index 5d15e365dfa..5fd7559370f 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -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(
diff --git a/source/blender/editors/space_outliner/outliner_edit.cc b/source/blender/editors/space_outliner/outliner_edit.cc
index 693fdc863ce..b41b260b14a 100644
--- a/source/blender/editors/space_outliner/outliner_edit.cc
+++ b/source/blender/editors/space_outliner/outliner_edit.cc
@@ -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);
       }
diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh
index 5eb8b955dc5..9db1d73dc76 100644
--- a/source/blender/editors/space_outliner/outliner_intern.hh
+++ b/source/blender/editors/space_outliner/outliner_intern.hh
@@ -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 {
diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc
index eae77d70ac2..fa31025b550 100644
--- a/source/blender/editors/space_outliner/outliner_tools.cc
+++ b/source/blender/editors/space_outliner/outliner_tools.cc
@@ -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);
     }
diff --git a/source/blender/editors/space_outliner/tree/tree_element_rna.cc 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list