[Libreoffice-commits] .: 2 commits - sc/qa sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 2 10:44:30 PDT 2012


 sc/qa/unit/ucalc.cxx           |   12 +++++++++++-
 sc/source/core/data/table2.cxx |   16 ++++++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)

New commits:
commit d3344dd85ee31b195a3709d16e734245e1d0a4b6
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Nov 2 13:27:31 2012 -0400

    Correctly handle cell note shifting when immediate row/column is deleted.
    
    Currently, having a note e.g. at D5, and deleting cell D4 and shifting
    the cells below upward will remove the note at D5.  But the correct behavior
    is to shift that note up to D4.  This change fixes it.
    
    Change-Id: Ia37f1ce67a003deab424f2b805a2ce333fc10ed4

diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 8bfb0e6..69e2f02 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -261,7 +261,8 @@ void ScTable::DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE
 
         if (nStartRow <= nRow && nStartCol <= nCol && nCol <= nEndCol)
         {
-            if(nRow - nStartRow > static_cast<SCROW>(nSize))
+            SCROW nEndRow = nStartRow + nSize - 1; // last row of deleted region
+            if (nEndRow < nRow)
             {
                 // This note will get shifted.
                 aNotes.insert(nCol, nRow - nSize, pPostIt);
@@ -365,6 +366,7 @@ void ScTable::InsertCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE
             aCol[MAXCOL - nSize - i].MoveTo(nStartRow, nEndRow, aCol[MAXCOL - i]);
     }
 
+    // Transfer those notes that will get shifted into another container.
     ScNotes aNotes(pDocument);
     ScNotes::iterator itr = maNotes.begin();
     while( itr != maNotes.end() )
@@ -374,13 +376,14 @@ void ScTable::InsertCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE
         ScPostIt* pPostIt = itr->second;
         ++itr;
 
-        if (nCol >= nStartCol)
+        if (nStartCol <= nCol && nStartRow <= nRow && nRow <= nEndRow)
         {
             aNotes.insert(nCol + nSize, nRow, pPostIt);
             maNotes.ReleaseNote(nCol, nRow);
         }
     }
 
+    // Re-insert the shifted notes.
     itr = aNotes.begin();
     while( itr != aNotes.end() )
     {
@@ -471,6 +474,7 @@ void ScTable::DeleteCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE
             aCol[nStartCol + nSize + i].MoveTo(nStartRow, nEndRow, aCol[nStartCol + i]);
     }
 
+    // Transfer those notes that will get shifted into another container.
     ScNotes aNotes(pDocument);
     ScNotes::iterator itr = maNotes.begin();
     while( itr != maNotes.end() )
@@ -480,18 +484,22 @@ void ScTable::DeleteCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE
         ScPostIt* pPostIt = itr->second;
         ++itr;
 
-        if (nCol >= nStartCol)
+        if (nStartCol <= nCol && nStartRow <= nRow && nRow <= nEndRow)
         {
-            if(nCol - nStartCol > static_cast<SCCOL>(nSize))
+            SCCOL nEndCol = nStartCol + nSize - 1;
+            if (nEndCol < nCol)
             {
+                // This note will get shifted.
                 aNotes.insert(nCol - nSize, nRow, pPostIt);
                 maNotes.ReleaseNote(nCol, nRow);
             }
             else
+                // The note is in the deleted region. Remove it.
                 maNotes.erase(nCol, nRow);
         }
     }
 
+    // Re-insert the shifted notes.
     itr = aNotes.begin();
     while( itr != aNotes.end() )
     {
commit 6bac39f309e11a515a2b2ecdf43a4b49ccd53502
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Nov 2 13:23:58 2012 -0400

    More test cases for cell notes that currently fail.
    
    Change-Id: I23a5a39ab13106a27a02adbec0ff1ab64a43abef

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 62e98c6..ce8ea86 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -4258,7 +4258,7 @@ void Test::testPostIts()
     rAddr.IncRow(); // cell C4
     CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNotes(rAddr.Tab())->findByAddress(rAddr) == pNote);
 
-    // Insert column at column 1.
+    // Insert column at column A.
     bool bInsertCol = m_pDoc->InsertCol(0, 0, MAXROW, 0, 1, 1);
     CPPUNIT_ASSERT_MESSAGE("failed to insert column", bInsertCol );
 
@@ -4285,6 +4285,16 @@ void Test::testPostIts()
     m_pDoc->DeleteRow(2, 0, 2, 0, 3, 1);
     CPPUNIT_ASSERT_MESSAGE("Note shouldn't have moved but it has.", m_pDoc->GetNotes(rAddr.Tab())->findByAddress(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->GetNotes(rAddr.Tab())->findByAddress(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->GetNotes(rAddr.Tab())->findByAddress(rAddr) == pNote);
+
     m_pDoc->DeleteTab(0);
 }
 


More information about the Libreoffice-commits mailing list