sc/qa/unit/ucalc.cxx | 106 +++++++++++++++++++++++++++++++++++++++ sc/qa/unit/ucalc.hxx | 2 sc/source/core/data/conditio.cxx | 37 +++++++++++++ 3 files changed, 145 insertions(+)
New commits: commit 146f6e7e68ea56f79b72047b97bd9fba66db499d Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Tue May 13 22:46:17 2014 -0400 fdo#76710: Adjust sheet position of conditional format entries. When inserting or deleting sheets. Change-Id: Ibf898350e22f092ec38b75ad98957832a5580e6a diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx index 49f2fea..80a2b53 100644 --- a/sc/source/core/data/conditio.cxx +++ b/sc/source/core/data/conditio.cxx @@ -2002,12 +2002,49 @@ void ScConditionalFormat::InsertCol(SCTAB nTab, SCROW nRowStart, SCROW nRowEnd, void ScConditionalFormat::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt ) { + for (size_t i = 0, n = maRanges.size(); i < n; ++i) + { + // We assume that the start and end sheet indices are equal. + ScRange* pRange = maRanges[i]; + SCTAB nTab = pRange->aStart.Tab(); + + if (nTab < rCxt.mnInsertPos) + // Unaffected. + continue; + + pRange->aStart.IncTab(rCxt.mnSheets); + pRange->aEnd.IncTab(rCxt.mnSheets); + } + for (CondFormatContainer::iterator it = maEntries.begin(); it != maEntries.end(); ++it) it->UpdateInsertTab(rCxt); } void ScConditionalFormat::UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt ) { + for (size_t i = 0, n = maRanges.size(); i < n; ++i) + { + // We assume that the start and end sheet indices are equal. + ScRange* pRange = maRanges[i]; + SCTAB nTab = pRange->aStart.Tab(); + + if (nTab < rCxt.mnDeletePos) + // Left of the deleted sheet(s). Unaffected. + continue; + + if (nTab <= rCxt.mnDeletePos+rCxt.mnSheets-1) + { + // On the deleted sheet(s). + pRange->aStart.SetTab(-1); + pRange->aEnd.SetTab(-1); + continue; + } + + // Right of the deleted sheet(s). Adjust the sheet indices. + pRange->aStart.IncTab(-1*rCxt.mnSheets); + pRange->aEnd.IncTab(-1*rCxt.mnSheets); + } + for (CondFormatContainer::iterator it = maEntries.begin(); it != maEntries.end(); ++it) it->UpdateDeleteTab(rCxt); } commit dff4725f0dbb3bd7c32155e51ba49c05ee104d4f Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Tue May 13 22:42:44 2014 -0400 fdo#76710: Write test for this. Change-Id: Ia0338d2839f0f319881948c208a74bee950da4af diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 2a2f706..14a323b 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -5882,6 +5882,112 @@ void Test::testCondFormatInsertRow() m_pDoc->DeleteTab(0); } +void Test::testCondFormatInsertDeleteSheets() +{ + m_pDoc->InsertTab(0, "Test"); + + // Add a conditional format to B2:B4. + ScConditionalFormat* pFormat = new ScConditionalFormat(1, m_pDoc); + pFormat->AddRange(ScRange(1,1,0,1,3,0)); + + sal_uLong nKey = m_pDoc->AddCondFormat(pFormat, 0); + + // Add condition in which if the value equals 2, set the "Result" style. + ScCondFormatEntry* pEntry = new ScCondFormatEntry( + SC_COND_EQUAL, "=2", "" , m_pDoc, ScAddress(0,0,0), ScGlobal::GetRscString(STR_STYLENAME_RESULT)); + pFormat->AddEntry(pEntry); + + // Apply the format to the range. + m_pDoc->AddCondFormatData(pFormat->GetRange(), 0, nKey); + + // Make sure this conditional format entry is really there. + ScConditionalFormatList* pList = m_pDoc->GetCondFormList(0); + CPPUNIT_ASSERT(pList); + const ScConditionalFormat* pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT_MESSAGE("Wrong condntional format instance.", pCheck == pFormat); + + // ... and its range is B2:B4. + ScRangeList aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + const ScRange* pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4.", *pRange == ScRange(1,1,0,1,3,0)); + + ScDocFunc& rFunc = getDocShell().GetDocFunc(); + + // Insert a new sheet at the left. + bool bInserted = rFunc.InsertTable(0, "Inserted", true, true); + CPPUNIT_ASSERT(bInserted); + + pList = m_pDoc->GetCondFormList(1); + CPPUNIT_ASSERT(pList); + pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT(pCheck); + + // Make sure the range also got shifted. + aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4 on the 2nd sheet after the sheet insertion.", *pRange == ScRange(1,1,1,1,3,1)); + + // Delete the sheet to the left. + bool bDeleted = rFunc.DeleteTable(0, true, true); + CPPUNIT_ASSERT(bDeleted); + + pList = m_pDoc->GetCondFormList(0); + CPPUNIT_ASSERT(pList); + pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT(pCheck); + + // Make sure the range got shifted back. + aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4 on the 1st sheet after the sheet removal.", *pRange == ScRange(1,1,0,1,3,0)); + + SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + + // Undo and re-check. + pUndoMgr->Undo(); + + pList = m_pDoc->GetCondFormList(1); + CPPUNIT_ASSERT(pList); + pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT(pCheck); + + aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4 on the 2nd sheet after the undo of the sheet removal.", *pRange == ScRange(1,1,1,1,3,1)); + +#if 0 // TODO : Undo of sheet insertion currently depends on the presence of + // view shell, and crashes when executed during cppunit run. + + // Undo again and re-check. + pUndoMgr->Undo(); + + pList = m_pDoc->GetCondFormList(0); + CPPUNIT_ASSERT(pList); + pCheck = pList->GetFormat(nKey); + CPPUNIT_ASSERT(pCheck); + + // Make sure the range got shifted back. + aCheckRange = pCheck->GetRange(); + CPPUNIT_ASSERT_MESSAGE("This should be a single range.", aCheckRange.size() == 1); + pRange = aCheckRange[0]; + CPPUNIT_ASSERT(pRange); + CPPUNIT_ASSERT_MESSAGE("Format should be applied to B2:B4 on the 1st sheet after the undo of sheet insertion.", *pRange == ScRange(1,1,0,1,3,0)); +#else + m_pDoc->DeleteTab(1); +#endif + + m_pDoc->DeleteTab(0); +} + void Test::testCondCopyPaste() { m_pDoc->InsertTab(0, "Test"); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index f69da1b..ec32e23 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -353,6 +353,7 @@ public: void testCondFormatINSDEL(); void testCondFormatInsertRow(); void testCondFormatInsertCol(); + void testCondFormatInsertDeleteSheets(); void testCondCopyPaste(); void testIconSet(); @@ -512,6 +513,7 @@ public: CPPUNIT_TEST(testCondFormatINSDEL); CPPUNIT_TEST(testCondFormatInsertRow); CPPUNIT_TEST(testCondFormatInsertCol); + CPPUNIT_TEST(testCondFormatInsertDeleteSheets); CPPUNIT_TEST(testCondCopyPaste); CPPUNIT_TEST(testIconSet); CPPUNIT_TEST(testImportStream); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits