diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-13 11:57:33 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-13 12:40:42 +0100 |
commit | 00431a8afcad08da11835131c2cd423d7f8cd115 (patch) | |
tree | 784ae98f19af2d303e9141d6cfe5c9151864a558 /cui | |
parent | fd877edc1822816be04b2e2fa0f883c00b5d2fb0 (diff) |
loplugin:useuniqueptr in SvxEntries
Change-Id: I4e105326ddba11822beb9affe97196c77a5baf4b
Reviewed-on: https://gerrit.libreoffice.org/51203
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/customize/SvxMenuConfigPage.cxx | 2 | ||||
-rw-r--r-- | cui/source/customize/cfg.cxx | 41 | ||||
-rw-r--r-- | cui/source/inc/cfg.hxx | 18 |
3 files changed, 24 insertions, 37 deletions
diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx index 75fbaa16378b..202ffaebef8c 100644 --- a/cui/source/customize/SvxMenuConfigPage.cxx +++ b/cui/source/customize/SvxMenuConfigPage.cxx @@ -320,7 +320,7 @@ IMPL_LINK( SvxMenuConfigPage, GearHdl, MenuButton *, pButton, void ) if ( pDialog->Execute() == RET_OK ) { - GetSaveInData()->SetEntries( pDialog->GetEntries() ); + GetSaveInData()->SetEntries( pDialog->ReleaseEntries() ); ReloadTopLevelListBox( pDialog->GetSelectedEntry() ); GetSaveInData()->SetModified(); } diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index e90bfa358621..5762979a7528 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -440,13 +440,9 @@ MenuSaveInData::GetEntries() } void -MenuSaveInData::SetEntries( SvxEntries* pNewEntries ) +MenuSaveInData::SetEntries( std::unique_ptr<SvxEntries> pNewEntries ) { - // delete old menu hierarchy first - delete pRootEntry->GetEntries(); - - // now set new menu hierarchy - pRootEntry->SetEntries( pNewEntries ); + pRootEntry->SetEntries( std::move(pNewEntries) ); } bool SaveInData::LoadSubMenus( const uno::Reference< container::XIndexAccess >& xMenuSettings, @@ -849,10 +845,9 @@ SvxEntries* ContextMenuSaveInData::GetEntries() return m_pRootEntry->GetEntries(); } -void ContextMenuSaveInData::SetEntries( SvxEntries* pNewEntries ) +void ContextMenuSaveInData::SetEntries( std::unique_ptr<SvxEntries> pNewEntries ) { - delete m_pRootEntry->GetEntries(); - m_pRootEntry->SetEntries( pNewEntries ); + m_pRootEntry->SetEntries( std::move(pNewEntries) ); } bool ContextMenuSaveInData::HasURL( const OUString& rURL ) @@ -1900,7 +1895,7 @@ SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog( // Copy the entries list passed in if ( entries != nullptr ) { - mpEntries = new SvxEntries; + mpEntries.reset( new SvxEntries ); for (auto const& entry : *entries) { SvTreeListEntry* pLBEntry = @@ -1921,7 +1916,7 @@ SvxMainMenuOrganizerDialog::SvxMainMenuOrganizerDialog( OUString prefix = CuiResId( RID_SVXSTR_NEW_MENU ); OUString newname = SvxConfigPageHelper::generateCustomName( prefix, entries ); - OUString newurl = SvxConfigPageHelper::generateCustomMenuURL( mpEntries ); + OUString newurl = SvxConfigPageHelper::generateCustomMenuURL( mpEntries.get() ); SvxConfigEntry* pNewEntryData = new SvxConfigEntry( newname, newurl, true, /*bParentData*/false ); @@ -2036,9 +2031,9 @@ IMPL_LINK( SvxMainMenuOrganizerDialog, MoveHdl, Button *, pButton, void ) SvxConfigEntry* pTargetData = static_cast<SvxConfigEntry*>(pTargetEntry->GetUserData()); - SvxEntries::iterator iter1 = GetEntries()->begin(); - SvxEntries::iterator iter2 = GetEntries()->begin(); - SvxEntries::const_iterator end = GetEntries()->end(); + SvxEntries::iterator iter1 = mpEntries->begin(); + SvxEntries::iterator iter2 = mpEntries->begin(); + SvxEntries::const_iterator end = mpEntries->end(); // Advance the iterators to the positions of the source and target while (*iter1 != pSourceData && ++iter1 != end) ; @@ -2084,19 +2079,15 @@ SvxConfigEntry::SvxConfigEntry( const OUString& rDisplayName, { if (bPopUp) { - mpEntries = new SvxEntries; + mpEntries.reset( new SvxEntries ); } } SvxConfigEntry::~SvxConfigEntry() { - if ( mpEntries != nullptr ) + for (auto const& entry : *mpEntries) { - for (auto const& entry : *mpEntries) - { - delete entry; - } - delete mpEntries; + delete entry; } } @@ -2406,13 +2397,9 @@ SvxEntries* ToolbarSaveInData::GetEntries() } void -ToolbarSaveInData::SetEntries( SvxEntries* pNewEntries ) +ToolbarSaveInData::SetEntries( std::unique_ptr<SvxEntries> pNewEntries ) { - // delete old menu hierarchy first - delete pRootEntry->GetEntries(); - - // now set new menu hierarchy - pRootEntry->SetEntries( pNewEntries ); + pRootEntry->SetEntries( std::move(pNewEntries) ); } bool diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx index 6f79414f0671..00e2dcc4b27c 100644 --- a/cui/source/inc/cfg.hxx +++ b/cui/source/inc/cfg.hxx @@ -175,7 +175,7 @@ public: virtual bool HasURL( const OUString& aURL ) = 0; virtual bool HasSettings() = 0; virtual SvxEntries* GetEntries() = 0; - virtual void SetEntries( SvxEntries* ) = 0; + virtual void SetEntries( std::unique_ptr<SvxEntries> ) = 0; virtual void Reset() = 0; virtual bool Apply() = 0; }; @@ -214,7 +214,7 @@ public: /// methods inherited from SaveInData SvxEntries* GetEntries() override; - void SetEntries( SvxEntries* ) override; + void SetEntries( std::unique_ptr<SvxEntries> ) override; bool HasURL( const OUString& ) override { return false; } bool HasSettings() override { return m_xMenuSettings.is(); } void Reset() override; @@ -236,7 +236,7 @@ public: virtual ~ContextMenuSaveInData() override; SvxEntries* GetEntries() override; - void SetEntries( SvxEntries* pNewEntries ) override; + void SetEntries( std::unique_ptr<SvxEntries> pNewEntries ) override; bool HasSettings() override; bool HasURL( const OUString& rURL ) override; void Reset() override; @@ -268,7 +268,7 @@ private: css::uno::Reference< css::graphic::XGraphic > xBackupGraphic; - SvxEntries *mpEntries; + std::unique_ptr<SvxEntries> mpEntries; public: @@ -307,8 +307,8 @@ public: bool IsBinding() const { return !bPopUp; } bool IsSeparator() const { return nId == 0; } - SvxEntries* GetEntries() const { return mpEntries; } - void SetEntries( SvxEntries* entries ) { mpEntries = entries; } + SvxEntries* GetEntries() const { return mpEntries.get(); } + void SetEntries( std::unique_ptr<SvxEntries> entries ) { mpEntries = std::move(entries); } void SetMain() { bIsMain = true; } bool IsMain() { return bIsMain; } @@ -501,7 +501,7 @@ class SvxMainMenuOrganizerDialog : public ModalDialog VclPtr<PushButton> m_pMoveUpButton; VclPtr<PushButton> m_pMoveDownButton; - SvxEntries* mpEntries; + std::unique_ptr<SvxEntries> mpEntries; SvTreeListEntry* pNewMenuEntry; bool bModified; @@ -518,7 +518,7 @@ public: virtual ~SvxMainMenuOrganizerDialog() override; virtual void dispose() override; - SvxEntries* GetEntries() { return mpEntries;} + std::unique_ptr<SvxEntries> ReleaseEntries() { return std::move(mpEntries);} SvxConfigEntry* GetSelectedEntry(); }; @@ -561,7 +561,7 @@ public: sal_Int32 GetSystemStyle( const OUString& rResourceURL ); SvxEntries* GetEntries() override; - void SetEntries( SvxEntries* ) override; + void SetEntries( std::unique_ptr<SvxEntries> ) override; bool HasSettings() override; bool HasURL( const OUString& rURL ) override; void Reset() override; |