diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-11 09:56:41 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-11 14:08:27 +0200 |
commit | e5246409cc384cd2ba321620e92250f7ddf153af (patch) | |
tree | eae4b87b9df1918bc69e081d87449a34ef483a99 | |
parent | 1c0e591accda7669bec9ccfc23977ce3f7386930 (diff) |
return std::unique_ptr from SfxItemSet::Clone
Change-Id: Ie747b5c8ff0b82b9f8d268f9a60dbde41b5f022b
Reviewed-on: https://gerrit.libreoffice.org/52712
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
32 files changed, 73 insertions, 94 deletions
diff --git a/cui/source/dialogs/iconcdlg.cxx b/cui/source/dialogs/iconcdlg.cxx index ebce7af401ac..32800dab81d3 100644 --- a/cui/source/dialogs/iconcdlg.cxx +++ b/cui/source/dialogs/iconcdlg.cxx @@ -149,7 +149,6 @@ IconChoiceDialog::IconChoiceDialog ( vcl::Window* pParent, const OUString& rID, mnCurrentPageId ( HyperLinkPageType::NONE ), pSet ( nullptr ), - pOutSet ( nullptr ), pExampleSet ( nullptr ), pRanges ( nullptr ) { @@ -171,7 +170,7 @@ IconChoiceDialog::IconChoiceDialog ( vcl::Window* pParent, const OUString& rID, if ( pSet ) { pExampleSet = new SfxItemSet( *pSet ); - pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ); + pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() )); } // Buttons @@ -208,8 +207,7 @@ void IconChoiceDialog::dispose() delete pRanges; pRanges = nullptr; - delete pOutSet; - pOutSet = nullptr; + pOutSet.reset(); m_pIconCtrl.clear(); m_pOKBtn.clear(); @@ -503,7 +501,7 @@ void IconChoiceDialog::SetInputSet( const SfxItemSet* pInSet ) if ( !bSet && !pExampleSet && !pOutSet ) { pExampleSet = new SfxItemSet( *pSet ); - pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ); + pOutSet.reset(new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() )); } } @@ -623,7 +621,7 @@ void IconChoiceDialog::Ok() if ( !pExampleSet && pSet ) pOutSet = pSet->Clone( false ); // without items else if ( pExampleSet ) - pOutSet = new SfxItemSet( *pExampleSet ); + pOutSet.reset(new SfxItemSet( *pExampleSet )); } for ( size_t i = 0, nCount = maPageList.size(); i < nCount; ++i ) diff --git a/cui/source/inc/iconcdlg.hxx b/cui/source/inc/iconcdlg.hxx index 759c9a0999b0..f65ebc645c34 100644 --- a/cui/source/inc/iconcdlg.hxx +++ b/cui/source/inc/iconcdlg.hxx @@ -111,7 +111,7 @@ private: VclPtr<VclVBox> m_pTabContainer; const SfxItemSet* pSet; - SfxItemSet* pOutSet; + std::unique_ptr<SfxItemSet> pOutSet; SfxItemSet* pExampleSet; sal_uInt16* pRanges; diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index 5ccacadf0637..09805ce0705d 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -602,7 +602,7 @@ uno::Any SvxUnoTextRangeBase::_getPropertyValue(const OUString& PropertyName, sa const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName ); if( pMap ) { - SfxItemSet* pAttribs = nullptr; + std::unique_ptr<SfxItemSet> pAttribs; if( nPara != -1 ) pAttribs = pForwarder->GetParaAttribs( nPara ).Clone(); else @@ -613,7 +613,6 @@ uno::Any SvxUnoTextRangeBase::_getPropertyValue(const OUString& PropertyName, sa getPropertyValue( pMap, aAny, *pAttribs ); - delete pAttribs; return aAny; } } @@ -886,7 +885,7 @@ uno::Sequence< uno::Any > SvxUnoTextRangeBase::_getPropertyValues( const uno::Se SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : nullptr; if( pForwarder ) { - SfxItemSet* pAttribs = nullptr; + std::unique_ptr<SfxItemSet> pAttribs; if( nPara != -1 ) pAttribs = pForwarder->GetParaAttribs( nPara ).Clone(); else @@ -905,9 +904,6 @@ uno::Sequence< uno::Any > SvxUnoTextRangeBase::_getPropertyValues( const uno::Se getPropertyValue( pMap, *pValues, *pAttribs ); } } - - delete pAttribs; - } return aValues; diff --git a/include/sfx2/prnmon.hxx b/include/sfx2/prnmon.hxx index 22ff12fd2501..4f1bacd93e80 100644 --- a/include/sfx2/prnmon.hxx +++ b/include/sfx2/prnmon.hxx @@ -37,7 +37,7 @@ class SfxPrintOptionsDialog : public ModalDialog private: std::unique_ptr<SfxPrintOptDlg_Impl> pDlgImpl; SfxViewShell* pViewSh; - SfxItemSet* pOptions; + std::unique_ptr<SfxItemSet> pOptions; VclPtr<SfxTabPage> pPage; public: diff --git a/include/sfx2/tabdlg.hxx b/include/sfx2/tabdlg.hxx index ce7498c2182b..65eb615fe6f1 100644 --- a/include/sfx2/tabdlg.hxx +++ b/include/sfx2/tabdlg.hxx @@ -82,7 +82,7 @@ friend class SfxTabDialogUIObject; bool m_bOwnsBaseFmtBtn; SfxItemSet* m_pSet; - SfxItemSet* m_pOutSet; + std::unique_ptr<SfxItemSet> m_pOutSet; std::unique_ptr< TabDlg_Impl > m_pImpl; sal_uInt16* m_pRanges; sal_uInt16 m_nAppPageId; @@ -176,7 +176,7 @@ public: // may provide local slots converted by Map const sal_uInt16* GetInputRanges( const SfxItemPool& ); void SetInputSet( const SfxItemSet* pInSet ); - const SfxItemSet* GetOutputItemSet() const { return m_pOutSet; } + const SfxItemSet* GetOutputItemSet() const { return m_pOutSet.get(); } const PushButton& GetOKButton() const { return *m_pOKBtn; } PushButton& GetOKButton() { return *m_pOKBtn; } diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx index c8e32863ba84..12daca908fbd 100644 --- a/include/svl/itemset.hxx +++ b/include/svl/itemset.hxx @@ -126,7 +126,7 @@ public: SfxItemSet( SfxItemPool&, const sal_uInt16* nWhichPairTable ); virtual ~SfxItemSet(); - virtual SfxItemSet * Clone(bool bItems = true, SfxItemPool *pToPool = nullptr) const; + virtual std::unique_ptr<SfxItemSet> Clone(bool bItems = true, SfxItemPool *pToPool = nullptr) const; // Get number of items sal_uInt16 Count() const { return m_nCount; } @@ -251,7 +251,7 @@ public: SfxAllItemSet( const SfxItemSet & ); SfxAllItemSet( const SfxAllItemSet & ); - virtual SfxItemSet * Clone( bool bItems = true, SfxItemPool *pToPool = nullptr ) const override; + virtual std::unique_ptr<SfxItemSet> Clone( bool bItems = true, SfxItemPool *pToPool = nullptr ) const override; virtual const SfxPoolItem* Put( const SfxPoolItem&, sal_uInt16 nWhich ) override; using SfxItemSet::Put; }; diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx index 362a4c2352c3..46aa4b0745c6 100644 --- a/sc/inc/postit.hxx +++ b/sc/inc/postit.hxx @@ -341,7 +341,7 @@ public: */ static ScPostIt* CreateNoteFromObjectData( ScDocument& rDoc, const ScAddress& rPos, - SfxItemSet* pItemSet, OutlinerParaObject* pOutlinerObj, + std::unique_ptr<SfxItemSet> pItemSet, OutlinerParaObject* pOutlinerObj, const tools::Rectangle& rCaptionRect, bool bShown, bool bAlwaysCreateCaption ); diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx index d0940a051592..c3bbe97a772c 100644 --- a/sc/source/core/data/patattr.cxx +++ b/sc/source/core/data/patattr.cxx @@ -104,7 +104,7 @@ ScPatternAttr::~ScPatternAttr() SfxPoolItem* ScPatternAttr::Clone( SfxItemPool *pPool ) const { - ScPatternAttr* pPattern = new ScPatternAttr( std::unique_ptr<SfxItemSet>(GetItemSet().Clone(true, pPool)) ); + ScPatternAttr* pPattern = new ScPatternAttr( GetItemSet().Clone(true, pPool) ); pPattern->pStyle = pStyle; pPattern->pName = pName; diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx index 676a0dafb35a..50d416077d89 100644 --- a/sc/source/core/data/postit.cxx +++ b/sc/source/core/data/postit.cxx @@ -1240,7 +1240,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromCaption( } ScPostIt* ScNoteUtil::CreateNoteFromObjectData( - ScDocument& rDoc, const ScAddress& rPos, SfxItemSet* pItemSet, + ScDocument& rDoc, const ScAddress& rPos, std::unique_ptr<SfxItemSet> pItemSet, OutlinerParaObject* pOutlinerObj, const tools::Rectangle& rCaptionRect, bool bShown, bool bAlwaysCreateCaption ) { @@ -1248,7 +1248,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromObjectData( ScNoteData aNoteData( bShown ); aNoteData.mxInitData.reset( new ScCaptionInitData ); ScCaptionInitData& rInitData = *aNoteData.mxInitData; - rInitData.mxItemSet.reset( pItemSet ); + rInitData.mxItemSet = std::move(pItemSet); rInitData.mxOutlinerObj.reset( pOutlinerObj ); // convert absolute caption position to relative position diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index cc9ba05135c0..f6610a62a010 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -910,7 +910,7 @@ void ScXMLTableRowCellContext::SetAnnotation(const ScAddress& rPos) { // create cell note with all data from drawing object pNote = ScNoteUtil::CreateNoteFromObjectData( *pDoc, rPos, - xItemSet.release(), xOutlinerObj.release(), + std::move(xItemSet), xOutlinerObj.release(), aCaptionRect, mxAnnotationData->mbShown, false ); } } diff --git a/sc/source/ui/unoobj/confuno.cxx b/sc/source/ui/unoobj/confuno.cxx index fefdcc3773b7..d892bba47647 100644 --- a/sc/source/ui/unoobj/confuno.cxx +++ b/sc/source/ui/unoobj/confuno.cxx @@ -215,7 +215,7 @@ void SAL_CALL ScDocumentConfiguration::setPropertyValue( if (pPrinter->GetName() != sPrinterName) { - VclPtrInstance<SfxPrinter> pNewPrinter( std::unique_ptr<SfxItemSet>(pPrinter->GetOptions().Clone()), sPrinterName ); + VclPtrInstance<SfxPrinter> pNewPrinter( pPrinter->GetOptions().Clone(), sPrinterName ); if (pNewPrinter->IsKnown()) pDocShell->SetPrinter( pNewPrinter, SfxPrinterChangeFlags::PRINTER ); else diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx index b85ef75f5417..a910b01f877e 100644 --- a/sc/source/ui/view/formatsh.cxx +++ b/sc/source/ui/view/formatsh.cxx @@ -1769,7 +1769,7 @@ void ScFormatShell::ExecuteAttr( SfxRequest& rReq ) ScMarkData aFuncMark( pViewData->GetMarkData() ); ScViewUtil::UnmarkFiltered( aFuncMark, pDoc ); - pDoc->SetPreviewFont( std::unique_ptr<SfxItemSet>(aSetItem.GetItemSet().Clone()) ); + pDoc->SetPreviewFont( aSetItem.GetItemSet().Clone() ); aFuncMark.MarkToMulti(); if ( !aFuncMark.IsMarked() && !aFuncMark.IsMultiMarked() ) diff --git a/sd/source/ui/unoidl/UnoDocumentSettings.cxx b/sd/source/ui/unoidl/UnoDocumentSettings.cxx index 7d85f27bb0e6..8a3d19ace163 100644 --- a/sd/source/ui/unoidl/UnoDocumentSettings.cxx +++ b/sd/source/ui/unoidl/UnoDocumentSettings.cxx @@ -725,7 +725,7 @@ DocumentSettings::_setPropertyValues(const PropertyMapEntry** ppEntries, SfxPrinter *pTempPrinter = pDocSh->GetPrinter( true ); if (pTempPrinter) { - VclPtr<SfxPrinter> pNewPrinter = VclPtr<SfxPrinter>::Create( std::unique_ptr<SfxItemSet>(pTempPrinter->GetOptions().Clone()), aPrinterName ); + VclPtr<SfxPrinter> pNewPrinter = VclPtr<SfxPrinter>::Create( pTempPrinter->GetOptions().Clone(), aPrinterName ); pDocSh->SetPrinter( pNewPrinter ); } } @@ -748,7 +748,7 @@ DocumentSettings::_setPropertyValues(const PropertyMapEntry** ppEntries, bool bPreferPrinterPapersize = false; if( pPrinter ) { - pItemSet.reset(pPrinter->GetOptions().Clone()); + pItemSet = pPrinter->GetOptions().Clone(); bPreferPrinterPapersize = pPrinter->GetPrinterSettingsPreferred(); } else diff --git a/sd/source/ui/view/drviews7.cxx b/sd/source/ui/view/drviews7.cxx index b416561ae130..230d75c2e853 100644 --- a/sd/source/ui/view/drviews7.cxx +++ b/sd/source/ui/view/drviews7.cxx @@ -1758,7 +1758,7 @@ void DrawViewShell::SetPageProperties (SfxRequest& rReq) { SdrPageProperties& rPageProperties = pPage->getSdrPageProperties(); const SfxItemSet &aPageItemSet = rPageProperties.GetItemSet(); - SfxItemSet *pTempSet = aPageItemSet.Clone(false, &mpDrawView->GetModel()->GetItemPool()); + std::unique_ptr<SfxItemSet> pTempSet = aPageItemSet.Clone(false, &mpDrawView->GetModel()->GetItemPool()); rPageProperties.ClearItem(XATTR_FILLSTYLE); rPageProperties.ClearItem(XATTR_FILLGRADIENT); @@ -1792,7 +1792,7 @@ void DrawViewShell::SetPageProperties (SfxRequest& rReq) // MigrateItemSet guarantees unique gradient names SfxItemSet aMigrateSet( mpDrawView->GetModel()->GetItemPool(), svl::Items<XATTR_FILLGRADIENT, XATTR_FILLGRADIENT>{} ); aMigrateSet.Put( aGradientItem ); - SdrModel::MigrateItemSet( &aMigrateSet, pTempSet, mpDrawView->GetModel() ); + SdrModel::MigrateItemSet( &aMigrateSet, pTempSet.get(), mpDrawView->GetModel() ); rPageProperties.PutItemSet( *pTempSet ); rPageProperties.PutItem( XFillStyleItem( drawing::FillStyle_GRADIENT ) ); @@ -1819,8 +1819,6 @@ void DrawViewShell::SetPageProperties (SfxRequest& rReq) break; } - delete pTempSet; - rReq.Done(); } else diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx index 24bfc02def63..47ba55e34947 100644 --- a/sfx2/source/appl/appopen.cxx +++ b/sfx2/source/appl/appopen.cxx @@ -385,7 +385,7 @@ ErrCode SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString & css::uno::Reference< css::frame::XModel > xModel ( xDoc->GetModel(), css::uno::UNO_QUERY ); if ( xModel.is() ) { - SfxItemSet* pNew = xDoc->GetMedium()->GetItemSet()->Clone(); + std::unique_ptr<SfxItemSet> pNew = xDoc->GetMedium()->GetItemSet()->Clone(); pNew->ClearItem( SID_PROGRESS_STATUSBAR_CONTROL ); pNew->ClearItem( SID_FILTER_NAME ); css::uno::Sequence< css::beans::PropertyValue > aArgs; @@ -395,7 +395,6 @@ ErrCode SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString & aArgs[nLength].Name = "Title"; aArgs[nLength].Value <<= xDoc->GetTitle( SFX_TITLE_DETECT ); xModel->attachResource( OUString(), aArgs ); - delete pNew; } return xDoc->GetErrorCode(); diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx index d24668bd59e2..d4db8a054e4a 100644 --- a/sfx2/source/dialog/tabdlg.cxx +++ b/sfx2/source/dialog/tabdlg.cxx @@ -372,8 +372,7 @@ void SfxTabDialog::dispose() m_pImpl.reset(); delete m_pSet; m_pSet = nullptr; - delete m_pOutSet; - m_pOutSet = nullptr; + m_pOutSet.reset(); delete m_pExampleSet; m_pExampleSet = nullptr; delete [] m_pRanges; @@ -487,7 +486,7 @@ void SfxTabDialog::Init_Impl(bool bFmtFlag) if ( m_pSet ) { m_pExampleSet = new SfxItemSet( *m_pSet ); - m_pOutSet = new SfxItemSet( *m_pSet->GetPool(), m_pSet->GetRanges() ); + m_pOutSet.reset(new SfxItemSet( *m_pSet->GetPool(), m_pSet->GetRanges() )); } } @@ -776,7 +775,7 @@ short SfxTabDialog::Ok() if ( !m_pOutSet ) { if ( m_pExampleSet ) - m_pOutSet = new SfxItemSet( *m_pExampleSet ); + m_pOutSet.reset(new SfxItemSet( *m_pExampleSet )); else if ( m_pSet ) m_pOutSet = m_pSet->Clone( false ); // without Items } @@ -1338,7 +1337,7 @@ void SfxTabDialog::SetInputSet( const SfxItemSet* pInSet ) if (!bSet && !m_pExampleSet && !m_pOutSet && m_pSet) { m_pExampleSet = new SfxItemSet( *m_pSet ); - m_pOutSet = new SfxItemSet( *m_pSet->GetPool(), m_pSet->GetRanges() ); + m_pOutSet.reset(new SfxItemSet( *m_pSet->GetPool(), m_pSet->GetRanges() )); } } diff --git a/sfx2/source/doc/printhelper.cxx b/sfx2/source/doc/printhelper.cxx index 8c6a9a4f2e2a..41c2f547c99b 100644 --- a/sfx2/source/doc/printhelper.cxx +++ b/sfx2/source/doc/printhelper.cxx @@ -345,7 +345,7 @@ void SfxPrintHelper::impl_setPrinter(const uno::Sequence< beans::PropertyValue > if ( aPrinterName != pPrinter->GetName() ) { - pPrinter = VclPtr<SfxPrinter>::Create( std::unique_ptr<SfxItemSet>(pPrinter->GetOptions().Clone()), aPrinterName ); + pPrinter = VclPtr<SfxPrinter>::Create( pPrinter->GetOptions().Clone(), aPrinterName ); nChangeFlags = SfxPrinterChangeFlags::PRINTER; } break; diff --git a/sfx2/source/view/printer.cxx b/sfx2/source/view/printer.cxx index 1036f63f872d..312241f71e63 100644 --- a/sfx2/source/view/printer.cxx +++ b/sfx2/source/view/printer.cxx @@ -157,7 +157,7 @@ VclPtr<SfxPrinter> SfxPrinter::Clone() const { if ( IsDefPrinter() ) { - VclPtr<SfxPrinter> pNewPrinter = VclPtr<SfxPrinter>::Create( std::unique_ptr<SfxItemSet>(GetOptions().Clone()) ); + VclPtr<SfxPrinter> pNewPrinter = VclPtr<SfxPrinter>::Create( GetOptions().Clone() ); pNewPrinter->SetJobSetup( GetJobSetup() ); pNewPrinter->SetPrinterProps( this ); pNewPrinter->SetMapMode( GetMapMode() ); @@ -208,7 +208,7 @@ SfxPrintOptionsDialog::SfxPrintOptionsDialog(vcl::Window *pParent, DBG_ASSERT( pPage, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" ); if( pPage ) { - pPage->Reset( pOptions ); + pPage->Reset( pOptions.get() ); SetHelpId( pPage->GetHelpId() ); pPage->Show(); } @@ -224,7 +224,7 @@ void SfxPrintOptionsDialog::dispose() { pDlgImpl.reset(); pPage.disposeAndClear(); - delete pOptions; + pOptions.reset(); ModalDialog::dispose(); } @@ -236,9 +236,9 @@ short SfxPrintOptionsDialog::Execute() short nRet = ModalDialog::Execute(); if ( nRet == RET_OK ) - pPage->FillItemSet( pOptions ); + pPage->FillItemSet( pOptions.get() ); else - pPage->Reset( pOptions ); + pPage->Reset( pOptions.get() ); return nRet; } diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx index 1d070d54e978..580a4b4295dd 100644 --- a/sfx2/source/view/viewprn.cxx +++ b/sfx2/source/view/viewprn.cxx @@ -380,7 +380,7 @@ void SfxPrinterController::jobFinished( css::view::PrintableState nState ) pDocPrt->SetJobSetup( getPrinter()->GetJobSetup() ); else { - VclPtr<SfxPrinter> pNewPrt = VclPtr<SfxPrinter>::Create( std::unique_ptr<SfxItemSet>(pDocPrt->GetOptions().Clone()), getPrinter()->GetName() ); + VclPtr<SfxPrinter> pNewPrt = VclPtr<SfxPrinter>::Create( pDocPrt->GetOptions().Clone(), getPrinter()->GetName() ); pNewPrt->SetJobSetup( getPrinter()->GetJobSetup() ); mpViewShell->SetPrinter( pNewPrt, SfxPrinterChangeFlags::PRINTER | SfxPrinterChangeFlags::JOBSETUP ); } @@ -438,7 +438,7 @@ IMPL_LINK_NOARG(SfxDialogExecutor_Impl, Execute, Button*, void) { DBG_ASSERT( _pSetupParent, "no dialog parent" ); if( _pSetupParent ) - _pOptions.reset( static_cast<SfxPrinter*>( _pSetupParent->GetPrinter() )->GetOptions().Clone() ); + _pOptions = static_cast<SfxPrinter*>( _pSetupParent->GetPrinter() )->GetOptions().Clone(); } assert(_pOptions); @@ -452,7 +452,7 @@ IMPL_LINK_NOARG(SfxDialogExecutor_Impl, Execute, Button*, void) pDlg->DisableHelp(); if ( pDlg->Execute() == RET_OK ) { - _pOptions.reset( pDlg->GetOptions().Clone() ); + _pOptions = pDlg->GetOptions().Clone(); } } @@ -765,7 +765,7 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq ) if ( pPrinterItem ) { // use PrinterName parameter to create a printer - pPrinter = VclPtr<SfxPrinter>::Create( std::unique_ptr<SfxItemSet>(pDocPrinter->GetOptions().Clone()), pPrinterItem->GetValue() ); + pPrinter = VclPtr<SfxPrinter>::Create( pDocPrinter->GetOptions().Clone(), pPrinterItem->GetValue() ); // if printer is unknown, it can't be used - now printer from document will be used if ( !pPrinter->IsKnown() ) diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx index 39efdb4c8845..0afc6093de15 100644 --- a/starmath/source/unomodel.cxx +++ b/starmath/source/unomodel.cxx @@ -589,7 +589,7 @@ void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any* if ( !sPrinterName.isEmpty() ) { - VclPtrInstance<SfxPrinter> pNewPrinter( std::unique_ptr<SfxItemSet>(pPrinter->GetOptions().Clone()), sPrinterName ); + VclPtrInstance<SfxPrinter> pNewPrinter( pPrinter->GetOptions().Clone(), sPrinterName ); if (pNewPrinter->IsKnown()) pDocSh->SetPrinter ( pNewPrinter ); else diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx index 398a74896084..784e23a33e22 100644 --- a/svl/source/items/itemset.cxx +++ b/svl/source/items/itemset.cxx @@ -1397,11 +1397,11 @@ bool SfxItemSet::Equals(const SfxItemSet &rCmp, bool bComparePool) const return true; } -SfxItemSet *SfxItemSet::Clone(bool bItems, SfxItemPool *pToPool ) const +std::unique_ptr<SfxItemSet> SfxItemSet::Clone(bool bItems, SfxItemPool *pToPool ) const { if (pToPool && pToPool != m_pPool) { - SfxItemSet *pNewSet = new SfxItemSet(*pToPool, m_pWhichRanges); + std::unique_ptr<SfxItemSet> pNewSet(new SfxItemSet(*pToPool, m_pWhichRanges)); if ( bItems ) { SfxWhichIter aIter(*pNewSet); @@ -1417,9 +1417,9 @@ SfxItemSet *SfxItemSet::Clone(bool bItems, SfxItemPool *pToPool ) const return pNewSet; } else - return bItems + return std::unique_ptr<SfxItemSet>(bItems ? new SfxItemSet(*this) - : new SfxItemSet(*m_pPool, m_pWhichRanges); + : new SfxItemSet(*m_pPool, m_pWhichRanges)); } void SfxItemSet::PutDirect(const SfxPoolItem &rItem) @@ -1692,17 +1692,17 @@ void SfxItemSet::DisableItem(sal_uInt16 nWhich) Put( SfxVoidItem(0), nWhich ); } -SfxItemSet *SfxAllItemSet::Clone(bool bItems, SfxItemPool *pToPool ) const +std::unique_ptr<SfxItemSet> SfxAllItemSet::Clone(bool bItems, SfxItemPool *pToPool ) const { if (pToPool && pToPool != m_pPool) { - SfxAllItemSet *pNewSet = new SfxAllItemSet( *pToPool ); + std::unique_ptr<SfxAllItemSet> pNewSet(new SfxAllItemSet( *pToPool )); if ( bItems ) pNewSet->Set( *this ); - return pNewSet; + return std::unique_ptr<SfxItemSet>(pNewSet.release()); // clang3.8 does not seem to be able to upcast std::unique_ptr } else - return bItems ? new SfxAllItemSet(*this) : new SfxAllItemSet(*m_pPool); + return std::unique_ptr<SfxItemSet>(bItems ? new SfxAllItemSet(*this) : new SfxAllItemSet(*m_pPool)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sdr/properties/defaultproperties.cxx b/svx/source/sdr/properties/defaultproperties.cxx index 56d23b6851bd..5a798b5b4e1c 100644 --- a/svx/source/sdr/properties/defaultproperties.cxx +++ b/svx/source/sdr/properties/defaultproperties.cxx @@ -51,18 +51,17 @@ namespace sdr } DefaultProperties::DefaultProperties(const DefaultProperties& rProps, SdrObject& rObj) - : BaseProperties(rObj), - mpItemSet(nullptr) + : BaseProperties(rObj) { if(rProps.mpItemSet) { // Clone may be to another model and thus another ItemPool. // SfxItemSet supports that thus we are able to Clone all // SfxItemState::SET items to the target pool. - mpItemSet.reset( + mpItemSet = rProps.mpItemSet->Clone( true, - &rObj.getSdrModelFromSdrObject().GetItemPool())); + &rObj.getSdrModelFromSdrObject().GetItemPool()); // React on ModelChange: If metric has changed, scale items. // As seen above, clone is supported, but scale is not included, diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index b8bdbe02fee0..6603f5a18e22 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -112,7 +112,7 @@ class GDIMetaFile; struct SvxShapeImpl { SvxShape& mrAntiImpl; - SfxItemSet* mpItemSet; + std::unique_ptr<SfxItemSet> mpItemSet; sal_uInt32 mnObjId; SvxShapeMaster* mpMaster; bool mbHasSdrObjectOwnership; @@ -131,7 +131,6 @@ struct SvxShapeImpl SvxShapeImpl( SvxShape& _rAntiImpl, ::osl::Mutex& _rMutex ) :mrAntiImpl( _rAntiImpl ) - ,mpItemSet( nullptr ) ,mnObjId( 0 ) ,mpMaster( nullptr ) ,mbHasSdrObjectOwnership( false ) @@ -1631,12 +1630,9 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any& { if( mpImpl->mpItemSet == nullptr ) { - pSet = mpImpl->mpItemSet = GetSdrObject()->GetMergedItemSet().Clone(); - } - else - { - pSet = mpImpl->mpItemSet; + mpImpl->mpItemSet = GetSdrObject()->GetMergedItemSet().Clone(); } + pSet = mpImpl->mpItemSet.get(); } else { @@ -1808,11 +1804,7 @@ void SAL_CALL SvxShape::setPropertyValues( const css::uno::Sequence< OUString >& void SvxShape::endSetPropertyValues() { mbIsMultiPropertyCall = false; - if( mpImpl->mpItemSet ) - { - delete mpImpl->mpItemSet; - mpImpl->mpItemSet = nullptr; - } + mpImpl->mpItemSet.reset(); } diff --git a/sw/inc/swatrset.hxx b/sw/inc/swatrset.hxx index 7392b33f09b5..18e6ad0e8585 100644 --- a/sw/inc/swatrset.hxx +++ b/sw/inc/swatrset.hxx @@ -172,7 +172,7 @@ public: SwAttrSet( SwAttrPool&, const sal_uInt16* nWhichPairTable ); SwAttrSet( const SwAttrSet& ); - virtual SfxItemSet* Clone(bool bItems = true, SfxItemPool *pToPool = nullptr) const override; + virtual std::unique_ptr<SfxItemSet> Clone(bool bItems = true, SfxItemPool *pToPool = nullptr) const override; bool Put_BC( const SfxPoolItem& rAttr, SwAttrSet* pOld, SwAttrSet* pNew ); bool Put_BC( const SfxItemSet& rSet, SwAttrSet* pOld, SwAttrSet* pNew ); diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 20e559088dd6..c06da717c749 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -1981,7 +1981,7 @@ void SwUiWriterTest::testTdf79236() //Getting some paragraph style SwTextFormatColl* pTextFormat = pDoc->FindTextFormatCollByName("Text Body"); const SwAttrSet& rAttrSet = pTextFormat->GetAttrSet(); - SfxItemSet* pNewSet = rAttrSet.Clone(); + std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone(); sal_uInt16 initialCount = pNewSet->Count(); SvxAdjustItem AdjustItem = rAttrSet.GetAdjust(); SvxAdjust initialAdjust = AdjustItem.GetAdjust(); diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx index 91c4cd7b0a15..bd0e3c5e92bb 100644 --- a/sw/source/core/attr/swatrset.cxx +++ b/sw/source/core/attr/swatrset.cxx @@ -148,17 +148,17 @@ SwAttrSet::SwAttrSet( const SwAttrSet& rSet ) { } -SfxItemSet* SwAttrSet::Clone( bool bItems, SfxItemPool *pToPool ) const +std::unique_ptr<SfxItemSet> SwAttrSet::Clone( bool bItems, SfxItemPool *pToPool ) const { if ( pToPool && pToPool != GetPool() ) { SwAttrPool* pAttrPool = dynamic_cast< SwAttrPool* >(pToPool); - SfxItemSet* pTmpSet = nullptr; + std::unique_ptr<SfxItemSet> pTmpSet; if ( !pAttrPool ) pTmpSet = SfxItemSet::Clone( bItems, pToPool ); else { - pTmpSet = new SwAttrSet( *pAttrPool, GetRanges() ); + pTmpSet.reset(new SwAttrSet( *pAttrPool, GetRanges() )); if ( bItems ) { SfxWhichIter aIter(*pTmpSet); @@ -175,9 +175,10 @@ SfxItemSet* SwAttrSet::Clone( bool bItems, SfxItemPool *pToPool ) const return pTmpSet; } else - return bItems + return std::unique_ptr<SfxItemSet>( + bItems ? new SwAttrSet( *this ) - : new SwAttrSet( *GetPool(), GetRanges() ); + : new SwAttrSet( *GetPool(), GetRanges() )); } bool SwAttrSet::Put_BC( const SfxPoolItem& rAttr, diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index 4430547b343b..58e44dc5346d 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -735,7 +735,7 @@ lcl_InsertLabel(SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable, /* #i6447#: Only the selected items are copied from the old format. */ - SfxItemSet* pNewSet = pNewFormat->GetAttrSet().Clone(); + std::unique_ptr<SfxItemSet> pNewSet = pNewFormat->GetAttrSet().Clone(); // Copy only the set attributes. // The others should apply from the Templates. @@ -868,7 +868,7 @@ lcl_InsertLabel(SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable, else pOldFormat->SetFormatAttr( *pNewSet ); - delete pNewSet; + pNewSet.reset(); // Have only the FlyFrames created. // We leave this to established methods (especially for InCntFlys). @@ -1054,7 +1054,7 @@ lcl_InsertDrawLabel( SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable // The TextAttribute needs to be destroyed. // Unfortunately, this also destroys the Format next to the Frames. // To avoid this, we disconnect the attribute from the Format. - SfxItemSet* pNewSet = pOldFormat->GetAttrSet().Clone( false ); + std::unique_ptr<SfxItemSet> pNewSet = pOldFormat->GetAttrSet().Clone( false ); // Protect the Frame's size and position if ( rSdrObj.IsMoveProtect() || rSdrObj.IsResizeProtect() ) @@ -1174,7 +1174,7 @@ lcl_InsertDrawLabel( SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable else pOldFormat->SetFormatAttr( *pNewSet ); - delete pNewSet; + pNewSet.reset(); // Have only the FlyFrames created. // We leave this to established methods (especially for InCntFlys). diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx index 7e958cd7be8c..559216676999 100644 --- a/sw/source/core/text/txtfld.cxx +++ b/sw/source/core/text/txtfld.cxx @@ -422,10 +422,10 @@ static void checkApplyParagraphMarkFormatToNumbering( SwFont* pNumFnt, SwTextFor std::shared_ptr<SfxItemSet> pSet(hint->GetAutoFormat().GetStyleHandle()); // Check each item and in case it should be ignored, then clear it. - std::shared_ptr<SfxItemSet> pCleanedSet; + std::unique_ptr<SfxItemSet> pCleanedSet; if (pSet.get()) { - pCleanedSet.reset(pSet->Clone()); + pCleanedSet = pSet->Clone(); SfxItemIter aIter(*pSet); const SfxPoolItem* pItem = aIter.GetCurItem(); diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index d7b70e8a297d..2db0657c3fe1 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -880,7 +880,7 @@ void SwpHints::BuildPortions( SwTextNode& rNode, SwTextAttr& rNewHint, // #i81764# This should not be applied for no length attributes!!! <-- if ( !bNoLengthAttribute && rNode.HasSwAttrSet() && pNewStyle->Count() ) { - SfxItemSet* pNewSet = nullptr; + std::unique_ptr<SfxItemSet> pNewSet; SfxItemIter aIter2( *pNewStyle ); const SfxPoolItem* pItem = aIter2.GetCurItem(); @@ -910,8 +910,6 @@ void SwpHints::BuildPortions( SwTextNode& rNode, SwTextAttr& rNewHint, pNewStyle = rNode.getIDocumentStyleAccess().getAutomaticStyle( *pNewSet, IStyleAccess::AUTO_STYLE_CHAR ); else pNewStyle.reset(); - - delete pNewSet; } } diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index 1ca1123f3724..8fae25735fcb 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -328,7 +328,7 @@ static bool lcl_HaveCommonAttributes( IStyleAccess& rStyleAccess, { bool bRet = false; - SfxItemSet* pNewSet = nullptr; + std::unique_ptr<SfxItemSet> pNewSet; if ( !pSet1 ) { @@ -363,7 +363,6 @@ static bool lcl_HaveCommonAttributes( IStyleAccess& rStyleAccess, { if ( pNewSet->Count() ) pStyleHandle = rStyleAccess.getAutomaticStyle( *pNewSet, IStyleAccess::AUTO_STYLE_CHAR ); - delete pNewSet; bRet = true; } diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index 18047a1ca874..6c6d2c35f846 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -1940,9 +1940,9 @@ SwUnoCursorHelper::GetPropertyStates( //try again to find out if a value has been inherited if( beans::PropertyState_DIRECT_VALUE == pStates[i] ) { - if (!pSetParent.get()) + if (!pSetParent) { - pSetParent.reset( pSet->Clone( false ) ); + pSetParent = pSet->Clone( false ); // #i63870# SwUnoCursorHelper::GetCursorAttr( rPaM, *pSetParent, true, false ); diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx b/sw/source/uibase/uno/SwXDocumentSettings.cxx index 132fddc777de..f665bfefc0b0 100644 --- a/sw/source/uibase/uno/SwXDocumentSettings.cxx +++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx @@ -398,7 +398,7 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf SfxPrinter* pPrinter = mpDoc->getIDocumentDeviceAccess().getPrinter( true ); if ( pPrinter->GetName() != sPrinterName ) { - VclPtrInstance<SfxPrinter> pNewPrinter( std::unique_ptr<SfxItemSet>(pPrinter->GetOptions().Clone()), sPrinterName ); + VclPtrInstance<SfxPrinter> pNewPrinter( pPrinter->GetOptions().Clone(), sPrinterName ); assert (! pNewPrinter->isDisposed() ); if( pNewPrinter->IsKnown() ) { |