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

Noel (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 23 06:31:11 UTC 2021


 chart2/source/controller/accessibility/AccessibleBase.cxx  |    2 
 chart2/source/controller/main/ChartController.cxx          |   10 ++--
 chart2/source/controller/main/CommandDispatchContainer.cxx |    5 +-
 chart2/source/model/main/Axis.cxx                          |    7 +--
 chart2/source/model/main/DataSeries.cxx                    |    7 +--
 chart2/source/tools/CachedDataSequence.cxx                 |    4 -
 chart2/source/tools/UncachedDataSequence.cxx               |    3 -
 chart2/source/view/main/ChartView.cxx                      |   28 ++++---------
 8 files changed, 26 insertions(+), 40 deletions(-)

New commits:
commit 9861aaad25f3e9bf5d78c56143c3f3b727c73007
Author:     Noel <noel.grandin at collabora.co.uk>
AuthorDate: Mon Feb 22 19:44:07 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Feb 23 07:30:22 2021 +0100

    loplugin:refcounting in chart2
    
    Change-Id: I4949e67aae74631acc138a3a52621705cda0dd77
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111353
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/chart2/source/controller/accessibility/AccessibleBase.cxx b/chart2/source/controller/accessibility/AccessibleBase.cxx
index 7d9e244bfa1b..9e05f896b422 100644
--- a/chart2/source/controller/accessibility/AccessibleBase.cxx
+++ b/chart2/source/controller/accessibility/AccessibleBase.cxx
@@ -427,7 +427,7 @@ void SAL_CALL AccessibleBase::disposing()
         m_aAccInfo.m_pParent = nullptr;
 
         // attach new empty state set helper to member reference
-        ::utl::AccessibleStateSetHelper * pHelper = new ::utl::AccessibleStateSetHelper();
+        rtl::Reference<::utl::AccessibleStateSetHelper> pHelper = new ::utl::AccessibleStateSetHelper();
         pHelper->AddState(AccessibleStateType::DEFUNC);
         // release old helper and attach new one
         m_xStateSetHelper = pHelper;
diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx
index d19f3b97ef32..3d310d8d8bea 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -588,7 +588,7 @@ sal_Bool SAL_CALL ChartController::attachModel( const uno::Reference< frame::XMo
     aGuard.reset(); // lock for m_aDispatchContainer access
     // set new model at dispatchers
     m_aDispatchContainer.setModel( aNewModelRef->getModel());
-    ControllerCommandDispatch * pDispatch = new ControllerCommandDispatch( m_xCC, this, &m_aDispatchContainer );
+    rtl::Reference<ControllerCommandDispatch> pDispatch = new ControllerCommandDispatch( m_xCC, this, &m_aDispatchContainer );
     pDispatch->initialize();
 
     // the dispatch container will return "this" for all commands returned by
@@ -596,13 +596,13 @@ sal_Bool SAL_CALL ChartController::attachModel( const uno::Reference< frame::XMo
     // is called here at the ChartController.
     m_aDispatchContainer.setChartDispatch( pDispatch, impl_getAvailableCommands() );
 
-    DrawCommandDispatch* pDrawDispatch = new DrawCommandDispatch( m_xCC, this );
+    rtl::Reference<DrawCommandDispatch> pDrawDispatch = new DrawCommandDispatch( m_xCC, this );
     pDrawDispatch->initialize();
-    m_aDispatchContainer.setDrawCommandDispatch( pDrawDispatch );
+    m_aDispatchContainer.setDrawCommandDispatch( pDrawDispatch.get() );
 
-    ShapeController* pShapeController = new ShapeController( m_xCC, this );
+    rtl::Reference<ShapeController> pShapeController = new ShapeController( m_xCC, this );
     pShapeController->initialize();
-    m_aDispatchContainer.setShapeController( pShapeController );
+    m_aDispatchContainer.setShapeController( pShapeController.get() );
     aGuard.clear();
 
 #ifdef TEST_ENABLE_MODIFY_LISTENER
diff --git a/chart2/source/controller/main/CommandDispatchContainer.cxx b/chart2/source/controller/main/CommandDispatchContainer.cxx
index b007ebe5c652..dee4c961358e 100644
--- a/chart2/source/controller/main/CommandDispatchContainer.cxx
+++ b/chart2/source/controller/main/CommandDispatchContainer.cxx
@@ -27,6 +27,7 @@
 #include <com/sun/star/frame/XDispatchProvider.hpp>
 #include <com/sun/star/frame/XModel.hpp>
 #include <com/sun/star/view/XSelectionSupplier.hpp>
+#include <rtl/ref.hxx>
 
 #include <o3tl/sorted_vector.hxx>
 
@@ -87,7 +88,7 @@ Reference< frame::XDispatch > CommandDispatchContainer::getDispatchForURL(
         if( xModel.is() && ( rURL.Path == "Undo" || rURL.Path == "Redo" ||
                              rURL.Path == "GetUndoStrings" || rURL.Path == "GetRedoStrings" ) )
         {
-            CommandDispatch * pDispatch = new UndoCommandDispatch( m_xContext, xModel );
+            rtl::Reference<CommandDispatch> pDispatch = new UndoCommandDispatch( m_xContext, xModel );
             xResult.set( pDispatch );
             pDispatch->initialize();
             m_aCachedDispatches[ ".uno:Undo" ].set( xResult );
@@ -99,7 +100,7 @@ Reference< frame::XDispatch > CommandDispatchContainer::getDispatchForURL(
         else if( xModel.is() && ( rURL.Path == "Context" || rURL.Path == "ModifiedStatus" ) )
         {
             Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), uno::UNO_QUERY );
-            CommandDispatch * pDispatch = new StatusBarCommandDispatch( m_xContext, xModel, xSelSupp );
+            rtl::Reference<CommandDispatch> pDispatch = new StatusBarCommandDispatch( m_xContext, xModel, xSelSupp );
             xResult.set( pDispatch );
             pDispatch->initialize();
             m_aCachedDispatches[ ".uno:Context" ].set( xResult );
diff --git a/chart2/source/model/main/Axis.cxx b/chart2/source/model/main/Axis.cxx
index ff42899d0c18..d736ca6c5137 100644
--- a/chart2/source/model/main/Axis.cxx
+++ b/chart2/source/model/main/Axis.cxx
@@ -37,6 +37,7 @@
 #include <com/sun/star/awt/Size.hpp>
 #include <cppuhelper/supportsservice.hxx>
 #include <tools/diagnose_ex.h>
+#include <rtl/ref.hxx>
 
 #include <vector>
 #include <algorithm>
@@ -517,12 +518,10 @@ void SAL_CALL Axis::setTitleObject( const Reference< chart2::XTitle >& xNewTitle
 // ____ XCloneable ____
 Reference< util::XCloneable > SAL_CALL Axis::createClone()
 {
-    Axis * pNewAxis( new Axis( *this ));
-    // hold a reference to the clone
-    Reference< util::XCloneable > xResult( pNewAxis );
+    rtl::Reference<Axis> pNewAxis( new Axis( *this ));
     // do initialization that uses uno references to the clone
     pNewAxis->Init();
-    return xResult;
+    return pNewAxis;
 }
 
 // ____ XModifyBroadcaster ____
diff --git a/chart2/source/model/main/DataSeries.cxx b/chart2/source/model/main/DataSeries.cxx
index a2f1247ad08e..b873c19650b9 100644
--- a/chart2/source/model/main/DataSeries.cxx
+++ b/chart2/source/model/main/DataSeries.cxx
@@ -31,6 +31,7 @@
 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
 #include <cppuhelper/supportsservice.hxx>
 #include <tools/diagnose_ex.h>
+#include <rtl/ref.hxx>
 
 #include <algorithm>
 
@@ -221,13 +222,11 @@ DataSeries::~DataSeries()
 // ____ XCloneable ____
 uno::Reference< util::XCloneable > SAL_CALL DataSeries::createClone()
 {
-    DataSeries * pNewSeries( new DataSeries( *this ));
-    // hold a reference to the clone
-    uno::Reference< util::XCloneable > xResult( pNewSeries );
+    rtl::Reference<DataSeries> pNewSeries( new DataSeries( *this ));
     // do initialization that uses uno references to the clone
     pNewSeries->Init( *this );
 
-    return xResult;
+    return pNewSeries;
 }
 
 // ____ OPropertySet ____
diff --git a/chart2/source/tools/CachedDataSequence.cxx b/chart2/source/tools/CachedDataSequence.cxx
index 6c8826701779..42b5249adc2b 100644
--- a/chart2/source/tools/CachedDataSequence.cxx
+++ b/chart2/source/tools/CachedDataSequence.cxx
@@ -310,9 +310,7 @@ Sequence< OUString > SAL_CALL CachedDataSequence::generateLabel( chart2::data::L
 
 Reference< util::XCloneable > SAL_CALL CachedDataSequence::createClone()
 {
-    CachedDataSequence * pNewSeq = new CachedDataSequence( *this );
-
-    return Reference< util::XCloneable >( pNewSeq );
+    return new CachedDataSequence( *this );
 }
 
 void SAL_CALL CachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
diff --git a/chart2/source/tools/UncachedDataSequence.cxx b/chart2/source/tools/UncachedDataSequence.cxx
index fee4af622126..40412ffa16ae 100644
--- a/chart2/source/tools/UncachedDataSequence.cxx
+++ b/chart2/source/tools/UncachedDataSequence.cxx
@@ -281,8 +281,7 @@ void SAL_CALL UncachedDataSequence::setName( const OUString& aName )
 
 Reference< util::XCloneable > SAL_CALL UncachedDataSequence::createClone()
 {
-    UncachedDataSequence * pNewSeq = new UncachedDataSequence( *this );
-    return Reference< util::XCloneable >( pNewSeq );
+    return new UncachedDataSequence( *this );
 }
 
 // ____ XModifiable ____
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 93bf35672123..41a9aaa00393 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -1178,26 +1178,16 @@ uno::Any SAL_CALL ChartView::getTransferData( const datatransfer::DataFlavor& aF
     update();
 
     SvMemoryStream aStream( 1024, 1024 );
-    utl::OStreamWrapper* pStreamWrapper = new utl::OStreamWrapper( aStream );
+    rtl::Reference<utl::OStreamWrapper> pStreamWrapper = new utl::OStreamWrapper( aStream );
 
-    uno::Reference< io::XOutputStream > xOutStream( pStreamWrapper );
-    uno::Reference< io::XInputStream > xInStream( pStreamWrapper );
-    uno::Reference< io::XSeekable > xSeekable( pStreamWrapper );
+    this->getMetaFile( pStreamWrapper, bHighContrastMetaFile );
 
-    if( xOutStream.is() )
-    {
-        this->getMetaFile( xOutStream, bHighContrastMetaFile );
-
-        if( xInStream.is() && xSeekable.is() )
-        {
-            xSeekable->seek(0);
-            sal_Int32 nBytesToRead = xInStream->available();
-            uno::Sequence< sal_Int8 > aSeq( nBytesToRead );
-            xInStream->readBytes( aSeq, nBytesToRead);
-            aRet <<= aSeq;
-            xInStream->closeInput();
-        }
-    }
+    pStreamWrapper->seek(0);
+    sal_Int32 nBytesToRead = pStreamWrapper->available();
+    uno::Sequence< sal_Int8 > aSeq( nBytesToRead );
+    pStreamWrapper->readBytes( aSeq, nBytesToRead);
+    aRet <<= aSeq;
+    pStreamWrapper->closeInput();
 
     return aRet;
 }
@@ -3117,7 +3107,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
 com_sun_star_comp_chart2_ChartView_get_implementation(css::uno::XComponentContext *context,
                                                          css::uno::Sequence<css::uno::Any> const &)
 {
-    ::chart::ChartModel *pChartModel = new ::chart::ChartModel(context);
+    rtl::Reference<::chart::ChartModel> pChartModel = new ::chart::ChartModel(context);
     return cppu::acquire(new ::chart::ChartView(context, *pChartModel));
 }
 


More information about the Libreoffice-commits mailing list