diff options
Diffstat (limited to 'sc/source/core/data')
-rw-r--r-- | sc/source/core/data/colorscale.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/documen2.cxx | 1 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 9 | ||||
-rw-r--r-- | sc/source/core/data/documentimport.cxx | 22 | ||||
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 11 | ||||
-rw-r--r-- | sc/source/core/data/dptabres.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/mtvelements.cxx | 5 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 17 | ||||
-rw-r--r-- | sc/source/core/data/table3.cxx | 4 |
10 files changed, 83 insertions, 10 deletions
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index 4ea3606e48b8..a257fae0a87d 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -484,8 +484,10 @@ Color CalcColor( double nVal, double nVal1, const Color& rCol1, double nVal2, co double GetPercentile( const std::vector<double>& rArray, double fPercentile ) { size_t nSize = rArray.size(); - size_t nIndex = static_cast<size_t>(::rtl::math::approxFloor( fPercentile * (nSize-1))); - double fDiff = fPercentile * (nSize-1) - ::rtl::math::approxFloor( fPercentile * (nSize-1)); + double fFloor = ::rtl::math::approxFloor(fPercentile * (nSize-1)); + SAL_WARN_IF(fFloor < 0, "sc", "negative percentile"); + size_t nIndex = fFloor >= 0 ? static_cast<size_t>(fFloor) : 0; + double fDiff = fPercentile * (nSize-1) - fFloor; std::vector<double>::const_iterator iter = rArray.begin() + nIndex; if (fDiff == 0.0) return *iter; diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index 88c9b972c912..a810494b056c 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -221,6 +221,7 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) : mbUseEmbedFonts(false), mbTrackFormulasPending(false), mbFinalTrackFormulas(false), + mbLayoutStrings(false), mnMutationGuardFlags(0) { SetStorageGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 06a1a532e628..ea10ba0913f3 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -6448,7 +6448,7 @@ ScPostIt* ScDocument::GetNote(const ScAddress& rPos) ScPostIt* ScDocument::GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size())) - return maTabs[nTab]->aCol[nCol].GetCellNote(nRow); + return maTabs[nTab]->GetNote(nCol, nRow); else return nullptr; @@ -6461,7 +6461,8 @@ void ScDocument::SetNote(const ScAddress& rPos, ScPostIt* pNote) void ScDocument::SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, ScPostIt* pNote) { - return maTabs[nTab]->aCol[nCol].SetCellNote(nRow, pNote); + if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size())) + maTabs[nTab]->SetNote(nCol, nRow, std::move(pNote)); } bool ScDocument::HasNote(const ScAddress& rPos) const @@ -6491,6 +6492,9 @@ bool ScDocument::HasColNotes(SCCOL nCol, SCTAB nTab) const if (!pTab) return false; + if (nCol >= MAXCOLCOUNT) + return false; + return pTab->aCol[nCol].HasCellNotes(); } @@ -6534,6 +6538,7 @@ ScPostIt* ScDocument::GetOrCreateNote(const ScAddress& rPos) else return CreateNote(rPos); } + ScPostIt* ScDocument::CreateNote(const ScAddress& rPos) { ScPostIt* pPostIt = new ScPostIt(*this, rPos); diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx index a7a3ba8e0326..04aa11c9b4b7 100644 --- a/sc/source/core/data/documentimport.cxx +++ b/sc/source/core/data/documentimport.cxx @@ -93,6 +93,15 @@ struct ScDocumentImportImpl return rTab.getBlockPosition(nCol); } + void invalidateBlockPositionSet(SCTAB nTab) + { + if (sal_uInt16(nTab) >= maBlockPosSet.size()) + return; + + sc::TableColumnBlockPositionSet& rTab = maBlockPosSet[nTab]; + rTab.invalidate(); + } + void initForSheets() { size_t n = mrDoc.GetTableCount(); @@ -180,6 +189,11 @@ void ScDocumentImport::setOriginDate(sal_uInt16 nYear, sal_uInt16 nMonth, sal_uI mpImpl->mrDoc.pDocOptions->SetDate(nDay, nMonth, nYear); } +void ScDocumentImport::invalidateBlockPositionSet(SCTAB nTab) +{ + mpImpl->invalidateBlockPositionSet(nTab); +} + void ScDocumentImport::setAutoInput(const ScAddress& rPos, const OUString& rStr, const ScSetStringParam* pStringParam) { ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab()); @@ -367,6 +381,14 @@ void ScDocumentImport::setFormulaCell(const ScAddress& rPos, ScFormulaCell* pCel mpImpl->mrDoc.CheckLinkFormulaNeedingCheck( *pCell->GetCode()); sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells; + + sc::CellStoreType::position_type aPos = rCells.position(rPos.Row()); + if (aPos.first != rCells.end() && aPos.first->type == sc::element_type_formula) + { + ScFormulaCell* p = sc::formula_block::at(*aPos.first->data, aPos.second); + sc::SharedFormulaUtil::unshareFormulaCell(aPos, *p); + } + pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), pCell); } diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index cb733d25a8da..22d1941f1eb0 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -1038,7 +1038,16 @@ bool ScDPObject::GetMembers( sal_Int32 nDim, sal_Int32 nHier, vector<ScDPLabelDa for (sal_Int32 i = 0; i < nCount; ++i) { - Reference<container::XNamed> xMember(xMembersIA->getByIndex(i), UNO_QUERY); + Reference<container::XNamed> xMember; + try + { + xMember = Reference<container::XNamed>(xMembersIA->getByIndex(i), UNO_QUERY); + } + catch (const container::NoSuchElementException&) + { + //TOOLS_WARN_EXCEPTION("sc", "ScNameToIndexAccess getByIndex failed"); + } + ScDPLabelData::Member aMem; if (xMember.is()) diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx index 38107b70e09f..d3e0d108f38a 100644 --- a/sc/source/core/data/dptabres.cxx +++ b/sc/source/core/data/dptabres.cxx @@ -2769,7 +2769,10 @@ ScDPResultDimension::~ScDPResultDimension() ScDPResultMember *ScDPResultDimension::FindMember( SCROW iData ) const { if( bIsDataLayout ) - return maMemberArray[0].get(); + { + SAL_WARN_IF(maMemberArray.empty(), "sc.core", "MemberArray is empty"); + return !maMemberArray.empty() ? maMemberArray[0].get() : nullptr; + } MemberHash::const_iterator aRes = maMemberHash.find( iData ); if( aRes != maMemberHash.end()) { @@ -2976,8 +2979,11 @@ void ScDPResultDimension::LateInitFrom( long ScDPResultDimension::GetSize(long nMeasure) const { - long nTotal = 0; long nMemberCount = maMemberArray.size(); + if (!nMemberCount) + return 0; + + long nTotal = 0; if (bIsDataLayout) { OSL_ENSURE(nMeasure == SC_DPMEASURE_ALL || pResultData->GetMeasureCount() == 1, @@ -3130,7 +3136,7 @@ void ScDPResultDimension::SortMembers( ScDPResultMember* pRefMember ) // handle children // for data layout, call only once - sorting measure is always taken from settings - long nLoopCount = bIsDataLayout ? 1 : nCount; + long nLoopCount = bIsDataLayout ? std::min<long>(1, nCount) : nCount; for (long i=0; i<nLoopCount; i++) { ScDPResultMember* pMember = maMemberArray[i].get(); diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index b43e908352ed..77b6746a7fcb 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -939,6 +939,9 @@ ScFormulaCell::~ScFormulaCell() if (!mxGroup || !mxGroup->mpCode) // Formula token is not shared. delete pCode; + + if (mxGroup && mxGroup->mpTopCell == this) + mxGroup->mpTopCell = nullptr; } ScFormulaCell* ScFormulaCell::Clone() const @@ -2010,7 +2013,8 @@ void ScFormulaCell::InterpretTail( ScInterpreterContext& rContext, ScInterpretTa // XXX if mbNeedsNumberFormat was set even if the current format // was not General then we'd have to obtain the current format here // and check at least the types. - if (bSetFormat && (bForceNumberFormat || ((nFormatIndex % SV_COUNTRY_LANGUAGE_OFFSET) != 0))) + const bool bSetNumberFormat = bSetFormat && (bForceNumberFormat || ((nFormatIndex % SV_COUNTRY_LANGUAGE_OFFSET) != 0)); + if (bSetNumberFormat && !pDocument->IsInLayoutStrings()) { // set number format explicitly if (!pDocument->IsThreadedGroupCalcInProgress()) diff --git a/sc/source/core/data/mtvelements.cxx b/sc/source/core/data/mtvelements.cxx index e34010af54d8..598b43f963f3 100644 --- a/sc/source/core/data/mtvelements.cxx +++ b/sc/source/core/data/mtvelements.cxx @@ -153,6 +153,11 @@ ColumnBlockPosition* TableColumnBlockPositionSet::getBlockPosition( SCCOL nCol ) return &it->second; } +void TableColumnBlockPositionSet::invalidate() +{ + mpImpl->maColumns.clear(); +} + ScRefCellValue toRefCell( const sc::CellStoreType::const_iterator& itPos, size_t nOffset ) { switch (itPos->type) diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index e640b31622f4..66c072d12cc0 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1600,6 +1600,21 @@ ScPostIt* ScTable::ReleaseNote( SCCOL nCol, SCROW nRow ) return aCol[nCol].ReleaseNote(nRow); } +ScPostIt* ScTable::GetNote( SCCOL nCol, SCROW nRow ) +{ + if (!ValidCol(nCol) || nCol >= MAXCOLCOUNT) + return nullptr; + return aCol[nCol].GetCellNote(nRow); +} + +void ScTable::SetNote( SCCOL nCol, SCROW nRow, ScPostIt* pNote ) +{ + if (!ValidColRow(nCol, nRow)) + return; + + CreateColumnIfNotExists(nCol).SetCellNote(nRow, std::move(pNote)); +} + size_t ScTable::GetNoteCount( SCCOL nCol ) const { if (!ValidCol(nCol)) @@ -3714,7 +3729,7 @@ void ScTable::CopyData( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW n if (bThisTab) { - aCell.release(aCol[nDestX], nDestY); + aCell.release(CreateColumnIfNotExists(nDestX), nDestY); SetPattern( nDestX, nDestY, *GetPattern( nCol, nRow ) ); } else diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 487e7eec6626..0b78cd9c31f4 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -3145,6 +3145,10 @@ SCSIZE ScTable::Query(const ScQueryParam& rParamOrg, bool bKeepSub) if (bResult) { CopyData( aParam.nCol1,j, aParam.nCol2,j, aParam.nDestCol,nOutRow,aParam.nDestTab ); +#if 0 + if( nTab == aParam.nDestTab ) // copy to self, changes may invalidate caching position hints + blockPos.invalidate(); +#endif ++nOutRow; } } |