diff options
Diffstat (limited to 'source/blender/editors/space_outliner/tree')
-rw-r--r-- | source/blender/editors/space_outliner/tree/tree_element_rna.cc | 31 | ||||
-rw-r--r-- | source/blender/editors/space_outliner/tree/tree_element_rna.hh | 10 |
2 files changed, 34 insertions, 7 deletions
diff --git a/source/blender/editors/space_outliner/tree/tree_element_rna.cc b/source/blender/editors/space_outliner/tree/tree_element_rna.cc index 1aa30e1a99a..b39ff74b03a 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_rna.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_rna.cc @@ -73,6 +73,11 @@ bool TreeElementRNACommon::expandPoll(const SpaceOutliner &) const return isRNAValid(); } +PropertyRNA *TreeElementRNACommon::getRNAProperty() const +{ + return nullptr; +} + /* -------------------------------------------------------------------- */ /* RNA Struct */ @@ -108,10 +113,12 @@ void TreeElementRNAStruct::expand(SpaceOutliner &space_outliner) const int tot = RNA_property_collection_length(ptr, iterprop); CLAMP_MAX(tot, max_index); + TreeElementRNAProperty *parent_prop_te = legacy_te_.parent ? + tree_element_cast<TreeElementRNAProperty>( + legacy_te_.parent) : + nullptr; /* auto open these cases */ - if (!legacy_te_.parent || - (RNA_property_type(reinterpret_cast<PropertyRNA *>(legacy_te_.parent->directdata))) == - PROP_POINTER) { + if (!parent_prop_te || (RNA_property_type(parent_prop_te->getRNAProperty()) == PROP_POINTER)) { if (!tselem.used) { tselem.flag &= ~TSE_CLOSED; } @@ -157,7 +164,6 @@ TreeElementRNAProperty::TreeElementRNAProperty(TreeElement &legacy_te, PropertyRNA *prop = reinterpret_cast<PropertyRNA *>(propptr.data); legacy_te_.name = RNA_property_ui_name(prop); - legacy_te_.directdata = prop; rna_prop_ = prop; } @@ -225,6 +231,11 @@ void TreeElementRNAProperty::expand(SpaceOutliner &space_outliner) const } } +PropertyRNA *TreeElementRNAProperty::getRNAProperty() const +{ + return rna_prop_; +} + /* -------------------------------------------------------------------- */ /* RNA Array Element */ @@ -236,11 +247,9 @@ TreeElementRNAArrayElement::TreeElementRNAArrayElement(TreeElement &legacy_te, BLI_assert(legacy_te.store_elem->type == TSE_RNA_ARRAY_ELEM); BLI_assert(legacy_te.parent && (legacy_te.parent->store_elem->type == TSE_RNA_PROPERTY)); - PropertyRNA *prop = reinterpret_cast<PropertyRNA *>(legacy_te_.parent->directdata); - legacy_te_.directdata = prop; legacy_te_.index = index; - char c = RNA_property_array_item_char(prop, index); + char c = RNA_property_array_item_char(TreeElementRNAArrayElement::getRNAProperty(), index); legacy_te_.name = reinterpret_cast<char *>( MEM_callocN(sizeof(char[20]), "OutlinerRNAArrayName")); @@ -253,4 +262,12 @@ TreeElementRNAArrayElement::TreeElementRNAArrayElement(TreeElement &legacy_te, legacy_te_.flag |= TE_FREE_NAME; } +PropertyRNA *TreeElementRNAArrayElement::getRNAProperty() const +{ + /* Forward query to the parent (which is expected to be a #TreeElementRNAProperty). */ + const TreeElementRNAProperty *parent_prop_te = tree_element_cast<TreeElementRNAProperty>( + legacy_te_.parent); + return parent_prop_te ? parent_prop_te->getRNAProperty() : nullptr; +} + } // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/tree/tree_element_rna.hh b/source/blender/editors/space_outliner/tree/tree_element_rna.hh index 352b8763acb..bce527e724b 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_rna.hh +++ b/source/blender/editors/space_outliner/tree/tree_element_rna.hh @@ -43,6 +43,12 @@ class TreeElementRNACommon : public AbstractTreeElement { bool isExpandValid() const override; bool expandPoll(const SpaceOutliner &) const override; + /** + * If this element represents a property or is part of a property (array element), this returns + * the property. Otherwise nullptr. + */ + virtual PropertyRNA *getRNAProperty() const; + bool isRNAValid() const; }; @@ -63,6 +69,8 @@ class TreeElementRNAProperty : public TreeElementRNACommon { public: TreeElementRNAProperty(TreeElement &legacy_te, PointerRNA &rna_ptr, int index); void expand(SpaceOutliner &space_outliner) const override; + + PropertyRNA *getRNAProperty() const override; }; /* -------------------------------------------------------------------- */ @@ -70,6 +78,8 @@ class TreeElementRNAProperty : public TreeElementRNACommon { class TreeElementRNAArrayElement : public TreeElementRNACommon { public: TreeElementRNAArrayElement(TreeElement &legacy_te, PointerRNA &rna_ptr, int index); + + PropertyRNA *getRNAProperty() const override; }; } // namespace blender::ed::outliner |