chart2/source/controller/inc/ChartController.hxx             |   10 -
 chart2/source/controller/inc/CommandDispatchContainer.hxx    |    8 
 chart2/source/controller/main/ChartController.cxx            |   81 +++-----
 chart2/source/controller/main/ChartController_EditData.cxx   |    3 
 chart2/source/controller/main/ChartController_Insert.cxx     |  102 +++++------
 chart2/source/controller/main/ChartController_Position.cxx   |    4 
 chart2/source/controller/main/ChartController_Properties.cxx |   94 +++++-----
 chart2/source/controller/main/ChartController_TextEdit.cxx   |    5 
 chart2/source/controller/main/ChartController_Tools.cxx      |   76 +++-----
 chart2/source/controller/main/ChartController_Window.cxx     |   46 ++--
 chart2/source/controller/main/ChartDropTargetHelper.cxx      |    8 
 chart2/source/controller/main/ChartDropTargetHelper.hxx      |    6 
 chart2/source/controller/main/ChartModelClone.cxx            |   60 ++----
 chart2/source/controller/main/ChartModelClone.hxx            |   12 -
 chart2/source/controller/main/CommandDispatchContainer.cxx   |    7 
 chart2/source/controller/main/ControllerCommandDispatch.cxx  |   50 ++---
 chart2/source/controller/main/DragMethod_Base.cxx            |   10 -
 chart2/source/controller/main/DragMethod_Base.hxx            |    9 
 chart2/source/controller/main/DragMethod_PieSegment.cxx      |    8 
 chart2/source/controller/main/DragMethod_PieSegment.hxx      |    2 
 chart2/source/controller/main/DragMethod_RotateDiagram.cxx   |    9 
 chart2/source/controller/main/DragMethod_RotateDiagram.hxx   |    2 
 chart2/source/controller/main/ElementSelector.cxx            |   34 +--
 chart2/source/controller/main/ElementSelector.hxx            |    7 
 chart2/source/controller/main/StatusBarCommandDispatch.cxx   |   20 +-
 chart2/source/controller/main/StatusBarCommandDispatch.hxx   |    5 
 chart2/source/controller/main/UndoActions.cxx                |    3 
 chart2/source/controller/main/UndoActions.hxx                |    6 
 chart2/source/controller/main/UndoCommandDispatch.cxx        |    6 
 chart2/source/controller/main/UndoCommandDispatch.hxx        |    6 
 chart2/source/controller/main/UndoGuard.cxx                  |    6 
 chart2/source/controller/main/UndoGuard.hxx                  |    2 
 32 files changed, 341 insertions(+), 366 deletions(-)

New commits:
commit 4ab36ed96f9dce18bad751c67bb447d3783f3aba
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 19 10:04:48 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jan 19 11:38:51 2022 +0100

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

diff --git a/chart2/source/controller/inc/ChartController.hxx 
b/chart2/source/controller/inc/ChartController.hxx
index 451a3bfe9a52..01019e39473e 100644
--- a/chart2/source/controller/inc/ChartController.hxx
+++ b/chart2/source/controller/inc/ChartController.hxx
@@ -336,24 +336,24 @@ public:
 
     css::uno::Reference<css::uno::XInterface> const & getChartView() const;
 
+    rtl::Reference<::chart::ChartModel> getChartModel();
+
 private:
     class TheModel : public salhelper::SimpleReferenceObject
     {
         public:
-            explicit TheModel( const css::uno::Reference<
-                        css::frame::XModel > & xModel );
+            explicit TheModel( const rtl::Reference<::chart::ChartModel> & 
xModel );
 
             virtual ~TheModel() override;
 
             void        addListener( ChartController* pController );
             void        removeListener(  ChartController* pController );
             void        tryTermination();
-            const css::uno::Reference< css::frame::XModel >&
+            const rtl::Reference<::chart::ChartModel>&
                         getModel() const { return m_xModel;}
 
         private:
-            css::uno::Reference< css::frame::XModel >     m_xModel;
-            css::uno::Reference< css::util::XCloseable >  m_xCloseable;
+            rtl::Reference<::chart::ChartModel>     m_xModel;
 
             //the ownership between model and controller is not clear at first
             //each controller might consider himself as owner of the model 
first
diff --git a/chart2/source/controller/inc/CommandDispatchContainer.hxx 
b/chart2/source/controller/inc/CommandDispatchContainer.hxx
index 1ed026597d73..ae95313c0f20 100644
--- a/chart2/source/controller/inc/CommandDispatchContainer.hxx
+++ b/chart2/source/controller/inc/CommandDispatchContainer.hxx
@@ -18,7 +18,7 @@
  */
 #pragma once
 
-#include <cppuhelper/weakref.hxx>
+#include <unotools/weakref.hxx>
 #include <o3tl/sorted_vector.hxx>
 
 #include <map>
@@ -33,7 +33,7 @@ namespace com::sun::star::util { struct URL; }
 
 namespace chart
 {
-
+class ChartModel;
 class DrawCommandDispatch;
 class ShapeController;
 
@@ -73,7 +73,7 @@ public:
         const css::uno::Reference< css::uno::XComponentContext > & xContext );
 
     void setModel(
-        const css::uno::Reference< css::frame::XModel > & xModel );
+        const rtl::Reference<::chart::ChartModel> & xModel );
 
     /** Set a chart dispatcher that is used for all commands contained in
         rChartCommands
@@ -122,7 +122,7 @@ private:
     mutable tDisposeVector m_aToBeDisposedDispatches;
 
     css::uno::Reference< css::uno::XComponentContext >    m_xContext;
-    css::uno::WeakReference< css::frame::XModel >         m_xModel;
+    unotools::WeakReference< ::chart::ChartModel >         m_xModel;
 
     css::uno::Reference< css::frame::XDispatch >          m_xChartDispatcher;
     o3tl::sorted_vector< OUString >                       m_aChartCommands;
diff --git a/chart2/source/controller/main/ChartController.cxx 
b/chart2/source/controller/main/ChartController.cxx
index 19c314da2635..751afe7f30ee 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -122,12 +122,10 @@ ChartController::~ChartController()
     stopDoubleClickWaiting();
 }
 
-ChartController::TheModel::TheModel( const uno::Reference< frame::XModel > & 
xModel ) :
+ChartController::TheModel::TheModel( const rtl::Reference<::chart::ChartModel> 
& xModel ) :
     m_xModel( xModel ),
     m_bOwnership( true )
 {
-    m_xCloseable =
-        uno::Reference< util::XCloseable >( xModel, uno::UNO_QUERY );
 }
 
 ChartController::TheModel::~TheModel()
@@ -136,33 +134,22 @@ ChartController::TheModel::~TheModel()
 
 void ChartController::TheModel::addListener( ChartController* pController )
 {
-    if(m_xCloseable.is())
+    if(m_xModel)
     {
         //if you need to be able to veto against the destruction of the model
         // you must add as a close listener
 
         //otherwise you 'can' add as closelistener or 'must' add as dispose 
event listener
 
-        m_xCloseable->addCloseListener(
+        m_xModel->addCloseListener(
             static_cast<util::XCloseListener*>(pController) );
     }
-    else if( m_xModel.is() )
-    {
-        //we need to add as dispose event listener
-        m_xModel->addEventListener(
-            static_cast<util::XCloseListener*>(pController) );
-    }
-
 }
 
 void ChartController::TheModel::removeListener(  ChartController* pController )
 {
-    if(m_xCloseable.is())
-        m_xCloseable->removeCloseListener(
-            static_cast<util::XCloseListener*>(pController) );
-
-    else if( m_xModel.is() )
-        m_xModel->removeEventListener(
+    if(m_xModel)
+        m_xModel->removeCloseListener(
             static_cast<util::XCloseListener*>(pController) );
 }
 
@@ -173,7 +160,7 @@ void ChartController::TheModel::tryTermination()
 
     try
     {
-        if(m_xCloseable.is())
+        if(m_xModel.is())
         {
             try
             {
@@ -181,7 +168,7 @@ void ChartController::TheModel::tryTermination()
                 //I think yes, because there might be other CloseListeners 
later in the list which might be interested still
                 //but make sure that we do not throw the CloseVetoException 
here ourselves
                 //so stop listening before trying to terminate or check the 
source of queryclosing event
-                m_xCloseable->close(true);
+                m_xModel->close(true);
 
                 m_bOwnership                = false;
             }
@@ -196,12 +183,6 @@ void ChartController::TheModel::tryTermination()
             }
 
         }
-        else if( m_xModel.is() )
-        {
-            //@todo correct??
-            m_xModel->dispose();
-            return;
-        }
     }
     catch(const uno::Exception&)
     {
@@ -436,8 +417,7 @@ void SAL_CALL ChartController::attachFrame(
         m_xViewWindow.set( pChartWindow->GetComponentInterface(), 
uno::UNO_QUERY );
         pChartWindow->Show();
         m_apDropTargetHelper.reset(
-            new ChartDropTargetHelper( pChartWindow->GetDropTarget(),
-                                       uno::Reference< chart2::XChartDocument 
>( getModel(), uno::UNO_QUERY )));
+            new ChartDropTargetHelper( pChartWindow->GetDropTarget(), 
getChartModel()));
 
         impl_createDrawViewController();
     }
@@ -529,7 +509,7 @@ void SAL_CALL ChartController::modeChanged( const 
util::ModeChangeEvent& rEvent
                     if( m_aSelection.hasSelection() )
                         this->impl_selectObjectAndNotiy();
                     else
-                        ChartModelHelper::triggerRangeHighlighting( getModel() 
);
+                        ChartModelHelper::triggerRangeHighlighting( 
getChartModel() );
 
                     impl_initializeAccessible();
 
@@ -557,7 +537,10 @@ sal_Bool SAL_CALL ChartController::attachModel( const 
uno::Reference< frame::XMo
         return false; //behave passive if already disposed or suspended
     aGuard.clear();
 
-    TheModelRef aNewModelRef( new TheModel( xModel), m_aModelMutex);
+    ::chart::ChartModel* pChartModel = 
dynamic_cast<::chart::ChartModel*>(xModel.get());
+    assert(!xModel || pChartModel);
+
+    TheModelRef aNewModelRef( new TheModel(pChartModel), m_aModelMutex);
     TheModelRef aOldModelRef(m_aModel,m_aModelMutex);
     m_aModel = aNewModelRef;
 
@@ -571,9 +554,8 @@ sal_Bool SAL_CALL ChartController::attachModel( const 
uno::Reference< frame::XMo
 
         aOldModelRef->removeListener( this );
  #ifdef TEST_ENABLE_MODIFY_LISTENER
-        uno::Reference< util::XModifyBroadcaster > xMBroadcaster( 
aOldModelRef->getModel(),uno::UNO_QUERY );
-        if( xMBroadcaster.is())
-            xMBroadcaster->removeModifyListener( this );
+        if( aOldModelRef->getModel().is())
+            aOldModelRef->getModel()->removeModifyListener( this );
 #endif
     }
 
@@ -601,9 +583,8 @@ sal_Bool SAL_CALL ChartController::attachModel( const 
uno::Reference< frame::XMo
     aGuard.clear();
 
 #ifdef TEST_ENABLE_MODIFY_LISTENER
-    uno::Reference< util::XModifyBroadcaster > xMBroadcaster( 
aNewModelRef->getModel(),uno::UNO_QUERY );
-    if( xMBroadcaster.is())
-        xMBroadcaster->addModifyListener( this );
+    if( aNewModelRef->getModel().is())
+        aNewModelRef->getModel()->addModifyListener( this );
 #endif
 
     // #i119999# Do not do this per default to allow the user to deselect the 
chart OLE with a single press to ESC
@@ -643,6 +624,11 @@ uno::Reference< frame::XFrame > SAL_CALL 
ChartController::getFrame()
 }
 
 uno::Reference< frame::XModel > SAL_CALL ChartController::getModel()
+{
+    return getChartModel();
+}
+
+rtl::Reference<::chart::ChartModel> ChartController::getChartModel()
 {
     //provides access to currently attached model
     //returns the currently attached model
@@ -652,7 +638,7 @@ uno::Reference< frame::XModel > SAL_CALL 
ChartController::getModel()
     if(aModelRef.is())
         return aModelRef->getModel();
 
-    return uno::Reference< frame::XModel > ();
+    return nullptr;
 }
 
 uno::Any SAL_CALL ChartController::getViewData()
@@ -822,9 +808,8 @@ void SAL_CALL ChartController::dispose()
 #ifdef TEST_ENABLE_MODIFY_LISTENER
             try
             {
-                uno::Reference< util::XModifyBroadcaster > xMBroadcaster( 
aModelRef->getModel(),uno::UNO_QUERY );
-                if( xMBroadcaster.is())
-                    xMBroadcaster->removeModifyListener( this );
+                if( aModelRef->getModel().is())
+                    aModelRef->getModel()->removeModifyListener( this );
             }
             catch( const uno::Exception & )
             {
@@ -881,7 +866,7 @@ void SAL_CALL ChartController::queryClosing(
     if( !aModelRef.is() )
         return;
 
-    if( aModelRef->getModel() != rSource.Source )
+    if( 
uno::Reference<XInterface>(static_cast<cppu::OWeakObject*>(aModelRef->getModel().get()))
 != rSource.Source )
     {
         OSL_FAIL( "queryClosing was called on a controller from an unknown 
source" );
         return;
@@ -925,7 +910,7 @@ bool ChartController::impl_releaseThisModel(
     bool bReleaseModel = false;
     {
         ::osl::Guard< ::osl::Mutex > aGuard( m_aModelMutex );
-        if( m_aModel.is() && m_aModel->getModel() == xModel )
+        if( m_aModel.is() && uno::Reference< uno::XInterface 
>(static_cast<cppu::OWeakObject*>(m_aModel->getModel().get())) == xModel )
         {
             m_aModel = nullptr;
             m_xUndoManager.clear();
@@ -1342,7 +1327,7 @@ void ChartController::executeDispatch_ChartType()
 
     SolarMutexGuard aSolarGuard;
     //prepare and open dialog
-    ChartTypeDialog aDlg(GetChartFrame(), getModel());
+    ChartTypeDialog aDlg(GetChartFrame(), getChartModel());
     if (aDlg.run() == RET_OK)
     {
         impl_adaptDataSeriesAutoResize();
@@ -1353,14 +1338,14 @@ void ChartController::executeDispatch_ChartType()
 void ChartController::executeDispatch_SourceData()
 {
     //convert properties to ItemSet
-    uno::Reference< XChartDocument >   xChartDoc( getModel(), uno::UNO_QUERY );
+    rtl::Reference< ::chart::ChartModel >  xChartDoc = getChartModel();
     OSL_ENSURE( xChartDoc.is(), "Invalid XChartDocument" );
     if( !xChartDoc.is() )
         return;
 
     // If there is a data table we should ask user if we really want to 
destroy it
     // and switch to data ranges.
-    ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartDoc);
+    ChartModel& rModel = *xChartDoc;
     if ( rModel.hasInternalDataProvider() )
     {
         // Check if we will able to create data provider later
@@ -1404,12 +1389,12 @@ void ChartController::executeDispatch_SourceData()
 
 void ChartController::executeDispatch_MoveSeries( bool bForward )
 {
-    ControllerLockGuardUNO aCLGuard( getModel() );
+    ControllerLockGuardUNO aCLGuard( getChartModel() );
 
     //get selected series
     OUString aObjectCID(m_aSelection.getSelectedCID());
     uno::Reference< XDataSeries > xGivenDataSeries( 
ObjectIdentifier::getDataSeriesForCID( //yyy todo also legend entries and 
labels?
-            aObjectCID, getModel() ) );
+            aObjectCID, getChartModel() ) );
 
     UndoGuardWithSelection aUndoGuard(
         ActionDescriptionProvider::createDescription(
@@ -1417,7 +1402,7 @@ void ChartController::executeDispatch_MoveSeries( bool 
bForward )
             SchResId(STR_OBJECT_DATASERIES)),
         m_xUndoManager );
 
-    bool bChanged = DiagramHelper::moveSeries( ChartModelHelper::findDiagram( 
getModel() ), xGivenDataSeries, bForward );
+    bool bChanged = DiagramHelper::moveSeries( ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(getChartModel()) ), xGivenDataSeries, 
bForward );
     if( bChanged )
     {
         m_aSelection.setSelection( ObjectIdentifier::getMovedSeriesCID( 
aObjectCID, bForward ) );
diff --git a/chart2/source/controller/main/ChartController_EditData.cxx 
b/chart2/source/controller/main/ChartController_EditData.cxx
index e9820cab3cce..4f0a979956b0 100644
--- a/chart2/source/controller/main/ChartController_EditData.cxx
+++ b/chart2/source/controller/main/ChartController_EditData.cxx
@@ -19,6 +19,7 @@
 
 #include <ChartWindow.hxx>
 #include <ChartController.hxx>
+#include <ChartModel.hxx>
 
 #include <dlg_DataEditor.hxx>
 #include "UndoGuard.hxx"
@@ -37,7 +38,7 @@ namespace chart
 
 void ChartController::executeDispatch_EditData()
 {
-    Reference< chart2::XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY 
);
+    rtl::Reference<::chart::ChartModel> xChartDoc( getChartModel(), 
uno::UNO_QUERY );
     if (xChartDoc.is())
     {
         SolarMutexGuard aSolarGuard;
diff --git a/chart2/source/controller/main/ChartController_Insert.cxx 
b/chart2/source/controller/main/ChartController_Insert.cxx
index 04c27782c375..1620c1ec5c1f 100644
--- a/chart2/source/controller/main/ChartController_Insert.cxx
+++ b/chart2/source/controller/main/ChartController_Insert.cxx
@@ -94,7 +94,7 @@ void ChartController::executeDispatch_InsertAxes()
     try
     {
         InsertAxisOrGridDialogData aDialogInput;
-        uno::Reference< XDiagram > xDiagram = 
ChartModelHelper::findDiagram(getModel());
+        uno::Reference< XDiagram > xDiagram = 
ChartModelHelper::findDiagram(uno::Reference<chart2::XChartDocument>(getChartModel()));
         AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, 
xDiagram );
         AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, 
xDiagram );
 
@@ -103,7 +103,7 @@ void ChartController::executeDispatch_InsertAxes()
         if (aDlg.run() == RET_OK)
         {
             // lock controllers till end of block
-            ControllerLockGuardUNO aCLGuard( getModel() );
+            ControllerLockGuardUNO aCLGuard( getChartModel() );
 
             InsertAxisOrGridDialogData aDialogOutput;
             aDlg.getResult(aDialogOutput);
@@ -132,7 +132,7 @@ void ChartController::executeDispatch_InsertGrid()
     try
     {
         InsertAxisOrGridDialogData aDialogInput;
-        uno::Reference< XDiagram > xDiagram = 
ChartModelHelper::findDiagram(getModel());
+        uno::Reference< XDiagram > xDiagram = 
ChartModelHelper::findDiagram(uno::Reference<chart2::XChartDocument>(getChartModel()));
         AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, 
xDiagram, false );
         AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, 
xDiagram, false );
 
@@ -141,7 +141,7 @@ void ChartController::executeDispatch_InsertGrid()
         if (aDlg.run() == RET_OK)
         {
             // lock controllers till end of block
-            ControllerLockGuardUNO aCLGuard( getModel() );
+            ControllerLockGuardUNO aCLGuard( getChartModel() );
             InsertAxisOrGridDialogData aDialogOutput;
             aDlg.getResult( aDialogOutput );
             bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram
@@ -166,17 +166,17 @@ void ChartController::executeDispatch_InsertTitles()
     try
     {
         TitleDialogData aDialogInput;
-        aDialogInput.readFromModel( getModel() );
+        aDialogInput.readFromModel( getChartModel() );
 
         SolarMutexGuard aGuard;
         SchTitleDlg aDlg(GetChartFrame(), aDialogInput);
         if (aDlg.run() == RET_OK)
         {
             // lock controllers till end of block
-            ControllerLockGuardUNO aCLGuard( getModel() );
+            ControllerLockGuardUNO aCLGuard( getChartModel() );
             TitleDialogData aDialogOutput(impl_createReferenceSizeProvider());
             aDlg.getResult(aDialogOutput);
-            bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), 
m_xCC, &aDialogInput );
+            bool bChanged = aDialogOutput.writeDifferenceToModel( 
getChartModel(), m_xCC, &aDialogInput );
             if( bChanged )
                 aUndoGuard.commit();
         }
@@ -223,12 +223,12 @@ void ChartController::executeDispatch_OpenLegendDialog()
         //prepare and open dialog
         SolarMutexGuard aGuard;
         SchLegendDlg aDlg(GetChartFrame(), m_xCC);
-        aDlg.init( getModel() );
+        aDlg.init( getChartModel() );
         if (aDlg.run() == RET_OK)
         {
             // lock controllers till end of block
-            ControllerLockGuardUNO aCLGuard( getModel() );
-            aDlg.writeToModel( getModel() );
+            ControllerLockGuardUNO aCLGuard( getChartModel() );
+            aDlg.writeToModel( getChartModel() );
             aUndoGuard.commit();
         }
     }
@@ -247,7 +247,7 @@ void 
ChartController::executeDispatch_InsertMenu_DataLabels()
 
     //if a series is selected insert labels for that series only:
     uno::Reference< chart2::XDataSeries > xSeries =
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel());
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel());
     if( xSeries.is() )
     {
         // add labels
@@ -266,7 +266,7 @@ void 
ChartController::executeDispatch_InsertMenu_DataLabels()
     try
     {
         wrapper::AllDataLabelItemConverter aItemConverter(
-            getModel(),
+            getChartModel(),
             m_pDrawModelWrapper->GetItemPool(),
             m_pDrawModelWrapper->getSdrModel(),
             uno::Reference< lang::XMultiServiceFactory >( getModel(), 
uno::UNO_QUERY ));
@@ -288,7 +288,7 @@ void 
ChartController::executeDispatch_InsertMenu_DataLabels()
             SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
             aDlg.FillItemSet(aOutItemSet);
             // lock controllers till end of block
-            ControllerLockGuardUNO aCLGuard( getModel() );
+            ControllerLockGuardUNO aCLGuard( getChartModel() );
             bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model 
should be changed now
             if( bChanged )
                 aUndoGuard.commit();
@@ -307,7 +307,7 @@ void ChartController::executeDispatch_InsertMeanValue()
             ActionDescriptionProvider::ActionType::Insert, SchResId( 
STR_OBJECT_AVERAGE_LINE )),
         m_xUndoManager );
     lcl_InsertMeanValueLine( ObjectIdentifier::getDataSeriesForCID( 
m_aSelection.getSelectedCID(),
-                                                                    getModel() 
) );
+                                                                    
getChartModel() ) );
     aUndoGuard.commit();
 }
 
@@ -319,7 +319,7 @@ void 
ChartController::executeDispatch_InsertMenu_MeanValues()
         m_xUndoManager );
 
     uno::Reference< chart2::XDataSeries > xSeries =
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() );
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() );
     if( xSeries.is() )
     {
         //if a series is selected insert mean value only for that series:
@@ -328,7 +328,7 @@ void 
ChartController::executeDispatch_InsertMenu_MeanValues()
     else
     {
         std::vector< uno::Reference< chart2::XDataSeries > > aSeries(
-            DiagramHelper::getDataSeriesFromDiagram( 
ChartModelHelper::findDiagram( getModel() )));
+            DiagramHelper::getDataSeriesFromDiagram( 
ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(getChartModel()) )));
 
         for( const auto& xSrs : aSeries )
             lcl_InsertMeanValueLine( xSrs );
@@ -341,7 +341,7 @@ void 
ChartController::executeDispatch_InsertMenu_Trendlines()
     OUString aCID = m_aSelection.getSelectedCID();
 
     uno::Reference< chart2::XDataSeries > xSeries =
-        ObjectIdentifier::getDataSeriesForCID( aCID, getModel() );
+        ObjectIdentifier::getDataSeriesForCID( aCID, getChartModel() );
 
     if( !xSeries.is() )
         return;
@@ -352,7 +352,7 @@ void 
ChartController::executeDispatch_InsertMenu_Trendlines()
 void ChartController::executeDispatch_InsertTrendline()
 {
     uno::Reference< chart2::XRegressionCurveContainer > 
xRegressionCurveContainer(
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel()), uno::UNO_QUERY );
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel()), uno::UNO_QUERY );
 
     if( !xRegressionCurveContainer.is() )
         return;
@@ -384,7 +384,7 @@ void ChartController::executeDispatch_InsertTrendline()
         ObjectIdentifier::createDataCurveCID(
             ObjectIdentifier::getSeriesParticleFromCID( 
m_aSelection.getSelectedCID()),
             RegressionCurveHelper::getRegressionCurveIndex( 
xRegressionCurveContainer, xCurve ), false ));
-    aDialogParameter.init( getModel() );
+    aDialogParameter.init( getChartModel() );
     ViewElementListProvider aViewElementListProvider( 
m_pDrawModelWrapper.get());
     SolarMutexGuard aGuard;
     SchAttribTabDlg aDialog(
@@ -400,7 +400,7 @@ void ChartController::executeDispatch_InsertTrendline()
         const SfxItemSet* pOutItemSet = aDialog.GetOutputItemSet();
         if( pOutItemSet )
         {
-            ControllerLockGuardUNO aCLGuard( getModel() );
+            ControllerLockGuardUNO aCLGuard( getChartModel() );
             aItemConverter.ApplyItemSet( *pOutItemSet );
         }
         aUndoGuard.commit();
@@ -413,7 +413,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool 
bYError )
 
     //if a series is selected insert error bars for that series only:
     uno::Reference< chart2::XDataSeries > xSeries =
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() );
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() );
 
     if( xSeries.is())
     {
@@ -442,7 +442,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool 
bYError )
         ObjectPropertiesDialogParameter aDialogParameter(
             ObjectIdentifier::createClassifiedIdentifierWithParent(
                 objType, u"", m_aSelection.getSelectedCID()));
-        aDialogParameter.init( getModel() );
+        aDialogParameter.init( getChartModel() );
         ViewElementListProvider aViewElementListProvider( 
m_pDrawModelWrapper.get());
         SolarMutexGuard aGuard;
         SchAttribTabDlg aDlg(
@@ -451,7 +451,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool 
bYError )
                 uno::Reference< util::XNumberFormatsSupplier >(
                         getModel(), uno::UNO_QUERY ) );
         aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
-            InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( 
getModel(),
+            InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( 
getChartModel(),
                                                                              
m_xChartView, m_aSelection.getSelectedCID()));
 
         // note: when a user pressed "OK" but didn't change any settings in the
@@ -461,7 +461,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool 
bYError )
             const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
             if( pOutItemSet )
             {
-                ControllerLockGuardUNO aCLGuard( getModel() );
+                ControllerLockGuardUNO aCLGuard( getChartModel() );
                 aItemConverter.ApplyItemSet( *pOutItemSet );
             }
             aUndoGuard.commit();
@@ -479,7 +479,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool 
bYError )
         try
         {
             wrapper::AllSeriesStatisticsConverter aItemConverter(
-                getModel(), m_pDrawModelWrapper->GetItemPool() );
+                getChartModel(), m_pDrawModelWrapper->GetItemPool() );
             SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
             aItemConverter.FillItemSet( aItemSet );
 
@@ -487,11 +487,11 @@ void ChartController::executeDispatch_InsertErrorBars( 
bool bYError )
             SolarMutexGuard aGuard;
             InsertErrorBarsDialog aDlg(
                 GetChartFrame(), aItemSet,
-                uno::Reference< chart2::XChartDocument >( getModel(), 
uno::UNO_QUERY ),
+                getChartModel(),
                 bYError ? ErrorBarResources::ERROR_BAR_Y : 
ErrorBarResources::ERROR_BAR_X);
 
             aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
-                
InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), 
m_xChartView, OUString() ) );
+                
InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( 
getChartModel(), m_xChartView, OUString() ) );
 
             if (aDlg.run() == RET_OK)
             {
@@ -499,7 +499,7 @@ void ChartController::executeDispatch_InsertErrorBars( bool 
bYError )
                 aDlg.FillItemSet( aOutItemSet );
 
                 // lock controllers till end of block
-                ControllerLockGuardUNO aCLGuard( getModel() );
+                ControllerLockGuardUNO aCLGuard( getChartModel() );
                 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet 
);//model should be changed now
                 if( bChanged )
                     aUndoGuard.commit();
@@ -515,11 +515,11 @@ void ChartController::executeDispatch_InsertErrorBars( 
bool bYError )
 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
 {
     uno::Reference< chart2::XRegressionCurve > xRegCurve(
-        ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
getModel() ), uno::UNO_QUERY );
+        ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
uno::Reference<chart2::XChartDocument>(getChartModel()) ), uno::UNO_QUERY );
     if( !xRegCurve.is() )
     {
         uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
-            ObjectIdentifier::getDataSeriesForCID( 
m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
+            ObjectIdentifier::getDataSeriesForCID( 
m_aSelection.getSelectedCID(), getChartModel() ), uno::UNO_QUERY );
         xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( 
xRegCurveCnt ) );
     }
     if( !xRegCurve.is())
@@ -543,7 +543,7 @@ void 
ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
 void ChartController::executeDispatch_InsertR2Value()
 {
     uno::Reference< beans::XPropertySet > xEqProp =
-        ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
getModel() );
+        ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
uno::Reference<chart2::XChartDocument>(getChartModel()) );
     if( xEqProp.is())
     {
         UndoGuard aUndoGuard(
@@ -558,7 +558,7 @@ void ChartController::executeDispatch_InsertR2Value()
 void ChartController::executeDispatch_DeleteR2Value()
 {
     uno::Reference< beans::XPropertySet > xEqProp =
-        ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
getModel() );
+        ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
uno::Reference<chart2::XChartDocument>(getChartModel()) );
     if( xEqProp.is())
     {
         UndoGuard aUndoGuard(
@@ -573,7 +573,7 @@ void ChartController::executeDispatch_DeleteR2Value()
 void ChartController::executeDispatch_DeleteMeanValue()
 {
     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() ), uno::UNO_QUERY );
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() ), uno::UNO_QUERY );
     if( xRegCurveCnt.is())
     {
         UndoGuard aUndoGuard(
@@ -588,7 +588,7 @@ void ChartController::executeDispatch_DeleteMeanValue()
 void ChartController::executeDispatch_DeleteTrendline()
 {
     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() ), uno::UNO_QUERY );
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() ), uno::UNO_QUERY );
     if( xRegCurveCnt.is())
     {
         UndoGuard aUndoGuard(
@@ -603,7 +603,7 @@ void ChartController::executeDispatch_DeleteTrendline()
 void ChartController::executeDispatch_DeleteTrendlineEquation()
 {
     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() ), uno::UNO_QUERY );
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() ), uno::UNO_QUERY );
     if( xRegCurveCnt.is())
     {
         UndoGuard aUndoGuard(
@@ -618,7 +618,7 @@ void 
ChartController::executeDispatch_DeleteTrendlineEquation()
 void ChartController::executeDispatch_DeleteErrorBars( bool bYError )
 {
     uno::Reference< chart2::XDataSeries > xDataSeries(
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() ));
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() ));
     if( xDataSeries.is())
     {
         UndoGuard aUndoGuard(
@@ -633,7 +633,7 @@ void ChartController::executeDispatch_DeleteErrorBars( bool 
bYError )
 void ChartController::executeDispatch_InsertDataLabels()
 {
     uno::Reference< chart2::XDataSeries > xSeries =
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() );
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() );
     if( xSeries.is() )
     {
         UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( 
ActionDescriptionProvider::ActionType::Insert,
@@ -649,14 +649,14 @@ void ChartController::executeDispatch_InsertDataLabel()
     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( 
ActionDescriptionProvider::ActionType::Insert,
         SchResId( STR_OBJECT_LABEL )),
         m_xUndoManager );
-    DataSeriesHelper::insertDataLabelToPoint( 
ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
getModel() ) );
+    DataSeriesHelper::insertDataLabelToPoint( 
ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
uno::Reference<chart2::XChartDocument>(getChartModel()) ) );
     aUndoGuard.commit();
 }
 
 void ChartController::executeDispatch_DeleteDataLabels()
 {
     uno::Reference< chart2::XDataSeries > xSeries =
-        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() );
+        ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() );
     if( xSeries.is() )
     {
         UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( 
ActionDescriptionProvider::ActionType::Delete,
@@ -672,7 +672,7 @@ void ChartController::executeDispatch_DeleteDataLabel()
     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( 
ActionDescriptionProvider::ActionType::Delete,
         SchResId( STR_OBJECT_LABEL )),
         m_xUndoManager );
-    DataSeriesHelper::deleteDataLabelsFromPoint( 
ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
getModel() ) );
+    DataSeriesHelper::deleteDataLabelsFromPoint( 
ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), 
uno::Reference<chart2::XChartDocument>(getChartModel()) ) );
     aUndoGuard.commit();
 }
 
@@ -681,7 +681,7 @@ void ChartController::executeDispatch_ResetAllDataPoints()
     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( 
ActionDescriptionProvider::ActionType::Format,
         SchResId( STR_OBJECT_DATAPOINTS )),
         m_xUndoManager );
-    uno::Reference< chart2::XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() );
+    uno::Reference< chart2::XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() );
     if( xSeries.is() )
         xSeries->resetAllDataPoints();
     aUndoGuard.commit();
@@ -691,7 +691,7 @@ void ChartController::executeDispatch_ResetDataPoint()
     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( 
ActionDescriptionProvider::ActionType::Format,
         SchResId( STR_OBJECT_DATAPOINT )),
         m_xUndoManager );
-    uno::Reference< chart2::XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() );
+    uno::Reference< chart2::XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() );
     if( xSeries.is() )
     {
         sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( 
m_aSelection.getSelectedCID() );
@@ -711,11 +711,11 @@ void ChartController::executeDispatch_InsertAxisTitle()
                 ActionDescriptionProvider::ActionType::Insert, SchResId( 
STR_OBJECT_TITLE )),
             m_xUndoManager );
 
-            Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getModel() );
+            Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getChartModel() );
             sal_Int32 nDimensionIndex = -1;
             sal_Int32 nCooSysIndex = -1;
             sal_Int32 nAxisIndex = -1;
-            AxisHelper::getIndicesForAxis( xAxis, 
ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, 
nAxisIndex );
+            AxisHelper::getIndicesForAxis( xAxis, 
ChartModelHelper::findDiagram(uno::Reference<chart2::XChartDocument>(getChartModel())),
 nCooSysIndex, nDimensionIndex, nAxisIndex );
 
             TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
             if( nDimensionIndex==0 )
@@ -726,7 +726,7 @@ void ChartController::executeDispatch_InsertAxisTitle()
                 eTitleType = TitleHelper::Z_AXIS_TITLE;
 
             std::unique_ptr< ReferenceSizeProvider > apRefSizeProvider( 
impl_createReferenceSizeProvider());
-            xTitle = TitleHelper::createTitle( eTitleType, 
ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, 
apRefSizeProvider.get() );
+            xTitle = TitleHelper::createTitle( eTitleType, 
ObjectNameProvider::getTitleNameByType(eTitleType), getChartModel(), m_xCC, 
apRefSizeProvider.get() );
             aUndoGuard.commit();
         }
     }
@@ -745,7 +745,7 @@ void ChartController::executeDispatch_InsertAxis()
 
     try
     {
-        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getModel() );
+        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getChartModel() );
         if( xAxis.is() )
         {
             AxisHelper::makeAxisVisible( xAxis );
@@ -767,7 +767,7 @@ void ChartController::executeDispatch_DeleteAxis()
 
     try
     {
-        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getModel() );
+        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getChartModel() );
         if( xAxis.is() )
         {
             AxisHelper::makeAxisInvisible( xAxis );
@@ -789,7 +789,7 @@ void ChartController::executeDispatch_InsertMajorGrid()
 
     try
     {
-        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getModel() );
+        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getChartModel() );
         if( xAxis.is() )
         {
             AxisHelper::makeGridVisible( xAxis->getGridProperties() );
@@ -811,7 +811,7 @@ void ChartController::executeDispatch_DeleteMajorGrid()
 
     try
     {
-        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getModel() );
+        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getChartModel() );
         if( xAxis.is() )
         {
             AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
@@ -833,7 +833,7 @@ void ChartController::executeDispatch_InsertMinorGrid()
 
     try
     {
-        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getModel() );
+        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getChartModel() );
         if( xAxis.is() )
         {
             const Sequence< Reference< beans::XPropertySet > > aSubGrids( 
xAxis->getSubGridProperties() );
@@ -857,7 +857,7 @@ void ChartController::executeDispatch_DeleteMinorGrid()
 
     try
     {
-        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getModel() );
+        Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
m_aSelection.getSelectedCID(), getChartModel() );
         if( xAxis.is() )
         {
             const Sequence< Reference< beans::XPropertySet > > aSubGrids( 
xAxis->getSubGridProperties() );
diff --git a/chart2/source/controller/main/ChartController_Position.cxx 
b/chart2/source/controller/main/ChartController_Position.cxx
index 4b9479c78dab..f57a3b8e8f96 100644
--- a/chart2/source/controller/main/ChartController_Position.cxx
+++ b/chart2/source/controller/main/ChartController_Position.cxx
@@ -183,7 +183,7 @@ void ChartController::executeDispatch_PositionAndSize(const 
::css::uno::Sequence
 
             awt::Rectangle aNewObjectRect;
             lcl_getPositionAndSizeFromItemSet( aItemSet, aNewObjectRect, 
ToSize(aOldObjectRect) );
-            awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
+            awt::Size aPageSize( ChartModelHelper::getPageSize( 
getChartModel() ) );
             awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
 
             bool bChanged = false;
@@ -193,7 +193,7 @@ void ChartController::executeDispatch_PositionAndSize(const 
::css::uno::Sequence
                 bChanged = 
DiagramHelper::switchDiagramPositioningToExcludingPositioning(rModel, false , 
true);
             }
 
-            bool bMoved = PositionAndSizeHelper::moveObject( 
m_aSelection.getSelectedCID(), getModel()
+            bool bMoved = PositionAndSizeHelper::moveObject( 
m_aSelection.getSelectedCID(), getChartModel()
                         , aNewObjectRect, aOldObjectRect, aPageRect );
             if( bMoved || bChanged )
                 aUndoGuard.commit();
diff --git a/chart2/source/controller/main/ChartController_Properties.cxx 
b/chart2/source/controller/main/ChartController_Properties.cxx
index 965df27134f6..f3a0d309cce7 100644
--- a/chart2/source/controller/main/ChartController_Properties.cxx
+++ b/chart2/source/controller/main/ChartController_Properties.cxx
@@ -41,6 +41,7 @@
 #include <AxisHelper.hxx>
 #include <TitleHelper.hxx>
 #include <ChartTypeHelper.hxx>
+#include <ChartModel.hxx>
 #include <ColorPerPointHelper.hxx>
 #include <DiagramHelper.hxx>
 #include <ControllerLockGuard.hxx>
@@ -71,7 +72,7 @@ namespace
 {
 
 wrapper::ItemConverter* createItemConverter(
-    const OUString & aObjectCID, const uno::Reference<frame::XModel>& 
xChartModel,
+    const OUString & aObjectCID, const rtl::Reference<::chart::ChartModel>& 
xChartModel,
     const uno::Reference<uno::XComponentContext>& xContext, SdrModel& 
rDrawModel,
     ExplicitValueProvider* pExplicitValueProvider, ReferenceSizeProvider const 
* pRefSizeProvider )
 {
@@ -90,7 +91,7 @@ wrapper::ItemConverter* createItemConverter(
     if( !bAffectsMultipleObjects )
     {
         uno::Reference< beans::XPropertySet > xObjectProperties =
-            ObjectIdentifier::getObjectPropertySet( aObjectCID, xChartModel );
+            ObjectIdentifier::getObjectPropertySet( aObjectCID, 
uno::Reference<chart2::XChartDocument>(xChartModel ));
         if(!xObjectProperties.is())
             return nullptr;
         //create itemconverter for a single object
@@ -99,7 +100,7 @@ wrapper::ItemConverter* createItemConverter(
             case OBJECTTYPE_PAGE:
                 pItemConverter =  new wrapper::GraphicPropertyItemConverter(
                                         xObjectProperties, 
rDrawModel.GetItemPool(),
-                                        rDrawModel, uno::Reference< 
lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
+                                        rDrawModel, xChartModel,
                                         
wrapper::GraphicObjectType::LineAndFillProperties );
                     break;
             case OBJECTTYPE_TITLE:
@@ -110,7 +111,7 @@ wrapper::ItemConverter* createItemConverter(
 
                 pItemConverter = new wrapper::TitleItemConverter(
                     xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
-                    uno::Reference<lang::XMultiServiceFactory>(xChartModel, 
uno::UNO_QUERY),
+                    xChartModel,
                     pRefSize.get());
             }
             break;
@@ -122,7 +123,7 @@ wrapper::ItemConverter* createItemConverter(
 
                 pItemConverter = new wrapper::LegendItemConverter(
                     xObjectProperties, rDrawModel.GetItemPool(), rDrawModel,
-                    uno::Reference<lang::XMultiServiceFactory>(xChartModel, 
uno::UNO_QUERY),
+                    xChartModel,
                     pRefSize.get());
             }
             break;
@@ -134,7 +135,7 @@ wrapper::ItemConverter* createItemConverter(
             case OBJECTTYPE_DIAGRAM_FLOOR:
                 pItemConverter =  new wrapper::GraphicPropertyItemConverter(
                                         xObjectProperties, 
rDrawModel.GetItemPool(),
-                                        rDrawModel, uno::Reference< 
lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
+                                        rDrawModel, xChartModel,
                                         
wrapper::GraphicObjectType::LineAndFillProperties );
                     break;
             case OBJECTTYPE_AXIS:
@@ -144,7 +145,7 @@ wrapper::ItemConverter* createItemConverter(
                     pRefSize.reset( new awt::Size( 
pRefSizeProvider->getPageSize()));
 
                 uno::Reference< beans::XPropertySet > xDiaProp;
-                xDiaProp.set( ChartModelHelper::findDiagram( xChartModel ), 
uno::UNO_QUERY );
+                xDiaProp.set( ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(xChartModel) ), uno::UNO_QUERY );
 
                 // the second property set contains the property 
CoordinateOrigin
                 // nOriginIndex is the index of the corresponding index of the
@@ -160,7 +161,7 @@ wrapper::ItemConverter* createItemConverter(
                 pItemConverter =  new wrapper::AxisItemConverter(
                     xObjectProperties, rDrawModel.GetItemPool(),
                     rDrawModel,
-                    uno::Reference< chart2::XChartDocument >( xChartModel, 
uno::UNO_QUERY ),
+                    xChartModel,
                     &aExplicitScale, &aExplicitIncrement,
                     pRefSize.get() );
             }
@@ -180,7 +181,7 @@ wrapper::ItemConverter* createItemConverter(
 
                 sal_Int32 nNumberFormat = 
ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( 
xObjectProperties );
                 sal_Int32 nPercentNumberFormat = 
ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
-                    
xObjectProperties,uno::Reference<util::XNumberFormatsSupplier>(xChartModel, 
uno::UNO_QUERY));
+                    xObjectProperties, xChartModel);
 
                 pItemConverter = new wrapper::TextLabelItemConverter(
                     xChartModel, xObjectProperties, xSeries,
@@ -201,7 +202,7 @@ wrapper::ItemConverter* createItemConverter(
                 uno::Reference< XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel );
                 uno::Reference< XChartType > xChartType = 
ChartModelHelper::getChartTypeOfSeries( xChartModel, xSeries );
 
-                uno::Reference< XDiagram > xDiagram( 
ChartModelHelper::findDiagram( xChartModel ) );
+                uno::Reference< XDiagram > xDiagram( 
ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(xChartModel) ) );
                 sal_Int32 nDimensionCount = DiagramHelper::getDimension( 
xDiagram );
                 if( !ChartTypeHelper::isSupportingAreaProperties( xChartType, 
nDimensionCount ) )
                     eMapTo = wrapper::GraphicObjectType::LineDataPoint;
@@ -233,11 +234,11 @@ wrapper::ItemConverter* createItemConverter(
                 }
                 sal_Int32 
nNumberFormat=ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel( 
xObjectProperties );
                 sal_Int32 
nPercentNumberFormat=ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
-                        xObjectProperties,uno::Reference< 
util::XNumberFormatsSupplier >(xChartModel, uno::UNO_QUERY));
+                        xObjectProperties, xChartModel);
 
                 pItemConverter =  new wrapper::DataPointItemConverter( 
xChartModel, xContext,
                                         xObjectProperties, xSeries, 
rDrawModel.GetItemPool(), rDrawModel,
-                                        uno::Reference< 
lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
+                                        xChartModel,
                                         eMapTo, pRefSize.get(), bDataSeries, 
bUseSpecialFillColor, nSpecialFillColor, true,
                                         nNumberFormat, nPercentNumberFormat, 
nPointIndex );
                 break;
@@ -247,7 +248,7 @@ wrapper::ItemConverter* createItemConverter(
             case OBJECTTYPE_DATA_AVERAGE_LINE:
                 pItemConverter =  new wrapper::GraphicPropertyItemConverter(
                                         xObjectProperties, 
rDrawModel.GetItemPool(),
-                                        rDrawModel, uno::Reference< 
lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
+                                        rDrawModel, xChartModel,
                                         
wrapper::GraphicObjectType::LineProperties );
                     break;
 
@@ -256,7 +257,7 @@ wrapper::ItemConverter* createItemConverter(
             case OBJECTTYPE_DATA_ERRORS_Z:
                 pItemConverter =  new wrapper::ErrorBarItemConverter(
                     xChartModel, xObjectProperties, rDrawModel.GetItemPool(),
-                    rDrawModel, uno::Reference< lang::XMultiServiceFactory >( 
xChartModel, uno::UNO_QUERY ));
+                    rDrawModel, xChartModel);
                 break;
 
             case OBJECTTYPE_DATA_CURVE:
@@ -264,7 +265,7 @@ wrapper::ItemConverter* createItemConverter(
                     xObjectProperties, uno::Reference< 
chart2::XRegressionCurveContainer >(
                         ObjectIdentifier::getDataSeriesForCID( aObjectCID, 
xChartModel ), uno::UNO_QUERY ),
                     rDrawModel.GetItemPool(), rDrawModel,
-                    uno::Reference< lang::XMultiServiceFactory >( xChartModel, 
uno::UNO_QUERY ));
+                    xChartModel);
                 break;
             case OBJECTTYPE_DATA_CURVE_EQUATION:
             {
@@ -274,7 +275,7 @@ wrapper::ItemConverter* createItemConverter(
 
                 pItemConverter =  new wrapper::RegressionEquationItemConverter(
                                         xObjectProperties, 
rDrawModel.GetItemPool(), rDrawModel,
-                                        uno::Reference< 
lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
+                                        xChartModel,
                                         pRefSize.get());
                 break;
             }
@@ -284,7 +285,7 @@ wrapper::ItemConverter* createItemConverter(
             case OBJECTTYPE_DATA_STOCK_GAIN:
                 pItemConverter =  new wrapper::GraphicPropertyItemConverter(
                                         xObjectProperties, 
rDrawModel.GetItemPool(),
-                                        rDrawModel, uno::Reference< 
lang::XMultiServiceFactory >( xChartModel, uno::UNO_QUERY ),
+                                        rDrawModel, xChartModel,
                                         
wrapper::GraphicObjectType::LineAndFillProperties );
                     break;
             default: //OBJECTTYPE_UNKNOWN
@@ -298,7 +299,7 @@ wrapper::ItemConverter* createItemConverter(
         {
             case OBJECTTYPE_TITLE:
                 pItemConverter =  new wrapper::AllTitleItemConverter( 
xChartModel, rDrawModel.GetItemPool(),
-                                                                     
rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, 
uno::UNO_QUERY ));
+                                                                     
rDrawModel, xChartModel);
                 break;
             case OBJECTTYPE_AXIS:
             {
@@ -314,7 +315,7 @@ wrapper::ItemConverter* createItemConverter(
             case OBJECTTYPE_GRID:
             case OBJECTTYPE_SUBGRID:
                 pItemConverter =  new wrapper::AllGridItemConverter( 
xChartModel, rDrawModel.GetItemPool(),
-                                                                     
rDrawModel, uno::Reference< lang::XMultiServiceFactory >( xChartModel, 
uno::UNO_QUERY ));
+                                                                     
rDrawModel, xChartModel);
                 break;
             default: //for this type it is not supported to change all 
elements at once
                 break;
@@ -324,7 +325,7 @@ wrapper::ItemConverter* createItemConverter(
     return pItemConverter;
 }
 
-OUString lcl_getTitleCIDForCommand( std::string_view rDispatchCommand, const 
uno::Reference< frame::XModel > & xChartModel )
+OUString lcl_getTitleCIDForCommand( std::string_view rDispatchCommand, const 
rtl::Reference<::chart::ChartModel> & xChartModel )
 {
     if( rDispatchCommand == "AllTitles")
         return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_TITLE, 
u"ALLELEMENTS" );
@@ -347,7 +348,7 @@ OUString lcl_getTitleCIDForCommand( std::string_view 
rDispatchCommand, const uno
     return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, 
xChartModel );
 }
 
-OUString lcl_getAxisCIDForCommand( std::string_view rDispatchCommand, const 
uno::Reference< frame::XModel >& xChartModel )
+OUString lcl_getAxisCIDForCommand( std::string_view rDispatchCommand, const 
rtl::Reference<::chart::ChartModel>& xChartModel )
 {
     if( rDispatchCommand == "DiagramAxisAll")
         return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_AXIS, 
u"ALLELEMENTS" );
@@ -375,14 +376,14 @@ OUString lcl_getAxisCIDForCommand( std::string_view 
rDispatchCommand, const uno:
         nDimensionIndex=1; bMainAxis=false;
     }
 
-    uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( 
xChartModel ) );
+    uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(xChartModel) ) );
     uno::Reference< XAxis > xAxis( AxisHelper::getAxis( nDimensionIndex, 
bMainAxis, xDiagram ) );
     return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, 
xChartModel );
 }
 
-OUString lcl_getGridCIDForCommand( std::string_view rDispatchCommand, const 
uno::Reference< frame::XModel >& xChartModel )
+OUString lcl_getGridCIDForCommand( std::string_view rDispatchCommand, const 
rtl::Reference<::chart::ChartModel>& xChartModel )
 {
-    uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( 
xChartModel ) );
+    uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(xChartModel) ) );
 
     if( rDispatchCommand == "DiagramGridAll")
         return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_GRID, 
u"ALLELEMENTS" );
@@ -432,13 +433,12 @@ OUString lcl_getErrorCIDForCommand( const ObjectType 
eDispatchType, const Object
     return ObjectIdentifier::createClassifiedIdentifierWithParent( 
eDispatchType, u"", rSelectedCID );
 }
 
-OUString lcl_getObjectCIDForCommand( std::string_view rDispatchCommand, const 
uno::Reference< XChartDocument > & xChartDocument, const OUString& rSelectedCID 
)
+OUString lcl_getObjectCIDForCommand( std::string_view rDispatchCommand, const 
rtl::Reference<::chart::ChartModel> & xChartDocument, const OUString& 
rSelectedCID )
 {
     ObjectType eObjectType = OBJECTTYPE_UNKNOWN;
 
-    uno::Reference< frame::XModel > xChartModel = xChartDocument;
     const ObjectType eSelectedType = ObjectIdentifier::getObjectType( 
rSelectedCID );
-    uno::Reference< XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartModel );
+    uno::Reference< XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartDocument );
     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( xSeries, 
uno::UNO_QUERY );
 
     //legend
@@ -474,7 +474,7 @@ OUString lcl_getObjectCIDForCommand( std::string_view 
rDispatchCommand, const un
         || rDispatchCommand == "AllTitles"
         )
     {
-        return lcl_getTitleCIDForCommand( rDispatchCommand, xChartModel );
+        return lcl_getTitleCIDForCommand( rDispatchCommand, xChartDocument );
     }
     //axis
     else if( rDispatchCommand == "DiagramAxisX"
@@ -485,7 +485,7 @@ OUString lcl_getObjectCIDForCommand( std::string_view 
rDispatchCommand, const un
         || rDispatchCommand == "DiagramAxisAll"
         )
     {
-        return lcl_getAxisCIDForCommand( rDispatchCommand, xChartModel );
+        return lcl_getAxisCIDForCommand( rDispatchCommand, xChartDocument );
     }
     //grid
     else if( rDispatchCommand == "DiagramGridYMain"
@@ -497,7 +497,7 @@ OUString lcl_getObjectCIDForCommand( std::string_view 
rDispatchCommand, const un
         || rDispatchCommand == "DiagramGridAll"
         )
     {
-        return lcl_getGridCIDForCommand( rDispatchCommand, xChartModel );
+        return lcl_getGridCIDForCommand( rDispatchCommand, xChartDocument );
     }
     //data series
     else if( rDispatchCommand == "FormatDataSeries" )
@@ -592,8 +592,8 @@ OUString lcl_getObjectCIDForCommand( std::string_view 
rDispatchCommand, const un
             return rSelectedCID;
         else
         {
-            Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
rSelectedCID, xChartModel );
-            return ObjectIdentifier::createClassifiedIdentifierForObject( 
xAxis , xChartModel );
+            Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
rSelectedCID, xChartDocument );
+            return ObjectIdentifier::createClassifiedIdentifierForObject( 
xAxis , xChartDocument );
         }
     }
     // major grid
@@ -603,8 +603,8 @@ OUString lcl_getObjectCIDForCommand( std::string_view 
rDispatchCommand, const un
             return rSelectedCID;
         else
         {
-            Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
rSelectedCID, xChartModel );
-            return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, 
xChartModel );
+            Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
rSelectedCID, xChartDocument );
+            return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, 
xChartDocument );
         }
 
     }
@@ -615,8 +615,8 @@ OUString lcl_getObjectCIDForCommand( std::string_view 
rDispatchCommand, const un
             return rSelectedCID;
         else
         {
-            Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
rSelectedCID, xChartModel );
-            return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, 
xChartModel, 0 /*sub grid index*/ );
+            Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( 
rSelectedCID, xChartDocument );
+            return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, 
xChartDocument, 0 /*sub grid index*/ );
         }
     }
     // title
@@ -652,7 +652,7 @@ OUString lcl_getObjectCIDForCommand( std::string_view 
rDispatchCommand, const un
 
 void ChartController::executeDispatch_FormatObject(std::u16string_view 
rDispatchCommand)
 {
-    uno::Reference< XChartDocument > xChartDocument( getModel(), 
uno::UNO_QUERY );
+    rtl::Reference<::chart::ChartModel> xChartDocument( getChartModel() );
     OString aCommand( OUStringToOString( rDispatchCommand, 
RTL_TEXTENCODING_ASCII_US ) );
     OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, 
xChartDocument, m_aSelection.getSelectedCID() );
     executeDlg_ObjectProperties( rObjectCID );
@@ -722,7 +722,7 @@ bool 
ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
         }
         if( eObjectType==OBJECTTYPE_DIAGRAM_WALL || 
eObjectType==OBJECTTYPE_DIAGRAM_FLOOR )
         {
-            if( !DiagramHelper::isSupportingFloorAndWall( 
ChartModelHelper::findDiagram( getModel() ) ) )
+            if( !DiagramHelper::isSupportingFloorAndWall( 
ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(getChartModel()) ) ) )
                 return bRet;
         }
 
@@ -731,7 +731,7 @@ bool 
ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
         std::unique_ptr<ReferenceSizeProvider> 
pRefSizeProv(impl_createReferenceSizeProvider());
 
         std::unique_ptr<wrapper::ItemConverter> pItemConverter(
-            createItemConverter( rObjectCID, getModel(), m_xCC,
+            createItemConverter( rObjectCID, getChartModel(), m_xCC,
                                  m_pDrawModelWrapper->getSdrModel(),
                                  
comphelper::getFromUnoTunnel<ExplicitValueProvider>(m_xChartView),
                                  pRefSizeProv.get()));
@@ -748,7 +748,7 @@ bool 
ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
 
         //prepare dialog
         ObjectPropertiesDialogParameter aDialogParameter( rObjectCID );
-        aDialogParameter.init( getModel() );
+        aDialogParameter.init( getChartModel() );
         ViewElementListProvider aViewElementListProvider( 
m_pDrawModelWrapper.get() );
 
         SolarMutexGuard aGuard;
@@ -761,12 +761,12 @@ bool 
ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
         if(aDialogParameter.HasSymbolProperties())
         {
             uno::Reference< beans::XPropertySet > xObjectProperties =
-                ObjectIdentifier::getObjectPropertySet( rObjectCID, getModel() 
);
-            wrapper::DataPointItemConverter aSymbolItemConverter( getModel(), 
m_xCC
-                                        , xObjectProperties, 
ObjectIdentifier::getDataSeriesForCID( rObjectCID, getModel() )
+                ObjectIdentifier::getObjectPropertySet( rObjectCID, 
uno::Reference<chart2::XChartDocument>(getChartModel()) );
+            wrapper::DataPointItemConverter aSymbolItemConverter( 
getChartModel(), m_xCC
+                                        , xObjectProperties, 
ObjectIdentifier::getDataSeriesForCID( rObjectCID, getChartModel() )
                                         , 
m_pDrawModelWrapper->getSdrModel().GetItemPool()
                                         , m_pDrawModelWrapper->getSdrModel()
-                                        , uno::Reference< 
lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )
+                                        , getChartModel()
                                         , 
wrapper::GraphicObjectType::FilledDataPoint );
 
             SfxItemSet 
aSymbolShapeProperties(aSymbolItemConverter.CreateEmptyItemSet() );
@@ -780,7 +780,7 @@ bool 
ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
         if( aDialogParameter.HasStatisticProperties() )
         {
             aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
-                
InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), 
m_xChartView, rObjectCID ) );
+                
InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( 
getChartModel(), m_xChartView, rObjectCID ) );
         }
 
         //open the dialog
@@ -789,7 +789,7 @@ bool 
ChartController::executeDlg_ObjectProperties_withoutUndoGuard(
             const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
             if(pOutItemSet)
             {
-                ControllerLockGuardUNO aCLGuard( getModel());
+                ControllerLockGuardUNO aCLGuard( getChartModel());
                 (void)pItemConverter->ApplyItemSet(*pOutItemSet); //model 
should be changed now
                 bRet = true;
             }
@@ -814,7 +814,7 @@ void ChartController::executeDispatch_View3D()
 
         //open dialog
         SolarMutexGuard aSolarGuard;
-        View3DDialog aDlg(GetChartFrame(), getModel());
+        View3DDialog aDlg(GetChartFrame(), getChartModel());
         if (aDlg.run() == RET_OK)
             aUndoGuard.commit();
     }
diff --git a/chart2/source/controller/main/ChartController_TextEdit.cxx 
b/chart2/source/controller/main/ChartController_TextEdit.cxx
index f2aa1b5db47f..adc7b3cb0dda 100644
--- a/chart2/source/controller/main/ChartController_TextEdit.cxx
+++ b/chart2/source/controller/main/ChartController_TextEdit.cxx
@@ -23,6 +23,7 @@
 #include "UndoGuard.hxx"
 #include <DrawViewWrapper.hxx>
 #include <ChartWindow.hxx>
+#include <ChartModel.hxx>
 #include <TitleHelper.hxx>
 #include <ObjectIdentifier.hxx>
 #include <ControllerLockGuard.hxx>
@@ -135,10 +136,10 @@ bool ChartController::EndTextEdit()
     if ( !aObjectCID.isEmpty() )
     {
         uno::Reference< beans::XPropertySet > xPropSet =
-            ObjectIdentifier::getObjectPropertySet( aObjectCID, getModel() );
+            ObjectIdentifier::getObjectPropertySet( aObjectCID, 
uno::Reference<chart2::XChartDocument>(getChartModel()) );
 
         // lock controllers till end of block
-        ControllerLockGuardUNO aCLGuard( getModel() );
+        ControllerLockGuardUNO aCLGuard( getChartModel() );
 
         TitleHelper::setCompleteString( aString, uno::Reference<
             css::chart2::XTitle >::query( xPropSet ), m_xCC );
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx 
b/chart2/source/controller/main/ChartController_Tools.cxx
index 7f86b0aaa799..2ba1c61bda3d 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -92,16 +92,15 @@ namespace
 
 bool lcl_deleteDataSeries(
     const OUString & rCID,
-    const Reference< frame::XModel > & xModel,
+    const rtl::Reference<::chart::ChartModel> & xModel,
     const Reference< document::XUndoManager > & xUndoManager )
 {
     bool bResult = false;
     uno::Reference< chart2::XDataSeries > xSeries( 
ObjectIdentifier::getDataSeriesForCID( rCID, xModel ));
-    uno::Reference< chart2::XChartDocument > xChartDoc( xModel, uno::UNO_QUERY 
);
-    if( xSeries.is() && xChartDoc.is())
+    if( xSeries.is() && xModel.is())
     {
         uno::Reference< chart2::XChartType > xChartType(
-            DataSeriesHelper::getChartTypeOfSeries( xSeries, 
xChartDoc->getFirstDiagram()));
+            DataSeriesHelper::getChartTypeOfSeries( xSeries, 
xModel->getFirstDiagram()));
         if( xChartType.is())
         {
             UndoGuard aUndoGuard(
@@ -109,7 +108,7 @@ bool lcl_deleteDataSeries(
                     ActionDescriptionProvider::ActionType::Delete, SchResId( 
STR_OBJECT_DATASERIES )),
                 xUndoManager );
 
-            Reference< chart2::XDiagram > xDiagram( 
ChartModelHelper::findDiagram( xModel ) );
+            Reference< chart2::XDiagram > xDiagram( 
ChartModelHelper::findDiagram( uno::Reference<chart2::XChartDocument>(xModel) ) 
);
             uno::Reference< chart2::XAxis > xAxis( 
DiagramHelper::getAttachedAxis( xSeries, xDiagram ) );
 
             DataSeriesHelper::deleteSeries( xSeries, xChartType );
@@ -125,13 +124,13 @@ bool lcl_deleteDataSeries(
 
 bool lcl_deleteDataCurve(
     const OUString & rCID,
-    const Reference< frame::XModel > & xModel,
+    const rtl::Reference<::chart::ChartModel> & xModel,
     const Reference< document::XUndoManager > & xUndoManager )
 {
     bool bResult = false;
 
     uno::Reference< beans::XPropertySet > xProperties(
-        ObjectIdentifier::getObjectPropertySet( rCID, xModel));
+        ObjectIdentifier::getObjectPropertySet( rCID, 
uno::Reference<chart2::XChartDocument>(xModel)));
 
     uno::Reference< chart2::XRegressionCurve > xRegressionCurve( xProperties, 
uno::UNO_QUERY );
 
@@ -139,7 +138,7 @@ bool lcl_deleteDataCurve(
     {
         uno::Reference< chart2::XRegressionCurveContainer > 
xRegressionCurveContainer(
             ObjectIdentifier::getObjectPropertySet(
-                ObjectIdentifier::getFullParentParticle( rCID ), xModel), 
uno::UNO_QUERY );
+                ObjectIdentifier::getFullParentParticle( rCID ), 
uno::Reference<chart2::XChartDocument>(xModel)), uno::UNO_QUERY );
 
         if( xRegressionCurveContainer.is())
         {
@@ -161,10 +160,9 @@ bool lcl_deleteDataCurve(
 
 std::unique_ptr<ReferenceSizeProvider> 
ChartController::impl_createReferenceSizeProvider()
 {
-    awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
+    awt::Size aPageSize( ChartModelHelper::getPageSize( getChartModel() ) );
 
-    return std::make_unique<ReferenceSizeProvider>(
-        aPageSize, Reference<chart2::XChartDocument>(getModel(), 
uno::UNO_QUERY));
+    return std::make_unique<ReferenceSizeProvider>(aPageSize, getChartModel());
 }
 
 void ChartController::impl_adaptDataSeriesAutoResize()
@@ -181,8 +179,8 @@ void ChartController::executeDispatch_NewArrangement()
 
     try
     {
-        Reference< frame::XModel > xModel( getModel() );
-        Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( 
xModel ));
+        rtl::Reference<::chart::ChartModel> xModel( getChartModel() );
+        Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(xModel) ));
         if( xDiagram.is())
         {
             UndoGuard aUndoGuard(
@@ -243,7 +241,7 @@ void ChartController::executeDispatch_ScaleText()
     UndoGuard aUndoGuard(
         SchResId( STR_ACTION_SCALE_TEXT ),
         m_xUndoManager );
-    ControllerLockGuardUNO aCtlLockGuard( getModel() );
+    ControllerLockGuardUNO aCtlLockGuard( getChartModel() );
 
     std::unique_ptr<ReferenceSizeProvider> 
pRefSizeProv(impl_createReferenceSizeProvider());
     OSL_ASSERT(pRefSizeProv);
@@ -607,7 +605,7 @@ bool ChartController::executeDispatch_Delete()
                         ActionDescriptionProvider::ActionType::Delete, 
SchResId( STR_OBJECT_TITLE )),
                     m_xUndoManager );
                 TitleHelper::removeTitle(
-                    ObjectIdentifier::getTitleTypeForCID( aCID ), getModel() );
+                    ObjectIdentifier::getTitleTypeForCID( aCID ), 
getChartModel() );
                 bReturn = true;
                 aUndoGuard.commit();
                 break;
@@ -633,7 +631,7 @@ bool ChartController::executeDispatch_Delete()
             }
 
             case OBJECTTYPE_DATA_SERIES:
-                bReturn = lcl_deleteDataSeries( aCID, getModel(), 
m_xUndoManager );
+                bReturn = lcl_deleteDataSeries( aCID, getChartModel(), 
m_xUndoManager );
                 break;
 
             case OBJECTTYPE_LEGEND_ENTRY:
@@ -642,14 +640,14 @@ bool ChartController::executeDispatch_Delete()
                     ObjectIdentifier::getFullParentParticle( aCID ));
                 if( eParentObjectType == OBJECTTYPE_DATA_SERIES )
                 {
-                    bReturn = lcl_deleteDataSeries( aCID, getModel(), 
m_xUndoManager );
+                    bReturn = lcl_deleteDataSeries( aCID, getChartModel(), 
m_xUndoManager );
                 }
                 else if( eParentObjectType == OBJECTTYPE_DATA_CURVE )
                 {
                     sal_Int32 nEndPos = aCID.lastIndexOf(':');
                     OUString aParentCID = aCID.copy(0, nEndPos);
 
-                    bReturn = lcl_deleteDataCurve(aParentCID, getModel(), 
m_xUndoManager );
+                    bReturn = lcl_deleteDataCurve(aParentCID, getChartModel(), 
m_xUndoManager );
                 }
                 else if( eParentObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
                 {
@@ -663,7 +661,7 @@ bool ChartController::executeDispatch_Delete()
             {
                 uno::Reference< chart2::XRegressionCurveContainer > 
xRegCurveCnt(
                     ObjectIdentifier::getObjectPropertySet(
-                        ObjectIdentifier::getFullParentParticle( aCID ), 
getModel()), uno::UNO_QUERY );
+                        ObjectIdentifier::getFullParentParticle( aCID ), 
uno::Reference<chart2::XChartDocument>(getChartModel())), uno::UNO_QUERY );
                 if( xRegCurveCnt.is())
                 {
                     UndoGuard aUndoGuard(
@@ -679,18 +677,18 @@ bool ChartController::executeDispatch_Delete()
 
             case OBJECTTYPE_DATA_CURVE:
             {
-                bReturn = lcl_deleteDataCurve( aCID, getModel(), 
m_xUndoManager );
+                bReturn = lcl_deleteDataCurve( aCID, getChartModel(), 
m_xUndoManager );
             }
             break;
 
             case OBJECTTYPE_DATA_CURVE_EQUATION:
             {
                 uno::Reference< beans::XPropertySet > xEqProp(
-                    ObjectIdentifier::getObjectPropertySet( aCID, getModel()));
+                    ObjectIdentifier::getObjectPropertySet( aCID, 
uno::Reference<chart2::XChartDocument>(getChartModel())));
 
                 if( xEqProp.is())
                 {
-                    uno::Reference< frame::XModel > xModel( getModel() );
+                    rtl::Reference<::chart::ChartModel> xModel( 
getChartModel() );
                     UndoGuard aUndoGuard(
                         ActionDescriptionProvider::createDescription(
                             ActionDescriptionProvider::ActionType::Delete, 
SchResId( STR_OBJECT_CURVE_EQUATION )),
@@ -713,7 +711,7 @@ bool ChartController::executeDispatch_Delete()
             case OBJECTTYPE_DATA_ERRORS_Z:
             {
                 uno::Reference< beans::XPropertySet > xErrorBarProp(
-                    ObjectIdentifier::getObjectPropertySet( aCID, getModel() 
));
+                    ObjectIdentifier::getObjectPropertySet( aCID, 
uno::Reference<chart2::XChartDocument>(getChartModel()) ));
                 if( xErrorBarProp.is())
                 {
                     TranslateId pId;
@@ -725,7 +723,7 @@ bool ChartController::executeDispatch_Delete()
                     else
                         pId = STR_OBJECT_ERROR_BARS_Z;
 
-                    uno::Reference< frame::XModel > xModel( getModel() );
+                    rtl::Reference<::chart::ChartModel> xModel( 
getChartModel() );
                     UndoGuard aUndoGuard(
                         ActionDescriptionProvider::createDescription(
                             ActionDescriptionProvider::ActionType::Delete, 
SchResId(pId)),
@@ -746,7 +744,7 @@ bool ChartController::executeDispatch_Delete()
             case OBJECTTYPE_DATA_LABEL:
             {
                 uno::Reference< beans::XPropertySet > xObjectProperties =
-                    ObjectIdentifier::getObjectPropertySet( aCID, getModel() );
+                    ObjectIdentifier::getObjectPropertySet( aCID, 
uno::Reference<chart2::XChartDocument>(getChartModel()) );
                 if( xObjectProperties.is() )
                 {
                     UndoGuard aUndoGuard(
@@ -764,7 +762,7 @@ bool ChartController::executeDispatch_Delete()
                     aLabel.ShowSeriesName = false;
                     if( aObjectType == OBJECTTYPE_DATA_LABELS )
                     {
-                        uno::Reference< chart2::XDataSeries > xSeries( 
ObjectIdentifier::getDataSeriesForCID( aCID, getModel() ));
+                        uno::Reference< chart2::XDataSeries > xSeries( 
ObjectIdentifier::getDataSeriesForCID( aCID, getChartModel() ));
                         
DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, 
CHART_UNONAME_LABEL, uno::Any(aLabel) );
                         
DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, 
CHART_UNONAME_CUSTOM_LABEL_FIELDS, uno::Any() );
                     }
@@ -858,7 +856,7 @@ void ChartController::executeDispatch_ToggleGridHorizontal()
 {
     UndoGuard aUndoGuard(
         SchResId( STR_ACTION_TOGGLE_GRID_HORZ ), m_xUndoManager );
-    Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( 
getModel() ));
+    Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(getChartModel()) ));
     if( !xDiagram.is())
         return;
 
@@ -891,7 +889,7 @@ void ChartController::executeDispatch_ToggleGridVertical()
 {
     UndoGuard aUndoGuard(
         SchResId( STR_ACTION_TOGGLE_GRID_VERTICAL ), m_xUndoManager );
-    Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( 
getModel() ));
+    Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(getChartModel()) ));
     if( !xDiagram.is())
         return;
 
@@ -925,11 +923,11 @@ void 
ChartController::executeDispatch_FillColor(sal_uInt32 nColor)
     try
     {
         OUString aCID( m_aSelection.getSelectedCID() );
-        const uno::Reference< frame::XModel >& xChartModel = getModel();
+        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
         if( xChartModel.is() )
         {
             Reference< beans::XPropertySet > xPointProperties(
-                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
+                ObjectIdentifier::getObjectPropertySet( aCID, 
uno::Reference<chart2::XChartDocument>(xChartModel) ) );
             if( xPointProperties.is() )
                 xPointProperties->setPropertyValue( "FillColor", uno::Any( 
nColor ) );
         }
@@ -948,12 +946,12 @@ void 
ChartController::executeDispatch_FillGradient(OUString sJSONGradient)
     try
     {
         OUString aCID( m_aSelection.getSelectedCID() );
-        const uno::Reference< frame::XModel >& xChartModel = getModel();
+        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
 
         if( xChartModel.is() )
         {
             Reference< beans::XPropertySet > xPropSet(
-                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
+                ObjectIdentifier::getObjectPropertySet( aCID, 
uno::Reference<chart2::XChartDocument>(xChartModel) ) );
 
             if( xPropSet.is() )
             {
@@ -962,7 +960,7 @@ void ChartController::executeDispatch_FillGradient(OUString 
sJSONGradient)
                                 + 
OUString::number(static_cast<sal_Int32>(aXGradient.GetAngle().get()));
 
                 OUString aNewName = 
PropertyHelper::addGradientUniqueNameToTable(css::uno::Any(aGradient),
-                                        
css::uno::Reference<css::lang::XMultiServiceFactory>(xChartModel, 
css::uno::UNO_QUERY_THROW),
+                                        xChartModel,
                                         aPrefferedName);
 
                 xPropSet->setPropertyValue("FillGradientName", 
css::uno::Any(aNewName));
@@ -980,11 +978,11 @@ void 
ChartController::executeDispatch_LineColor(sal_uInt32 nColor)
     try
     {
         OUString aCID( m_aSelection.getSelectedCID() );
-        const uno::Reference< frame::XModel >& xChartModel = getModel();
+        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
         if( xChartModel.is() )
         {
             Reference< beans::XPropertySet > xPropSet(
-                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
+                ObjectIdentifier::getObjectPropertySet( aCID, 
uno::Reference<chart2::XChartDocument>(xChartModel) ) );
 
             ObjectType eType = ObjectIdentifier::getObjectType(aCID);
             if (eType == OBJECTTYPE_DIAGRAM)
@@ -1010,11 +1008,11 @@ void 
ChartController::executeDispatch_LineWidth(sal_uInt32 nWidth)
     try
     {
         OUString aCID( m_aSelection.getSelectedCID() );
-        const uno::Reference< frame::XModel >& xChartModel = getModel();
+        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
         if( xChartModel.is() )
         {
             Reference< beans::XPropertySet > xPropSet(
-                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
+                ObjectIdentifier::getObjectPropertySet( aCID, 
uno::Reference<chart2::XChartDocument>(xChartModel) ) );
 
             ObjectType eType = ObjectIdentifier::getObjectType(aCID);
             if (eType == OBJECTTYPE_DIAGRAM)
@@ -1071,11 +1069,11 @@ void 
ChartController::executeDispatch_LOKPieSegmentDragging( int nOffset )
     try
     {
         OUString aCID( m_aSelection.getSelectedCID() );
-        const uno::Reference< frame::XModel >& xChartModel = getModel();
+        rtl::Reference<::chart::ChartModel> xChartModel = getChartModel();
         if( xChartModel.is() )
         {
             Reference< beans::XPropertySet > xPointProperties(
-                ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ) );
+                ObjectIdentifier::getObjectPropertySet( aCID, 
uno::Reference<chart2::XChartDocument>(xChartModel) ) );
             if( xPointProperties.is() )
                 xPointProperties->setPropertyValue( "Offset", uno::Any( 
nOffset / 100.0 ) );
         }
diff --git a/chart2/source/controller/main/ChartController_Window.cxx 
b/chart2/source/controller/main/ChartController_Window.cxx
index 76ccba722e54..24f5255ad380 100644
--- a/chart2/source/controller/main/ChartController_Window.cxx
+++ b/chart2/source/controller/main/ChartController_Window.cxx
@@ -250,7 +250,7 @@ void SAL_CALL ChartController::setPosSize(
 
     //todo: for standalone chart: detect whether we are standalone
     //change map mode to fit new size
-    awt::Size aModelPageSize = ChartModelHelper::getPageSize( getModel() );
+    awt::Size aModelPageSize = ChartModelHelper::getPageSize( getChartModel() 
);
     sal_Int32 nScaleXNumerator = aLogicSize.Width();
     sal_Int32 nScaleXDenominator = aModelPageSize.Width;
     sal_Int32 nScaleYNumerator = aLogicSize.Height();
@@ -666,7 +666,7 @@ void ChartController::execute_MouseButtonDown( const 
MouseEvent& rMEvt )
                         rMEvt.IsRight(),
                         m_bWaitingForDoubleClick );
 
-        if( !m_aSelection.isRotateableObjectSelected( getModel() ) )
+        if( !m_aSelection.isRotateableObjectSelected( getChartModel() ) )
         {
                 m_eDragMode = SdrDragMode::Move;
                 pDrawViewWrapper->SetDragMode(m_eDragMode);
@@ -699,14 +699,14 @@ void ChartController::execute_MouseButtonDown( const 
MouseEvent& rMEvt )
                     else if( eKind==SdrHdlKind::UpperLeft || 
eKind==SdrHdlKind::UpperRight || eKind==SdrHdlKind::LowerLeft || 
eKind==SdrHdlKind::LowerRight )
                         eRotationDirection = 
DragMethod_RotateDiagram::ROTATIONDIRECTION_Z;
                 }
-                pDragMethod = new DragMethod_RotateDiagram( *pDrawViewWrapper, 
m_aSelection.getSelectedCID(), getModel(), eRotationDirection );
+                pDragMethod = new DragMethod_RotateDiagram( *pDrawViewWrapper, 
m_aSelection.getSelectedCID(), getChartModel(), eRotationDirection );
             }
         }
         else
         {
             OUString aDragMethodServiceName( 
ObjectIdentifier::getDragMethodServiceName( m_aSelection.getSelectedCID() ) );
             if( aDragMethodServiceName == 
ObjectIdentifier::getPieSegmentDragMethodServiceName() )
-                pDragMethod = new DragMethod_PieSegment( *pDrawViewWrapper, 
m_aSelection.getSelectedCID(), getModel() );
+                pDragMethod = new DragMethod_PieSegment( *pDrawViewWrapper, 
m_aSelection.getSelectedCID(), getChartModel() );
         }
         pDrawViewWrapper->SdrView::BegDragObj(aMPos, nullptr, 
pHitSelectionHdl, nDrgLog, pDragMethod);
     }
@@ -739,7 +739,7 @@ void ChartController::execute_MouseMove( const MouseEvent& 
rMEvt )
 
 void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt )
 {
-    ControllerLockGuardUNO aCLGuard( getModel() );
+    ControllerLockGuardUNO aCLGuard( getChartModel() );
     bool bMouseUpWithoutMouseDown = !m_bWaitingForMouseUp;
     m_bWaitingForMouseUp = false;
     bool bNotifySelectionChange = false;
@@ -839,7 +839,7 @@ void ChartController::execute_MouseButtonUp( const 
MouseEvent& rMEvt )
                     {
                         tools::Rectangle aObjectRect = pObj->GetSnapRect();
                         tools::Rectangle aOldObjectRect = 
pObj->GetLastBoundRect();
-                        awt::Size aPageSize( ChartModelHelper::getPageSize( 
getModel() ) );
+                        awt::Size aPageSize( ChartModelHelper::getPageSize( 
getChartModel() ) );
                         tools::Rectangle aPageRect( 
0,0,aPageSize.Width,aPageSize.Height );
 
                         const E3dObject* pE3dObject(dynamic_cast< const 
E3dObject*>(pObj));
@@ -870,7 +870,7 @@ void ChartController::execute_MouseButtonUp( const 
MouseEvent& rMEvt )
                             bChanged = 
DiagramHelper::switchDiagramPositioningToExcludingPositioning( *pModel, false , 
true );
 
                         bool bMoved = PositionAndSizeHelper::moveObject( 
m_aSelection.getSelectedCID()
-                                        , getModel()
+                                        , getChartModel()
                                         , 
awt::Rectangle(aObjectRect.Left(),aObjectRect.Top(),aObjectRect.getWidth(),aObjectRect.getHeight())
                                         , 
awt::Rectangle(aOldObjectRect.Left(), aOldObjectRect.Top(), 0, 0)
                                         , 
awt::Rectangle(aPageRect.Left(),aPageRect.Top(),aPageRect.getWidth(),aPageRect.getHeight())
 );
@@ -893,7 +893,7 @@ void ChartController::execute_MouseButtonUp( const 
MouseEvent& rMEvt )
             if( !bDraggingDone ) //mouse wasn't moved while dragging
             {
                 bool bClickedTwiceOnDragableObject = 
SelectionHelper::isDragableObjectHitTwice( aMPos, 
m_aSelection.getSelectedCID(), *pDrawViewWrapper );
-                bool bIsRotateable = m_aSelection.isRotateableObjectSelected( 
getModel() );
+                bool bIsRotateable = m_aSelection.isRotateableObjectSelected( 
getChartModel() );
 
                 //toggle between move and rotate
                 if( bIsRotateable && bClickedTwiceOnDragableObject && 
m_eDragMode==SdrDragMode::Move )
@@ -1031,7 +1031,7 @@ void ChartController::execute_Command( const 
CommandEvent& rCEvt )
                 xPopupMenu->insertSeparator( -1 );
 
                 ObjectType eObjectType = ObjectIdentifier::getObjectType( 
m_aSelection.getSelectedCID() );
-                Reference< XDiagram > xDiagram = 
ChartModelHelper::findDiagram( getModel() );
+                Reference< XDiagram > xDiagram = 
ChartModelHelper::findDiagram( 
uno::Reference<chart2::XChartDocument>(getChartModel()) );
 
                 OUString aFormatCommand( lcl_getFormatCommandForObjectCID( 
m_aSelection.getSelectedCID() ) );
                 lcl_insertMenuCommand( xPopupMenu, nUniqueId++, aFormatCommand 
);
@@ -1041,7 +1041,7 @@ void ChartController::execute_Command( const 
CommandEvent& rCEvt )
                 if( eObjectType == OBJECTTYPE_DATA_SERIES || eObjectType == 
OBJECTTYPE_DATA_POINT )
                 {
                     bool bIsPoint = ( eObjectType == OBJECTTYPE_DATA_POINT );
-                    uno::Reference< XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getModel() );
+                    uno::Reference< XDataSeries > xSeries = 
ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), 
getChartModel() );
                     uno::Reference< chart2::XRegressionCurveContainer > 
xCurveCnt( xSeries, uno::UNO_QUERY );
                     Reference< chart2::XRegressionCurve > xTrendline( 
RegressionCurveHelper::getFirstCurveNotMeanValueLine( xCurveCnt ) );
                     bool bHasEquation = RegressionCurveHelper::hasEquation( 
xTrendline );
@@ -1197,7 +1197,7 @@ void ChartController::execute_Command( const 
CommandEvent& rCEvt )
 
                 else if( eObjectType  == OBJECTTYPE_AXIS || eObjectType == 
OBJECTTYPE_GRID || eObjectType == OBJECTTYPE_SUBGRID )
                 {
-                    Reference< XAxis > xAxis = 
ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
+                    Reference< XAxis > xAxis = 
ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() 
);
                     if( xAxis.is() && xDiagram.is() )
                     {
                         sal_Int32 nDimensionIndex = -1;
@@ -1382,7 +1382,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& 
rKEvt )
     if( ! bReturn )
     {
         // Navigation (Tab/F3/Home/End)
-        uno::Reference< XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY 
);
+        rtl::Reference<::chart::ChartModel> xChartDoc( getChartModel() );
         ObjectKeyNavigation aObjNav( m_aSelection.getSelectedOID(), xChartDoc, 
comphelper::getFromUnoTunnel<ExplicitValueProvider>( m_xChartView ));
         awt::KeyEvent aKeyEvent( ::svt::AcceleratorExecute::st_VCLKey2AWTKey( 
aKeyCode ));
         bReturn = aObjNav.handleKeyEvent( aKeyEvent );
@@ -1394,7 +1394,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& 
rKEvt )
             {
                 aNewSelection = aNewOID.getAny();
             }
-            if ( m_eDragMode == SdrDragMode::Rotate && 
!SelectionHelper::isRotateableObject( aNewOID.getObjectCID(), getModel() ) )
+            if ( m_eDragMode == SdrDragMode::Rotate && 
!SelectionHelper::isRotateableObject( aNewOID.getObjectCID(), getChartModel() ) 
)
             {
                 m_eDragMode = SdrDragMode::Move;
             }
@@ -1522,7 +1522,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& 
rKEvt )
                             if (pObj)
                             {
                                 tools::Rectangle aRect = pObj->GetSnapRect();
-                                awt::Size 
aPageSize(ChartModelHelper::getPageSize(getModel()));
+                                awt::Size 
aPageSize(ChartModelHelper::getPageSize(getChartModel()));
                                 if ((fShiftAmountX > 0.0 && (aRect.Right() + 
fShiftAmountX > aPageSize.Width)) ||
                                     (fShiftAmountX < 0.0 && (aRect.Left() + 
fShiftAmountX < 0)) ||
                                     (fShiftAmountY > 0.0 && (aRect.Bottom() + 
fShiftAmountY > aPageSize.Height)) ||
@@ -1530,7 +1530,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& 
rKEvt )
                                     bReturn = false;
                                 else
                                     bReturn = 
PositionAndSizeHelper::moveObject(
-                                        m_aSelection.getSelectedCID(), 
getModel(),
+                                        m_aSelection.getSelectedCID(), 
getChartModel(),
                                         awt::Rectangle(aRect.Left() + 
fShiftAmountX, aRect.Top() + fShiftAmountY, aRect.getWidth(), 
aRect.getHeight()),
                                         awt::Rectangle(aRect.Left(), 
aRect.Top(), 0, 0),
                                         awt::Rectangle(0, 0, aPageSize.Width, 
aPageSize.Height));
@@ -1548,7 +1548,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& 
rKEvt )
                         {
                             awt::Point aPos( xShape->getPosition() );
                             awt::Size aSize( xShape->getSize() );
-                            awt::Size aPageSize( 
ChartModelHelper::getPageSize( getModel() ) );
+                            awt::Size aPageSize( 
ChartModelHelper::getPageSize( getChartModel() ) );
                             aPos.X = static_cast< tools::Long >( static_cast< 
double >( aPos.X ) + fShiftAmountX );
                             aPos.Y = static_cast< tools::Long >( static_cast< 
double >( aPos.Y ) + fShiftAmountY );
                             if( aPos.X + aSize.Width > aPageSize.Width )
@@ -1628,9 +1628,9 @@ bool ChartController::requestQuickHelp(
     OUString & rOutQuickHelpText,
     awt::Rectangle & rOutEqualRect )
 {
-    uno::Reference< frame::XModel > xChartModel;
+    rtl::Reference<::chart::ChartModel> xChartModel;
     if( m_aModel.is())
-        xChartModel.set( getModel() );
+        xChartModel = getChartModel();
     if( !xChartModel.is())
         return false;
 
@@ -1789,9 +1789,9 @@ bool ChartController::impl_moveOrResizeObject(
     bool bResult = false;
     bool bNeedResize = ( eType == CENTERED_RESIZE_OBJECT );
 
-    uno::Reference< frame::XModel > xChartModel( getModel() );
+    rtl::Reference<::chart::ChartModel> xChartModel( getChartModel() );
     uno::Reference< beans::XPropertySet > xObjProp(
-        ObjectIdentifier::getObjectPropertySet( rCID, xChartModel ));
+        ObjectIdentifier::getObjectPropertySet( rCID, 
uno::Reference<chart2::XChartDocument>(xChartModel) ));
     if( xObjProp.is())
     {
         awt::Size aRefSize = ChartModelHelper::getPageSize( xChartModel );
@@ -1870,7 +1870,7 @@ bool ChartController::impl_DragDataPoint( const OUString 
& rCID, double fAdditio
 
     sal_Int32 nDataPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( 
rCID );
     uno::Reference< chart2::XDataSeries > xSeries(
-        ObjectIdentifier::getDataSeriesForCID( rCID, getModel() ));
+        ObjectIdentifier::getDataSeriesForCID( rCID, getChartModel() ));
     if( xSeries.is())
     {
         try
@@ -2051,7 +2051,7 @@ void ChartController::impl_SetMousePointer( const 
MouseEvent & rEvent )
     {
         if( (m_eDragMode == SdrDragMode::Rotate)
             && SelectionHelper::isRotateableObject( aHitObjectCID
-                , getModel() ) )
+                , getChartModel() ) )
             pChartWindow->SetPointer( PointerStyle::Rotate );
         else
         {
@@ -2079,7 +2079,7 @@ css::uno::Reference<css::uno::XInterface> const & 
ChartController::getChartView(
 
 void ChartController::sendPopupRequest(OUString const & rCID, tools::Rectangle 
aRectangle)
 {
-    ChartModel* pChartModel = 
dynamic_cast<ChartModel*>(m_aModel->getModel().get());
+    ChartModel* pChartModel = m_aModel->getModel().get();
     if (!pChartModel)
         return;
 
diff --git a/chart2/source/controller/main/ChartDropTargetHelper.cxx 
b/chart2/source/controller/main/ChartDropTargetHelper.cxx
index 15272dfc5963..ceb599569e16 100644
--- a/chart2/source/controller/main/ChartDropTargetHelper.cxx
+++ b/chart2/source/controller/main/ChartDropTargetHelper.cxx
@@ -19,6 +19,7 @@
 
 #include "ChartDropTargetHelper.hxx"
 #include <DataSourceHelper.hxx>
+#include <ChartModel.hxx>
 
 #include <com/sun/star/chart2/XChartDocument.hpp>
 #include <com/sun/star/chart2/data/XDataProvider.hpp>
@@ -60,7 +61,7 @@ namespace chart
 
 ChartDropTargetHelper::ChartDropTargetHelper(
     const Reference< datatransfer::dnd::XDropTarget >& rxDropTarget,
-    const Reference< chart2::XChartDocument > & xChartDocument ) :
+    const rtl::Reference<::chart::ChartModel> & xChartDocument ) :
         DropTargetHelper( rxDropTarget ),
         m_xChartDocument( xChartDocument )
 {}
@@ -109,10 +110,9 @@ sal_Int8 ChartDropTargetHelper::ExecuteDrop( const 
ExecuteDropEvent& rEvt )
                 if( aStrings.size() >= 3 && aStrings[0] == "soffice" )
                 {
                     OUString aRangeString( aStrings[2] );
-                    Reference< container::XChild > xChild( m_xChartDocument, 
uno::UNO_QUERY );
-                    if( xChild.is())
+                    if( m_xChartDocument.is())
                     {
-                        Reference< frame::XModel > xParentModel( 
xChild->getParent(), uno::UNO_QUERY );
+                        Reference< frame::XModel > xParentModel( 
m_xChartDocument->getParent(), uno::UNO_QUERY );
                         if( xParentModel.is() &&
                             m_xChartDocument.is())
                         {
diff --git a/chart2/source/controller/main/ChartDropTargetHelper.hxx 
b/chart2/source/controller/main/ChartDropTargetHelper.hxx
index 84c8dfe98f45..4955d6eaea43 100644
--- a/chart2/source/controller/main/ChartDropTargetHelper.hxx
+++ b/chart2/source/controller/main/ChartDropTargetHelper.hxx
@@ -19,6 +19,7 @@
 #pragma once
 
 #include <vcl/transfer.hxx>
+#include <rtl/ref.hxx>
 
 namespace com::sun::star {
     namespace chart2 {
@@ -28,6 +29,7 @@ namespace com::sun::star {
 
 namespace chart
 {
+class ChartModel;
 
 class ChartDropTargetHelper : public DropTargetHelper
 {
@@ -35,7 +37,7 @@ public:
     ChartDropTargetHelper() = delete;
     explicit ChartDropTargetHelper(
         const css::uno::Reference< css::datatransfer::dnd::XDropTarget >& 
rxDropTarget,
-        const css::uno::Reference< css::chart2::XChartDocument > & 
xChartDocument );
+        const rtl::Reference<::chart::ChartModel> & xChartDocument );
     virtual ~ChartDropTargetHelper() override;
 
 protected:
@@ -46,7 +48,7 @@ protected:
 private:
     bool satisfiesPrerequisites() const;
 
-    css::uno::Reference< css::chart2::XChartDocument > m_xChartDocument;
+    rtl::Reference<::chart::ChartModel> m_xChartDocument;
 };
 
 } //  namespace chart
diff --git a/chart2/source/controller/main/ChartModelClone.cxx 
b/chart2/source/controller/main/ChartModelClone.cxx
index 6348aee6e6f9..dfb089d566e8 100644
--- a/chart2/source/controller/main/ChartModelClone.cxx
+++ b/chart2/source/controller/main/ChartModelClone.cxx
@@ -60,36 +60,33 @@ namespace chart
     // = helper
     namespace
     {
-        Reference< XModel > lcl_cloneModel( const Reference< XModel > & xModel 
)
+        rtl::Reference<::chart::ChartModel> lcl_cloneModel( const 
rtl::Reference<::chart::ChartModel> & xModel )
         {
-            Reference< XModel > xResult;
             try
             {
-                const Reference< XCloneable > xCloneable( xModel, 
UNO_QUERY_THROW );
-                xResult.set( xCloneable->createClone(), UNO_QUERY_THROW );
+                return new ChartModel(*xModel);
             }
             catch( const Exception& )
             {
                 DBG_UNHANDLED_EXCEPTION("chart2");
             }
-            return xResult;
+            return nullptr;
         }
 
     }
 
     // = ChartModelClone
-    ChartModelClone::ChartModelClone( const Reference< XModel >& i_model, 
const ModelFacet i_facet )
+    ChartModelClone::ChartModelClone( const 
rtl::Reference<::chart::ChartModel>& i_model, const ModelFacet i_facet )
     {
-        m_xModelClone.set( lcl_cloneModel( i_model ) );
+        m_xModelClone = lcl_cloneModel( i_model );
 
         try
         {
             if ( i_facet == E_MODEL_WITH_DATA )
             {
-                const Reference< XChartDocument > xChartDoc( m_xModelClone, 
UNO_QUERY_THROW );
-                ENSURE_OR_THROW( xChartDoc->hasInternalDataProvider(), 
"invalid chart model" );
+                ENSURE_OR_THROW( m_xModelClone && 
m_xModelClone->hasInternalDataProvider(), "invalid chart model" );
 
-                const Reference< XCloneable > xCloneable( 
xChartDoc->getDataProvider(), UNO_QUERY_THROW );
+                const Reference< XCloneable > xCloneable( 
m_xModelClone->getDataProvider(), UNO_QUERY_THROW );
                 m_xDataClone.set( xCloneable->createClone(), UNO_QUERY_THROW );
             }
 
@@ -116,15 +113,6 @@ namespace chart
         if ( impl_isDisposed() )
             return;
 
-        try
-        {
-            Reference< XComponent > xComp( m_xModelClone, UNO_QUERY_THROW );
-            xComp->dispose();
-        }
-        catch( const Exception& )
-        {
-            DBG_UNHANDLED_EXCEPTION("chart2");
-        }
         m_xModelClone.clear();
         m_xDataClone.clear();
         m_aSelection.clear();
@@ -139,7 +127,7 @@ namespace chart
         return E_MODEL;
     }
 
-    void ChartModelClone::applyToModel( const Reference< XModel >& i_model ) 
const
+    void ChartModelClone::applyToModel( const 
rtl::Reference<::chart::ChartModel>& i_model ) const
     {
         applyModelContentToModel( i_model, m_xModelClone, m_xDataClone );
 
@@ -179,8 +167,9 @@ namespace chart
         }
     }
 
-    void ChartModelClone::applyModelContentToModel( const Reference< XModel >& 
i_model,
-        const Reference< XModel >& i_modelToCopyFrom, const Reference< 
XInternalDataProvider >& i_data )
+    void ChartModelClone::applyModelContentToModel( const 
rtl::Reference<::chart::ChartModel>& i_model,
+        const rtl::Reference<::chart::ChartModel>& i_modelToCopyFrom,
+        const Reference< XInternalDataProvider >& i_data )
     {
         ENSURE_OR_RETURN_VOID( i_model.is(), 
"ChartModelElement::applyModelContentToModel: invalid source model!" );
         ENSURE_OR_RETURN_VOID( i_modelToCopyFrom.is(), 
"ChartModelElement::applyModelContentToModel: invalid source model!" );
@@ -188,25 +177,20 @@ namespace chart
         {
             // locked controllers of destination
             ControllerLockGuardUNO aLockedControllers( i_model );
-            Reference< XChartDocument > xSource( i_modelToCopyFrom, 
UNO_QUERY_THROW );
-            Reference< XChartDocument > xDestination( i_model, UNO_QUERY_THROW 
);
 
             // propagate the correct flag for plotting of hidden values to the 
data provider and all used sequences
-            ChartModel& rModel = dynamic_cast<ChartModel&>(*i_model);
-            
ChartModelHelper::setIncludeHiddenCells(ChartModelHelper::isIncludeHiddenCells( 
i_modelToCopyFrom ), rModel);
+            
ChartModelHelper::setIncludeHiddenCells(ChartModelHelper::isIncludeHiddenCells( 
i_modelToCopyFrom ), *i_model);
 
             // diagram
-            xDestination->setFirstDiagram( xSource->getFirstDiagram() );
+            i_model->setFirstDiagram( i_modelToCopyFrom->getFirstDiagram() );
 
             // main title
-            Reference< XTitled > xDestinationTitled( xDestination, 
UNO_QUERY_THROW );
-            Reference< XTitled > xSourceTitled( xSource, UNO_QUERY_THROW );
-            xDestinationTitled->setTitleObject( 
xSourceTitled->getTitleObject() );
+            i_model->setTitleObject( i_modelToCopyFrom->getTitleObject() );
 
             // page background
             ::comphelper::copyProperties(
-                xSource->getPageBackground(),
-                xDestination->getPageBackground() );

... etc. - the rest is truncated

Reply via email to