LibreOffice Module sc (master) 1
UndoGroupSparklines.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
12
13#include <globstr.hrc>
14#include <scresid.hxx>
15
16#include <Sparkline.hxx>
17#include <SparklineGroup.hxx>
19#include <utility>
20
21namespace sc
22{
24 std::shared_ptr<sc::SparklineGroup> pSparklineGroup)
25 : ScSimpleUndo(&rDocShell)
26 , m_aRange(rRange)
27 , m_pSparklineGroup(std::move(pSparklineGroup))
28{
29}
30
32
34{
35 BeginUndo();
36
37 ScDocument& rDocument = pDocShell->GetDocument();
38
39 for (auto& rUndoData : m_aUndoData)
40 {
41 rDocument.DeleteSparkline(rUndoData.m_aAddress);
42 auto* pCreated
43 = rDocument.CreateSparkline(rUndoData.m_aAddress, rUndoData.m_pSparklineGroup);
44 pCreated->setInputRange(rUndoData.m_aDataRangeList);
45 }
46
47 m_aUndoData.clear();
48
50
51 EndUndo();
52}
53
55{
56 BeginRedo();
57
58 ScDocument& rDocument = pDocShell->GetDocument();
59
60 for (ScAddress aAddress = m_aRange.aStart; aAddress.Col() <= m_aRange.aEnd.Col();
61 aAddress.IncCol())
62 {
63 aAddress.SetRow(m_aRange.aStart.Row());
64 for (; aAddress.Row() <= m_aRange.aEnd.Row(); aAddress.IncRow())
65 {
66 if (auto pSparkline = rDocument.GetSparkline(aAddress))
67 {
68 m_aUndoData.emplace_back(aAddress, pSparkline->getInputRange(),
69 pSparkline->getSparklineGroup());
70
71 rDocument.DeleteSparkline(aAddress);
72 auto* pCreated = rDocument.CreateSparkline(aAddress, m_pSparklineGroup);
73 pCreated->setInputRange(pSparkline->getInputRange());
74 }
75 }
76 }
77
79
80 EndRedo();
81}
82
83void UndoGroupSparklines::Repeat(SfxRepeatTarget& /*rTarget*/) {}
84
85bool UndoGroupSparklines::CanRepeat(SfxRepeatTarget& /*rTarget*/) const { return false; }
86
87OUString UndoGroupSparklines::GetComment() const { return ScResId(STR_UNDO_GROUP_SPARKLINES); }
88
89} // end sc namespace
90
91/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
void PostPaint(SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab, SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart, sal_uInt16 nExtFlags=0)
Definition: docsh3.cxx:101
SC_DLLPUBLIC std::shared_ptr< sc::Sparkline > GetSparkline(ScAddress const &rPosition)
Returns sparkline at the address if it exists.
Definition: document.cxx:6495
SC_DLLPUBLIC sc::Sparkline * CreateSparkline(ScAddress const &rPosition, std::shared_ptr< sc::SparklineGroup > const &pSparklineGroup)
Definition: document.cxx:6508
SC_DLLPUBLIC bool DeleteSparkline(ScAddress const &rPosition)
Definition: document.cxx:6516
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
void BeginRedo()
Definition: undobase.cxx:145
void EndRedo()
Definition: undobase.cxx:154
void EndUndo()
Definition: undobase.cxx:125
ScDocShell * pDocShell
Definition: undobase.hxx:50
void BeginUndo()
Definition: undobase.cxx:90
void setInputRange(ScRangeList const &rInputRange)
Definition: Sparkline.hxx:47
virtual ~UndoGroupSparklines() override
std::vector< UndoGroupSparklinesData > m_aUndoData
UndoGroupSparklines(ScDocShell &rDocShell, ScRange const &rRange, std::shared_ptr< sc::SparklineGroup > pSparklineGroup)
void Repeat(SfxRepeatTarget &rTarget) override
bool CanRepeat(SfxRepeatTarget &rTarget) const override
OUString GetComment() const override
std::shared_ptr< sc::SparklineGroup > m_pSparklineGroup
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90