cid#1607171 Data race condition
[LibreOffice.git] / sc / source / ui / undo / UndoUngroupSparklines.cxx
blob8a0f629ab621523be53cb4b75409a9797ea6ff78
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/UndoUngroupSparklines.hxx>
13 #include <globstr.hrc>
14 #include <scresid.hxx>
16 #include <Sparkline.hxx>
17 #include <SparklineGroup.hxx>
19 namespace sc
21 UndoUngroupSparklines::UndoUngroupSparklines(ScDocShell& rDocShell, ScRange const& rRange)
22 : ScSimpleUndo(&rDocShell)
23 , m_aRange(rRange)
27 UndoUngroupSparklines::~UndoUngroupSparklines() = default;
29 void UndoUngroupSparklines::Undo()
31 BeginUndo();
33 ScDocument& rDocument = pDocShell->GetDocument();
35 for (SparklineUndoData& rUndoData : m_aUndoData)
37 rDocument.DeleteSparkline(rUndoData.m_aAddress);
38 auto* pCreated
39 = rDocument.CreateSparkline(rUndoData.m_aAddress, rUndoData.m_pSparklineGroup);
40 pCreated->setInputRange(rUndoData.m_aDataRangeList);
43 m_aUndoData.clear();
45 pDocShell->PostPaint(m_aRange, PaintPartFlags::All);
47 EndUndo();
50 void UndoUngroupSparklines::Redo()
52 BeginRedo();
54 ScDocument& rDocument = pDocShell->GetDocument();
56 for (ScAddress aAddress = m_aRange.aStart; aAddress.Col() <= m_aRange.aEnd.Col();
57 aAddress.IncCol())
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);
77 EndRedo();
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); }
86 } // end sc namespace
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */