diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-02-11 21:14:36 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-02-12 11:21:27 +0100 |
commit | 89afca98f060be1f6a49c47cf7eaf123dd7ed4fa (patch) | |
tree | b78afef3ccaab7c3305a19c30f357834775cbd7f /sfx2 | |
parent | d8cfa8473c9b163747eb9172832fdbcbf886bde8 (diff) |
devtools: remove code duplication when creating child nodes
We essentially do the same thing in PropertyNode, StructNode and
SequenceNode when creating a child node. Remove the duplication
and move it into a common place (BasicValueNode) under
createNodeObjectForAny method.
Change-Id: If993c9018a537bf24683a526e76d438bd5105619
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110797
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/devtools/ObjectInspectorTreeHandler.cxx | 137 |
1 files changed, 32 insertions, 105 deletions
diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx index 8dbc389d2103..fd51a06ee3e8 100644 --- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx +++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx @@ -233,6 +233,8 @@ protected: return xInterface; } + ObjectInspectorNodeInterface* createNodeObjectForAny(OUString const& rName, uno::Any& rAny); + public: BasicValueNode(OUString const& rName, uno::Any const& rAny, uno::Reference<uno::XComponentContext> const& xContext) @@ -444,47 +446,12 @@ public: for (int i = 0; i < nLength; i++) { - uno::Any aCurrentAny = xIdlArray->get(maAny, i); + uno::Any aArrayValue = xIdlArray->get(maAny, i); uno::Reference<uno::XInterface> xCurrent; - if (aCurrentAny.hasValue()) - { - switch (aCurrentAny.getValueType().getTypeClass()) - { - case uno::TypeClass_INTERFACE: - { - auto xInterface - = uno::Reference<uno::XInterface>(aCurrentAny, uno::UNO_QUERY); - lclAppendNodeToParent( - pTree, rParent, - new GenericPropertiesNode(OUString::number(i), aCurrentAny, mxContext)); - } - break; - - case uno::TypeClass_SEQUENCE: - { - lclAppendNodeToParent( - pTree, rParent, - new SequenceNode(OUString::number(i), aCurrentAny, mxContext)); - } - break; - - case uno::TypeClass_STRUCT: - { - lclAppendNodeToParent( - pTree, rParent, - new StructNode(OUString::number(i), aCurrentAny, mxContext)); - } - break; - default: - { - lclAppendNodeToParent( - pTree, rParent, - new BasicValueNode(OUString::number(i), aCurrentAny, mxContext)); - } - break; - } - } + auto* pObjectInspectorNode = createNodeObjectForAny(OUString::number(i), aArrayValue); + if (pObjectInspectorNode) + lclAppendNodeToParent(pTree, rParent, pObjectInspectorNode); } } @@ -538,41 +505,9 @@ void GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree, { } - switch (aCurrentAny.getValueType().getTypeClass()) - { - case uno::TypeClass_INTERFACE: - { - auto xInterface = uno::Reference<uno::XInterface>(aCurrentAny, uno::UNO_QUERY); - if (xInterface.is()) - { - lclAppendNodeToParent( - pTree, rParent, - new GenericPropertiesNode(xProperty.Name, aCurrentAny, mxContext)); - } - } - break; - - case uno::TypeClass_SEQUENCE: - { - lclAppendNodeToParent(pTree, rParent, - new SequenceNode(xProperty.Name, aCurrentAny, mxContext)); - } - break; - - case uno::TypeClass_STRUCT: - { - lclAppendNodeToParent(pTree, rParent, - new StructNode(xProperty.Name, aCurrentAny, mxContext)); - } - break; - - default: - { - lclAppendNodeToParent(pTree, rParent, - new BasicValueNode(xProperty.Name, aCurrentAny, mxContext)); - } - break; - } + auto* pObjectInspectorNode = createNodeObjectForAny(xProperty.Name, aCurrentAny); + if (pObjectInspectorNode) + lclAppendNodeToParent(pTree, rParent, pObjectInspectorNode); } } @@ -589,42 +524,34 @@ void StructNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree, weld::Tree OUString aFieldName = xField->getName(); uno::Any aFieldValue = xField->get(maAny); - switch (aFieldValue.getValueType().getTypeClass()) - { - case uno::TypeClass_INTERFACE: - { - auto xInterface = uno::Reference<uno::XInterface>(aFieldValue, uno::UNO_QUERY); - if (xInterface.is()) - { - lclAppendNodeToParent( - pTree, rParent, - new GenericPropertiesNode(aFieldName, aFieldValue, mxContext)); - } - } - break; + auto* pObjectInspectorNode = createNodeObjectForAny(aFieldName, aFieldValue); + if (pObjectInspectorNode) + lclAppendNodeToParent(pTree, rParent, pObjectInspectorNode); + } +} - case uno::TypeClass_SEQUENCE: - { - lclAppendNodeToParent(pTree, rParent, - new SequenceNode(aFieldName, aFieldValue, mxContext)); - } - break; +ObjectInspectorNodeInterface* BasicValueNode::createNodeObjectForAny(OUString const& rName, + uno::Any& rAny) +{ + if (!rAny.hasValue()) + return nullptr; - case uno::TypeClass_STRUCT: - { - lclAppendNodeToParent(pTree, rParent, - new StructNode(aFieldName, aFieldValue, mxContext)); - } - break; + switch (rAny.getValueType().getTypeClass()) + { + case uno::TypeClass_INTERFACE: + return new GenericPropertiesNode(rName, rAny, mxContext); - default: - { - lclAppendNodeToParent(pTree, rParent, - new BasicValueNode(aFieldName, aFieldValue, mxContext)); - } + case uno::TypeClass_SEQUENCE: + return new SequenceNode(rName, rAny, mxContext); + + case uno::TypeClass_STRUCT: + return new StructNode(rName, rAny, mxContext); + + default: break; - } } + + return new BasicValueNode(rName, rAny, mxContext); } } // end anonymous namespace |