sc/inc/table.hxx                   |    3 +-
 sc/qa/unit/ucalc_sharedformula.cxx |   48 +++++++++++++++++++++++++++++++++++++
 sc/source/core/data/document.cxx   |    2 -
 sc/source/core/data/table2.cxx     |    7 ++++-
 4 files changed, 57 insertions(+), 3 deletions(-)

New commits:
commit 64073c45aac22696bed6b688bb34974d646f3c34
Author: Kohei Yoshida <kohei.yosh...@gmail.com>
Date:   Wed Aug 14 11:51:05 2013 -0400

    Do the same when inserting columns.
    
    Change-Id: I387ef3c2c8345bb5be75909596f59af80b966443

diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 5e3f959..06e8151 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -388,7 +388,8 @@ public:
         const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCCOL nEndCol, 
SCROW nStartRow, SCSIZE nSize, bool* pUndoOutline = NULL );
 
     bool        TestInsertCol( SCROW nStartRow, SCROW nEndRow, SCSIZE nSize ) 
const;
-    void        InsertCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, 
SCSIZE nSize );
+    void InsertCol(
+        const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, 
SCROW nEndRow, SCSIZE nSize );
     void DeleteCol(
         const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, 
SCROW nEndRow, SCSIZE nSize, bool* pUndoOutline = NULL );
 
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx 
b/sc/qa/unit/ucalc_sharedformula.cxx
index 4d9ad67..39e5176 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -340,6 +340,54 @@ void Test::testSharedFormulasRefUpdate()
     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pFC->GetSharedTopRow());
     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength());
 
+    // Insert cells over A11:B11 to shift to right again.
+    m_pDoc->InsertCol(ScRange(0,10,0,1,10,0));
+    if (!checkFormula(*m_pDoc, ScAddress(1,0,0), "A10"))
+        CPPUNIT_FAIL("Wrong formula in B1");
+    if (!checkFormula(*m_pDoc, ScAddress(1,1,0), "C11"))
+        CPPUNIT_FAIL("Wrong formula in B2");
+    if (!checkFormula(*m_pDoc, ScAddress(1,2,0), "A12"))
+        CPPUNIT_FAIL("Wrong formula in B3");
+
+    pFC = m_pDoc->GetFormulaCell(ScAddress(1,0,0));
+    CPPUNIT_ASSERT_MESSAGE("B1 should be a non-shared formula cell.", pFC && 
!pFC->IsShared());
+    pFC = m_pDoc->GetFormulaCell(ScAddress(1,1,0));
+    CPPUNIT_ASSERT_MESSAGE("B2 should be a non-shared formula cell.", pFC && 
!pFC->IsShared());
+    pFC = m_pDoc->GetFormulaCell(ScAddress(1,2,0));
+    CPPUNIT_ASSERT_MESSAGE("B3 should be a non-shared formula cell.", pFC && 
!pFC->IsShared());
+
+    // Insert cells over A12:B12 to shift to right.
+    m_pDoc->InsertCol(ScRange(0,11,0,1,11,0));
+    if (!checkFormula(*m_pDoc, ScAddress(1,0,0), "A10"))
+        CPPUNIT_FAIL("Wrong formula in B1");
+    if (!checkFormula(*m_pDoc, ScAddress(1,1,0), "C11"))
+        CPPUNIT_FAIL("Wrong formula in B2");
+    if (!checkFormula(*m_pDoc, ScAddress(1,2,0), "C12"))
+        CPPUNIT_FAIL("Wrong formula in B3");
+
+    pFC = m_pDoc->GetFormulaCell(ScAddress(1,0,0));
+    CPPUNIT_ASSERT_MESSAGE("B1 should be a non-shared formula cell.", pFC && 
!pFC->IsShared());
+    // B2 and B3 should be grouped.
+    pFC = m_pDoc->GetFormulaCell(ScAddress(1,1,0));
+    CPPUNIT_ASSERT_MESSAGE("This must be a shared formula cell.", pFC && 
pFC->IsShared());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(1), pFC->GetSharedTopRow());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(2), pFC->GetSharedLength());
+
+    // Insert cells over A10:B10 to shift to right.
+    m_pDoc->InsertCol(ScRange(0,9,0,1,9,0));
+    if (!checkFormula(*m_pDoc, ScAddress(1,0,0), "C10"))
+        CPPUNIT_FAIL("Wrong formula in B1");
+    if (!checkFormula(*m_pDoc, ScAddress(1,1,0), "C11"))
+        CPPUNIT_FAIL("Wrong formula in B2");
+    if (!checkFormula(*m_pDoc, ScAddress(1,2,0), "C12"))
+        CPPUNIT_FAIL("Wrong formula in B3");
+
+    // B1:B3 should be now grouped.
+    pFC = m_pDoc->GetFormulaCell(ScAddress(1,0,0));
+    CPPUNIT_ASSERT_MESSAGE("This must be a shared formula cell.", pFC && 
pFC->IsShared());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(0), pFC->GetSharedTopRow());
+    CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength());
+
     m_pDoc->DeleteTab(0);
 }
 
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 2e3a279..db97f77 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1423,7 +1423,7 @@ bool ScDocument::InsertCol( SCROW nStartRow, SCTAB 
nStartTab,
 
         for (i=nStartTab; i<=nEndTab && i < static_cast<SCTAB>(maTabs.size()); 
i++)
             if (maTabs[i] && (!pTabMark || pTabMark->GetTableSelect(i)))
-                maTabs[i]->InsertCol( nStartCol, nStartRow, nEndRow, nSize );
+                maTabs[i]->InsertCol(aCxt.maRegroupCols, nStartCol, nStartRow, 
nEndRow, nSize);
 
         if ( pChangeTrack && pChangeTrack->IsInDeleteUndo() )
         {   // durch Restaurierung von Referenzen auf geloeschte Bereiche ist
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index d2174de..f60ed3f 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -341,7 +341,8 @@ bool ScTable::TestInsertCol( SCROW nStartRow, SCROW 
nEndRow, SCSIZE nSize ) cons
 }
 
 
-void ScTable::InsertCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, 
SCSIZE nSize )
+void ScTable::InsertCol(
+    const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCROW nStartRow, SCROW 
nEndRow, SCSIZE nSize )
 {
     if (nStartRow==0 && nEndRow==MAXROW)
     {
@@ -388,6 +389,10 @@ void ScTable::InsertCol( SCCOL nStartCol, SCROW nStartRow, 
SCROW nEndRow, SCSIZE
             aCol[MAXCOL - nSize - i].MoveTo(nStartRow, nEndRow, aCol[MAXCOL - 
i]);
     }
 
+    std::vector<SCCOL> aRegroupCols;
+    rRegroupCols.getColumns(nTab, aRegroupCols);
+    std::for_each(aRegroupCols.begin(), aRegroupCols.end(), 
ColumnRegroupFormulaCells(aCol));
+
     // Transfer those notes that will get shifted into another container.
     ScNotes aNotes(pDocument);
     ScNotes::iterator itr = maNotes.begin();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to