diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-05 15:52:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-06 14:36:56 +0200 |
commit | 3e62ac3e9ef2f6759d8faca2c012dba51c314ba5 (patch) | |
tree | a7a8c60af750eb9317ad75fabbb9cafaeba21e53 /chart2 | |
parent | b603c7629143b99f19f7ac6c4da2ab67d5ba20df (diff) |
loplugin:useuniqueptr in VCoordinateSystem
Change-Id: I369d6755d3de2dd885214115559150256298852d
Reviewed-on: https://gerrit.libreoffice.org/60051
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/inc/ChartView.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/axes/VCoordinateSystem.cxx | 10 | ||||
-rw-r--r-- | chart2/source/view/inc/VCoordinateSystem.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 81 |
4 files changed, 43 insertions, 52 deletions
diff --git a/chart2/inc/ChartView.hxx b/chart2/inc/ChartView.hxx index 9d71af8c8eab..5ae3930ebd01 100644 --- a/chart2/inc/ChartView.hxx +++ b/chart2/inc/ChartView.hxx @@ -223,7 +223,7 @@ private: //member std::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper; - std::vector< VCoordinateSystem* > m_aVCooSysList; + std::vector< std::unique_ptr<VCoordinateSystem> > m_aVCooSysList; ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx index b6446e3462c1..9d7373cc4abe 100644 --- a/chart2/source/view/axes/VCoordinateSystem.cxx +++ b/chart2/source/view/axes/VCoordinateSystem.cxx @@ -52,7 +52,7 @@ using namespace ::com::sun::star::chart2; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; -VCoordinateSystem* VCoordinateSystem::createCoordinateSystem( +std::unique_ptr<VCoordinateSystem> VCoordinateSystem::createCoordinateSystem( const Reference< XCoordinateSystem >& xCooSysModel ) { if( !xCooSysModel.is() ) @@ -61,13 +61,13 @@ VCoordinateSystem* VCoordinateSystem::createCoordinateSystem( OUString aViewServiceName = xCooSysModel->getViewServiceName(); //@todo: in future the coordinatesystems should be instantiated via service factory - VCoordinateSystem* pRet=nullptr; + std::unique_ptr<VCoordinateSystem> pRet; if( aViewServiceName == CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME ) - pRet = new VCartesianCoordinateSystem(xCooSysModel); + pRet.reset( new VCartesianCoordinateSystem(xCooSysModel) ); else if( aViewServiceName == CHART2_COOSYSTEM_POLAR_VIEW_SERVICE_NAME ) - pRet = new VPolarCoordinateSystem(xCooSysModel); + pRet.reset( new VPolarCoordinateSystem(xCooSysModel) ); if(!pRet) - pRet = new VCoordinateSystem(xCooSysModel); + pRet.reset( new VCoordinateSystem(xCooSysModel) ); return pRet; } diff --git a/chart2/source/view/inc/VCoordinateSystem.hxx b/chart2/source/view/inc/VCoordinateSystem.hxx index a9af6553a7ea..997c23e7c571 100644 --- a/chart2/source/view/inc/VCoordinateSystem.hxx +++ b/chart2/source/view/inc/VCoordinateSystem.hxx @@ -51,7 +51,7 @@ class VCoordinateSystem public: virtual ~VCoordinateSystem(); - static VCoordinateSystem* createCoordinateSystem( const css::uno::Reference< + static std::unique_ptr<VCoordinateSystem> createCoordinateSystem( const css::uno::Reference< css::chart2::XCoordinateSystem >& xCooSysModel ); /// @throws css::uno::RuntimeException diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 5bd8dc7b8f04..4c393df4edbe 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -262,7 +262,7 @@ typedef std::vector<std::unique_ptr<VSeriesPlotter> > SeriesPlottersType; class SeriesPlotterContainer { public: - explicit SeriesPlotterContainer( std::vector< VCoordinateSystem* >& rVCooSysList ); + explicit SeriesPlotterContainer( std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList ); ~SeriesPlotterContainer(); /** It is used to set coordinate systems (`m_rVCooSysList`), this method @@ -338,7 +338,7 @@ public: drawing::Direction3D getPreferredAspectRatio(); SeriesPlottersType& getSeriesPlotterList() { return m_aSeriesPlotterList; } - std::vector< VCoordinateSystem* >& getCooSysList() { return m_rVCooSysList; } + std::vector< std::unique_ptr<VCoordinateSystem> >& getCooSysList() { return m_rVCooSysList; } std::vector< LegendEntryProvider* > getLegendEntryProviderList(); void AdaptScaleOfYAxisWithoutAttachedSeries( ChartModel& rModel ); @@ -353,7 +353,7 @@ private: /** A vector of coordinate systems. */ - std::vector< VCoordinateSystem* >& m_rVCooSysList; + std::vector< std::unique_ptr<VCoordinateSystem> >& m_rVCooSysList; /** A map whose key is a `XAxis` interface and the related value is * an object of `AxisUsage` type. @@ -372,7 +372,7 @@ private: sal_Int32 m_nDefaultDateNumberFormat; }; -SeriesPlotterContainer::SeriesPlotterContainer( std::vector< VCoordinateSystem* >& rVCooSysList ) +SeriesPlotterContainer::SeriesPlotterContainer( std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList ) : m_rVCooSysList( rVCooSysList ) , m_nMaxAxisIndex(0) , m_bChartTypeUsesShiftedCategoryPositionPerDefault(false) @@ -383,7 +383,7 @@ SeriesPlotterContainer::SeriesPlotterContainer( std::vector< VCoordinateSystem* SeriesPlotterContainer::~SeriesPlotterContainer() { // - remove plotter from coordinatesystems - for(VCoordinateSystem* nC : m_rVCooSysList) + for(auto & nC : m_rVCooSysList) nC->clearMinimumAndMaximumSupplierList(); } @@ -396,48 +396,47 @@ std::vector< LegendEntryProvider* > SeriesPlotterContainer::getLegendEntryProvid return aRet; } -VCoordinateSystem* findInCooSysList( const std::vector< VCoordinateSystem* >& rVCooSysList +VCoordinateSystem* findInCooSysList( const std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList , const uno::Reference< XCoordinateSystem >& xCooSys ) { - for(VCoordinateSystem* pVCooSys : rVCooSysList) + for(auto & pVCooSys : rVCooSysList) { if(pVCooSys->getModel()==xCooSys) - return pVCooSys; + return pVCooSys.get(); } return nullptr; } -VCoordinateSystem* lcl_getCooSysForPlotter( const std::vector< VCoordinateSystem* >& rVCooSysList, MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier ) +VCoordinateSystem* lcl_getCooSysForPlotter( const std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList, MinimumAndMaximumSupplier* pMinimumAndMaximumSupplier ) { if(!pMinimumAndMaximumSupplier) return nullptr; - for(VCoordinateSystem* pVCooSys : rVCooSysList) + for(auto & pVCooSys : rVCooSysList) { if(pVCooSys->hasMinimumAndMaximumSupplier( pMinimumAndMaximumSupplier )) - return pVCooSys; + return pVCooSys.get(); } return nullptr; } -VCoordinateSystem* addCooSysToList( std::vector< VCoordinateSystem* >& rVCooSysList +VCoordinateSystem* addCooSysToList( std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList , const uno::Reference< XCoordinateSystem >& xCooSys , ChartModel& rChartModel ) { - VCoordinateSystem* pVCooSys = findInCooSysList( rVCooSysList, xCooSys ); - if( !pVCooSys ) - { - pVCooSys = VCoordinateSystem::createCoordinateSystem(xCooSys ); - if(pVCooSys) - { - OUString aCooSysParticle( ObjectIdentifier::createParticleForCoordinateSystem( xCooSys, rChartModel ) ); - pVCooSys->setParticle(aCooSysParticle); + VCoordinateSystem* pExistingVCooSys = findInCooSysList( rVCooSysList, xCooSys ); + if( pExistingVCooSys ) + return pExistingVCooSys; - pVCooSys->setExplicitCategoriesProvider( new ExplicitCategoriesProvider(xCooSys, rChartModel) ); + std::unique_ptr<VCoordinateSystem> pVCooSys = VCoordinateSystem::createCoordinateSystem(xCooSys ); + if(!pVCooSys) + return nullptr; - rVCooSysList.push_back( pVCooSys ); - } - } - return pVCooSys; + OUString aCooSysParticle( ObjectIdentifier::createParticleForCoordinateSystem( xCooSys, rChartModel ) ); + pVCooSys->setParticle(aCooSysParticle); + + pVCooSys->setExplicitCategoriesProvider( new ExplicitCategoriesProvider(xCooSys, rChartModel) ); + rVCooSysList.push_back( std::move(pVCooSys) ); + return rVCooSysList.back().get(); } void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( @@ -621,10 +620,8 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( { uno::Sequence< OUString > aSeriesNames; bool bSeriesNamesInitialized = false; - for(VCoordinateSystem* pVCooSys : m_rVCooSysList) + for(auto & pVCooSys : m_rVCooSysList) { - if(!pVCooSys) - continue; if( pVCooSys->needSeriesNamesForAxis() ) { if(!bSeriesNamesInitialized) @@ -662,7 +659,7 @@ void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate) // Loop through coordinate systems in the diagram (though for now // there should only be one coordinate system per diagram). - for (VCoordinateSystem* pVCooSys : m_rVCooSysList) + for (auto & pVCooSys : m_rVCooSysList) { uno::Reference<XCoordinateSystem> xCooSys = pVCooSys->getModel(); sal_Int32 nDimCount = xCooSys->getDimension(); @@ -697,14 +694,14 @@ void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate) } AxisUsage& rAxisUsage = m_aAxisUsageList[xAxis]; - rAxisUsage.addCoordinateSystem(pVCooSys, nDimIndex, nAxisIndex); + rAxisUsage.addCoordinateSystem(pVCooSys.get(), nDimIndex, nAxisIndex); } } } // Determine the highest axis index of all dimensions. m_nMaxAxisIndex = 0; - for (VCoordinateSystem* pVCooSys : m_rVCooSysList) + for (auto & pVCooSys : m_rVCooSysList) { uno::Reference<XCoordinateSystem> xCooSys = pVCooSys->getModel(); sal_Int32 nDimCount = xCooSys->getDimension(); @@ -785,7 +782,7 @@ void SeriesPlotterContainer::setNumberFormatsFromAxes() void SeriesPlotterContainer::updateScalesAndIncrementsOnAxes() { - for(VCoordinateSystem* nC : m_rVCooSysList) + for(auto & nC : m_rVCooSysList) nC->updateScalesAndIncrementsOnAxes(); } @@ -1136,13 +1133,7 @@ ChartView::~ChartView() void ChartView::impl_deleteCoordinateSystems() { //delete all coordinate systems - std::vector< VCoordinateSystem* > aVectorToDeleteObjects; - std::swap( aVectorToDeleteObjects, m_aVCooSysList );//#i109770# - for (auto const& elem : aVectorToDeleteObjects) - { - delete elem; - } - aVectorToDeleteObjects.clear(); + m_aVCooSysList.clear();//#i109770# } // datatransfer::XTransferable @@ -1469,7 +1460,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D basegfx::B2IRectangle aAvailableOuterRect = BaseGFXHelper::makeRectangle(rParam.maRemainingSpace); - const std::vector< VCoordinateSystem* >& rVCooSysList( rParam.mpSeriesPlotterContainer->getCooSysList() ); + const std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList( rParam.mpSeriesPlotterContainer->getCooSysList() ); SeriesPlottersType& rSeriesPlotterList = rParam.mpSeriesPlotterContainer->getSeriesPlotterList(); //create VAxis, so they can give necessary information for automatic scaling @@ -1479,7 +1470,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D size_t nC = 0; for( nC=0; nC < rVCooSysList.size(); nC++) { - VCoordinateSystem* pVCooSys = rVCooSysList[nC]; + VCoordinateSystem* pVCooSys = rVCooSysList[nC].get(); if(nDimensionCount==3) { uno::Reference<beans::XPropertySet> xSceneProperties( xDiagram, uno::UNO_QUERY ); @@ -1529,7 +1520,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D //init all coordinate systems for( nC=0; nC < rVCooSysList.size(); nC++) { - VCoordinateSystem* pVCooSys = rVCooSysList[nC]; + VCoordinateSystem* pVCooSys = rVCooSysList[nC].get(); pVCooSys->initPlottingTargets(xSeriesTargetInFrontOfAxis,xTextTargetShapes,m_xShapeFactory,xSeriesTargetBehindAxis); pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( @@ -1547,7 +1538,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D //todo: this is just a workaround at the moment for pie and donut labels if( !bIsPieOrDonut && (!rVCooSysList.empty()) ) { - VCoordinateSystem* pVCooSys = rVCooSysList[0]; + VCoordinateSystem* pVCooSys = rVCooSysList[0].get(); pVCooSys->createMaximumAxesLabels(); aConsumedOuterRect = ShapeFactory::getRectangleOfShape(xBoundingShape); @@ -1587,7 +1578,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D //create axes and grids for the final size for( nC=0; nC < rVCooSysList.size(); nC++) { - VCoordinateSystem* pVCooSys = rVCooSysList[nC]; + VCoordinateSystem* pVCooSys = rVCooSysList[nC].get(); pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( createTransformationSceneToScreen( aVDiagram.getCurrentRectangle() ) )); @@ -1648,7 +1639,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D //set new transformation for( nC=0; nC < rVCooSysList.size(); nC++) { - VCoordinateSystem* pVCooSys = rVCooSysList[nC]; + VCoordinateSystem* pVCooSys = rVCooSysList[nC].get(); pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( createTransformationSceneToScreen( aNewInnerRect ) )); } |