chart2/source/model/template/StockChartTypeTemplate.cxx |   13 
 chart2/source/tools/AxisHelper.cxx                      |   29 -
 chart2/source/tools/DiagramHelper.cxx                   |  262 ++++++----------
 3 files changed, 128 insertions(+), 176 deletions(-)

New commits:
commit 98f360b261d7b36fa63b10fadb86cf6f381cbd36
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Jan 21 18:43:59 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Jan 22 08:17:54 2022 +0100

    use more concrete types in chart2, BaseCoordinateSystem
    
    Change-Id: Iea726c410829fbd3f116ecead76610e356ef83ca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128739
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/model/template/StockChartTypeTemplate.cxx 
b/chart2/source/model/template/StockChartTypeTemplate.cxx
index 9f54c44cbca4..3cd5ec0e5c92 100644
--- a/chart2/source/model/template/StockChartTypeTemplate.cxx
+++ b/chart2/source/model/template/StockChartTypeTemplate.cxx
@@ -21,6 +21,8 @@
 #include <DataSeriesHelper.hxx>
 #include "StockDataInterpreter.hxx"
 #include <DiagramHelper.hxx>
+#include <Diagram.hxx>
+#include <BaseCoordinateSystem.hxx>
 #include <servicenames_charttypes.hxx>
 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
@@ -371,6 +373,8 @@ sal_Bool SAL_CALL StockChartTypeTemplate::matchesTemplate(
 
     if( ! xDiagram.is())
         return bResult;
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
 
     try
     {
@@ -385,14 +389,9 @@ sal_Bool SAL_CALL StockChartTypeTemplate::matchesTemplate(
         Reference< chart2::XChartType > xLineChartType;
         sal_Int32 nNumberOfChartTypes = 0;
 
-        Reference< XCoordinateSystemContainer > xCooSysCnt(
-            xDiagram, uno::UNO_QUERY_THROW );
-        const Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
-            xCooSysCnt->getCoordinateSystems());
-        for( Reference< XCoordinateSystem > const & coords : aCooSysSeq )
+        for( rtl::Reference< BaseCoordinateSystem > const & coords : 
pDiagram->getBaseCoordinateSystems() )
         {
-            Reference< XChartTypeContainer > xCTCnt( coords, 
uno::UNO_QUERY_THROW );
-            const Sequence< Reference< XChartType > > aChartTypeSeq( 
xCTCnt->getChartTypes());
+            const Sequence< Reference< XChartType > > aChartTypeSeq( 
coords->getChartTypes());
             for( Reference< XChartType >  const & chartType : aChartTypeSeq )
             {
                 if( chartType.is())
diff --git a/chart2/source/tools/AxisHelper.cxx 
b/chart2/source/tools/AxisHelper.cxx
index d936cf59c92b..38bdb6f4f98f 100644
--- a/chart2/source/tools/AxisHelper.cxx
+++ b/chart2/source/tools/AxisHelper.cxx
@@ -777,17 +777,15 @@ bool AxisHelper::getIndicesForAxis( const Reference< 
XAxis >& xAxis, const Refer
     rOutDimensionIndex = -1;
     rOutAxisIndex = -1;
 
-    Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, 
uno::UNO_QUERY );
-    if(xCooSysContainer.is())
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
+    const std::vector< rtl::Reference< BaseCoordinateSystem > > & aCooSysList 
= pDiagram->getBaseCoordinateSystems();
+    for( sal_Int32 nC=0; nC < static_cast<sal_Int32>(aCooSysList.size()); ++nC 
)
     {
-        Sequence< Reference< XCoordinateSystem > > aCooSysList = 
xCooSysContainer->getCoordinateSystems();
-        for( sal_Int32 nC=0; nC<aCooSysList.getLength(); ++nC )
+        if( AxisHelper::getIndicesForAxis( xAxis, aCooSysList[nC], 
rOutDimensionIndex, rOutAxisIndex ) )
         {
-            if( AxisHelper::getIndicesForAxis( xAxis, aCooSysList[nC], 
rOutDimensionIndex, rOutAxisIndex ) )
-            {
-                rOutCooSysIndex = nC;
-                return true;
-            }
+            rOutCooSysIndex = nC;
+            return true;
         }
     }
 
@@ -844,17 +842,14 @@ Sequence< Reference< XAxis > > 
AxisHelper::getAllAxesOfDiagram(
       const Reference< XDiagram >& xDiagram
     , bool bOnlyVisible )
 {
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
     std::vector< Reference< XAxis > > aAxisVector;
 
-    Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, 
uno::UNO_QUERY );
-    if(xCooSysContainer.is())
+    for( rtl::Reference< BaseCoordinateSystem > const & coords : 
pDiagram->getBaseCoordinateSystems() )
     {
-        const Sequence< Reference< XCoordinateSystem > > aCooSysList = 
xCooSysContainer->getCoordinateSystems();
-        for( Reference< XCoordinateSystem > const & coords : aCooSysList )
-        {
-            std::vector< Reference< XAxis > > aAxesPerCooSys( 
AxisHelper::getAllAxesOfCoordinateSystem( coords, bOnlyVisible ) );
-            aAxisVector.insert( aAxisVector.end(), aAxesPerCooSys.begin(), 
aAxesPerCooSys.end() );
-        }
+        std::vector< Reference< XAxis > > aAxesPerCooSys( 
AxisHelper::getAllAxesOfCoordinateSystem( coords, bOnlyVisible ) );
+        aAxisVector.insert( aAxisVector.end(), aAxesPerCooSys.begin(), 
aAxesPerCooSys.end() );
     }
 
     return comphelper::containerToSequence( aAxisVector );
diff --git a/chart2/source/tools/DiagramHelper.cxx 
b/chart2/source/tools/DiagramHelper.cxx
index 1aa9ad5cc381..7d9136e7291a 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -120,30 +120,24 @@ void DiagramHelper::setVertical(
 {
     try
     {
-        Reference< XCoordinateSystemContainer > xCnt( xDiagram, uno::UNO_QUERY 
);
-        if (!xCnt.is())
+        if (!xDiagram.is())
             return;
 
-        const Sequence< Reference<XCoordinateSystem> > aCooSys = 
xCnt->getCoordinateSystems();
+        Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+        assert(pDiagram);
+
         uno::Any aValue;
         aValue <<= bVertical;
-        for( uno::Reference< XCoordinateSystem > const & xCooSys : aCooSys )
+        for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : 
pDiagram->getBaseCoordinateSystems() )
         {
-            Reference< beans::XPropertySet > xProp( xCooSys, uno::UNO_QUERY );
             bool bChanged = false;
-            if (xProp.is())
-            {
-                bool bOldSwap = false;
-                if( !(xProp->getPropertyValue("SwapXAndYAxis") >>= bOldSwap)
-                    || bVertical != bOldSwap )
-                    bChanged = true;
+            bool bOldSwap = false;
+            if( !(xCooSys->getPropertyValue("SwapXAndYAxis") >>= bOldSwap)
+                || bVertical != bOldSwap )
+                bChanged = true;
 
-                if( bChanged )
-                    xProp->setPropertyValue("SwapXAndYAxis", aValue);
-            }
-
-            if (!xCooSys.is())
-                continue;
+            if( bChanged )
+                xCooSys->setPropertyValue("SwapXAndYAxis", aValue);
 
             const sal_Int32 nDimensionCount = xCooSys->getDimension();
             sal_Int32 nDimIndex = 0;
@@ -198,20 +192,16 @@ bool DiagramHelper::getVertical( const uno::Reference< 
chart2::XDiagram > & xDia
     rbFound = false;
     rbAmbiguous = false;
 
-    Reference< XCoordinateSystemContainer > xCnt( xDiagram, uno::UNO_QUERY );
-    if (!xCnt.is())
+    if (!xDiagram.is())
         return false;
 
-    const Sequence< Reference<XCoordinateSystem> > aCooSys = 
xCnt->getCoordinateSystems();
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
 
-    for (Reference<XCoordinateSystem> const & coords : aCooSys)
+    for (rtl::Reference<BaseCoordinateSystem> const & coords : 
pDiagram->getBaseCoordinateSystems())
     {
-        Reference<beans::XPropertySet> xProp(coords, uno::UNO_QUERY);
-        if (!xProp.is())
-            continue;
-
         bool bCurrent = false;
-        if (xProp->getPropertyValue("SwapXAndYAxis") >>= bCurrent)
+        if (coords->getPropertyValue("SwapXAndYAxis") >>= bCurrent)
         {
             if (!rbFound)
             {
@@ -233,6 +223,8 @@ void DiagramHelper::setStackMode(
     StackMode eStackMode
 )
 {
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
     try
     {
         bool bValueFound = false;
@@ -255,11 +247,7 @@ void DiagramHelper::setStackMode(
             bPercent = true;
 
         //iterate through all coordinate systems
-        uno::Reference< XCoordinateSystemContainer > xCooSysContainer( 
xDiagram, uno::UNO_QUERY );
-        if( !xCooSysContainer.is() )
-            return;
-        const uno::Sequence< uno::Reference< XCoordinateSystem > > 
aCooSysList( xCooSysContainer->getCoordinateSystems() );
-        for( uno::Reference< XCoordinateSystem > const & xCooSys : aCooSysList 
)
+        for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : 
pDiagram->getBaseCoordinateSystems() )
         {
             //set correct percent stacking
             const sal_Int32 nMaximumScaleIndex = 
xCooSys->getMaximumAxisIndexByDimension(1);
@@ -280,10 +268,7 @@ void DiagramHelper::setStackMode(
                 }
             }
             //iterate through all chart types in the current coordinate system
-            uno::Reference< XChartTypeContainer > xChartTypeContainer( 
xCooSys, uno::UNO_QUERY );
-            if( !xChartTypeContainer.is() )
-                continue;
-            uno::Sequence< uno::Reference< XChartType > > aChartTypeList( 
xChartTypeContainer->getChartTypes() );
+            uno::Sequence< uno::Reference< XChartType > > aChartTypeList( 
xCooSys->getChartTypes() );
             if (!aChartTypeList.hasElements())
                 continue;
 
@@ -317,18 +302,16 @@ StackMode DiagramHelper::getStackMode( const Reference< 
XDiagram > & xDiagram, b
 
     StackMode eGlobalStackMode = StackMode::NONE;
 
-    //iterate through all coordinate systems
-    uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, 
uno::UNO_QUERY );
-    if( !xCooSysContainer.is() )
+    if( !xDiagram.is() )
         return eGlobalStackMode;
-    const uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( 
xCooSysContainer->getCoordinateSystems() );
-    for( uno::Reference< XCoordinateSystem > const & xCooSys : aCooSysList )
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
+
+    //iterate through all coordinate systems
+    for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : 
pDiagram->getBaseCoordinateSystems() )
     {
         //iterate through all chart types in the current coordinate system
-        uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, 
uno::UNO_QUERY );
-        if( !xChartTypeContainer.is() )
-            continue;
-        uno::Sequence< uno::Reference< XChartType > > aChartTypeList( 
xChartTypeContainer->getChartTypes() );
+        uno::Sequence< uno::Reference< XChartType > > aChartTypeList( 
xCooSys->getChartTypes() );
         for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
         {
             uno::Reference< XChartType > xChartType( aChartTypeList[nT] );
@@ -435,22 +418,20 @@ sal_Int32 DiagramHelper::getDimension( const Reference< 
XDiagram > & xDiagram )
 {
     // -1: not yet set
     sal_Int32 nResult = -1;
+    if (!xDiagram)
+        return nResult;
+
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
 
     try
     {
-        Reference< XCoordinateSystemContainer > xCooSysCnt( xDiagram, 
uno::UNO_QUERY );
-        if( xCooSysCnt.is() )
+        for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : 
pDiagram->getBaseCoordinateSystems() )
         {
-            const Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
-                xCooSysCnt->getCoordinateSystems());
-
-            for( Reference< XCoordinateSystem > const & xCooSys : aCooSysSeq )
+            if(xCooSys.is())
             {
-                if(xCooSys.is())
-                {
-                    nResult = xCooSys->getDimension();
-                    break;
-                }
+                nResult = xCooSys->getDimension();
+                break;
             }
         }
     }
@@ -468,6 +449,8 @@ void DiagramHelper::setDimension(
 {
     if( ! xDiagram.is())
         return;
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
 
     if( DiagramHelper::getDimension( xDiagram ) == nNewDimensionCount )
         return;
@@ -480,23 +463,19 @@ void DiagramHelper::setDimension(
         bool bIsSupportingOnlyDeepStackingFor3D=false;
 
         //change all coordinate systems:
-        Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, 
uno::UNO_QUERY_THROW );
-        const Sequence< Reference< XCoordinateSystem > > aCooSysList( 
xCooSysContainer->getCoordinateSystems() );
-        for( Reference<XCoordinateSystem> const & xOldCooSys : aCooSysList )
+        auto aCoordSystems = pDiagram->getBaseCoordinateSystems();
+        for( rtl::Reference<BaseCoordinateSystem> const & xOldCooSys : 
aCoordSystems )
         {
-            Reference< XCoordinateSystem > xNewCooSys;
+            rtl::Reference< BaseCoordinateSystem > xNewCooSys;
 
-            Reference< XChartTypeContainer > xChartTypeContainer( xOldCooSys, 
uno::UNO_QUERY );
-            if( !xChartTypeContainer.is() )
-                continue;
-
-            const Sequence< Reference< XChartType > > aChartTypeList( 
xChartTypeContainer->getChartTypes() );
+            const Sequence< Reference< XChartType > > aChartTypeList( 
xOldCooSys->getChartTypes() );
             for( Reference< XChartType > const & xChartType : aChartTypeList )
             {
                 bIsSupportingOnlyDeepStackingFor3D = 
ChartTypeHelper::isSupportingOnlyDeepStackingFor3D( xChartType );
                 if(!xNewCooSys.is())
                 {
-                    xNewCooSys = xChartType->createCoordinateSystem( 
nNewDimensionCount );
+                    xNewCooSys = 
dynamic_cast<BaseCoordinateSystem*>(xChartType->createCoordinateSystem( 
nNewDimensionCount ).get());
+                    assert(xNewCooSys);
                     break;
                 }
                 //@todo make sure that all following charttypes are also 
capable of the new dimension
@@ -620,24 +599,18 @@ uno::Reference< XChartType > 
DiagramHelper::getChartTypeOfSeries(
         return nullptr;
     if(!xDiagram.is())
         return nullptr;
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
 
     //iterate through the model to find the given xSeries
     //the found parent indicates the charttype
 
     //iterate through all coordinate systems
-    uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, 
uno::UNO_QUERY );
-    if( !xCooSysContainer.is())
-        return nullptr;
 
-    const uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( 
xCooSysContainer->getCoordinateSystems() );
-    for( uno::Reference< XCoordinateSystem > const & xCooSys : aCooSysList )
+    for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : 
pDiagram->getBaseCoordinateSystems() )
     {
         //iterate through all chart types in the current coordinate system
-        uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, 
uno::UNO_QUERY );
-        OSL_ASSERT( xChartTypeContainer.is());
-        if( !xChartTypeContainer.is() )
-            continue;
-        const uno::Sequence< uno::Reference< XChartType > > aChartTypeList( 
xChartTypeContainer->getChartTypes() );
+        const uno::Sequence< uno::Reference< XChartType > > aChartTypeList( 
xCooSys->getChartTypes() );
         for( uno::Reference< XChartType > const & xChartType : aChartTypeList )
         {
             //iterate through all series in this chart type
@@ -662,17 +635,16 @@ std::vector< Reference< XDataSeries > >
         const Reference< XDiagram > & xDiagram )
 {
     std::vector< Reference< XDataSeries > > aResult;
+    if (!xDiagram)
+        return aResult;
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
 
     try
     {
-        Reference< XCoordinateSystemContainer > xCooSysCnt(
-            xDiagram, uno::UNO_QUERY_THROW );
-        const Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
-            xCooSysCnt->getCoordinateSystems());
-        for( Reference< XCoordinateSystem > const & coords : aCooSysSeq )
+        for( rtl::Reference< BaseCoordinateSystem > const & coords : 
pDiagram->getBaseCoordinateSystems() )
         {
-            Reference< XChartTypeContainer > xCTCnt( coords, 
uno::UNO_QUERY_THROW );
-            const Sequence< Reference< XChartType > > aChartTypeSeq( 
xCTCnt->getChartTypes());
+            const Sequence< Reference< XChartType > > aChartTypeSeq( 
coords->getChartTypes());
             for( Reference< XChartType> const & chartType : aChartTypeSeq )
             {
                 Reference< XDataSeriesContainer > xDSCnt( chartType, 
uno::UNO_QUERY_THROW );
@@ -692,27 +664,24 @@ std::vector< Reference< XDataSeries > >
 Sequence< Sequence< Reference< XDataSeries > > >
         DiagramHelper::getDataSeriesGroups( const Reference< XDiagram > & 
xDiagram )
 {
+    if (!xDiagram)
+        return {};
+
     vector< Sequence< Reference< XDataSeries > > > aResult;
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
 
     //iterate through all coordinate systems
-    Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, 
uno::UNO_QUERY );
-    if( xCooSysContainer.is() )
+    for( rtl::Reference< BaseCoordinateSystem > const & coords : 
pDiagram->getBaseCoordinateSystems() )
     {
-        const Sequence< Reference< XCoordinateSystem > > aCooSysList( 
xCooSysContainer->getCoordinateSystems() );
-        for( Reference< XCoordinateSystem > const & coords : aCooSysList )
+        //iterate through all chart types in the current coordinate system
+        const Sequence< Reference< XChartType > > aChartTypeList( 
coords->getChartTypes() );
+        for( Reference< XChartType >  const & chartType : aChartTypeList )
         {
-            //iterate through all chart types in the current coordinate system
-            Reference< XChartTypeContainer > xChartTypeContainer( coords, 
uno::UNO_QUERY );
-            if( !xChartTypeContainer.is() )
+            Reference< XDataSeriesContainer > xDataSeriesContainer( chartType, 
uno::UNO_QUERY );
+            if( !xDataSeriesContainer.is() )
                 continue;
-            const Sequence< Reference< XChartType > > aChartTypeList( 
xChartTypeContainer->getChartTypes() );
-            for( Reference< XChartType >  const & chartType : aChartTypeList )
-            {
-                Reference< XDataSeriesContainer > xDataSeriesContainer( 
chartType, uno::UNO_QUERY );
-                if( !xDataSeriesContainer.is() )
-                    continue;
-                aResult.push_back( xDataSeriesContainer->getDataSeries() );
-            }
+            aResult.push_back( xDataSeriesContainer->getDataSeries() );
         }
     }
     return comphelper::containerToSequence( aResult );
@@ -721,21 +690,19 @@ Sequence< Sequence< Reference< XDataSeries > > >
 Reference< XChartType >
     DiagramHelper::getChartTypeByIndex( const Reference< XDiagram >& xDiagram, 
sal_Int32 nIndex )
 {
+    if (!xDiagram)
+        return nullptr;
+
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
+
     Reference< XChartType > xChartType;
 
     //iterate through all coordinate systems
-    Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, 
uno::UNO_QUERY );
-    if( ! xCooSysContainer.is())
-        return xChartType;
-
-    const Sequence< Reference< XCoordinateSystem > > aCooSysList( 
xCooSysContainer->getCoordinateSystems() );
     sal_Int32 nTypesSoFar = 0;
-    for( Reference< XCoordinateSystem > const & coords : aCooSysList )
+    for( rtl::Reference< BaseCoordinateSystem > const & coords : 
pDiagram->getBaseCoordinateSystems() )
     {
-        Reference< XChartTypeContainer > xChartTypeContainer( coords, 
uno::UNO_QUERY );
-        if( !xChartTypeContainer.is() )
-            continue;
-        Sequence< Reference< XChartType > > aChartTypeList( 
xChartTypeContainer->getChartTypes() );
+        Sequence< Reference< XChartType > > aChartTypeList( 
coords->getChartTypes() );
         if( nIndex >= 0 && nIndex < (nTypesSoFar + aChartTypeList.getLength()) 
)
         {
             xChartType.set( aChartTypeList[nIndex - nTypesSoFar] );
@@ -751,7 +718,7 @@ namespace
 {
 
 std::vector< Reference< XAxis > > lcl_getAxisHoldingCategoriesFromDiagram(
-    const Reference< XDiagram > & xDiagram )
+    const rtl::Reference< Diagram > & xDiagram )
 {
     std::vector< Reference< XAxis > > aRet;
 
@@ -759,11 +726,7 @@ std::vector< Reference< XAxis > > 
lcl_getAxisHoldingCategoriesFromDiagram(
     Reference< XAxis > xFallBack;
     try
     {
-        Reference< XCoordinateSystemContainer > xCooSysCnt(
-            xDiagram, uno::UNO_QUERY_THROW );
-        const Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
-            xCooSysCnt->getCoordinateSystems());
-        for( Reference< XCoordinateSystem > const & xCooSys : aCooSysSeq )
+        for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : 
xDiagram->getBaseCoordinateSystems() )
         {
             OSL_ASSERT( xCooSys.is());
             for( sal_Int32 nN = xCooSys->getDimension(); nN--; )
@@ -805,13 +768,10 @@ bool DiagramHelper::isCategoryDiagram(
 {
     try
     {
-        Reference< XCoordinateSystemContainer > xCooSysCnt(
-            xDiagram, uno::UNO_QUERY_THROW );
-        const Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
-            xCooSysCnt->getCoordinateSystems());
-        for( Reference< XCoordinateSystem > const & xCooSys : aCooSysSeq )
+        Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+        assert(pDiagram);
+        for( rtl::Reference< BaseCoordinateSystem > const & xCooSys : 
pDiagram->getBaseCoordinateSystems() )
         {
-            OSL_ASSERT( xCooSys.is());
             for( sal_Int32 nN = xCooSys->getDimension(); nN--; )
             {
                 const sal_Int32 nMaximumScaleIndex = 
xCooSys->getMaximumAxisIndexByDimension(nN);
@@ -843,8 +803,10 @@ void DiagramHelper::setCategoriesToDiagram(
     bool bSetAxisType  /* = false */,
     bool bCategoryAxis /* = true */ )
 {
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
     std::vector< Reference< chart2::XAxis > > aCatAxes(
-        lcl_getAxisHoldingCategoriesFromDiagram( xDiagram ));
+        lcl_getAxisHoldingCategoriesFromDiagram( pDiagram ));
 
     for (const Reference< chart2::XAxis >& xCatAxis : aCatAxes)
     {
@@ -869,11 +831,13 @@ Reference< data::XLabeledDataSequence >
         const Reference< XDiagram > & xDiagram )
 {
     Reference< data::XLabeledDataSequence > xResult;
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
 
     try
     {
         std::vector< Reference< chart2::XAxis > > aCatAxes(
-            lcl_getAxisHoldingCategoriesFromDiagram( xDiagram ));
+            lcl_getAxisHoldingCategoriesFromDiagram( pDiagram ));
         //search for first categories
         if (!aCatAxes.empty())
         {
@@ -1193,28 +1157,24 @@ Sequence< Reference< XChartType > >
     DiagramHelper::getChartTypesFromDiagram(
         const Reference< XDiagram > & xDiagram )
 {
-    std::vector< Reference< XChartType > > aResult;
+    if(!xDiagram)
+        return {};
 
-    if(xDiagram.is())
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(pDiagram);
+    std::vector< Reference< XChartType > > aResult;
+    try
     {
-        try
+        for( rtl::Reference< BaseCoordinateSystem > const & coords : 
pDiagram->getBaseCoordinateSystems() )
         {
-            Reference< XCoordinateSystemContainer > xCooSysCnt(
-                xDiagram, uno::UNO_QUERY_THROW );
-            const Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
-                xCooSysCnt->getCoordinateSystems());
-            for( Reference< XCoordinateSystem > const & coords : aCooSysSeq )
-            {
-                Reference< XChartTypeContainer > xCTCnt( coords, 
uno::UNO_QUERY_THROW );
-                const Sequence< Reference< XChartType > > aChartTypeSeq( 
xCTCnt->getChartTypes());
-                aResult.insert( aResult.end(), aChartTypeSeq.begin(), 
aChartTypeSeq.end() );
-            }
-        }
-        catch( const uno::Exception & )
-        {
-            DBG_UNHANDLED_EXCEPTION("chart2");
+            const Sequence< Reference< XChartType > > aChartTypeSeq( 
coords->getChartTypes());
+            aResult.insert( aResult.end(), aChartTypeSeq.begin(), 
aChartTypeSeq.end() );
         }
     }
+    catch( const uno::Exception & )
+    {
+        DBG_UNHANDLED_EXCEPTION("chart2");
+    }
 
     return comphelper::containerToSequence( aResult );
 }
@@ -1265,7 +1225,7 @@ namespace
      */
 
 bool lcl_moveSeriesOrCheckIfMoveIsAllowed(
-    const Reference< XDiagram >& xDiagram,
+    const rtl::Reference< Diagram >& xDiagram,
     const Reference< XDataSeries >& xGivenDataSeries,
     bool bForward,
     bool bDoMove )
@@ -1274,24 +1234,18 @@ bool lcl_moveSeriesOrCheckIfMoveIsAllowed(
 
     try
     {
-        uno::Reference< XCoordinateSystemContainer > xCooSysContainer( 
xDiagram, uno::UNO_QUERY );
-
-        if( xGivenDataSeries.is() && xCooSysContainer.is() )
+        if( xGivenDataSeries.is() && xDiagram.is() )
         {
             //find position of series.
             bool bFound = false;
-            uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( 
xCooSysContainer->getCoordinateSystems() );
+            const std::vector< rtl::Reference< BaseCoordinateSystem > > & 
aCooSysList( xDiagram->getBaseCoordinateSystems() );
 
-            for( sal_Int32 nCS = 0; !bFound && nCS < aCooSysList.getLength(); 
++nCS )
+            for( sal_Int32 nCS = 0; !bFound && nCS < 
static_cast<sal_Int32>(aCooSysList.size()); ++nCS )
             {
-                uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] 
);
+                const rtl::Reference< BaseCoordinateSystem > & xCooSys( 
aCooSysList[nCS] );
 
                 //iterate through all chart types in the current coordinate 
system
-                uno::Reference< XChartTypeContainer > xChartTypeContainer( 
xCooSys, uno::UNO_QUERY );
-                OSL_ASSERT( xChartTypeContainer.is());
-                if( !xChartTypeContainer.is() )
-                    continue;
-                uno::Sequence< uno::Reference< XChartType > > aChartTypeList( 
xChartTypeContainer->getChartTypes() );
+                uno::Sequence< uno::Reference< XChartType > > aChartTypeList( 
xCooSys->getChartTypes() );
                 uno::Reference< XChartType > xFormerChartType;
 
                 for( sal_Int32 nT = 0; !bFound && nT < 
aChartTypeList.getLength(); ++nT )
@@ -1420,8 +1374,10 @@ bool DiagramHelper::isSeriesMoveable(
 {
     const bool bDoMove = false;
 
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(!xDiagram || pDiagram);
     bool bIsMoveable = lcl_moveSeriesOrCheckIfMoveIsAllowed(
-        xDiagram, xGivenDataSeries, bForward, bDoMove );
+        pDiagram, xGivenDataSeries, bForward, bDoMove );
 
     return bIsMoveable;
 }
@@ -1430,8 +1386,10 @@ bool DiagramHelper::moveSeries( const Reference< 
XDiagram >& xDiagram, const Ref
 {
     const bool bDoMove = true;
 
+    Diagram* pDiagram = dynamic_cast<Diagram*>(xDiagram.get());
+    assert(!xDiagram || pDiagram);
     bool bMoved = lcl_moveSeriesOrCheckIfMoveIsAllowed(
-        xDiagram, xGivenDataSeries, bForward, bDoMove );
+        pDiagram, xGivenDataSeries, bForward, bDoMove );
 
     return bMoved;
 }

Reply via email to