summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-11-01 13:28:00 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-11-04 13:59:17 -0500
commit13b69492716c506976a31a26fe0590aa06b3d1a3 (patch)
tree05837961fe9f727d2fcc8697c69cd7b2b7fc16f5 /sc
parent07b66cd3ac1a9f6c7b61a1d7da6e9d266e6de92d (diff)
We need to update sheet positions of range names when modifying sheets.
And add Dump() to ScRangeData for debugging convenience and re-enable previously failed test cases. Change-Id: I9d8f41a8be4c9c301254ef300c7b7f0c1ea7f393
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/rangenam.hxx5
-rw-r--r--sc/qa/unit/ucalc_formula.cxx13
-rw-r--r--sc/source/core/tool/rangenam.cxx20
3 files changed, 36 insertions, 2 deletions
diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index 65fae47150b1..6113709b118b 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -24,6 +24,7 @@
#include "address.hxx"
#include "formula/grammar.hxx"
#include "scdllapi.h"
+#include "calcmacros.hxx"
#include <map>
#include <vector>
@@ -151,6 +152,10 @@ public:
SCCOL GetMaxCol() const;
void CompileUnresolvedXML();
+
+#if DEBUG_FORMULA_COMPILER
+ void Dump() const;
+#endif
};
inline bool ScRangeData::HasType( RangeType nType ) const
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx
index 92eebc245480..598c65df68e5 100644
--- a/sc/qa/unit/ucalc_formula.cxx
+++ b/sc/qa/unit/ucalc_formula.cxx
@@ -1296,20 +1296,29 @@ void Test::testFormulaRefUpdateNamedExpression()
m_pDoc->SetValue(ScAddress(3,9,0), 20);
CPPUNIT_ASSERT_EQUAL(43.0, m_pDoc->GetValue(ScAddress(2,7,0)));
-#if 0
// Insert a new sheet before the current.
m_pDoc->InsertTab(0, "New");
OUString aName;
m_pDoc->GetName(1, aName);
CPPUNIT_ASSERT_EQUAL(OUString("Formula"), aName);
+
+ pName = pGlobalNames->findByUpperName("MYRANGE");
+ CPPUNIT_ASSERT_MESSAGE("Failed to find named expression 'MyRange' in the global scope.", pName);
+
m_pDoc->SetValue(ScAddress(3,9,1), 10);
CPPUNIT_ASSERT_EQUAL(33.0, m_pDoc->GetValue(ScAddress(2,7,1)));
m_pDoc->DeleteTab(0);
+ aName = OUString();
+ m_pDoc->GetName(0, aName);
+ CPPUNIT_ASSERT_EQUAL(OUString("Formula"), aName);
+
+ pName = pGlobalNames->findByUpperName("MYRANGE");
+ CPPUNIT_ASSERT_MESSAGE("Failed to find named expression 'MyRange' in the global scope.", pName);
+
m_pDoc->SetValue(ScAddress(3,9,0), 11);
CPPUNIT_ASSERT_EQUAL(34.0, m_pDoc->GetValue(ScAddress(2,7,0)));
-#endif
// Clear all and start over.
clearRange(m_pDoc, ScRange(0,0,0,100,100,0));
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index b963eab091ba..4389a4b137e6 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -196,6 +196,18 @@ void ScRangeData::CompileUnresolvedXML()
}
}
+#if DEBUG_FORMULA_COMPILER
+void ScRangeData::Dump() const
+{
+ cout << "-- ScRangeData" << endl;
+ cout << " name: " << aName << endl;
+ cout << " ref position: (col=" << aPos.Col() << ", row=" << aPos.Row() << ", sheet=" << aPos.Tab() << ")" << endl;
+
+ if (pCode)
+ pCode->Dump();
+}
+#endif
+
void ScRangeData::GuessPosition()
{
// set a position that allows "absoluting" of all relative references
@@ -392,6 +404,9 @@ void ScRangeData::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt, SCTAB nL
sc::RefUpdateResult aRes = pCode->AdjustReferenceOnInsertedTab(rCxt, aPos);
if (aRes.mbReferenceModified)
rCxt.maUpdatedNames.setUpdatedName(nLocalTab, nIndex);
+
+ if (rCxt.mnInsertPos <= aPos.Tab())
+ aPos.IncTab(rCxt.mnSheets);
}
void ScRangeData::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nLocalTab )
@@ -399,6 +414,9 @@ void ScRangeData::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt, SCTAB nL
sc::RefUpdateResult aRes = pCode->AdjustReferenceOnDeletedTab(rCxt, aPos);
if (aRes.mbReferenceModified)
rCxt.maUpdatedNames.setUpdatedName(nLocalTab, nIndex);
+
+ if (rCxt.mnDeletePos <= aPos.Tab())
+ aPos.IncTab(-rCxt.mnSheets);
}
void ScRangeData::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocalTab )
@@ -406,6 +424,8 @@ void ScRangeData::UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt, SCTAB nLocal
sc::RefUpdateResult aRes = pCode->AdjustReferenceOnMovedTab(rCxt, aPos);
if (aRes.mbReferenceModified)
rCxt.maUpdatedNames.setUpdatedName(nLocalTab, nIndex);
+
+ aPos.SetTab(rCxt.getNewTab(aPos.Tab()));
}
void ScRangeData::MakeValidName( OUString& rName )