chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx |   15 ++++++
 chart2/source/controller/inc/ChartDocumentWrapper.hxx             |    4 +
 chart2/source/inc/ChartViewHelper.hxx                             |   14 +++++-
 chart2/source/tools/ChartViewHelper.cxx                           |   10 +++-
 xmloff/source/chart/SchXMLImport.cxx                              |   22 
+++++++++-
 5 files changed, 58 insertions(+), 7 deletions(-)

New commits:
commit f26bf09a0e93449ea85269a09a8a073a20903349
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Oct 16 15:22:17 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Oct 16 18:27:49 2023 +0200

    tdf#141892: Set chart view to dirty state after loading
    
    Previously, ChartViewHelper::setViewToDirtyState was only called in
    ChartModel::impl_notifyModifiedListeners during the load process of
    inline charts; after commit 574eec9036c5f185b3572ba1e0ca9d111eb361dc,
    the chart doesn't set its modified state when loading, and thus the
    view did not get notified about the necessary updates.
    
    This change introduces a hidden property in ChartDocumentWrapper,
    named 'ODFImport_UpdateView', which is set in SchXMLImport dtor
    to force the notification after the loading.
    
    Change-Id: Id9d82f16d233d2172cd6808a8498822e13b21b21
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158051
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx 
b/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx
index 70c9ace455b9..ea01ae000b65 100644
--- a/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx
+++ b/chart2/source/controller/chartapiwrapper/ChartDocumentWrapper.cxx
@@ -19,6 +19,7 @@
 
 #include <ChartDocumentWrapper.hxx>
 #include <ChartView.hxx>
+#include <ChartViewHelper.hxx>
 #include <ChartTypeManager.hxx>
 #include <ChartTypeTemplate.hxx>
 #include <servicenames.hxx>
@@ -1366,6 +1367,20 @@ void ChartDocumentWrapper::_disposing( const 
lang::EventObject& rSource )
         m_xChartView.clear();
 }
 
+// ____ XPropertySet ____
+void SAL_CALL ChartDocumentWrapper::setPropertyValue(const OUString& 
rPropertyName, const css::uno::Any& rValue)
+{
+    if (rPropertyName == u"ODFImport_UpdateView")
+    {
+        // A hack used at load time to notify the view that it needs an update
+        // See SchXMLImport::~SchXMLImport
+        if (auto xChartModel = rValue.query<css::chart2::XChartDocument>())
+            ChartViewHelper::setViewToDirtyState_UNO(xChartModel);
+        return;
+    }
+    ChartDocumentWrapper_Base::setPropertyValue(rPropertyName, rValue);
+}
+
 // WrappedPropertySet
 Reference< beans::XPropertySet > ChartDocumentWrapper::getInnerPropertySet()
 {
diff --git a/chart2/source/controller/inc/ChartDocumentWrapper.hxx 
b/chart2/source/controller/inc/ChartDocumentWrapper.hxx
index 04f76d705b6b..a5bded3c8fb7 100644
--- a/chart2/source/controller/inc/ChartDocumentWrapper.hxx
+++ b/chart2/source/controller/inc/ChartDocumentWrapper.hxx
@@ -139,6 +139,10 @@ protected:
     virtual std::vector< std::unique_ptr<WrappedProperty> > 
createWrappedProperties() override;
     virtual css::uno::Reference< css::beans::XPropertySet > 
getInnerPropertySet() override;
 
+    // ____ XPropertySet ____
+    virtual void SAL_CALL setPropertyValue(const OUString& rPropertyName,
+                                           const css::uno::Any& rValue) 
override;
+
 private: //methods
     void impl_resetAddIn();
 
diff --git a/chart2/source/inc/ChartViewHelper.hxx 
b/chart2/source/inc/ChartViewHelper.hxx
index 06fef6a1ff9b..be70dd9fecb4 100644
--- a/chart2/source/inc/ChartViewHelper.hxx
+++ b/chart2/source/inc/ChartViewHelper.hxx
@@ -21,14 +21,22 @@
 #include "charttoolsdllapi.hxx"
 #include <rtl/ref.hxx>
 
+#include <com/sun/star/uno/Reference.hxx>
+
+namespace com::sun::star::chart2
+{
+class XChartDocument;
+}
+
 namespace chart
 {
 class ChartModel;
 
-class OOO_DLLPUBLIC_CHARTTOOLS ChartViewHelper
+namespace ChartViewHelper
 {
-public:
-    static void setViewToDirtyState(const rtl::Reference<::chart::ChartModel>& 
xChartModel);
+OOO_DLLPUBLIC_CHARTTOOLS void setViewToDirtyState(const 
rtl::Reference<ChartModel>& xChartModel);
+OOO_DLLPUBLIC_CHARTTOOLS void
+setViewToDirtyState_UNO(const 
css::uno::Reference<css::chart2::XChartDocument>& xChartModel);
 };
 
 } //namespace chart
diff --git a/chart2/source/tools/ChartViewHelper.cxx 
b/chart2/source/tools/ChartViewHelper.cxx
index 183d28189531..8011da3c171c 100644
--- a/chart2/source/tools/ChartViewHelper.cxx
+++ b/chart2/source/tools/ChartViewHelper.cxx
@@ -21,8 +21,7 @@
 #include <ChartModel.hxx>
 #include <servicenames.hxx>
 
-#include <com/sun/star/frame/XModel.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/chart2/XChartDocument.hpp>
 #include <com/sun/star/util/XModifyListener.hpp>
 #include <comphelper/diagnose_ex.hxx>
 
@@ -51,6 +50,13 @@ void ChartViewHelper::setViewToDirtyState(const 
rtl::Reference<::chart::ChartMod
         DBG_UNHANDLED_EXCEPTION("chart2");
     }
 }
+
+void ChartViewHelper::setViewToDirtyState_UNO(
+    const css::uno::Reference<css::chart2::XChartDocument>& xChartModel)
+{
+    if (auto pChartModel = dynamic_cast<ChartModel*>(xChartModel.get()))
+        setViewToDirtyState(rtl::Reference(pChartModel));
+}
 } //namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/chart/SchXMLImport.cxx 
b/xmloff/source/chart/SchXMLImport.cxx
index 945fe62c63e3..52f0ea4207dd 100644
--- a/xmloff/source/chart/SchXMLImport.cxx
+++ b/xmloff/source/chart/SchXMLImport.cxx
@@ -253,8 +253,26 @@ SchXMLImport::SchXMLImport(
 SchXMLImport::~SchXMLImport() noexcept
 {
     uno::Reference< chart2::XChartDocument > xChartDoc( GetModel(), 
uno::UNO_QUERY );
-    if( xChartDoc.is() && xChartDoc->hasControllersLocked() )
-        xChartDoc->unlockControllers();
+    if (xChartDoc.is())
+    {
+        if (xChartDoc->hasControllersLocked())
+            xChartDoc->unlockControllers();
+        if (auto xPropSet = xChartDoc.query<beans::XPropertySet>())
+        {
+            try
+            {
+                // The view of the chart might not received a notification 
about the updates,
+                // which is only sent when the chart model is set modified; 
during the load,
+                // setting modified is disabled. So, the view needs an 
explicit notification.
+                // See ChartDocumentWrapper::setPropertyValue
+                xPropSet->setPropertyValue(u"ODFImport_UpdateView"_ustr, 
css::uno::Any(xChartDoc));
+            }
+            catch (css::beans::UnknownPropertyException&)
+            {
+                // That's absolutely fine!
+            }
+        }
+    }
 }
 
 // create the main context (subcontexts are created

Reply via email to