[Libreoffice-commits] core.git: include/svl include/svx svx/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 3 06:26:13 UTC 2018


 include/svl/broadcast.hxx      |    1 
 include/svx/svdlayer.hxx       |   17 ++++++-----
 svx/source/svdraw/svdedtv.cxx  |    4 +-
 svx/source/svdraw/svdlayer.cxx |   60 +++++++++++++++++++----------------------
 svx/source/svdraw/svdmodel.cxx |    2 -
 svx/source/svdraw/svdundo.cxx  |    8 ++---
 6 files changed, 44 insertions(+), 48 deletions(-)

New commits:
commit 48bf5a74186140760a734091a85e85d198e6fdfa
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Sep 28 11:24:45 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Oct 3 08:25:48 2018 +0200

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

diff --git a/include/svl/broadcast.hxx b/include/svl/broadcast.hxx
index b4c8be5f9ac0..27181e03294e 100644
--- a/include/svl/broadcast.hxx
+++ b/include/svl/broadcast.hxx
@@ -82,7 +82,6 @@ private:
 
     /// Indicate that this broadcaster will be destructed (we indicate this on all ScColumn's broadcasters during the ScTable destruction, eg.)
     bool mbAboutToDie:1;
-    bool mbDisposing:1;
     mutable bool mbNormalized:1;
     mutable bool mbDestNormalized:1;
 };
diff --git a/include/svx/svdlayer.hxx b/include/svx/svdlayer.hxx
index b36a1e9fdb1e..cd8ad1384fb8 100644
--- a/include/svx/svdlayer.hxx
+++ b/include/svx/svdlayer.hxx
@@ -24,6 +24,7 @@
 #include <svx/svdtypes.hxx>
 #include <svx/svxdllapi.h>
 #include <algorithm>
+#include <memory>
 #include <vector>
 
 /**
@@ -110,7 +111,7 @@ friend class SdrModel;
 friend class SdrPage;
 
 protected:
-    std::vector<SdrLayer*> aLayer;
+    std::vector<std::unique_ptr<SdrLayer>> maLayers;
     SdrLayerAdmin* pParent; // The page's admin knows the doc's admin
     SdrModel* pModel; // For broadcasting
     OUString maControlLayerName;
@@ -129,11 +130,11 @@ public:
 
     void               SetModel(SdrModel* pNewModel);
 
-    void               InsertLayer(SdrLayer* pLayer, sal_uInt16 nPos);
-    SdrLayer*          RemoveLayer(sal_uInt16 nPos);
+    void               InsertLayer(std::unique_ptr<SdrLayer> pLayer, sal_uInt16 nPos);
+    std::unique_ptr<SdrLayer> RemoveLayer(sal_uInt16 nPos);
 
-    // Delete the entire layer
-    void               ClearLayer();
+    // Delete all layers
+    void               ClearLayers();
 
     // New layer is created and inserted
     SdrLayer*          NewLayer(const OUString& rName, sal_uInt16 nPos=0xFFFF);
@@ -142,10 +143,10 @@ public:
     void               NewStandardLayer(sal_uInt16 nPos);
 
     // Iterate over all layers
-    sal_uInt16         GetLayerCount() const                                         { return sal_uInt16(aLayer.size()); }
+    sal_uInt16         GetLayerCount() const                                         { return sal_uInt16(maLayers.size()); }
 
-    SdrLayer*          GetLayer(sal_uInt16 i)                                        { return aLayer[i]; }
-    const SdrLayer*    GetLayer(sal_uInt16 i) const                                  { return aLayer[i]; }
+    SdrLayer*          GetLayer(sal_uInt16 i)                                        { return maLayers[i].get(); }
+    const SdrLayer*    GetLayer(sal_uInt16 i) const                                  { return maLayers[i].get(); }
 
     sal_uInt16         GetLayerPos(SdrLayer* pLayer) const;
 
diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx
index 5a3cd46dd117..1b5720af2536 100644
--- a/svx/source/svdraw/svdedtv.cxx
+++ b/svx/source/svdraw/svdedtv.cxx
@@ -261,12 +261,12 @@ void SdrEditView::DeleteLayer(const OUString& rName)
         if( bUndo )
         {
             AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoDeleteLayer(nLayerNum, rLA, *mpModel));
-            rLA.RemoveLayer(nLayerNum);
+            rLA.RemoveLayer(nLayerNum).release();
             EndUndo();
         }
         else
         {
-            delete rLA.RemoveLayer(nLayerNum);
+            rLA.RemoveLayer(nLayerNum);
         }
 
         mpModel->SetChanged();
diff --git a/svx/source/svdraw/svdlayer.cxx b/svx/source/svdraw/svdlayer.cxx
index 1d87fb830f42..fef4c22927b3 100644
--- a/svx/source/svdraw/svdlayer.cxx
+++ b/svx/source/svdraw/svdlayer.cxx
@@ -111,7 +111,6 @@ bool SdrLayer::operator==(const SdrLayer& rCmpLayer) const
 }
 
 SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent):
-    aLayer(),
     pParent(pNewParent),
     pModel(nullptr),
     maControlLayerName("controls")
@@ -119,7 +118,6 @@ SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent):
 }
 
 SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin):
-    aLayer(),
     pParent(nullptr),
     pModel(nullptr),
     maControlLayerName("controls")
@@ -129,24 +127,21 @@ SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin):
 
 SdrLayerAdmin::~SdrLayerAdmin()
 {
-    ClearLayer();
 }
 
-void SdrLayerAdmin::ClearLayer()
+void SdrLayerAdmin::ClearLayers()
 {
-    for( std::vector<SdrLayer*>::const_iterator it = aLayer.begin(); it != aLayer.end(); ++it )
-        delete *it;
-    aLayer.clear();
+    maLayers.clear();
 }
 
 SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmin)
 {
-    ClearLayer();
+    maLayers.clear();
     pParent=rSrcLayerAdmin.pParent;
     sal_uInt16 i;
     sal_uInt16 nCount=rSrcLayerAdmin.GetLayerCount();
     for (i=0; i<nCount; i++) {
-        aLayer.push_back(new SdrLayer(*rSrcLayerAdmin.GetLayer(i)));
+        maLayers.emplace_back(new SdrLayer(*rSrcLayerAdmin.GetLayer(i)));
     }
     return *this;
 }
@@ -172,20 +167,20 @@ void SdrLayerAdmin::Broadcast() const
     }
 }
 
-void SdrLayerAdmin::InsertLayer(SdrLayer* pLayer, sal_uInt16 nPos)
+void SdrLayerAdmin::InsertLayer(std::unique_ptr<SdrLayer> pLayer, sal_uInt16 nPos)
 {
+        pLayer->SetModel(pModel);
         if(nPos==0xFFFF)
-            aLayer.push_back(pLayer);
+            maLayers.push_back(std::move(pLayer));
         else
-            aLayer.insert(aLayer.begin() + nPos, pLayer);
-        pLayer->SetModel(pModel);
+            maLayers.insert(maLayers.begin() + nPos, std::move(pLayer));
         Broadcast();
 }
 
-SdrLayer* SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos)
+std::unique_ptr<SdrLayer> SdrLayerAdmin::RemoveLayer(sal_uInt16 nPos)
 {
-    SdrLayer* pRetLayer=aLayer[nPos];
-    aLayer.erase(aLayer.begin()+nPos);
+    std::unique_ptr<SdrLayer> pRetLayer = std::move(maLayers[nPos]);
+    maLayers.erase(maLayers.begin()+nPos);
     Broadcast();
     return pRetLayer;
 }
@@ -196,9 +191,9 @@ SdrLayer* SdrLayerAdmin::NewLayer(const OUString& rName, sal_uInt16 nPos)
     SdrLayer* pLay=new SdrLayer(nID,rName);
     pLay->SetModel(pModel);
     if(nPos==0xFFFF)
-        aLayer.push_back(pLay);
+        maLayers.push_back(std::unique_ptr<SdrLayer>(pLay));
     else
-        aLayer.insert(aLayer.begin() + nPos, pLay);
+        maLayers.insert(maLayers.begin() + nPos, std::unique_ptr<SdrLayer>(pLay));
     Broadcast();
     return pLay;
 }
@@ -210,9 +205,9 @@ void SdrLayerAdmin::NewStandardLayer(sal_uInt16 nPos)
     pLay->SetStandardLayer();
     pLay->SetModel(pModel);
     if(nPos==0xFFFF)
-        aLayer.push_back(pLay);
+        maLayers.push_back(std::unique_ptr<SdrLayer>(pLay));
     else
-        aLayer.insert(aLayer.begin() + nPos, pLay);
+        maLayers.insert(maLayers.begin() + nPos, std::unique_ptr<SdrLayer>(pLay));
     Broadcast();
 }
 
@@ -220,11 +215,10 @@ sal_uInt16 SdrLayerAdmin::GetLayerPos(SdrLayer* pLayer) const
 {
     sal_uInt16 nRet=SDRLAYERPOS_NOTFOUND;
     if (pLayer!=nullptr) {
-        std::vector<SdrLayer*>::const_iterator it = std::find(aLayer.begin(), aLayer.end(), pLayer);
-        if (it==aLayer.end()) {
-            nRet=SDRLAYERPOS_NOTFOUND;
-        } else {
-            nRet=it - aLayer.begin();
+        auto it = std::find_if(maLayers.begin(), maLayers.end(),
+                    [&](const std::unique_ptr<SdrLayer> & p) { return p.get() == pLayer; });
+        if (it!=maLayers.end()) {
+            nRet=it - maLayers.begin();
         }
     }
     return nRet;
@@ -266,9 +260,9 @@ SdrLayerID SdrLayerAdmin::GetLayerID(const OUString& rName) const
 
 const SdrLayer* SdrLayerAdmin::GetLayerPerID(SdrLayerID nID) const
 {
-    for (SdrLayer* pLayer : aLayer)
+    for (auto const & pLayer : maLayers)
         if (pLayer->GetID() == nID)
-            return pLayer;
+            return pLayer.get();
     return nullptr;
 }
 
@@ -313,7 +307,7 @@ void SdrLayerAdmin::SetControlLayerName(const OUString& rNewName)
 void  SdrLayerAdmin::getVisibleLayersODF( SdrLayerIDSet& rOutSet) const
 {
     rOutSet.ClearAll();
-    for( SdrLayer* pCurrentLayer : aLayer )
+    for( auto & pCurrentLayer : maLayers )
     {
         if ( pCurrentLayer->IsVisibleODF() )
             rOutSet.Set( pCurrentLayer->GetID() );
@@ -323,7 +317,7 @@ void  SdrLayerAdmin::getVisibleLayersODF( SdrLayerIDSet& rOutSet) const
 void SdrLayerAdmin::getPrintableLayersODF( SdrLayerIDSet& rOutSet) const
 {
     rOutSet.ClearAll();
-    for( SdrLayer* pCurrentLayer : aLayer )
+    for( auto & pCurrentLayer : maLayers )
     {
         if ( pCurrentLayer->IsPrintableODF() )
             rOutSet.Set( pCurrentLayer->GetID() );
@@ -333,7 +327,7 @@ void SdrLayerAdmin::getPrintableLayersODF( SdrLayerIDSet& rOutSet) const
 void SdrLayerAdmin::getLockedLayersODF( SdrLayerIDSet& rOutSet) const
 {
     rOutSet.ClearAll();
-    for( SdrLayer* pCurrentLayer : aLayer )
+    for( auto& pCurrentLayer : maLayers )
     {
         if ( pCurrentLayer->IsLockedODF() )
             rOutSet.Set( pCurrentLayer->GetID() );
@@ -355,18 +349,20 @@ void SdrLayerAdmin::QueryValue(const SdrLayerIDSet& rViewLayerSet, css::uno::Any
     sal_uInt8 nByteIndex = 0;
     sal_uInt8 nBitpos = 0;
     sal_uInt16 nLayerPos = 0; // Position of the layer in member aLayer and in <draw:layer-set> in file
-    for( SdrLayer* pCurrentLayer : aLayer )
+    sal_uInt16 nLayerIndex = 0;
+    for( auto& pCurrentLayer : maLayers )
     {
         SdrLayerID nCurrentID = pCurrentLayer->GetID();
         if ( rViewLayerSet.IsSet(nCurrentID) )
         {
-            nLayerPos = GetLayerPos(pCurrentLayer);
+            nLayerPos = nLayerIndex;
             nByteIndex = nLayerPos / 8;
             if (nByteIndex > 31)
                 continue; // skip position, if too large for bitfield
             nBitpos = nLayerPos % 8;
             aTmp[nByteIndex] |= (1 << nBitpos);
         }
+        ++nLayerIndex;
     }
 
     // Second transform the bitfield to byte sequence, same as in previous version of QueryValue
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index c7f34d9dd3e3..405ef170ab23 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -645,7 +645,7 @@ void SdrModel::ClearModel(bool bCalledFromDestructor)
     maMaPag.clear();
     MasterPageListChanged();
 
-    pLayerAdmin->ClearLayer();
+    pLayerAdmin->ClearLayers();
 }
 
 SdrModel* SdrModel::AllocModel() const
diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx
index a4b5b965cdfb..d990914a8e6a 100644
--- a/svx/source/svdraw/svdundo.cxx
+++ b/svx/source/svdraw/svdundo.cxx
@@ -1275,7 +1275,7 @@ void SdrUndoNewLayer::Undo()
 {
     DBG_ASSERT(!bItsMine,"SdrUndoNewLayer::Undo(): Layer already belongs to UndoAction.");
     bItsMine=true;
-    SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNum);
+    SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNum).release();
     DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoNewLayer::Undo(): Removed layer is != pLayer.");
 }
 
@@ -1283,7 +1283,7 @@ void SdrUndoNewLayer::Redo()
 {
     DBG_ASSERT(bItsMine,"SdrUndoNewLayer::Undo(): Layer does not belong to UndoAction.");
     bItsMine=false;
-    pLayerAdmin->InsertLayer(pLayer,nNum);
+    pLayerAdmin->InsertLayer(std::unique_ptr<SdrLayer>(pLayer),nNum);
 }
 
 OUString SdrUndoNewLayer::GetComment() const
@@ -1296,14 +1296,14 @@ void SdrUndoDelLayer::Undo()
 {
     DBG_ASSERT(bItsMine,"SdrUndoDelLayer::Undo(): Layer does not belong to UndoAction.");
     bItsMine=false;
-    pLayerAdmin->InsertLayer(pLayer,nNum);
+    pLayerAdmin->InsertLayer(std::unique_ptr<SdrLayer>(pLayer),nNum);
 }
 
 void SdrUndoDelLayer::Redo()
 {
     DBG_ASSERT(!bItsMine,"SdrUndoDelLayer::Undo(): Layer already belongs to UndoAction.");
     bItsMine=true;
-    SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNum);
+    SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNum).release();
     DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoDelLayer::Redo(): Removed layer is != pLayer.");
 }
 


More information about the Libreoffice-commits mailing list