diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-02-04 22:14:00 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-02-05 00:29:24 -0500 |
commit | b55bd1f51c54f560da3956d54e4dd30ad1422252 (patch) | |
tree | 9c8276c9f39e7aeb2bcba14f6be8b3f69ffd72d3 /sc | |
parent | fc16069d1a8db45b7ecaa01c3ee1af0e904062c2 (diff) |
Implement GetMarkedColSpans() counterpart.
Change-Id: Ia2f4828a91ad3c89f7867e0f2e0248f885d3fff7
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/markdata.hxx | 1 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 17 | ||||
-rw-r--r-- | sc/source/core/data/markdata.cxx | 20 |
3 files changed, 38 insertions, 0 deletions
diff --git a/sc/inc/markdata.hxx b/sc/inc/markdata.hxx index 0a5b19fc9bde..4002e1f89ad0 100644 --- a/sc/inc/markdata.hxx +++ b/sc/inc/markdata.hxx @@ -111,6 +111,7 @@ public: SCCOLROW GetMarkRowRanges( SCCOLROW* pRanges ); std::vector<sc::ColRowSpan> GetMarkedRowSpans( SCTAB nTab ) const; + std::vector<sc::ColRowSpan> GetMarkedColSpans( SCTAB nTab ) const; bool IsColumnMarked( SCCOL nCol ) const; bool IsRowMarked( SCROW nRow ) const; diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 8341ef9515f0..33d13f53e4c3 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -616,6 +616,8 @@ void Test::testMarkData() // Empty mark. Nothing is selected. std::vector<sc::ColRowSpan> aSpans = aMarkData.GetMarkedRowSpans(0); CPPUNIT_ASSERT_MESSAGE("Span should be empty.", aSpans.empty()); + aSpans = aMarkData.GetMarkedColSpans(0); + CPPUNIT_ASSERT_MESSAGE("Span should be empty.", aSpans.empty()); // Select B3:F7. aMarkData.SetMarkArea(ScRange(1,2,0,5,6,0)); @@ -624,6 +626,11 @@ void Test::testMarkData() CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(2), aSpans[0].mnStart); CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(6), aSpans[0].mnEnd); + aSpans = aMarkData.GetMarkedColSpans(0); + CPPUNIT_ASSERT_MESSAGE("There should be one selected column span.", aSpans.size() == 1); + CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(1), aSpans[0].mnStart); + CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(5), aSpans[0].mnEnd); + // Select A11:B13. aMarkData.SetMultiMarkArea(ScRange(0,10,0,1,12,0)); aSpans = aMarkData.GetMarkedRowSpans(0); @@ -633,12 +640,22 @@ void Test::testMarkData() CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(10), aSpans[1].mnStart); CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(12), aSpans[1].mnEnd); + aSpans = aMarkData.GetMarkedColSpans(0); + CPPUNIT_ASSERT_MESSAGE("There should be one selected column span.", aSpans.size() == 1); + CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(0), aSpans[0].mnStart); + CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(5), aSpans[0].mnEnd); + // Select C8:C10. aMarkData.SetMultiMarkArea(ScRange(2,7,0,2,9,0)); aSpans = aMarkData.GetMarkedRowSpans(0); CPPUNIT_ASSERT_MESSAGE("There should be one selected row span.", aSpans.size() == 1); CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(2), aSpans[0].mnStart); CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(12), aSpans[0].mnEnd); + + aSpans = aMarkData.GetMarkedColSpans(0); + CPPUNIT_ASSERT_MESSAGE("There should be one selected column span.", aSpans.size() == 1); + CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(0), aSpans[0].mnStart); + CPPUNIT_ASSERT_EQUAL(static_cast<SCCOLROW>(5), aSpans[0].mnEnd); } void Test::testInput() diff --git a/sc/source/core/data/markdata.cxx b/sc/source/core/data/markdata.cxx index 37693777a8c1..7f58b681b4e3 100644 --- a/sc/source/core/data/markdata.cxx +++ b/sc/source/core/data/markdata.cxx @@ -571,6 +571,26 @@ std::vector<sc::ColRowSpan> ScMarkData::GetMarkedRowSpans( SCTAB nTab ) const return sc::toSpanArray<SCCOLROW,sc::ColRowSpan>(aSpans); } +std::vector<sc::ColRowSpan> ScMarkData::GetMarkedColSpans( SCTAB nTab ) const +{ + typedef mdds::flat_segment_tree<SCCOLROW, bool> SpansType; + + ScRangeList aRanges = GetMarkedRanges(); + SpansType aSpans(0, MAXCOL+1, false); + SpansType::const_iterator itPos = aSpans.begin(); + + for (size_t i = 0, n = aRanges.size(); i < n; ++i) + { + const ScRange& r = *aRanges[i]; + if (r.aStart.Tab() != nTab) + continue; + + itPos = aSpans.insert(itPos, r.aStart.Col(), r.aEnd.Col()+1, true).first; + } + + return sc::toSpanArray<SCCOLROW,sc::ColRowSpan>(aSpans); +} + bool ScMarkData::IsAllMarked( const ScRange& rRange ) const { if ( !bMultiMarked ) |