sc/inc/sortparam.hxx              |   21 ++++++++++++++-------
 sc/source/core/data/sortparam.cxx |   24 +++++-------------------
 sc/source/ui/dbgui/tpsort.cxx     |    3 +--
 3 files changed, 20 insertions(+), 28 deletions(-)

New commits:
commit ca183d2a678900dcbc28ab2fd6cc34e0380cc0d2
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Wed Oct 29 10:41:31 2025 +0900
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Wed Dec 17 07:15:53 2025 +0100

    sc: simplify ScSortKeyState
    
    Use the default values so it's not needed to set them, just set
    what is different from the default.
    Document the struct.
    
    Change-Id: I7365080b006bc1959e890b21346fee847e382d25
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193290
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <[email protected]>

diff --git a/sc/inc/sortparam.hxx b/sc/inc/sortparam.hxx
index 3f266984bd47..0de0e3bbdb1b 100644
--- a/sc/inc/sortparam.hxx
+++ b/sc/inc/sortparam.hxx
@@ -37,19 +37,27 @@ struct ScQueryParam;
 class SdrObject;
 class ScPostIt;
 
+/** Sort by which color */
 enum class ScColorSortMode {
     None,
     TextColor,
     BackgroundColor
 };
 
+/** Sort key state defines one way how to sort the range.
+ *
+ * A range of values can be sorted in multiple way, each column a different 
way.
+ *
+ * For example: sort column A ascending and if the column when there are same 
values, define that those should be
+ * sorted descending usign the column C.
+ **/
 struct ScSortKeyState
 {
-    SCCOLROW nField;
-    bool     bDoSort;
-    bool     bAscending;
-    ScColorSortMode aColorSortMode;
-    Color    aColorSortColor;
+    SCCOLROW nField = 0;
+    bool bDoSort = false;
+    bool bAscending = true;
+    ScColorSortMode aColorSortMode = ScColorSortMode::None;
+    Color aColorSortColor;
 };
 
 /** Struct to hold non-data extended area, used with
@@ -144,8 +152,7 @@ struct SC_DLLPUBLIC ScSortParam
     SCTAB       nDestTab;
     SCCOL       nDestCol;
     SCROW       nDestRow;
-    ::std::vector<ScSortKeyState>
-                maKeyState;
+    std::vector<ScSortKeyState> maKeyState;
     css::lang::Locale aCollatorLocale;
     OUString    aCollatorAlgorithm;
     sal_uInt16  nCompatHeader;
diff --git a/sc/source/core/data/sortparam.cxx 
b/sc/source/core/data/sortparam.cxx
index 9e583bbeb5d2..9b6f483192e1 100644
--- a/sc/source/core/data/sortparam.cxx
+++ b/sc/source/core/data/sortparam.cxx
@@ -52,8 +52,6 @@ ScSortParam::~ScSortParam() {}
 
 void ScSortParam::Clear()
 {
-    ScSortKeyState aKeyState;
-
     nCol1=nCol2=nDestCol = 0;
     nRow1=nRow2=nDestRow = 0;
     nSourceTab = 0;
@@ -69,13 +67,8 @@ void ScSortParam::Clear()
     aCollatorLocale = css::lang::Locale();
     aCollatorAlgorithm.clear();
 
-    aKeyState.bDoSort = false;
-    aKeyState.nField = 0;
-    aKeyState.bAscending = true;
-    aKeyState.aColorSortMode = ScColorSortMode::None;
-
     // Initialize to default size
-    maKeyState.assign( DEFSORT, aKeyState );
+    maKeyState.assign(DEFSORT, {});
 }
 
 ScSortParam& ScSortParam::operator=( const ScSortParam& r )
@@ -184,7 +177,6 @@ ScSortParam::ScSortParam( const ScSubTotalParam& rSub, 
const ScSortParam& rOld )
                 key.bDoSort = true;
                 key.nField = group.nField;
                 key.bAscending = rSub.bAscending;
-                key.aColorSortMode = ScColorSortMode::None;
                 maKeyState.push_back(key);
             }
 
@@ -203,7 +195,6 @@ ScSortParam::ScSortParam( const ScSubTotalParam& rSub, 
const ScSortParam& rOld )
                 key.bDoSort = true;
                 key.nField = nThisField;
                 key.bAscending = rOld.maKeyState[i].bAscending;
-                key.aColorSortMode = ScColorSortMode::None;
                 maKeyState.push_back(key);
             }
         }
@@ -224,18 +215,13 @@ ScSortParam::ScSortParam( const ScQueryParam& rParam, 
SCCOL nCol ) :
 
     ScSortKeyState aKeyState;
     aKeyState.bDoSort = true;
-    aKeyState.nField = nCol;
     aKeyState.bAscending = true;
-    aKeyState.aColorSortMode = ScColorSortMode::None;
-
-    maKeyState.push_back( aKeyState );
+    aKeyState.nField = nCol;
+    maKeyState.push_back(aKeyState);
 
     // Set the rest
-    aKeyState.bDoSort = false;
-    aKeyState.nField = 0;
-
-    for (sal_uInt16 i=1; i<GetSortKeyCount(); i++)
-        maKeyState.push_back( aKeyState );
+    for (sal_uInt16 i = 1; i < GetSortKeyCount(); i++)
+        maKeyState.emplace_back();
 }
 
 void ScSortParam::MoveToDest()
diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx
index caafc07b800f..3c7ac5387ff1 100644
--- a/sc/source/ui/dbgui/tpsort.cxx
+++ b/sc/source/ui/dbgui/tpsort.cxx
@@ -392,8 +392,7 @@ sal_uInt16 ScTabPageSortFields::GetFieldSelPos( SCCOLROW 
nField )
 void ScTabPageSortFields::SetLastSortKey( sal_uInt16 nItem )
 {
     // Extend local SortParam copy
-    const ScSortKeyState atempKeyState = { 0, false, true, 
ScColorSortMode::None, Color() };
-    aSortData.maKeyState.push_back( atempKeyState );
+    aSortData.maKeyState.emplace_back(); // insert default key state
 
     // Add Sort Key Item
     ++nSortKeyCount;

Reply via email to