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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 2 08:05:03 PDT 2012


 sc/qa/unit/ucalc.cxx           |   26 ++++++++++++++++++++------
 sc/source/core/data/table2.cxx |   10 ++++++++--
 2 files changed, 28 insertions(+), 8 deletions(-)

New commits:
commit e8487c8a3f3ece74143928352e1e8a7dfb72d424
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Nov 2 11:01:15 2012 -0400

    Fix incorrect shifting of cell notes upon cell insertion / deletion.
    
    Steps to reproduce:
    
    1) Insert a comment at D5.
    2) Move cursor to C4.
    3) Right-click and select Insert.
    4) Choose shift cells down.
    5) The comment gets shifted down but it shouldn't.
    
    The same thing happens when deleting a cell and shifting content.
    
    Change-Id: I5a71845cca6abde6b7c940e152e155da26343cef

diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 193e7f0..8bfb0e6 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -171,6 +171,7 @@ void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE
     for (SCCOL j=nStartCol; j<=nEndCol; j++)
         aCol[j].InsertRow( nStartRow, nSize );
 
+    // Transfer those notes that will get shifted into another container.
     ScNotes aNotes(pDocument);
     ScNotes::iterator itr = maNotes.begin();
     while( itr != maNotes.end() )
@@ -180,13 +181,14 @@ void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE
         ScPostIt* pPostIt = itr->second;
         ++itr;
 
-        if (nRow >= nStartRow)
+        if (nStartRow <= nRow && nStartCol <= nCol && nCol <= nEndCol)
         {
             aNotes.insert(nCol, nRow + nSize, pPostIt);
             maNotes.ReleaseNote(nCol, nRow);
         }
     }
 
+    // Re-insert the shifted notes.
     itr = aNotes.begin();
     while( itr != aNotes.end() )
     {
@@ -247,6 +249,7 @@ void ScTable::DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE
         }
     }
 
+    // Transfer those notes that will get shifted into another container.
     ScNotes aNotes(pDocument);
     ScNotes::iterator itr = maNotes.begin();
     while( itr != maNotes.end() )
@@ -256,18 +259,21 @@ void ScTable::DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE
         ScPostIt* pPostIt = itr->second;
         ++itr;
 
-        if (nRow >= nStartRow)
+        if (nStartRow <= nRow && nStartCol <= nCol && nCol <= nEndCol)
         {
             if(nRow - nStartRow > static_cast<SCROW>(nSize))
             {
+                // This note will get shifted.
                 aNotes.insert(nCol, nRow - nSize, pPostIt);
                 maNotes.ReleaseNote(nCol, nRow);
             }
             else
+                // Note is in the deleted area. Remove it.
                 maNotes.erase(nCol, nRow);
         }
     }
 
+    // Re-insert the shifted notes.
     itr = aNotes.begin();
     while( itr != aNotes.end() )
     {
commit e127cb937698938e233e7b469a10e35585ddb88f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Nov 2 10:40:14 2012 -0400

    Added comment for the note test code & added test for new scenario.
    
    The new test currently fails due to bug.
    
    Change-Id: I447f43039f32c33eb55c182515e826a8250d7525

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 66ad169..62e98c6 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -4242,7 +4242,7 @@ void Test::testPostIts()
     rtl::OUString aTabName2("Table2");
     m_pDoc->InsertTab(0, aTabName);
 
-    ScAddress rAddr(2, 2, 0);
+    ScAddress rAddr(2, 2, 0); // cell C3
     ScPostIt *pNote = m_pDoc->GetNotes(rAddr.Tab())->GetOrCreateNote(rAddr);
     pNote->SetText(rAddr, aHello);
     pNote->SetAuthor(aJimBob);
@@ -4250,29 +4250,41 @@ void Test::testPostIts()
     ScPostIt *pGetNote = m_pDoc->GetNotes(rAddr.Tab())->findByAddress(rAddr);
     CPPUNIT_ASSERT_MESSAGE("note should be itself", pGetNote == pNote );
 
-    bool bInsertRow = m_pDoc->InsertRow( 0, 0, 100, 0, 1, 1 );
+    // 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->GetNotes(rAddr.Tab())->findByAddress(rAddr) == NULL);
-    rAddr.IncRow();
+    rAddr.IncRow(); // cell C4
     CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNotes(rAddr.Tab())->findByAddress(rAddr) == pNote);
 
-    bool bInsertCol = m_pDoc->InsertCol( 0, 0, 100, 0, 1, 1 );
+    // Insert column at column 1.
+    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->GetNotes(rAddr.Tab())->findByAddress(rAddr) == NULL);
-    rAddr.IncCol();
+    rAddr.IncCol(); // cell D4
     CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNotes(rAddr.Tab())->findByAddress(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->GetNotes(rAddr.Tab())->findByAddress(rAddr) == NULL);
-    rAddr.IncTab();
+    rAddr.IncTab(); // Move to the next sheet.
     CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNotes(rAddr.Tab())->findByAddress(rAddr) == pNote);
 
     m_pDoc->DeleteTab(0);
     rAddr.IncTab(-1);
     CPPUNIT_ASSERT_MESSAGE("note not there", m_pDoc->GetNotes(rAddr.Tab())->findByAddress(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->GetNotes(rAddr.Tab())->findByAddress(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->GetNotes(rAddr.Tab())->findByAddress(rAddr) == pNote);
+
     m_pDoc->DeleteTab(0);
 }
 
commit 14f230d30fd10d1b390102fa30f4bd8a3da6eb6a
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Fri Nov 2 10:06:31 2012 -0400

    A little more check won't hurt...
    
    Change-Id: I1cd3fb194b78eb11cb91b7779cab32a461046d9f

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 7c2c1af..66ad169 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5214,11 +5214,13 @@ void Test::testShiftCells()
     m_pDoc->InsertCol(3, 0, 3, 0, 3, 1);
     OUString aStr = m_pDoc->GetString(5, 3, 0);
     CPPUNIT_ASSERT_MESSAGE("We should have a string cell here.", aStr == aTestVal);
+    CPPUNIT_ASSERT_MESSAGE("D5 is supposed to be blank.", m_pDoc->IsBlockEmpty(0, 3, 4, 3, 4));
 
     // Delete cell D5, to shift the text cell back into D5.
     m_pDoc->DeleteCol(3, 0, 3, 0, 3, 1);
     aStr = m_pDoc->GetString(4, 3, 0);
     CPPUNIT_ASSERT_MESSAGE("We should have a string cell here.", aStr == aTestVal);
+    CPPUNIT_ASSERT_MESSAGE("E5 is supposed to be blank.", m_pDoc->IsBlockEmpty(0, 4, 4, 4, 4));
 
     m_pDoc->DeleteTab(0);
 }


More information about the Libreoffice-commits mailing list