diff options
author | Tor Lillqvist <tml@collabora.com> | 2017-09-14 21:11:27 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2018-01-23 15:33:05 +0100 |
commit | c0c65bfa65f33d9756ba1e4f58ebc691e321089f (patch) | |
tree | ecaa724dbedbf8e087bf667d80d3215d432dbc15 /sc | |
parent | 75520f7c427237e10f751c685012dcb86a345836 (diff) |
Handle also the case where a range extends an existing one with overlap
Check for a new range being joined Extending an existing one in any of
four directions (up, right, down, left), within a tab (sheet), that
is. And add unit test for this.
Reviewed-on: https://gerrit.libreoffice.org/42304
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
(cherry picked from commit 596efaad51735a130e7b7bd27dbc34dc07f32f68)
Change-Id: I4bd0525c2837f8b4b9d5a8967e0d5d661c6a5e2f
Reviewed-on: https://gerrit.libreoffice.org/48410
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/rangelst_test.cxx | 57 | ||||
-rw-r--r-- | sc/source/core/tool/rangelst.cxx | 12 |
2 files changed, 65 insertions, 4 deletions
diff --git a/sc/qa/unit/rangelst_test.cxx b/sc/qa/unit/rangelst_test.cxx index dce700164ecd..79c57364e209 100644 --- a/sc/qa/unit/rangelst_test.cxx +++ b/sc/qa/unit/rangelst_test.cxx @@ -44,6 +44,8 @@ public: void testDeleteArea_0Ranges(); void testJoin_Case1(); void testJoin_Case2(); + void testJoin_Case3(); + void testJoin_Case4(); void testGetIntersectedRange(); void testUpdateReference_DeleteRow(); @@ -72,6 +74,8 @@ public: CPPUNIT_TEST(testDeleteArea_0Ranges); CPPUNIT_TEST(testJoin_Case1); CPPUNIT_TEST(testJoin_Case2); + CPPUNIT_TEST(testJoin_Case3); + CPPUNIT_TEST(testJoin_Case4); CPPUNIT_TEST(testUpdateReference_DeleteRow); CPPUNIT_TEST(testUpdateReference_DeleteLastRow); CPPUNIT_TEST(testUpdateReference_DeleteCol); @@ -424,6 +428,59 @@ void Test::testJoin_Case2() CPPUNIT_ASSERT_EQUAL(ScRange(1,1,0,9,3,0), *aList[0]); } +void Test::testJoin_Case3() +{ + ScRangeList aList; + aList.Join(ScRange(1,1,0,6,6,0)); + aList.Join(ScRange(3,3,0,4,4,0)); + + // The second one should have been swallowed by the first one + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList.size()); + CPPUNIT_ASSERT_EQUAL(ScRange(1,1,0,6,6,0), *aList[0]); + + // Add a disjoint one + aList.Join(ScRange(8,8,0,9,9,0)); + + // Should be two ones now + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList.size()); + // The first one should still be as is + CPPUNIT_ASSERT_EQUAL(ScRange(1,1,0,6,6,0), *aList[0]); + // Ditto for the second one + CPPUNIT_ASSERT_EQUAL(ScRange(8,8,0,9,9,0), *aList[1]); +} + +void Test::testJoin_Case4() +{ + ScRangeList aList; + aList.Join(ScRange(1,1,0,2,6,0)); + // Join a range that overlaps it and extends it vertically + aList.Join(ScRange(1,4,0,2,8,0)); + + // The one range in the list should have been extended + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList.size()); + CPPUNIT_ASSERT_EQUAL(ScRange(1,1,0,2,8,0), *aList[0]); + + // Join a range that overlaps it and extends it horizontally + aList.Join(ScRange(2,1,0,4,8,0)); + + // Again, should have just been extended + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList.size()); + CPPUNIT_ASSERT_EQUAL(ScRange(1,1,0,4,8,0), *aList[0]); + + // And then the same but on top / to the left of existing range + ScRangeList aList2; + aList2.Join(ScRange(4,4,0,8,8,0)); + aList2.Join(ScRange(4,1,0,8,6,0)); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList2.size()); + CPPUNIT_ASSERT_EQUAL(ScRange(4,1,0,8,8,0), *aList2[0]); + + aList2.Join(ScRange(1,1,0,6,8,0)); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList2.size()); + CPPUNIT_ASSERT_EQUAL(ScRange(1,1,0,8,8,0), *aList2[0]); +} + void Test::testUpdateReference_DeleteRow() { ScRangeList aList(ScRange(1,1,0,4,4,0)); diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx index 5ae74f9c0f3d..19fed29aba75 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -299,12 +299,14 @@ void ScRangeList::Join( const ScRange& r, bool bIsInList ) { // 2D if ( p->aStart.Col() == nCol1 && p->aEnd.Col() == nCol2 ) { - if ( p->aStart.Row() == nRow2+1 ) + if ( p->aStart.Row() <= nRow2+1 && + p->aStart.Row() >= nRow1 ) { // top p->aStart.SetRow( nRow1 ); bJoined = true; } - else if ( p->aEnd.Row() == nRow1-1 ) + else if ( p->aEnd.Row() >= nRow1-1 && + p->aEnd.Row() <= nRow2 ) { // bottom p->aEnd.SetRow( nRow2 ); bJoined = true; @@ -312,12 +314,14 @@ void ScRangeList::Join( const ScRange& r, bool bIsInList ) } else if ( p->aStart.Row() == nRow1 && p->aEnd.Row() == nRow2 ) { - if ( p->aStart.Col() == nCol2+1 ) + if ( p->aStart.Col() <= nCol2+1 && + p->aStart.Col() >= nCol1 ) { // left p->aStart.SetCol( nCol1 ); bJoined = true; } - else if ( p->aEnd.Col() == nCol1-1 ) + else if ( p->aEnd.Col() >= nCol1-1 && + p->aEnd.Col() <= nCol2 ) { // right p->aEnd.SetCol( nCol2 ); bJoined = true; |