diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-03-22 11:03:24 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-04-04 09:53:21 +0200 |
commit | af38d84380ee78f61822e8e080a56e955842b71e (patch) | |
tree | 3d8ea56915c0e494020b375be04ff52da1d3ee80 | |
parent | 20ed714f87dd22e5f11a65c4208045037dc20017 (diff) |
sc: undo/redo for sparklines when deleting the cell content
This adds support for undo/redo when clearing the content of a
cell, which includes a sparkline.
Change-Id: I79d9ef965e21cf5b35de84aa3b5cb93b644777ed
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132476
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | sc/inc/column.hxx | 2 | ||||
-rw-r--r-- | sc/inc/table.hxx | 1 | ||||
-rw-r--r-- | sc/qa/unit/SparklineTest.cxx | 65 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 17 | ||||
-rw-r--r-- | sc/source/ui/undo/undoblk3.cxx | 2 |
5 files changed, 86 insertions, 1 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 3afda2acd885..f60ea22cbc30 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -674,7 +674,7 @@ public: void DeleteSparklineCells(sc::ColumnBlockPosition& rBlockPos, SCROW nRow1, SCROW nRow2); bool DeleteSparkline(SCROW nRow); bool IsSparklinesEmptyBlock(SCROW nStartRow, SCROW nEndRow) const; - void CopyCellSparklinesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest) const; + void CopyCellSparklinesToDocument(SCROW nRow1, SCROW nRow2, ScColumn& rDestCol, SCROW nRowOffsetDest = 0) const; void DuplicateSparklines(SCROW nStartRow, size_t nDataSize, ScColumn& rDestCol, sc::ColumnBlockPosition& rDestBlockPos, SCROW nRowOffsetDest = 0) const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 14eb33fa50f7..7a3ce91a43a0 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -477,6 +477,7 @@ public: bool DeleteSparkline(SCCOL nCol, SCROW nRow); sc::SparklineList& GetSparklineList(); + void CopySparklinesToTable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab); // Notes / Comments std::unique_ptr<ScPostIt> ReleaseNote( SCCOL nCol, SCROW nRow ); diff --git a/sc/qa/unit/SparklineTest.cxx b/sc/qa/unit/SparklineTest.cxx index 6173cea5f297..ac9c0996ac59 100644 --- a/sc/qa/unit/SparklineTest.cxx +++ b/sc/qa/unit/SparklineTest.cxx @@ -52,6 +52,7 @@ public: void testCutPasteSparkline(); void testUndoRedoInsertSparkline(); void testUndoRedoDeleteSparkline(); + void testUndoRedoClearContentForSparkline(); CPPUNIT_TEST_SUITE(SparklineTest); CPPUNIT_TEST(testAddSparkline); @@ -60,6 +61,7 @@ public: CPPUNIT_TEST(testCutPasteSparkline); CPPUNIT_TEST(testUndoRedoInsertSparkline); CPPUNIT_TEST(testUndoRedoDeleteSparkline); + CPPUNIT_TEST(testUndoRedoClearContentForSparkline); CPPUNIT_TEST_SUITE_END(); }; @@ -351,6 +353,69 @@ void SparklineTest::testUndoRedoDeleteSparkline() xDocSh->DoClose(); } +void SparklineTest::testUndoRedoClearContentForSparkline() +{ + ScDocShellRef xDocSh = loadEmptyDocument(); + CPPUNIT_ASSERT(xDocSh); + + ScDocument& rDocument = xDocSh->GetDocument(); + ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell); + + auto& rDocFunc = xDocSh->GetDocFunc(); + + // Try to delete sparkline that doesn't exist - returns false + CPPUNIT_ASSERT(!rDocFunc.DeleteSparkline(ScAddress(0, 6, 0))); + + // insert test data - A1:A6 + insertTestData(rDocument); + + // Sparkline range + ScRange aRange(0, 6, 0, 0, 6, 0); + + // Check Sparkline at cell A7 doesn't exists + auto pSparkline = rDocument.GetSparkline(aRange.aStart); + CPPUNIT_ASSERT(!pSparkline); + + auto pSparklineGroup = std::make_shared<sc::SparklineGroup>(); + CPPUNIT_ASSERT(rDocFunc.InsertSparklines(ScRange(0, 0, 0, 0, 5, 0), aRange, pSparklineGroup)); + + // Check Sparkline at cell A7 exists + pSparkline = rDocument.GetSparkline(aRange.aStart); + CPPUNIT_ASSERT(pSparkline); + CPPUNIT_ASSERT_EQUAL(SCCOL(0), pSparkline->getColumn()); + CPPUNIT_ASSERT_EQUAL(SCROW(6), pSparkline->getRow()); + + // Clear content - including sparkline + ScMarkData aMark(rDocument.GetSheetLimits()); + aMark.SetMarkArea(aRange.aStart); + rDocFunc.DeleteContents(aMark, InsertDeleteFlags::CONTENTS, true, true); + + // Check Sparkline at cell A7 doesn't exists + pSparkline = rDocument.GetSparkline(aRange.aStart); + CPPUNIT_ASSERT(!pSparkline); + + // Undo + rDocument.GetUndoManager()->Undo(); + + // Check Sparkline at cell A7 exists + pSparkline = rDocument.GetSparkline(aRange.aStart); + CPPUNIT_ASSERT(pSparkline); + CPPUNIT_ASSERT_EQUAL(SCCOL(0), pSparkline->getColumn()); + CPPUNIT_ASSERT_EQUAL(SCROW(6), pSparkline->getRow()); + + // Redo + rDocument.GetUndoManager()->Redo(); + + // Check Sparkline at cell A7 doesn't exists + pSparkline = rDocument.GetSparkline(aRange.aStart); + CPPUNIT_ASSERT(!pSparkline); + + CPPUNIT_ASSERT(!rDocument.HasSparkline(aRange.aStart)); + + xDocSh->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SparklineTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index e6170d2339ab..010f324d2c74 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1439,6 +1439,11 @@ void ScTable::CopyToTable( if(nFlags & InsertDeleteFlags::OUTLINE) // also only when bColRowFlags pDestTab->SetOutlineTable( pOutlineTable.get() ); + if (nFlags & InsertDeleteFlags::SPARKLINES) + { + CopySparklinesToTable(nCol1, nRow1, nCol2, nRow2, pDestTab); + } + if (!bIsUndoDoc && bCopyCaptions && (nFlags & (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES))) { bool bCloneCaption = (nFlags & InsertDeleteFlags::NOCAPTIONS) == InsertDeleteFlags::NONE; @@ -1446,6 +1451,18 @@ void ScTable::CopyToTable( } } +void ScTable::CopySparklinesToTable(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab) +{ + if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2)) + return; + + nCol2 = ClampToAllocatedColumns(nCol2); + for (SCCOL i = nCol1; i <= nCol2; i++) + { + aCol[i].CopyCellSparklinesToDocument(nRow1, nRow2, pDestTab->CreateColumnIfNotExists(i)); + } +} + void ScTable::CopyCaptionsToTable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab, bool bCloneCaption ) { diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx index 073035be799b..57ce491c6fcb 100644 --- a/sc/source/ui/undo/undoblk3.cxx +++ b/sc/source/ui/undo/undoblk3.cxx @@ -119,6 +119,8 @@ void ScUndoDeleteContents::DoChange( const bool bUndo ) nUndoFlags |= InsertDeleteFlags::ATTRIB; if (nFlags & InsertDeleteFlags::EDITATTR) // Edit-Engine attribute nUndoFlags |= InsertDeleteFlags::STRING; // -> Cells will be changed + if (nFlags & InsertDeleteFlags::SPARKLINES) + nUndoFlags |= InsertDeleteFlags::SPARKLINES; // do not create clones of note captions, they will be restored via drawing undo nUndoFlags |= InsertDeleteFlags::NOCAPTIONS; |