[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - 2 commits - sc/qa sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Tue Jul 9 20:03:10 PDT 2013


 sc/qa/unit/ucalc.cxx               |   26 ++++++++++++++++---------
 sc/qa/unit/ucalc.hxx               |    3 ++
 sc/qa/unit/ucalc_sharedformula.cxx |   38 +++++++++++++++++++++++++++++++++++++
 sc/source/core/data/column.cxx     |   15 +++++---------
 4 files changed, 64 insertions(+), 18 deletions(-)

New commits:
commit c6f020fae150cdbf8a2a64fc41d0f328534c2a51
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Jul 9 23:04:50 2013 -0400

    Add test for formula grouping during undo.
    
    Change-Id: Ifab98b1eedf4420ed5b609e0684422c8aae0d33c

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index e592ccd..1f13dfe 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5738,16 +5738,13 @@ void Test::testCopyPaste()
     ScDocument aClipDoc(SCDOCMODE_CLIP);
     copyToClip(m_pDoc, aRange, &aClipDoc);
 
-    sal_uInt16 nFlags = IDF_ALL;
     aRange = ScRange(0,1,1,2,1,1);//target: Sheet2.A2:C2
     ScDocument* pUndoDoc = new ScDocument(SCDOCMODE_UNDO);
     pUndoDoc->InitUndo(m_pDoc, 1, 1, true, true);
-    ScMarkData aMarkData2;
-    aMarkData2.SetMarkArea(aRange);
-    ScRefUndoData* pRefUndoData= new ScRefUndoData(m_pDoc);
-    ScUndoPaste aUndo(
-        &m_xDocShRef, aRange, aMarkData2, pUndoDoc, NULL, IDF_ALL, pRefUndoData, false);
-    m_pDoc->CopyFromClip(aRange, aMarkData2, nFlags, NULL, &aClipDoc);
+    boost::scoped_ptr<ScUndoPaste> pUndo(createUndoPaste(*m_xDocShRef, aRange, pUndoDoc));
+    ScMarkData aMark;
+    aMark.SetMarkArea(aRange);
+    m_pDoc->CopyFromClip(aRange, aMark, IDF_ALL, NULL, &aClipDoc);
 
     //check values after copying
     OUString aString;
@@ -5769,13 +5766,13 @@ void Test::testCopyPaste()
 
 
     //check undo and redo
-    aUndo.Undo();
+    pUndo->Undo();
     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();
+    pUndo->Redo();
     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);
@@ -6941,6 +6938,17 @@ void Test::pasteFromClip(ScDocument* pDestDoc, const ScRange& rDestRange, ScDocu
     pDestDoc->CopyFromClip(rDestRange, aMark, IDF_ALL, NULL, pClipDoc);
 }
 
+ScUndoPaste* Test::createUndoPaste(ScDocShell& rDocSh, const ScRange& rRange, ScDocument* pUndoDoc)
+{
+    ScDocument* pDoc = rDocSh.GetDocument();
+    ScMarkData aMarkData;
+    aMarkData.SetMarkArea(rRange);
+    ScRefUndoData* pRefUndoData = new ScRefUndoData(pDoc);
+
+    return new ScUndoPaste(
+        &rDocSh, rRange, aMarkData, pUndoDoc, NULL, IDF_ALL, pRefUndoData, false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 1a141a0..513a4c0 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -12,6 +12,8 @@
 
 #include "helper/qahelper.hxx"
 
+class ScUndoPaste;
+
 /**
  * Temporarily set formula grammar.
  */
@@ -31,6 +33,7 @@ public:
     static void clearRange(ScDocument* pDoc, const ScRange& rRange);
     static void copyToClip(ScDocument* pSrcDoc, const ScRange& rRange, ScDocument* pClipDoc);
     static void pasteFromClip(ScDocument* pDestDoc, const ScRange& rDestRange, ScDocument* pClipDoc);
+    static ScUndoPaste* createUndoPaste(ScDocShell& rDocSh, const ScRange& rRange, ScDocument* pUndoDoc);
 
     Test();
 
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 0ce78e9..3fee4dc 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -10,6 +10,7 @@
 #include "ucalc.hxx"
 #include "editutil.hxx"
 #include "clipparam.hxx"
+#include "undoblk.hxx"
 
 #include "formula/grammar.hxx"
 
@@ -263,6 +264,43 @@ void Test::testSharedFormulasCopyPaste()
     CPPUNIT_ASSERT_EQUAL(1, pFC->GetSharedTopRow());
     CPPUNIT_ASSERT_EQUAL(9, pFC->GetSharedLength());
 
+    ScRange aRange(1,0,0,1,9,0); // B1:B10
+    ScDocument* pUndoDoc = new ScDocument(SCDOCMODE_UNDO);
+    pUndoDoc->InitUndo(m_pDoc, 0, 0, true, true);
+    m_pDoc->CopyToDocument(aRange, IDF_CONTENTS, false, pUndoDoc);
+    boost::scoped_ptr<ScUndoPaste> pUndo(createUndoPaste(*m_xDocShRef, aRange, pUndoDoc));
+
+    // First, make sure the formula cells are shared in the undo document.
+    aPos.SetCol(1);
+    for (SCROW i = 0; i <= 9; ++i)
+    {
+        aPos.SetRow(i);
+        pFC = pUndoDoc->GetFormulaCell(aPos);
+        CPPUNIT_ASSERT_MESSAGE("Must be a formula cell.", pFC);
+        CPPUNIT_ASSERT_EQUAL(0, pFC->GetSharedTopRow());
+        CPPUNIT_ASSERT_EQUAL(10, pFC->GetSharedLength());
+    }
+
+    // Overwrite B1:B10.
+    for (SCROW i = 0; i <= 9; ++i)
+        m_pDoc->SetValue(ScAddress(1,i,0), i*10);
+
+    for (SCROW i = 0; i <= 9; ++i)
+        CPPUNIT_ASSERT_MESSAGE("Numeric cell was expected.", m_pDoc->GetCellType(ScAddress(1,i,0)) == CELLTYPE_VALUE);
+
+    // Undo the action to fill B1:B10 with formula cells again.
+    pUndo->Undo();
+
+    aPos.SetCol(1);
+    for (SCROW i = 0; i <= 9; ++i)
+    {
+        aPos.SetRow(i);
+        pFC = m_pDoc->GetFormulaCell(aPos);
+        CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pFC);
+        CPPUNIT_ASSERT_EQUAL(0, pFC->GetSharedTopRow());
+        CPPUNIT_ASSERT_EQUAL(10, pFC->GetSharedLength());
+    }
+
     m_pDoc->DeleteTab(0);
 }
 
commit f69b88bc6074bca58e450b37beb68e5a2c007405
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Jul 9 22:56:30 2013 -0400

    Grouping of formula cells during undo.
    
    Change-Id: I57693eee34a073cd3f39fdd4f5a74eafb12c9dc7

diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index c69a3c1..7ce2d5b 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1572,7 +1572,6 @@ class CopyAsLinkHandler
     sc::ColumnBlockPosition maDestPos;
     sc::ColumnBlockPosition* mpDestPos;
     sal_uInt16 mnCopyFlags;
-    std::vector<ScFormulaCell*> maCellBuffer;
 
     void setDefaultAttrToDest(size_t nRow)
     {
@@ -1602,13 +1601,12 @@ class CopyAsLinkHandler
     {
         size_t nTopRow = aNode.position + nOffset;
 
-        maCellBuffer.clear();
-        maCellBuffer.reserve(nDataSize);
-
         for (size_t i = 0; i < nDataSize; ++i)
-            maCellBuffer.push_back(createRefCell(nTopRow + i));
+        {
+            SCROW nRow = nTopRow + i;
+            mrDestCol.SetFormulaCell(maDestPos, nRow, createRefCell(nRow));
+        }
 
-        maDestPos.miCellPos = mrDestCol.GetCellStore().set(maDestPos.miCellPos, nTopRow, maCellBuffer.begin(), maCellBuffer.end());
         setDefaultAttrsToDest(nTopRow, nDataSize);
     }
 
@@ -1727,7 +1725,7 @@ class CopyByCloneHandler
             // Clone as formula cell.
             ScFormulaCell* pCell = new ScFormulaCell(rSrcCell, mrDestCol.GetDoc(), aDestPos);
             pCell->SetDirtyVar();
-            maDestPos.miCellPos = mrDestCol.GetCellStore().set(maDestPos.miCellPos, nRow, pCell);
+            mrDestCol.SetFormulaCell(maDestPos, nRow, pCell);
             setDefaultAttrToDest(nRow);
             return;
         }
@@ -1743,8 +1741,7 @@ class CopyByCloneHandler
                 // error codes are cloned with values
                 ScFormulaCell* pErrCell = new ScFormulaCell(&mrDestCol.GetDoc(), aDestPos);
                 pErrCell->SetErrCode(nErr);
-                maDestPos.miCellPos = mrDestCol.GetCellStore().set(
-                    maDestPos.miCellPos, nRow, new ScFormulaCell(rSrcCell, mrDestCol.GetDoc(), aDestPos));
+                mrDestCol.SetFormulaCell(maDestPos, nRow, pErrCell);
                 setDefaultAttrToDest(nRow);
                 return;
             }


More information about the Libreoffice-commits mailing list