[Libreoffice-commits] core.git: 4 commits - sc/inc sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed Feb 5 20:02:33 PST 2014


 sc/inc/column.hxx                |    2 
 sc/inc/document.hxx              |    2 
 sc/inc/mtvcellfunc.hxx           |   10 ++
 sc/inc/table.hxx                 |    3 
 sc/qa/unit/ucalc.cxx             |  174 ++++++++++++++++++++++++---------------
 sc/qa/unit/ucalc.hxx             |    8 +
 sc/source/core/data/column.cxx   |    2 
 sc/source/core/data/column2.cxx  |   28 ++++++
 sc/source/core/data/document.cxx |   31 ++++--
 sc/source/core/data/table2.cxx   |   17 +++
 sc/source/ui/undo/undoblk.cxx    |    1 
 11 files changed, 199 insertions(+), 79 deletions(-)

New commits:
commit bc504b5adfaeeac0b910b89b0c98ae564f1ff5b8
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Feb 5 22:59:04 2014 -0500

    fdo#74556: Correctly handle note captions life cycles.
    
    When copying notes to clipboard, we don't clone captions but leave them
    pointing to the original captions objects. Also, during undo and redo,
    we need to clear all caption pointers to prevent them from being deleted
    when the ScPostIt objects get deleted. The undo and redo of caption objects
    are handled in the drawing layer afterwards.
    
    Change-Id: I2b9cf0858dba5b3cac26db3ef501ea09779a795a

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 23a2a82..7f91d90 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -518,6 +518,7 @@ public:
     ScPostIt* ReleaseNote( SCROW nRow );
     size_t GetNoteCount() const;
     void CreateAllNoteCaptions();
+    void ForgetNoteCaptions( SCROW nRow1, SCROW nRow2 );
     SCROW GetNotePosition( size_t nIndex ) const;
     void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const;
     void GetNotesInRange( SCROW nStartRow, SCROW nEndRow, std::vector<sc::NoteEntry>& rNotes ) const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index e214a32..64212ed 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -919,6 +919,7 @@ public:
      * code uses sdr objects to export note data.
      */
     void CreateAllNoteCaptions();
+    void ForgetNoteCaptions( const ScRangeList& rRanges );
 
     ScAddress GetNotePosition( size_t nIndex ) const;
     SCROW GetNotePosition( SCTAB nTab, SCCOL nCol, size_t nIndex ) const;
diff --git a/sc/inc/mtvcellfunc.hxx b/sc/inc/mtvcellfunc.hxx
index 793f2db..fc6d2dc 100644
--- a/sc/inc/mtvcellfunc.hxx
+++ b/sc/inc/mtvcellfunc.hxx
@@ -166,6 +166,16 @@ void ProcessNote(CellNoteStoreType& rStore, _Func& rFunc)
     ProcessElements1<CellNoteStoreType, cellnote_block, _Func, FuncElseNoOp<size_t> >(rStore, rFunc, aElse);
 }
 
+template<typename _FuncElem>
+typename CellNoteStoreType::iterator
+ProcessNote(
+    const CellNoteStoreType::iterator& it, CellNoteStoreType& rStore, SCROW nRow1, SCROW nRow2, _FuncElem& rFuncElem)
+{
+    FuncElseNoOp<size_t> aElse;
+    return ProcessElements1<
+        CellNoteStoreType, cellnote_block, _FuncElem, FuncElseNoOp<size_t> >(it, rStore, nRow1, nRow2, rFuncElem, aElse);
+}
+
 }
 
 #endif
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 0ac441c..1e8764b 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -393,6 +393,7 @@ public:
     size_t GetNoteCount( SCCOL nCol ) const;
     SCROW GetNotePosition( SCCOL nCol, size_t nIndex ) const;
     void CreateAllNoteCaptions();
+    void ForgetNoteCaptions( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
 
     void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const;
     void GetNotesInRange( const ScRange& rRange, std::vector<sc::NoteEntry>& rNotes ) const;
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index ff8ed6b..52eb27e 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1278,7 +1278,7 @@ class CopyToClipHandler
 
     void duplicateNotes(SCROW nStartRow, size_t nDataSize )
     {
-        mrSrcCol.DuplicateNotes(nStartRow, nDataSize, mrDestCol, maDestPos);
+        mrSrcCol.DuplicateNotes(nStartRow, nDataSize, mrDestCol, maDestPos, false);
     }
 
 public:
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index f6c7cd9..af06f1b 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1252,6 +1252,14 @@ public:
     }
 };
 
+struct NoteCaptionCleaner
+{
+    void operator() ( size_t /*nRow*/, ScPostIt* p )
+    {
+        p->ForgetCaption();
+    }
+};
+
 }
 
 void ScColumn::CreateAllNoteCaptions()
@@ -1260,6 +1268,16 @@ void ScColumn::CreateAllNoteCaptions()
     sc::ProcessNote(maCellNotes, aFunc);
 }
 
+void ScColumn::ForgetNoteCaptions( SCROW nRow1, SCROW nRow2 )
+{
+    if (!ValidRow(nRow1) || !ValidRow(nRow2))
+        return;
+
+    NoteCaptionCleaner aFunc;
+    sc::CellNoteStoreType::iterator it = maCellNotes.begin();
+    sc::ProcessNote(it, maCellNotes, nRow1, nRow2, aFunc);
+}
+
 SCROW ScColumn::GetNotePosition( size_t nIndex ) const
 {
     // Return the row position of the nth note in the column.
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 3194f78..3f08fd6 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6245,6 +6245,24 @@ void ScDocument::CreateAllNoteCaptions()
     }
 }
 
+void ScDocument::ForgetNoteCaptions( const ScRangeList& rRanges )
+{
+    for (size_t i = 0, n = rRanges.size(); i < n; ++i)
+    {
+        const ScRange* p = rRanges[i];
+        const ScAddress& s = p->aStart;
+        const ScAddress& e = p->aEnd;
+        for (SCTAB nTab = s.Tab(); nTab <= s.Tab(); ++nTab)
+        {
+            ScTable* pTab = FetchTable(nTab);
+            if (!pTab)
+                continue;
+
+            pTab->ForgetNoteCaptions(s.Col(), s.Row(), e.Col(), e.Row());
+        }
+    }
+}
+
 ScAddress ScDocument::GetNotePosition( size_t nIndex ) const
 {
     for (size_t nTab = 0; nTab < maTabs.size(); ++nTab)
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 41f5e0d..88ffc1f 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1551,6 +1551,15 @@ void ScTable::CreateAllNoteCaptions()
         aCol[i].CreateAllNoteCaptions();
 }
 
+void ScTable::ForgetNoteCaptions( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
+{
+    if (!ValidCol(nCol1) || !ValidCol(nCol2))
+        return;
+
+    for (SCCOL i = nCol1; i <= nCol2; ++i)
+        aCol[i].ForgetNoteCaptions(nRow1, nRow2);
+}
+
 void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const
 {
     for (SCCOL nCol = 0; nCol < MAXCOLCOUNT; ++nCol)
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index a622258..2b30fed 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -946,6 +946,7 @@ void ScUndoPaste::DoChange(bool bUndo)
     sal_uInt16 nExtFlags = 0;
     pDocShell->UpdatePaintExt(nExtFlags, maBlockRanges.Combine());
 
+    pDoc->ForgetNoteCaptions(maBlockRanges);
     aMarkData.MarkToMulti();
     pDoc->DeleteSelection(nUndoFlags, aMarkData, false); // no broadcasting here
     for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)
commit fe5d604ecf6de4935c622e0e95efc085c4a3cbfd
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Feb 5 19:21:22 2014 -0500

    fdo#74556: Have ReleaseNote() really release note rather than destroying it.
    
    Change-Id: I2d271476ae91354f33f19d074fa717b2a0b47ff7

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index ee73c3f..23a2a82 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -515,6 +515,7 @@ public:
     void SetCellNote( SCROW nRow, ScPostIt* pNote);
     bool IsNotesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const;
 
+    ScPostIt* ReleaseNote( SCROW nRow );
     size_t GetNoteCount() const;
     void CreateAllNoteCaptions();
     SCROW GetNotePosition( size_t nIndex ) const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 98b40b0..e214a32 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -909,7 +909,6 @@ public:
     SC_DLLPUBLIC bool            HasColNotes(SCCOL nCol, SCTAB nTab);
     SC_DLLPUBLIC bool            HasTabNotes(SCTAB nTab);
     SC_DLLPUBLIC ScPostIt*       ReleaseNote(const ScAddress& rPos);
-    SC_DLLPUBLIC ScPostIt*       ReleaseNote(SCCOL nCol, SCROW nRow, SCTAB nTab);
     SC_DLLPUBLIC ScPostIt*       GetOrCreateNote(const ScAddress& rPos);
     SC_DLLPUBLIC ScPostIt*       CreateNote(const ScAddress& rPos);
     size_t CountNotes() const;
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 522fde8..0ac441c 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -388,6 +388,8 @@ public:
 
     ScPostIt*   GetNote(const SCCOL nCol, const SCROW nRow);
 
+    ScPostIt* ReleaseNote( SCCOL nCol, SCROW nRow );
+
     size_t GetNoteCount( SCCOL nCol ) const;
     SCROW GetNotePosition( SCCOL nCol, size_t nIndex ) const;
     void CreateAllNoteCaptions();
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 5a1e19d..f6c7cd9 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1212,6 +1212,16 @@ bool ScColumn::IsNotesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const
     return nEndRow < nNextRow;
 }
 
+ScPostIt* ScColumn::ReleaseNote( SCROW nRow )
+{
+    if (!ValidRow(nRow))
+        return NULL;
+
+    ScPostIt* p = NULL;
+    maCellNotes.release(nRow, p);
+    return p;
+}
+
 size_t ScColumn::GetNoteCount() const
 {
     size_t nCount = 0;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 1fb89cc..3194f78 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6192,16 +6192,11 @@ bool ScDocument::HasTabNotes(SCTAB nTab)
 
 ScPostIt* ScDocument::ReleaseNote(const ScAddress& rPos)
 {
-        return ReleaseNote(rPos.Col(), rPos.Row(), rPos.Tab());
-}
-ScPostIt* ScDocument::ReleaseNote(SCCOL nCol, SCROW nRow, SCTAB nTab)
-{
-
-    ScPostIt* pPostIt = GetNote(nCol, nRow, nTab);
-    if (pPostIt != NULL)
-        maTabs[nTab]->aCol[nCol].DeleteCellNote(nRow);
+    ScTable* pTab = FetchTable(rPos.Tab());
+    if (!pTab)
+        return NULL;
 
-    return pPostIt;
+    return pTab->ReleaseNote(rPos.Col(), rPos.Row());
 }
 
 ScPostIt* ScDocument::GetOrCreateNote(const ScAddress& rPos)
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index d566e91..41f5e0d 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1521,6 +1521,14 @@ ScPostIt* ScTable::GetNote(const SCCOL nCol, const SCROW nRow)
     return pDocument->GetNote(nCol, nRow, nTab);
 }
 
+ScPostIt* ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
+{
+    if (!ValidCol(nCol))
+        return NULL;
+
+    return aCol[nCol].ReleaseNote(nRow);
+}
+
 size_t ScTable::GetNoteCount( SCCOL nCol ) const
 {
     if (!ValidCol(nCol))
commit 771aadfce7d4b0dca678b0722c8f951371816082
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Feb 5 18:59:39 2014 -0500

    fdo#74556: Write test for ReleaseNote().
    
    It's supposed to release note instance, not destroy it.
    
    Change-Id: I40cd1a97d20b495f03fda68a991ad576de13ebc5

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index b09399a..3bab048 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -69,6 +69,7 @@
 #include <svx/svdpage.hxx>
 #include <svx/svdocirc.hxx>
 #include <svx/svdopath.hxx>
+#include <svx/svdocapt.hxx>
 #include "svl/srchitem.hxx"
 #include "svl/sharedstringpool.hxx"
 
@@ -4756,6 +4757,49 @@ void Test::testNoteDeleteCol()
     pDoc->DeleteTab(0);
 }
 
+void Test::testNoteLifeCycle()
+{
+    m_pDoc->InsertTab(0, "Test");
+
+    // We need a drawing layer in order to create caption objects.
+    m_pDoc->InitDrawLayer(&getDocShell());
+
+    ScAddress aPos(1,1,0);
+    ScPostIt* pNote = m_pDoc->GetOrCreateNote(aPos);
+    CPPUNIT_ASSERT_MESSAGE("Failed to insert a new cell comment.", pNote);
+
+    pNote->SetText(aPos, "New note");
+    ScPostIt* pNote2 = m_pDoc->ReleaseNote(aPos);
+    CPPUNIT_ASSERT_MESSAGE("This note instance is expected to be identical to the original.", pNote == pNote2);
+    CPPUNIT_ASSERT_MESSAGE("The note shouldn't be here after it's been released.", !m_pDoc->HasNote(aPos));
+
+    // Modify the internal state of the note instance to make sure it's really
+    // been released.
+    pNote->SetText(aPos, "New content");
+
+    // Re-insert the note back to the same place.
+    m_pDoc->SetNote(aPos, pNote);
+    const SdrCaptionObj* pCaption = pNote->GetOrCreateCaption(aPos);
+    CPPUNIT_ASSERT_MESSAGE("Failed to create a caption object.", pCaption);
+    CPPUNIT_ASSERT_MESSAGE("This caption should belong to the drawing layer of the document.",
+                           pCaption->GetModel() == m_pDoc->GetDrawLayer());
+
+    // Copy B2 with note to a clipboard.
+
+    ScClipParam aClipParam(aPos, false);
+    ScDocument aClipDoc(SCDOCMODE_CLIP);
+    ScMarkData aMarkData;
+    aMarkData.SelectOneTable(0);
+    m_pDoc->CopyToClip(aClipParam, &aClipDoc, &aMarkData, false, false, true, true, false);
+
+    ScPostIt* pClipNote = aClipDoc.GetNote(aPos);
+    CPPUNIT_ASSERT_MESSAGE("Failed to copy note to the clipboard.", pClipNote);
+    CPPUNIT_ASSERT_MESSAGE("Note on the clipboard should share the same caption object from the original.",
+                           pClipNote->GetCaption() == pCaption);
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testAreasWithNotes()
 {
     ScDocument* pDoc = getDocShell().GetDocument();
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 2dbb229..67a7581 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -300,6 +300,7 @@ public:
     void testNoteBasic();
     void testNoteDeleteRow();
     void testNoteDeleteCol();
+    void testNoteLifeCycle();
     void testAreasWithNotes();
     void testAnchoredRotatedShape();
     void testCellTextWidth();
@@ -428,6 +429,7 @@ public:
     CPPUNIT_TEST(testShiftCells);
     CPPUNIT_TEST(testNoteDeleteRow);
     CPPUNIT_TEST(testNoteDeleteCol);
+    CPPUNIT_TEST(testNoteLifeCycle);
     CPPUNIT_TEST(testAreasWithNotes);
     CPPUNIT_TEST(testAnchoredRotatedShape);
     CPPUNIT_TEST(testCellTextWidth);
commit f6f83f2ffdbea4fdbf744626c43e837cde44872f
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Feb 5 16:38:39 2014 -0500

    Move this test closer to the other tests for cell notes.
    
    Change-Id: I101e7fd20016b925cfcc25f6785937bc2fb8a03a

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index d393aa4..b09399a 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -3133,71 +3133,6 @@ void Test::testGraphicsOnSheetMove()
     m_pDoc->DeleteTab(0);
 }
 
-void Test::testPostIts()
-{
-    OUString aHello("Hello world");
-    OUString aJimBob("Jim Bob");
-    OUString aTabName("PostIts");
-    OUString aTabName2("Table2");
-    m_pDoc->InsertTab(0, aTabName);
-
-    ScAddress rAddr(2, 2, 0); // cell C3
-    ScPostIt *pNote = m_pDoc->GetOrCreateNote(rAddr);
-
-    pNote->SetText(rAddr, aHello);
-    pNote->SetAuthor(aJimBob);
-
-    ScPostIt *pGetNote = m_pDoc->GetNote(rAddr);
-    CPPUNIT_ASSERT_MESSAGE("note should be itself", pGetNote == pNote );
-
-    // Insert one row at row 1.
-    bool bInsertRow = m_pDoc->InsertRow(0, 0, MAXCOL, 0, 1, 1);
-    CPPUNIT_ASSERT_MESSAGE("failed to insert row", bInsertRow );
-
-    CPPUNIT_ASSERT_MESSAGE("note hasn't moved", m_pDoc->GetNote(rAddr) == NULL);
-    rAddr.IncRow(); // cell C4
-    CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNote(rAddr) == pNote);
-
-    // Insert column at column A.
-    bool bInsertCol = m_pDoc->InsertCol(0, 0, MAXROW, 0, 1, 1);
-    CPPUNIT_ASSERT_MESSAGE("failed to insert column", bInsertCol );
-
-    CPPUNIT_ASSERT_MESSAGE("note hasn't moved", m_pDoc->GetNote(rAddr) == NULL);
-    rAddr.IncCol(); // cell D4
-    CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNote(rAddr) == pNote);
-
-    // Insert a new sheet to shift the current sheet to the right.
-    m_pDoc->InsertTab(0, aTabName2);
-    CPPUNIT_ASSERT_MESSAGE("note hasn't moved", m_pDoc->GetNote(rAddr) == NULL);
-    rAddr.IncTab(); // Move to the next sheet.
-    CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNote(rAddr) == pNote);
-
-    m_pDoc->DeleteTab(0);
-    rAddr.IncTab(-1);
-    CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNote(rAddr) == pNote);
-
-    // Insert cell at C4.  This should NOT shift the note position.
-    bInsertRow = m_pDoc->InsertRow(2, 0, 2, 0, 3, 1);
-    CPPUNIT_ASSERT_MESSAGE("Failed to insert cell at C4.", bInsertRow);
-    CPPUNIT_ASSERT_MESSAGE("Note shouldn't have moved but it has.", m_pDoc->GetNote(rAddr) == pNote);
-
-    // Delete cell at C4.  Again, this should NOT shift the note position.
-    m_pDoc->DeleteRow(2, 0, 2, 0, 3, 1);
-    CPPUNIT_ASSERT_MESSAGE("Note shouldn't have moved but it has.", m_pDoc->GetNote(rAddr) == pNote);
-
-    // Now, with the note at D4, delete cell D3. This should shift the note one cell up.
-    m_pDoc->DeleteRow(3, 0, 3, 0, 2, 1);
-    rAddr.IncRow(-1); // cell D3
-    CPPUNIT_ASSERT_MESSAGE("Note at D4 should have shifted up to D3.", m_pDoc->GetNote(rAddr) == pNote);
-
-    // Delete column C. This should shift the note one cell left.
-    m_pDoc->DeleteCol(0, 0, MAXROW, 0, 2, 1);
-    rAddr.IncCol(-1); // cell C3
-    CPPUNIT_ASSERT_MESSAGE("Note at D3 should have shifted left to C3.", m_pDoc->GetNote(rAddr) == pNote);
-
-    m_pDoc->DeleteTab(0);
-}
-
 void Test::testToggleRefFlag()
 {
     // In this test, there is no need to insert formula string into a cell in
@@ -4706,6 +4641,71 @@ void Test::testShiftCells()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testNoteBasic()
+{
+    OUString aHello("Hello world");
+    OUString aJimBob("Jim Bob");
+    OUString aTabName("PostIts");
+    OUString aTabName2("Table2");
+    m_pDoc->InsertTab(0, aTabName);
+
+    ScAddress rAddr(2, 2, 0); // cell C3
+    ScPostIt *pNote = m_pDoc->GetOrCreateNote(rAddr);
+
+    pNote->SetText(rAddr, aHello);
+    pNote->SetAuthor(aJimBob);
+
+    ScPostIt *pGetNote = m_pDoc->GetNote(rAddr);
+    CPPUNIT_ASSERT_MESSAGE("note should be itself", pGetNote == pNote );
+
+    // Insert one row at row 1.
+    bool bInsertRow = m_pDoc->InsertRow(0, 0, MAXCOL, 0, 1, 1);
+    CPPUNIT_ASSERT_MESSAGE("failed to insert row", bInsertRow );
+
+    CPPUNIT_ASSERT_MESSAGE("note hasn't moved", m_pDoc->GetNote(rAddr) == NULL);
+    rAddr.IncRow(); // cell C4
+    CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNote(rAddr) == pNote);
+
+    // Insert column at column A.
+    bool bInsertCol = m_pDoc->InsertCol(0, 0, MAXROW, 0, 1, 1);
+    CPPUNIT_ASSERT_MESSAGE("failed to insert column", bInsertCol );
+
+    CPPUNIT_ASSERT_MESSAGE("note hasn't moved", m_pDoc->GetNote(rAddr) == NULL);
+    rAddr.IncCol(); // cell D4
+    CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNote(rAddr) == pNote);
+
+    // Insert a new sheet to shift the current sheet to the right.
+    m_pDoc->InsertTab(0, aTabName2);
+    CPPUNIT_ASSERT_MESSAGE("note hasn't moved", m_pDoc->GetNote(rAddr) == NULL);
+    rAddr.IncTab(); // Move to the next sheet.
+    CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNote(rAddr) == pNote);
+
+    m_pDoc->DeleteTab(0);
+    rAddr.IncTab(-1);
+    CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNote(rAddr) == pNote);
+
+    // Insert cell at C4.  This should NOT shift the note position.
+    bInsertRow = m_pDoc->InsertRow(2, 0, 2, 0, 3, 1);
+    CPPUNIT_ASSERT_MESSAGE("Failed to insert cell at C4.", bInsertRow);
+    CPPUNIT_ASSERT_MESSAGE("Note shouldn't have moved but it has.", m_pDoc->GetNote(rAddr) == pNote);
+
+    // Delete cell at C4.  Again, this should NOT shift the note position.
+    m_pDoc->DeleteRow(2, 0, 2, 0, 3, 1);
+    CPPUNIT_ASSERT_MESSAGE("Note shouldn't have moved but it has.", m_pDoc->GetNote(rAddr) == pNote);
+
+    // Now, with the note at D4, delete cell D3. This should shift the note one cell up.
+    m_pDoc->DeleteRow(3, 0, 3, 0, 2, 1);
+    rAddr.IncRow(-1); // cell D3
+    CPPUNIT_ASSERT_MESSAGE("Note at D4 should have shifted up to D3.", m_pDoc->GetNote(rAddr) == pNote);
+
+    // Delete column C. This should shift the note one cell left.
+    m_pDoc->DeleteCol(0, 0, MAXROW, 0, 2, 1);
+    rAddr.IncCol(-1); // cell C3
+    CPPUNIT_ASSERT_MESSAGE("Note at D3 should have shifted left to C3.", m_pDoc->GetNote(rAddr) == pNote);
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testNoteDeleteRow()
 {
     ScDocument* pDoc = getDocShell().GetDocument();
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 7c9b5f8..2dbb229 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -270,8 +270,6 @@ public:
     void testGraphicsInGroup();
     void testGraphicsOnSheetMove();
 
-    void testPostIts();
-
     /**
      * Test toggling relative/absolute flag of cell and cell range references.
      * This corresponds with hitting Shift-F4 while the cursor is on a formula
@@ -298,6 +296,8 @@ public:
     void testSortWithFormulaRefs();
     void testSortWithStrings();
     void testShiftCells();
+
+    void testNoteBasic();
     void testNoteDeleteRow();
     void testNoteDeleteCol();
     void testAreasWithNotes();
@@ -391,7 +391,7 @@ public:
     CPPUNIT_TEST(testDataArea);
     CPPUNIT_TEST(testGraphicsInGroup);
     CPPUNIT_TEST(testGraphicsOnSheetMove);
-    CPPUNIT_TEST(testPostIts);
+    CPPUNIT_TEST(testNoteBasic);
     CPPUNIT_TEST(testStreamValid);
     CPPUNIT_TEST(testFunctionLists);
     CPPUNIT_TEST(testToggleRefFlag);


More information about the Libreoffice-commits mailing list