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/UndoGroupSparklines.hxx>
13 #include <globstr.hrc>
14 #include <scresid.hxx>
16 #include <Sparkline.hxx>
17 #include <SparklineGroup.hxx>
22 UndoGroupSparklines::UndoGroupSparklines(ScDocShell
& rDocShell
, ScRange
const& rRange
,
23 std::shared_ptr
<sc::SparklineGroup
> pSparklineGroup
)
24 : ScSimpleUndo(&rDocShell
)
26 , m_pSparklineGroup(std::move(pSparklineGroup
))
30 UndoGroupSparklines::~UndoGroupSparklines() = default;
32 void UndoGroupSparklines::Undo()
36 ScDocument
& rDocument
= pDocShell
->GetDocument();
38 for (auto& rUndoData
: m_aUndoData
)
40 rDocument
.DeleteSparkline(rUndoData
.m_aAddress
);
42 = rDocument
.CreateSparkline(rUndoData
.m_aAddress
, rUndoData
.m_pSparklineGroup
);
43 pCreated
->setInputRange(rUndoData
.m_aDataRangeList
);
48 pDocShell
->PostPaint(m_aRange
, PaintPartFlags::All
);
53 void UndoGroupSparklines::Redo()
57 ScDocument
& rDocument
= pDocShell
->GetDocument();
59 for (ScAddress aAddress
= m_aRange
.aStart
; aAddress
.Col() <= m_aRange
.aEnd
.Col();
62 aAddress
.SetRow(m_aRange
.aStart
.Row());
63 for (; aAddress
.Row() <= m_aRange
.aEnd
.Row(); aAddress
.IncRow())
65 if (auto pSparkline
= rDocument
.GetSparkline(aAddress
))
67 m_aUndoData
.emplace_back(aAddress
, pSparkline
->getInputRange(),
68 pSparkline
->getSparklineGroup());
70 rDocument
.DeleteSparkline(aAddress
);
71 auto* pCreated
= rDocument
.CreateSparkline(aAddress
, m_pSparklineGroup
);
72 pCreated
->setInputRange(pSparkline
->getInputRange());
77 pDocShell
->PostPaint(m_aRange
, PaintPartFlags::All
);
82 void UndoGroupSparklines::Repeat(SfxRepeatTarget
& /*rTarget*/) {}
84 bool UndoGroupSparklines::CanRepeat(SfxRepeatTarget
& /*rTarget*/) const { return false; }
86 OUString
UndoGroupSparklines::GetComment() const { return ScResId(STR_UNDO_GROUP_SPARKLINES
); }
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */