[Libreoffice-commits] core.git: Branch 'feature/sc-notes-storage' - sc/qa sc/source

Laurent Godard lgodard.libre at laposte.net
Tue Sep 24 02:00:04 PDT 2013


Rebased ref, commits from common ancestor:
commit 117ea65d6e5586e8c1c0805481ca81a1e15049ac
Author: Laurent Godard <lgodard.libre at laposte.net>
Date:   Mon Sep 23 18:08:42 2013 +0200

    transport attached notes when moving a block of cell
    
    Change-Id: I608be1197cf4177aa67870ff34b61cf1fd67204c

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index fb0d07f..df95270 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -2915,15 +2915,15 @@ void Test::testCopyPaste()
     // add notes to A1:C1
     ScAddress aAdrA1 (0, 0, 0); // empty cell content
     OUString aHelloA1("Hello world in A1");
-    ScPostIt *pNoteA1 = m_pDoc->GetOrCreateNote(aAdrA1);
+    ScPostIt* pNoteA1 = m_pDoc->GetOrCreateNote(aAdrA1);
     pNoteA1->SetText(aAdrA1, aHelloA1);
     ScAddress aAdrB1 (1, 0, 0); // formula cell content
     OUString aHelloB1("Hello world in B1");
-    ScPostIt *pNoteB1 = m_pDoc->GetOrCreateNote(aAdrB1);
+    ScPostIt* pNoteB1 = m_pDoc->GetOrCreateNote(aAdrB1);
     pNoteB1->SetText(aAdrB1, aHelloB1);
     ScAddress aAdrC1 (2, 0, 0); // string cell content
     OUString aHelloC1("Hello world in C1");
-    ScPostIt *pNoteC1 = m_pDoc->GetOrCreateNote(aAdrC1);
+    ScPostIt* pNoteC1 = m_pDoc->GetOrCreateNote(aAdrC1);
     pNoteC1->SetText(aAdrC1, aHelloC1);
 
     //copy Sheet1.A1:C1 to Sheet2.A2:C2
@@ -3014,15 +3014,15 @@ void Test::testCopyPasteTranspose()
     // add notes to A1:C1
     ScAddress aAdrA1 (0, 0, 0); // numerical cell content
     OUString aHelloA1("Hello world in A1");
-    ScPostIt *pNoteA1 = m_pDoc->GetOrCreateNote(aAdrA1);
+    ScPostIt* pNoteA1 = m_pDoc->GetOrCreateNote(aAdrA1);
     pNoteA1->SetText(aAdrA1, aHelloA1);
     ScAddress aAdrB1 (1, 0, 0); // formula cell content
     OUString aHelloB1("Hello world in B1");
-    ScPostIt *pNoteB1 = m_pDoc->GetOrCreateNote(aAdrB1);
+    ScPostIt* pNoteB1 = m_pDoc->GetOrCreateNote(aAdrB1);
     pNoteB1->SetText(aAdrB1, aHelloB1);
     ScAddress aAdrC1 (2, 0, 0); // string cell content
     OUString aHelloC1("Hello world in C1");
-    ScPostIt *pNoteC1 = m_pDoc->GetOrCreateNote(aAdrC1);
+    ScPostIt* pNoteC1 = m_pDoc->GetOrCreateNote(aAdrC1);
     pNoteC1->SetText(aAdrC1, aHelloC1);
 
     // transpose clipboard, paste and check on Sheet2
@@ -3068,6 +3068,73 @@ void Test::testCopyPasteTranspose()
 
 }
 
+void Test::testMoveBlock()
+{
+
+    ScDocument* pDoc = getDocShell().GetDocument();
+
+    pDoc->InsertTab(0, "SheetNotes");
+
+    pDoc->SetValue(0, 0, 0, 1);
+    pDoc->SetString(1, 0, 0, OUString("=A1+1"));
+    pDoc->SetString(2, 0, 0, OUString("test"));
+
+    // add notes to A1:C1
+    ScAddress aAddrA1 (0, 0, 0);
+    OUString aHelloA1("Hello world in A1");
+    ScPostIt* pNoteA1 = pDoc->GetOrCreateNote(aAddrA1);
+    pNoteA1->SetText(aAddrA1, aHelloA1);
+    ScAddress aAddrB1 (1, 0, 0);
+    OUString aHelloB1("Hello world in B1");
+    ScPostIt* pNoteB1 = pDoc->GetOrCreateNote(aAddrB1);
+    pNoteB1->SetText(aAddrB1, aHelloB1);
+    ScAddress aAddrC1 (2, 0, 0);
+    OUString aHelloC1("Hello world in C1");
+    ScPostIt* pNoteC1 = pDoc->GetOrCreateNote(aAddrC1);
+    pNoteC1->SetText(aAddrC1, aHelloC1);
+    ScAddress aAddrD1 (3, 0, 0);
+
+    std::cout << "B1 note before moveblock: " << pNoteB1->GetText() << std::endl;
+    std::cout << "B1 note before moveblock should be: " << aHelloB1 << std::endl;
+
+    // previous tests on cell note content are ok. this one fails !!! :(
+    CPPUNIT_ASSERT_MESSAGE("Note content in B1", pNoteB1->GetText() == aHelloB1);
+
+    // move notes to B1:D1
+    bool bCut = true;
+    ScDocFunc& rDocFunc = getDocShell().GetDocFunc();
+    bool bMoveDone = rDocFunc.MoveBlock(ScRange(0, 0 ,0 ,2 ,0 ,0), ScAddress(1, 0, 0), bCut, false, false, false);
+
+    std::cout << "B1 note after moveblock: " << pDoc->GetNote(aAddrB1)->GetText() << std::endl;
+
+    CPPUNIT_ASSERT_MESSAGE("Cells not moved", bMoveDone);
+
+    //check cell content
+    OUString aString = pDoc->GetString(3, 0, 0);
+    CPPUNIT_ASSERT_MESSAGE("Cell D1 should contain: test", aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test")));
+    m_pDoc->GetFormula(2, 0, 0, aString);
+    CPPUNIT_ASSERT_MESSAGE("Cell C1 should contain an updated formula", aString.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("=B1+1")));
+    double fValue = pDoc->GetValue(aAddrB1);
+    ASSERT_DOUBLES_EQUAL_MESSAGE("Cell B1 should contain 1", fValue, 1);
+
+    // cell notes has been moved 1 cell right (event when overlapping)
+    CPPUNIT_ASSERT_MESSAGE("There should be NO note on A1", !pDoc->HasNote(aAddrA1));
+    CPPUNIT_ASSERT_MESSAGE("There should be a note on B1", pDoc->HasNote(aAddrB1));
+    CPPUNIT_ASSERT_MESSAGE("There should be a note on C1", pDoc->HasNote(aAddrC1));
+    CPPUNIT_ASSERT_MESSAGE("There should be a note on D1", pDoc->HasNote(aAddrD1));
+// still failing, wrong content ???
+    OUString sNoteText;
+    sNoteText =  pDoc->GetNote(aAddrB1)->GetText();
+    CPPUNIT_ASSERT_MESSAGE("Note content in B1", sNoteText == aHelloA1);
+    sNoteText =  pDoc->GetNote(aAddrC1)->GetText();
+    CPPUNIT_ASSERT_MESSAGE("Note content in C1", sNoteText == aHelloB1);
+    sNoteText =  pDoc->GetNote(aAddrD1)->GetText();
+    CPPUNIT_ASSERT_MESSAGE("Note content in D1", sNoteText == aHelloC1);
+//
+
+    pDoc->DeleteTab(0);
+}
+
 void Test::testCopyPasteRelativeFormula()
 {
     m_pDoc->InsertTab(0, "Formula");
@@ -3956,11 +4023,11 @@ void Test::testNoteDeleteRow()
     pNote->SetText(rAddr, aHello);
     pNote->SetAuthor(aJimBob);
 
-    CPPUNIT_ASSERT_MESSAGE("there should be a note", m_pDoc->HasNote(1, 1, 0));
+    CPPUNIT_ASSERT_MESSAGE("there should be a note", pDoc->HasNote(1, 1, 0));
 
     pDoc->DeleteRow(0, 0, MAXCOL, 0, 1, 1);
 
-    CPPUNIT_ASSERT_MESSAGE("there should be no more note", !m_pDoc->HasNote(1, 1, 0));
+    CPPUNIT_ASSERT_MESSAGE("there should be no more note", !pDoc->HasNote(1, 1, 0));
 
     pDoc->DeleteTab(0);
 }
@@ -3978,11 +4045,11 @@ void Test::testNoteDeleteCol()
     pNote->SetText(rAddr, aHello);
     pNote->SetAuthor(aJimBob);
 
-    CPPUNIT_ASSERT_MESSAGE("there should be a note", m_pDoc->HasNote(1, 1, 0));
+    CPPUNIT_ASSERT_MESSAGE("there should be a note", pDoc->HasNote(1, 1, 0));
 
     pDoc->DeleteCol(0, 0, MAXROW, 0, 1, 1);
 
-    CPPUNIT_ASSERT_MESSAGE("there should be no more note", !m_pDoc->HasNote(1, 1, 0));
+    CPPUNIT_ASSERT_MESSAGE("there should be no more note", !pDoc->HasNote(1, 1, 0));
 
     pDoc->DeleteTab(0);
 }
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 1273241..0a141a3 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -215,6 +215,7 @@ public:
     void testAutofilter();
     void testCopyPaste();
     void testCopyPasteTranspose();
+    void testMoveBlock();
     void testCopyPasteRelativeFormula();
     void testMergedCells();
     void testUpdateReference();
@@ -348,6 +349,7 @@ public:
     CPPUNIT_TEST(testAutofilter);
     CPPUNIT_TEST(testCopyPaste);
     CPPUNIT_TEST(testCopyPasteTranspose);
+    CPPUNIT_TEST(testMoveBlock);
     CPPUNIT_TEST(testCopyPasteRelativeFormula);
     CPPUNIT_TEST(testMergedCells);
     CPPUNIT_TEST(testUpdateReference);
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 193c8d3..70df4d0 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1670,7 +1670,7 @@ class CopyAsLinkHandler
 
     void duplicateNotes(SCROW nStartRow, size_t nDataSize ) // TODO : notes suboptimal
     {
-        // the link status is only for cell content as it is not possible to un-link a note
+        // the link status is only for cell content as it is not possible to un-link a note --> the note is copied
         sc::CellNoteStoreType maSrcCellNotes = mrSrcCol.GetCellNoteStore();
         SCROW nRowMax = nStartRow + nDataSize;
 
@@ -1885,6 +1885,7 @@ class CopyByCloneHandler
                                  aDestPos, true );
                 mrDestCol.GetDoc().ReleaseNote(aDestPos);
                 mrDestCol.GetDoc().SetNote(aDestPos, pClonedNote);
+                pClonedNote->UpdateCaptionPos(aDestPos);
             }
         }
     }
@@ -2232,9 +2233,9 @@ void resetColumnPosition(sc::CellStoreType& rCells, SCCOL nCol)
 void ScColumn::SwapCol(ScColumn& rCol)
 {
     maBroadcasters.swap(rCol.maBroadcasters);
-    maCellNotes.swap(rCol.maCellNotes);
     maCells.swap(rCol.maCells);
     maCellTextAttrs.swap(rCol.maCellTextAttrs);
+    maCellNotes.swap(rCol.maCellNotes); // TODO : notes update caption ?
 
     ScAttrArray* pTempAttr = rCol.pAttrArray;
     rCol.pAttrArray = pAttrArray;
@@ -2278,7 +2279,7 @@ void ScColumn::MoveTo(SCROW nStartRow, SCROW nEndRow, ScColumn& rCol)
 
     // Move the broadcasters to the destination column.
     maBroadcasters.transfer(nStartRow, nEndRow, rCol.maBroadcasters, nStartRow);
-    maCellNotes.transfer(nStartRow, nEndRow, rCol.maCellNotes, nStartRow);
+    maCellNotes.transfer(nStartRow, nEndRow, rCol.maCellNotes, nStartRow); // TODO : notes - update caption ?
     maCells.transfer(nStartRow, nEndRow, rCol.maCells, nStartRow);
     maCellTextAttrs.transfer(nStartRow, nEndRow, rCol.maCellTextAttrs, nStartRow);
 
@@ -2383,6 +2384,8 @@ public:
     {
         ScAddress aUndoPos(mnCol, nRow, mnTab);
         mbUpdated |= pCell->UpdateReference(mrCxt, mpUndoDoc, &aUndoPos);
+
+
     }
 
     bool isUpdated() const { return mbUpdated; }
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 6241a0e..81c1966 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -2717,14 +2717,14 @@ sal_Bool ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos
         aDestMark.SelectTable( nTab, sal_True );        // Destination selektieren
     aDestMark.SetMarkArea( aPasteDest );
 
-    /*  Do not copy cell notes and drawing objects here. While pasting, the
+    /*  Do not drawing objects here. While pasting, the
         function ScDocument::UpdateReference() is called which calls
         ScDrawLayer::MoveCells() which may move away inserted objects to wrong
-        positions (e.g. if source and destination range overlaps). Cell notes
-        and drawing objects are pasted below after doing all adjusting. */
-    pDoc->CopyFromClip( aPasteDest, aDestMark, IDF_ALL & ~(IDF_NOTE | IDF_OBJECTS),
+        positions (e.g. if source and destination range overlaps).*/
+    pDoc->CopyFromClip( aPasteDest, aDestMark, IDF_ALL & ~(IDF_OBJECTS),
                         pRefUndoDoc, pClipDoc, sal_True, false, bIncludeFiltered );
 
+
     // skipped rows and merged cells don't mix
     if ( !bIncludeFiltered && pClipDoc->HasClipFilteredRows() )
         UnmergeCells( aPasteDest, false );
@@ -2734,15 +2734,11 @@ sal_Bool ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos
                             ScRange( 0,nDestRow,nDestTab, MAXCOL,nDestEndRow,nDestEndTab ),
                             false );
 
-    /*  Paste cell notes and drawing objects after adjusting formula references
+    /*  Paste drawing objects after adjusting formula references
         and row heights. There are no cell notes or drawing objects, if the
-        clipdoc does not contain a drawing layer.
-        #i102056# Passing IDF_NOTE only would overwrite cell contents with
-        empty note cells, therefore the special modifier IDF_ADDNOTES is passed
-        here too which changes the behaviour of ScColumn::CopyFromClip() to not
-        touch existing cells. */
+        clipdoc does not contain a drawing layer.*/
     if ( pClipDoc->GetDrawLayer() )
-        pDoc->CopyFromClip( aPasteDest, aDestMark, IDF_NOTE | IDF_ADDNOTES | IDF_OBJECTS,
+        pDoc->CopyFromClip( aPasteDest, aDestMark, IDF_OBJECTS,
                             pRefUndoDoc, pClipDoc, sal_True, false, bIncludeFiltered );
 
     if (bRecord)


More information about the Libreoffice-commits mailing list