Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/undo/UndoUngroupSparklines.cxx
Line
Count
Source
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
11
#include <undo/UndoUngroupSparklines.hxx>
12
13
#include <globstr.hrc>
14
#include <scresid.hxx>
15
16
#include <Sparkline.hxx>
17
#include <SparklineGroup.hxx>
18
19
namespace sc
20
{
21
UndoUngroupSparklines::UndoUngroupSparklines(ScDocShell& rShell, ScRange const& rRange)
22
0
    : ScSimpleUndo(rShell)
23
0
    , m_aRange(rRange)
24
0
{
25
0
}
26
27
0
UndoUngroupSparklines::~UndoUngroupSparklines() = default;
28
29
void UndoUngroupSparklines::Undo()
30
0
{
31
0
    BeginUndo();
32
33
0
    ScDocument& rDocument = rDocShell.GetDocument();
34
35
0
    for (SparklineUndoData& rUndoData : m_aUndoData)
36
0
    {
37
0
        rDocument.DeleteSparkline(rUndoData.m_aAddress);
38
0
        auto* pCreated
39
0
            = rDocument.CreateSparkline(rUndoData.m_aAddress, rUndoData.m_pSparklineGroup);
40
0
        pCreated->setInputRange(rUndoData.m_aDataRangeList);
41
0
    }
42
43
0
    m_aUndoData.clear();
44
45
0
    rDocShell.PostPaint(m_aRange, PaintPartFlags::All);
46
47
0
    EndUndo();
48
0
}
49
50
void UndoUngroupSparklines::Redo()
51
0
{
52
0
    BeginRedo();
53
54
0
    ScDocument& rDocument = rDocShell.GetDocument();
55
56
0
    for (ScAddress aAddress = m_aRange.aStart; aAddress.Col() <= m_aRange.aEnd.Col();
57
0
         aAddress.IncCol())
58
0
    {
59
0
        aAddress.SetRow(m_aRange.aStart.Row());
60
0
        for (; aAddress.Row() <= m_aRange.aEnd.Row(); aAddress.IncRow())
61
0
        {
62
0
            if (auto pSparkline = rDocument.GetSparkline(aAddress))
63
0
            {
64
0
                auto const& rpGroup = pSparkline->getSparklineGroup();
65
0
                m_aUndoData.emplace_back(aAddress, pSparkline->getInputRange(), rpGroup);
66
0
                auto pSparklineGroupCopy
67
0
                    = std::make_shared<sc::SparklineGroup>(rpGroup->getAttributes());
68
0
                rDocument.DeleteSparkline(aAddress);
69
0
                auto* pCreated = rDocument.CreateSparkline(aAddress, pSparklineGroupCopy);
70
0
                pCreated->setInputRange(pSparkline->getInputRange());
71
0
            }
72
0
        }
73
0
    }
74
75
0
    rDocShell.PostPaint(m_aRange, PaintPartFlags::All);
76
77
0
    EndRedo();
78
0
}
79
80
0
void UndoUngroupSparklines::Repeat(SfxRepeatTarget& /*rTarget*/) {}
81
82
0
bool UndoUngroupSparklines::CanRepeat(SfxRepeatTarget& /*rTarget*/) const { return false; }
83
84
0
OUString UndoUngroupSparklines::GetComment() const { return ScResId(STR_UNDO_UNGROUP_SPARKLINES); }
85
86
} // end sc namespace
87
88
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */