summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-08-13 23:47:58 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-08-13 23:48:30 -0400
commit05f5191de3895b5c6b263d6dfba63f494e5e4a5b (patch)
tree68b5c4e47b748a3a35067bce81b3baf12d9aeb82 /sc
parentc4d26f327605b77c8395bdb512d8ddcd8c11bfd1 (diff)
Do the same when deleting rows.
Change-Id: Ib1deab33a8771e196d0520bae872eb0d492c913e
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/table.hxx4
-rw-r--r--sc/qa/unit/ucalc_sharedformula.cxx31
-rw-r--r--sc/source/core/data/document.cxx4
-rw-r--r--sc/source/core/data/table2.cxx9
4 files changed, 42 insertions, 6 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index fa6247cb6312..5e3f9598863f 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -384,8 +384,8 @@ public:
bool TestInsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize ) const;
void InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize );
- void DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize,
- bool* pUndoOutline = NULL );
+ void DeleteRow(
+ 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 );
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 094db8f1acd1..4d9ad67f0e38 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -309,6 +309,37 @@ 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:A12 and shift down.
+ m_pDoc->InsertRow(ScRange(0,10,0,0,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), "A13"))
+ CPPUNIT_FAIL("Wrong formula in B2");
+ if (!checkFormula(*m_pDoc, ScAddress(1,2,0), "A14"))
+ 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("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());
+
+ // Delete A11:A12 to bring it back to the way it was.
+ m_pDoc->DeleteRow(ScRange(0,10,0,0,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), "A11"))
+ 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("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 9fdf84ac46cb..2e3a27944b50 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1301,10 +1301,10 @@ void ScDocument::DeleteRow( SCCOL nStartCol, SCTAB nStartTab,
}
while ( lcl_GetNextTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) ) );
+ sc::RefUpdateContext aCxt(*this);
if ( ValidRow(nStartRow+nSize) )
{
lcl_GetFirstTabRange( nTabRangeStart, nTabRangeEnd, pTabMark, static_cast<SCTAB>(maTabs.size()) );
- sc::RefUpdateContext aCxt(*this);
aCxt.meMode = URM_INSDEL;
aCxt.maRange = ScRange(nStartCol, nStartRow+nSize, nTabRangeStart, nEndCol, MAXROW, nTabRangeEnd);
aCxt.mnRowDelta = -(static_cast<SCROW>(nSize));
@@ -1320,7 +1320,7 @@ void ScDocument::DeleteRow( SCCOL nStartCol, SCTAB nStartTab,
for ( i = nStartTab; i <= nEndTab && i < static_cast<SCTAB>(maTabs.size()); i++)
if (maTabs[i] && (!pTabMark || pTabMark->GetTableSelect(i)))
- maTabs[i]->DeleteRow( nStartCol, nEndCol, nStartRow, nSize, pUndoOutline );
+ maTabs[i]->DeleteRow(aCxt.maRegroupCols, nStartCol, nEndCol, nStartRow, nSize, pUndoOutline);
if ( ValidRow(nStartRow+nSize) )
{ // Listeners have been removed in UpdateReference
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index f900f6286245..d2174de1fb93 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -227,8 +227,9 @@ void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE
}
-void ScTable::DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize,
- bool* pUndoOutline )
+void ScTable::DeleteRow(
+ const sc::ColumnSet& rRegroupCols, SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize,
+ bool* pUndoOutline )
{
if (nStartCol==0 && nEndCol==MAXCOL)
{
@@ -266,6 +267,10 @@ void ScTable::DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE
}
}
+ 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();