[Libreoffice-commits] core.git: 2 commits - sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Jul 30 06:21:33 UTC 2018


 sw/source/ui/index/cntex.cxx        |   22 +++++-----
 sw/source/ui/index/cnttab.cxx       |   76 ++++++++++++++----------------------
 sw/source/ui/misc/glossary.cxx      |    6 +-
 sw/source/uibase/inc/glossary.hxx   |    2 
 sw/source/uibase/inc/swuicnttab.hxx |   17 ++++----
 5 files changed, 56 insertions(+), 67 deletions(-)

New commits:
commit 47220de23b44aacf2bf3a1eff592972c3d1da2fc
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 26 16:39:41 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Jul 30 08:21:19 2018 +0200

    loplugin:useuniqueptr in SwGlossaryDlg
    
    Change-Id: I46df74af9eae2cedc7121d6454e92faf03321c63
    Reviewed-on: https://gerrit.libreoffice.org/58240
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/ui/misc/glossary.cxx b/sw/source/ui/misc/glossary.cxx
index a7badfffdfea..386377e6c476 100644
--- a/sw/source/ui/misc/glossary.cxx
+++ b/sw/source/ui/misc/glossary.cxx
@@ -247,7 +247,7 @@ SwGlossaryDlg::~SwGlossaryDlg()
 void SwGlossaryDlg::dispose()
 {
     m_pCategoryBox->Clear();
-    delete pExampleFrame;
+    pExampleFrame.reset();
     m_pInsertTipCB.clear();
     m_pNameED.clear();
     m_pShortNameLbl.clear();
@@ -1067,8 +1067,8 @@ void SwGlossaryDlg::ShowPreview()
     if (!pExampleFrame)
     {
         Link<SwOneExampleFrame&,void> aLink(LINK(this, SwGlossaryDlg, PreviewLoadedHdl));
-        pExampleFrame = new SwOneExampleFrame( *m_pExampleWIN,
-                        EX_SHOW_ONLINE_LAYOUT, &aLink );
+        pExampleFrame.reset(new SwOneExampleFrame( *m_pExampleWIN,
+                        EX_SHOW_ONLINE_LAYOUT, &aLink ));
     }
 
     ShowAutoText(::GetCurrGlosGroup(), m_pShortNameEdit->GetText());
diff --git a/sw/source/uibase/inc/glossary.hxx b/sw/source/uibase/inc/glossary.hxx
index d6bf120c5290..9b6e0b17dc28 100644
--- a/sw/source/uibase/inc/glossary.hxx
+++ b/sw/source/uibase/inc/glossary.hxx
@@ -106,7 +106,7 @@ class SwGlossaryDlg : public SvxStandardDialog
     OUString        sReadonlyPath;
 
     css::uno::Reference< css::text::XAutoTextContainer2 > m_xAutoText;
-    SwOneExampleFrame*  pExampleFrame;
+    std::unique_ptr<SwOneExampleFrame>  pExampleFrame;
 
     SwGlossaryHdl*  pGlossaryHdl;
 
commit c14b9ccc3d274644a721398edc7e336b5463cf81
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 26 16:37:13 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Jul 30 08:21:10 2018 +0200

    loplugin:useuniqueptr in SwMultiTOXTabDialog
    
    and use a std::vector and a custom struct for storing stuff instead of a
    rrays and a separate count field
    
    Change-Id: Ic1063ed0bfdc06f83a01d18503ccf6f9503f5b9d
    Reviewed-on: https://gerrit.libreoffice.org/58239
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/ui/index/cntex.cxx b/sw/source/ui/index/cntex.cxx
index 358bfb6e0094..5d796bcbda59 100644
--- a/sw/source/ui/index/cntex.cxx
+++ b/sw/source/ui/index/cntex.cxx
@@ -114,7 +114,7 @@ IMPL_LINK_NOARG(SwMultiTOXTabDialog, CreateExample_Hdl, SwOneExampleFrame&, void
         {
             OUString sTmp = "IndexSection_" + OUString::number(i);
             uno::Any aSection = xSections->getByName( sTmp );
-            aSection >>= m_pxIndexSectionsArray[i]->xContainerSection;
+            aSection >>= m_vTypeData[i].m_pxIndexSections->xContainerSection;
          }
          uno::Reference< text::XDocumentIndexesSupplier >  xIdxSupp(xModel, uno::UNO_QUERY);
          uno::Reference< container::XIndexAccess >  xIdxs = xIdxSupp->getDocumentIndexes();
@@ -154,17 +154,17 @@ void SwMultiTOXTabDialog::CreateOrUpdateExample(
             "com.sun.star.text.Bibliography"
         };
 
-         OSL_ENSURE(m_pxIndexSectionsArray[nTOXIndex] &&
-                        m_pxIndexSectionsArray[nTOXIndex]->xContainerSection.is(),
+         OSL_ENSURE(m_vTypeData[nTOXIndex].m_pxIndexSections &&
+                        m_vTypeData[nTOXIndex].m_pxIndexSections->xContainerSection.is(),
                             "Section not created");
          uno::Reference< frame::XModel > & xModel = m_pExampleFrame->GetModel();
          bool bInitialCreate = true;
-         if(!m_pxIndexSectionsArray[nTOXIndex]->xDocumentIndex.is())
+         if(!m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex.is())
          {
              bInitialCreate = true;
-             if(!m_pxIndexSectionsArray[nTOXIndex]->xContainerSection.is())
+             if(!m_vTypeData[nTOXIndex].m_pxIndexSections->xContainerSection.is())
                  throw uno::RuntimeException();
-             uno::Reference< text::XTextRange >  xAnchor = m_pxIndexSectionsArray[nTOXIndex]->xContainerSection->getAnchor();
+             uno::Reference< text::XTextRange >  xAnchor = m_vTypeData[nTOXIndex].m_pxIndexSections->xContainerSection->getAnchor();
              xAnchor = xAnchor->getStart();
              uno::Reference< text::XTextCursor >  xCursor = xAnchor->getText()->createTextCursorByRange(xAnchor);
 
@@ -172,21 +172,21 @@ void SwMultiTOXTabDialog::CreateOrUpdateExample(
 
              OUString sIndexTypeName(OUString::createFromAscii( IndexServiceNames[
                     nTOXIndex <= TOX_AUTHORITIES ? nTOXIndex : TOX_USER] ));
-             m_pxIndexSectionsArray[nTOXIndex]->xDocumentIndex.set(xFact->createInstance(sIndexTypeName), uno::UNO_QUERY);
-             uno::Reference< text::XTextContent >  xContent(m_pxIndexSectionsArray[nTOXIndex]->xDocumentIndex, uno::UNO_QUERY);
+             m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex.set(xFact->createInstance(sIndexTypeName), uno::UNO_QUERY);
+             uno::Reference< text::XTextContent >  xContent(m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex, uno::UNO_QUERY);
              uno::Reference< text::XTextRange >  xRg(xCursor, uno::UNO_QUERY);
              xCursor->getText()->insertTextContent(xRg, xContent, false);
          }
          for(sal_uInt16 i = 0 ; i <= TOX_AUTHORITIES; i++)
          {
-            uno::Reference< beans::XPropertySet >  xSectPr(m_pxIndexSectionsArray[i]->xContainerSection, uno::UNO_QUERY);
+            uno::Reference< beans::XPropertySet >  xSectPr(m_vTypeData[i].m_pxIndexSections->xContainerSection, uno::UNO_QUERY);
             if(xSectPr.is())
             {
                 xSectPr->setPropertyValue(UNO_NAME_IS_VISIBLE, makeAny(i == nTOXIndex));
             }
          }
          // set properties
-         uno::Reference< beans::XPropertySet >  xIdxProps(m_pxIndexSectionsArray[nTOXIndex]->xDocumentIndex, uno::UNO_QUERY);
+         uno::Reference< beans::XPropertySet >  xIdxProps(m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex, uno::UNO_QUERY);
          uno::Reference< beans::XPropertySetInfo >  xInfo = xIdxProps->getPropertySetInfo();
          SwTOXDescription& rDesc = GetTOXDescription(m_eCurrentTOXType);
          SwTOIOptions nIdxOptions = rDesc.GetIndexOptions();
@@ -398,7 +398,7 @@ void SwMultiTOXTabDialog::CreateOrUpdateExample(
                     pForm->GetTemplate(i + nOffset));
             }
         }
-        m_pxIndexSectionsArray[nTOXIndex]->xDocumentIndex->update();
+        m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex->update();
 
     }
     catch (const Exception&)
diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index c24579c5ccc1..48517308463e 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -237,21 +237,16 @@ SwMultiTOXTabDialog::SwMultiTOXTabDialog(vcl::Window* pParent, const SfxItemSet&
     m_eCurrentTOXType.nIndex = 0;
 
     const sal_uInt16 nUserTypeCount = m_rWrtShell.GetTOXTypeCount(TOX_USER);
-    m_nTypeCount = nUserTypeCount + 6;
-    m_pFormArray = new SwForm*[m_nTypeCount];
-    m_pDescriptionArray = new SwTOXDescription*[m_nTypeCount];
-    m_pxIndexSectionsArray = new SwIndexSections_Impl*[m_nTypeCount];
+    m_vTypeData.resize(nUserTypeCount + 6);
     //the standard user index is on position TOX_USER
     //all user indexes follow after position TOX_AUTHORITIES
     if(pCurTOX)
     {
         m_bEditTOX = true;
     }
-    for(int i = m_nTypeCount - 1; i > -1; i--)
+    for(int i = m_vTypeData.size() - 1; i > -1; i--)
     {
-        m_pFormArray[i] = nullptr;
-        m_pDescriptionArray[i] = nullptr;
-        m_pxIndexSectionsArray[i] = new SwIndexSections_Impl;
+        m_vTypeData[i].m_pxIndexSections.reset(new SwIndexSections_Impl);
         if(pCurTOX)
         {
             m_eCurrentTOXType.eType = pCurTOX->GetType();
@@ -270,8 +265,8 @@ SwMultiTOXTabDialog::SwMultiTOXTabDialog(vcl::Window* pParent, const SfxItemSet&
                     }
                 }
             }
-            m_pFormArray[nArrayIndex] = new SwForm(pCurTOX->GetTOXForm());
-            m_pDescriptionArray[nArrayIndex] = CreateTOXDescFromTOXBase(pCurTOX);
+            m_vTypeData[nArrayIndex].m_pForm.reset(new SwForm(pCurTOX->GetTOXForm()));
+            m_vTypeData[nArrayIndex].m_pDescription = CreateTOXDescFromTOXBase(pCurTOX);
             if(TOX_AUTHORITIES == m_eCurrentTOXType.eType)
             {
                 const SwAuthorityFieldType* pFType = static_cast<const SwAuthorityFieldType*>(
@@ -283,12 +278,12 @@ SwMultiTOXTabDialog::SwMultiTOXTabDialog(vcl::Window* pParent, const SfxItemSet&
                         sBrackets += OUStringLiteral1(pFType->GetPrefix());
                     if(pFType->GetSuffix())
                         sBrackets += OUStringLiteral1(pFType->GetSuffix());
-                    m_pDescriptionArray[nArrayIndex]->SetAuthBrackets(sBrackets);
-                    m_pDescriptionArray[nArrayIndex]->SetAuthSequence(pFType->IsSequence());
+                    m_vTypeData[nArrayIndex].m_pDescription->SetAuthBrackets(sBrackets);
+                    m_vTypeData[nArrayIndex].m_pDescription->SetAuthSequence(pFType->IsSequence());
                 }
                 else
                 {
-                    m_pDescriptionArray[nArrayIndex]->SetAuthBrackets("[]");
+                    m_vTypeData[nArrayIndex].m_pDescription->SetAuthBrackets("[]");
                 }
             }
         }
@@ -327,18 +322,9 @@ void SwMultiTOXTabDialog::dispose()
     // fdo#38515 Avoid setting focus on deleted controls in the destructors
     EnableInput( false );
 
-    for(sal_uInt16 i = 0; i < m_nTypeCount; i++)
-    {
-        delete m_pFormArray[i];
-        delete m_pDescriptionArray[i];
-        delete m_pxIndexSectionsArray[i];
-    }
-    delete[] m_pxIndexSectionsArray;
-
-    delete[] m_pFormArray;
-    delete[] m_pDescriptionArray;
-    delete m_pMgr;
-    delete m_pExampleFrame;
+    m_vTypeData.clear();
+    m_pMgr.reset();
+    m_pExampleFrame.reset();
     m_pExampleContainerWIN.clear();
     m_pShowExampleCB.clear();
     SfxTabDialog::dispose();
@@ -375,10 +361,10 @@ short SwMultiTOXTabDialog::Ok()
     SwTOXBase aNewDef(*m_rWrtShell.GetDefaultTOXBase( m_eCurrentTOXType.eType, true ));
 
     const sal_uInt16 nIndex = m_eCurrentTOXType.GetFlatIndex();
-    if(m_pFormArray[nIndex])
+    if(m_vTypeData[nIndex].m_pForm)
     {
-        rDesc.SetForm(*m_pFormArray[nIndex]);
-        aNewDef.SetTOXForm(*m_pFormArray[nIndex]);
+        rDesc.SetForm(*m_vTypeData[nIndex].m_pForm);
+        aNewDef.SetTOXForm(*m_vTypeData[nIndex].m_pForm);
     }
     rDesc.ApplyTo(aNewDef);
     if(!m_bGlobalFlag)
@@ -397,26 +383,26 @@ short SwMultiTOXTabDialog::Ok()
 SwForm* SwMultiTOXTabDialog::GetForm(CurTOXType eType)
 {
     const sal_uInt16 nIndex = eType.GetFlatIndex();
-    if(!m_pFormArray[nIndex])
-        m_pFormArray[nIndex] = new SwForm(eType.eType);
-    return m_pFormArray[nIndex];
+    if(!m_vTypeData[nIndex].m_pForm)
+        m_vTypeData[nIndex].m_pForm.reset(new SwForm(eType.eType));
+    return m_vTypeData[nIndex].m_pForm.get();
 }
 
 SwTOXDescription& SwMultiTOXTabDialog::GetTOXDescription(CurTOXType eType)
 {
     const sal_uInt16 nIndex = eType.GetFlatIndex();
-    if(!m_pDescriptionArray[nIndex])
+    if(!m_vTypeData[nIndex].m_pDescription)
     {
         const SwTOXBase* pDef = m_rWrtShell.GetDefaultTOXBase( eType.eType );
         if(pDef)
-            m_pDescriptionArray[nIndex] = CreateTOXDescFromTOXBase(pDef);
+            m_vTypeData[nIndex].m_pDescription = CreateTOXDescFromTOXBase(pDef);
         else
         {
-            m_pDescriptionArray[nIndex] = new SwTOXDescription(eType.eType);
+            m_vTypeData[nIndex].m_pDescription.reset(new SwTOXDescription(eType.eType));
             if(eType.eType == TOX_USER)
-                m_pDescriptionArray[nIndex]->SetTitle(m_sUserDefinedIndex);
+                m_vTypeData[nIndex].m_pDescription->SetTitle(m_sUserDefinedIndex);
             else
-                m_pDescriptionArray[nIndex]->SetTitle(
+                m_vTypeData[nIndex].m_pDescription->SetTitle(
                     m_rWrtShell.GetTOXType(eType.eType, 0)->GetTypeName());
         }
         if(TOX_AUTHORITIES == eType.eType)
@@ -425,26 +411,26 @@ SwTOXDescription& SwMultiTOXTabDialog::GetTOXDescription(CurTOXType eType)
                                             m_rWrtShell.GetFieldType(SwFieldIds::TableOfAuthorities, aEmptyOUStr));
             if(pFType)
             {
-                m_pDescriptionArray[nIndex]->SetAuthBrackets(OUStringLiteral1(pFType->GetPrefix()) +
+                m_vTypeData[nIndex].m_pDescription->SetAuthBrackets(OUStringLiteral1(pFType->GetPrefix()) +
                                                   OUStringLiteral1(pFType->GetSuffix()));
-                m_pDescriptionArray[nIndex]->SetAuthSequence(pFType->IsSequence());
+                m_vTypeData[nIndex].m_pDescription->SetAuthSequence(pFType->IsSequence());
             }
             else
             {
-                m_pDescriptionArray[nIndex]->SetAuthBrackets("[]");
+                m_vTypeData[nIndex].m_pDescription->SetAuthBrackets("[]");
             }
         }
         else if(TOX_INDEX == eType.eType)
-            m_pDescriptionArray[nIndex]->SetMainEntryCharStyle(SwResId(STR_POOLCHR_IDX_MAIN_ENTRY));
+            m_vTypeData[nIndex].m_pDescription->SetMainEntryCharStyle(SwResId(STR_POOLCHR_IDX_MAIN_ENTRY));
 
     }
-    return *m_pDescriptionArray[nIndex];
+    return *m_vTypeData[nIndex].m_pDescription;
 }
 
-SwTOXDescription* SwMultiTOXTabDialog::CreateTOXDescFromTOXBase(
+std::unique_ptr<SwTOXDescription> SwMultiTOXTabDialog::CreateTOXDescFromTOXBase(
             const SwTOXBase*pCurTOX)
 {
-    SwTOXDescription * pDesc = new SwTOXDescription(pCurTOX->GetType());
+    std::unique_ptr<SwTOXDescription> pDesc(new SwTOXDescription(pCurTOX->GetType()));
     for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
         pDesc->SetStyleNames(pCurTOX->GetStyleNames(i), i);
     pDesc->SetAutoMarkURL(m_rWrtShell.GetTOIAutoMarkURL());
@@ -494,8 +480,8 @@ IMPL_LINK_NOARG( SwMultiTOXTabDialog, ShowPreviewHdl, Button*, void )
             else
             {
                 Link<SwOneExampleFrame&,void> aLink(LINK(this, SwMultiTOXTabDialog, CreateExample_Hdl));
-                m_pExampleFrame = new SwOneExampleFrame(
-                        *m_pExampleContainerWIN, EX_SHOW_ONLINE_LAYOUT, &aLink, &sTemplate);
+                m_pExampleFrame.reset(new SwOneExampleFrame(
+                        *m_pExampleContainerWIN, EX_SHOW_ONLINE_LAYOUT, &aLink, &sTemplate));
 
                 if(!m_pExampleFrame->IsServiceAvailable())
                 {
diff --git a/sw/source/uibase/inc/swuicnttab.hxx b/sw/source/uibase/inc/swuicnttab.hxx
index 892d88256a14..0941e1bab00c 100644
--- a/sw/source/uibase/inc/swuicnttab.hxx
+++ b/sw/source/uibase/inc/swuicnttab.hxx
@@ -65,7 +65,7 @@ class SwMultiTOXTabDialog : public SfxTabDialog
 {
     VclPtr<vcl::Window>     m_pExampleContainerWIN;
     VclPtr<CheckBox>        m_pShowExampleCB;
-    SwTOXMgr*               m_pMgr;
+    std::unique_ptr<SwTOXMgr> m_pMgr;
     SwWrtShell&             m_rWrtShell;
 
     sal_uInt16              m_nSelectId;
@@ -73,18 +73,21 @@ class SwMultiTOXTabDialog : public SfxTabDialog
     sal_uInt16              m_nBackGroundId;
     sal_uInt16              m_nEntriesId;
 
-    SwOneExampleFrame*      m_pExampleFrame;
+    std::unique_ptr<SwOneExampleFrame> m_pExampleFrame;
 
-    SwTOXDescription**      m_pDescriptionArray;
-    SwForm**                m_pFormArray;
-    SwIndexSections_Impl**  m_pxIndexSectionsArray;
+    struct TypeData
+    {
+        std::unique_ptr<SwForm> m_pForm;
+        std::unique_ptr<SwTOXDescription> m_pDescription;
+        std::unique_ptr<SwIndexSections_Impl> m_pxIndexSections;
+    };
+    std::vector<TypeData>   m_vTypeData;
 
     SwTOXBase*              m_pParamTOXBase;
 
     CurTOXType              m_eCurrentTOXType;
 
     OUString                m_sUserDefinedIndex;
-    sal_uInt16              m_nTypeCount;
     sal_uInt16              m_nInitialTOXType;
 
     bool                m_bEditTOX;
@@ -92,7 +95,7 @@ class SwMultiTOXTabDialog : public SfxTabDialog
     bool                m_bGlobalFlag;
 
     virtual short       Ok() override;
-    SwTOXDescription*   CreateTOXDescFromTOXBase(const SwTOXBase*pCurTOX);
+    std::unique_ptr<SwTOXDescription> CreateTOXDescFromTOXBase(const SwTOXBase*pCurTOX);
 
     DECL_LINK(CreateExample_Hdl, SwOneExampleFrame&, void);
     DECL_LINK(ShowPreviewHdl, Button*, void);


More information about the Libreoffice-commits mailing list