From 92c2a7e026beaaabf4cd3b8c612c15e9b933a90a Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 10 Jul 2018 11:17:50 +0200 Subject: loplugin:useuniqueptr in ScModelObj Change-Id: I12635d45555bc59d14134b8eef3e093f3fd4e6a0 Reviewed-on: https://gerrit.libreoffice.org/57242 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/inc/docuno.hxx | 4 ++-- sc/source/ui/unoobj/docuno.cxx | 21 +++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index c9a450210ef3..630caed76206 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -93,8 +93,8 @@ class SC_DLLPUBLIC ScModelObj : public SfxBaseModel, private: SfxItemPropertySet aPropSet; ScDocShell* pDocShell; - ScPrintFuncCache* pPrintFuncCache; - ScPrintUIOptions* pPrinterOptions; + std::unique_ptr pPrintFuncCache; + std::unique_ptr pPrinterOptions; std::unique_ptr m_pPrintState; css::uno::Reference xNumberAgg; css::uno::Reference xDrawGradTab; diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index b910162833ef..06a5d3e122d7 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -410,8 +410,8 @@ ScModelObj::~ScModelObj() if (xNumberAgg.is()) xNumberAgg->setDelegator(uno::Reference()); - delete pPrintFuncCache; - delete pPrinterOptions; + pPrintFuncCache.reset(); + pPrinterOptions.reset(); } uno::Reference< uno::XAggregation> const & ScModelObj::GetFormatter() @@ -1336,7 +1336,7 @@ void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) pNumFmt->SetNumberFormatter( nullptr ); } - DELETEZ( pPrintFuncCache ); // must be deleted because it has a pointer to the DocShell + pPrintFuncCache.reset(); // must be deleted because it has a pointer to the DocShell m_pPrintState.reset(); } else if ( nId == SfxHintId::DataChanged ) @@ -1344,7 +1344,7 @@ void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) // cached data for rendering become invalid when contents change // (if a broadcast is added to SetDrawModified, is has to be tested here, too) - DELETEZ( pPrintFuncCache ); + pPrintFuncCache.reset(); m_pPrintState.reset(); // handle "OnCalculate" sheet events (search also for VBA event handlers) @@ -1708,8 +1708,7 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection, if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) ) { - delete pPrintFuncCache; - pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus ); + pPrintFuncCache.reset(new ScPrintFuncCache( pDocShell, aMark, aStatus )); } sal_Int32 nPages = pPrintFuncCache->GetPageCount(); @@ -1763,8 +1762,7 @@ uno::Sequence SAL_CALL ScModelObj::getRenderer( sal_Int32 { if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) ) { - delete pPrintFuncCache; - pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus ); + pPrintFuncCache.reset(new ScPrintFuncCache( pDocShell, aMark, aStatus )); } nTotalPages = pPrintFuncCache->GetPageCount(); } @@ -1802,7 +1800,7 @@ uno::Sequence SAL_CALL ScModelObj::getRenderer( sal_Int32 })); if( ! pPrinterOptions ) - pPrinterOptions = new ScPrintUIOptions; + pPrinterOptions.reset(new ScPrintUIOptions); else pPrinterOptions->SetDefaults(); pPrinterOptions->appendPrintUIOptions( aSequence ); @@ -1886,7 +1884,7 @@ uno::Sequence SAL_CALL ScModelObj::getRenderer( sal_Int32 } if( ! pPrinterOptions ) - pPrinterOptions = new ScPrintUIOptions; + pPrinterOptions.reset(new ScPrintUIOptions); else pPrinterOptions->SetDefaults(); pPrinterOptions->appendPrintUIOptions( aSequence ); @@ -1912,8 +1910,7 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) ) { - delete pPrintFuncCache; - pPrintFuncCache = new ScPrintFuncCache( pDocShell, aMark, aStatus ); + pPrintFuncCache.reset(new ScPrintFuncCache( pDocShell, aMark, aStatus )); } long nTotalPages = pPrintFuncCache->GetPageCount(); sal_Int32 nRenderer = lcl_GetRendererNum( nSelRenderer, aPagesStr, nTotalPages ); -- cgit