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

Eike Rathke erack at redhat.com
Mon Nov 24 18:14:28 PST 2014


 sc/inc/tokenarray.hxx           |    6 +++++
 sc/qa/unit/filters-test.cxx     |   47 ++++++++++++++++++++++++++++++++--------
 sc/qa/unit/ucalc.hxx            |    1 
 sc/qa/unit/ucalc_sort.cxx       |   13 ++++++++++-
 sc/source/core/data/column4.cxx |    2 +
 sc/source/core/data/table3.cxx  |    4 +++
 sc/source/core/tool/token.cxx   |   43 ++++++++++++++++++++++++++++++++++++
 7 files changed, 106 insertions(+), 10 deletions(-)

New commits:
commit 46e6f78f2b7595e7009975a2365395a74ca2df83
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Nov 25 03:07:00 2014 +0100

    check internal and external sheet references in both modes
    
    Actually fdo#77018 is not "fixed", but is a case for
    UpdateReferenceOnSort=true now.
    
    Change-Id: Ibc92c0a95749089c79787e38898bfe77fe30fb0f

diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index 1592241..db2ea40 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -80,7 +80,8 @@ public:
     void testEnhancedProtectionXLSX();
     void testSortWithSharedFormulasODS();
     void testSortWithSheetExternalReferencesODS();
-    void testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef xDocShRef, SCROW nRow1, SCROW nRow2 );
+    void testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef xDocShRef, SCROW nRow1, SCROW nRow2,
+            bool bCheckRelativeInSheet );
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testCVEs);
@@ -619,20 +620,44 @@ void ScFiltersTest::testSortWithSheetExternalReferencesODS()
     sc::AutoCalcSwitch aACSwitch(rDoc, true); // turn auto calc on.
     rDoc.CalcAll();
 
-    // The relative test only works with UpdateReferenceOnSort == true, set it
-    // now. We reset the value back to the original in tearDown()
+    // We reset the SortRefUpdate value back to the original in tearDown().
     ScInputOptions aInputOption = SC_MOD()->GetInputOptions();
+
+    // The complete relative test only works with UpdateReferenceOnSort==true,
+    // but the internal and external sheet references have to work in both
+    // modes.
+
     aInputOption.SetSortRefUpdate(true);
     SC_MOD()->SetInputOptions(aInputOption);
 
-    // Sort A15:D20 with relative row references.
-    testSortWithSheetExternalReferencesODS_Impl( xDocSh, 14, 19);
+    // Sort A15:D20 with relative row references. UpdateReferenceOnSort==true
+    // With in-sheet relative references.
+    testSortWithSheetExternalReferencesODS_Impl( xDocSh, 14, 19, true);
+
+    // Undo sort with relative references to perform same sort.
+    rDoc.GetUndoManager()->Undo();
+    rDoc.CalcAll();
+
+    aInputOption.SetSortRefUpdate(false);
+    SC_MOD()->SetInputOptions(aInputOption);
+
+    // Sort A15:D20 with relative row references. UpdateReferenceOnSort==false
+    // Without in-sheet relative references.
+    testSortWithSheetExternalReferencesODS_Impl( xDocSh, 14, 19, false);
+
+    // Undo sort with relative references to perform new sort.
+    rDoc.GetUndoManager()->Undo();
+    rDoc.CalcAll();
 
     // Sort with absolute references has to work in both UpdateReferenceOnSort
     // modes.
 
+    aInputOption.SetSortRefUpdate(true);
+    SC_MOD()->SetInputOptions(aInputOption);
+
     // Sort A23:D28 with absolute row references. UpdateReferenceOnSort==true
-    testSortWithSheetExternalReferencesODS_Impl( xDocSh, 22, 27);
+    // With in-sheet relative references.
+    testSortWithSheetExternalReferencesODS_Impl( xDocSh, 22, 27, true);
 
     // Undo sort with absolute references to perform same sort.
     rDoc.GetUndoManager()->Undo();
@@ -642,12 +667,14 @@ void ScFiltersTest::testSortWithSheetExternalReferencesODS()
     SC_MOD()->SetInputOptions(aInputOption);
 
     // Sort A23:D28 with absolute row references. UpdateReferenceOnSort==false
-    testSortWithSheetExternalReferencesODS_Impl( xDocSh, 22, 27);
+    // With in-sheet relative references.
+    testSortWithSheetExternalReferencesODS_Impl( xDocSh, 22, 27, true);
 
     xDocSh->DoClose();
 }
 
-void ScFiltersTest::testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef xDocSh, SCROW nRow1, SCROW nRow2 )
+void ScFiltersTest::testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef xDocSh, SCROW nRow1, SCROW nRow2,
+        bool bCheckRelativeInSheet )
 {
     ScDocument& rDoc = xDocSh->GetDocument();
 
@@ -694,9 +721,11 @@ void ScFiltersTest::testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef x
         double aCheck[] = { 5, 4, 3, 2, 1 };
         CPPUNIT_ASSERT_EQUAL( aCheck[nRow-nRow1-1], rDoc.GetValue( ScAddress(0,nRow,0)));
     }
+    // The last column (D) are in-sheet relative references.
+    SCCOL nEndCol = (bCheckRelativeInSheet ? 3 : 2);
     for (SCROW nRow=nRow1+1; nRow <= nRow2; ++nRow)
     {
-        for (SCCOL nCol=1; nCol <= 3; ++nCol)
+        for (SCCOL nCol=1; nCol <= nEndCol; ++nCol)
         {
             double aCheck[] = { 12345, 1234, 123, 12, 1 };
             CPPUNIT_ASSERT_EQUAL( aCheck[nRow-nRow1-1], rDoc.GetValue( ScAddress(nCol,nRow,0)));
commit fb2c3fec1b98b54f929d0cec64789b79306e03b1
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Nov 25 02:22:16 2014 +0100

    check that the fdo#79441 case works in both update references modes
    
    Change-Id: I4aa997847661021af27f27e8763a89a61f185f1f

diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 99883c5..7cad0ad 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -366,6 +366,7 @@ public:
     void testSortRefUpdate2();
     void testSortRefUpdate3();
     void testSortRefUpdate4();
+    void testSortRefUpdate4_Impl();
     void testSortRefUpdate5();
     void testSortRefUpdate6();
     void testSortOutOfPlaceResult();
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index e6ff96e..fa33810 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -1029,8 +1029,19 @@ void Test::testSortRefUpdate3()
 // testRefInterne.ods
 void Test::testSortRefUpdate4()
 {
-    SortRefUpdateSetter aUpdateSet;
+    // This test has to work in both update reference modes.
+    {
+        SortRefNoUpdateSetter aUpdateSet;
+        testSortRefUpdate4_Impl();
+    }
+    {
+        SortRefUpdateSetter aUpdateSet;
+        testSortRefUpdate4_Impl();
+    }
+}
 
+void Test::testSortRefUpdate4_Impl()
+{
     sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.
     m_pDoc->InsertTab(0, "Sort");
     m_pDoc->InsertTab(1, "Lesson1");
commit f0e7364603c9566bc158303c515c3274ccba62ca
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Nov 24 23:29:32 2014 +0100

    fix fdo#79441 again and keep references to other sheets during sort
    
    ... also if other references are not updated. References to other sheets
    are never to be treated as relative during sort, they are always
    absolute, even if they have relative row/column part references.
    
    Broken again during the big sort mess. Even if there was a unit test,
    which didn't help as it got disabled / adapted to the change..
    
    Change-Id: Ic0e61c5e1cb0728e20725c29e450ab0eb55c3305

diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index 84f4312..07f344b 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -206,6 +206,12 @@ public:
     void AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const ScAddress& rNewPos );
 
     /**
+     * Adjust all internal references on base position change if they point to
+     * a sheet other than the one of rOldPos.
+     */
+    void AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rOldPos, const ScAddress& rNewPos );
+
+    /**
      * Clear sheet deleted flag from internal reference tokens if the sheet
      * index falls within specified range.  Note that when a reference is on a
      * sheet that's been deleted, its referenced sheet index retains the
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index 777f5a4..42d166a 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -1023,6 +1023,8 @@ public:
             pCell->aPos.SetRow(nRow);
             if (mbUpdateRefs)
                 pCell->GetCode()->AdjustReferenceOnMovedOrigin(aOldPos, pCell->aPos);
+            else
+                pCell->GetCode()->AdjustReferenceOnMovedOriginIfOtherSheet(aOldPos, pCell->aPos);
         }
         else
         {
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 1111160..227dfab 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -868,6 +868,10 @@ void ScTable::SortReorderByRow(
                         pNew->CopyAllBroadcasters(*rCell.maCell.mpFormula);
                         pNew->GetCode()->AdjustReferenceOnMovedOrigin(aOldPos, aCellPos);
                     }
+                    else
+                    {
+                        pNew->GetCode()->AdjustReferenceOnMovedOriginIfOtherSheet(aOldPos, aCellPos);
+                    }
 
                     rCellStore.push_back(pNew);
                 }
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index f0030f6..77f7cc2 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -3426,6 +3426,49 @@ void ScTokenArray::AdjustReferenceOnMovedOrigin( const ScAddress& rOldPos, const
     }
 }
 
+void ScTokenArray::AdjustReferenceOnMovedOriginIfOtherSheet( const ScAddress& rOldPos, const ScAddress& rNewPos )
+{
+    FormulaToken** p = pCode;
+    FormulaToken** pEnd = p + static_cast<size_t>(nLen);
+    for (; p != pEnd; ++p)
+    {
+        bool bAdjust = false;
+        switch ((*p)->GetType())
+        {
+            case svExternalSingleRef:
+                bAdjust = true;     // always
+                // fallthru
+            case svSingleRef:
+            {
+                formula::FormulaToken* pToken = *p;
+                ScSingleRefData& rRef = *pToken->GetSingleRef();
+                ScAddress aAbs = rRef.toAbs(rOldPos);
+                if (!bAdjust)
+                    bAdjust = (aAbs.Tab() != rOldPos.Tab());
+                if (bAdjust)
+                    rRef.SetAddress(aAbs, rNewPos);
+            }
+            break;
+            case svExternalDoubleRef:
+                bAdjust = true;     // always
+                // fallthru
+            case svDoubleRef:
+            {
+                formula::FormulaToken* pToken = *p;
+                ScComplexRefData& rRef = *pToken->GetDoubleRef();
+                ScRange aAbs = rRef.toAbs(rOldPos);
+                if (!bAdjust)
+                    bAdjust = (rOldPos.Tab() < aAbs.aStart.Tab() || aAbs.aEnd.Tab() < rOldPos.Tab());
+                if (bAdjust)
+                    rRef.SetRange(aAbs, rNewPos);
+            }
+            break;
+            default:
+                ;
+        }
+    }
+}
+
 namespace {
 
 void clearTabDeletedFlag( ScSingleRefData& rRef, const ScAddress& rPos, SCTAB nStartTab, SCTAB nEndTab )


More information about the Libreoffice-commits mailing list