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

Eike Rathke erack at redhat.com
Sun Jun 21 09:37:20 PDT 2015


 sc/qa/unit/ucalc_formula.cxx     |   21 +++++++++++++++++++++
 sc/source/core/tool/compiler.cxx |   35 ++++++++++++++++-------------------
 sc/source/core/tool/token.cxx    |   12 +++---------
 3 files changed, 40 insertions(+), 28 deletions(-)

New commits:
commit 8ade7dce21143cd280935b174f4359d3d6d6d20b
Author: Eike Rathke <erack at redhat.com>
Date:   Sun Jun 21 18:23:54 2015 +0200

    unit test for adjustSingleRefInName() during column insertion
    
    Change-Id: Ie406361c3a3497619f4faf3680f389f3bdf76a4b

diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index b7ced94..0cb6cfb 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -1704,6 +1704,11 @@ void Test::testFormulaRefUpdateInsertColumns()
 
     m_pDoc->InsertTab(0, "Formula");
 
+    // Set named range for B2 with absolute column and relative same row.
+    const ScAddress aNamePos(0,1,0);
+    bool bInserted = m_pDoc->InsertNewRangeName("RowRelativeRange", aNamePos, "$Formula.$B2");
+    CPPUNIT_ASSERT(bInserted);
+
     // Set values in B1:B3.
     m_pDoc->SetValue(ScAddress(1,0,0), 1.0);
     m_pDoc->SetValue(ScAddress(1,1,0), 2.0);
@@ -1713,6 +1718,10 @@ void Test::testFormulaRefUpdateInsertColumns()
     m_pDoc->SetString(ScAddress(1,3,0), "=SUM(B1:B3)");
     CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(1,3,0)));
 
+    // Use named range in C2 to reference B2.
+    m_pDoc->SetString(ScAddress(2,1,0), "=RowRelativeRange");
+    CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+
     // Inert columns over A:B.
     ScMarkData aMark;
     aMark.SelectOneTable(0);
@@ -1725,6 +1734,18 @@ void Test::testFormulaRefUpdateInsertColumns()
 
     CPPUNIT_ASSERT_EQUAL(6.0, m_pDoc->GetValue(ScAddress(3,3,0)));
 
+    // Check that the named reference points to the moved cell, now D2.
+    ScRangeData* pName = m_pDoc->GetRangeName()->findByUpperName("ROWRELATIVERANGE");
+    CPPUNIT_ASSERT(pName);
+    OUString aSymbol;
+    pName->GetSymbol(aSymbol, aNamePos, formula::FormulaGrammar::GRAM_ENGLISH);
+    CPPUNIT_ASSERT_EQUAL(OUString("$Formula.$D2"), aSymbol);
+
+    // Check that the formula using the name, now in E2, still has the same result.
+    if (!checkFormula(*m_pDoc, ScAddress(4,1,0), "RowRelativeRange"))
+        CPPUNIT_FAIL("Wrong formula in E2 after column insertion.");
+    CPPUNIT_ASSERT_EQUAL(2.0, m_pDoc->GetValue(ScAddress(4,1,0)));
+
     m_pDoc->DeleteTab(0);
 }
 
commit f35673a825ecd4c4b331302c0408c65b9906f97f
Author: Eike Rathke <erack at redhat.com>
Date:   Sun Jun 21 17:50:10 2015 +0200

    adjustSingleRefInName() handle relative column and row independently
    
    The absolute part needs to be adjusted when the referenced column or row
    is moved, even if the other part is relative.
    
    Change-Id: Ibd6c2f58b7e01ced4d2e521f29295c044d27924a

diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 98ecefb..3585ec4 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -3227,18 +3227,12 @@ bool adjustSingleRefInName(
         return false;
     }
 
-    if (rRef.IsColRel() || rRef.IsRowRel())
-    {
-        // Adjust references only when both column and row are absolute.
-        return false;
-    }
-
     if (!rCxt.maRange.In(rRef.toAbs(rPos)))
         return false;
 
     bool bChanged = false;
 
-    if (rCxt.mnColDelta)
+    if (rCxt.mnColDelta && !rRef.IsColRel())
     {
         // Adjust absolute column reference.
         if (rCxt.maRange.aStart.Col() <= rRef.Col() && rRef.Col() <= rCxt.maRange.aEnd.Col())
@@ -3248,7 +3242,7 @@ bool adjustSingleRefInName(
         }
     }
 
-    if (rCxt.mnRowDelta)
+    if (rCxt.mnRowDelta && !rRef.IsRowRel())
     {
         // Adjust absolute row reference.
         if (rCxt.maRange.aStart.Row() <= rRef.Row() && rRef.Row() <= rCxt.maRange.aEnd.Row())
commit 6a3c3673d2d50cc42c1b92a841306232a8cf022f
Author: Eike Rathke <erack at redhat.com>
Date:   Sun Jun 21 00:14:41 2015 +0200

    TableRef: clone inner reference token in copy-ctor
    
    Change-Id: I4d195932bf81c105197de64cc592894e2492b801

diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 5561423..98ecefb 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -892,7 +892,7 @@ ScTableRefToken::ScTableRefToken( sal_uInt16 nIndex, ScTableRefToken::Item eItem
 
 ScTableRefToken::ScTableRefToken( const ScTableRefToken& r ) :
     FormulaToken(r),
-    mxAreaRefRPN(r.mxAreaRefRPN),
+    mxAreaRefRPN(r.mxAreaRefRPN->Clone()),
     mnIndex(r.mnIndex),
     meItem(r.meItem)
 {
commit 9e978e58650c18500aaea6e2e927d5439c65917f
Author: Eike Rathke <erack at redhat.com>
Date:   Sat Jun 20 00:37:54 2015 +0200

    TableRef: sheet reference always absolute and 3D
    
    Change-Id: I17a2889c21efe9943b348049a1e9384df167435d

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 876cc7b..0a2c60a 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -5202,12 +5202,7 @@ bool ScCompiler::HandleTableRef()
                     {
                         aRefData.SetRowRel( true);
                     }
-                    if (aRange.aStart.Tab() != aPos.Tab())
-                        aRefData.SetFlag3D( true);
-                    else
-                    {
-                        aRefData.SetTabRel( true);
-                    }
+                    aRefData.SetFlag3D( true);
                     aRefData.SetAddress( aRange.aStart, aPos);
                     pTR->SetAreaRefRPN( pNew->AddSingleReference( aRefData ));
                 }
@@ -5222,13 +5217,7 @@ bool ScCompiler::HandleTableRef()
                         aRefData.Ref1.SetRowRel( true);
                         aRefData.Ref2.SetRowRel( true);
                     }
-                    if (aRange.aStart.Tab() != aPos.Tab())
-                        aRefData.Ref1.SetFlag3D( true);
-                    else
-                    {
-                        aRefData.Ref1.SetTabRel( true);
-                        aRefData.Ref2.SetTabRel( true);
-                    }
+                    aRefData.Ref1.SetFlag3D( true);
                     aRefData.SetRange( aRange, aPos);
                     pTR->SetAreaRefRPN( pNew->AddDoubleReference( aRefData ));
                 }
commit afa74bb6e8b828bdc08b8b214bce9c9c3797abdb
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jun 19 23:57:43 2015 +0200

    TableRef: generated reference's column relativity follows column specifier
    
    Change-Id: Ie0781bf5ebeb4cec0e3bb96f8c471e469b1b223a

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 2d7b37d..876cc7b 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -5078,6 +5078,8 @@ bool ScCompiler::HandleTableRef()
                 break;
         }
         bool bColumnRange = false;
+        bool bCol1Rel = false;
+        bool bCol2Rel = false;
         int nLevel = 0;
         if (bForwardToClose && GetTokenIfOpCode( ocTableRefOpen))
         {
@@ -5127,6 +5129,7 @@ bool ScCompiler::HandleTableRef()
                             if (eState == sOpen && p->GetType() == svSingleRef)
                             {
                                 bColumnRange = true;
+                                bCol1Rel = p->GetSingleRef()->IsColRel();
                                 eState = sLast;
                             }
                             else
@@ -5172,6 +5175,7 @@ bool ScCompiler::HandleTableRef()
                                 {
                                     aColRange.aEnd = mpToken->GetSingleRef()->toAbs( aPos);
                                     aColRange.Justify();
+                                    bCol2Rel = mpToken->GetSingleRef()->IsColRel();
                                 }
                             }
                         }
@@ -5193,7 +5197,7 @@ bool ScCompiler::HandleTableRef()
                 {
                     ScSingleRefData aRefData;
                     aRefData.InitFlags();
-                    aRefData.SetColRel( true);
+                    aRefData.SetColRel( bCol1Rel);
                     if (eItem == ScTableRefToken::THIS_ROW)
                     {
                         aRefData.SetRowRel( true);
@@ -5211,8 +5215,8 @@ bool ScCompiler::HandleTableRef()
                 {
                     ScComplexRefData aRefData;
                     aRefData.InitFlags();
-                    aRefData.Ref1.SetColRel( true);
-                    aRefData.Ref2.SetColRel( true);
+                    aRefData.Ref1.SetColRel( bCol1Rel);
+                    aRefData.Ref2.SetColRel( bCol2Rel);
                     if (eItem == ScTableRefToken::THIS_ROW)
                     {
                         aRefData.Ref1.SetRowRel( true);
commit 2a5f48f7f48804d5ac7d67c5a4f3f28315815a7a
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jun 19 22:49:50 2015 +0200

    TableRef: column specifier is an absolute reference
    
    Change-Id: Ia7de5dc101a410aa1c25f36e64627fa3461ee772

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index e4a7293..2d7b37d 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3450,10 +3450,14 @@ bool ScCompiler::IsTableRefColumn( const OUString& rName ) const
             OUString aStr = aIter.getString();
             if (ScGlobal::GetpTransliteration()->isEqual( aStr, aName))
             {
+                /* XXX NOTE: we could init the column as relative so copying a
+                 * formula across columns would point to the relative column,
+                 * but do it absolute because:
+                 * a) it makes the reference work in named expressions without
+                 * having to distinguish
+                 * b) Excel does it the same. */
                 ScSingleRefData aRef;
-                aRef.InitFlags();
-                aRef.SetColRel( true );
-                aRef.SetAddress( aIter.GetPos(), aPos);
+                aRef.InitAddress( aIter.GetPos());
                 maRawToken.SetSingleReference( aRef );
                 return true;
             }


More information about the Libreoffice-commits mailing list