diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-03-20 20:49:18 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-04-04 09:52:09 +0200 |
commit | 54536bca332651051dc8a5ba02995c069cb75fd2 (patch) | |
tree | ffbeb6f757bcd5aaf68de43b87c6e3d02f5935c9 | |
parent | b8cf500ed8ac7bd01a351e2815ce8251e506d79c (diff) |
sc: add Undo/Redo for inserting Sparklines
Move the code to insert a sparkline from the SparklineDialog to
DocFunc and inside the UndoInsertSparkline, so there is no code
duplication and the code can be tested.
Change-Id: I85f4020190ae835b33e706ec9cb2cda9fd6fc752
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132474
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | sc/Library_sc.mk | 2 | ||||
-rw-r--r-- | sc/inc/SparklineData.hxx | 42 | ||||
-rw-r--r-- | sc/inc/globstr.hrc | 2 | ||||
-rw-r--r-- | sc/qa/unit/SparklineTest.cxx | 78 | ||||
-rw-r--r-- | sc/source/ui/dialogs/SparklineDialog.cxx | 95 | ||||
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 82 | ||||
-rw-r--r-- | sc/source/ui/inc/docfunc.hxx | 7 | ||||
-rw-r--r-- | sc/source/ui/inc/undo/UndoInsertSparkline.hxx | 45 | ||||
-rw-r--r-- | sc/source/ui/sparklines/SparklineData.cxx | 30 | ||||
-rw-r--r-- | sc/source/ui/undo/UndoInsertSparkline.cxx | 78 |
10 files changed, 364 insertions, 97 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index f145d3a7fbf2..2a9c6f659a0a 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -512,6 +512,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/sidebar/NumberFormatControl \ sc/source/ui/sidebar/NumberFormatPropertyPanel \ sc/source/ui/sidebar/ScPanelFactory \ + sc/source/ui/sparklines/SparklineData \ sc/source/ui/StatisticsDialogs/AnalysisOfVarianceDialog \ sc/source/ui/StatisticsDialogs/CorrelationDialog \ sc/source/ui/StatisticsDialogs/CovarianceDialog \ @@ -549,6 +550,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/undo/undostyl \ sc/source/ui/undo/undotab \ sc/source/ui/undo/undoutil \ + sc/source/ui/undo/UndoInsertSparkline \ sc/source/ui/unoobj/ChartRangeSelectionListener \ sc/source/ui/unoobj/addruno \ sc/source/ui/unoobj/afmtuno \ diff --git a/sc/inc/SparklineData.hxx b/sc/inc/SparklineData.hxx new file mode 100644 index 000000000000..80cc8a0329c2 --- /dev/null +++ b/sc/inc/SparklineData.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +#include "address.hxx" +#include "scdllapi.h" + +namespace sc +{ +struct SC_DLLPUBLIC SparklineData +{ + ScAddress maPosition; + ScRange maData; + + SparklineData(ScAddress const& rPosition, ScRange const& rData) + : maPosition(rPosition) + , maData(rData) + { + } +}; + +enum class RangeOrientation +{ + Unknown, + Row, + Col +}; + +SC_DLLPUBLIC RangeOrientation calculateOrientation(sal_Int32 nOutputSize, + ScRange const& rInputRange); + +} // end sc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc index 793d3cb95d55..6ae26c9d4a0f 100644 --- a/sc/inc/globstr.hrc +++ b/sc/inc/globstr.hrc @@ -539,7 +539,7 @@ #define STR_HYPHENATECELL_ON NC_("STR_HYPHENATECELL_ON", "Hyphenate: On") #define STR_HYPHENATECELL_OFF NC_("STR_HYPHENATECELL_OFF", "Hyphenate: Off") #define STR_INDENTCELL NC_("STR_INDENTCELL", "Indent: ") - +#define STR_UNDO_INSERT_SPARKLINE_GROUP NC_("STR_UNDO_INSERT_SPARKLINE", "Insert Sparkline Group") #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/SparklineTest.cxx b/sc/qa/unit/SparklineTest.cxx index 167c4e4d9e3d..7fafeef861ef 100644 --- a/sc/qa/unit/SparklineTest.cxx +++ b/sc/qa/unit/SparklineTest.cxx @@ -11,6 +11,8 @@ #include <docsh.hxx> #include <tabvwsh.hxx> #include <cliputil.hxx> +#include <docfunc.hxx> + #include <Sparkline.hxx> #include <SparklineGroup.hxx> @@ -21,8 +23,6 @@ class SparklineTest : public ScBootstrapFixture private: uno::Reference<uno::XInterface> m_xCalcComponent; - sc::Sparkline* createTestSparkline(ScDocument& rDocument); - public: SparklineTest() : ScBootstrapFixture("sc/qa/unit/data") @@ -50,29 +50,38 @@ public: void testDeleteSprkline(); void testCopyPasteSparkline(); void testCutPasteSparkline(); + void testUndoRedoInsertSparkline(); CPPUNIT_TEST_SUITE(SparklineTest); CPPUNIT_TEST(testAddSparkline); CPPUNIT_TEST(testDeleteSprkline); CPPUNIT_TEST(testCopyPasteSparkline); CPPUNIT_TEST(testCutPasteSparkline); + CPPUNIT_TEST(testUndoRedoInsertSparkline); CPPUNIT_TEST_SUITE_END(); }; -sc::Sparkline* SparklineTest::createTestSparkline(ScDocument& rDocument) +namespace +{ +void insertTestData(ScDocument& rDocument) { - auto pSparklineGroup = std::make_shared<sc::SparklineGroup>(); - - sc::Sparkline* pSparkline = rDocument.CreateSparkline(ScAddress(0, 6, 0), pSparklineGroup); - if (!pSparkline) - return nullptr; - rDocument.SetValue(0, 0, 0, 4); rDocument.SetValue(0, 1, 0, -2); rDocument.SetValue(0, 2, 0, 1); rDocument.SetValue(0, 3, 0, -3); rDocument.SetValue(0, 4, 0, 5); rDocument.SetValue(0, 5, 0, 3); +} + +sc::Sparkline* createTestSparkline(ScDocument& rDocument) +{ + auto pSparklineGroup = std::make_shared<sc::SparklineGroup>(); + + sc::Sparkline* pSparkline = rDocument.CreateSparkline(ScAddress(0, 6, 0), pSparklineGroup); + if (!pSparkline) + return nullptr; + + insertTestData(rDocument); ScRangeList aList; aList.push_back(ScRange(0, 0, 0, 0, 5, 0)); @@ -81,6 +90,8 @@ sc::Sparkline* SparklineTest::createTestSparkline(ScDocument& rDocument) return pSparkline; } +} // end anonymous namespace + void SparklineTest::testAddSparkline() { ScDocShellRef xDocSh = loadEmptyDocument(); @@ -228,6 +239,55 @@ void SparklineTest::testCutPasteSparkline() xDocSh->DoClose(); } +void SparklineTest::testUndoRedoInsertSparkline() +{ + ScDocShellRef xDocSh = loadEmptyDocument(); + CPPUNIT_ASSERT(xDocSh); + + ScDocument& rDocument = xDocSh->GetDocument(); + ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell); + + auto& rDocFunc = xDocSh->GetDocFunc(); + + // 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>(); + 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()); + + // Undo + rDocument.GetUndoManager()->Undo(); + + // Check Sparkline at cell A7 doesn't exists + pSparkline = rDocument.GetSparkline(aRange.aStart); + CPPUNIT_ASSERT(!pSparkline); + + // Redo + rDocument.GetUndoManager()->Redo(); + + // 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()); + + xDocSh->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SparklineTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/dialogs/SparklineDialog.cxx b/sc/source/ui/dialogs/SparklineDialog.cxx index fac1d8274be5..103582c25a6e 100644 --- a/sc/source/ui/dialogs/SparklineDialog.cxx +++ b/sc/source/ui/dialogs/SparklineDialog.cxx @@ -8,10 +8,13 @@ */ #include <SparklineDialog.hxx> +#include <SparklineData.hxx> #include <SparklineGroup.hxx> #include <Sparkline.hxx> #include <reffact.hxx> +#include <docfunc.hxx> + #include <svx/colorbox.hxx> namespace sc @@ -310,48 +313,24 @@ IMPL_LINK_NOARG(SparklineDialog, SelectSparklineType, weld::Toggleable&, void) mpLocalSparklineGroup->m_eType = sc::SparklineType::Stacked; } -namespace -{ -enum class RangeOrientation -{ - Unknown, - Row, - Col -}; - -RangeOrientation calculateOrientation(sal_Int32 nOutputSize, ScRange const& rInputRange) -{ - sal_Int32 nRowSize = rInputRange.aEnd.Row() - rInputRange.aStart.Row(); - sal_Int32 nColSize = rInputRange.aEnd.Col() - rInputRange.aStart.Col(); - - auto eInputOrientation = RangeOrientation::Unknown; - if (nOutputSize == nRowSize) - eInputOrientation = RangeOrientation::Row; - else if (nOutputSize == nColSize) - eInputOrientation = RangeOrientation::Col; - return eInputOrientation; -} - -} // end anonymous namespace - bool SparklineDialog::checkValidInputOutput() { if (!maInputRange.IsValid() || !maOutputRange.IsValid()) return false; - RangeOrientation eInputOrientation = RangeOrientation::Unknown; + sc::RangeOrientation eInputOrientation = sc::RangeOrientation::Unknown; if (maOutputRange.aStart.Col() == maOutputRange.aEnd.Col()) { sal_Int32 nOutputRowSize = maOutputRange.aEnd.Row() - maOutputRange.aStart.Row(); - eInputOrientation = calculateOrientation(nOutputRowSize, maInputRange); + eInputOrientation = sc::calculateOrientation(nOutputRowSize, maInputRange); } else if (maOutputRange.aStart.Row() == maOutputRange.aEnd.Row()) { sal_Int32 nOutputColSize = maOutputRange.aEnd.Col() - maOutputRange.aStart.Col(); - eInputOrientation = calculateOrientation(nOutputColSize, maInputRange); + eInputOrientation = sc::calculateOrientation(nOutputColSize, maInputRange); } - return eInputOrientation != RangeOrientation::Unknown; + return eInputOrientation != sc::RangeOrientation::Unknown; } void SparklineDialog::perform() @@ -364,65 +343,9 @@ void SparklineDialog::perform() mpLocalSparklineGroup->m_aColorFirst = mxColorFirst->GetSelectEntryColor(); mpLocalSparklineGroup->m_aColorLast = mxColorLast->GetSelectEntryColor(); - if (maOutputRange.aStart.Col() == maOutputRange.aEnd.Col()) - { - sal_Int32 nOutputRowSize = maOutputRange.aEnd.Row() - maOutputRange.aStart.Row(); - - auto eInputOrientation = calculateOrientation(nOutputRowSize, maInputRange); - - if (eInputOrientation == RangeOrientation::Unknown) - return; - - sal_Int32 nIndex = 0; - for (ScAddress aAddress = maOutputRange.aStart; aAddress.Row() <= maOutputRange.aEnd.Row(); - aAddress.IncRow()) - { - ScRange aInputRangeSlice = maInputRange; - if (eInputOrientation == RangeOrientation::Row) - { - aInputRangeSlice.aStart.SetRow(maInputRange.aStart.Row() + nIndex); - aInputRangeSlice.aEnd.SetRow(maInputRange.aStart.Row() + nIndex); - } - else - { - aInputRangeSlice.aStart.SetCol(maInputRange.aStart.Col() + nIndex); - aInputRangeSlice.aEnd.SetCol(maInputRange.aStart.Col() + nIndex); - } - auto* pCreated = mrDocument.CreateSparkline(aAddress, mpLocalSparklineGroup); - pCreated->setInputRange(aInputRangeSlice); - nIndex++; - } - } - else if (maOutputRange.aStart.Row() == maOutputRange.aEnd.Row()) - { - sal_Int32 nOutputColSize = maOutputRange.aEnd.Col() - maOutputRange.aStart.Col(); - - auto eInputOrientation = calculateOrientation(nOutputColSize, maInputRange); - - if (eInputOrientation == RangeOrientation::Unknown) - return; + auto& rDocFunc = mrViewData.GetDocShell()->GetDocFunc(); - sal_Int32 nIndex = 0; - - for (ScAddress aAddress = maOutputRange.aStart; aAddress.Col() <= maOutputRange.aEnd.Col(); - aAddress.IncCol()) - { - ScRange aInputRangeSlice = maInputRange; - if (eInputOrientation == RangeOrientation::Row) - { - aInputRangeSlice.aStart.SetRow(maInputRange.aStart.Row() + nIndex); - aInputRangeSlice.aEnd.SetRow(maInputRange.aStart.Row() + nIndex); - } - else - { - aInputRangeSlice.aStart.SetCol(maInputRange.aStart.Col() + nIndex); - aInputRangeSlice.aEnd.SetCol(maInputRange.aStart.Col() + nIndex); - } - auto* pCreated = mrDocument.CreateSparkline(aAddress, mpLocalSparklineGroup); - pCreated->setInputRange(aInputRangeSlice); - nIndex++; - } - } + rDocFunc.InsertSparklines(maInputRange, maOutputRange, mpLocalSparklineGroup); } } diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index b6c93a86cfc0..f28ca7e74344 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -94,6 +94,9 @@ #include <conditio.hxx> #include <columnspanset.hxx> #include <validat.hxx> +#include <SparklineGroup.hxx> +#include <SparklineData.hxx> +#include <undo/UndoInsertSparkline.hxx> #include <config_features.h> #include <memory> @@ -5759,4 +5762,83 @@ void ScDocFunc::EndListAction() rDocShell.GetUndoManager()->LeaveListAction(); } +bool ScDocFunc::InsertSparklines(ScRange const& rDataRange, ScRange const& rSparklineRange, + std::shared_ptr<sc::SparklineGroup> pSparklineGroup) +{ + std::vector<sc::SparklineData> aSparklineDataVector; + + if (rSparklineRange.aStart.Col() == rSparklineRange.aEnd.Col()) + { + sal_Int32 nOutputRowSize = rSparklineRange.aEnd.Row() - rSparklineRange.aStart.Row(); + + auto eInputOrientation = sc::calculateOrientation(nOutputRowSize, rDataRange); + + if (eInputOrientation == sc::RangeOrientation::Unknown) + return false; + + sal_Int32 nIndex = 0; + + for (ScAddress aAddress = rSparklineRange.aStart; aAddress.Row() <= rSparklineRange.aEnd.Row(); + aAddress.IncRow()) + { + ScRange aInputRangeSlice = rDataRange; + if (eInputOrientation == sc::RangeOrientation::Row) + { + aInputRangeSlice.aStart.SetRow(rDataRange.aStart.Row() + nIndex); + aInputRangeSlice.aEnd.SetRow(rDataRange.aStart.Row() + nIndex); + } + else + { + aInputRangeSlice.aStart.SetCol(rDataRange.aStart.Col() + nIndex); + aInputRangeSlice.aEnd.SetCol(rDataRange.aStart.Col() + nIndex); + } + + aSparklineDataVector.emplace_back(aAddress, aInputRangeSlice); + + nIndex++; + } + } + else if (rSparklineRange.aStart.Row() == rSparklineRange.aEnd.Row()) + { + sal_Int32 nOutputColSize = rSparklineRange.aEnd.Col() - rSparklineRange.aStart.Col(); + + auto eInputOrientation = sc::calculateOrientation(nOutputColSize, rDataRange); + + if (eInputOrientation == sc::RangeOrientation::Unknown) + return false; + + sal_Int32 nIndex = 0; + + for (ScAddress aAddress = rSparklineRange.aStart; aAddress.Col() <= rSparklineRange.aEnd.Col(); + aAddress.IncCol()) + { + ScRange aInputRangeSlice = rDataRange; + if (eInputOrientation == sc::RangeOrientation::Row) + { + aInputRangeSlice.aStart.SetRow(rDataRange.aStart.Row() + nIndex); + aInputRangeSlice.aEnd.SetRow(rDataRange.aStart.Row() + nIndex); + } + else + { + aInputRangeSlice.aStart.SetCol(rDataRange.aStart.Col() + nIndex); + aInputRangeSlice.aEnd.SetCol(rDataRange.aStart.Col() + nIndex); + } + + aSparklineDataVector.emplace_back(aAddress, aInputRangeSlice); + + nIndex++; + } + } + + if (aSparklineDataVector.empty()) + return false; + + auto pUndoInsertSparkline = std::make_unique<sc::UndoInsertSparkline>(rDocShell, aSparklineDataVector, pSparklineGroup); + // insert the sparkline by "redoing" + pUndoInsertSparkline->Redo(); + rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndoInsertSparkline)); + + return true; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/docfunc.hxx b/sc/source/ui/inc/docfunc.hxx index 8b0ea7d7c16a..52d61cb2e86e 100644 --- a/sc/source/ui/inc/docfunc.hxx +++ b/sc/source/ui/inc/docfunc.hxx @@ -51,8 +51,10 @@ class ScPostIt; enum class TransliterationFlags; enum class CreateNameFlags; -namespace sc { +namespace sc +{ struct ColRowSpan; + class SparklineGroup; } class ScDocFunc @@ -234,6 +236,9 @@ public: void ConvertFormulaToValue( const ScRange& rRange, bool bInteraction ); + SC_DLLPUBLIC bool InsertSparklines(ScRange const& rDataRange, ScRange const& rSparklineRange, + std::shared_ptr<sc::SparklineGroup> pSparklineGroup); + private: void ProtectDocument(const ScDocProtection& rProtect); }; diff --git a/sc/source/ui/inc/undo/UndoInsertSparkline.hxx b/sc/source/ui/inc/undo/UndoInsertSparkline.hxx new file mode 100644 index 000000000000..d9e1885f171c --- /dev/null +++ b/sc/source/ui/inc/undo/UndoInsertSparkline.hxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +#include <undobase.hxx> +#include <address.hxx> +#include <memory> + +namespace sc +{ +class SparklineGroup; +struct SparklineData; + +/** Undo action for inserting a Sparkline */ +class UndoInsertSparkline : public ScSimpleUndo +{ +private: + std::vector<sc::SparklineData> maSparklineDataVector; + std::shared_ptr<sc::SparklineGroup> mpSparklineGroup; + +public: + UndoInsertSparkline(ScDocShell& rDocShell, + std::vector<SparklineData> const& rSparklineDataVector, + std::shared_ptr<sc::SparklineGroup> pSparklineGroup); + + virtual ~UndoInsertSparkline() override; + + void Undo() override; + void Redo() override; + bool CanRepeat(SfxRepeatTarget& rTarget) const override; + void Repeat(SfxRepeatTarget& rTarget) override; + OUString GetComment() const override; +}; + +} // namespace sc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/sparklines/SparklineData.cxx b/sc/source/ui/sparklines/SparklineData.cxx new file mode 100644 index 000000000000..a126acc10b0a --- /dev/null +++ b/sc/source/ui/sparklines/SparklineData.cxx @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <SparklineData.hxx> + +namespace sc +{ +RangeOrientation calculateOrientation(sal_Int32 nOutputSize, ScRange const& rInputRange) +{ + sal_Int32 nRowSize = rInputRange.aEnd.Row() - rInputRange.aStart.Row(); + sal_Int32 nColSize = rInputRange.aEnd.Col() - rInputRange.aStart.Col(); + + auto eInputOrientation = RangeOrientation::Unknown; + if (nOutputSize == nRowSize) + eInputOrientation = RangeOrientation::Row; + else if (nOutputSize == nColSize) + eInputOrientation = RangeOrientation::Col; + return eInputOrientation; +} + +} // end sc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/undo/UndoInsertSparkline.cxx b/sc/source/ui/undo/UndoInsertSparkline.cxx new file mode 100644 index 000000000000..c35cc3f6dc03 --- /dev/null +++ b/sc/source/ui/undo/UndoInsertSparkline.cxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <undo/UndoInsertSparkline.hxx> +#include <globstr.hrc> +#include <scresid.hxx> + +#include <Sparkline.hxx> +#include <SparklineGroup.hxx> +#include <SparklineData.hxx> + +namespace sc +{ +UndoInsertSparkline::UndoInsertSparkline(ScDocShell& rDocShell, + std::vector<SparklineData> const& rSparklineDataVector, + std::shared_ptr<sc::SparklineGroup> pSparklineGroup) + : ScSimpleUndo(&rDocShell) + , maSparklineDataVector(rSparklineDataVector) + , mpSparklineGroup(pSparklineGroup) +{ +} + +UndoInsertSparkline::~UndoInsertSparkline() {} + +void UndoInsertSparkline::Undo() +{ + BeginUndo(); + + ScDocument& rDocument = pDocShell->GetDocument(); + ScRangeList aRanges; + for (auto const& rSparklineData : maSparklineDataVector) + { + rDocument.DeleteSparkline(rSparklineData.maPosition); + aRanges.push_back(ScRange(rSparklineData.maPosition)); + } + + pDocShell->PostPaint(aRanges, PaintPartFlags::All); + + EndUndo(); +} + +void UndoInsertSparkline::Redo() +{ + BeginRedo(); + + ScDocument& rDocument = pDocShell->GetDocument(); + ScRangeList aRanges; + for (auto const& rSparklineData : maSparklineDataVector) + { + auto* pCreated = rDocument.CreateSparkline(rSparklineData.maPosition, mpSparklineGroup); + pCreated->setInputRange(rSparklineData.maData); + aRanges.push_back(ScRange(rSparklineData.maPosition)); + } + + pDocShell->PostPaint(aRanges, PaintPartFlags::All); + + EndRedo(); +} + +void UndoInsertSparkline::Repeat(SfxRepeatTarget& /*rTarget*/) {} + +bool UndoInsertSparkline::CanRepeat(SfxRepeatTarget& /*rTarget*/) const { return false; } + +OUString UndoInsertSparkline::GetComment() const +{ + return ScResId(STR_UNDO_INSERT_SPARKLINE_GROUP); +} + +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |