summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTibor Nagy <nagy.tibor2@nisz.hu>2020-10-05 20:47:14 +0200
committerGabor Kelemen <kelemen.gabor2@nisz.hu>2021-02-24 08:25:46 +0100
commitf5394680e45d56cd666dfb545c5da2c0c4192131 (patch)
tree7466afb547831d3575c58184f9b2bda8b677e949
parent989d8f1111e502bc100580a4f0c32c4a46b14fd2 (diff)
tdf#125462 sc: remove red (invalid data) circle
around the cell after typing valid data in it. This mark wasn't removed when correct data is entered in the cell, giving the impression that the entered value is incorrect. Note: This fixes only the directly modified cell, not the other cells with red circles which refer the modified cell. Testing: Tools->Detective->Mark Invalid Data adds these red circles around the cells with invalid content, according to their validation added by Data->Validity... Co-authored-by: Attila Szűcs (NISZ) Change-Id: Ib7ca3c453a930669a7c58e89b91654de36b8bb3b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103995 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit 9971b1602d2a526dd8f2cc8255794515bb4e2168) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111414 Tested-by: Gabor Kelemen <kelemen.gabor2@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gabor2@nisz.hu>
-rw-r--r--sc/inc/detfunc.hxx1
-rw-r--r--sc/qa/unit/data/xlsx/testDeleteCircles.xlsxbin0 -> 8420 bytes
-rw-r--r--sc/qa/unit/subsequent_filters-test.cxx42
-rw-r--r--sc/source/core/tool/detfunc.cxx55
-rw-r--r--sc/source/ui/docshell/docfunc.cxx10
5 files changed, 108 insertions, 0 deletions
diff --git a/sc/inc/detfunc.hxx b/sc/inc/detfunc.hxx
index b8d1d2c0bc81..443e75deb8c0 100644
--- a/sc/inc/detfunc.hxx
+++ b/sc/inc/detfunc.hxx
@@ -126,6 +126,7 @@ public:
bool DeleteSucc( SCCOL nCol, SCROW nRow );
bool DeletePred( SCCOL nCol, SCROW nRow );
bool DeleteAll( ScDetectiveDelete eWhat );
+ bool DeleteCirclesAt( SCCOL nCol, SCROW nRow );
bool MarkInvalid(bool& rOverflow);
diff --git a/sc/qa/unit/data/xlsx/testDeleteCircles.xlsx b/sc/qa/unit/data/xlsx/testDeleteCircles.xlsx
new file mode 100644
index 000000000000..1f544957fcd9
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/testDeleteCircles.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 7ff383a8a760..b760998bd5a8 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -65,6 +65,7 @@
#include <externalrefmgr.hxx>
#include <stlpool.hxx>
#include <hints.hxx>
+#include <detfunc.hxx>
#include <orcusfilters.hxx>
#include <filter.hxx>
@@ -265,6 +266,7 @@ public:
void testShapeDisplacementOnRotationImport();
void testTextBoxBodyUpright();
void testTextLengthDataValidityXLSX();
+ void testDeleteCircles();
CPPUNIT_TEST_SUITE(ScFiltersTest);
CPPUNIT_TEST(testBooleanFormatXLSX);
@@ -418,6 +420,7 @@ public:
CPPUNIT_TEST(testShapeDisplacementOnRotationImport);
CPPUNIT_TEST(testTextBoxBodyUpright);
CPPUNIT_TEST(testTextLengthDataValidityXLSX);
+ CPPUNIT_TEST(testDeleteCircles);
CPPUNIT_TEST_SUITE_END();
@@ -4624,6 +4627,45 @@ void ScFiltersTest::testTextLengthDataValidityXLSX()
xDocSh->DoClose();
}
+void ScFiltersTest::testDeleteCircles()
+{
+ ScDocShellRef xDocSh = loadDoc("testDeleteCircles.", FORMAT_XLSX);
+ CPPUNIT_ASSERT_MESSAGE("Failed to load testDeleteCircles.xlsx", 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);
+
+ ScRefCellValue aCellA1; // A1 = "Hello"
+ ScAddress aPosA1(0, 0, 0);
+ aCellA1.assign(rDoc, aPosA1);
+
+ // Mark invalid value
+ bool bOverflow;
+ bool bMarkInvalid = ScDetectiveFunc(rDoc, 0).MarkInvalid(bOverflow);
+ CPPUNIT_ASSERT_EQUAL(true, bMarkInvalid);
+
+ // There should be a circle object!
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount());
+
+ // The value of A1 change to Hello1.
+ rDoc.SetString(0, 0, 0, "Hello1");
+
+ // Check that the data is valid.(True if text length = 6)
+ const ScValidationData* pData = rDoc.GetValidationEntry(1);
+ bool bValidA1 = pData->IsDataValid(aCellA1, aPosA1);
+ // if valid, delete circle.
+ if (bValidA1)
+ ScDetectiveFunc(rDoc, 0).DeleteCirclesAt(aPosA1.Col(), aPosA1.Row());
+
+ // There should not be a circle object!
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pPage->GetObjCount());
+
+ xDocSh->DoClose();
+}
+
ScFiltersTest::ScFiltersTest()
: ScBootstrapFixture( "sc/qa/unit/data" )
{
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index 3f0419364bac..e8dfae30cb5a 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -1238,6 +1238,61 @@ bool ScDetectiveFunc::DeletePred( SCCOL nCol, SCROW nRow )
return ( nLevelCount != 0 );
}
+bool ScDetectiveFunc::DeleteCirclesAt( SCCOL nCol, SCROW nRow )
+{
+ tools::Rectangle aRect = GetDrawRect(nCol, nRow);
+ aRect.AdjustLeft(-250);
+ aRect.AdjustRight(250);
+ aRect.AdjustTop(-70);
+ aRect.AdjustBottom(70);
+
+ Point aStartCorner = aRect.TopLeft();
+ Point aEndCorner = aRect.BottomRight();
+
+ ScDrawLayer* pModel = pDoc->GetDrawLayer();
+ if (!pModel)
+ return false;
+
+ SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab));
+ OSL_ENSURE(pPage, "Page ?");
+
+ pPage->RecalcObjOrdNums();
+
+ const size_t nObjCount = pPage->GetObjCount();
+ size_t nDelCount = 0;
+ if (nObjCount)
+ {
+ std::unique_ptr<SdrObject*[]> ppObj(new SdrObject*[nObjCount]);
+
+ SdrObjListIter aIter(pPage, SdrIterMode::Flat);
+ SdrObject* pObject = aIter.Next();
+ while (pObject)
+ {
+ if (pObject->GetLayer() == SC_LAYER_INTERN
+ && dynamic_cast<const SdrCircObj*>(pObject) != nullptr)
+ {
+ tools::Rectangle aObjRect = static_cast<SdrCircObj*>(pObject)->GetLogicRect();
+ if (RectIsPoints(aObjRect, aStartCorner, aEndCorner))
+ ppObj[nDelCount++] = pObject;
+ }
+
+ pObject = aIter.Next();
+ }
+
+ for (size_t i = 1; i <= nDelCount; ++i)
+ pModel->AddCalcUndo(std::make_unique<SdrUndoRemoveObj>(*ppObj[nDelCount - i]));
+
+ for (size_t i = 1; i <= nDelCount; ++i)
+ pPage->RemoveObject(ppObj[nDelCount - i]->GetOrdNum());
+
+ ppObj.reset();
+
+ Modified();
+ }
+
+ return (nDelCount != 0);
+}
+
bool ScDetectiveFunc::DeleteAll( ScDetectiveDelete eWhat )
{
ScDrawLayer* pModel = pDoc->GetDrawLayer();
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 3d840ad3c2ab..c0a205532ca2 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -92,6 +92,7 @@
#include <sheetevents.hxx>
#include <conditio.hxx>
#include <columnspanset.hxx>
+#include <validat.hxx>
#include <memory>
#include <utility>
@@ -816,6 +817,15 @@ bool ScDocFunc::SetNormalString( bool& o_rbNumFmtSet, const ScAddress& rPos, con
if (bApi)
NotifyInputHandler( rPos );
+ const SfxUInt32Item* pItem = rDoc.GetAttr(rPos, ATTR_VALIDDATA);
+ const ScValidationData* pData = rDoc.GetValidationEntry(pItem->GetValue());
+ if (pData)
+ {
+ ScRefCellValue aCell(rDoc, rPos);
+ if (pData->IsDataValid(aCell, rPos))
+ ScDetectiveFunc(&rDoc, rPos.Tab()).DeleteCirclesAt(rPos.Col(), rPos.Row());
+ }
+
return true;
}