sw/qa/uibase/fldui/fldui.cxx     |   22 ++++++++++++++++++++++
 sw/source/core/fields/fldbas.cxx |   13 +++++++++++++
 2 files changed, 35 insertions(+)

New commits:
commit 054085b09123098d2a72eea9f536fa3abcd99030
Author:     Andreas Heinisch <[email protected]>
AuthorDate: Wed Feb 25 02:00:33 2026 +0100
Commit:     Andreas Heinisch <[email protected]>
CommitDate: Fri Feb 27 08:18:10 2026 +0100

    tdf#45048 - Add subtype description for document statistics fields
    
    Change-Id: I1bb88eca425791aa764b21310ac2bdc9cd6c98a2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200283
    Reviewed-by: Andreas Heinisch <[email protected]>
    Tested-by: Jenkins

diff --git a/sw/qa/uibase/fldui/fldui.cxx b/sw/qa/uibase/fldui/fldui.cxx
index 3d442a52c3fa..c24432aacd99 100644
--- a/sw/qa/uibase/fldui/fldui.cxx
+++ b/sw/qa/uibase/fldui/fldui.cxx
@@ -20,6 +20,7 @@
 #include <fldmgr.hxx>
 #include <authfld.hxx>
 #include <ndtxt.hxx>
+#include <docufld.hxx>
 
 using namespace com::sun::star;
 
@@ -119,6 +120,27 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertRefmark)
     CPPUNIT_ASSERT_EQUAL(u"aaabbbccc"_ustr, pTextNode->GetText());
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf45048SubtypeDescription)
+{
+    // Create an empty document
+    createSwDoc();
+    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+
+    // Insert a filename field containing a specific format
+    SwFieldMgr aFieldMgr(pWrtShell);
+    SwInsertField_Data aFieldData(SwFieldTypesEnum::DocumentStatistics,
+                                  
static_cast<sal_uInt32>(SwDocStatSubType::Page), u""_ustr,
+                                  u""_ustr, SVX_NUM_PAGEDESC);
+    CPPUNIT_ASSERT(aFieldMgr.InsertField(aFieldData));
+    pWrtShell->SttEndDoc(true);
+
+    // Without the accompanying fix in place, this test would have failed with 
:
+    // - Expected: Statistics: Pages
+    // - Actual  : Statistics
+    // i.e. the description of the subtype ("Pages") was not included
+    CPPUNIT_ASSERT_EQUAL(u"Statistics: Pages"_ustr, 
aFieldMgr.GetCurField()->GetFieldName());
+}
+
 CPPUNIT_TEST_FIXTURE(Test, 
testTdf56126InsertConditionalFieldWithVerticalSeparator)
 {
     // Create an empty document
diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx
index c8e18513e046..6b5f0ca90165 100644
--- a/sw/source/core/fields/fldbas.cxx
+++ b/sw/source/core/fields/fldbas.cxx
@@ -48,6 +48,7 @@
 #include <chpfld.hxx>
 #include <flddat.hxx>
 #include <usrfld.hxx>
+#include <fldmgr.hxx>
 
 using namespace ::com::sun::star;
 
@@ -334,6 +335,18 @@ OUString SwField::GetFieldName() const
             (pDateTimeField->GetSubType() & SwDateTimeSubType::Date) ? 
SwFieldTypesEnum::Date : SwFieldTypesEnum::Time;
     }
     OUString sRet = SwFieldType::GetTypeStr( nTypeId );
+
+    // tdf#45048 - add subtype description for document statistics fields
+    if (nTypeId == SwFieldTypesEnum::DocumentStatistics)
+    {
+        std::vector<OUString> aDocStatSubTypesList;
+        SwFieldMgr().GetSubTypes(SwFieldTypesEnum::DocumentStatistics, 
aDocStatSubTypesList);
+        const auto nSubType
+            = static_cast<sal_uInt16>(static_cast<const 
SwDocStatField*>(this)->GetSubType());
+        if (nSubType < aDocStatSubTypesList.size())
+            sRet += ": " + aDocStatSubTypesList[nSubType];
+    }
+
     if (IsFixed())
     {
         sRet += " " + SwViewShell::GetShellRes()->aFixedStr;

Reply via email to