diff options
author | Vasily Melenchuk <Vasily.Melenchuk@cib.de> | 2018-04-06 20:19:10 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-06-08 00:47:06 +0200 |
commit | 1e55a47e89a9d9d6cf9cb3993484022aaf2c097b (patch) | |
tree | 3a3372525645775c32721e59ce8c205c8f474ffd | |
parent | 2a7f74900fb646235b74d4c9bd4690e44edc3ed4 (diff) |
tdf#62268: allow row height recalculation on document load
During document load rows with style:use-optimal-row-height="true"
should recalculate it's height.
Change-Id: Ib38b5b753d9ff8352116d77851d228c5d77bd530
Reviewed-on: https://gerrit.libreoffice.org/52521
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | sc/qa/unit/data/ods/tdf62268.ods | bin | 0 -> 9096 bytes | |||
-rw-r--r-- | sc/qa/unit/helper/qahelper.cxx | 3 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 59 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_filters-test.cxx | 26 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.cxx | 21 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.hxx | 5 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlrowi.cxx | 16 |
7 files changed, 94 insertions, 36 deletions
diff --git a/sc/qa/unit/data/ods/tdf62268.ods b/sc/qa/unit/data/ods/tdf62268.ods Binary files differnew file mode 100644 index 000000000000..da88adfd25cd --- /dev/null +++ b/sc/qa/unit/data/ods/tdf62268.ods diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index 8aa9cc883568..ed660cfa7928 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -754,7 +754,8 @@ void ScBootstrapFixture::miscRowHeightsTest( TestParam const * aTestValues, unsi bool bOpt = !(rDoc.GetRowFlags( nRow, nTab ) & CRFlags::ManualSize); CPPUNIT_ASSERT_EQUAL(aTestValues[ index ].pData[ i ].bOptimal, bOpt); } - CPPUNIT_ASSERT_EQUAL(nExpectedHeight, nHeight); + // Due to some minor differences on Mac this comparison is made bit fuzzy + CPPUNIT_ASSERT_LESSEQUAL( 3, abs( nHeight - nExpectedHeight ) ); } } xShell->DoClose(); diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index bf1813ee7edd..3ff3c4301e3d 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -1026,60 +1026,57 @@ void ScExportTest::testOutlineExportXLSX() // We expected that exactly 13 unique Nodes will be produced assertXPath(pSheet, "/x:worksheet/x:cols/x:col", 13); - // We need to save all 30 rows, as it provides information about outLineLevel - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "r", "1"); + // First row is empty and default so it is not written into XML file + // so we need to save 29 rows, as it provides information about outLineLevel + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "r", "2"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "hidden", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "outlineLevel", "0"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "outlineLevel", "1"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[2]", "r", "2"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[2]", "r", "3"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[2]", "hidden", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[2]", "outlineLevel", "1"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[2]", "outlineLevel", "2"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[2]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[3]", "r", "3"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[3]", "r", "4"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[3]", "hidden", "false"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[3]", "outlineLevel", "2"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[3]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]", "r", "4"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]", "r", "5"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]", "hidden", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]", "outlineLevel", "2"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]", "outlineLevel", "3"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[5]", "r", "5"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[5]", "r", "6"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[5]", "hidden", "false"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[5]", "outlineLevel", "3"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[5]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[6]", "r", "6"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[6]", "hidden", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[6]", "outlineLevel", "3"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[6]", "r", "7"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[6]", "hidden", "true"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[6]", "outlineLevel", "4"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[6]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[7]", "r", "7"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[7]", "r", "8"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[7]", "hidden", "true"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[7]", "outlineLevel", "4"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[7]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[8]", "r", "8"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[8]", "r", "9"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[8]", "hidden", "true"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[8]", "outlineLevel", "4"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[8]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[9]", "r", "9"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[9]", "hidden", "true"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[9]", "outlineLevel", "4"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[9]", "collapsed", "false"); // Next rows are the same as the previous one but it needs to bre preserved, // as they contain information about outlineLevel - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[21]", "r", "21"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[21]", "hidden", "true"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[21]", "outlineLevel", "4"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[21]", "collapsed", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[22]", "r", "22"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[20]", "r", "21"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[20]", "hidden", "true"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[20]", "outlineLevel", "4"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[20]", "collapsed", "false"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[21]", "r", "22"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[21]", "hidden", "false"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[21]", "outlineLevel", "3"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[21]", "collapsed", "true"); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[22]", "r", "23"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[22]", "hidden", "false"); assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[22]", "outlineLevel", "3"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[22]", "collapsed", "true"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[23]", "r", "23"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[23]", "hidden", "false"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[23]", "outlineLevel", "3"); - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[23]", "collapsed", "false"); - - // We expected that exactly 30 Row Nodes will be produced - assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row", 30); + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[22]", "collapsed", "false"); + + // We expected that exactly 29 Row Nodes will be produced + assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row", 29); } void ScExportTest::testAllRowsHiddenXLSX() diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 6aa41875f61c..3252d9143fc8 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -245,6 +245,7 @@ public: void testBorderColorsXLSXML(); void testHiddenRowsColumnsXLSXML(); void testColumnWidthRowHeightXLSXML(); + void testTdf62268(); CPPUNIT_TEST_SUITE(ScFiltersTest); CPPUNIT_TEST(testBooleanFormatXLSX); @@ -376,6 +377,7 @@ public: CPPUNIT_TEST(testHiddenRowsColumnsXLSXML); CPPUNIT_TEST(testColumnWidthRowHeightXLSXML); CPPUNIT_TEST(testCondFormatFormulaListenerXLSX); + CPPUNIT_TEST(testTdf62268); CPPUNIT_TEST_SUITE_END(); @@ -2652,8 +2654,8 @@ void ScFiltersTest::testMiscRowHeights() TestParam::RowData MultiLineOptData[] = { - // Row 0 is 12.63 mm and optimal flag is set - { 0, 0, 0, 1263, CHECK_OPTIMAL, true }, + // Row 0 is 12.63 mm, but optimal flag is set + { 0, 0, 0, 1236, CHECK_OPTIMAL, true }, // Row 1 is 11.99 mm and optimal flag is NOT set { 1, 1, 0, 1199, CHECK_OPTIMAL, false }, }; @@ -2685,8 +2687,9 @@ void ScFiltersTest::testOptimalHeightReset() ScDocument& rDoc = xDocSh->GetDocument(); // open document in read/write mode ( otherwise optimal height stuff won't // be triggered ) *and* you can't delete cell contents. - int nHeight = sc::TwipsToHMM ( rDoc.GetRowHeight(nRow, nTab, false) ); - CPPUNIT_ASSERT_EQUAL(1263, nHeight); + int nHeight = rDoc.GetRowHeight(nRow, nTab, false); + // Due to some minor differences on Mac this comparison is made bit fuzzy + CPPUNIT_ASSERT_LESSEQUAL( 3, abs( nHeight - 701 ) ); ScDocFunc &rFunc = xDocSh->GetDocFunc(); @@ -4059,6 +4062,21 @@ void ScFiltersTest::testCondFormatFormulaListenerXLSX() xDocSh->DoClose(); } +void ScFiltersTest::testTdf62268() +{ + ScDocShellRef xDocSh = loadDoc("tdf62268.", FORMAT_ODS); + ScDocument& rDoc = xDocSh->GetDocument(); + int nHeight; + + SCTAB nTab = 0; + nHeight = rDoc.GetRowHeight(0, nTab, false); + CPPUNIT_ASSERT_EQUAL(256, nHeight); + nHeight = rDoc.GetRowHeight(1, nTab, false); + CPPUNIT_ASSERT_EQUAL(1905, nHeight); + + xDocSh->DoClose(); +} + ScFiltersTest::ScFiltersTest() : ScBootstrapFixture( "sc/qa/unit/data" ) { diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index 86434cd10c0c..902070025fe8 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -76,6 +76,7 @@ #include "pivotsource.hxx" #include <unonames.hxx> #include <numformat.hxx> +#include <sizedev.hxx> #include <comphelper/base64.hxx> #include <comphelper/extract.hxx> @@ -1803,6 +1804,26 @@ void SAL_CALL ScXMLImport::endDocument() pDoc->SetStreamValid( nTab, true ); } } + + // There are rows with optimal height which need to be updated + if (!maRecalcRowRanges.empty()) + { + bool bLockHeight = pDoc->IsAdjustHeightLocked(); + if (bLockHeight) + { + pDoc->UnlockAdjustHeight(); + } + + ScSizeDeviceProvider aProv(static_cast<ScDocShell*>(pDoc->GetDocumentShell())); + ScDocRowHeightUpdater aUpdater(*pDoc, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), &maRecalcRowRanges); + aUpdater.update(); + + if (bLockHeight) + { + pDoc->LockAdjustHeight(); + } + } + aTables.FixupOLEs(); } if (GetModel().is()) diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx index 36dc316787ad..bccf395f798c 100644 --- a/sc/source/filter/xml/xmlimprt.hxx +++ b/sc/source/filter/xml/xmlimprt.hxx @@ -32,6 +32,7 @@ #include <global.hxx> #include <formula/grammar.hxx> #include <compiler.hxx> +#include <dociter.hxx> #include "xmlstyle.hxx" #include <com/sun/star/sheet/ValidationAlertStyle.hpp> @@ -270,6 +271,8 @@ class ScXMLImport: public SvXMLImport ScMyTables aTables; + std::vector<ScDocRowHeightUpdater::TabRanges> maRecalcRowRanges; + std::unique_ptr<ScMyNamedExpressions> m_pMyNamedExpressions; SheetNamedExpMap m_SheetNamedExpressions; @@ -342,6 +345,8 @@ public: ScMyTables& GetTables() { return aTables; } + std::vector<ScDocRowHeightUpdater::TabRanges>& GetRecalcRowRanges() { return maRecalcRowRanges; } + bool IsStylesOnlyMode() const { return !bLoadDoc; } static sal_Int16 GetCellType(const char* rStrValue, const sal_Int32 nStrLength); diff --git a/sc/source/filter/xml/xmlrowi.cxx b/sc/source/filter/xml/xmlrowi.cxx index 7f958d459f4d..3093c33f0a8e 100644 --- a/sc/source/filter/xml/xmlrowi.cxx +++ b/sc/source/filter/xml/xmlrowi.cxx @@ -27,6 +27,7 @@ #include <olinetab.hxx> #include <sheetdata.hxx> #include <documentimport.hxx> +#include <unonames.hxx> #include <xmloff/xmltkmap.hxx> #include <xmloff/nmspmap.hxx> @@ -198,6 +199,21 @@ void SAL_CALL ScXMLTableRowContext::endFastElement(sal_Int32 /*nElement*/) } if (bFiltered) xRowProperties->setPropertyValue(SC_ISFILTERED, uno::makeAny(bFiltered)); + + uno::Any any = xRowProperties->getPropertyValue(SC_UNONAME_OHEIGHT); + bool bOptionalHeight = false; + any >>= bOptionalHeight; + if (bOptionalHeight) + { + // Save this row for later height update + std::vector<ScDocRowHeightUpdater::TabRanges>& rRecalcRanges = rXMLImport.GetRecalcRowRanges(); + while (static_cast<SCTAB>(rRecalcRanges.size()) <= nSheet) + { + rRecalcRanges.emplace_back(0); + } + rRecalcRanges.at(nSheet).mnTab = nSheet; + rRecalcRanges.at(nSheet).mpRanges->setTrue(nFirstRow, nCurrentRow); + } } } } |