[Libreoffice-commits] core.git: sc/source

Noel Grandin noel.grandin at collabora.co.uk
Wed Jul 4 09:08:06 UTC 2018


 sc/source/ui/drawfunc/drawsh5.cxx |    4 ++--
 sc/source/ui/inc/tabview.hxx      |   28 +++++++++++++---------------
 sc/source/ui/view/formatsh.cxx    |    6 +++---
 sc/source/ui/view/tabview.cxx     |    1 +
 sc/source/ui/view/tabview2.cxx    |    9 ++++-----
 sc/source/ui/view/tabview5.cxx    |   38 +++++++++++++++++++-------------------
 sc/source/ui/view/tabvwsh2.cxx    |   24 +++++++++---------------
 7 files changed, 51 insertions(+), 59 deletions(-)

New commits:
commit c7f762973d21118ce3f5b0baab8850dc89bc4765
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Jul 3 11:09:03 2018 +0200

    loplugin:useuniqueptr in ScTabView
    
    and remove pDrawOld, was not being used for anything useful.
    
    Change-Id: I65ded5758ca5f7636bf7188012707410f59fb81d
    Reviewed-on: https://gerrit.libreoffice.org/56910
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/ui/drawfunc/drawsh5.cxx b/sc/source/ui/drawfunc/drawsh5.cxx
index 962a1b257509..8cd59b32e9ff 100644
--- a/sc/source/ui/drawfunc/drawsh5.cxx
+++ b/sc/source/ui/drawfunc/drawsh5.cxx
@@ -668,8 +668,8 @@ void ScDrawShell::ExecFormatPaintbrush( const SfxRequest& rReq )
         ScDrawView* pDrawView = pViewData->GetScDrawView();
         if ( pDrawView && pDrawView->AreObjectsMarked() )
         {
-            SfxItemSet* pItemSet = new SfxItemSet( pDrawView->GetAttrFromMarked(true/*bOnlyHardAttr*/) );
-            pView->SetDrawBrushSet( pItemSet, bLock );
+            std::unique_ptr<SfxItemSet> pItemSet(new SfxItemSet( pDrawView->GetAttrFromMarked(true/*bOnlyHardAttr*/) ));
+            pView->SetDrawBrushSet( std::move(pItemSet), bLock );
         }
     }
 }
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index e9034d248057..52f838705a13 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -28,6 +28,7 @@
 
 #include <sfx2/ipclient.hxx>
 
+#include "fupoor.hxx"
 #include "hiranges.hxx"
 #include "viewutil.hxx"
 #include "select.hxx"
@@ -147,8 +148,7 @@ private:
     Size                aFrameSize;             // passed on as for DoResize
     Point               aBorderPos;
 
-    FuPoor*             pDrawActual;
-    FuPoor*             pDrawOld;
+    std::unique_ptr<FuPoor> pDrawActual;
 
     std::array<VclPtr<ScGridWindow>, 4> pGridWin;
     std::array<VclPtr<ScColBar>, 2> pColBar;
@@ -168,11 +168,11 @@ private:
 
     std::unique_ptr<sdr::overlay::OverlayObjectList> mxInputHintOO; // help hint for data validation
 
-    ScPageBreakData*    pPageBreakData;
-    std::vector<ScHighlightEntry>   maHighlightRanges;
+    std::unique_ptr<ScPageBreakData>  pPageBreakData;
+    std::vector<ScHighlightEntry>     maHighlightRanges;
 
-    ScDocument*         pBrushDocument;         // cell formats for format paint brush
-    SfxItemSet*         pDrawBrushSet;          // drawing object attributes for paint brush
+    std::unique_ptr<ScDocument>       pBrushDocument;         // cell formats for format paint brush
+    std::unique_ptr<SfxItemSet>       pDrawBrushSet;          // drawing object attributes for paint brush
 
     Timer               aScrollTimer;
     VclPtr<ScGridWindow>       pTimerWindow;
@@ -325,16 +325,14 @@ public:
     bool            IsDrawSelMode() const       { return bDrawSelMode; }
     void            SetDrawSelMode(bool bNew)   { bDrawSelMode = bNew; }
 
-    void            SetDrawFuncPtr(FuPoor* pFuncPtr)    { pDrawActual = pFuncPtr; }
-    void            SetDrawFuncOldPtr(FuPoor* pFuncPtr) { pDrawOld = pFuncPtr; }
-    FuPoor*         GetDrawFuncPtr()                    { return pDrawActual; }
-    FuPoor*         GetDrawFuncOldPtr()                 { return pDrawOld; }
+    void            SetDrawFuncPtr(std::unique_ptr<FuPoor> pFuncPtr);
+    FuPoor*         GetDrawFuncPtr()  { return pDrawActual.get(); }
 
     void            DrawDeselectAll();
     void            DrawMarkListHasChanged();
     void            UpdateAnchorHandles();
 
-    ScPageBreakData* GetPageBreakData()     { return pPageBreakData; }
+    ScPageBreakData* GetPageBreakData()     { return pPageBreakData.get(); }
     const std::vector<ScHighlightEntry>& GetHighlightRanges()   { return maHighlightRanges; }
 
     void            UpdatePageBreakData( bool bForcePaint = false );
@@ -594,11 +592,11 @@ public:
     vcl::Window*         GetFrameWin() const { return pFrameWin; }
 
     bool            HasPaintBrush() const           { return pBrushDocument || pDrawBrushSet; }
-    ScDocument*     GetBrushDocument() const        { return pBrushDocument; }
-    SfxItemSet*     GetDrawBrushSet() const         { return pDrawBrushSet; }
+    ScDocument*     GetBrushDocument() const        { return pBrushDocument.get(); }
+    SfxItemSet*     GetDrawBrushSet() const         { return pDrawBrushSet.get(); }
     bool            IsPaintBrushLocked() const      { return bLockPaintBrush; }
-    void            SetBrushDocument( ScDocument* pNew, bool bLock );
-    void            SetDrawBrushSet( SfxItemSet* pNew, bool bLock );
+    void            SetBrushDocument( std::unique_ptr<ScDocument> pNew, bool bLock );
+    void            SetDrawBrushSet( std::unique_ptr<SfxItemSet> pNew, bool bLock );
     void            ResetBrushDocument();
 
     bool ContinueOnlineSpelling();
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index b4a5fa80fddf..aa19eb2a0bfa 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -2796,9 +2796,9 @@ void ScFormatShell::ExecFormatPaintbrush( const SfxRequest& rReq )
         if ( pViewData->GetSimpleArea(aDummy) != SC_MARK_SIMPLE )
             pView->Unmark();
 
-        ScDocument* pBrushDoc = new ScDocument( SCDOCMODE_CLIP );
-        pView->CopyToClip( pBrushDoc, false, true );
-        pView->SetBrushDocument( pBrushDoc, bLock );
+        std::unique_ptr<ScDocument> pBrushDoc(new ScDocument( SCDOCMODE_CLIP ));
+        pView->CopyToClip( pBrushDoc.get(), false, true );
+        pView->SetBrushDocument( std::move(pBrushDoc), bLock );
     }
 }
 
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 3cb3ecd67edb..ce567a793310 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -25,6 +25,7 @@
 #include <vcl/help.hxx>
 #include <vcl/settings.hxx>
 
+#include <pagedata.hxx>
 #include <tabview.hxx>
 #include <tabvwsh.hxx>
 #include <document.hxx>
diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx
index 88a491eea54a..30868a8faee1 100644
--- a/sc/source/ui/view/tabview2.cxx
+++ b/sc/source/ui/view/tabview2.cxx
@@ -1446,7 +1446,7 @@ void ScTabView::ErrorMessage(const char* pGlobStrId)
 
 void ScTabView::UpdatePageBreakData( bool bForcePaint )
 {
-    ScPageBreakData* pNewData = nullptr;
+    std::unique_ptr<ScPageBreakData> pNewData;
 
     if (aViewData.IsPagebreakMode())
     {
@@ -1457,9 +1457,9 @@ void ScTabView::UpdatePageBreakData( bool bForcePaint )
         sal_uInt16 nCount = rDoc.GetPrintRangeCount(nTab);
         if (!nCount)
             nCount = 1;
-        pNewData = new ScPageBreakData(nCount);
+        pNewData.reset( new ScPageBreakData(nCount) );
 
-        ScPrintFunc aPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab, 0,0,nullptr, nullptr, pNewData );
+        ScPrintFunc aPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab, 0,0,nullptr, nullptr, pNewData.get() );
         // ScPrintFunc fills the PageBreakData in ctor
         if ( nCount > 1 )
         {
@@ -1472,8 +1472,7 @@ void ScTabView::UpdatePageBreakData( bool bForcePaint )
             PaintGrid();
     }
 
-    delete pPageBreakData;
-    pPageBreakData = pNewData;
+    pPageBreakData = std::move(pNewData);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/tabview5.cxx b/sc/source/ui/view/tabview5.cxx
index 058bedd5b1d0..6900ce9fc430 100644
--- a/sc/source/ui/view/tabview5.cxx
+++ b/sc/source/ui/view/tabview5.cxx
@@ -28,6 +28,7 @@
 #include <sfx2/dispatch.hxx>
 #include <sfx2/lokhelper.hxx>
 #include <sfx2/objsh.hxx>
+#include <o3tl/make_unique.hxx>
 
 #include <tabview.hxx>
 #include <tabvwsh.hxx>
@@ -130,7 +131,6 @@ void ScTabView::Init()
     //  UpdateShow is done during resize or a copy of an existing view from ctor
 
     pDrawActual = nullptr;
-    pDrawOld    = nullptr;
 
     //  DrawView cannot be create in the TabView - ctor
     //  when the ViewShell isn't constructed yet...
@@ -153,13 +153,12 @@ ScTabView::~ScTabView()
         TransferableHelper::ClearSelection( GetActiveWin() );       // may delete pOld
     }
 
-    DELETEZ(pBrushDocument);
-    DELETEZ(pDrawBrushSet);
+    pBrushDocument.reset();
+    pDrawBrushSet.reset();
 
-    DELETEZ(pPageBreakData);
+    pPageBreakData.reset();
 
-    DELETEZ(pDrawOld);
-    DELETEZ(pDrawActual);
+    pDrawActual.reset();
 
     if (comphelper::LibreOfficeKit::isActive())
     {
@@ -247,7 +246,7 @@ void ScTabView::MakeDrawView( TriState nForceDesignMode )
                                             // so that immediately can be drawn
             }
         SfxRequest aSfxRequest(SID_OBJECT_SELECT, SfxCallMode::SLOT, aViewData.GetViewShell()->GetPool());
-        SetDrawFuncPtr(new FuSelection(*aViewData.GetViewShell(), GetActiveWin(), pDrawView,
+        SetDrawFuncPtr(o3tl::make_unique<FuSelection>(*aViewData.GetViewShell(), GetActiveWin(), pDrawView,
                                        pLayer,aSfxRequest));
 
         //  used when switching back from page preview: restore saved design mode state
@@ -613,26 +612,20 @@ void ScTabView::MakeVisible( const tools::Rectangle& rHMMRect )
     }
 }
 
-void ScTabView::SetBrushDocument( ScDocument* pNew, bool bLock )
+void ScTabView::SetBrushDocument( std::unique_ptr<ScDocument> pNew, bool bLock )
 {
-    delete pBrushDocument;
-    delete pDrawBrushSet;
-
-    pBrushDocument = pNew;
-    pDrawBrushSet = nullptr;
+    pDrawBrushSet.reset();
+    pBrushDocument = std::move(pNew);
 
     bLockPaintBrush = bLock;
 
     aViewData.GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
 }
 
-void ScTabView::SetDrawBrushSet( SfxItemSet* pNew, bool bLock )
+void ScTabView::SetDrawBrushSet( std::unique_ptr<SfxItemSet> pNew, bool bLock )
 {
-    delete pBrushDocument;
-    delete pDrawBrushSet;
-
-    pBrushDocument = nullptr;
-    pDrawBrushSet = pNew;
+    pBrushDocument.reset();
+    pDrawBrushSet = std::move(pNew);
 
     bLockPaintBrush = bLock;
 
@@ -691,4 +684,11 @@ void ScTabView::OnLOKNoteStateChanged(const ScPostIt* pNote)
     }
 }
 
+void ScTabView::SetDrawFuncPtr(std::unique_ptr<FuPoor> pNew)
+{
+    if (pDrawActual)
+        pDrawActual->Deactivate();
+    pDrawActual = std::move(pNew);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/tabvwsh2.cxx b/sc/source/ui/view/tabvwsh2.cxx
index 58ecae85f7ff..c93c46970727 100644
--- a/sc/source/ui/view/tabvwsh2.cxx
+++ b/sc/source/ui/view/tabvwsh2.cxx
@@ -24,6 +24,7 @@
 #include <unotools/moduleoptions.hxx>
 #include <svl/languageoptions.hxx>
 #include <sfx2/dispatch.hxx>
+#include <o3tl/make_unique.hxx>
 
 #include <tabvwsh.hxx>
 #include <drawsh.hxx>
@@ -198,14 +199,7 @@ void ScTabViewShell::ExecDraw(SfxRequest& rReq)
     }
 
     if (pTabView->GetDrawFuncPtr())
-    {
-        if (pTabView->GetDrawFuncOldPtr() != pTabView->GetDrawFuncPtr())
-            delete pTabView->GetDrawFuncOldPtr();
-
-        pTabView->GetDrawFuncPtr()->Deactivate();
-        pTabView->SetDrawFuncOldPtr(pTabView->GetDrawFuncPtr());
         pTabView->SetDrawFuncPtr(nullptr);
-    }
 
     SfxRequest aNewReq(rReq);
     aNewReq.SetSlot(nDrawSfxId);
@@ -217,7 +211,7 @@ void ScTabViewShell::ExecDraw(SfxRequest& rReq)
         case SID_OBJECT_SELECT:
             // not always switch back
             if(pView->GetMarkedObjectList().GetMarkCount() == 0) SetDrawShell(bEx);
-            pTabView->SetDrawFuncPtr(new FuSelection(*this, pWin, pView, pDoc, aNewReq));
+            pTabView->SetDrawFuncPtr(o3tl::make_unique<FuSelection>(*this, pWin, pView, pDoc, aNewReq));
             break;
 
         case SID_DRAW_LINE:
@@ -232,12 +226,12 @@ void ScTabViewShell::ExecDraw(SfxRequest& rReq)
         case SID_DRAW_RECT:
         case SID_DRAW_ELLIPSE:
         case SID_DRAW_MEASURELINE:
-            pTabView->SetDrawFuncPtr(new FuConstRectangle(*this, pWin, pView, pDoc, aNewReq));
+            pTabView->SetDrawFuncPtr(o3tl::make_unique<FuConstRectangle>(*this, pWin, pView, pDoc, aNewReq));
             break;
 
         case SID_DRAW_CAPTION:
         case SID_DRAW_CAPTION_VERTICAL:
-            pTabView->SetDrawFuncPtr(new FuConstRectangle(*this, pWin, pView, pDoc, aNewReq));
+            pTabView->SetDrawFuncPtr(o3tl::make_unique<FuConstRectangle>(*this, pWin, pView, pDoc, aNewReq));
             pView->SetFrameDragSingles( false );
             rBindings.Invalidate( SID_BEZIER_EDIT );
             break;
@@ -250,25 +244,25 @@ void ScTabViewShell::ExecDraw(SfxRequest& rReq)
         case SID_DRAW_BEZIER_FILL:
         case SID_DRAW_FREELINE:
         case SID_DRAW_FREELINE_NOFILL:
-            pTabView->SetDrawFuncPtr(new FuConstPolygon(*this, pWin, pView, pDoc, aNewReq));
+            pTabView->SetDrawFuncPtr(o3tl::make_unique<FuConstPolygon>(*this, pWin, pView, pDoc, aNewReq));
             break;
 
         case SID_DRAW_ARC:
         case SID_DRAW_PIE:
         case SID_DRAW_CIRCLECUT:
-            pTabView->SetDrawFuncPtr(new FuConstArc(*this, pWin, pView, pDoc, aNewReq));
+            pTabView->SetDrawFuncPtr(o3tl::make_unique<FuConstArc>(*this, pWin, pView, pDoc, aNewReq));
             break;
 
         case SID_DRAW_TEXT:
         case SID_DRAW_TEXT_VERTICAL:
         case SID_DRAW_TEXT_MARQUEE:
         case SID_DRAW_NOTEEDIT:
-            pTabView->SetDrawFuncPtr(new FuText(*this, pWin, pView, pDoc, aNewReq));
+            pTabView->SetDrawFuncPtr(o3tl::make_unique<FuText>(*this, pWin, pView, pDoc, aNewReq));
             break;
 
         case SID_FM_CREATE_CONTROL:
             SetDrawFormShell(true);
-            pTabView->SetDrawFuncPtr(new FuConstUnoControl(*this, pWin, pView, pDoc, aNewReq));
+            pTabView->SetDrawFuncPtr(o3tl::make_unique<FuConstUnoControl>(*this, pWin, pView, pDoc, aNewReq));
             nFormSfxId = nNewFormId;
             break;
 
@@ -280,7 +274,7 @@ void ScTabViewShell::ExecDraw(SfxRequest& rReq)
         case SID_DRAWTBX_CS_STAR :
         case SID_DRAW_CS_ID :
         {
-            pTabView->SetDrawFuncPtr( new FuConstCustomShape(*this, pWin, pView, pDoc, aNewReq));
+            pTabView->SetDrawFuncPtr( o3tl::make_unique<FuConstCustomShape>(*this, pWin, pView, pDoc, aNewReq));
             if ( nNewId != SID_DRAW_CS_ID )
             {
                 const SfxStringItem* pEnumCommand = rReq.GetArg<SfxStringItem>(nNewId);


More information about the Libreoffice-commits mailing list