sc/qa/unit/data/ods/tdf140866.ods |binary sc/qa/unit/scshapetest.cxx | 50 ++++++++++++++++++++++++++++++++++++++ sc/source/core/data/drwlayer.cxx | 4 ++- 3 files changed, 53 insertions(+), 1 deletion(-)
New commits: commit d932a383766b6133ffe9ebf077f95cc328807b1b Author: Balazs Varga <[email protected]> AuthorDate: Fri Sep 26 17:03:06 2025 +0200 Commit: Balazs Varga <[email protected]> CommitDate: Mon Sep 29 11:12:24 2025 +0200 tdf#140866 - sc fix cell comments disappear after ods saving They disappeared because before saving the file to ods some other drawing objects very copied and pasted on the sheet which caused a recalculation of all the cell anchored drawing object's anchor position with SetCellAnchoredFromPosition since commit: 545737df40880875304bffc3f49800d1d2e99723 No need to recalculate the cell anchor position of Caption objects since their anchor position is handled differently. Change-Id: I83d54075974d9a7c2676af23f285e621afe0d523 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191548 Tested-by: Gabor Kelemen <[email protected]> Tested-by: Jenkins Reviewed-by: Balazs Varga <[email protected]> diff --git a/sc/qa/unit/data/ods/tdf140866.ods b/sc/qa/unit/data/ods/tdf140866.ods new file mode 100644 index 000000000000..5b3c73161782 Binary files /dev/null and b/sc/qa/unit/data/ods/tdf140866.ods differ diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx index fbea25178581..7431f13a9f1e 100644 --- a/sc/qa/unit/scshapetest.cxx +++ b/sc/qa/unit/scshapetest.cxx @@ -25,6 +25,7 @@ #include <drwlayer.hxx> #include <fuconcustomshape.hxx> #include <fuconuno.hxx> +#include <postit.hxx> #include <tabvwsh.hxx> #include <userdat.hxx> @@ -78,6 +79,17 @@ static SdrObject* lcl_getSdrObjectbyName(ScDocument& rDoc, std::u16string_view r return pObj; } +static void lcl_SelectObjectByName(ScTabViewShell& rViewShell, std::u16string_view rObjName) +{ + bool bFound = rViewShell.SelectObject(rObjName); + CPPUNIT_ASSERT_MESSAGE( + OString(OUStringToOString(rObjName, RTL_TEXTENCODING_UTF8) + " not found.").getStr(), + bFound); + + CPPUNIT_ASSERT(rViewShell.GetViewData().GetScDrawView()->GetMarkedObjectList().GetMarkCount() + != 0); +} + CPPUNIT_TEST_FIXTURE(ScShapeTest, testTdf144242_OpenBezier_noSwapWH) { // Shapes, which have rotation incorporated in their points, got erroneously width-height @@ -1373,6 +1385,44 @@ CPPUNIT_TEST_FIXTURE(ScShapeTest, testTdf167450_copySheet) CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aRectSource, pObjTarget->GetLogicRect(), 1); } +CPPUNIT_TEST_FIXTURE(ScShapeTest, testTdf140866) +{ + // Load a document, which has a comment in cell $sheet2.$A$1, and a custom shape in cell + // $sheet2.$B$11. When the shape from $sheet2.$B$11 was copied and pasted to $sheet2.$D$9, + // the anchor position of comment is changed and after saved to ods the comment was gone. + createScDoc("ods/tdf140866.ods"); + ScDocument* pDoc = getScDoc(); + + // Check that we have the comment on A1 + ScPostIt* pNote = pDoc->GetNote(ScAddress(0, 0, 0)); + CPPUNIT_ASSERT(pNote); + CPPUNIT_ASSERT_EQUAL(u"Test 1"_ustr, pNote->GetText()); + + goToCell(u"$Sheet2.$B$11"_ustr); + lcl_SelectObjectByName(*getViewShell(), u"Shape 1"); + + // Copy and paste + dispatchCommand(mxComponent, u".uno:Copy"_ustr, {}); + goToCell(u"$Sheet2.$D$9"_ustr); + dispatchCommand(mxComponent, u".uno:Paste"_ustr, {}); + + // Check that we still have the comment on A1 + pNote = pDoc->GetNote(ScAddress(0, 0, 0)); + CPPUNIT_ASSERT(pNote); + CPPUNIT_ASSERT_EQUAL(u"Test 1"_ustr, pNote->GetText()); + + // Save, reload + saveAndReload(u"calc8"_ustr); + pDoc = getScDoc(); + // Check that we still have the comment on A1 after save&reload + pNote = pDoc->GetNote(ScAddress(0, 0, 0)); + // Without the fix in place the comment was gone and test would have failed with: + // assertion failed + // - Expression : pNote + CPPUNIT_ASSERT(pNote); + CPPUNIT_ASSERT_EQUAL(u"Test 1"_ustr, pNote->GetText()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx index 88103e4ed20a..5540894cf274 100644 --- a/sc/source/core/data/drwlayer.cxx +++ b/sc/source/core/data/drwlayer.cxx @@ -2693,7 +2693,9 @@ bool ScDrawLayer::IsCellAnchored( const SdrObject& rObj ) { // Cell anchored object always has a user data, to store the anchor cell // info. If it doesn't then it's page-anchored. - return GetFirstUserDataOfType(&rObj, SC_UD_OBJDATA) != nullptr; + // tdf#140866: Caption objects anchor position are handled differently. + return GetFirstUserDataOfType(&rObj, SC_UD_OBJDATA) != nullptr + && rObj.GetObjIdentifier() != SdrObjKind::Caption; } bool ScDrawLayer::IsResizeWithCell( const SdrObject& rObj )
