sc/inc/document.hxx | 6 ++++++ sc/qa/unit/ucalc.cxx | 35 +++++++++++++++++++++++++++++++++++ sc/qa/unit/ucalc.hxx | 2 ++ sc/source/core/data/table2.cxx | 35 +++++++++++++++++++++++++++++++---- 4 files changed, 74 insertions(+), 4 deletions(-)
New commits: commit 7345a032bb6758dcbe425c911d557d0b22d7d5ec Author: Kohei Yoshida <[email protected]> Date: Fri Oct 7 21:51:04 2016 -0400 Reduce the number of calls to underlying flat_segment_tree structure. By replacing the getValue() call to getRangeData(). Change-Id: Ia563b08dd356d9653e6a6ce16256196b28f56b65 diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 36ed4ef..7925af6 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -3673,9 +3673,13 @@ sal_uLong ScTable::GetRowOffset( SCROW nRow, bool bHiddenAsZero ) const SCROW ScTable::GetRowForHeight(sal_uLong nHeight) const { - sal_uInt32 nSum = 0; + sal_uLong nSum = 0; ScFlatBoolRowSegments::RangeData aData; + + ScFlatUInt16RowSegments::RangeData aRowHeightRange; + aRowHeightRange.mnRow2 = -1; + for (SCROW nRow = 0; nRow <= MAXROW; ++nRow) { if (!mpHiddenRows->getRangeData(nRow, aData)) @@ -3689,8 +3693,15 @@ SCROW ScTable::GetRowForHeight(sal_uLong nHeight) const continue; } - sal_uInt32 nNew = mpRowHeights->getValue(nRow); - nSum += nNew; + if (aRowHeightRange.mnRow2 < nRow) + { + if (!mpRowHeights->getRangeData(nRow, aRowHeightRange)) + // Failed to fetch the range data for whatever reason. + break; + } + + nSum += aRowHeightRange.mnValue; + if (nSum > nHeight) { if (nRow >= MAXROW) commit f37292941fef7375b8bc29783f54e0c64d670a24 Author: Kohei Yoshida <[email protected]> Date: Fri Oct 7 21:39:02 2016 -0400 Write test case for it. Change-Id: I63f8b5d490686f838c0618d670bb21a957690866 diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index f1d705f..86e2ed6 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -465,6 +465,41 @@ void Test::testDocStatistics() m_pDoc->DeleteTab(0); // This may fail in case there is only one sheet in the document. } +void Test::testRowForHeight() +{ + m_pDoc->InsertTab(0, "Sheet1"); + m_pDoc->SetRowHeightRange( 0, 9, 0, 100); + m_pDoc->SetRowHeightRange(10, 19, 0, 200); + m_pDoc->SetRowHeightRange(20, 29, 0, 300); + + // Hide some rows. + m_pDoc->SetRowHidden(3, 5, 0, true); + m_pDoc->SetRowHidden(8, 12, 0, true); + + struct Check + { + sal_uLong nHeight; + SCROW nRow; + }; + + std::vector<Check> aChecks = { + { 1, 1 }, + { 99, 1 }, + { 120, 2 }, + { 330, 7 }, + { 420, 13 }, + { 780, 15 }, + { 1860, 20 }, + { 4020, 28 }, + }; + + for (const Check& rCheck : aChecks) + { + SCROW nRow = m_pDoc->GetRowForHeight(0, rCheck.nHeight); + CPPUNIT_ASSERT_EQUAL(rCheck.nRow, nRow); + } +} + void Test::testDataEntries() { m_pDoc->InsertTab(0, "Test"); diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx index cbc9981..2a7a1a2 100644 --- a/sc/qa/unit/ucalc.hxx +++ b/sc/qa/unit/ucalc.hxx @@ -107,6 +107,7 @@ public: void testMarkData(); void testInput(); void testDocStatistics(); + void testRowForHeight(); /** * The 'data entries' data is a list of strings used for suggestions as @@ -492,6 +493,7 @@ public: CPPUNIT_TEST(testMarkData); CPPUNIT_TEST(testInput); CPPUNIT_TEST(testDocStatistics); + CPPUNIT_TEST(testRowForHeight); CPPUNIT_TEST(testDataEntries); CPPUNIT_TEST(testSelectionFunction); CPPUNIT_TEST(testFormulaCreateStringFromTokens); commit 61b76cd8ca6a4a98a2ffe6fb42c73eba561aa87f Author: Kohei Yoshida <[email protected]> Date: Fri Oct 7 21:34:51 2016 -0400 Properly skip the hidden row(s) at the end. This method is supposed to return the first visible row that occurs below the specified hight. The old code would sometimes return a hidden row. Change-Id: Idf32c625c4f51355cd5d8a9f12ae9bbdddd4e5aa diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 727e68c..2dbe866 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1689,6 +1689,12 @@ public: SC_DLLPUBLIC sal_uInt16 GetRowHeight( SCROW nRow, SCTAB nTab, bool bHiddenAsZero = true ) const; SC_DLLPUBLIC sal_uInt16 GetRowHeight( SCROW nRow, SCTAB nTab, SCROW* pStartRow, SCROW* pEndRow ) const; SC_DLLPUBLIC sal_uLong GetRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero = true ) const; + + /** + * Given the height i.e. total vertical distance from the top of the sheet + * grid, return the first visible row whose top position is below the + * specified height. + */ SCROW GetRowForHeight( SCTAB nTab, sal_uLong nHeight ) const; sal_uLong GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, double fScale ) const; SC_DLLPUBLIC sal_uLong GetColOffset( SCCOL nCol, SCTAB nTab, bool bHiddenAsZero = true ) const; diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index df61646..36ed4ef 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -3679,10 +3679,12 @@ SCROW ScTable::GetRowForHeight(sal_uLong nHeight) const for (SCROW nRow = 0; nRow <= MAXROW; ++nRow) { if (!mpHiddenRows->getRangeData(nRow, aData)) + // Failed to fetch the range data for whatever reason. break; if (aData.mbValue) { + // This row is hidden. Skip ahead all hidden rows. nRow = aData.mnRow2; continue; } @@ -3691,7 +3693,21 @@ SCROW ScTable::GetRowForHeight(sal_uLong nHeight) const nSum += nNew; if (nSum > nHeight) { - return nRow < MAXROW ? nRow + 1 : MAXROW; + if (nRow >= MAXROW) + return MAXROW; + + // Find the next visible row. + ++nRow; + + if (!mpHiddenRows->getRangeData(nRow, aData)) + // Failed to fetch the range data for whatever reason. + break; + + if (aData.mbValue) + // These rows are hidden. + nRow = aData.mnRow2 + 1; + + return nRow <= MAXROW ? nRow : MAXROW; } } return -1; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
