[Libreoffice-commits] core.git: sc/inc sc/source

Eike Rathke erack at redhat.com
Mon May 4 18:03:34 PDT 2015


 sc/inc/document.hxx                |   14 ++++++++------
 sc/inc/table.hxx                   |   10 ++++------
 sc/source/core/data/documen3.cxx   |    2 +-
 sc/source/core/data/document.cxx   |    6 ++++--
 sc/source/core/data/table1.cxx     |   19 +++++++++++--------
 sc/source/core/data/table3.cxx     |   19 +++++--------------
 sc/source/ui/docshell/dbdocfun.cxx |    8 +++++++-
 7 files changed, 40 insertions(+), 38 deletions(-)

New commits:
commit 1aa43709f1eafe76bb5b2c658bf88c16bb73ea4f
Author: Eike Rathke <erack at redhat.com>
Date:   Mon May 4 23:45:15 2015 +0200

    rework Sort trim data area logic
    
    Determine the effective data area before all operations, so obtaining
    uniform row heights, the actual sort and setting dirty and setting row
    heights after sort is done only on the trimmed area.
    
    Also make sorting leading empty columns to the end work again if no row
    headers were given.
    
    Change-Id: If2b6a15ca69e0db2ca71a888a134f7441b04cc27

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 8f2e65f..e5e6a5b 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1096,12 +1096,17 @@ public:
 
                         @param o_bShrunk
                                Out parameter, true if area was shrunk, false if not.
+                        @param  bStickyTopRow
+                                If TRUE, do not adjust the top row.
+                        @param  bStickyLeftCol
+                                If TRUE, do not adjust the left column.
 
                         @returns true if there is any data, false if not.
                      */
     bool            ShrinkToUsedDataArea( bool& o_bShrunk,
                                           SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow,
-                                          SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly ) const;
+                                          SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly,
+                                          bool bStickyTopRow = false, bool bStickyLeftCol = false ) const;
 
     /**
      * Return the last non-empty row position in given columns that's no
@@ -1718,12 +1723,9 @@ public:
     SC_DLLPUBLIC SvNumberFormatter* GetFormatTable() const;
     SC_DLLPUBLIC SvNumberFormatter* CreateFormatTable() const;
 
-    /** Sort a range of data.
-        @param  rSortParam may get adjusted to the actual range used if it did
-                encompass leading or trailing empty blocks
-     */
+    /** Sort a range of data. */
     void Sort(
-        SCTAB nTab, ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
+        SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
         ScProgress* pProgress, sc::ReorderParam* pUndo );
 
     void Reorder( const sc::ReorderParam& rParam, ScProgress* pProgress );
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index d50bd5b..2b37a28 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -505,7 +505,8 @@ public:
                              bool bIncludeOld, bool bOnlyDown ) const;
 
     bool        ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rStartRow,
-                                      SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly ) const;
+                                      SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly,
+                                      bool bStickyTopRow, bool bStickyLeftCol ) const;
 
     SCROW GetLastDataRow( SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const;
 
@@ -844,12 +845,9 @@ public:
     void        StripHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 );
     void        ExtendHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2 );
 
-    /** Sort a range of data.
-        @param  rSortParam may get adjusted to the actual range used if it did
-                encompass leading or trailing empty blocks
-     */
+    /** Sort a range of data. */
     void Sort(
-        ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
+        const ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
         ScProgress* pProgress, sc::ReorderParam* pUndo );
 
     void Reorder( const sc::ReorderParam& rParam, ScProgress* pProgress );
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 57a20e1..bf359ef 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1342,7 +1342,7 @@ bool ScDocument::UpdateOutlineRow( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, b
 }
 
 void ScDocument::Sort(
-    SCTAB nTab, ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
+    SCTAB nTab, const ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
     ScProgress* pProgress, sc::ReorderParam* pUndo )
 {
     if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 9293b87..973a623 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1026,14 +1026,16 @@ bool ScDocument::ShrinkToDataArea(SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow
 }
 
 bool ScDocument::ShrinkToUsedDataArea( bool& o_bShrunk, SCTAB nTab, SCCOL& rStartCol,
-        SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly ) const
+        SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly,
+        bool bStickyTopRow, bool bStickyLeftCol ) const
 {
     if (!ValidTab(nTab) || nTab >= static_cast<SCTAB> (maTabs.size()) || !maTabs[nTab])
     {
         o_bShrunk = false;
         return false;
     }
-    return maTabs[nTab]->ShrinkToUsedDataArea( o_bShrunk, rStartCol, rStartRow, rEndCol, rEndRow, bColumnsOnly);
+    return maTabs[nTab]->ShrinkToUsedDataArea( o_bShrunk, rStartCol, rStartRow, rEndCol, rEndRow,
+            bColumnsOnly, bStickyTopRow, bStickyLeftCol);
 }
 
 SCROW ScDocument::GetLastDataRow( SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index e2beed5..b665e9f 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -912,7 +912,7 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S
 }
 
 bool ScTable::ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rStartRow,
-        SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly ) const
+        SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly, bool bStickyTopRow, bool bStickyLeftCol ) const
 {
     o_bShrunk = false;
 
@@ -943,20 +943,23 @@ bool ScTable::ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rS
                 break;  // while
         }
 
-        while (rStartCol < rEndCol)
+        if (!bStickyLeftCol)
         {
-            if (aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow))
+            while (rStartCol < rEndCol)
             {
-                ++rStartCol;
-                bChanged = true;
+                if (aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow))
+                {
+                    ++rStartCol;
+                    bChanged = true;
+                }
+                else
+                    break;  // while
             }
-            else
-                break;  // while
         }
 
         if (!bColumnsOnly)
         {
-            if (rStartRow < rEndRow)
+            if (!bStickyTopRow && rStartRow < rEndRow)
             {
                 bool bFound = false;
                 for (SCCOL i=rStartCol; i<=rEndCol && !bFound; i++)
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 49ecc0f..aab8e59 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1677,7 +1677,7 @@ void ScTable::DecoladeRow( ScSortInfoArray* pArray, SCROW nRow1, SCROW nRow2 )
 }
 
 void ScTable::Sort(
-    ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
+    const ScSortParam& rSortParam, bool bKeepQuery, bool bUpdateRefs,
     ScProgress* pProgress, sc::ReorderParam* pUndo )
 {
     InitSortCollator( rSortParam );
@@ -1693,20 +1693,13 @@ void ScTable::Sort(
         pUndo->mbHasHeaders = rSortParam.bHasHeader;
     }
 
-    // Trim empty leading and trailing column ranges.
-    while (rSortParam.nCol1 < rSortParam.nCol2 && aCol[rSortParam.nCol1].IsEmptyBlock(rSortParam.nRow1, rSortParam.nRow2))
-        ++rSortParam.nCol1;
-    while (rSortParam.nCol1 < rSortParam.nCol2 && aCol[rSortParam.nCol2].IsEmptyBlock(rSortParam.nRow1, rSortParam.nRow2))
-        --rSortParam.nCol2;
+    // It is assumed that the data area has already been trimmed as necessary.
 
+    aSortParam = rSortParam;    // must be assigned before calling IsSorted()
     if (rSortParam.bByRow)
     {
-        SCROW nLastRow = 0;
-        for (SCCOL nCol = rSortParam.nCol1; nCol <= rSortParam.nCol2; nCol++)
-            nLastRow = std::max(nLastRow, aCol[nCol].GetLastDataPos());
-        rSortParam.nRow2 = nLastRow = std::max( std::min(nLastRow, rSortParam.nRow2), rSortParam.nRow1);
+        SCROW nLastRow = rSortParam.nRow2;
         SCROW nRow1 = (rSortParam.bHasHeader ? rSortParam.nRow1 + 1 : rSortParam.nRow1);
-        aSortParam = rSortParam;    // must be assigned before calling IsSorted()
         if (nRow1 < nLastRow && !IsSorted(nRow1, nLastRow))
         {
             if(pProgress)
@@ -1733,9 +1726,7 @@ void ScTable::Sort(
     else
     {
         SCCOL nLastCol = rSortParam.nCol2;
-        SCCOL nCol1 = (rSortParam.bHasHeader ?
-            rSortParam.nCol1 + 1 : rSortParam.nCol1);
-        aSortParam = rSortParam;    // must be assigned before calling IsSorted()
+        SCCOL nCol1 = (rSortParam.bHasHeader ? rSortParam.nCol1 + 1 : rSortParam.nCol1);
         if (nCol1 < nLastCol && !IsSorted(nCol1, nLastCol))
         {
             if(pProgress)
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 170a76e..17b6132 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -526,6 +526,13 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
 
     WaitObject aWait( rDocShell.GetActiveDialogParent() );
 
+    // Adjust aLocalParam cols/rows to used data area. Keep sticky top row or
+    // column (depending on direction) in any case, not just if it has headers,
+    // so empty leading cells will be sorted to the end.
+    bool bShrunk = false;
+    rDoc.ShrinkToUsedDataArea( bShrunk, nTab, aLocalParam.nCol1, aLocalParam.nRow1,
+            aLocalParam.nCol2, aLocalParam.nRow2, false, aLocalParam.bByRow, !aLocalParam.bByRow);
+
     SCROW nStartRow = aLocalParam.nRow1;
     if (aLocalParam.bByRow && aLocalParam.bHasHeader && nStartRow < aLocalParam.nRow2)
         ++nStartRow;
@@ -556,7 +563,6 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
         ScInputOptions aInputOption = SC_MOD()->GetInputOptions();
         bool bUpdateRefs = aInputOption.GetSortRefUpdate();
         ScProgress aProgress(&rDocShell, ScGlobal::GetRscString(STR_PROGRESS_SORTING), 0);
-        // aLocalParam range now may get adapted to exclude empty edges
         rDoc.Sort(nTab, aLocalParam, bRepeatQuery, bUpdateRefs, &aProgress, &aUndoParam);
     }
 


More information about the Libreoffice-commits mailing list