Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/config/SwBaselineGridConfig.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <sal/config.h>
11
12
#include <ranges>
13
14
#include <SwBaselineGridConfig.hxx>
15
#include <usrpref.hxx>
16
17
#include <o3tl/any.hxx>
18
#include <osl/diagnose.h>
19
20
#include <com/sun/star/uno/Sequence.hxx>
21
22
SwBaselineGridConfig::SwBaselineGridConfig(SwMasterUsrPref& rParent)
23
9
    : ConfigItem(u"Office.Writer/BaselineGrid"_ustr)
24
9
    , m_rParent(rParent)
25
9
{
26
9
    Load();
27
9
    EnableNotification(GetPropertyNames());
28
9
}
29
30
const css::uno::Sequence<OUString>& SwBaselineGridConfig::GetPropertyNames()
31
18
{
32
18
    static css::uno::Sequence<OUString> aNames{
33
18
        u"VisibleGrid"_ustr, // 0
34
18
    };
35
18
    return aNames;
36
18
}
37
38
void SwBaselineGridConfig::ImplCommit()
39
0
{
40
0
    const css::uno::Sequence<OUString> aNames = GetPropertyNames();
41
0
    css::uno::Sequence<css::uno::Any> aValues(aNames.getLength());
42
0
    css::uno::Any* pValues = aValues.getArray();
43
44
0
    for (sal_Int32 nProp : std::views::iota(0, aNames.getLength()))
45
0
    {
46
0
        switch (nProp)
47
0
        {
48
0
            case 0: // "VisibleGrid"
49
0
                pValues[nProp] <<= m_rParent.IsBaselineGridVisible();
50
0
                break;
51
0
        }
52
0
    }
53
0
    PutProperties(aNames, aValues);
54
0
}
55
56
void SwBaselineGridConfig::Load()
57
9
{
58
9
    const css::uno::Sequence<OUString> aNames = GetPropertyNames();
59
9
    const css::uno::Sequence<css::uno::Any> aValues = GetProperties(aNames);
60
61
9
    OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
62
9
    if (aValues.getLength() != aNames.getLength())
63
0
        return;
64
65
9
    const css::uno::Any* pValues = aValues.getConstArray();
66
9
    for (sal_Int32 nProp : std::views::iota(0, aNames.getLength()))
67
9
    {
68
9
        if (pValues[nProp].hasValue())
69
0
        {
70
0
            switch (nProp)
71
0
            {
72
0
                case 0: // "VisibleGrid"
73
0
                {
74
0
                    const bool bVisible = *o3tl::doAccess<bool>(pValues[nProp]);
75
0
                    m_rParent.SetBaselineGridVisible(bVisible);
76
0
                    break;
77
0
                }
78
0
            }
79
0
        }
80
9
    }
81
9
}
82
83
0
void SwBaselineGridConfig::Notify(const css::uno::Sequence<OUString>&) { Load(); }
84
85
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */