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/UndoUngroupSparklines.hxx>
13 #include <globstr.hrc>
14 #include <scresid.hxx>
16 #include <Sparkline.hxx>
17 #include <SparklineGroup.hxx>
21 UndoUngroupSparklines::UndoUngroupSparklines(ScDocShell
& rDocShell
, ScRange
const& rRange
)
22 : ScSimpleUndo(&rDocShell
)
27 UndoUngroupSparklines::~UndoUngroupSparklines() = default;
29 void UndoUngroupSparklines::Undo()
33 ScDocument
& rDocument
= pDocShell
->GetDocument();
35 for (SparklineUndoData
& rUndoData
: m_aUndoData
)
37 rDocument
.DeleteSparkline(rUndoData
.m_aAddress
);
39 = rDocument
.CreateSparkline(rUndoData
.m_aAddress
, rUndoData
.m_pSparklineGroup
);
40 pCreated
->setInputRange(rUndoData
.m_aDataRangeList
);
45 pDocShell
->PostPaint(m_aRange
, PaintPartFlags::All
);
50 void UndoUngroupSparklines::Redo()
54 ScDocument
& rDocument
= pDocShell
->GetDocument();
56 for (ScAddress aAddress
= m_aRange
.aStart
; aAddress
.Col() <= m_aRange
.aEnd
.Col();
59 aAddress
.SetRow(m_aRange
.aStart
.Row());
60 for (; aAddress
.Row() <= m_aRange
.aEnd
.Row(); aAddress
.IncRow())
62 if (auto pSparkline
= rDocument
.GetSparkline(aAddress
))
64 auto const& rpGroup
= pSparkline
->getSparklineGroup();
65 m_aUndoData
.emplace_back(aAddress
, pSparkline
->getInputRange(), rpGroup
);
66 auto pSparklineGroupCopy
67 = std::make_shared
<sc::SparklineGroup
>(rpGroup
->getAttributes());
68 rDocument
.DeleteSparkline(aAddress
);
69 auto* pCreated
= rDocument
.CreateSparkline(aAddress
, pSparklineGroupCopy
);
70 pCreated
->setInputRange(pSparkline
->getInputRange());
75 pDocShell
->PostPaint(m_aRange
, PaintPartFlags::All
);
80 void UndoUngroupSparklines::Repeat(SfxRepeatTarget
& /*rTarget*/) {}
82 bool UndoUngroupSparklines::CanRepeat(SfxRepeatTarget
& /*rTarget*/) const { return false; }
84 OUString
UndoUngroupSparklines::GetComment() const { return ScResId(STR_UNDO_UNGROUP_SPARKLINES
); }
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */