Kaydet (Commit) 3e62ac3e authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in VCoordinateSystem

Change-Id: I369d6755d3de2dd885214115559150256298852d
Reviewed-on: https://gerrit.libreoffice.org/60051
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst b603c762
...@@ -223,7 +223,7 @@ private: //member ...@@ -223,7 +223,7 @@ private: //member
std::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper; std::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper;
std::vector< VCoordinateSystem* > m_aVCooSysList; std::vector< std::unique_ptr<VCoordinateSystem> > m_aVCooSysList;
::cppu::OMultiTypeInterfaceContainerHelper ::cppu::OMultiTypeInterfaceContainerHelper
m_aListenerContainer; m_aListenerContainer;
......
...@@ -52,7 +52,7 @@ using namespace ::com::sun::star::chart2; ...@@ -52,7 +52,7 @@ using namespace ::com::sun::star::chart2;
using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence; using ::com::sun::star::uno::Sequence;
VCoordinateSystem* VCoordinateSystem::createCoordinateSystem( std::unique_ptr<VCoordinateSystem> VCoordinateSystem::createCoordinateSystem(
const Reference< XCoordinateSystem >& xCooSysModel ) const Reference< XCoordinateSystem >& xCooSysModel )
{ {
if( !xCooSysModel.is() ) if( !xCooSysModel.is() )
...@@ -61,13 +61,13 @@ VCoordinateSystem* VCoordinateSystem::createCoordinateSystem( ...@@ -61,13 +61,13 @@ VCoordinateSystem* VCoordinateSystem::createCoordinateSystem(
OUString aViewServiceName = xCooSysModel->getViewServiceName(); OUString aViewServiceName = xCooSysModel->getViewServiceName();
//@todo: in future the coordinatesystems should be instantiated via service factory //@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 ) 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 ) else if( aViewServiceName == CHART2_COOSYSTEM_POLAR_VIEW_SERVICE_NAME )
pRet = new VPolarCoordinateSystem(xCooSysModel); pRet.reset( new VPolarCoordinateSystem(xCooSysModel) );
if(!pRet) if(!pRet)
pRet = new VCoordinateSystem(xCooSysModel); pRet.reset( new VCoordinateSystem(xCooSysModel) );
return pRet; return pRet;
} }
......
...@@ -51,7 +51,7 @@ class VCoordinateSystem ...@@ -51,7 +51,7 @@ class VCoordinateSystem
public: public:
virtual ~VCoordinateSystem(); virtual ~VCoordinateSystem();
static VCoordinateSystem* createCoordinateSystem( const css::uno::Reference< static std::unique_ptr<VCoordinateSystem> createCoordinateSystem( const css::uno::Reference<
css::chart2::XCoordinateSystem >& xCooSysModel ); css::chart2::XCoordinateSystem >& xCooSysModel );
/// @throws css::uno::RuntimeException /// @throws css::uno::RuntimeException
......
...@@ -262,7 +262,7 @@ typedef std::vector<std::unique_ptr<VSeriesPlotter> > SeriesPlottersType; ...@@ -262,7 +262,7 @@ typedef std::vector<std::unique_ptr<VSeriesPlotter> > SeriesPlottersType;
class SeriesPlotterContainer class SeriesPlotterContainer
{ {
public: public:
explicit SeriesPlotterContainer( std::vector< VCoordinateSystem* >& rVCooSysList ); explicit SeriesPlotterContainer( std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList );
~SeriesPlotterContainer(); ~SeriesPlotterContainer();
/** It is used to set coordinate systems (`m_rVCooSysList`), this method /** It is used to set coordinate systems (`m_rVCooSysList`), this method
...@@ -338,7 +338,7 @@ public: ...@@ -338,7 +338,7 @@ public:
drawing::Direction3D getPreferredAspectRatio(); drawing::Direction3D getPreferredAspectRatio();
SeriesPlottersType& getSeriesPlotterList() { return m_aSeriesPlotterList; } 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(); std::vector< LegendEntryProvider* > getLegendEntryProviderList();
void AdaptScaleOfYAxisWithoutAttachedSeries( ChartModel& rModel ); void AdaptScaleOfYAxisWithoutAttachedSeries( ChartModel& rModel );
...@@ -353,7 +353,7 @@ private: ...@@ -353,7 +353,7 @@ private:
/** A vector of coordinate systems. /** 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 /** A map whose key is a `XAxis` interface and the related value is
* an object of `AxisUsage` type. * an object of `AxisUsage` type.
...@@ -372,7 +372,7 @@ private: ...@@ -372,7 +372,7 @@ private:
sal_Int32 m_nDefaultDateNumberFormat; sal_Int32 m_nDefaultDateNumberFormat;
}; };
SeriesPlotterContainer::SeriesPlotterContainer( std::vector< VCoordinateSystem* >& rVCooSysList ) SeriesPlotterContainer::SeriesPlotterContainer( std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList )
: m_rVCooSysList( rVCooSysList ) : m_rVCooSysList( rVCooSysList )
, m_nMaxAxisIndex(0) , m_nMaxAxisIndex(0)
, m_bChartTypeUsesShiftedCategoryPositionPerDefault(false) , m_bChartTypeUsesShiftedCategoryPositionPerDefault(false)
...@@ -383,7 +383,7 @@ SeriesPlotterContainer::SeriesPlotterContainer( std::vector< VCoordinateSystem* ...@@ -383,7 +383,7 @@ SeriesPlotterContainer::SeriesPlotterContainer( std::vector< VCoordinateSystem*
SeriesPlotterContainer::~SeriesPlotterContainer() SeriesPlotterContainer::~SeriesPlotterContainer()
{ {
// - remove plotter from coordinatesystems // - remove plotter from coordinatesystems
for(VCoordinateSystem* nC : m_rVCooSysList) for(auto & nC : m_rVCooSysList)
nC->clearMinimumAndMaximumSupplierList(); nC->clearMinimumAndMaximumSupplierList();
} }
...@@ -396,48 +396,47 @@ std::vector< LegendEntryProvider* > SeriesPlotterContainer::getLegendEntryProvid ...@@ -396,48 +396,47 @@ std::vector< LegendEntryProvider* > SeriesPlotterContainer::getLegendEntryProvid
return aRet; return aRet;
} }
VCoordinateSystem* findInCooSysList( const std::vector< VCoordinateSystem* >& rVCooSysList VCoordinateSystem* findInCooSysList( const std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList
, const uno::Reference< XCoordinateSystem >& xCooSys ) , const uno::Reference< XCoordinateSystem >& xCooSys )
{ {
for(VCoordinateSystem* pVCooSys : rVCooSysList) for(auto & pVCooSys : rVCooSysList)
{ {
if(pVCooSys->getModel()==xCooSys) if(pVCooSys->getModel()==xCooSys)
return pVCooSys; return pVCooSys.get();
} }
return nullptr; 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) if(!pMinimumAndMaximumSupplier)
return nullptr; return nullptr;
for(VCoordinateSystem* pVCooSys : rVCooSysList) for(auto & pVCooSys : rVCooSysList)
{ {
if(pVCooSys->hasMinimumAndMaximumSupplier( pMinimumAndMaximumSupplier )) if(pVCooSys->hasMinimumAndMaximumSupplier( pMinimumAndMaximumSupplier ))
return pVCooSys; return pVCooSys.get();
} }
return nullptr; return nullptr;
} }
VCoordinateSystem* addCooSysToList( std::vector< VCoordinateSystem* >& rVCooSysList VCoordinateSystem* addCooSysToList( std::vector< std::unique_ptr<VCoordinateSystem> >& rVCooSysList
, const uno::Reference< XCoordinateSystem >& xCooSys , const uno::Reference< XCoordinateSystem >& xCooSys
, ChartModel& rChartModel ) , ChartModel& rChartModel )
{ {
VCoordinateSystem* pVCooSys = findInCooSysList( rVCooSysList, xCooSys ); VCoordinateSystem* pExistingVCooSys = findInCooSysList( rVCooSysList, xCooSys );
if( !pVCooSys ) if( pExistingVCooSys )
{ return pExistingVCooSys;
pVCooSys = VCoordinateSystem::createCoordinateSystem(xCooSys );
if(pVCooSys) std::unique_ptr<VCoordinateSystem> pVCooSys = VCoordinateSystem::createCoordinateSystem(xCooSys );
{ if(!pVCooSys)
return nullptr;
OUString aCooSysParticle( ObjectIdentifier::createParticleForCoordinateSystem( xCooSys, rChartModel ) ); OUString aCooSysParticle( ObjectIdentifier::createParticleForCoordinateSystem( xCooSys, rChartModel ) );
pVCooSys->setParticle(aCooSysParticle); pVCooSys->setParticle(aCooSysParticle);
pVCooSys->setExplicitCategoriesProvider( new ExplicitCategoriesProvider(xCooSys, rChartModel) ); pVCooSys->setExplicitCategoriesProvider( new ExplicitCategoriesProvider(xCooSys, rChartModel) );
rVCooSysList.push_back( std::move(pVCooSys) );
rVCooSysList.push_back( pVCooSys ); return rVCooSysList.back().get();
}
}
return pVCooSys;
} }
void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter(
...@@ -621,10 +620,8 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( ...@@ -621,10 +620,8 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter(
{ {
uno::Sequence< OUString > aSeriesNames; uno::Sequence< OUString > aSeriesNames;
bool bSeriesNamesInitialized = false; bool bSeriesNamesInitialized = false;
for(VCoordinateSystem* pVCooSys : m_rVCooSysList) for(auto & pVCooSys : m_rVCooSysList)
{ {
if(!pVCooSys)
continue;
if( pVCooSys->needSeriesNamesForAxis() ) if( pVCooSys->needSeriesNamesForAxis() )
{ {
if(!bSeriesNamesInitialized) if(!bSeriesNamesInitialized)
...@@ -662,7 +659,7 @@ void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate) ...@@ -662,7 +659,7 @@ void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate)
// Loop through coordinate systems in the diagram (though for now // Loop through coordinate systems in the diagram (though for now
// there should only be one coordinate system per diagram). // 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(); uno::Reference<XCoordinateSystem> xCooSys = pVCooSys->getModel();
sal_Int32 nDimCount = xCooSys->getDimension(); sal_Int32 nDimCount = xCooSys->getDimension();
...@@ -697,14 +694,14 @@ void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate) ...@@ -697,14 +694,14 @@ void SeriesPlotterContainer::initAxisUsageList(const Date& rNullDate)
} }
AxisUsage& rAxisUsage = m_aAxisUsageList[xAxis]; AxisUsage& rAxisUsage = m_aAxisUsageList[xAxis];
rAxisUsage.addCoordinateSystem(pVCooSys, nDimIndex, nAxisIndex); rAxisUsage.addCoordinateSystem(pVCooSys.get(), nDimIndex, nAxisIndex);
} }
} }
} }
// Determine the highest axis index of all dimensions. // Determine the highest axis index of all dimensions.
m_nMaxAxisIndex = 0; m_nMaxAxisIndex = 0;
for (VCoordinateSystem* pVCooSys : m_rVCooSysList) for (auto & pVCooSys : m_rVCooSysList)
{ {
uno::Reference<XCoordinateSystem> xCooSys = pVCooSys->getModel(); uno::Reference<XCoordinateSystem> xCooSys = pVCooSys->getModel();
sal_Int32 nDimCount = xCooSys->getDimension(); sal_Int32 nDimCount = xCooSys->getDimension();
...@@ -785,7 +782,7 @@ void SeriesPlotterContainer::setNumberFormatsFromAxes() ...@@ -785,7 +782,7 @@ void SeriesPlotterContainer::setNumberFormatsFromAxes()
void SeriesPlotterContainer::updateScalesAndIncrementsOnAxes() void SeriesPlotterContainer::updateScalesAndIncrementsOnAxes()
{ {
for(VCoordinateSystem* nC : m_rVCooSysList) for(auto & nC : m_rVCooSysList)
nC->updateScalesAndIncrementsOnAxes(); nC->updateScalesAndIncrementsOnAxes();
} }
...@@ -1136,13 +1133,7 @@ ChartView::~ChartView() ...@@ -1136,13 +1133,7 @@ ChartView::~ChartView()
void ChartView::impl_deleteCoordinateSystems() void ChartView::impl_deleteCoordinateSystems()
{ {
//delete all coordinate systems //delete all coordinate systems
std::vector< VCoordinateSystem* > aVectorToDeleteObjects; m_aVCooSysList.clear();//#i109770#
std::swap( aVectorToDeleteObjects, m_aVCooSysList );//#i109770#
for (auto const& elem : aVectorToDeleteObjects)
{
delete elem;
}
aVectorToDeleteObjects.clear();
} }
// datatransfer::XTransferable // datatransfer::XTransferable
...@@ -1469,7 +1460,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D ...@@ -1469,7 +1460,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D
basegfx::B2IRectangle aAvailableOuterRect = BaseGFXHelper::makeRectangle(rParam.maRemainingSpace); 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(); SeriesPlottersType& rSeriesPlotterList = rParam.mpSeriesPlotterContainer->getSeriesPlotterList();
//create VAxis, so they can give necessary information for automatic scaling //create VAxis, so they can give necessary information for automatic scaling
...@@ -1479,7 +1470,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D ...@@ -1479,7 +1470,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D
size_t nC = 0; size_t nC = 0;
for( nC=0; nC < rVCooSysList.size(); nC++) for( nC=0; nC < rVCooSysList.size(); nC++)
{ {
VCoordinateSystem* pVCooSys = rVCooSysList[nC]; VCoordinateSystem* pVCooSys = rVCooSysList[nC].get();
if(nDimensionCount==3) if(nDimensionCount==3)
{ {
uno::Reference<beans::XPropertySet> xSceneProperties( xDiagram, uno::UNO_QUERY ); uno::Reference<beans::XPropertySet> xSceneProperties( xDiagram, uno::UNO_QUERY );
...@@ -1529,7 +1520,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D ...@@ -1529,7 +1520,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D
//init all coordinate systems //init all coordinate systems
for( nC=0; nC < rVCooSysList.size(); nC++) for( nC=0; nC < rVCooSysList.size(); nC++)
{ {
VCoordinateSystem* pVCooSys = rVCooSysList[nC]; VCoordinateSystem* pVCooSys = rVCooSysList[nC].get();
pVCooSys->initPlottingTargets(xSeriesTargetInFrontOfAxis,xTextTargetShapes,m_xShapeFactory,xSeriesTargetBehindAxis); pVCooSys->initPlottingTargets(xSeriesTargetInFrontOfAxis,xTextTargetShapes,m_xShapeFactory,xSeriesTargetBehindAxis);
pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix(
...@@ -1547,7 +1538,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D ...@@ -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 //todo: this is just a workaround at the moment for pie and donut labels
if( !bIsPieOrDonut && (!rVCooSysList.empty()) ) if( !bIsPieOrDonut && (!rVCooSysList.empty()) )
{ {
VCoordinateSystem* pVCooSys = rVCooSysList[0]; VCoordinateSystem* pVCooSys = rVCooSysList[0].get();
pVCooSys->createMaximumAxesLabels(); pVCooSys->createMaximumAxesLabels();
aConsumedOuterRect = ShapeFactory::getRectangleOfShape(xBoundingShape); aConsumedOuterRect = ShapeFactory::getRectangleOfShape(xBoundingShape);
...@@ -1587,7 +1578,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D ...@@ -1587,7 +1578,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D
//create axes and grids for the final size //create axes and grids for the final size
for( nC=0; nC < rVCooSysList.size(); nC++) for( nC=0; nC < rVCooSysList.size(); nC++)
{ {
VCoordinateSystem* pVCooSys = rVCooSysList[nC]; VCoordinateSystem* pVCooSys = rVCooSysList[nC].get();
pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix(
createTransformationSceneToScreen( aVDiagram.getCurrentRectangle() ) )); createTransformationSceneToScreen( aVDiagram.getCurrentRectangle() ) ));
...@@ -1648,7 +1639,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D ...@@ -1648,7 +1639,7 @@ awt::Rectangle ChartView::impl_createDiagramAndContent( const CreateShapeParam2D
//set new transformation //set new transformation
for( nC=0; nC < rVCooSysList.size(); nC++) for( nC=0; nC < rVCooSysList.size(); nC++)
{ {
VCoordinateSystem* pVCooSys = rVCooSysList[nC]; VCoordinateSystem* pVCooSys = rVCooSysList[nC].get();
pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix(
createTransformationSceneToScreen( aNewInnerRect ) )); createTransformationSceneToScreen( aNewInnerRect ) ));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment