sc/inc/document.hxx | 5 +++ sc/qa/unit/ucalc.cxx | 53 ++++++++++++++++++++++++++++++++++++- sc/qa/unit/ucalc.hxx | 2 + sc/source/core/data/document10.cxx | 20 +++++++++++++ sc/source/ui/undo/undoblk.cxx | 2 + 5 files changed, 81 insertions(+), 1 deletion(-)
New commits: commit 3032d08226f77505e7105fb7cfb7f4b4741fd3ca Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Mon Jan 27 21:06:30 2014 -0500 fdo#74014: Broadcast cells on undoing of "cut". Change-Id: I0fdf518078c86f259e72307f8011a988555a9235 diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 6a980ab..3b106d7 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1808,6 +1808,11 @@ public: */ void Broadcast( const ScHint& rHint ); + /** + * Cell broadcast in specified range. + */ + void BroadcastCells( const ScRange& rRange, sal_uLong nHint ); + /// only area, no cell broadcast void AreaBroadcast( const ScHint& rHint ); /// only areas in range, no cell broadcasts diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx index ee3e35d..805fb3c 100644 --- a/sc/source/core/data/document10.cxx +++ b/sc/source/core/data/document10.cxx @@ -170,4 +170,24 @@ bool ScDocument::CopyOneCellFromClip( return true; } +void ScDocument::BroadcastCells( const ScRange& rRange, sal_uLong nHint ) +{ + ScHint aHint(nHint, ScAddress()); + ScAddress& rPos = aHint.GetAddress(); + + for (SCTAB nTab = rRange.aStart.Tab(); nTab <= rRange.aEnd.Tab(); ++nTab) + { + rPos.SetTab(nTab); + for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol) + { + rPos.SetCol(nCol); + for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow) + { + rPos.SetRow(nRow); + Broadcast(aHint); + } + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx index 946ed99..9d83309 100644 --- a/sc/source/ui/undo/undoblk.cxx +++ b/sc/source/ui/undo/undoblk.cxx @@ -786,6 +786,8 @@ void ScUndoCut::DoChange( const sal_Bool bUndo ) ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack(); if ( pChangeTrack ) pChangeTrack->Undo( nStartChangeAction, nEndChangeAction ); + + pDoc->BroadcastCells(aCopyRange, SC_HINT_DATACHANGED); } else // only for Redo { commit fa11b0842a51b59eb131a084310c177235ebe487 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Mon Jan 27 20:22:48 2014 -0500 fdo#74014: Write unit test for this first. Change-Id: I59fb04e2d7dc8148064564b900680e1b6e1b5e43 diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index c4737cf..257afad 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -3537,7 +3537,6 @@ void Test::testCopyPasteAsLink() void Test::testCopyPasteTranspose() { - m_pDoc->InsertTab(0, OUString("Sheet1")); m_pDoc->InsertTab(1, OUString("Sheet2")); @@ -3602,6 +3601,58 @@ void Test::testCopyPasteTranspose() } +void Test::testUndoCut() +{ + m_pDoc->InsertTab(0, "Test"); + + sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc. + + // Insert values into A1:A3. + m_pDoc->SetValue(ScAddress(0,0,0), 1.0); + m_pDoc->SetValue(ScAddress(0,1,0), 10.0); + m_pDoc->SetValue(ScAddress(0,2,0), 100.0); + + // SUM in A4. + m_pDoc->SetString(ScAddress(0,3,0), "=SUM(A1:A3)"); + CPPUNIT_ASSERT_EQUAL(111.0, m_pDoc->GetValue(0,3,0)); + + // Select A1:A3. + ScMarkData aMark; + ScRange aRange(0,0,0,0,2,0); + aMark.SetMarkArea(aRange); + aMark.MarkToMulti(); + + // Set up an undo object for cutting A1:A3. + ScDocument* pUndoDoc = new ScDocument(SCDOCMODE_UNDO); + pUndoDoc->InitUndo(m_pDoc, 0 ,0); + m_pDoc->CopyToDocument(aRange, IDF_ALL, false, pUndoDoc); + CPPUNIT_ASSERT_EQUAL( 1.0, pUndoDoc->GetValue(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL( 10.0, pUndoDoc->GetValue(ScAddress(0,1,0))); + CPPUNIT_ASSERT_EQUAL(100.0, pUndoDoc->GetValue(ScAddress(0,2,0))); + ScUndoCut aUndo(&getDocShell(), aRange, aRange.aEnd, aMark, pUndoDoc); + + // "Cut" the selection. + m_pDoc->DeleteSelection(IDF_ALL, aMark); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(0,3,0)); // The SUM should be zero after the "cut". + + // Undo it, and check the result. + aUndo.Undo(); + CPPUNIT_ASSERT_EQUAL( 1.0, m_pDoc->GetValue(ScAddress(0,0,0))); + CPPUNIT_ASSERT_EQUAL( 10.0, m_pDoc->GetValue(ScAddress(0,1,0))); + CPPUNIT_ASSERT_EQUAL(100.0, m_pDoc->GetValue(ScAddress(0,2,0))); + CPPUNIT_ASSERT_EQUAL(111.0, m_pDoc->GetValue(0,3,0)); // The SUM value should be back to the original. + + // Redo it and check. + aUndo.Redo(); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(0,3,0)); + + // Undo again. + aUndo.Undo(); + CPPUNIT_ASSERT_EQUAL(111.0, m_pDoc->GetValue(0,3,0)); + + m_pDoc->DeleteTab(0); +} + void Test::testMoveBlock() { m_pDoc->InsertTab(0, "SheetNotes"); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index f6007ff..52fb51f 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -238,6 +238,7 @@ public: void testCopyPaste(); void testCopyPasteAsLink(); void testCopyPasteTranspose(); + void testUndoCut(); void testMoveBlock(); void testCopyPasteRelativeFormula(); void testMergedCells(); @@ -390,6 +391,7 @@ public: CPPUNIT_TEST(testCopyPaste); CPPUNIT_TEST(testCopyPasteAsLink); CPPUNIT_TEST(testCopyPasteTranspose); + CPPUNIT_TEST(testUndoCut); CPPUNIT_TEST(testMoveBlock); CPPUNIT_TEST(testCopyPasteRelativeFormula); CPPUNIT_TEST(testMergedCells); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits