diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-14 11:51:05 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-08-14 11:52:55 -0400 |
commit | 64073c45aac22696bed6b688bb34974d646f3c34 (patch) | |
tree | 4d3e4733e0438fe0117462e25e7c2491bc2647de /sc | |
parent | 9a9ee66f0d9dd126ed31db096b77f9c67355411b (diff) |
Do the same when inserting columns.
Change-Id: I387ef3c2c8345bb5be75909596f59af80b966443
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/table.hxx | 3 | ||||
-rw-r--r-- | sc/qa/unit/ucalc_sharedformula.cxx | 48 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 7 |
4 files changed, 57 insertions, 3 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 5e3f9598863f..06e8151ddda8 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 4d9ad67f0e38..39e5176d61df 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 2e3a27944b50..db97f7773e6c 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 d2174de1fb93..f60ed3f92d02 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(); |