[Libreoffice-commits] core.git: 3 commits - sc/qa sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Sat Oct 18 17:25:30 PDT 2014
sc/qa/unit/ucalc.hxx | 14 ++++---
sc/qa/unit/ucalc_formula.cxx | 80 ++++++++++++++++++++++++++++++++++++++++--
sc/source/core/tool/token.cxx | 47 ++++++++++++++++++++++++
3 files changed, 132 insertions(+), 9 deletions(-)
New commits:
commit 281847613bd3ae472523822f4be9c21cc353867e
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Sat Oct 18 20:22:53 2014 -0400
fdo#82047: Correctly adjust references in range names on row deletion.
Change-Id: Iac924b0b6932863f7f9cc088f996e0b07c340d2c
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index f3c38ab..cb36699 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -3161,6 +3161,53 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName(
if (adjustDoubleRefInName(rRef, rCxt, rPos))
aRes.mbReferenceModified = true;
}
+ else if (rCxt.mnRowDelta < 0)
+ {
+ // row(s) deleted.
+ if (rRef.Ref1.IsRowRel() || rRef.Ref2.IsRowRel())
+ // Don't modify relative references in names.
+ break;
+
+ if (aAbs.aStart.Col() < rCxt.maRange.aStart.Col() || rCxt.maRange.aEnd.Col() < aAbs.aEnd.Col())
+ // column range of the reference is not entirely in the deleted column range.
+ break;
+
+ ScRange aDeleted = rCxt.maRange;
+ aDeleted.aStart.IncRow(rCxt.mnRowDelta);
+ aDeleted.aEnd.SetRow(aDeleted.aStart.Row()-rCxt.mnRowDelta-1);
+
+ if (aAbs.aEnd.Row() < aDeleted.aStart.Row() || aDeleted.aEnd.Row() < aAbs.aStart.Row())
+ // reference range doesn't intersect with the deleted range.
+ break;
+
+ if (aDeleted.aStart.Row() <= aAbs.aStart.Row() && aAbs.aEnd.Row() <= aDeleted.aEnd.Row())
+ {
+ // This reference is entirely deleted.
+ rRef.Ref1.SetRowDeleted(true);
+ rRef.Ref2.SetRowDeleted(true);
+ aRes.mbReferenceModified = true;
+ break;
+ }
+
+ if (aAbs.aStart.Row() < aDeleted.aStart.Row())
+ {
+ if (aDeleted.aEnd.Row() < aAbs.aEnd.Row())
+ // Deleted in the middle. Make the reference shorter.
+ rRef.Ref2.IncRow(rCxt.mnRowDelta);
+ else
+ // Deleted at tail end. Cut off the lower part.
+ rRef.Ref2.SetAbsRow(aDeleted.aStart.Row()-1);
+ }
+ else
+ {
+ // Deleted at the top. Cut the top off and shift up.
+ rRef.Ref1.SetAbsRow(aDeleted.aEnd.Row()+1);
+ rRef.Ref1.IncRow(rCxt.mnRowDelta);
+ rRef.Ref2.IncRow(rCxt.mnRowDelta);
+ }
+
+ aRes.mbReferenceModified = true;
+ }
else if (rCxt.maRange.Intersects(aAbs))
{
if (rCxt.mnColDelta && rCxt.maRange.aStart.Row() <= aAbs.aStart.Row() && aAbs.aEnd.Row() <= rCxt.maRange.aEnd.Row())
commit 03075bfac25408d805b6cfecce56fa0c4cb9d88d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Sat Oct 18 20:22:28 2014 -0400
fdo#82047: Write test for this.
Change-Id: I0e5e54b517d3fb3cb28eb133b2cbe5bf5ca6b1d6
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 114ca8d..472779c 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -136,6 +136,7 @@ public:
void testFormulaRefUpdateName();
void testFormulaRefUpdateNameMove();
void testFormulaRefUpdateNameExpandRef();
+ void testFormulaRefUpdateNameDeleteRow();
void testFormulaRefUpdateValidity();
void testMultipleOperations();
void testFuncCOLUMN();
@@ -428,6 +429,7 @@ public:
CPPUNIT_TEST(testFormulaRefUpdateName);
CPPUNIT_TEST(testFormulaRefUpdateNameMove);
CPPUNIT_TEST(testFormulaRefUpdateNameExpandRef);
+ CPPUNIT_TEST(testFormulaRefUpdateNameDeleteRow);
CPPUNIT_TEST(testFormulaRefUpdateValidity);
CPPUNIT_TEST(testMultipleOperations);
CPPUNIT_TEST(testFuncCOLUMN);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 3ae29cb..5e0018a 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -2285,6 +2285,80 @@ void Test::testFormulaRefUpdateNameExpandRef()
m_pDoc->DeleteTab(0);
}
+void Test::testFormulaRefUpdateNameDeleteRow()
+{
+ m_pDoc->InsertTab(0, "Test");
+
+ // Insert a new name 'MyRange' to reference B2:B4.
+ bool bInserted = m_pDoc->InsertNewRangeName("MyRange", ScAddress(0,0,0), "$B$2:$B$4");
+ CPPUNIT_ASSERT(bInserted);
+
+ const ScRangeData* pName = m_pDoc->GetRangeName()->findByUpperName("MYRANGE");
+ CPPUNIT_ASSERT(pName);
+
+ sc::TokenStringContext aCxt(m_pDoc, formula::FormulaGrammar::GRAM_ENGLISH);
+ const ScTokenArray* pCode = pName->GetCode();
+ OUString aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0));
+ CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr);
+
+ ScDocFunc& rFunc = getDocShell().GetDocFunc();
+
+ // Delete row 3.
+ ScMarkData aMark;
+ aMark.SelectOneTable(0);
+ rFunc.DeleteCells(ScRange(0,2,0,MAXCOL,2,0), &aMark, DEL_CELLSUP, true, true);
+
+ // The reference in the name should get updated to B2:B3.
+ aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0));
+ CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$3"), aExpr);
+
+ // Delete row 3 again.
+ rFunc.DeleteCells(ScRange(0,2,0,MAXCOL,2,0), &aMark, DEL_CELLSUP, true, true);
+ aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0));
+ CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$2"), aExpr);
+
+ // Undo and check.
+ SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
+ CPPUNIT_ASSERT(pUndoMgr);
+
+ pUndoMgr->Undo();
+
+ pName = m_pDoc->GetRangeName()->findByUpperName("MYRANGE");
+ CPPUNIT_ASSERT(pName);
+ pCode = pName->GetCode();
+
+ aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0));
+ CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$3"), aExpr);
+
+ // Undo again and check.
+ pUndoMgr->Undo();
+
+ pName = m_pDoc->GetRangeName()->findByUpperName("MYRANGE");
+ CPPUNIT_ASSERT(pName);
+ pCode = pName->GetCode();
+
+ aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0));
+ CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr);
+
+ // Delete row 2-3.
+ rFunc.DeleteCells(ScRange(0,1,0,MAXCOL,2,0), &aMark, DEL_CELLSUP, true, true);
+
+ aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0));
+ CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$2"), aExpr);
+
+ // Undo and check.
+ pUndoMgr->Undo();
+
+ pName = m_pDoc->GetRangeName()->findByUpperName("MYRANGE");
+ CPPUNIT_ASSERT(pName);
+ pCode = pName->GetCode();
+
+ aExpr = pCode->CreateString(aCxt, ScAddress(0,0,0));
+ CPPUNIT_ASSERT_EQUAL(OUString("$B$2:$B$4"), aExpr);
+
+ m_pDoc->DeleteTab(0);
+}
+
void Test::testFormulaRefUpdateValidity()
{
struct {
commit 2f821f3b81d093cb6f738c1a51822e907ab80054
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Sat Oct 18 16:38:03 2014 -0400
NamedExpression is too lengthy. Let's just call it 'Name'. We'll know.
Change-Id: Ia4da886b050397831383005131ff9f21570934ad
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 0053646..114ca8d 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -133,9 +133,9 @@ public:
void testFormulaRefUpdateMoveUndo();
void testFormulaRefUpdateMoveToSheet();
void testFormulaRefUpdateDeleteContent();
- void testFormulaRefUpdateNamedExpression();
- void testFormulaRefUpdateNamedExpressionMove();
- void testFormulaRefUpdateNamedExpressionExpandRef();
+ void testFormulaRefUpdateName();
+ void testFormulaRefUpdateNameMove();
+ void testFormulaRefUpdateNameExpandRef();
void testFormulaRefUpdateValidity();
void testMultipleOperations();
void testFuncCOLUMN();
@@ -425,9 +425,9 @@ public:
CPPUNIT_TEST(testFormulaRefUpdateMoveUndo);
CPPUNIT_TEST(testFormulaRefUpdateMoveToSheet);
CPPUNIT_TEST(testFormulaRefUpdateDeleteContent);
- CPPUNIT_TEST(testFormulaRefUpdateNamedExpression);
- CPPUNIT_TEST(testFormulaRefUpdateNamedExpressionMove);
- CPPUNIT_TEST(testFormulaRefUpdateNamedExpressionExpandRef);
+ CPPUNIT_TEST(testFormulaRefUpdateName);
+ CPPUNIT_TEST(testFormulaRefUpdateNameMove);
+ CPPUNIT_TEST(testFormulaRefUpdateNameExpandRef);
CPPUNIT_TEST(testFormulaRefUpdateValidity);
CPPUNIT_TEST(testMultipleOperations);
CPPUNIT_TEST(testFuncCOLUMN);
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 84d34e0..3ae29cb 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -1944,7 +1944,7 @@ void Test::testFormulaRefUpdateDeleteContent()
m_pDoc->DeleteTab(0);
}
-void Test::testFormulaRefUpdateNamedExpression()
+void Test::testFormulaRefUpdateName()
{
m_pDoc->InsertTab(0, "Formula");
@@ -2075,7 +2075,7 @@ void Test::testFormulaRefUpdateNamedExpression()
m_pDoc->DeleteTab(0);
}
-void Test::testFormulaRefUpdateNamedExpressionMove()
+void Test::testFormulaRefUpdateNameMove()
{
sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn auto calc on.
@@ -2177,7 +2177,7 @@ void Test::testFormulaRefUpdateNamedExpressionMove()
m_pDoc->DeleteTab(0);
}
-void Test::testFormulaRefUpdateNamedExpressionExpandRef()
+void Test::testFormulaRefUpdateNameExpandRef()
{
setExpandRefs(true);
More information about the Libreoffice-commits
mailing list