tdf#138137 sc: remove red circle in merged cell

This mark wasn't removed when valid data is entered in the merged cell.

Co-authored-by: Attila Szűcs (NISZ)
Change-Id: I7632abadde9c482819f80af2600ab4c58292a821
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106172
Tested-by: Jenkins
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 6975e4387640a1473ca158f503637be61ac9dedb)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106447
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sc/qa/unit/data/ods/deleteCircleInMergedCell.ods b/sc/qa/unit/data/ods/deleteCircleInMergedCell.ods
new file mode 100644
index 0000000..f4d078d
--- /dev/null
+++ b/sc/qa/unit/data/ods/deleteCircleInMergedCell.ods
Binary files differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index af64711..23a2c27 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -104,6 +104,7 @@ public:
    virtual void tearDown() override;

    //ods, xls, xlsx filter tests
    void testDeleteCircleInMergedCellODS();
    void testBooleanFormatXLSX();
    void testBasicCellContentODS();
    void testRangeNameXLS();
@@ -292,6 +293,7 @@ public:
    void testDeleteCirclesInRowAndCol();

    CPPUNIT_TEST_SUITE(ScFiltersTest);
    CPPUNIT_TEST(testDeleteCircleInMergedCellODS);
    CPPUNIT_TEST(testBooleanFormatXLSX);
    CPPUNIT_TEST(testBasicCellContentODS);
    CPPUNIT_TEST(testRangeNameXLS);
@@ -524,6 +526,40 @@ void testRangeNameImpl(const ScDocument& rDoc)

}

void ScFiltersTest::testDeleteCircleInMergedCellODS()
{
    ScDocShellRef xDocSh = loadDoc("deleteCircleInMergedCell.", FORMAT_ODS);
    CPPUNIT_ASSERT_MESSAGE("Failed to load deleteCircleInMergedCell.ods", xDocSh.is());

    ScDocument& rDoc = xDocSh->GetDocument();

    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
    SdrPage* pPage = pDrawLayer->GetPage(0);
    CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage);

    // There should be a circle object!
    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount());

    ScRefCellValue aMergedCell;
    ScAddress aPosMergedCell(0, 0, 0);
    aMergedCell.assign(rDoc, aPosMergedCell);

    // The value of merged cell change to 6.
    aMergedCell.mfValue = 6;

    // Check that the data is valid.(True if the value = 6)
    const ScValidationData* pData = rDoc.GetValidationEntry(1);
    bool bValidA1 = pData->IsDataValid(aMergedCell, aPosMergedCell);
    // if valid, delete circle.
    if (bValidA1)
        ScDetectiveFunc(rDoc, 0).DeleteCirclesAt(aPosMergedCell.Col(), aPosMergedCell.Row());

    // There should not be a circle object!
    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount());

    xDocSh->DoClose();
}

void ScFiltersTest::testBasicCellContentODS()
{
    ScDocShellRef xDocSh = loadDoc("basic-cell-content.", FORMAT_ODS);
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index 786b462..1fa94ab 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -1240,7 +1240,7 @@ bool ScDetectiveFunc::DeletePred( SCCOL nCol, SCROW nRow )

bool ScDetectiveFunc::DeleteCirclesAt( SCCOL nCol, SCROW nRow )
{
    tools::Rectangle aRect = GetDrawRect(nCol, nRow);
    tools::Rectangle aRect = ScDrawLayer::GetCellRect(rDoc, ScAddress(nCol, nRow, nTab), true);
    aRect.AdjustLeft(-250);
    aRect.AdjustRight(250);
    aRect.AdjustTop(-70);