chart2/source/controller/dialogs/DialogModel.cxx            |    2 
 chart2/source/controller/main/ChartController.cxx           |    2 
 chart2/source/controller/main/ControllerCommandDispatch.cxx |    6 
 chart2/source/inc/Diagram.hxx                               |   39 ++
 chart2/source/inc/DiagramHelper.hxx                         |   40 --
 chart2/source/model/main/Diagram.cxx                        |  188 +++++++++++
 chart2/source/tools/DiagramHelper.cxx                       |  191 ------------
 7 files changed, 231 insertions(+), 237 deletions(-)

New commits:
commit 0fc4f285b2578a68e30004baafc37ea189aa8c00
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Mar 15 16:18:55 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Mar 17 11:03:45 2023 +0000

    move isSeriesMoveable inside chart2::Diagram
    
    Change-Id: I119552a4f1300eafc8b060f567777a74dc11772f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149038
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/controller/dialogs/DialogModel.cxx 
b/chart2/source/controller/dialogs/DialogModel.cxx
index d6d1fbd71b97..495bf8f396d3 100644
--- a/chart2/source/controller/dialogs/DialogModel.cxx
+++ b/chart2/source/controller/dialogs/DialogModel.cxx
@@ -531,7 +531,7 @@ void DialogModel::moveSeries(
     ControllerLockGuardUNO aLockedControllers( m_xChartDocument );
 
     rtl::Reference< Diagram > xDiagram( 
m_xChartDocument->getFirstChartDiagram());
-    DiagramHelper::moveSeries( xDiagram, xSeries, 
eDirection==MoveDirection::Down );
+    xDiagram->moveSeries( xSeries, eDirection==MoveDirection::Down );
 }
 
 rtl::Reference< ::chart::DataSeries > DialogModel::insertSeriesAfter(
diff --git a/chart2/source/controller/main/ChartController.cxx 
b/chart2/source/controller/main/ChartController.cxx
index dbd7efb9d147..bc658ef03267 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -1437,7 +1437,7 @@ void ChartController::executeDispatch_MoveSeries( bool 
bForward )
             SchResId(STR_OBJECT_DATASERIES)),
         m_xUndoManager );
 
-    bool bChanged = DiagramHelper::moveSeries( getFirstDiagram(), 
xGivenDataSeries, bForward );
+    bool bChanged = getFirstDiagram()->moveSeries( xGivenDataSeries, bForward 
);
     if( bChanged )
     {
         m_aSelection.setSelection( ObjectIdentifier::getMovedSeriesCID( 
aObjectCID, bForward ) );
diff --git a/chart2/source/controller/main/ControllerCommandDispatch.cxx 
b/chart2/source/controller/main/ControllerCommandDispatch.cxx
index 6e90d50bf2e7..53e02f017aaa 100644
--- a/chart2/source/controller/main/ControllerCommandDispatch.cxx
+++ b/chart2/source/controller/main/ControllerCommandDispatch.cxx
@@ -204,13 +204,11 @@ void ControllerState::update(
 
     bIsDeleteableObjectSelected = ChartController::isObjectDeleteable( aSelObj 
);
 
-    bMayMoveSeriesForward = (aObjectType!=OBJECTTYPE_DATA_POINT) && 
DiagramHelper::isSeriesMoveable(
-        ChartModelHelper::findDiagram( xModel ),
+    bMayMoveSeriesForward = (aObjectType!=OBJECTTYPE_DATA_POINT) && xDiagram 
&& xDiagram->isSeriesMoveable(
         xGivenDataSeries,
         MOVE_SERIES_FORWARD );
 
-    bMayMoveSeriesBackward = (aObjectType!=OBJECTTYPE_DATA_POINT) && 
DiagramHelper::isSeriesMoveable(
-        ChartModelHelper::findDiagram( xModel ),
+    bMayMoveSeriesBackward = (aObjectType!=OBJECTTYPE_DATA_POINT) && xDiagram 
&& xDiagram->isSeriesMoveable(
         xGivenDataSeries,
         MOVE_SERIES_BACKWARD );
 
diff --git a/chart2/source/inc/Diagram.hxx b/chart2/source/inc/Diagram.hxx
index c505d42824a1..a5e877a1f4cf 100644
--- a/chart2/source/inc/Diagram.hxx
+++ b/chart2/source/inc/Diagram.hxx
@@ -33,6 +33,7 @@
 #include <vector>
 
 namespace com::sun::star::beans { struct PropertyValue; }
+namespace com::sun::star::chart2 { class XDataSeries; }
 namespace com::sun::star::chart2::data { class XDataSource; }
 namespace com::sun::star::uno { class XComponentContext; }
 
@@ -180,6 +181,44 @@ public:
 
     bool isSupportingFloorAndWall();
 
+    /**
+    * Move a series forward or backward.
+    *
+    * @param xDiagram
+    *  Reference to the diagram that contains the series.
+    *
+    * @param xGivenDataSeries
+    *  Reference to the series that should be moved.
+    *
+    * @param bForward
+    *  Direction in which the series should be moved.
+    *
+    * @returns </sal_True> if the series was moved successfully.
+    *
+    */
+    bool moveSeries(
+                const css::uno::Reference< css::chart2::XDataSeries >& 
xGivenDataSeries,
+                bool bForward );
+
+    /**
+    * Test if a series can be moved.
+    *
+    * @param xDiagram
+    *  Reference to the diagram that contains the series.
+    *
+    * @param xGivenDataSeries
+    *  Reference to the series that should be tested for moving.
+    *
+    * @param bForward
+    *  Direction of the move to be checked.
+    *
+    * @returns </sal_True> if the series can be moved.
+    *
+    */
+    bool isSeriesMoveable(
+            const css::uno::Reference< css::chart2::XDataSeries >& 
xGivenDataSeries,
+            bool bForward );
+
 private:
     // ____ XModifyListener ____
     virtual void SAL_CALL modified(
diff --git a/chart2/source/inc/DiagramHelper.hxx 
b/chart2/source/inc/DiagramHelper.hxx
index 78133572d9cc..3e4a8ea30e12 100644
--- a/chart2/source/inc/DiagramHelper.hxx
+++ b/chart2/source/inc/DiagramHelper.hxx
@@ -223,46 +223,6 @@ public:
                 const rtl::Reference< ::chart::ChartType >& xFirstType,
                 const rtl::Reference< ::chart::ChartType >& xSecondType );
 
-    /**
-        * Test if a series can be moved.
-        *
-        * @param xDiagram
-        *  Reference to the diagram that contains the series.
-        *
-        * @param xGivenDataSeries
-        *  Reference to the series that should be tested for moving.
-        *
-        * @param bForward
-        *  Direction of the move to be checked.
-        *
-        * @returns </sal_True> if the series can be moved.
-        *
-        */
-    static bool isSeriesMoveable(
-            const rtl::Reference< ::chart::Diagram >& xDiagram,
-            const css::uno::Reference< css::chart2::XDataSeries >& 
xGivenDataSeries,
-            bool bForward );
-
-    /**
-        * Move a series forward or backward.
-        *
-        * @param xDiagram
-        *  Reference to the diagram that contains the series.
-        *
-        * @param xGivenDataSeries
-        *  Reference to the series that should be moved.
-        *
-        * @param bForward
-        *  Direction in which the series should be moved.
-        *
-        * @returns </sal_True> if the series was moved successfully.
-        *
-        */
-    static bool moveSeries(
-                const rtl::Reference< ::chart::Diagram >& xDiagram,
-                const css::uno::Reference< css::chart2::XDataSeries >& 
xGivenDataSeries,
-                bool bForward );
-
     static bool setDiagramPositioning( const 
rtl::Reference<::chart::ChartModel>& xChartModel,
         const css::awt::Rectangle& rPosRect /*100th mm*/ );
 
diff --git a/chart2/source/model/main/Diagram.cxx 
b/chart2/source/model/main/Diagram.cxx
index ee0a55239567..fabaa5b5db1a 100644
--- a/chart2/source/model/main/Diagram.cxx
+++ b/chart2/source/model/main/Diagram.cxx
@@ -46,9 +46,11 @@
 #include <com/sun/star/chart/MissingValueTreatment.hpp>
 #include <com/sun/star/container/NoSuchElementException.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/util/CloseVetoException.hpp>
 
 #include <cppuhelper/supportsservice.hxx>
 #include <comphelper/diagnose_ex.hxx>
+#include <o3tl/safeint.hxx>
 
 #include <algorithm>
 #include <utility>
@@ -841,6 +843,192 @@ bool Diagram::isSupportingFloorAndWall()
     return true;
 }
 
+ /**
+ * This method implements the logic of checking if a series can be moved
+ * forward/backward. Depending on the "bDoMove" parameter the series will
+ * be moved (bDoMove = true) or the function just will test if the
+ * series can be moved without doing the move (bDoMove = false).
+ *
+ * @param xDiagram
+ *  Reference to the diagram that contains the series.
+ *
+ * @param xGivenDataSeries
+ *  Reference to the series that should moved or tested for moving.
+ *
+ * @param bForward
+ *  Direction in which the series should be moved or tested for moving.
+ *
+ * @param bDoMove
+ *  Should this function really move the series (true) or just test if it is
+ *  possible (false).
+ *
+ *
+ * @returns
+ *  in case of bDoMove == true
+ *      - True : if the move was done
+ *      - False : the move failed
+ *  in case of bDoMove == false
+ *      - True : the series can be moved
+ *      - False : the series can not be moved
+ *
+ */
+static bool lcl_moveSeriesOrCheckIfMoveIsAllowed(
+    Diagram& rDiagram,
+    const rtl::Reference< DataSeries >& xGivenDataSeries,
+    bool bForward,
+    bool bDoMove )
+{
+    bool bMovedOrMoveAllowed = false;
+
+    try
+    {
+        if( !xGivenDataSeries.is() )
+            return false;
+
+        //find position of series.
+        bool bFound = false;
+        const std::vector< rtl::Reference< BaseCoordinateSystem > > & 
aCooSysList( rDiagram.getBaseCoordinateSystems() );
+
+        for( std::size_t nCS = 0; !bFound && nCS < aCooSysList.size(); ++nCS )
+        {
+            const rtl::Reference< BaseCoordinateSystem > & xCooSys( 
aCooSysList[nCS] );
+
+            //iterate through all chart types in the current coordinate system
+            std::vector< rtl::Reference< ChartType > > aChartTypeList( 
xCooSys->getChartTypes2() );
+            rtl::Reference< ChartType > xFormerChartType;
+
+            for( std::size_t nT = 0; !bFound && nT < aChartTypeList.size(); 
++nT )
+            {
+                rtl::Reference< ChartType > xCurrentChartType( 
aChartTypeList[nT] );
+
+                //iterate through all series in this chart type
+
+                std::vector< rtl::Reference< DataSeries > > aSeriesList = 
xCurrentChartType->getDataSeries2();
+
+                for( std::size_t nS = 0; !bFound && nS < aSeriesList.size(); 
++nS )
+                {
+
+                    // We found the series we are interested in!
+                    if( xGivenDataSeries==aSeriesList[nS] )
+                    {
+                        std::size_t nOldSeriesIndex = nS;
+                        bFound = true;
+
+                        try
+                        {
+                            sal_Int32 nNewSeriesIndex = nS;
+
+                            // tdf#34517 Bringing forward means increasing, 
backwards means decreasing series position
+                            if( !bForward )
+                                nNewSeriesIndex--;
+                            else
+                                nNewSeriesIndex++;
+
+                            if( nNewSeriesIndex >= 0 && 
o3tl::make_unsigned(nNewSeriesIndex) < aSeriesList.size() )
+                            {
+                                //move series in the same charttype
+                                bMovedOrMoveAllowed = true;
+                                if( bDoMove )
+                                {
+                                    aSeriesList[ nOldSeriesIndex ] = 
aSeriesList[ nNewSeriesIndex ];
+                                    aSeriesList[ nNewSeriesIndex ] = 
xGivenDataSeries;
+                                    xCurrentChartType->setDataSeries( 
aSeriesList );
+                                }
+                            }
+                            else if( nNewSeriesIndex<0 )
+                            {
+                                //exchange series with former charttype
+                                if( xFormerChartType.is() && 
DiagramHelper::areChartTypesCompatible( xFormerChartType, xCurrentChartType ) )
+                                {
+                                    bMovedOrMoveAllowed = true;
+                                    if( bDoMove )
+                                    {
+                                        std::vector< rtl::Reference< 
DataSeries > > aOtherSeriesList = xFormerChartType->getDataSeries2();
+                                        sal_Int32 nOtherSeriesIndex = 
aOtherSeriesList.size()-1;
+                                        if( nOtherSeriesIndex >= 0 && 
o3tl::make_unsigned(nOtherSeriesIndex) < aOtherSeriesList.size() )
+                                        {
+                                            rtl::Reference< DataSeries > 
xExchangeSeries( aOtherSeriesList[nOtherSeriesIndex] );
+                                            
aOtherSeriesList[nOtherSeriesIndex] = xGivenDataSeries;
+                                            
xFormerChartType->setDataSeries(aOtherSeriesList);
+
+                                            
aSeriesList[nOldSeriesIndex]=xExchangeSeries;
+                                            
xCurrentChartType->setDataSeries(aSeriesList);
+                                        }
+                                    }
+                                }
+                            }
+                            else if( nT+1 < aChartTypeList.size() )
+                            {
+                                //exchange series with next charttype
+                                rtl::Reference< ChartType > xOtherChartType( 
aChartTypeList[nT+1] );
+                                if( xOtherChartType.is() && 
DiagramHelper::areChartTypesCompatible( xOtherChartType, xCurrentChartType ) )
+                                {
+                                    bMovedOrMoveAllowed = true;
+                                    if( bDoMove )
+                                    {
+                                        std::vector< rtl::Reference< 
DataSeries > > aOtherSeriesList = xOtherChartType->getDataSeries2();
+                                        if( !aOtherSeriesList.empty() )
+                                        {
+                                            rtl::Reference< DataSeries > 
xExchangeSeries( aOtherSeriesList[0] );
+                                            aOtherSeriesList[0] = 
xGivenDataSeries;
+                                            
xOtherChartType->setDataSeries(aOtherSeriesList);
+
+                                            
aSeriesList[nOldSeriesIndex]=xExchangeSeries;
+                                            
xCurrentChartType->setDataSeries(aSeriesList);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        catch( const util::CloseVetoException& )
+                        {
+                        }
+                        catch( const uno::RuntimeException& )
+                        {
+                        }
+                    }
+                }
+                xFormerChartType = xCurrentChartType;
+            }
+        }
+    }
+    catch( const util::CloseVetoException& )
+    {
+    }
+    catch( const uno::RuntimeException& )
+    {
+    }
+    return bMovedOrMoveAllowed;
+}
+
+bool Diagram::isSeriesMoveable(
+    const Reference< css::chart2::XDataSeries >& xGivenDataSeries,
+    bool bForward )
+{
+    const bool bDoMove = false;
+
+    rtl::Reference pGivenDataSeries = 
dynamic_cast<DataSeries*>(xGivenDataSeries.get());
+    assert(pGivenDataSeries || !xGivenDataSeries);
+
+    bool bIsMoveable = lcl_moveSeriesOrCheckIfMoveIsAllowed(
+        *this, pGivenDataSeries, bForward, bDoMove );
+
+    return bIsMoveable;
+}
+
+bool Diagram::moveSeries( const Reference< css::chart2::XDataSeries >& 
xGivenDataSeries, bool bForward )
+{
+    const bool bDoMove = true;
+
+    rtl::Reference pGivenDataSeries = 
dynamic_cast<DataSeries*>(xGivenDataSeries.get());
+    assert(pGivenDataSeries || !xGivenDataSeries);
+
+    bool bMoved = lcl_moveSeriesOrCheckIfMoveIsAllowed(
+        *this, pGivenDataSeries, bForward, bDoMove );
+
+    return bMoved;
+}
+
 
 } //  namespace chart
 
diff --git a/chart2/source/tools/DiagramHelper.cxx 
b/chart2/source/tools/DiagramHelper.cxx
index 101ac972b33e..cfbb0cc7d834 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -1129,197 +1129,6 @@ bool DiagramHelper::areChartTypesCompatible( const 
rtl::Reference< ChartType >&
     return ( aFirstRoles == aSecondRoles );
 }
 
-namespace
-{
-     /**
-     * This method implements the logic of checking if a series can be moved
-     * forward/backward. Depending on the "bDoMove" parameter the series will
-     * be moved (bDoMove = true) or the function just will test if the
-     * series can be moved without doing the move (bDoMove = false).
-     *
-     * @param xDiagram
-     *  Reference to the diagram that contains the series.
-     *
-     * @param xGivenDataSeries
-     *  Reference to the series that should moved or tested for moving.
-     *
-     * @param bForward
-     *  Direction in which the series should be moved or tested for moving.
-     *
-     * @param bDoMove
-     *  Should this function really move the series (true) or just test if it 
is
-     *  possible (false).
-     *
-     *
-     * @returns
-     *  in case of bDoMove == true
-     *      - True : if the move was done
-     *      - False : the move failed
-     *  in case of bDoMove == false
-     *      - True : the series can be moved
-     *      - False : the series can not be moved
-     *
-     */
-
-bool lcl_moveSeriesOrCheckIfMoveIsAllowed(
-    const rtl::Reference< Diagram >& xDiagram,
-    const rtl::Reference< DataSeries >& xGivenDataSeries,
-    bool bForward,
-    bool bDoMove )
-{
-    bool bMovedOrMoveAllowed = false;
-
-    try
-    {
-        if( xGivenDataSeries.is() && xDiagram.is() )
-        {
-            //find position of series.
-            bool bFound = false;
-            const std::vector< rtl::Reference< BaseCoordinateSystem > > & 
aCooSysList( xDiagram->getBaseCoordinateSystems() );
-
-            for( std::size_t nCS = 0; !bFound && nCS < aCooSysList.size(); 
++nCS )
-            {
-                const rtl::Reference< BaseCoordinateSystem > & xCooSys( 
aCooSysList[nCS] );
-
-                //iterate through all chart types in the current coordinate 
system
-                std::vector< rtl::Reference< ChartType > > aChartTypeList( 
xCooSys->getChartTypes2() );
-                rtl::Reference< ChartType > xFormerChartType;
-
-                for( std::size_t nT = 0; !bFound && nT < 
aChartTypeList.size(); ++nT )
-                {
-                    rtl::Reference< ChartType > xCurrentChartType( 
aChartTypeList[nT] );
-
-                    //iterate through all series in this chart type
-
-                    std::vector< rtl::Reference< DataSeries > > aSeriesList = 
xCurrentChartType->getDataSeries2();
-
-                    for( std::size_t nS = 0; !bFound && nS < 
aSeriesList.size(); ++nS )
-                    {
-
-                        // We found the series we are interested in!
-                        if( xGivenDataSeries==aSeriesList[nS] )
-                        {
-                            std::size_t nOldSeriesIndex = nS;
-                            bFound = true;
-
-                            try
-                            {
-                                sal_Int32 nNewSeriesIndex = nS;
-
-                                // tdf#34517 Bringing forward means 
increasing, backwards means decreasing series position
-                                if( !bForward )
-                                    nNewSeriesIndex--;
-                                else
-                                    nNewSeriesIndex++;
-
-                                if( nNewSeriesIndex >= 0 && 
o3tl::make_unsigned(nNewSeriesIndex) < aSeriesList.size() )
-                                {
-                                    //move series in the same charttype
-                                    bMovedOrMoveAllowed = true;
-                                    if( bDoMove )
-                                    {
-                                        aSeriesList[ nOldSeriesIndex ] = 
aSeriesList[ nNewSeriesIndex ];
-                                        aSeriesList[ nNewSeriesIndex ] = 
xGivenDataSeries;
-                                        xCurrentChartType->setDataSeries( 
aSeriesList );
-                                    }
-                                }
-                                else if( nNewSeriesIndex<0 )
-                                {
-                                    //exchange series with former charttype
-                                    if( xFormerChartType.is() && 
DiagramHelper::areChartTypesCompatible( xFormerChartType, xCurrentChartType ) )
-                                    {
-                                        bMovedOrMoveAllowed = true;
-                                        if( bDoMove )
-                                        {
-                                            std::vector< rtl::Reference< 
DataSeries > > aOtherSeriesList = xFormerChartType->getDataSeries2();
-                                            sal_Int32 nOtherSeriesIndex = 
aOtherSeriesList.size()-1;
-                                            if( nOtherSeriesIndex >= 0 && 
o3tl::make_unsigned(nOtherSeriesIndex) < aOtherSeriesList.size() )
-                                            {
-                                                rtl::Reference< DataSeries > 
xExchangeSeries( aOtherSeriesList[nOtherSeriesIndex] );
-                                                
aOtherSeriesList[nOtherSeriesIndex] = xGivenDataSeries;
-                                                
xFormerChartType->setDataSeries(aOtherSeriesList);
-
-                                                
aSeriesList[nOldSeriesIndex]=xExchangeSeries;
-                                                
xCurrentChartType->setDataSeries(aSeriesList);
-                                            }
-                                        }
-                                    }
-                                }
-                                else if( nT+1 < aChartTypeList.size() )
-                                {
-                                    //exchange series with next charttype
-                                    rtl::Reference< ChartType > 
xOtherChartType( aChartTypeList[nT+1] );
-                                    if( xOtherChartType.is() && 
DiagramHelper::areChartTypesCompatible( xOtherChartType, xCurrentChartType ) )
-                                    {
-                                        bMovedOrMoveAllowed = true;
-                                        if( bDoMove )
-                                        {
-                                            std::vector< rtl::Reference< 
DataSeries > > aOtherSeriesList = xOtherChartType->getDataSeries2();
-                                            if( !aOtherSeriesList.empty() )
-                                            {
-                                                rtl::Reference< DataSeries > 
xExchangeSeries( aOtherSeriesList[0] );
-                                                aOtherSeriesList[0] = 
xGivenDataSeries;
-                                                
xOtherChartType->setDataSeries(aOtherSeriesList);
-
-                                                
aSeriesList[nOldSeriesIndex]=xExchangeSeries;
-                                                
xCurrentChartType->setDataSeries(aSeriesList);
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                            catch( const util::CloseVetoException& )
-                            {
-                            }
-                            catch( const uno::RuntimeException& )
-                            {
-                            }
-                        }
-                    }
-                    xFormerChartType = xCurrentChartType;
-                }
-            }
-        }
-    }
-    catch( const util::CloseVetoException& )
-    {
-    }
-    catch( const uno::RuntimeException& )
-    {
-    }
-    return bMovedOrMoveAllowed;
-}
-} // anonymous namespace
-
-bool DiagramHelper::isSeriesMoveable(
-    const rtl::Reference< Diagram >& xDiagram,
-    const Reference< XDataSeries >& xGivenDataSeries,
-    bool bForward )
-{
-    const bool bDoMove = false;
-
-    rtl::Reference pGivenDataSeries = 
dynamic_cast<DataSeries*>(xGivenDataSeries.get());
-    assert(pGivenDataSeries || !xGivenDataSeries);
-
-    bool bIsMoveable = lcl_moveSeriesOrCheckIfMoveIsAllowed(
-        xDiagram, pGivenDataSeries, bForward, bDoMove );
-
-    return bIsMoveable;
-}
-
-bool DiagramHelper::moveSeries( const rtl::Reference< Diagram >& xDiagram, 
const Reference< XDataSeries >& xGivenDataSeries, bool bForward )
-{
-    const bool bDoMove = true;
-
-    rtl::Reference pGivenDataSeries = 
dynamic_cast<DataSeries*>(xGivenDataSeries.get());
-    assert(pGivenDataSeries || !xGivenDataSeries);
-
-    bool bMoved = lcl_moveSeriesOrCheckIfMoveIsAllowed(
-        xDiagram, pGivenDataSeries, bForward, bDoMove );
-
-    return bMoved;
-}
-
 static void lcl_ensureRange0to1( double& rValue )
 {
     if(rValue<0.0)

Reply via email to