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/UndoSpillPivotTable.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
#include <undo/UndoSpillPivotTable.hxx>
11
#include <docsh.hxx>
12
#include <dpobject.hxx>
13
#include <document.hxx>
14
#include <formula/errorcodes.hxx>
15
#include <globstr.hrc>
16
#include <scresid.hxx>
17
18
namespace sc
19
{
20
UndoSpillPivotTable::UndoSpillPivotTable(ScDocShell& rNewDocShell, const OUString& rDPName,
21
                                         const ScRange& rOutputRange)
22
0
    : ScSimpleUndo(rNewDocShell)
23
0
    , maDPName(rDPName)
24
0
    , maOutputRange(rOutputRange)
25
0
{
26
0
}
27
28
0
OUString UndoSpillPivotTable::GetComment() const { return ScResId(STR_UNDO_PIVOT_MODIFY); }
29
30
void UndoSpillPivotTable::Undo()
31
0
{
32
    // Undo: go from rendered pivot table back to #SPILL! state.
33
0
    BeginUndo();
34
35
0
    ScDocument& rDocument = rDocShell.GetDocument();
36
0
    ScDPObject* pDPObject = rDocument.GetDPCollection()->GetByName(maDPName);
37
0
    if (pDPObject)
38
0
    {
39
        // Clear the rendered output.
40
0
        rDocument.DeleteAreaTab(maOutputRange, InsertDeleteFlags::ALL);
41
0
        rDocument.RemoveFlagsTab(maOutputRange.aStart.Col(), maOutputRange.aStart.Row(),
42
0
                                 maOutputRange.aEnd.Col(), maOutputRange.aEnd.Row(),
43
0
                                 maOutputRange.aStart.Tab(), ScMF::Auto);
44
45
        // Write #SPILL! into the origin cell.
46
0
        ScAddress aOrigin = maOutputRange.aStart;
47
0
        rDocument.SetError(aOrigin.Col(), aOrigin.Row(), aOrigin.Tab(), FormulaError::Spill);
48
0
        pDPObject->SetOutRange(ScRange(aOrigin));
49
0
        pDPObject->SetSpillError(true);
50
51
0
        rDocShell.PostPaint(maOutputRange, PaintPartFlags::Grid);
52
0
    }
53
54
0
    EndUndo();
55
0
}
56
57
void UndoSpillPivotTable::Redo()
58
0
{
59
    // Redo: resolve the spill and render the pivot table.
60
0
    BeginRedo();
61
62
0
    ScDocument& rDocument = rDocShell.GetDocument();
63
0
    ScDPObject* pDPObject = rDocument.GetDPCollection()->GetByName(maDPName);
64
0
    if (pDPObject)
65
0
    {
66
0
        ScAddress aOrigin = pDPObject->GetOutRange().aStart;
67
0
        pDPObject->InvalidateData();
68
0
        pDPObject->Output(aOrigin, true);
69
0
        rDocShell.PostPaintGridAll();
70
0
    }
71
72
0
    EndRedo();
73
0
}
74
75
0
void UndoSpillPivotTable::Repeat(SfxRepeatTarget& /*rTarget*/) {}
76
77
0
bool UndoSpillPivotTable::CanRepeat(SfxRepeatTarget& /*rTarget*/) const { return false; }
78
79
} // end sc namespace
80
81
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */