diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-03-16 09:27:44 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-03-20 17:54:47 +0000 |
commit | 770dd89094a8e60e4d8d9f927fde742e9349fa5d (patch) | |
tree | 01efb552ac2d9abcaee7f1542083e778903c7116 /chart2 | |
parent | 70595c0291e4cc137158c77f6136025b10ce6728 (diff) |
move getStackMode/setStackmode inside chart2::Diagram
Change-Id: Ie359d2a21d288e989bf2bcdfab781938bc8fa26f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149161
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx | 2 | ||||
-rw-r--r-- | chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx | 6 | ||||
-rw-r--r-- | chart2/source/inc/Diagram.hxx | 12 | ||||
-rw-r--r-- | chart2/source/inc/DiagramHelper.hxx | 16 | ||||
-rw-r--r-- | chart2/source/model/main/Diagram.cxx | 103 | ||||
-rw-r--r-- | chart2/source/tools/DiagramHelper.cxx | 102 |
6 files changed, 116 insertions, 125 deletions
diff --git a/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx b/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx index c624f9074687..b54e029d54db 100644 --- a/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx +++ b/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx @@ -672,7 +672,7 @@ void ChartDataWrapper::applyData( lcl_Operator& rDataOperator ) eStackMode = StackMode::ZStacked; else if( bPercent ) eStackMode = StackMode::YStackedPercent; - DiagramHelper::setStackMode( xDia, eStackMode ); + xDia->setStackMode( eStackMode ); } // notify listeners diff --git a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx index 29127127da6f..657751ed3c23 100644 --- a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx +++ b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx @@ -1229,8 +1229,8 @@ bool WrappedStackingProperty::detectInnerValue( StackMode& eStackMode ) const { bool bHasDetectableInnerValue = false; bool bIsAmbiguous = false; - eStackMode = DiagramHelper::getStackMode( m_spChart2ModelContact->getDiagram() - , bHasDetectableInnerValue, bIsAmbiguous ); + rtl::Reference<Diagram> xDiagram = m_spChart2ModelContact->getDiagram(); + eStackMode = xDiagram ? xDiagram->getStackMode( bHasDetectableInnerValue, bIsAmbiguous ) : StackMode::NONE; return bHasDetectableInnerValue; } @@ -1258,7 +1258,7 @@ void WrappedStackingProperty::setPropertyValue( const Any& rOuterValue, const Re if( xDiagram.is() ) { StackMode eNewStackMode = bNewValue ? m_eStackMode : StackMode::NONE; - DiagramHelper::setStackMode( xDiagram, eNewStackMode ); + xDiagram->setStackMode( eNewStackMode ); } } diff --git a/chart2/source/inc/Diagram.hxx b/chart2/source/inc/Diagram.hxx index e6f31bf5db46..9ff0f94bb020 100644 --- a/chart2/source/inc/Diagram.hxx +++ b/chart2/source/inc/Diagram.hxx @@ -45,6 +45,7 @@ class ChartType; class DataSeries; class Legend; class DataTable; +enum class StackMode; class Wall; enum class DiagramPositioningMode @@ -288,6 +289,17 @@ public: */ void setDimension( sal_Int32 nNewDimensionCount ); + + StackMode getStackMode(bool& rbFound, bool& rbAmbiguous); + + /** The stacking mode is only set at the series found inside + the first chart type. This is the standard for all current + templates (the only template that has more than one chart-type and + allows stacking is bar/line combi, and for this the stacking only + applies to the first chart type/the bars) + */ + void setStackMode(StackMode eStackMode); + private: // ____ XModifyListener ____ virtual void SAL_CALL modified( diff --git a/chart2/source/inc/DiagramHelper.hxx b/chart2/source/inc/DiagramHelper.hxx index efb696ffaf01..35f1de7e9eaf 100644 --- a/chart2/source/inc/DiagramHelper.hxx +++ b/chart2/source/inc/DiagramHelper.hxx @@ -88,22 +88,6 @@ public: static bool getVertical( const rtl::Reference< ::chart::Diagram > & xDiagram, bool& rbOutFoundResult, bool& rbOutAmbiguousResult ); - static StackMode getStackMode( - const rtl::Reference< ::chart::Diagram > & xDiagram, - bool& rbFound, bool& rbAmbiguous - ); - - /** The stacking mode is only set at the series found inside - the first chart type. This is the standard for all current - templates (the only template that has more than one chart-type and - allows stacking is bar/line combi, and for this the stacking only - applies to the first chart type/the bars) - */ - static void setStackMode( - const rtl::Reference< ::chart::Diagram > & xDiagram, - StackMode eStackMode - ); - /** Retrieves the stackmode of the first DataSeries or none. If the series have differing stack modes, rbAmbiguous is set to true. If no series is there rbFound is set to false. diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx index a52713c27d93..d2068529f93d 100644 --- a/chart2/source/model/main/Diagram.cxx +++ b/chart2/source/model/main/Diagram.cxx @@ -44,6 +44,7 @@ #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/chart2/AxisType.hpp> #include <com/sun/star/chart2/DataPointGeometry3D.hpp> +#include <com/sun/star/chart2/StackingDirection.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/chart2/RelativeSize.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp> @@ -1399,7 +1400,7 @@ void Diagram::setDimension( sal_Int32 nNewDimensionCount ) { bool rbFound = false; bool rbAmbiguous = true; - StackMode eStackMode = DiagramHelper::getStackMode( this, rbFound, rbAmbiguous ); + StackMode eStackMode = getStackMode( rbFound, rbAmbiguous ); bool bIsSupportingOnlyDeepStackingFor3D=false; //change all coordinate systems: @@ -1429,9 +1430,9 @@ void Diagram::setDimension( sal_Int32 nNewDimensionCount ) //correct stack mode if necessary if( nNewDimensionCount==3 && eStackMode != StackMode::ZStacked && bIsSupportingOnlyDeepStackingFor3D ) - DiagramHelper::setStackMode( this, StackMode::ZStacked ); + setStackMode( StackMode::ZStacked ); else if( nNewDimensionCount==2 && eStackMode == StackMode::ZStacked ) - DiagramHelper::setStackMode( this, StackMode::NONE ); + setStackMode( StackMode::NONE ); } catch( const uno::Exception & ) { @@ -1439,6 +1440,102 @@ void Diagram::setDimension( sal_Int32 nNewDimensionCount ) } } +void Diagram::setStackMode( StackMode eStackMode ) +{ + try + { + bool bValueFound = false; + bool bIsAmbiguous = false; + StackMode eOldStackMode = getStackMode( bValueFound, bIsAmbiguous ); + + if( eStackMode == eOldStackMode && !bIsAmbiguous ) + return; + + chart2::StackingDirection eNewDirection = chart2::StackingDirection_NO_STACKING; + if( eStackMode == StackMode::YStacked || eStackMode == StackMode::YStackedPercent ) + eNewDirection = chart2::StackingDirection_Y_STACKING; + else if( eStackMode == StackMode::ZStacked ) + eNewDirection = chart2::StackingDirection_Z_STACKING; + + uno::Any aNewDirection( eNewDirection ); + + bool bPercent = false; + if( eStackMode == StackMode::YStackedPercent ) + bPercent = true; + + //iterate through all coordinate systems + for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : getBaseCoordinateSystems() ) + { + //set correct percent stacking + const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(1); + for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI) + { + rtl::Reference< Axis > xAxis = xCooSys->getAxisByDimension2( 1,nI ); + if( xAxis.is()) + { + chart2::ScaleData aScaleData = xAxis->getScaleData(); + if( (aScaleData.AxisType==chart2::AxisType::PERCENT) != bPercent ) + { + if( bPercent ) + aScaleData.AxisType = chart2::AxisType::PERCENT; + else + aScaleData.AxisType = chart2::AxisType::REALNUMBER; + xAxis->setScaleData( aScaleData ); + } + } + } + //iterate through all chart types in the current coordinate system + const std::vector< rtl::Reference< ChartType > > & aChartTypeList( xCooSys->getChartTypes2() ); + if (aChartTypeList.empty()) + continue; + + rtl::Reference< ChartType > xChartType( aChartTypeList[0] ); + + //iterate through all series in this chart type + for( rtl::Reference< DataSeries > const & dataSeries : xChartType->getDataSeries2() ) + { + dataSeries->setPropertyValue( "StackingDirection", aNewDirection ); + } + } + } + catch( const uno::Exception & ) + { + DBG_UNHANDLED_EXCEPTION("chart2"); + } +} + +StackMode Diagram::getStackMode( bool& rbFound, bool& rbAmbiguous ) +{ + rbFound=false; + rbAmbiguous=false; + + StackMode eGlobalStackMode = StackMode::NONE; + + //iterate through all coordinate systems + for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : getBaseCoordinateSystems() ) + { + //iterate through all chart types in the current coordinate system + std::vector< rtl::Reference< ChartType > > aChartTypeList( xCooSys->getChartTypes2() ); + for( std::size_t nT = 0; nT < aChartTypeList.size(); ++nT ) + { + rtl::Reference< ChartType > xChartType( aChartTypeList[nT] ); + + StackMode eLocalStackMode = DiagramHelper::getStackModeFromChartType( + xChartType, rbFound, rbAmbiguous, xCooSys ); + + if( rbFound && eLocalStackMode != eGlobalStackMode && nT>0 ) + { + rbAmbiguous = true; + return eGlobalStackMode; + } + + eGlobalStackMode = eLocalStackMode; + } + } + + return eGlobalStackMode; +} + } // namespace chart diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx index 15037d3c6038..40dc56c2dfbe 100644 --- a/chart2/source/tools/DiagramHelper.cxx +++ b/chart2/source/tools/DiagramHelper.cxx @@ -207,108 +207,6 @@ bool DiagramHelper::getVertical( const rtl::Reference< Diagram > & xDiagram, return bValue; } -void DiagramHelper::setStackMode( - const rtl::Reference< Diagram > & xDiagram, - StackMode eStackMode -) -{ - try - { - bool bValueFound = false; - bool bIsAmbiguous = false; - StackMode eOldStackMode = DiagramHelper::getStackMode( xDiagram, bValueFound, bIsAmbiguous ); - - if( eStackMode == eOldStackMode && !bIsAmbiguous ) - return; - - StackingDirection eNewDirection = StackingDirection_NO_STACKING; - if( eStackMode == StackMode::YStacked || eStackMode == StackMode::YStackedPercent ) - eNewDirection = StackingDirection_Y_STACKING; - else if( eStackMode == StackMode::ZStacked ) - eNewDirection = StackingDirection_Z_STACKING; - - uno::Any aNewDirection( eNewDirection ); - - bool bPercent = false; - if( eStackMode == StackMode::YStackedPercent ) - bPercent = true; - - //iterate through all coordinate systems - for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : xDiagram->getBaseCoordinateSystems() ) - { - //set correct percent stacking - const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(1); - for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI) - { - rtl::Reference< Axis > xAxis = xCooSys->getAxisByDimension2( 1,nI ); - if( xAxis.is()) - { - chart2::ScaleData aScaleData = xAxis->getScaleData(); - if( (aScaleData.AxisType==AxisType::PERCENT) != bPercent ) - { - if( bPercent ) - aScaleData.AxisType = AxisType::PERCENT; - else - aScaleData.AxisType = AxisType::REALNUMBER; - xAxis->setScaleData( aScaleData ); - } - } - } - //iterate through all chart types in the current coordinate system - const std::vector< rtl::Reference< ChartType > > & aChartTypeList( xCooSys->getChartTypes2() ); - if (aChartTypeList.empty()) - continue; - - rtl::Reference< ChartType > xChartType( aChartTypeList[0] ); - - //iterate through all series in this chart type - for( rtl::Reference< DataSeries > const & dataSeries : xChartType->getDataSeries2() ) - { - dataSeries->setPropertyValue( "StackingDirection", aNewDirection ); - } - } - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } -} - -StackMode DiagramHelper::getStackMode( const rtl::Reference< Diagram > & xDiagram, bool& rbFound, bool& rbAmbiguous ) -{ - rbFound=false; - rbAmbiguous=false; - - StackMode eGlobalStackMode = StackMode::NONE; - - if( !xDiagram.is() ) - return eGlobalStackMode; - - //iterate through all coordinate systems - for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : xDiagram->getBaseCoordinateSystems() ) - { - //iterate through all chart types in the current coordinate system - std::vector< rtl::Reference< ChartType > > aChartTypeList( xCooSys->getChartTypes2() ); - for( std::size_t nT = 0; nT < aChartTypeList.size(); ++nT ) - { - rtl::Reference< ChartType > xChartType( aChartTypeList[nT] ); - - StackMode eLocalStackMode = DiagramHelper::getStackModeFromChartType( - xChartType, rbFound, rbAmbiguous, xCooSys ); - - if( rbFound && eLocalStackMode != eGlobalStackMode && nT>0 ) - { - rbAmbiguous = true; - return eGlobalStackMode; - } - - eGlobalStackMode = eLocalStackMode; - } - } - - return eGlobalStackMode; -} - StackMode DiagramHelper::getStackModeFromChartType( const rtl::Reference< ChartType > & xChartType, bool& rbFound, bool& rbAmbiguous, |