Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/operation/ConvertFormulaToValueOperation.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 <operation/ConvertFormulaToValueOperation.hxx>
11
12
#include <docsh.hxx>
13
#include <editable.hxx>
14
#include <rangelst.hxx>
15
#include <undoconvert.hxx>
16
17
namespace sc
18
{
19
ConvertFormulaToValueOperation::ConvertFormulaToValueOperation(ScDocShell& rDocShell,
20
                                                               const ScRange& rRange,
21
                                                               bool bInteraction)
22
0
    : Operation(OperationType::ConvertFormulaToValue, true, !bInteraction)
23
0
    , mrDocShell(rDocShell)
24
0
    , maRange(rRange)
25
0
{
26
0
}
27
28
bool ConvertFormulaToValueOperation::runImplementation()
29
0
{
30
0
    ScDocShellModificator aModificator(mrDocShell);
31
0
    ScDocument& rDoc = mrDocShell.GetDocument();
32
33
0
    if (mbRecord && !rDoc.IsUndoEnabled())
34
0
        mbRecord = false;
35
36
0
    ScRange aRange = convertRange(maRange);
37
38
0
    ScEditableTester aTester
39
0
        = ScEditableTester::CreateAndTestRange(rDoc, aRange, sc::EditAction::Unknown);
40
0
    if (!aTester.IsEditable())
41
0
    {
42
0
        if (!mbApi)
43
0
            mrDocShell.ErrorMessage(aTester.GetMessageId());
44
0
        return false;
45
0
    }
46
47
0
    sc::TableValues aUndoVals(aRange);
48
0
    sc::TableValues* pUndoVals = mbRecord ? &aUndoVals : nullptr;
49
50
    // A formula that nothing has read since its last change has no result to convert yet
51
0
    rDoc.InterpretCellsIfNeeded(ScRangeList(aRange));
52
53
0
    rDoc.ConvertFormulaToValue(aRange, pUndoVals);
54
55
0
    if (mbRecord && pUndoVals)
56
0
    {
57
0
        mrDocShell.GetUndoManager()->AddUndoAction(
58
0
            std::make_unique<sc::UndoFormulaToValue>(mrDocShell, *pUndoVals));
59
0
    }
60
61
0
    syncSheetViews();
62
63
0
    mrDocShell.PostPaint(aRange, PaintPartFlags::Grid);
64
0
    mrDocShell.PostDataChanged();
65
0
    rDoc.BroadcastCells(aRange, SfxHintId::ScDataChanged);
66
0
    aModificator.SetDocumentModified();
67
68
0
    return true;
69
0
}
70
}
71
72
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */