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

Noel Grandin noel.grandin at collabora.co.uk
Fri Sep 8 13:29:58 UTC 2017


 include/svx/svddrag.hxx        |   53 ++++++++++++++++++++---------------------
 svx/source/svdraw/svddrag.cxx  |   37 ++++++++++------------------
 svx/source/svdraw/svdocirc.cxx |    2 -
 svx/source/svdraw/svdopath.cxx |    4 +--
 4 files changed, 42 insertions(+), 54 deletions(-)

New commits:
commit 030273e2e28ef9c4d2118ca3851c64498dfe000a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Sep 8 13:30:05 2017 +0200

    clean up SdrDragStat
    
    - some light formatting in the header file
    - change aPnts from std::vector<Point*> to std::vector<Point>, no point
    in dynamically allocating a small value class
    - rename aPnts -> mvPnts
    - use std::unique_ptr for userdata
    - rename pUser to mpUserData
    - change some methods protected->private, since nothing external is
    using them
    
    Change-Id: I7a3f4c30c60ae1be3713f460fe65de95bed2f124
    Reviewed-on: https://gerrit.libreoffice.org/42102
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/svddrag.hxx b/include/svx/svddrag.hxx
index 608d32bfdfbd..4766863a045d 100644
--- a/include/svx/svddrag.hxx
+++ b/include/svx/svddrag.hxx
@@ -25,6 +25,7 @@
 #include <tools/fract.hxx>
 #include <svx/svxdllapi.h>
 
+#include <memory>
 #include <vector>
 
 // Status information for specialized object dragging. In order for the model
@@ -47,7 +48,7 @@ protected:
     SdrHdl*  pHdl;      // The Handle for the User
     SdrView* pView;
     SdrPageView* pPageView;
-    std::vector<Point*> aPnts; // All previous Points: [0]=Start, [Count()-2]=Prev
+    std::vector<Point> mvPnts; // All previous Points: [0]=Start, [Count()-2]=Prev
     Point     aRef1;     // Referencepoint: Resize fixed point, (axis of rotation,
     Point     aRef2;     // axis of reflection, ...)
     Point     aPos0;     // Position at the last Event
@@ -72,26 +73,25 @@ protected:
     bool  bOrtho8;
 
     SdrDragMethod* pDragMethod;
+    std::unique_ptr<SdrDragStatUserData>  mpUserData;     // Userdata
 
-protected:
     void Clear(bool bLeaveOne);
-    Point& Pnt(sal_uIntPtr nNum)                           { return *aPnts[nNum]; }
-//public:
-    SdrDragStatUserData*    pUser;     // Userdata
+protected:
+    Point&       Pnt(sal_uIntPtr nNum)               { return mvPnts[nNum]; }
 public:
-    SdrDragStat(): aPnts()                           { pUser=nullptr; Reset(); }
-    ~SdrDragStat()                                   { Clear(false); }
+    SdrDragStat()                                    { Reset(); }
+    ~SdrDragStat();
     void         Reset();
     SdrView*     GetView() const                     { return pView; }
     void         SetView(SdrView* pV)                { pView=pV; }
     SdrPageView* GetPageView() const                 { return pPageView; }
     void         SetPageView(SdrPageView* pPV)       { pPageView=pPV; }
-    const Point& GetPoint(sal_uIntPtr nNum) const    { return *aPnts[nNum]; }
-    sal_uIntPtr        GetPointCount() const           { return aPnts.size(); }
+    const Point& GetPoint(sal_uIntPtr nNum) const    { return mvPnts[nNum]; }
+    sal_uIntPtr  GetPointCount() const               { return mvPnts.size(); }
     const Point& GetStart() const                    { return GetPoint(0); }
     Point&       Start()                             { return Pnt(0); }
     const Point& GetPrev() const                     { return GetPoint(GetPointCount()-(GetPointCount()>=2 ? 2:1)); }
-    Point& Prev()                                    { return Pnt(GetPointCount()-(GetPointCount()>=2 ? 2:1)); }
+    Point&       Prev()                              { return Pnt(GetPointCount()-(GetPointCount()>=2 ? 2:1)); }
     const Point& GetPos0() const                     { return aPos0;  }
     const Point& GetNow() const                      { return GetPoint(GetPointCount()-1); }
     Point&       Now()                               { return Pnt(GetPointCount()-1); }
@@ -103,8 +103,8 @@ public:
     Point&       Ref2()                              { return aRef2;  }
     const        SdrHdl* GetHdl() const              { return pHdl;   }
     void         SetHdl(SdrHdl* pH)                  { pHdl=pH;       }
-    SdrDragStatUserData* GetUser() const             { return pUser;  }
-    void SetUser(SdrDragStatUserData* pU)            { pUser=pU; }
+    SdrDragStatUserData* GetUser() const             { return mpUserData.get();  }
+    void         SetUser(std::unique_ptr<SdrDragStatUserData> pU) { mpUserData = std::move(pU); }
     bool         IsShown() const                     { return bShown; }
     void         SetShown(bool bOn)                  { bShown=bOn; }
 
@@ -143,25 +143,24 @@ public:
     bool         IsMouseDown() const                  { return !bMouseIsUp; }
     void         SetMouseDown(bool bDown)         { bMouseIsUp=!bDown; }
 
-    static Point KorregPos(const Point& rNow, const Point& rPrev);
-    void  Reset(const Point& rPnt);
-    void  NextMove(const Point& rPnt);
-    void  NextPoint();
-    void  PrevPoint();
-    bool CheckMinMoved(const Point& rPnt);
-    long  GetDX() const                     { return GetNow().X()-GetPrev().X(); }
-    long  GetDY() const                     { return GetNow().Y()-GetPrev().Y(); }
-    Fraction GetXFact() const;
-    Fraction GetYFact() const;
+    void         Reset(const Point& rPnt);
+    void         NextMove(const Point& rPnt);
+    void         NextPoint();
+    void         PrevPoint();
+    bool         CheckMinMoved(const Point& rPnt);
+    long         GetDX() const                     { return GetNow().X()-GetPrev().X(); }
+    long         GetDY() const                     { return GetNow().Y()-GetPrev().Y(); }
+    Fraction     GetXFact() const;
+    Fraction     GetYFact() const;
 
-    SdrDragMethod* GetDragMethod() const               { return pDragMethod; }
-    void           SetDragMethod(SdrDragMethod* pMth)  { pDragMethod=pMth; }
+    SdrDragMethod* GetDragMethod() const             { return pDragMethod; }
+    void         SetDragMethod(SdrDragMethod* pMth)  { pDragMethod=pMth; }
 
-    const tools::Rectangle& GetActionRect() const             { return aActionRect; }
-    void             SetActionRect(const tools::Rectangle& rR) { aActionRect=rR; }
+    const tools::Rectangle& GetActionRect() const          { return aActionRect; }
+    void         SetActionRect(const tools::Rectangle& rR) { aActionRect=rR; }
 
     // Also considering 1stPointAsCenter
-    void TakeCreateRect(tools::Rectangle& rRect) const;
+    void         TakeCreateRect(tools::Rectangle& rRect) const;
 };
 
 #endif // INCLUDED_SVX_SVDDRAG_HXX
diff --git a/svx/source/svdraw/svddrag.cxx b/svx/source/svdraw/svddrag.cxx
index f9d943f009c5..76a7e59bceec 100644
--- a/svx/source/svdraw/svddrag.cxx
+++ b/svx/source/svdraw/svddrag.cxx
@@ -22,18 +22,16 @@
 
 SdrDragStatUserData::~SdrDragStatUserData() = default;
 
+SdrDragStat::~SdrDragStat()
+{
+}
+
 void SdrDragStat::Clear(bool bLeaveOne)
 {
-    while (!aPnts.empty()) {
-        delete aPnts.back();
-        aPnts.pop_back();
-    }
-    delete pUser;
-    pUser=nullptr;
-    aPnts.clear();
-    if (bLeaveOne) {
-        aPnts.push_back(new Point);
-    }
+    mpUserData.reset();
+    mvPnts.clear();
+    if (bLeaveOne)
+        mvPnts.emplace_back();
 }
 
 void SdrDragStat::Reset()
@@ -70,33 +68,24 @@ void SdrDragStat::NextMove(const Point& rPnt)
 {
     aPos0=GetNow();
     RealNow()=rPnt;
-    Point aBla=KorregPos(GetRealNow(),GetPrev());
-    Now()=aBla;
+    Now()=GetRealNow();
 }
 
 void SdrDragStat::NextPoint()
 {
     Point aPnt(GetNow());
-    aPnts.push_back(new Point(KorregPos(GetRealNow(),aPnt)));
+    mvPnts.emplace_back(GetRealNow());
     Prev()=aPnt;
 }
 
 void SdrDragStat::PrevPoint()
 {
-    if (aPnts.size()>=2) { // one has to remain at all times
-        Point* pPnt=aPnts[aPnts.size()-2];
-        aPnts.erase(aPnts.begin()+aPnts.size()-2);
-        delete pPnt;
-        Now()=KorregPos(GetRealNow(),GetPrev());
+    if (mvPnts.size()>=2) { // one has to remain at all times
+        mvPnts.erase(mvPnts.begin()+mvPnts.size()-2);
+        Now() = GetRealNow();
     }
 }
 
-Point SdrDragStat::KorregPos(const Point& rNow, const Point& /*rPrev*/)
-{
-    Point aRet(rNow);
-    return aRet;
-}
-
 bool SdrDragStat::CheckMinMoved(const Point& rPnt)
 {
     if (!bMinMoved) {
diff --git a/svx/source/svdraw/svdocirc.cxx b/svx/source/svdraw/svdocirc.cxx
index 3ea984b4b529..d20ea32e2c16 100644
--- a/svx/source/svdraw/svdocirc.cxx
+++ b/svx/source/svdraw/svdocirc.cxx
@@ -665,7 +665,7 @@ void SdrCircObj::ImpSetCreateParams(SdrDragStat& rStat)
     ImpCircUser* pU=static_cast<ImpCircUser*>(rStat.GetUser());
     if (pU==nullptr) {
         pU=new ImpCircUser;
-        rStat.SetUser(pU);
+        rStat.SetUser(std::unique_ptr<ImpCircUser>(pU));
     }
     pU->SetCreateParams(rStat);
 }
diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx
index b079c6ae3393..c364746e9e37 100644
--- a/svx/source/svdraw/svdopath.cxx
+++ b/svx/source/svdraw/svdopath.cxx
@@ -1269,10 +1269,10 @@ bool ImpPathForDragAndCreate::BegCreate(SdrDragStat& rStat)
     if (bMakeStartPoint) {
         aPathPolygon[0][1]=rStat.GetNow();
     }
-    ImpPathCreateUser* pU=new ImpPathCreateUser;
+    std::unique_ptr<ImpPathCreateUser> pU(new ImpPathCreateUser);
     pU->eStartKind=meObjectKind;
     pU->eAktKind=meObjectKind;
-    rStat.SetUser(pU);
+    rStat.SetUser(std::move(pU));
     return true;
 }
 


More information about the Libreoffice-commits mailing list