From d547d76c3bee10447de6fd90185212a177349386 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 12 Feb 2021 19:00:19 +0900 Subject: devtools: handle enum values and convert to enum names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now enum values were ignored, but now we show the converted enum numeric values to enum names, whcih is easier to understand than ust pure numberic values. Change-Id: I7579a731c20eda92f518ba0214619d8a98185cec Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110805 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- .../source/devtools/ObjectInspectorTreeHandler.cxx | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx index b00bbfc72c81..4d6d1bdad7bc 100644 --- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx +++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx @@ -27,6 +27,9 @@ #include #include #include +#include + +#include #include #include @@ -35,11 +38,15 @@ #include #include +#include using namespace css; namespace { +constexpr OUStringLiteral constTypeDescriptionManagerSingletonName + = u"/singletons/com.sun.star.reflection.theTypeDescriptionManager"; + uno::Reference TypeToIdlClass(const uno::Type& rType, const uno::Reference& xContext) { @@ -56,12 +63,17 @@ TypeToIdlClass(const uno::Type& rType, const uno::Reference& xContext) { + OUString aRetStr; + + // return early if we don't have any value + if (!aValue.hasValue()) + return aRetStr; + uno::Type aValType = aValue.getValueType(); uno::TypeClass eType = aValType.getTypeClass(); - OUString aRetStr; switch (eType) { case uno::TypeClass_INTERFACE: @@ -145,6 +157,27 @@ OUString AnyToString(const uno::Any& aValue) aRetStr = OUString::number(aNumber); break; } + case uno::TypeClass_ENUM: + { + sal_Int32 nIntValue = 0; + if (cppu::enum2int(nIntValue, aValue)) + { + uno::Reference xManager; + xManager.set(xContext->getValueByName(constTypeDescriptionManagerSingletonName), + uno::UNO_QUERY); + + uno::Reference xTypeDescription; + xTypeDescription.set(xManager->getByHierarchicalName(aValType.getTypeName()), + uno::UNO_QUERY); + + uno::Sequence aValues = xTypeDescription->getEnumValues(); + sal_Int32 nValuesIndex + = std::find(aValues.begin(), aValues.end(), nIntValue) - aValues.begin(); + uno::Sequence aNames = xTypeDescription->getEnumNames(); + aRetStr = aNames[nValuesIndex]; + } + break; + } default: break; @@ -282,7 +315,7 @@ public: { if (maAny.hasValue()) { - OUString aValue = AnyToString(maAny); + OUString aValue = AnyToString(maAny, mxContext); OUString aType = getAnyType(maAny, mxContext); return { -- cgit