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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 15 12:54:15 UTC 2018


 sc/inc/cellsuno.hxx              |    2 +-
 sc/inc/document.hxx              |    2 +-
 sc/source/core/data/document.cxx |    4 ++--
 sc/source/ui/inc/undotab.hxx     |    3 ++-
 sc/source/ui/undo/refundo.cxx    |    3 +--
 sc/source/ui/undo/undotab.cxx    |    6 +++---
 sc/source/ui/unoobj/cellsuno.cxx |   30 ++++++++++++------------------
 sc/source/ui/view/viewfun2.cxx   |    8 ++++----
 8 files changed, 26 insertions(+), 32 deletions(-)

New commits:
commit 664b4f31e6bd609846fd4bb2a17730209fe73ae5
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Aug 14 11:51:08 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 15 14:53:50 2018 +0200

    pass ScPrintRangeSaver around by std::unique_ptr
    
    Change-Id: I5b5ffe9f421b63951b05d9d6f58af346b8fdf0d1
    Reviewed-on: https://gerrit.libreoffice.org/59029
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/cellsuno.hxx b/sc/inc/cellsuno.hxx
index f36ec2a92573..625818ce5cfb 100644
--- a/sc/inc/cellsuno.hxx
+++ b/sc/inc/cellsuno.hxx
@@ -800,7 +800,7 @@ private:
     const SfxItemPropertySet*       pSheetPropSet;
 
     SCTAB                   GetTab_Impl() const;
-    void                    PrintAreaUndo_Impl( ScPrintRangeSaver* pOldRanges );
+    void                    PrintAreaUndo_Impl( std::unique_ptr<ScPrintRangeSaver> pOldRanges );
 
 protected:
     virtual const SfxItemPropertyMap& GetItemPropertyMap() override;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index ae159ac51495..74c5b65d3c34 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1945,7 +1945,7 @@ public:
     SC_DLLPUBLIC void            SetPrintEntireSheet( SCTAB nTab );
     SC_DLLPUBLIC void            SetRepeatColRange( SCTAB nTab, std::unique_ptr<ScRange> pNew );
     SC_DLLPUBLIC void            SetRepeatRowRange( SCTAB nTab, std::unique_ptr<ScRange> pNew );
-    ScPrintRangeSaver*           CreatePrintRangeSaver() const;
+    std::unique_ptr<ScPrintRangeSaver> CreatePrintRangeSaver() const;
     void                         RestorePrintRanges( const ScPrintRangeSaver& rSaver );
 
     SC_DLLPUBLIC tools::Rectangle       GetMMRect( SCCOL nStartCol, SCROW nStartRow,
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index ad695bcb3a2c..55a660a4930d 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6252,10 +6252,10 @@ void ScDocument::SetRepeatRowRange( SCTAB nTab, std::unique_ptr<ScRange> pNew )
         maTabs[nTab]->SetRepeatRowRange( std::move(pNew) );
 }
 
-ScPrintRangeSaver* ScDocument::CreatePrintRangeSaver() const
+std::unique_ptr<ScPrintRangeSaver> ScDocument::CreatePrintRangeSaver() const
 {
     const SCTAB nCount = static_cast<SCTAB>(maTabs.size());
-    ScPrintRangeSaver* pNew = new ScPrintRangeSaver( nCount );
+    std::unique_ptr<ScPrintRangeSaver> pNew(new ScPrintRangeSaver( nCount ));
     for (SCTAB i=0; i<nCount; i++)
         if (maTabs[i])
             maTabs[i]->FillPrintSaver( pNew->GetTabData(i) );
diff --git a/sc/source/ui/inc/undotab.hxx b/sc/source/ui/inc/undotab.hxx
index 06ad4eb87bac..621b94063d40 100644
--- a/sc/source/ui/inc/undotab.hxx
+++ b/sc/source/ui/inc/undotab.hxx
@@ -377,7 +377,8 @@ class ScUndoPrintRange : public ScSimpleUndo
 {
 public:
                     ScUndoPrintRange( ScDocShell* pShell, SCTAB nNewTab,
-                                        ScPrintRangeSaver* pOld, ScPrintRangeSaver* pNew );
+                                      std::unique_ptr<ScPrintRangeSaver> pOld,
+                                      std::unique_ptr<ScPrintRangeSaver> pNew );
     virtual         ~ScUndoPrintRange() override;
 
     virtual void    Undo() override;
diff --git a/sc/source/ui/undo/refundo.cxx b/sc/source/ui/undo/refundo.cxx
index d2a6c5cb2779..178b34ea8ba9 100644
--- a/sc/source/ui/undo/refundo.cxx
+++ b/sc/source/ui/undo/refundo.cxx
@@ -100,10 +100,9 @@ void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
 
     if (pPrintRanges)
     {
-        ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver();
+        std::unique_ptr<ScPrintRangeSaver> pNewRanges = pDoc->CreatePrintRangeSaver();
         if ( pNewRanges && *pPrintRanges == *pNewRanges )
             pPrintRanges.reset();
-        delete pNewRanges;
     }
 
     if (pDPCollection)
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 0217d41f15fd..d9de877c2f36 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -1296,11 +1296,11 @@ OUString ScUndoTabProtect::GetComment() const
 }
 
 ScUndoPrintRange::ScUndoPrintRange( ScDocShell* pShell, SCTAB nNewTab,
-                                    ScPrintRangeSaver* pOld, ScPrintRangeSaver* pNew ) :
+                                    std::unique_ptr<ScPrintRangeSaver> pOld, std::unique_ptr<ScPrintRangeSaver> pNew ) :
     ScSimpleUndo( pShell ),
     nTab( nNewTab ),
-    pOldRanges( pOld ),
-    pNewRanges( pNew )
+    pOldRanges( std::move(pOld) ),
+    pNewRanges( std::move(pNew) )
 {
 }
 
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 682d201556a4..4ede9777957f 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -7184,7 +7184,7 @@ void SAL_CALL ScTableSheetObj::copyRange( const table::CellAddress& aDestination
 
 // XPrintAreas
 
-void ScTableSheetObj::PrintAreaUndo_Impl( ScPrintRangeSaver* pOldRanges )
+void ScTableSheetObj::PrintAreaUndo_Impl( std::unique_ptr<ScPrintRangeSaver> pOldRanges )
 {
     //  page break and undo
     ScDocShell* pDocSh = GetDocShell();
@@ -7201,11 +7201,8 @@ void ScTableSheetObj::PrintAreaUndo_Impl( ScPrintRangeSaver* pOldRanges )
                 new ScUndoPrintRange(
                     pDocSh,
                     nTab,
-                    pOldRanges,
+                    std::move(pOldRanges),
                     rDoc.CreatePrintRangeSaver())); // create new ranges
-
-            // #i120105# ownership of old ranges has changed, mark as consumed
-            pOldRanges = nullptr;
         }
 
         ScPrintFunc(pDocSh, pDocSh->GetPrinter(), nTab).UpdatePages();
@@ -7218,9 +7215,6 @@ void ScTableSheetObj::PrintAreaUndo_Impl( ScPrintRangeSaver* pOldRanges )
 
         pDocSh->SetDocumentModified();
     }
-
-    // #i120105# pOldRanges not used, need to cleanup
-    delete pOldRanges;
 }
 
 uno::Sequence<table::CellRangeAddress> SAL_CALL ScTableSheetObj::getPrintAreas()
@@ -7259,7 +7253,7 @@ void SAL_CALL ScTableSheetObj::setPrintAreas(
     ScDocShell* pDocSh = GetDocShell();
     if ( pDocSh )
     {
-        ScPrintRangeSaver* pOldRanges = nullptr;
+        std::unique_ptr<ScPrintRangeSaver> pOldRanges;
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
 
@@ -7280,7 +7274,7 @@ void SAL_CALL ScTableSheetObj::setPrintAreas(
         }
 
         if ( rDoc.IsUndoEnabled() )
-            PrintAreaUndo_Impl( pOldRanges );   // Undo, Page Breaks, Modified etc.
+            PrintAreaUndo_Impl( std::move(pOldRanges) );   // Undo, Page Breaks, Modified etc.
     }
 }
 
@@ -7306,7 +7300,7 @@ void SAL_CALL ScTableSheetObj::setPrintTitleColumns( sal_Bool bPrintTitleColumns
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
 
-        ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver();
+        std::unique_ptr<ScPrintRangeSaver> pOldRanges = rDoc.CreatePrintRangeSaver();
 
         if ( bPrintTitleColumns )
         {
@@ -7318,7 +7312,7 @@ void SAL_CALL ScTableSheetObj::setPrintTitleColumns( sal_Bool bPrintTitleColumns
         else
             rDoc.SetRepeatColRange( nTab, nullptr );          // disable
 
-        PrintAreaUndo_Impl( pOldRanges );   // undo, page break, modified etc.
+        PrintAreaUndo_Impl( std::move(pOldRanges) );   // undo, page break, modified etc.
 
         //! save last set area during switch off and recreate during switch on ???
     }
@@ -7352,13 +7346,13 @@ void SAL_CALL ScTableSheetObj::setTitleColumns( const table::CellRangeAddress& a
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
 
-        ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver();
+        std::unique_ptr<ScPrintRangeSaver> pOldRanges = rDoc.CreatePrintRangeSaver();
 
         std::unique_ptr<ScRange> pNew(new ScRange);
         ScUnoConversion::FillScRange( *pNew, aTitleColumns );
         rDoc.SetRepeatColRange( nTab, std::move(pNew) );     // also always enable
 
-        PrintAreaUndo_Impl( pOldRanges );           // undo, page breaks, modified etc.
+        PrintAreaUndo_Impl( std::move(pOldRanges) );           // undo, page breaks, modified etc.
     }
 }
 
@@ -7384,7 +7378,7 @@ void SAL_CALL ScTableSheetObj::setPrintTitleRows( sal_Bool bPrintTitleRows )
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
 
-        ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver();
+        std::unique_ptr<ScPrintRangeSaver> pOldRanges = rDoc.CreatePrintRangeSaver();
 
         if ( bPrintTitleRows )
         {
@@ -7397,7 +7391,7 @@ void SAL_CALL ScTableSheetObj::setPrintTitleRows( sal_Bool bPrintTitleRows )
         else
             rDoc.SetRepeatRowRange( nTab, nullptr );          // disable
 
-        PrintAreaUndo_Impl( pOldRanges );   // undo, page breaks, modified etc.
+        PrintAreaUndo_Impl( std::move(pOldRanges) );   // undo, page breaks, modified etc.
 
         //! save last set area during switch off and recreate during switch on ???
     }
@@ -7431,13 +7425,13 @@ void SAL_CALL ScTableSheetObj::setTitleRows( const table::CellRangeAddress& aTit
         ScDocument& rDoc = pDocSh->GetDocument();
         SCTAB nTab = GetTab_Impl();
 
-        ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver();
+        std::unique_ptr<ScPrintRangeSaver> pOldRanges = rDoc.CreatePrintRangeSaver();
 
         std::unique_ptr<ScRange> pNew(new ScRange);
         ScUnoConversion::FillScRange( *pNew, aTitleRows );
         rDoc.SetRepeatRowRange( nTab, std::move(pNew) );     // also always enable
 
-        PrintAreaUndo_Impl( pOldRanges );           // Undo, page breaks, modified etc.
+        PrintAreaUndo_Impl( std::move(pOldRanges) );           // Undo, page breaks, modified etc.
     }
 }
 
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 52ffead4d2b3..dfa2728d2486 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -950,7 +950,7 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint,
     SCTAB nTab;
     bool bUndo (rDoc.IsUndoEnabled());
 
-    ScPrintRangeSaver* pOldRanges = rDoc.CreatePrintRangeSaver();
+    std::unique_ptr<ScPrintRangeSaver> pOldRanges = rDoc.CreatePrintRangeSaver();
 
     ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0);
 
@@ -1030,12 +1030,12 @@ void ScViewFunc::SetPrintRanges( bool bEntireSheet, const OUString* pPrint,
     if (bUndo)
     {
         SCTAB nCurTab = GetViewData().GetTabNo();
-        ScPrintRangeSaver* pNewRanges = rDoc.CreatePrintRangeSaver();
+        std::unique_ptr<ScPrintRangeSaver> pNewRanges = rDoc.CreatePrintRangeSaver();
         pDocSh->GetUndoManager()->AddUndoAction(
-                    new ScUndoPrintRange( pDocSh, nCurTab, pOldRanges, pNewRanges ) );
+                    new ScUndoPrintRange( pDocSh, nCurTab, std::move(pOldRanges), std::move(pNewRanges) ) );
     }
     else
-        delete pOldRanges;
+        pOldRanges.reset();
 
     //  update page breaks
 


More information about the Libreoffice-commits mailing list