chart2/source/inc/DataSeriesHelper.hxx                  |    4 +
 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, 70 insertions(+), 26 deletions(-)

New commits:
commit 4fc1f5963e671ab28ed39f27a9647ec0cfa327ea
Author:     Oliver Specht <[email protected]>
AuthorDate: Wed Jan 22 16:39:25 2025 +0100
Commit:     Thorsten Behrens <[email protected]>
CommitDate: Fri Feb 7 17:39:39 2025 +0100

    tdf#151278 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.
    Also: tdf#164724 tdf#164728 tdf#164729
    
    Change-Id: I98985d7979f449f5f3c6c8faaff2ce97811cc38e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181089
    Tested-by: allotropia jenkins <[email protected]>
    Reviewed-by: Thorsten Behrens <[email protected]>

diff --git a/chart2/source/inc/DataSeriesHelper.hxx 
b/chart2/source/inc/DataSeriesHelper.hxx
index 2015398a7681..d028f4fe7d65 100644
--- a/chart2/source/inc/DataSeriesHelper.hxx
+++ b/chart2/source/inc/DataSeriesHelper.hxx
@@ -185,6 +185,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 da35cf539708..1913b5f5f1ff 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 0f831db3d6c5..98e6e53275b7 100644
--- a/comphelper/source/container/embeddedobjectcontainer.cxx
+++ b/comphelper/source/container/embeddedobjectcontainer.cxx
@@ -485,19 +485,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 );
             }
         }
@@ -511,11 +511,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 0bb1669dd5ef..b26f376ddd9e 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -955,7 +955,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 7ab061cb815a..b906476cf7f9 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -2392,7 +2392,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
@@ -2809,6 +2809,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