sc/qa/unit/ucalc.cxx | 65 +++++++++++++++++++++++++++++++++++++++ sc/source/core/data/documen2.cxx | 30 ++++++++++++++++++ 2 files changed, 95 insertions(+)
New commits: commit 07f95ee7c043702c2dde2af2fc02228a0c5273d3 Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Sun Mar 5 17:11:27 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Mar 16 09:47:28 2023 +0000 tdf#66613 - Transfer tab: preserve print ranges and col/row repetitions Change-Id: Ib0e6f9942c2bae1f1fdfa2d0ead0868e9b790b1a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148284 Tested-by: Jenkins Tested-by: Andreas Heinisch <andreas.heini...@yahoo.de> Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148488 diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index b94ccf7526c2..e5aa8515c663 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -94,6 +94,7 @@ public: void testMarkData(); void testInput(); void testColumnIterator(); + void testTdf66613(); void testTdf90698(); void testTdf114406(); void testTdf93951(); @@ -244,6 +245,7 @@ public: CPPUNIT_TEST(testMarkData); CPPUNIT_TEST(testInput); CPPUNIT_TEST(testColumnIterator); + CPPUNIT_TEST(testTdf66613); CPPUNIT_TEST(testTdf90698); CPPUNIT_TEST(testTdf114406); CPPUNIT_TEST(testTdf93951); @@ -636,6 +638,69 @@ void Test::testColumnIterator() // tdf#118620 m_pDoc->DeleteTab(0); } +void Test::testTdf66613() +{ + // Create different print ranges and col/row repetitions for two tabs + const SCTAB nFirstTab = 0; + CPPUNIT_ASSERT(m_pDoc->InsertTab(nFirstTab, "FirstPrintRange")); + ScRange aFirstPrintRange(0, 0, nFirstTab, 2, 2, nFirstTab); + m_pDoc->AddPrintRange(nFirstTab, aFirstPrintRange); + ScRange aFirstRepeatColRange(0, 0, nFirstTab, 0, 0, nFirstTab); + m_pDoc->SetRepeatColRange(nFirstTab, aFirstRepeatColRange); + ScRange aFirstRepeatRowRange(1, 1, nFirstTab, 1, 1, nFirstTab); + m_pDoc->SetRepeatRowRange(nFirstTab, aFirstRepeatRowRange); + + const SCTAB nSecondTab = 1; + CPPUNIT_ASSERT(m_pDoc->InsertTab(nSecondTab, "SecondPrintRange")); + ScRange aSecondPrintRange(0, 0, nSecondTab, 3, 3, nSecondTab); + m_pDoc->AddPrintRange(nSecondTab, aSecondPrintRange); + ScRange aSecondRepeatColRange(1, 1, nSecondTab, 1, 1, nSecondTab); + m_pDoc->SetRepeatColRange(nSecondTab, aSecondRepeatColRange); + ScRange aSecondRepeatRowRange(2, 2, nSecondTab, 2, 2, nSecondTab); + m_pDoc->SetRepeatRowRange(nSecondTab, aSecondRepeatRowRange); + + // Transfer generated tabs to a new document with different order + ScDocument aScDocument; + aScDocument.TransferTab(*m_pDoc, nSecondTab, nFirstTab); + aScDocument.TransferTab(*m_pDoc, nFirstTab, nSecondTab); + + // Check the number of print ranges in both documents + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), m_pDoc->GetPrintRangeCount(nFirstTab)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), m_pDoc->GetPrintRangeCount(nSecondTab)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aScDocument.GetPrintRangeCount(nFirstTab)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aScDocument.GetPrintRangeCount(nSecondTab)); + + // Check the print ranges and col/row repetitions in both documents + CPPUNIT_ASSERT_EQUAL(aFirstPrintRange, *m_pDoc->GetPrintRange(nFirstTab, 0)); + CPPUNIT_ASSERT_EQUAL(aFirstRepeatColRange, *m_pDoc->GetRepeatColRange(nFirstTab)); + CPPUNIT_ASSERT_EQUAL(aFirstRepeatRowRange, *m_pDoc->GetRepeatRowRange(nFirstTab)); + CPPUNIT_ASSERT_EQUAL(aSecondPrintRange, *m_pDoc->GetPrintRange(nSecondTab, 0)); + CPPUNIT_ASSERT_EQUAL(aSecondRepeatColRange, *m_pDoc->GetRepeatColRange(nSecondTab)); + CPPUNIT_ASSERT_EQUAL(aSecondRepeatRowRange, *m_pDoc->GetRepeatRowRange(nSecondTab)); + + // Tabs have to be adjusted since the order of the tabs is inverted in the new document + std::vector<ScRange*> aScRanges + = { &aFirstPrintRange, &aFirstRepeatColRange, &aFirstRepeatRowRange, + &aSecondPrintRange, &aSecondRepeatColRange, &aSecondRepeatRowRange }; + for (size_t i = 0; i < aScRanges.size(); i++) + { + const SCTAB nTab = i >= 3 ? nFirstTab : nSecondTab; + aScRanges[i]->aStart.SetTab(nTab); + aScRanges[i]->aEnd.SetTab(nTab); + } + + // Without the fix in place, no print ranges and col/row repetitions would be present + CPPUNIT_ASSERT_EQUAL(aFirstPrintRange, *aScDocument.GetPrintRange(nSecondTab, 0)); + CPPUNIT_ASSERT_EQUAL(aFirstRepeatColRange, *aScDocument.GetRepeatColRange(nSecondTab)); + CPPUNIT_ASSERT_EQUAL(aFirstRepeatRowRange, *aScDocument.GetRepeatRowRange(nSecondTab)); + CPPUNIT_ASSERT_EQUAL(aSecondPrintRange, *aScDocument.GetPrintRange(nFirstTab, 0)); + CPPUNIT_ASSERT_EQUAL(aSecondRepeatColRange, *aScDocument.GetRepeatColRange(nFirstTab)); + CPPUNIT_ASSERT_EQUAL(aSecondRepeatRowRange, *aScDocument.GetRepeatRowRange(nFirstTab)); + + m_pDoc->DeleteTab(nFirstTab); + m_pDoc->DeleteTab(nSecondTab); +} + void Test::testTdf90698() { CPPUNIT_ASSERT(m_pDoc->InsertTab (0, "Test")); diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index e21da4be599b..a7ea162177a9 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -1023,6 +1023,36 @@ sal_uLong ScDocument::TransferTab( ScDocument& rSrcDoc, SCTAB nSrcPos, maTabs[nDestPos]->SetTabNo(nDestPos); maTabs[nDestPos]->SetTabBgColor(rSrcDoc.maTabs[nSrcPos]->GetTabBgColor()); + // tdf#66613 - copy existing print ranges and col/row repetitions + if (auto aRepeatColRange = rSrcDoc.maTabs[nSrcPos]->GetRepeatColRange()) + { + aRepeatColRange->aStart.SetTab(nDestPos); + aRepeatColRange->aEnd.SetTab(nDestPos); + maTabs[nDestPos]->SetRepeatColRange(aRepeatColRange); + } + + if (auto aRepeatRowRange = rSrcDoc.maTabs[nSrcPos]->GetRepeatRowRange()) + { + aRepeatRowRange->aStart.SetTab(nDestPos); + aRepeatRowRange->aEnd.SetTab(nDestPos); + maTabs[nDestPos]->SetRepeatRowRange(aRepeatRowRange); + } + + if (rSrcDoc.IsPrintEntireSheet(nSrcPos)) + maTabs[nDestPos]->SetPrintEntireSheet(); + else + { + const auto nPrintRangeCount = rSrcDoc.maTabs[nSrcPos]->GetPrintRangeCount(); + for (auto nPos = 0; nPos < nPrintRangeCount; nPos++) + { + // Adjust the tab for the print range at the new position + ScRange aSrcPrintRange(*rSrcDoc.maTabs[nSrcPos]->GetPrintRange(nPos)); + aSrcPrintRange.aStart.SetTab(nDestPos); + aSrcPrintRange.aEnd.SetTab(nDestPos); + maTabs[nDestPos]->AddPrintRange(aSrcPrintRange); + } + } + if ( !bResultsOnly ) { sc::RefUpdateContext aRefCxt(*this);