LibreOffice Module sc (master) 1
UndoUngroupSparklines.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
20namespace sc
21{
23 : ScSimpleUndo(&rDocShell)
24 , m_aRange(rRange)
25{
26}
27
29
31{
32 BeginUndo();
33
34 ScDocument& rDocument = pDocShell->GetDocument();
35
36 for (SparklineUndoData& rUndoData : m_aUndoData)
37 {
38 rDocument.DeleteSparkline(rUndoData.m_aAddress);
39 auto* pCreated
40 = rDocument.CreateSparkline(rUndoData.m_aAddress, rUndoData.m_pSparklineGroup);
41 pCreated->setInputRange(rUndoData.m_aDataRangeList);
42 }
43
44 m_aUndoData.clear();
45
47
48 EndUndo();
49}
50
52{
53 BeginRedo();
54
55 ScDocument& rDocument = pDocShell->GetDocument();
56
57 for (ScAddress aAddress = m_aRange.aStart; aAddress.Col() <= m_aRange.aEnd.Col();
58 aAddress.IncCol())
59 {
60 aAddress.SetRow(m_aRange.aStart.Row());
61 for (; aAddress.Row() <= m_aRange.aEnd.Row(); aAddress.IncRow())
62 {
63 if (auto pSparkline = rDocument.GetSparkline(aAddress))
64 {
65 auto const& rpGroup = pSparkline->getSparklineGroup();
66 m_aUndoData.emplace_back(aAddress, pSparkline->getInputRange(), rpGroup);
67 auto pSparklineGroupCopy
68 = std::make_shared<sc::SparklineGroup>(rpGroup->getAttributes());
69 rDocument.DeleteSparkline(aAddress);
70 auto* pCreated = rDocument.CreateSparkline(aAddress, pSparklineGroupCopy);
71 pCreated->setInputRange(pSparkline->getInputRange());
72 }
73 }
74 }
75
77
78 EndRedo();
79}
80
81void UndoUngroupSparklines::Repeat(SfxRepeatTarget& /*rTarget*/) {}
82
83bool UndoUngroupSparklines::CanRepeat(SfxRepeatTarget& /*rTarget*/) const { return false; }
84
85OUString UndoUngroupSparklines::GetComment() const { return ScResId(STR_UNDO_UNGROUP_SPARKLINES); }
86
87} // end sc namespace
88
89/* 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 ~UndoUngroupSparklines() override
std::vector< SparklineUndoData > m_aUndoData
void Repeat(SfxRepeatTarget &rTarget) override
OUString GetComment() const override
bool CanRepeat(SfxRepeatTarget &rTarget) const override
UndoUngroupSparklines(ScDocShell &rDocShell, ScRange const &rRange)
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
Previous sparkline group data, which is restored at undo ungroupping.