sc/qa/unit/ucalc_formula.cxx  |   29 +++++++++++++++++++++++++++++
 sc/source/core/tool/token.cxx |   19 ++++++++++---------
 2 files changed, 39 insertions(+), 9 deletions(-)

New commits:
commit d7163dfa5c207f973d226e494c1620651c2b2b75
Author: Eike Rathke <er...@redhat.com>
Date:   Tue Jun 9 23:41:36 2015 +0200

    more tests for the implemented cases, tdf#90001
    
    Change-Id: Iec22ad67c9deaada827ba8eac47581e08f934353
    (cherry picked from commit 782c116b5ac39aef27c3a00f7fc145c9f755e3a3)

diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index fe7d417..09ac70d 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -1616,6 +1616,35 @@ void Test::testFormulaRefUpdateSheetsDelete()
     m_pDoc->InsertTab(2, "Sheet3");
     m_pDoc->InsertTab(3, "Sheet4");
 
+    m_pDoc->SetString(ScAddress(4,1,0), "=SUM(Sheet2.A4:Sheet4.A4)");
+    m_pDoc->SetString(ScAddress(4,2,0), "=SUM($Sheet2.A4:$Sheet4.A4)");
+    m_pDoc->DeleteTab(1);
+    if (!checkFormula(*m_pDoc, ScAddress(4,1,0), "SUM(Sheet3.A4:Sheet4.A4)"))
+        CPPUNIT_FAIL("Wrong Formula");
+    if (!checkFormula(*m_pDoc, ScAddress(4,2,0), "SUM($Sheet3.A4:$Sheet4.A4)"))
+        CPPUNIT_FAIL("Wrong Formula");
+    m_pDoc->InsertTab(1, "Sheet2");
+
+    m_pDoc->SetString(ScAddress(5,1,3), "=SUM(Sheet1.A5:Sheet3.A5)");
+    m_pDoc->SetString(ScAddress(5,2,3), "=SUM($Sheet1.A5:$Sheet3.A5)");
+    m_pDoc->DeleteTab(2);
+    if (!checkFormula(*m_pDoc, ScAddress(5,1,2), "SUM(Sheet1.A5:Sheet2.A5)"))
+        CPPUNIT_FAIL("Wrong Formula");
+    if (!checkFormula(*m_pDoc, ScAddress(5,2,2), "SUM($Sheet1.A5:$Sheet2.A5)"))
+        CPPUNIT_FAIL("Wrong Formula");
+    m_pDoc->InsertTab(2, "Sheet3");
+
+    m_pDoc->SetString(ScAddress(6,1,3), "=SUM(Sheet1.A6:Sheet3.A6)");
+    m_pDoc->SetString(ScAddress(6,2,3), "=SUM($Sheet1.A6:$Sheet3.A6)");
+    m_pDoc->DeleteTabs(0,3);
+    if (!checkFormula(*m_pDoc, ScAddress(6,1,0), "SUM(#REF!.A6:#REF!.A6)"))
+        CPPUNIT_FAIL("Wrong Formula");
+    if (!checkFormula(*m_pDoc, ScAddress(6,2,0), "SUM($#REF!.A6:$#REF!.A6)"))
+        CPPUNIT_FAIL("Wrong Formula");
+    m_pDoc->InsertTab(0, "Sheet1");
+    m_pDoc->InsertTab(1, "Sheet2");
+    m_pDoc->InsertTab(2, "Sheet3");
+
     m_pDoc->SetString(ScAddress(1,1,1), "=SUM(Sheet1.A2:Sheet3.A2");
     m_pDoc->SetString(ScAddress(2,1,1), "=SUM(Sheet1.A1:Sheet2.A1");
     m_pDoc->SetString(ScAddress(3,1,1), "=SUM(Sheet2.A3:Sheet4.A3");
commit 78fc4b66fe2d2c9c45cb90202679ebf5f490ffc5
Author: Eike Rathke <er...@redhat.com>
Date:   Tue Jun 9 23:29:38 2015 +0200

    correct 3D reference update on sheet deletion, tdf#90001 follow-up
    
    be1b3daeeb64a44e577510561d02147b87db72c2 missed a few cases
    * a deleted reference start was shifted by two sheets instead of one if
      the formula was on a sheet before the deleted one
    * a deleted reference end was not correct if the formula was on a sheet
      behind the deleted one and used relative sheet reference
    * #REF! wasn't set when the entire referenced range was deleted
    
    Change-Id: Ib9c7492a651a8429fa1c411c8e447593e366e09d
    (cherry picked from commit 20e4ccc6ba366cd70c9218e016ccff4025e3d816)

diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 00c9395..4e20d93 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -3471,25 +3471,26 @@ bool adjustDoubleRefOnDeleteTab(ScComplexRefData& rRef, 
SCTAB nDelPos, SCTAB nSh
     ScAddress aEndPos = rRef2.toAbs(rOldPos);
     bool bMoreThanOneTab = aStartPos.Tab() != aEndPos.Tab();
     bool bModified = false;
-    if (bMoreThanOneTab && aStartPos.Tab() == nDelPos)
+    if (bMoreThanOneTab && aStartPos.Tab() == nDelPos && nDelPos + nSheets <= 
aEndPos.Tab())
     {
-        if (rRef1.IsTabRel())
+        if (rRef1.IsTabRel() && aStartPos.Tab() < rOldPos.Tab())
         {
-            aStartPos.IncTab(nSheets);
-            rRef1.SetAddress(aStartPos, rOldPos);
+            rRef1.IncTab(nSheets);
+            bModified = true;
         }
-        bModified = true;
     }
     else
     {
         bModified = adjustSingleRefOnDeletedTab(rRef1, nDelPos, nSheets, 
rOldPos, rNewPos);
     }
 
-    if (bMoreThanOneTab && aEndPos.Tab() == nDelPos)
+    if (bMoreThanOneTab && aEndPos.Tab() == nDelPos && aStartPos.Tab() <= 
nDelPos - nSheets)
     {
-        aEndPos.IncTab(-nSheets);
-        rRef2.SetAddress(aEndPos, rNewPos);
-        bModified = true;
+        if (!rRef2.IsTabRel() || rOldPos.Tab() < aEndPos.Tab())
+        {
+            rRef2.IncTab(-nSheets);
+            bModified = true;
+        }
     }
     else
     {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to