summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-06-20 15:24:03 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-06-24 16:51:37 -0400
commit66d3f24334e69e1655e83520950c59a0bda095a3 (patch)
treebcd6b8783ce82c2875dac837d0dc254e1c480440 /sc
parent2a1c5aba7640416c78501116dd42d12e74fe4734 (diff)
Make sure to set the cloned formula cells dirty during undo / redo.
This fixes the last failed unit test from ucalc. Change-Id: I37a79e444084397629cac77e2137377cd555a89c
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/ucalc.cxx26
-rw-r--r--sc/source/core/data/column.cxx6
-rw-r--r--sc/source/core/data/column3.cxx1
-rw-r--r--sc/source/core/data/document.cxx6
4 files changed, 18 insertions, 21 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 2a7ab02c300c..1122b60ef7d3 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5914,14 +5914,12 @@ void Test::testCopyPaste()
m_pDoc->SetRangeName(pGlobalRangeName);
m_pDoc->SetRangeName(0, pLocalRangeName1);
- //add formula
+ // Add formula to B1.
OUString aFormulaString("=local1+global+SUM($C$1:$D$4)");
m_pDoc->SetString(1, 0, 0, aFormulaString);
- double aValue = 0;
- m_pDoc->GetValue(1, 0, 0, aValue);
- std::cout << "Value: " << aValue << std::endl;
- ASSERT_DOUBLES_EQUAL_MESSAGE("formula should return 8", aValue, 8);
+ double fValue = m_pDoc->GetValue(ScAddress(1,0,0));
+ ASSERT_DOUBLES_EQUAL_MESSAGE("formula should return 8", fValue, 8);
//copy Sheet1.A1:C1 to Sheet2.A2:C2
ScRange aRange(0,0,0,2,0,0);
@@ -5939,17 +5937,17 @@ void Test::testCopyPaste()
aMarkData2.SetMarkArea(aRange);
ScRefUndoData* pRefUndoData= new ScRefUndoData(m_pDoc);
ScUndoPaste aUndo(
- &m_xDocShRef, ScRange(0, 1, 1, 2, 1, 1), aMarkData2, pUndoDoc, NULL, IDF_ALL, pRefUndoData, false);
+ &m_xDocShRef, aRange, aMarkData2, pUndoDoc, NULL, IDF_ALL, pRefUndoData, false);
m_pDoc->CopyFromClip(aRange, aMarkData2, nFlags, NULL, &aClipDoc);
//check values after copying
OUString aString;
- m_pDoc->GetValue(1,1,1, aValue);
+ fValue = m_pDoc->GetValue(ScAddress(1,1,1));
m_pDoc->GetFormula(1,1,1, aString);
- ASSERT_DOUBLES_EQUAL_MESSAGE("copied formula should return 2", aValue, 2);
+ ASSERT_DOUBLES_EQUAL_MESSAGE("copied formula should return 2", fValue, 2);
CPPUNIT_ASSERT_MESSAGE("formula string was not copied correctly", aString == aFormulaString);
- m_pDoc->GetValue(0,1,1, aValue);
- CPPUNIT_ASSERT_MESSAGE("copied value should be 1", aValue == 1);
+ fValue = m_pDoc->GetValue(ScAddress(0,1,1));
+ CPPUNIT_ASSERT_MESSAGE("copied value should be 1", fValue == 1);
//chack local range name after copying
pLocal1 = m_pDoc->GetRangeName(1)->findByUpperName(OUString("LOCAL1"));
@@ -5963,14 +5961,14 @@ void Test::testCopyPaste()
//check undo and redo
aUndo.Undo();
- m_pDoc->GetValue(1,1,1, aValue);
- ASSERT_DOUBLES_EQUAL_MESSAGE("after undo formula should return nothing", aValue, 0);
+ fValue = m_pDoc->GetValue(ScAddress(1,1,1));
+ ASSERT_DOUBLES_EQUAL_MESSAGE("after undo formula should return nothing", fValue, 0);
aString = m_pDoc->GetString(2, 1, 1);
CPPUNIT_ASSERT_MESSAGE("after undo string should be removed", aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
aUndo.Redo();
- m_pDoc->GetValue(1,1,1, aValue);
- ASSERT_DOUBLES_EQUAL_MESSAGE("formula should return 2 after redo", aValue, 2);
+ fValue = m_pDoc->GetValue(ScAddress(1,1,1));
+ ASSERT_DOUBLES_EQUAL_MESSAGE("formula should return 2 after redo", fValue, 2);
aString = m_pDoc->GetString(2, 1, 1);
CPPUNIT_ASSERT_MESSAGE("Cell Sheet2.C2 should contain: test", aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")));
m_pDoc->GetFormula(1,1,1, aString);
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index a62b05ce1157..c7ee06b8b482 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1587,8 +1587,9 @@ class CopyByCloneHandler : public sc::CellBlockCloneHandler
if (bForceFormula || bCloneFormula)
{
// Clone as formula cell.
- rPos.miCellPos = getDestCellStore().set(
- rPos.miCellPos, rDestPos.Row(), new ScFormulaCell(rSrcCell, getDestDoc(), rDestPos));
+ ScFormulaCell* pCell = new ScFormulaCell(rSrcCell, getDestDoc(), rDestPos);
+ pCell->SetDirtyVar();
+ rPos.miCellPos = getDestCellStore().set(rPos.miCellPos, rDestPos.Row(), pCell);
setDefaultAttrToDest(rPos, rDestPos.Row());
return;
@@ -1773,7 +1774,6 @@ void ScColumn::CopyToColumn(
pAttrArray->CopyArea( nRow1, nRow2, 0, *rColumn.pAttrArray);
}
-
if ((nFlags & IDF_CONTENTS) != 0)
{
boost::scoped_ptr<sc::CellBlockCloneHandler> pHdl(NULL);
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index f7718996e5b2..e4eb3fc9671c 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -388,7 +388,6 @@ void ScColumn::CopyCellsInRangeToColumn(
;
}
-
if (bLastBlock)
break;
}
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index b9bc16d2db4d..853c204fec6f 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -92,6 +92,7 @@
#include "formulacell.hxx"
#include "clipcontext.hxx"
#include "listenercontext.hxx"
+#include "scopetools.hxx"
#include <map>
#include <limits>
@@ -1921,13 +1922,13 @@ void ScDocument::UndoToDocument(const ScRange& rRange,
sal_uInt16 nFlags, bool bOnlyMarked, ScDocument* pDestDoc,
const ScMarkData* pMarks)
{
+ sc::AutoCalcSwitch aAutoCalcSwitch(*this, false);
+
ScRange aNewRange = rRange;
aNewRange.Justify();
SCTAB nTab1 = aNewRange.aStart.Tab();
SCTAB nTab2 = aNewRange.aEnd.Tab();
- bool bOldAutoCalc = pDestDoc->GetAutoCalc();
- pDestDoc->SetAutoCalc( false ); // avoid multiple calculations
sc::CopyToDocContext aCxt(*pDestDoc);
if (nTab1 > 0)
CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTab1-1, IDF_FORMULA, false, pDestDoc, pMarks );
@@ -1943,7 +1944,6 @@ void ScDocument::UndoToDocument(const ScRange& rRange,
if (nTab2 < static_cast<SCTAB>(maTabs.size()))
CopyToDocument( 0,0,nTab2+1, MAXCOL,MAXROW,maTabs.size(), IDF_FORMULA, false, pDestDoc, pMarks );
- pDestDoc->SetAutoCalc( bOldAutoCalc );
}
// bUseRangeForVBA added for VBA api support to allow content of a specified