diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-23 15:57:41 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-28 08:39:21 +0200 |
commit | b2e8bbeafa35c15d168961de711e4970eb0985cb (patch) | |
tree | 1d8259893caa4ff0c74a0e271c641c4f326ea8e2 /sc/source | |
parent | c4170e4bcba61865425d03a1292b9aea39dc1e6d (diff) |
loplugin:useuniqueptr in ScColumn
Change-Id: Iff6c68a29b9e7660132cbe4e556802b0f63706f0
Reviewed-on: https://gerrit.libreoffice.org/51904
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/data/documen3.cxx | 14 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/table1.cxx | 68 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 44 | ||||
-rw-r--r-- | sc/source/core/data/table5.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/table6.cxx | 5 | ||||
-rw-r--r-- | sc/source/filter/excel/excimp8.cxx | 2 | ||||
-rw-r--r-- | sc/source/filter/excel/impop.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/oox/workbookhelper.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/xml/xmldrani.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/docshell/dbdocfun.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 12 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh5.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/docfunc.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/undo/undocell.cxx | 10 | ||||
-rw-r--r-- | sc/source/ui/undo/undotab.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/undo/undoutil.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/unoobj/cellsuno.cxx | 19 | ||||
-rw-r--r-- | sc/source/ui/unoobj/eventuno.cxx | 10 | ||||
-rw-r--r-- | sc/source/ui/unoobj/nameuno.cxx | 14 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 8 |
21 files changed, 118 insertions, 136 deletions
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 4dc59a8127e7..5ef81ccde30e 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -114,7 +114,7 @@ void ScDocument::GetAllTabRangeNames(ScRangeName::TabNameCopyMap& rNames) const // no more tables to iterate through. break; - const ScRangeName* p = maTabs[i]->mpRangeName; + const ScRangeName* p = maTabs[i]->mpRangeName.get(); if (!p || p->empty()) // ignore empty ones. continue; @@ -145,7 +145,7 @@ void ScDocument::SetAllRangeNames(const std::map<OUString, std::unique_ptr<ScRan if (pName->empty()) SetRangeName( nTab, nullptr ); else - SetRangeName( nTab, new ScRangeName( *pName ) ); + SetRangeName( nTab, std::unique_ptr<ScRangeName>(new ScRangeName( *pName )) ); } } } @@ -160,7 +160,7 @@ void ScDocument::GetRangeNameMap(std::map<OUString, ScRangeName*>& aRangeNameMap if (!p ) { p = new ScRangeName(); - SetRangeName(i, p); + SetRangeName(i, std::unique_ptr<ScRangeName>(p)); } OUString aTableName; maTabs[i]->GetName(aTableName); @@ -189,12 +189,12 @@ ScRangeName* ScDocument::GetRangeName() const return pRangeName.get(); } -void ScDocument::SetRangeName(SCTAB nTab, ScRangeName* pNew) +void ScDocument::SetRangeName(SCTAB nTab, std::unique_ptr<ScRangeName> pNew) { if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab]) return; - return maTabs[nTab]->SetRangeName(pNew); + return maTabs[nTab]->SetRangeName(std::move(pNew)); } void ScDocument::SetRangeName( std::unique_ptr<ScRangeName> pNewRangeName ) @@ -654,10 +654,10 @@ const ScSheetEvents* ScDocument::GetSheetEvents( SCTAB nTab ) const return nullptr; } -void ScDocument::SetSheetEvents( SCTAB nTab, const ScSheetEvents* pNew ) +void ScDocument::SetSheetEvents( SCTAB nTab, std::unique_ptr<ScSheetEvents> pNew ) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->SetSheetEvents( pNew ); + maTabs[nTab]->SetSheetEvents( std::move(pNew) ); } bool ScDocument::HasSheetEventScript( SCTAB nTab, ScSheetEventId nEvent, bool bWithVbaEvents ) const diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index f9de8433ed13..878887211ccb 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -313,10 +313,10 @@ SCTAB ScDocument::GetTableCount() const return static_cast<SCTAB>(maTabs.size()); } -void ScDocument::SetAnonymousDBData(SCTAB nTab, ScDBData* pDBData) +void ScDocument::SetAnonymousDBData(SCTAB nTab, std::unique_ptr<ScDBData> pDBData) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->SetAnonymousDBData(pDBData); + maTabs[nTab]->SetAnonymousDBData(std::move(pDBData)); } void ScDocument::SetAnonymousDBData( std::unique_ptr<ScDBData> pDBData ) @@ -6256,16 +6256,16 @@ void ScDocument::SetPrintEntireSheet( SCTAB nTab ) maTabs[nTab]->SetPrintEntireSheet(); } -void ScDocument::SetRepeatColRange( SCTAB nTab, const ScRange* pNew ) +void ScDocument::SetRepeatColRange( SCTAB nTab, std::unique_ptr<ScRange> pNew ) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->SetRepeatColRange( pNew ); + maTabs[nTab]->SetRepeatColRange( std::move(pNew) ); } -void ScDocument::SetRepeatRowRange( SCTAB nTab, const ScRange* pNew ) +void ScDocument::SetRepeatRowRange( SCTAB nTab, std::unique_ptr<ScRange> pNew ) { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) - maTabs[nTab]->SetRepeatRowRange( pNew ); + maTabs[nTab]->SetRepeatRowRange( std::move(pNew) ); } ScPrintRangeSaver* ScDocument::CreatePrintRangeSaver() const diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 3cb2301f2cc1..17f3b037166d 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -296,7 +296,7 @@ ScTable::ScTable( ScDocument* pDoc, SCTAB nNewTab, const OUString& rNewName, if (bRowInfo) { mpRowHeights.reset(new ScFlatUInt16RowSegments(ScGlobal::nStdRowHeight)); - pRowFlags = new ScBitMaskCompressedArray<SCROW, CRFlags>( MAXROW, CRFlags::NONE); + pRowFlags.reset(new ScBitMaskCompressedArray<SCROW, CRFlags>( MAXROW, CRFlags::NONE)); } if ( pDocument->IsDocVisible() ) @@ -339,15 +339,15 @@ ScTable::~ScTable() COVERITY_NOEXCEPT_FALSE pDrawLayer->ScRemovePage( nTab ); } - delete pRowFlags; - delete pSheetEvents; - delete pOutlineTable; - delete pSearchText; - delete pRepeatColRange; - delete pRepeatRowRange; - delete pScenarioRanges; - delete mpRangeName; - delete pDBDataNoName; + pRowFlags.reset(); + pSheetEvents.reset(); + pOutlineTable.reset(); + pSearchText.reset(); + pRepeatColRange.reset(); + pRepeatRowRange.reset(); + pScenarioRanges.reset(); + mpRangeName.reset(); + pDBDataNoName.reset(); DestroySortCollator(); } @@ -488,7 +488,7 @@ bool ScTable::SetOptimalHeight( rCxt.getHeightArray().enableTreeSearch(true); SetRowHeightRangeFunc aFunc(this, rCxt.getPPTY()); - bool bChanged = SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags, nStartRow, nEndRow); + bool bChanged = SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow); if ( pProgress != pOuterProgress ) delete pProgress; @@ -515,7 +515,7 @@ void ScTable::SetOptimalHeightOnly( SetRowHeightOnlyFunc aFunc(this); rCxt.getHeightArray().enableTreeSearch(true); - SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags, nStartRow, nEndRow); + SetOptimalHeightsToRows(rCxt, aFunc, pRowFlags.get(), nStartRow, nEndRow); if ( pProgress != pOuterProgress ) delete pProgress; @@ -2005,19 +2005,6 @@ public: } }; -void setPrintRange(ScRange*& pRange1, const ScRange* pRange2) -{ - if (pRange2) - { - if (pRange1) - *pRange1 = *pRange2; - else - pRange1 = new ScRange(*pRange2); - } - else - DELETEZ(pRange1); -} - } void ScTable::CopyPrintRange(const ScTable& rTable) @@ -2030,37 +2017,35 @@ void ScTable::CopyPrintRange(const ScTable& rTable) bPrintEntireSheet = rTable.bPrintEntireSheet; - delete pRepeatColRange; - pRepeatColRange = nullptr; + pRepeatColRange.reset(); if (rTable.pRepeatColRange) { - pRepeatColRange = new ScRange(*rTable.pRepeatColRange); + pRepeatColRange.reset(new ScRange(*rTable.pRepeatColRange)); pRepeatColRange->aStart.SetTab(nTab); pRepeatColRange->aEnd.SetTab(nTab); } - delete pRepeatRowRange; - pRepeatRowRange = nullptr; + pRepeatRowRange.reset(); if (rTable.pRepeatRowRange) { - pRepeatRowRange = new ScRange(*rTable.pRepeatRowRange); + pRepeatRowRange.reset(new ScRange(*rTable.pRepeatRowRange)); pRepeatRowRange->aStart.SetTab(nTab); pRepeatRowRange->aEnd.SetTab(nTab); } } -void ScTable::SetRepeatColRange( const ScRange* pNew ) +void ScTable::SetRepeatColRange( std::unique_ptr<ScRange> pNew ) { - setPrintRange( pRepeatColRange, pNew ); + pRepeatColRange = std::move(pNew); SetStreamValid(false); InvalidatePageBreaks(); } -void ScTable::SetRepeatRowRange( const ScRange* pNew ) +void ScTable::SetRepeatRowRange( std::unique_ptr<ScRange> pNew ) { - setPrintRange( pRepeatRowRange, pNew ); + pRepeatRowRange = std::move(pNew); SetStreamValid(false); @@ -2105,15 +2090,17 @@ const ScRange* ScTable::GetPrintRange(sal_uInt16 nPos) const void ScTable::FillPrintSaver( ScPrintSaverTab& rSaveTab ) const { rSaveTab.SetAreas( aPrintRanges, bPrintEntireSheet ); - rSaveTab.SetRepeat( pRepeatColRange, pRepeatRowRange ); + rSaveTab.SetRepeat( pRepeatColRange.get(), pRepeatRowRange.get() ); } void ScTable::RestorePrintRanges( const ScPrintSaverTab& rSaveTab ) { aPrintRanges = rSaveTab.GetPrintRanges(); bPrintEntireSheet = rSaveTab.IsEntireSheet(); - SetRepeatColRange( rSaveTab.GetRepeatCol() ); - SetRepeatRowRange( rSaveTab.GetRepeatRow() ); + auto p = rSaveTab.GetRepeatCol(); + SetRepeatColRange( std::unique_ptr<ScRange>(p ? new ScRange(*p) : nullptr) ); + p = rSaveTab.GetRepeatRow(); + SetRepeatRowRange( std::unique_ptr<ScRange>(p ? new ScRange(*p) : nullptr) ); InvalidatePageBreaks(); // #i117952# forget page breaks for an old print range UpdatePageBreaks(nullptr); @@ -2213,10 +2200,9 @@ ScRefCellValue ScTable::VisibleDataCellIterator::next() return ScRefCellValue(); } -void ScTable::SetAnonymousDBData(ScDBData* pDBData) +void ScTable::SetAnonymousDBData(std::unique_ptr<ScDBData> pDBData) { - delete pDBDataNoName; - pDBDataNoName = pDBData; + pDBDataNoName = std::move(pDBData); } sal_uLong ScTable::AddCondFormat( ScConditionalFormat* pNew ) diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 4e51b19b345e..340e087bb927 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -101,17 +101,15 @@ bool ScTable::SetOutlineTable( const ScOutlineTable* pNewOutline ) { nOldSizeX = pOutlineTable->GetColArray().GetDepth(); nOldSizeY = pOutlineTable->GetRowArray().GetDepth(); - delete pOutlineTable; + pOutlineTable.reset(); } if (pNewOutline) { - pOutlineTable = new ScOutlineTable( *pNewOutline ); + pOutlineTable.reset(new ScOutlineTable( *pNewOutline )); nNewSizeX = pOutlineTable->GetColArray().GetDepth(); nNewSizeY = pOutlineTable->GetRowArray().GetDepth(); } - else - pOutlineTable = nullptr; return ( nNewSizeX != nOldSizeX || nNewSizeY != nOldSizeY ); // changed size? } @@ -119,16 +117,12 @@ bool ScTable::SetOutlineTable( const ScOutlineTable* pNewOutline ) void ScTable::StartOutlineTable() { if (!pOutlineTable) - pOutlineTable = new ScOutlineTable; + pOutlineTable.reset(new ScOutlineTable); } -void ScTable::SetSheetEvents( const ScSheetEvents* pNew ) +void ScTable::SetSheetEvents( std::unique_ptr<ScSheetEvents> pNew ) { - delete pSheetEvents; - if (pNew) - pSheetEvents = new ScSheetEvents(*pNew); - else - pSheetEvents = nullptr; + pSheetEvents = std::move(pNew); SetCalcNotification( false ); // discard notifications before the events were set @@ -494,7 +488,7 @@ void ScTable::CopyToClip( // copy content //local range names need to be copied first for formula cells if (!pTable->mpRangeName && mpRangeName) - pTable->mpRangeName = new ScRangeName(*mpRangeName); + pTable->mpRangeName.reset( new ScRangeName(*mpRangeName) ); SCCOL i; @@ -510,7 +504,7 @@ void ScTable::CopyToClip( pTable->CopyColHidden(*this, 0, nCol2); pTable->CopyColFiltered(*this, 0, nCol2); if (pDBDataNoName) - pTable->SetAnonymousDBData(new ScDBData(*pDBDataNoName)); + pTable->SetAnonymousDBData(std::unique_ptr<ScDBData>(new ScDBData(*pDBDataNoName))); if (pRowFlags && pTable->pRowFlags && mpRowHeights && pTable->mpRowHeights) { @@ -1150,13 +1144,13 @@ void ScTable::CopyToTable( if (pDBDataNoName) { - ScDBData* pNewDBData = new ScDBData(*pDBDataNoName); + std::unique_ptr<ScDBData> pNewDBData(new ScDBData(*pDBDataNoName)); SCCOL aCol1, aCol2; SCROW aRow1, aRow2; SCTAB aTab; pNewDBData->GetArea(aTab, aCol1, aRow1, aCol2, aRow2); pNewDBData->MoveTo(pDestTab->nTab, aCol1, aRow1, aCol2, aRow2); - pDestTab->SetAnonymousDBData(pNewDBData); + pDestTab->SetAnonymousDBData(std::move(pNewDBData)); } // Charts have to be adjusted when hide/show ScChartListenerCollection* pCharts = pDestTab->pDocument->GetChartListenerCollection(); @@ -1249,7 +1243,7 @@ void ScTable::CopyToTable( } if(nFlags & InsertDeleteFlags::OUTLINE) // also only when bColRowFlags - pDestTab->SetOutlineTable( pOutlineTable ); + pDestTab->SetOutlineTable( pOutlineTable.get() ); if (bCopyCaptions && (nFlags & (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES))) { @@ -1375,8 +1369,7 @@ bool ScTable::HasScenarioRange( const ScRange& rRange ) const void ScTable::InvalidateScenarioRanges() { - delete pScenarioRanges; - pScenarioRanges = nullptr; + pScenarioRanges.reset(); } const ScRangeList* ScTable::GetScenarioRanges() const @@ -1385,12 +1378,12 @@ const ScRangeList* ScTable::GetScenarioRanges() const if (!pScenarioRanges) { - const_cast<ScTable*>(this)->pScenarioRanges = new ScRangeList; + const_cast<ScTable*>(this)->pScenarioRanges.reset(new ScRangeList); ScMarkData aMark; MarkScenarioIn( aMark, ScScenarioFlags::NONE ); // always - aMark.FillRangeListWithMarks( pScenarioRanges, false ); + aMark.FillRangeListWithMarks( pScenarioRanges.get(), false ); } - return pScenarioRanges; + return pScenarioRanges.get(); } bool ScTable::TestCopyScenarioTo( const ScTable* pDestTab ) const @@ -3790,10 +3783,9 @@ void ScTable::SetDrawPageSize(bool bResetStreamValid, bool bUpdateNoteCaptionPos SetStreamValid(false); } -void ScTable::SetRangeName(ScRangeName* pNew) +void ScTable::SetRangeName(std::unique_ptr<ScRangeName> pNew) { - delete mpRangeName; - mpRangeName = pNew; + mpRangeName = std::move(pNew); //fdo#39792: mark stream as invalid, otherwise new ScRangeName will not be written to file SetStreamValid(false); @@ -3802,8 +3794,8 @@ void ScTable::SetRangeName(ScRangeName* pNew) ScRangeName* ScTable::GetRangeName() const { if (!mpRangeName) - mpRangeName = new ScRangeName; - return mpRangeName; + mpRangeName.reset(new ScRangeName); + return mpRangeName.get(); } sal_uLong ScTable::GetRowOffset( SCROW nRow, bool bHiddenAsZero ) const diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx index c39fb3816c94..85f62b7ecc87 100644 --- a/sc/source/core/data/table5.cxx +++ b/sc/source/core/data/table5.cxx @@ -1033,8 +1033,8 @@ void ScTable::SyncColRowFlags() } // Hidden flags. - lcl_syncFlags(*mpHiddenCols, *mpHiddenRows, mpColFlags.get(), pRowFlags, CRFlags::Hidden); - lcl_syncFlags(*mpFilteredCols, *mpFilteredRows, mpColFlags.get(), pRowFlags, CRFlags::Filtered); + lcl_syncFlags(*mpHiddenCols, *mpHiddenRows, mpColFlags.get(), pRowFlags.get(), CRFlags::Hidden); + lcl_syncFlags(*mpFilteredCols, *mpFilteredRows, mpColFlags.get(), pRowFlags.get(), CRFlags::Filtered); } void ScTable::SetPageSize( const Size& rSize ) diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx index efdb51803935..5a4f36fe3d70 100644 --- a/sc/source/core/data/table6.cxx +++ b/sc/source/core/data/table6.cxx @@ -815,7 +815,7 @@ bool ScTable::SearchAndReplace( ( TransliterationFlags::IGNORE_CASE | TransliterationFlags::IGNORE_WIDTH ); - pSearchText = new utl::TextSearch( aSearchOptions ); + pSearchText.reset( new utl::TextSearch( aSearchOptions ) ); if (nCommand == SvxSearchCmd::FIND) bFound = Search(rSearchItem, rCol, rRow, rMark, rUndoStr, pUndoDoc); @@ -826,8 +826,7 @@ bool ScTable::SearchAndReplace( else if (nCommand == SvxSearchCmd::REPLACE_ALL) bFound = ReplaceAll(rSearchItem, rMark, rMatchedRanges, rUndoStr, pUndoDoc); - delete pSearchText; - pSearchText = nullptr; + pSearchText.reset(); } } return bFound; diff --git a/sc/source/filter/excel/excimp8.cxx b/sc/source/filter/excel/excimp8.cxx index aa3e630f5d09..2cf116b9ee4d 100644 --- a/sc/source/filter/excel/excimp8.cxx +++ b/sc/source/filter/excel/excimp8.cxx @@ -794,7 +794,7 @@ void XclImpAutoFilterData::Apply() } else pCurrDBData->SetAdvancedQuerySource(nullptr); - rDoc.SetAnonymousDBData(Tab(), pCurrDBData); + rDoc.SetAnonymousDBData(Tab(), std::unique_ptr<ScDBData>(pCurrDBData)); } if( bActive ) diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx index 56b2de54f441..136904fa87c4 100644 --- a/sc/source/filter/excel/impop.cxx +++ b/sc/source/filter/excel/impop.cxx @@ -1348,13 +1348,13 @@ void ImportExcel::PostDocLoad() { if( p->aStart.Col() == 0 && p->aEnd.Col() == MAXCOL && bRowVirgin ) { - pD->SetRepeatRowRange( n, p ); + pD->SetRepeatRowRange( n, std::unique_ptr<ScRange>(new ScRange(*p)) ); bRowVirgin = false; } if( p->aStart.Row() == 0 && p->aEnd.Row() == MAXROW && bColVirgin ) { - pD->SetRepeatColRange( n, p ); + pD->SetRepeatColRange( n, std::unique_ptr<ScRange>(new ScRange(*p)) ); bColVirgin = false; } diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx index b37638da99cb..ce72e708e029 100644 --- a/sc/source/filter/oox/workbookhelper.cxx +++ b/sc/source/filter/oox/workbookhelper.cxx @@ -455,10 +455,10 @@ Reference< XDatabaseRange > WorkbookGlobals::createUnnamedDatabaseRangeObject( c ScDocument& rDoc = getScDocument(); if( rDoc.GetTableCount() <= aDestRange.aStart.Tab() ) throw css::lang::IndexOutOfBoundsException(); - ScDBData* pNewDBData = new ScDBData( STR_DB_LOCAL_NONAME, aDestRange.aStart.Tab(), + std::unique_ptr<ScDBData> pNewDBData(new ScDBData( STR_DB_LOCAL_NONAME, aDestRange.aStart.Tab(), aDestRange.aStart.Col(), aDestRange.aStart.Row(), - aDestRange.aEnd.Col(), aDestRange.aEnd.Row() ); - rDoc.SetAnonymousDBData( aDestRange.aStart.Tab() , pNewDBData ); + aDestRange.aEnd.Col(), aDestRange.aEnd.Row() )); + rDoc.SetAnonymousDBData( aDestRange.aStart.Tab() , std::move(pNewDBData) ); ScDocShell* pDocSh = static_cast< ScDocShell* >(rDoc.GetDocumentShell()); xDatabaseRange.set(new ScDatabaseRangeObj(pDocSh, aDestRange.aStart.Tab())); } diff --git a/sc/source/filter/xml/xmldrani.cxx b/sc/source/filter/xml/xmldrani.cxx index 721f7f946a8f..d71a07e51769 100644 --- a/sc/source/filter/xml/xmldrani.cxx +++ b/sc/source/filter/xml/xmldrani.cxx @@ -417,7 +417,7 @@ void SAL_CALL ScXMLDatabaseRangeContext::endFastElement( sal_Int32 /*nElement*/ pData->GetArea(aRange); setAutoFilterFlags(*pDoc, *pData); - pDoc->SetAnonymousDBData(aRange.aStart.Tab(), pData.release()); + pDoc->SetAnonymousDBData(aRange.aStart.Tab(), std::move(pData)); } return; } @@ -431,7 +431,7 @@ void SAL_CALL ScXMLDatabaseRangeContext::endFastElement( sal_Int32 /*nElement*/ pData->GetArea(aRange); if (setAutoFilterFlags(*pDoc, *pData)) - pDoc->SetAnonymousDBData(aRange.aStart.Tab(), pData.release()); + pDoc->SetAnonymousDBData(aRange.aStart.Tab(), std::move(pData)); else pDoc->GetDBCollection()->getAnonDBs().insert(pData.release()); } diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 3a8a5d28de06..555101ec5602 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -71,9 +71,9 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange ) if (bUndo) pUndoColl = new ScDBCollection( *pDocColl ); - ScDBData* pNew = new ScDBData( rName, rRange.aStart.Tab(), + std::unique_ptr<ScDBData> pNew(new ScDBData( rName, rRange.aStart.Tab(), rRange.aStart.Col(), rRange.aStart.Row(), - rRange.aEnd.Col(), rRange.aEnd.Row() ); + rRange.aEnd.Col(), rRange.aEnd.Row() )); // #i55926# While loading XML, formula cells only have a single string token, // so CompileDBFormula would never find any name (index) tokens, and would @@ -84,12 +84,12 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange ) rDoc.PreprocessDBDataUpdate(); if ( rName == STR_DB_LOCAL_NONAME ) { - rDoc.SetAnonymousDBData(rRange.aStart.Tab() , pNew); + rDoc.SetAnonymousDBData(rRange.aStart.Tab(), std::move(pNew)); bOk = true; } else { - bOk = pDocColl->getNamedDBs().insert(pNew); + bOk = pDocColl->getNamedDBs().insert(pNew.release()); } if ( bCompile ) rDoc.CompileHybridFormula(); diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 55913db5f4c9..78b36aec755c 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -91,6 +91,7 @@ #include <cellvalues.hxx> #include <undoconvert.hxx> #include <docfuncutil.hxx> +#include <sheetevents.hxx> #include <memory> #include <utility> @@ -3213,7 +3214,8 @@ bool ScDocFunc::DeleteTable( SCTAB nTab, bool bRecord ) } pUndoDoc->SetVisible( nTab, rDoc.IsVisible( nTab ) ); pUndoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) ); - pUndoDoc->SetSheetEvents( nTab, rDoc.GetSheetEvents( nTab ) ); + auto pSheetEvents = rDoc.GetSheetEvents( nTab ); + pUndoDoc->SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) ); // Drawing-Layer has to take care of its own undo!!! rDoc.BeginDrawUndo(); // DeleteTab generates SdrUndoDelPage @@ -4985,10 +4987,10 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, bool bRecord, Sc void ScDocFunc::ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab ) { - SetNewRangeNames( new ScRangeName(rNewRanges), true, nTab ); + SetNewRangeNames( std::unique_ptr<ScRangeName>(new ScRangeName(rNewRanges)), true, nTab ); } -void ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTAB nTab ) // takes ownership of pNewRanges +void ScDocFunc::SetNewRangeNames( std::unique_ptr<ScRangeName> pNewRanges, bool bModifyDoc, SCTAB nTab ) // takes ownership of pNewRanges { ScDocShellModificator aModificator( rDocShell ); @@ -5021,9 +5023,9 @@ void ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTA if ( bCompile ) rDoc.PreprocessRangeNameUpdate(); if (nTab >= 0) - rDoc.SetRangeName( nTab, pNewRanges ); // takes ownership + rDoc.SetRangeName( nTab, std::move(pNewRanges) ); // takes ownership else - rDoc.SetRangeName( std::unique_ptr<ScRangeName>(pNewRanges) ); // takes ownership + rDoc.SetRangeName( std::move(pNewRanges) ); // takes ownership if ( bCompile ) rDoc.CompileHybridFormula(); diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index 3eae94341395..935220d02c66 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -316,7 +316,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe pNoNameData = new ScDBData(STR_DB_LOCAL_NONAME, nTab, nStartCol,nStartRow, nEndCol,nEndRow, true, bHasHeader ); - aDocument.SetAnonymousDBData(nTab, pNoNameData); + aDocument.SetAnonymousDBData(nTab, std::unique_ptr<ScDBData>(pNoNameData)); } if ( pUndoColl ) diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index 00e48f29b9eb..7252612c5b35 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -194,7 +194,7 @@ public: bool UnmergeCells( const ScCellMergeOption& rOption, bool bRecord, ScUndoRemoveMerge* pUndoRemoveMerge ); // takes ownership of pNewRanges, nTab = -1 for local range names - void SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTAB nTab ); + void SetNewRangeNames( std::unique_ptr<ScRangeName> pNewRanges, bool bModifyDoc, SCTAB nTab ); void ModifyRangeNames( const ScRangeName& rNewRanges, SCTAB nTab = -1 ); /** * Modify all range names, global scope names as well as sheet local ones, diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx index 9e8e09a1bb6f..0af818eb34c4 100644 --- a/sc/source/ui/undo/undocell.cxx +++ b/sc/source/ui/undo/undocell.cxx @@ -996,17 +996,19 @@ void ScUndoRangeNames::DoChange( bool bUndo ) if ( bUndo ) { + auto p = std::unique_ptr<ScRangeName>(new ScRangeName( *pOldRanges )); if (mnTab >= 0) - rDoc.SetRangeName( mnTab, new ScRangeName( *pOldRanges ) ); + rDoc.SetRangeName( mnTab, std::move(p) ); else - rDoc.SetRangeName( std::unique_ptr<ScRangeName>(new ScRangeName( *pOldRanges )) ); + rDoc.SetRangeName( std::move(p) ); } else { + auto p = std::unique_ptr<ScRangeName>(new ScRangeName( *pNewRanges )); if (mnTab >= 0) - rDoc.SetRangeName( mnTab, new ScRangeName( *pNewRanges ) ); + rDoc.SetRangeName( mnTab, std::move(p) ); else - rDoc.SetRangeName( std::unique_ptr<ScRangeName>(new ScRangeName( *pNewRanges )) ); + rDoc.SetRangeName( std::move(p) ); } rDoc.CompileHybridFormula(); diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx index d99555e6a277..a92a2270e59d 100644 --- a/sc/source/ui/undo/undotab.cxx +++ b/sc/source/ui/undo/undotab.cxx @@ -47,6 +47,7 @@ #include <svx/svdpage.hxx> #include <drwlayer.hxx> #include <scresid.hxx> +#include <sheetevents.hxx> #include <memory> #include <utility> @@ -335,7 +336,8 @@ void ScUndoDeleteTab::Undo() } rDoc.SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) ); rDoc.SetTabBgColor( nTab, pRefUndoDoc->GetTabBgColor(nTab) ); - rDoc.SetSheetEvents( nTab, pRefUndoDoc->GetSheetEvents( nTab ) ); + auto pSheetEvents = pRefUndoDoc->GetSheetEvents( nTab ); + rDoc.SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) ); rDoc.SetLayoutRTL( nTab, pRefUndoDoc->IsLayoutRTL( nTab ) ); if ( pRefUndoDoc->IsTabProtected( nTab ) ) diff --git a/sc/source/ui/undo/undoutil.cxx b/sc/source/ui/undo/undoutil.cxx index dce4612ce60d..e60431d6d99f 100644 --- a/sc/source/ui/undo/undoutil.cxx +++ b/sc/source/ui/undo/undoutil.cxx @@ -87,7 +87,7 @@ ScDBData* ScUndoUtil::GetOldDBData( const ScDBData* pUndoData, ScDocument* pDoc, pRet = new ScDBData( STR_DB_LOCAL_NONAME, nTab, nCol1,nRow1, nCol2,nRow2, true, pDoc->HasColHeader( nCol1,nRow1,nCol2,nRow2,nTab ) ); - pDoc->SetAnonymousDBData(nTab,pRet); + pDoc->SetAnonymousDBData(nTab, std::unique_ptr<ScDBData>(pRet)); } } diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index c5830ce06c56..c4cdf2f8b43d 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -7311,8 +7311,7 @@ void SAL_CALL ScTableSheetObj::setPrintTitleColumns( sal_Bool bPrintTitleColumns { if ( !rDoc.GetRepeatColRange( nTab ) ) // do not change existing area { - ScRange aNew( 0, 0, nTab, 0, 0, nTab ); - rDoc.SetRepeatColRange( nTab, &aNew ); // enable + rDoc.SetRepeatColRange( nTab, std::unique_ptr<ScRange>(new ScRange( 0, 0, nTab, 0, 0, nTab )) ); // enable } } else @@ -7354,9 +7353,9 @@ void SAL_CALL ScTableSheetObj::setTitleColumns( const table::CellRangeAddress& a ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver(); - ScRange aNew; - ScUnoConversion::FillScRange( aNew, aTitleColumns ); - rDoc.SetRepeatColRange( nTab, &aNew ); // also always enable + std::unique_ptr<ScRange> pNew(new ScRange); + ScUnoConversion::FillScRange( *pNew, aTitleColumns ); + rDoc.SetRepeatColRange( nTab, std::move(pNew) ); // also always enable PrintAreaUndo_Impl( pOldRanges ); // undo, page breaks, modified etc. } @@ -7390,8 +7389,8 @@ void SAL_CALL ScTableSheetObj::setPrintTitleRows( sal_Bool bPrintTitleRows ) { if ( !rDoc.GetRepeatRowRange( nTab ) ) // do not change existing area { - ScRange aNew( 0, 0, nTab, 0, 0, nTab ); - rDoc.SetRepeatRowRange( nTab, &aNew ); // enable + std::unique_ptr<ScRange> pNew( new ScRange(0, 0, nTab, 0, 0, nTab) ); + rDoc.SetRepeatRowRange( nTab, std::move(pNew) ); // enable } } else @@ -7433,9 +7432,9 @@ void SAL_CALL ScTableSheetObj::setTitleRows( const table::CellRangeAddress& aTit ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver(); - ScRange aNew; - ScUnoConversion::FillScRange( aNew, aTitleRows ); - rDoc.SetRepeatRowRange( nTab, &aNew ); // also always enable + std::unique_ptr<ScRange> pNew(new ScRange); + ScUnoConversion::FillScRange( *pNew, aTitleRows ); + rDoc.SetRepeatRowRange( nTab, std::move(pNew) ); // also always enable PrintAreaUndo_Impl( pOldRanges ); // Undo, page breaks, modified etc. } diff --git a/sc/source/ui/unoobj/eventuno.cxx b/sc/source/ui/unoobj/eventuno.cxx index 6d33ea9c74c5..4de0597dc809 100644 --- a/sc/source/ui/unoobj/eventuno.cxx +++ b/sc/source/ui/unoobj/eventuno.cxx @@ -74,10 +74,10 @@ void SAL_CALL ScSheetEventsObj::replaceByName( const OUString& aName, const uno: if (nEvent == ScSheetEventId::NOTFOUND) throw container::NoSuchElementException(); - ScSheetEvents aNewEvents; + std::unique_ptr<ScSheetEvents> pNewEvents(new ScSheetEvents); const ScSheetEvents* pOldEvents = mpDocShell->GetDocument().GetSheetEvents(mnTab); if (pOldEvents) - aNewEvents = *pOldEvents; + *pNewEvents = *pOldEvents; OUString aScript; if ( aElement.hasValue() ) // empty Any -> reset event @@ -105,11 +105,11 @@ void SAL_CALL ScSheetEventsObj::replaceByName( const OUString& aName, const uno: } } if (!aScript.isEmpty()) - aNewEvents.SetScript( nEvent, &aScript ); + pNewEvents->SetScript( nEvent, &aScript ); else - aNewEvents.SetScript( nEvent, nullptr ); // reset + pNewEvents->SetScript( nEvent, nullptr ); // reset - mpDocShell->GetDocument().SetSheetEvents( mnTab, &aNewEvents ); + mpDocShell->GetDocument().SetSheetEvents( mnTab, std::move(pNewEvents) ); mpDocShell->SetDocumentModified(); } diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx index e1e7d1478c28..5e5ad772c0fe 100644 --- a/sc/source/ui/unoobj/nameuno.cxx +++ b/sc/source/ui/unoobj/nameuno.cxx @@ -169,7 +169,7 @@ void ScNamedRangeObj::Modify_Impl( const OUString* pNewName, const ScTokenArray* if (!pOld) return; - ScRangeName* pNewRanges = new ScRangeName(*pNames); + std::unique_ptr<ScRangeName> pNewRanges(new ScRangeName(*pNames)); OUString aInsName = pOld->GetName(); if (pNewName) @@ -199,14 +199,13 @@ void ScNamedRangeObj::Modify_Impl( const OUString* pNewName, const ScTokenArray* pNewRanges->erase(*pOld); if (pNewRanges->insert(pNew)) { - pDocShell->GetDocFunc().SetNewRangeNames(pNewRanges, mxParent->IsModifyAndBroadcast(), nTab); + pDocShell->GetDocFunc().SetNewRangeNames(std::move(pNewRanges), mxParent->IsModifyAndBroadcast(), nTab); aName = aInsName; //! broadcast? } else { pNew = nullptr; //! uno::Exception/Error or something - delete pNewRanges; } } @@ -492,19 +491,18 @@ void SAL_CALL ScNamedRangesObj::addNewByName( const OUString& aName, ScRangeName* pNames = GetRangeName_Impl(); if (pNames && !pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName))) { - ScRangeName* pNewRanges = new ScRangeName( *pNames ); + std::unique_ptr<ScRangeName> pNewRanges(new ScRangeName( *pNames )); // GRAM_API for API compatibility. ScRangeData* pNew = new ScRangeData( &rDoc, aName, aContent, aPos, nNewType,formula::FormulaGrammar::GRAM_API ); if ( pNewRanges->insert(pNew) ) { - pDocShell->GetDocFunc().SetNewRangeNames(pNewRanges, mbModifyAndBroadcast, GetTab_Impl()); + pDocShell->GetDocFunc().SetNewRangeNames(std::move(pNewRanges), mbModifyAndBroadcast, GetTab_Impl()); bDone = true; } else { pNew = nullptr; - delete pNewRanges; } } } @@ -549,9 +547,9 @@ void SAL_CALL ScNamedRangesObj::removeByName( const OUString& aName ) const ScRangeData* pData = pNames->findByUpperName(ScGlobal::pCharClass->uppercase(aName)); if (pData && lcl_UserVisibleName(*pData)) { - ScRangeName* pNewRanges = new ScRangeName(*pNames); + std::unique_ptr<ScRangeName> pNewRanges(new ScRangeName(*pNames)); pNewRanges->erase(*pData); - pDocShell->GetDocFunc().SetNewRangeNames( pNewRanges, mbModifyAndBroadcast, GetTab_Impl()); + pDocShell->GetDocFunc().SetNewRangeNames( std::move(pNewRanges), mbModifyAndBroadcast, GetTab_Impl()); bDone = true; } } diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index e176bbffb54c..6b3d0d83df0d 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -87,6 +87,7 @@ #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/lok.hxx> #include <mergecellsdialog.hxx> +#include <sheetevents.hxx> #include <vector> #include <memory> @@ -1009,7 +1010,7 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint, rDoc.SetRepeatColRange( nTab, nullptr ); else if ( aRange.ParseAny( *pRepCol, &rDoc, aDetails ) & ScRefFlags::VALID ) - rDoc.SetRepeatColRange( nTab, &aRange ); + rDoc.SetRepeatColRange( nTab, std::unique_ptr<ScRange>(new ScRange(aRange)) ); } // repeat rows @@ -1020,7 +1021,7 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint, rDoc.SetRepeatRowRange( nTab, nullptr ); else if ( aRange.ParseAny( *pRepRow, &rDoc, aDetails ) & ScRefFlags::VALID ) - rDoc.SetRepeatRowRange( nTab, &aRange ); + rDoc.SetRepeatRowRange( nTab, std::unique_ptr<ScRange>(new ScRange(aRange)) ); } } @@ -2369,7 +2370,8 @@ bool ScViewFunc::DeleteTables(const vector<SCTAB> &TheTabs, bool bRecord ) } pUndoDoc->SetVisible( nTab, rDoc.IsVisible( nTab ) ); pUndoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) ); - pUndoDoc->SetSheetEvents( nTab, rDoc.GetSheetEvents( nTab ) ); + auto pSheetEvents = rDoc.GetSheetEvents( nTab ); + pUndoDoc->SetSheetEvents( nTab, std::unique_ptr<ScSheetEvents>(pSheetEvents ? new ScSheetEvents(*pSheetEvents) : nullptr) ); pUndoDoc->SetLayoutRTL( nTab, rDoc.IsLayoutRTL( nTab ) ); if ( rDoc.IsTabProtected( nTab ) ) |