summaryrefslogtreecommitdiff
path: root/sfx2/source/devtools
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-03-15 16:22:40 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-03-16 03:41:58 +0100
commit42503d3e3004242b96d41c0722078fef6c69188a (patch)
tree4c7f104788f9caf2233b4f8ce6122459cd61ec82 /sfx2/source/devtools
parent2b9cf977810193b642761328ec15ec78ce245016 (diff)
devtools: extract conv. from enum value to name into a function
This conversion is not that trivial, as it needs to access some reflection UNO classes, so extract it to its own function. Change-Id: Iafd1aa7443f21d90efe60c70f725c07f6638feb0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112549 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sfx2/source/devtools')
-rw-r--r--sfx2/source/devtools/ObjectInspectorTreeHandler.cxx49
1 files changed, 27 insertions, 22 deletions
diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
index d5a9c9b990cf..a912e51fe704 100644
--- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
+++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
@@ -49,6 +49,27 @@ namespace
constexpr OUStringLiteral constTypeDescriptionManagerSingletonName
= u"/singletons/com.sun.star.reflection.theTypeDescriptionManager";
+OUString enumValueToEnumName(uno::Any const& aValue,
+ uno::Reference<uno::XComponentContext> const& xContext)
+{
+ sal_Int32 nIntValue = 0;
+ if (!cppu::enum2int(nIntValue, aValue))
+ return OUString();
+
+ uno::Reference<container::XHierarchicalNameAccess> xManager;
+ xManager.set(xContext->getValueByName(constTypeDescriptionManagerSingletonName),
+ uno::UNO_QUERY);
+
+ uno::Reference<reflection::XEnumTypeDescription> xTypeDescription;
+ xTypeDescription.set(xManager->getByHierarchicalName(aValue.getValueType().getTypeName()),
+ uno::UNO_QUERY);
+
+ uno::Sequence<sal_Int32> aValues = xTypeDescription->getEnumValues();
+ sal_Int32 nValuesIndex = std::find(aValues.begin(), aValues.end(), nIntValue) - aValues.begin();
+ uno::Sequence<OUString> aNames = xTypeDescription->getEnumNames();
+ return aNames[nValuesIndex];
+}
+
/** converts any value to a string */
OUString AnyToString(const uno::Any& aValue, const uno::Reference<uno::XComponentContext>& xContext)
{
@@ -56,7 +77,7 @@ OUString AnyToString(const uno::Any& aValue, const uno::Reference<uno::XComponen
// return early if we don't have any value
if (!aValue.hasValue())
- return "NULL";
+ return u"NULL";
uno::Type aValType = aValue.getValueType();
uno::TypeClass eType = aValType.getTypeClass();
@@ -67,14 +88,14 @@ OUString AnyToString(const uno::Any& aValue, const uno::Reference<uno::XComponen
{
uno::Reference<uno::XInterface> xInterface(aValue, uno::UNO_QUERY);
if (!xInterface.is())
- aRetStr = "NULL";
+ aRetStr = u"NULL";
else
- aRetStr = "<Object>";
+ aRetStr = u"<Object>";
break;
}
case uno::TypeClass_STRUCT:
{
- aRetStr = "<Struct>";
+ aRetStr = u"<Struct>";
break;
}
case uno::TypeClass_BOOLEAN:
@@ -91,7 +112,7 @@ OUString AnyToString(const uno::Any& aValue, const uno::Reference<uno::XComponen
}
case uno::TypeClass_STRING:
{
- aRetStr = "\"" + aValue.get<OUString>() + "\"";
+ aRetStr = u"\"" + aValue.get<OUString>() + u"\"";
break;
}
case uno::TypeClass_FLOAT:
@@ -156,23 +177,7 @@ OUString AnyToString(const uno::Any& aValue, const uno::Reference<uno::XComponen
}
case uno::TypeClass_ENUM:
{
- sal_Int32 nIntValue = 0;
- if (cppu::enum2int(nIntValue, aValue))
- {
- uno::Reference<container::XHierarchicalNameAccess> xManager;
- xManager.set(xContext->getValueByName(constTypeDescriptionManagerSingletonName),
- uno::UNO_QUERY);
-
- uno::Reference<reflection::XEnumTypeDescription> xTypeDescription;
- xTypeDescription.set(xManager->getByHierarchicalName(aValType.getTypeName()),
- uno::UNO_QUERY);
-
- uno::Sequence<sal_Int32> aValues = xTypeDescription->getEnumValues();
- sal_Int32 nValuesIndex
- = std::find(aValues.begin(), aValues.end(), nIntValue) - aValues.begin();
- uno::Sequence<OUString> aNames = xTypeDescription->getEnumNames();
- aRetStr = aNames[nValuesIndex];
- }
+ aRetStr = enumValueToEnumName(aValue, xContext);
break;
}