1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <undo/UndoDeleteSparklineGroup.hxx>
12 #include <globstr.hrc>
13 #include <scresid.hxx>
14 #include <document.hxx>
16 #include <Sparkline.hxx>
17 #include <SparklineList.hxx>
18 #include <SparklineGroup.hxx>
23 UndoDeleteSparklineGroup::UndoDeleteSparklineGroup(
24 ScDocShell
& rDocShell
, std::shared_ptr
<sc::SparklineGroup
> pSparklineGroup
, SCTAB nTab
)
25 : ScSimpleUndo(&rDocShell
)
26 , mpSparklineGroup(std::move(pSparklineGroup
))
31 UndoDeleteSparklineGroup::~UndoDeleteSparklineGroup() {}
33 void UndoDeleteSparklineGroup::Undo()
37 ScDocument
& rDocument
= pDocShell
->GetDocument();
39 for (auto const& pSparkline
: maSparklines
)
41 ScAddress
aAddress(pSparkline
->getColumn(), pSparkline
->getRow(), mnTab
);
42 auto* pNewSparkline
= rDocument
.CreateSparkline(aAddress
, mpSparklineGroup
);
43 pNewSparkline
->setInputRange(pSparkline
->getInputRange());
46 pDocShell
->PostPaintGridAll();
51 void UndoDeleteSparklineGroup::Redo()
55 ScDocument
& rDocument
= pDocShell
->GetDocument();
56 auto* pList
= rDocument
.GetSparklineList(mnTab
);
59 maSparklines
= pList
->getSparklinesFor(mpSparklineGroup
);
61 for (auto const& pSparkline
: maSparklines
)
63 ScAddress
aAddress(pSparkline
->getColumn(), pSparkline
->getRow(), mnTab
);
64 rDocument
.DeleteSparkline(aAddress
);
67 pDocShell
->PostPaintGridAll();
72 void UndoDeleteSparklineGroup::Repeat(SfxRepeatTarget
& /*rTarget*/) {}
74 bool UndoDeleteSparklineGroup::CanRepeat(SfxRepeatTarget
& /*rTarget*/) const { return false; }
76 OUString
UndoDeleteSparklineGroup::GetComment() const
78 return ScResId(STR_UNDO_DELETE_SPARKLINE_GROUP
);
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */