sc/inc/document.hxx | 3 + sc/qa/unit/subsequent_filters-test.cxx | 61 +++++++++++++-------------------- sc/source/core/data/cell.cxx | 3 + sc/source/core/data/documen2.cxx | 1 sc/source/filter/xml/xmlcelli.cxx | 17 +++++++-- sc/source/filter/xml/xmlimprt.cxx | 12 ++++-- sc/source/ui/docshell/docsh.cxx | 2 - 7 files changed, 54 insertions(+), 45 deletions(-)
New commits: commit 7a0fba0b0225f59f8c38b245cb21b81750271e26 Author: Daniel Bankston <[email protected]> Date: Tue Jul 3 03:06:29 2012 -0500 Use imported formula results if ODS doc was generated by LibreOffice During ODS import, use imported formula results instead of recalculating if the document was generated by LibreOffice. Still need to implement recalculating special cases such as NOW(). Change-Id: Ia54690224dc0d8f74b93cafd8d01b072e85c7416 diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index b4df35b..7559a4e 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -371,6 +371,7 @@ private: bool bInsertingFromOtherDoc; bool bLoadingMedium; bool bImportingXML; // special handling of formula text + bool bImportingLiboGenDoc; //to avoid recalculating formula results of libo generated docs bool bXMLFromWrapper; // distinguish ScXMLImportWrapper from external component bool bCalcingAfterLoad; // in CalcAfterLoad TRUE // don't construct/destruct listeners temporarily @@ -1563,6 +1564,8 @@ public: void SetLoadingMedium( bool bVal ); void SetImportingXML( bool bVal ); bool IsImportingXML() const { return bImportingXML; } + void SetImportingLiboGenDoc( bool bVal ) { bImportingLiboGenDoc = bVal; }; + bool IsImportingLiboGenDoc() const { return bImportingLiboGenDoc; } void SetXMLFromWrapper( bool bVal ); bool IsXMLFromWrapper() const { return bXMLFromWrapper; } void SetCalcingAfterLoad( bool bVal ) { bCalcingAfterLoad = bVal; } diff --git a/sc/source/core/data/cell.cxx b/sc/source/core/data/cell.cxx index 338b0ab..4d12292 100644 --- a/sc/source/core/data/cell.cxx +++ b/sc/source/core/data/cell.cxx @@ -1830,7 +1830,8 @@ void ScFormulaCell::SetDirty() void ScFormulaCell::SetDirtyVar() { - bDirty = true; + if(!pDocument->IsImportingLiboGenDoc()) + bDirty = true; // mark the sheet of this cell to be calculated //#FIXME do we need to revert this remnant of old fake vba events? pDocument->AddCalculateTable( aPos.Tab() ); } diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index 2419859..0921f20 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -188,6 +188,7 @@ ScDocument::ScDocument( ScDocumentMode eMode, bInsertingFromOtherDoc( false ), bLoadingMedium( false ), bImportingXML( false ), + bImportingLiboGenDoc( false ), bXMLFromWrapper( false ), bCalcingAfterLoad( false ), bNoListening( false ), diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index 1457033..fac8481 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -757,6 +757,8 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rCurrentPos, pFCell->SetHybridString( *pOUText ); else bDoIncrement = false; + if(rXMLImport.GetDocument()->IsImportingLiboGenDoc()) + pFCell->ResetDirty(); } } else @@ -788,7 +790,12 @@ void ScXMLTableRowCellContext::AddNumberCellToDoc( const ScAddress& rCurrentPos { ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rCurrentPos ); if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA ) - static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue ); + { + ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell); + pFCell->SetHybridDouble( fValue ); + if(rXMLImport.GetDocument()->IsImportingLiboGenDoc()) + pFCell->ResetDirty(); + } } else { @@ -1013,10 +1020,13 @@ void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rCellPo pNewCell = new ScFormulaCell( pDoc, rCellPos, pCode, eGrammar, MM_NONE ); delete pCode; + ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pNewCell); if( bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty() ) - static_cast<ScFormulaCell*>(pNewCell)->SetHybridString( *pOUTextValue ); + pFCell->SetHybridString( *pOUTextValue ); else - static_cast<ScFormulaCell*>(pNewCell)->SetHybridDouble( fValue ); + pFCell->SetHybridDouble( fValue ); + if(pDoc->IsImportingLiboGenDoc()) + pFCell->ResetDirty(); } else if ( aText[0] == '\'' && aText.getLength() > 1 ) { @@ -1036,7 +1046,6 @@ void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rCellPo else pNewCell = ScBaseCell::CreateTextCell( aText, pDoc ); } - pDoc->PutCell( rCellPos, pNewCell ); } } diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index 093c3bc..4b4b605 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -99,6 +99,7 @@ #define SC_REPEAT_ROW "repeat-row" #define SC_FILTER "filter" #define SC_PRINT_RANGE "print-range" +#define SC_LIBO_PROD_NAME "LibreOffice" using namespace com::sun::star; using namespace ::xmloff::token; @@ -2807,7 +2808,14 @@ throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::R uno::Reference<document::XActionLockable> xActionLockable(xDoc, uno::UNO_QUERY); if (xActionLockable.is()) xActionLockable->addActionLock(); + pDoc->EnableAdjustHeight(false); + + uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), uno::UNO_QUERY_THROW); + uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties(); + rtl::OUString sGenerator(xDocProps->getGenerator()); + if(sGenerator.match(SC_LIBO_PROD_NAME)) + pDoc->SetImportingLiboGenDoc(true); } // XServiceInfo @@ -3111,10 +3119,8 @@ throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeE } SvXMLImport::endDocument(); - if (pDoc && bSelfImportingXMLSet) - { + if(pDoc && bSelfImportingXMLSet) ScModelObj::getImplementation(GetModel())->AfterXMLLoading(true); - } } // XEventListener diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index e70cf2d..8b96ca6 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -445,7 +445,7 @@ sal_Bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::un aDocument.SetXMLFromWrapper( false ); AfterXMLLoading(bRet); - + aDocument.SetImportingLiboGenDoc(false); //! row heights... return bRet; commit 783baa016375c79a7cc95257813a90d42dfe7f4c Author: Daniel Bankston <[email protected]> Date: Mon Jul 2 13:36:36 2012 -0500 Improve performance of data validity unit test - Now using OStringBuffer instead of OString for multiple appends. - Simplified logic. Change-Id: I991c3e538439d68e242a7f97bab9c2d82631467e diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 1f29ae7..987c6e0 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -804,31 +804,24 @@ void checkValiditationEntries( const ValDataTestParams& rVDTParams ) //get actual data validation entry from document const ScValidationData* pValDataTest = pDoc->GetValidationEntry( rVDTParams.nExpectedIndex ); - rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Col())) ); - rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Row())) ); - rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Tab())) ); - rtl::OString msg( "Data Validation Entry with base-cell-address: (" + - sCol + "," + sRow + "," + sTab + ") was not imported correctly." ); + sal_Int32 nCol( static_cast<sal_Int32>(rVDTParams.aPosition.Col()) ); + sal_Int32 nRow( static_cast<sal_Int32>(rVDTParams.aPosition.Row()) ); + sal_Int32 nTab( static_cast<sal_Int32>(rVDTParams.aPosition.Tab()) ); + rtl::OStringBuffer sMsg("Data Validation Entry with base-cell-address: ("); + sMsg.append(nCol).append(",").append(nRow).append(",").append(nTab).append(") was not imported correctly."); //check if expected and actual data validation entries are equal - CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && aValData.EqualEntries(*pValDataTest) ); + CPPUNIT_ASSERT_MESSAGE( sMsg.getStr(), pValDataTest && aValData.EqualEntries(*pValDataTest) ); } -bool checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc, rtl::OString& sMsg ) +void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc ) { SCCOL nBCol( rValBaseAddr.Col() ); - SCTAB nBRow( rValBaseAddr.Row() ); - SCTAB nTab( rValBaseAddr.Tab() ); + SCROW nBRow( rValBaseAddr.Row() ); + SCTAB nTab( static_cast<const sal_Int32>(rValBaseAddr.Tab()) ); //get from the document the data validation entry we are checking against const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pDoc->GetAttr(nBCol, nBRow, nTab, ATTR_VALIDDATA) ); const ScValidationData* pValData = pDoc->GetValidationEntry( pItem->GetValue() ); - rtl::OString sCol, sRow; - rtl::OString sBCol = rtl::OString::valueOf(static_cast<sal_Int32>(nBCol)); - rtl::OString sBRow = rtl::OString::valueOf(static_cast<sal_Int32>(nBRow)); - rtl::OString sTab = rtl::OString::valueOf(static_cast<sal_Int32>(nTab)); - sMsg += "\nThe following cells failed to reference the data validation entry with base-cell-address: (" + - sBCol + "," + sBRow + "," + sTab + ")\n"; - bool bPassed = true; //check that each cell in the expected range is associated with the data validation entry for(SCCOL i = rRange.aStart.Col(); i <= rRange.aEnd.Col(); ++i) { @@ -836,27 +829,25 @@ bool checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, co { const SfxUInt32Item* pItemTest = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(i, j, nTab, ATTR_VALIDDATA) ); const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItemTest->GetValue() ); - - sCol = rtl::OString::valueOf(static_cast<sal_Int32>(i)); - sRow = rtl::OString::valueOf(static_cast<sal_Int32>(j)); + //prevent string operations for occurring unnecessarily if(!(pValDataTest && pValData->GetKey() == pValDataTest->GetKey())) { - bPassed = false; - rtl::OString sEntryKey = rtl::OString::valueOf(static_cast<sal_Int32>(pValData->GetKey())); - sMsg += "(" + sCol + "," + sRow + "," + sTab + "), expected key: " + sEntryKey + ", actual key: "; + sal_Int32 nCol = static_cast<const sal_Int32>(i); + sal_Int32 nRow = static_cast<const sal_Int32>(j); + sal_Int32 nTab32 = static_cast<const sal_Int32>(nTab); + rtl::OStringBuffer sMsg("\nData validation entry base-cell-address: ("); + sMsg.append( static_cast<const sal_Int32>(nBCol) ).append(","); + sMsg.append( static_cast<const sal_Int32>(nBRow) ).append(","); + sMsg.append( nTab32 ).append(")\n"); + sMsg.append("Cell: (").append(nCol).append(",").append(nRow).append(",").append(nTab32).append(")"); + sal_uInt32 expectedKey(pValData->GetKey()); + sal_uInt32 actualKey(-1); if(pValDataTest) - { - rtl::OString sTestKey = rtl::OString::valueOf(static_cast<sal_Int32>(pValDataTest->GetKey())); - sMsg += sTestKey; - } - else sMsg += "none"; - sMsg += "\n"; + actualKey = pValDataTest->GetKey(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMsg.getStr(), expectedKey, actualKey); } } } - if(bPassed) sMsg += "None failed.\n"; - sMsg += "\n"; - return bPassed; } } @@ -881,7 +872,7 @@ void ScFiltersTest::testDataValidityODS() //sheet2's expected Data Validation Entry values ValDataTestParams aVDTParams2( SC_VALID_WHOLE, SC_COND_BETWEEN, String("1"), String("10"), pDoc, - ScAddress(2,3,1), String("Error sheet 2"), + aValBaseAddr2, String("Error sheet 2"), String("Must be a whole number between 1 and 10."), SC_VALERR_STOP, 2 ); @@ -894,10 +885,8 @@ void ScFiltersTest::testDataValidityODS() ScRange aRange2( 2,3,1, 6,7,1 ); //sheet2 //check each sheet's cells for data validity - rtl::OString sMsg; - bool bPassed1 = checkCellValidity( aValBaseAddr1, aRange1, pDoc, sMsg ); - bool bPassed2 = checkCellValidity( aValBaseAddr2, aRange2, pDoc, sMsg ); - CPPUNIT_ASSERT_MESSAGE( sMsg.pData->buffer, bPassed1 && bPassed2 ); + checkCellValidity( aValBaseAddr1, aRange1, pDoc ); + checkCellValidity( aValBaseAddr2, aRange2, pDoc ); //check each sheet's content rtl::OUString aCSVFileName1; _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
