cid#1607171 Data race condition
[LibreOffice.git] / sc / source / ui / undo / UndoGroupSparklines.cxx
blob8883ea53fe75f414fb692cab8cab4c9297f32dfc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #include <undo/UndoGroupSparklines.hxx>
13 #include <globstr.hrc>
14 #include <scresid.hxx>
16 #include <Sparkline.hxx>
17 #include <SparklineGroup.hxx>
18 #include <utility>
20 namespace sc
22 UndoGroupSparklines::UndoGroupSparklines(ScDocShell& rDocShell, ScRange const& rRange,
23 std::shared_ptr<sc::SparklineGroup> pSparklineGroup)
24 : ScSimpleUndo(&rDocShell)
25 , m_aRange(rRange)
26 , m_pSparklineGroup(std::move(pSparklineGroup))
30 UndoGroupSparklines::~UndoGroupSparklines() = default;
32 void UndoGroupSparklines::Undo()
34 BeginUndo();
36 ScDocument& rDocument = pDocShell->GetDocument();
38 for (auto& rUndoData : m_aUndoData)
40 rDocument.DeleteSparkline(rUndoData.m_aAddress);
41 auto* pCreated
42 = rDocument.CreateSparkline(rUndoData.m_aAddress, rUndoData.m_pSparklineGroup);
43 pCreated->setInputRange(rUndoData.m_aDataRangeList);
46 m_aUndoData.clear();
48 pDocShell->PostPaint(m_aRange, PaintPartFlags::All);
50 EndUndo();
53 void UndoGroupSparklines::Redo()
55 BeginRedo();
57 ScDocument& rDocument = pDocShell->GetDocument();
59 for (ScAddress aAddress = m_aRange.aStart; aAddress.Col() <= m_aRange.aEnd.Col();
60 aAddress.IncCol())
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);
79 EndRedo();
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); }
88 } // end sc namespace
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */