diff options
author | Daniel Bankston <daniel.e.bankston@gmail.com> | 2012-07-08 11:26:52 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-07-11 20:37:41 -0400 |
commit | 20f8ade0aed4ce2f923370e148cd2d2b251fc863 (patch) | |
tree | b6847a6d2cbe2db645506cf29ec22cb10497683d /sc | |
parent | e94b1331b1e2139e09bd0ef663394ede80f11be3 (diff) |
Use cached formula results for matrices
Change-Id: Ia77a94184c3d598f16a2f51d996f4c7058d9e303
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/formularesult.cxx | 15 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcelli.cxx | 56 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlsubti.cxx | 69 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlsubti.hxx | 43 |
4 files changed, 68 insertions, 115 deletions
diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx index 96068999aa86..3b94481c4041 100644 --- a/sc/source/core/tool/formularesult.cxx +++ b/sc/source/core/tool/formularesult.cxx @@ -398,11 +398,16 @@ void ScFormulaResult::SetHybridDouble( double f ) ResetToDefaults(); if (mbToken && mpToken) { - String aString( GetString()); - String aFormula( GetHybridFormula()); - mpToken->DecRef(); - mpToken = new ScHybridCellToken( f, aString, aFormula); - mpToken->IncRef(); + if(GetType() == formula::svMatrixCell) + SetDouble(f); + else + { + String aString( GetString()); + String aFormula( GetHybridFormula()); + mpToken->DecRef(); + mpToken = new ScHybridCellToken( f, aString, aFormula); + mpToken->IncRef(); + } } else { diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index 3da5996ca10a..ed4350ad3e81 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -355,8 +355,7 @@ SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPr ScAddress aCellPos = rXMLImport.GetTables().GetCurrentCellPos(); - if( ((nCellType == util::NumberFormat::TEXT) || bFormulaTextResult) && - !rXMLImport.GetTables().IsPartOfMatrix(aCellPos.Col(), aCellPos.Row()) ) + if( ((nCellType == util::NumberFormat::TEXT) || bFormulaTextResult) ) { if (!bHasTextImport) { @@ -746,7 +745,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rCurrentPos, const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText ) { bool bDoIncrement = true; - if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos.Col(), rCurrentPos.Row()) ) + if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos) ) { ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rCurrentPos ); bDoIncrement = ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA ); @@ -761,6 +760,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rCurrentPos, pFCell->SetHybridString( *pOUText ); else bDoIncrement = false; + pFCell->SetFormatType( nCellType ); pFCell->ResetDirty(); } } @@ -789,7 +789,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rCurrentPos, void ScXMLTableRowCellContext::AddNumberCellToDoc( const ScAddress& rCurrentPos ) { - if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos.Col(), rCurrentPos.Row()) ) + if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos) ) { ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rCurrentPos ); if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA ) @@ -996,15 +996,6 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rCellPos ) } } -namespace{ - -bool isErrOrNA(const rtl::OUString& rStr) -{ - return (rStr.indexOf("Err:") > -1) || (rStr.indexOf("#N/A") > -1); -} - -} - void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rCellPos ) { ScDocument* pDoc = rXMLImport.GetDocument(); @@ -1015,10 +1006,6 @@ void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rCellPo ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard; pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc)); - //if this is an "Err:###" or "#N/A" then use text:p value - if( bFormulaTextResult && pOUTextContent && isErrOrNA(*pOUTextContent) ) - pOUTextValue.reset(*pOUTextContent); - ScBaseCell* pNewCell = NULL; if ( !aText.isEmpty() ) @@ -1065,6 +1052,15 @@ void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rCellPo } } +namespace{ + +bool isErrOrNA(const rtl::OUString& rStr) +{ + return (rStr.indexOf("Err:") > -1) || (rStr.indexOf("#N/A") > -1); +} + +} + void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos ) { if( cellExists(rCellPos) ) @@ -1072,9 +1068,13 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos ) SetContentValidation( rCellPos ); OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now"); rXMLImport.GetStylesImportHelper()->AddCell(rCellPos); - if (!bIsMatrix) - AddNonMatrixFormulaCell( rCellPos ); - else + + //if this is an "Err:###" or "#N/A" then use text:p value + if( bFormulaTextResult && pOUTextContent && isErrOrNA(*pOUTextContent) ) + pOUTextValue.reset(*pOUTextContent); + + //add matrix + if(bIsMatrix) { if (nMatrixCols > 0 && nMatrixRows > 0) { @@ -1083,8 +1083,24 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos ) rCellPos.Col() + nMatrixCols - 1, rCellPos.Row() + nMatrixRows - 1, pOUFormula->first, pOUFormula->second, eGrammar); + + //add the cached formula result of the first matrix position + ScFormulaCell* pFCell = + static_cast<ScFormulaCell*>( rXMLImport.GetDocument()->GetCell(rCellPos) ); + if(pFCell) + { + if( bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty() ) + pFCell->SetHybridString( *pOUTextValue ); + else + pFCell->SetHybridDouble( fValue ); + pFCell->SetFormatType( nCellType ); + pFCell->ResetDirty(); + } } } + else + AddNonMatrixFormulaCell( rCellPos ); + SetAnnotation( rCellPos ); SetDetectiveObj( rCellPos ); SetCellRangeSource( rCellPos ); diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx index 7825bbf6ef2b..c5a5eebd5153 100644 --- a/sc/source/filter/xml/xmlsubti.cxx +++ b/sc/source/filter/xml/xmlsubti.cxx @@ -207,18 +207,7 @@ void ScMyTables::DeleteTable() rImport.GetStylesImportHelper()->SetStylesToRanges(); rImport.SetStylesToRangesFinished(); - //#i48793#; has to be set before protection - if (!aMatrixRangeList.empty()) - { - ScMyMatrixRangeList::iterator aItr = aMatrixRangeList.begin(); - ScMyMatrixRangeList::iterator aEndItr = aMatrixRangeList.end(); - while(aItr != aEndItr) - { - SetMatrix(aItr->aScRange, aItr->sFormula, aItr->sFormulaNmsp, aItr->eGrammar); - ++aItr; - } - aMatrixRangeList.clear(); - } + maMatrixRangeList.RemoveAll(); if (rImport.GetDocument() && maProtectionData.mbProtected) { @@ -294,62 +283,30 @@ void ScMyTables::AddMatrixRange( nStartColumn, nStartRow, maCurrentCellPos.Tab(), nEndColumn, nEndRow, maCurrentCellPos.Tab() ); - ScMatrixRange aMRange(aScRange, rFormula, rFormulaNmsp, eGrammar); - aMatrixRangeList.push_back(aMRange); -} -bool ScMyTables::IsPartOfMatrix(const SCCOL nColumn, const SCROW nRow) -{ - bool bResult(false); - if (!aMatrixRangeList.empty()) - { - ScMyMatrixRangeList::iterator aItr(aMatrixRangeList.begin()); - ScMyMatrixRangeList::iterator aEndItr(aMatrixRangeList.end()); - bool bReady(false); - while(!bReady && aItr != aEndItr) - { - if (maCurrentCellPos.Tab() > aItr->aScRange.aStart.Tab()) - { - OSL_FAIL("should never hapen, because the list should be cleared in DeleteTable"); - aItr = aMatrixRangeList.erase(aItr); - } - else if ((nRow > aItr->aScRange.aEnd.Row()) && (nColumn > aItr->aScRange.aEnd.Col())) - { - SetMatrix(aItr->aScRange, aItr->sFormula, aItr->sFormulaNmsp, aItr->eGrammar); - aItr = aMatrixRangeList.erase(aItr); - } - else if (nColumn < aItr->aScRange.aStart.Col()) - bReady = true; - else if ( nColumn >= aItr->aScRange.aStart.Col() && nColumn <= aItr->aScRange.aEnd.Col() && - nRow >= aItr->aScRange.aStart.Row() && nRow <= aItr->aScRange.aEnd.Row() ) - { - bReady = true; - bResult = true; - } - else - ++aItr; - } - } - return bResult; -} + maMatrixRangeList.Append(aScRange); -void ScMyTables::SetMatrix(const ScRange& rScRange, const rtl::OUString& rFormula, - const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar) -{ ScDocument* pDoc = rImport.GetDocument(); ScMarkData aMark; - aMark.SetMarkArea( rScRange ); - aMark.SelectTable( rScRange.aStart.Tab(), sal_True ); + aMark.SetMarkArea( aScRange ); + aMark.SelectTable( aScRange.aStart.Tab(), sal_True ); ScTokenArray* pCode = new ScTokenArray; pCode->AddStringXML( rFormula ); if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !rFormulaNmsp.isEmpty() ) pCode->AddStringXML( rFormulaNmsp ); pDoc->InsertMatrixFormula( - rScRange.aStart.Col(), rScRange.aStart.Row(), - rScRange.aEnd.Col(), rScRange.aEnd.Row(), + aScRange.aStart.Col(), aScRange.aStart.Row(), + aScRange.aEnd.Col(), aScRange.aEnd.Row(), aMark, EMPTY_STRING, pCode, eGrammar ); delete pCode; pDoc->IncXMLImportedFormulaCount( rFormula.getLength() ); } +bool ScMyTables::IsPartOfMatrix(const ScAddress& rScAddress) const +{ + if (!maMatrixRangeList.empty()) + return maMatrixRangeList.In(rScAddress); + return false; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/xmlsubti.hxx b/sc/source/filter/xml/xmlsubti.hxx index 3f98af9d95f2..e080cfd7cfd3 100644 --- a/sc/source/filter/xml/xmlsubti.hxx +++ b/sc/source/filter/xml/xmlsubti.hxx @@ -40,28 +40,10 @@ #include "XMLTableShapeResizer.hxx" #include "formula/grammar.hxx" #include "tabprotection.hxx" - -#include <vector> -#include <list> -#include <boost/ptr_container/ptr_vector.hpp> +#include "rangelst.hxx" class ScXMLImport; -struct ScMatrixRange -{ - rtl::OUString sFormula; - rtl::OUString sFormulaNmsp; - formula::FormulaGrammar::Grammar eGrammar; - ScRange aScRange; - ScMatrixRange(const ScRange& rScRange, const rtl::OUString& rFormula, const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammarP) : - sFormula(rFormula), - sFormulaNmsp(rFormulaNmsp), - eGrammar(eGrammarP), - aScRange(rScRange) - { - } -}; - struct ScXMLTabProtectionData { ::rtl::OUString maPassword; @@ -77,8 +59,6 @@ struct ScXMLTabProtectionData class ScMyTables { private: - typedef std::list<ScMatrixRange> ScMyMatrixRangeList; - ScXMLImport& rImport; ScMyOLEFixer aFixupOLEs; @@ -89,8 +69,8 @@ private: ::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShapes > xShapes; rtl::OUString sCurrentSheetName; ScAddress maCurrentCellPos; + ScRangeList maMatrixRangeList; ScXMLTabProtectionData maProtectionData; - ScMyMatrixRangeList aMatrixRangeList; sal_Int32 nCurrentColStylePos; sal_Int16 nCurrentDrawPage; sal_Int16 nCurrentXShapes; @@ -132,18 +112,13 @@ public: const rtl::OUString &rRangeList); void AddMatrixRange( const SCCOL nStartColumn, - const SCROW nStartRow, - const SCCOL nEndColumn, - const SCROW nEndRow, - const rtl::OUString& rFormula, - const rtl::OUString& rFormulaNmsp, - const formula::FormulaGrammar::Grammar ); - - bool IsPartOfMatrix( const SCCOL nColumn, const SCROW nRow); - void SetMatrix( const ScRange& rScRange, - const rtl::OUString& rFormula, - const rtl::OUString& rFormulaNmsp, - const formula::FormulaGrammar::Grammar ); + const SCROW nStartRow, + const SCCOL nEndColumn, + const SCROW nEndRow, + const rtl::OUString& rFormula, + const rtl::OUString& rFormulaNmsp, + const formula::FormulaGrammar::Grammar ); + bool IsPartOfMatrix( const ScAddress& rScAddress) const; }; #endif |