sc/inc/pivot/PivotTableFormatOutput.hxx        |    9 ++++++---
 sc/source/core/data/PivotTableFormatOutput.cxx |   21 ++++++++++++++++-----
 2 files changed, 22 insertions(+), 8 deletions(-)

New commits:
commit 3dd12e20ddc0e1de5a654bea579285f1c67e29a9
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Wed Nov 12 14:52:29 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Thu Nov 13 01:26:15 2025 +0100

    sc: use a constant instead of -2 magic number for data dimension
    
    Change-Id: Iebd83615596dd90cb720e997d7ca61ba72d74a11
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193833
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/sc/inc/pivot/PivotTableFormatOutput.hxx 
b/sc/inc/pivot/PivotTableFormatOutput.hxx
index 3bbd19b28f36..42fe614451ad 100644
--- a/sc/inc/pivot/PivotTableFormatOutput.hxx
+++ b/sc/inc/pivot/PivotTableFormatOutput.hxx
@@ -35,10 +35,13 @@ enum class FormatResultDirection
     COLUMN
 };
 
+/// Data dimension constant
+constexpr tools::Long constDataDimension = -2;
+
 /// A field data for a format output,
 struct FormatOutputField
 {
-    tools::Long nDimension = -2;
+    tools::Long nDimension = constDataDimension;
     OUString aName;
     sal_Int32 nIndex = -1;
     bool bMatchesAll = false;
@@ -59,9 +62,9 @@ struct FormatOutputEntry
 /// data of one "field" that is part of a line
 struct FieldData
 {
-    tools::Long mnDimension = -2;
+    tools::Long mnDimension = constDataDimension;
     OUString aName;
-    tools::Long nIndex;
+    tools::Long nIndex = -1;
 
     bool bIsSet = false;
     bool bIsMember = false;
diff --git a/sc/source/core/data/PivotTableFormatOutput.cxx 
b/sc/source/core/data/PivotTableFormatOutput.cxx
index 45308a2129a0..caf95dd1785f 100644
--- a/sc/source/core/data/PivotTableFormatOutput.cxx
+++ b/sc/source/core/data/PivotTableFormatOutput.cxx
@@ -107,7 +107,7 @@ void fillOutputFieldFromSelection(FormatOutputField& 
rOutputField, Selection con
         else
             rOutputField.nIndex = rSelection.nIndices[0];
 
-        if (rOutputField.nDimension == -2)
+        if (rOutputField.nDimension == constDataDimension)
             rOutputField.aName = "DATA";
         else
             rOutputField.aName
@@ -195,8 +195,8 @@ void FormatOutput::prepare(SCTAB nTab, 
std::vector<ScDPOutLevelData> const& rCol
                 // Initialize column output fields to have 1 data output field
                 aEntry.aColumnOutputFields.resize(1);
                 FormatOutputField& rOutputField = 
aEntry.aColumnOutputFields[0];
-                rOutputField.nDimension = -2;
-                Selection const* pSelection = findSelection(rFormat, -2);
+                rOutputField.nDimension = constDataDimension;
+                Selection const* pSelection = findSelection(rFormat, 
constDataDimension);
                 if (pSelection)
                     fillOutputFieldFromSelection(rOutputField, *pSelection, 
nSelectionIndex,
                                                  aNameResolver);
@@ -272,11 +272,15 @@ void FormatOutput::insertFieldMember(size_t nFieldIndex, 
ScDPOutLevelData const&
         return;
 
     if (eResultDirection == sc::FormatResultDirection::ROW)
+    {
         fillLineAndFieldData(maRowLines, nFieldIndex, rField, nMemberIndex, 
rMember, nRowPos,
                              nColPos);
+    }
     else if (eResultDirection == sc::FormatResultDirection::COLUMN)
+    {
         fillLineAndFieldData(maColumnLines, nFieldIndex, rField, nMemberIndex, 
rMember, nColPos,
                              nRowPos);
+    }
 }
 namespace
 {
@@ -306,9 +310,11 @@ void checkForMatchingLines(std::vector<LineData> const& 
rLines,
                 {
                     if (rFormatEntry.bMatchesAll && !rFieldData.bSubtotal)
                         bFieldMatch = true;
-                    else if (nDimension == -2 && rFieldData.nIndex == 
rFormatEntry.nIndex)
+                    else if (nDimension == constDataDimension
+                             && rFieldData.nIndex == rFormatEntry.nIndex)
                         bFieldMatch = true;
-                    else if (nDimension != -2 && rFieldData.aName == 
rFormatEntry.aName)
+                    else if (nDimension != constDataDimension
+                             && rFieldData.aName == rFormatEntry.aName)
                         bFieldMatch = true;
                 }
                 else if (!rFormatEntry.bSet && eType == FormatType::Data && 
!rFieldData.bIsMember
@@ -404,6 +410,7 @@ void FormatOutput::apply(ScDocument& rDocument)
 
         std::vector<SCCOLROW> aRows;
         std::vector<SCCOLROW> aColumns;
+
         {
             std::vector<std::reference_wrapper<const LineData>> rMatches;
             std::vector<std::reference_wrapper<const LineData>> rMaybeMatches;
@@ -429,9 +436,13 @@ void FormatOutput::apply(ScDocument& rDocument)
         if (!aColumns.empty() && !aRows.empty() && rOutputEntry.eType == 
FormatType::Data)
         {
             for (SCCOLROW nRow : aRows)
+            {
                 for (SCCOLROW nColumn : aColumns)
+                {
                     rDocument.ApplyPattern(nColumn, nRow, *rOutputEntry.onTab,
                                            *rOutputEntry.pPattern);
+                }
+            }
         }
     }
 }

Reply via email to