chart2/source/inc/DataSeriesHelper.hxx                  |    5 ++
 chart2/source/tools/DataSeriesHelper.cxx                |   39 ++++++++++++++++
 chart2/source/view/main/ExplicitValueProvider.cxx       |   17 ------
 comphelper/source/container/embeddedobjectcontainer.cxx |   19 ++++---
 include/comphelper/embeddedobjectcontainer.hxx          |    3 -
 sw/source/core/ole/ndole.cxx                            |    5 +-
 xmloff/source/chart/SchXMLExport.cxx                    |    9 +++
 7 files changed, 71 insertions(+), 26 deletions(-)

New commits:
commit d440b72b336985dabc0ca3e511d88b90dc201b86
Author:     Oliver Specht <oliver.spe...@cib.de>
AuthorDate: Wed Jan 22 16:39:25 2025 +0100
Commit:     Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
CommitDate: Wed Feb 12 17:25:34 2025 +0100

    tdf#151278 tdf#164724 tdf#164728 tdf#164729 switch off charts number format
    
    from source
    
    Labels get their number format usually from source. When copy/pasted
    the chart has no connection to a source format anymore.
    The related LinkNumberFormatToSource flag is therefore reset.
    The label (data series) number format used is now also saved.
    
    Change-Id: I640083ec0036f116dec94cc982317e1e7992328b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180600
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Reviewed-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Tested-by: Jenkins
    (cherry picked from commit e72919a30132cabeb3e3fda2f9ce16688e9f40eb)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181277

diff --git a/chart2/source/inc/DataSeriesHelper.hxx 
b/chart2/source/inc/DataSeriesHelper.hxx
index 2015398a7681..29555c692221 100644
--- a/chart2/source/inc/DataSeriesHelper.hxx
+++ b/chart2/source/inc/DataSeriesHelper.hxx
@@ -43,6 +43,7 @@ namespace chart { class DataSource; }
 namespace chart { class Diagram; }
 namespace chart { class DataSeries; }
 namespace chart { class LabeledDataSequence; }
+namespace chart { class ChartModel; }
 
 namespace chart::DataSeriesHelper
 {
@@ -185,6 +186,10 @@ void deleteDataLabelsFromSeriesAndAllPoints( const 
rtl::Reference< ::chart::Data
 UNLESS_MERGELIBS(OOO_DLLPUBLIC_CHARTTOOLS)
 void deleteDataLabelsFromPoint( const css::uno::Reference< 
css::beans::XPropertySet >& xPointPropertySet );
 
+UNLESS_MERGELIBS(OOO_DLLPUBLIC_CHARTTOOLS)
+sal_Int32 getExplicitNumberFormatKeyForDataLabel(
+    const css::uno::Reference< css::beans::XPropertySet >& xPointPropertySet);
+
 } //  namespace chart::DataSeriesHelper
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/tools/DataSeriesHelper.cxx 
b/chart2/source/tools/DataSeriesHelper.cxx
index 202b67395c83..baba1a530294 100644
--- a/chart2/source/tools/DataSeriesHelper.cxx
+++ b/chart2/source/tools/DataSeriesHelper.cxx
@@ -675,6 +675,45 @@ void deleteDataLabelsFromPoint( const Reference< 
beans::XPropertySet >& xPointPr
     }
 }
 
+sal_Int32 getExplicitNumberFormatKeyForDataLabel(
+    const uno::Reference<beans::XPropertySet>& xSeriesOrPointProp)
+{
+    rtl::Reference< ::chart::DataSeries > xDataSeries( 
dynamic_cast<DataSeries*>(xSeriesOrPointProp.get()) );
+    sal_Int32 nFormat = 0;
+    if (!xDataSeries.is())
+        return nFormat;
+    try
+    {
+
+        bool bLinkToSource = true;
+        xDataSeries->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= 
bLinkToSource;
+        xDataSeries->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nFormat;
+
+        if (bLinkToSource && xDataSeries->getDataSequences().getLength())
+        {
+            Reference<data::XLabeledDataSequence> xLabeledSeq(
+                xDataSeries->getDataSequences()[0]);
+            if( xLabeledSeq.is() )
+            {
+                Reference< data::XDataSequence > xSeq( 
xLabeledSeq->getValues());
+                if( xSeq.is() )
+                {
+                    nFormat = xSeq->getNumberFormatKeyByIndex( -1 );
+                }
+            }
+
+        }
+    }
+    catch (const beans::UnknownPropertyException&)
+    {
+    }
+
+    if (nFormat < 0)
+        nFormat = 0;
+    return nFormat;
+
+}
+
 } //  namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/ExplicitValueProvider.cxx 
b/chart2/source/view/main/ExplicitValueProvider.cxx
index 5aa8fadcd77d..c34fe64cce65 100644
--- a/chart2/source/view/main/ExplicitValueProvider.cxx
+++ b/chart2/source/view/main/ExplicitValueProvider.cxx
@@ -26,6 +26,7 @@
 #include <BaseCoordinateSystem.hxx>
 #include <TitleHelper.hxx>
 #include <ObjectIdentifier.hxx>
+#include <DataSeriesHelper.hxx>
 
 #include <comphelper/servicehelper.hxx>
 #include <comphelper/diagnose_ex.hxx>
@@ -78,21 +79,7 @@ sal_Int32 
ExplicitValueProvider::getExplicitNumberFormatKeyForAxis(
 sal_Int32 ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
     const uno::Reference<beans::XPropertySet>& xSeriesOrPointProp)
 {
-    sal_Int32 nFormat = 0;
-    if (!xSeriesOrPointProp.is())
-        return nFormat;
-
-    try
-    {
-        xSeriesOrPointProp->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nFormat;
-    }
-    catch (const beans::UnknownPropertyException&)
-    {
-    }
-
-    if (nFormat < 0)
-        nFormat = 0;
-    return nFormat;
+    return 
DataSeriesHelper::getExplicitNumberFormatKeyForDataLabel(xSeriesOrPointProp);
 }
 
 sal_Int32 
ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabel(
diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx 
b/comphelper/source/container/embeddedobjectcontainer.cxx
index 2e5e311e997a..7c01ee23bd92 100644
--- a/comphelper/source/container/embeddedobjectcontainer.cxx
+++ b/comphelper/source/container/embeddedobjectcontainer.cxx
@@ -486,19 +486,19 @@ bool EmbeddedObjectContainer::StoreEmbeddedObject(
         if ( xPersist.is() )
         {
             uno::Sequence < beans::PropertyValue > aSeq;
+            auto aObjArgs(::comphelper::InitPropertySequence({
+                { "SourceShellID", uno::Any(rSrcShellID) },
+                { "DestinationShellID", uno::Any(rDestShellID) }
+            }));
             if ( bCopy )
             {
-                auto aObjArgs(::comphelper::InitPropertySequence({
-                    { "SourceShellID", uno::Any(rSrcShellID) },
-                    { "DestinationShellID", uno::Any(rDestShellID) }
-                }));
                 xPersist->storeToEntry(pImpl->mxStorage, rName, aSeq, 
aObjArgs);
             }
             else
             {
                 //TODO/LATER: possible optimization, don't store immediately
                 //xPersist->setPersistentEntry( pImpl->mxStorage, rName, 
embed::EntryInitModes::ENTRY_NO_INIT, aSeq, aSeq );
-                xPersist->storeAsEntry( pImpl->mxStorage, rName, aSeq, aSeq );
+                xPersist->storeAsEntry( pImpl->mxStorage, rName, aSeq, 
aObjArgs );
                 xPersist->saveCompleted( true );
             }
         }
@@ -512,11 +512,14 @@ bool EmbeddedObjectContainer::StoreEmbeddedObject(
 
     return true;
 }
-
-bool EmbeddedObjectContainer::InsertEmbeddedObject( const uno::Reference < 
embed::XEmbeddedObject >& xObj, OUString& rName )
+bool EmbeddedObjectContainer::InsertEmbeddedObject( const uno::Reference < 
embed::XEmbeddedObject >& xObj, OUString& rName,
+        OUString const* pTargetShellID )
 {
     // store it into the container storage
-    if (StoreEmbeddedObject(xObj, rName, false, OUString(), OUString()))
+    OUString sTargetShellID;
+    if (pTargetShellID)
+        sTargetShellID = *pTargetShellID;
+    if (StoreEmbeddedObject(xObj, rName, false, OUString(), sTargetShellID))
     {
         // remember object
         AddEmbeddedObject( xObj, rName );
diff --git a/include/comphelper/embeddedobjectcontainer.hxx 
b/include/comphelper/embeddedobjectcontainer.hxx
index 8c75718dce35..a847f1e1b55d 100644
--- a/include/comphelper/embeddedobjectcontainer.hxx
+++ b/include/comphelper/embeddedobjectcontainer.hxx
@@ -109,7 +109,8 @@ public:
                         OUString const* pBaseURL = nullptr );
 
     // insert an embedded object into the container - objects persistent 
representation will be added to the storage
-    bool            InsertEmbeddedObject( const css::uno::Reference < 
css::embed::XEmbeddedObject >&, OUString& );
+    bool            InsertEmbeddedObject( const css::uno::Reference < 
css::embed::XEmbeddedObject >&, OUString&,
+        OUString const* pTargetShellID = nullptr);
 
     // load an embedded object from a MediaDescriptor and insert it into the 
container
     // a new object will be created from the new content and returned
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index 26dbd086f8c1..20cef31053a3 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -957,7 +957,10 @@ void SwOLEObj::SetNode( SwOLENode* pNode )
     if ( xChild.is() && xChild->getParent() != p->GetModel() )
         // it is possible that the parent was set already
         xChild->setParent( p->GetModel() );
-    if (!p->GetEmbeddedObjectContainer().InsertEmbeddedObject( 
m_xOLERef.GetObject(), aObjName ) )
+    rtl::OUString sTargetShellID = 
SfxObjectShell::CreateShellID(rDoc.GetDocShell());
+
+    if (!p->GetEmbeddedObjectContainer().InsertEmbeddedObject( 
m_xOLERef.GetObject(), aObjName,
+        &sTargetShellID) )
     {
         OSL_FAIL( "InsertObject failed" );
         if ( xChild.is() )
diff --git a/xmloff/source/chart/SchXMLExport.cxx 
b/xmloff/source/chart/SchXMLExport.cxx
index 91b203bc2d42..198f6a14c4e3 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -2433,7 +2433,7 @@ void SchXMLExportHelper_Impl::exportAxis(
         lcl_exportNumberFormat( u"NumberFormat"_ustr, rAxisProps, mrExport );
         aPropertyStates = mxExpPropMapper->Filter(mrExport, rAxisProps);
 
-        if (!maSrcShellID.isEmpty() && !maDestShellID.isEmpty() && 
maSrcShellID != maDestShellID)
+        if (!maDestShellID.isEmpty() && (!maSrcShellID.isEmpty() || 
maSrcShellID != maDestShellID))
         {
             // Disable link to source number format property when pasting to
             // a different doc shell.  These shell ID's should be both empty
@@ -2850,6 +2850,13 @@ void SchXMLExportHelper_Impl::exportSeries(
 
                                 if( mxExpPropMapper.is())
                                     aPropertyStates = 
mxExpPropMapper->Filter(mrExport, xPropSet);
+                                if (!maDestShellID.isEmpty() && 
(!maSrcShellID.isEmpty() || maSrcShellID != maDestShellID))
+                                {
+                                    // Disable link to source number format 
property when pasting to
+                                    // a different doc shell.  These shell 
ID's should be both empty
+                                    // during real ODF export.
+                                    disableLinkedNumberFormat(aPropertyStates, 
mxExpPropMapper->getPropertySetMapper());
+                                }
                             }
 
                             if( bExportContent )

Reply via email to