Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/func/unmovss.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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <unmovss.hxx>
21
#include <drawdoc.hxx>
22
#include <stlsheet.hxx>
23
#include <stlpool.hxx>
24
25
SdMoveStyleSheetsUndoAction::SdMoveStyleSheetsUndoAction( SdDrawDocument& rTheDoc, StyleSheetCopyResultVector& rTheStyles, bool bInserted)
26
0
: SdUndoAction(rTheDoc)
27
0
, mbMySheets( !bInserted )
28
0
{
29
0
    maStyles.swap( rTheStyles );
30
31
0
    maListOfChildLists.resize( maStyles.size() );
32
    // create list with lists of style sheet children
33
0
    std::size_t i = 0;
34
0
    for (const auto& a : maStyles)
35
0
    {
36
0
        maListOfChildLists[i++] = SdStyleSheetPool::CreateChildList(a.m_xStyleSheet.get());
37
0
    }
38
0
}
39
40
void SdMoveStyleSheetsUndoAction::Undo()
41
0
{
42
0
    SfxStyleSheetBasePool* pPool  = mrDoc.GetStyleSheetPool();
43
44
0
    if (mbMySheets)
45
0
    {
46
        // the styles have to be inserted in the pool
47
48
        // first insert all styles to the pool
49
0
        for (auto& a : maStyles)
50
0
        {
51
0
            if (!a.m_bCreatedByCopy) // tdf#119259, existed before this action, so leave it alone
52
0
                continue;
53
0
            pPool->Insert(a.m_xStyleSheet.get());
54
0
        }
55
56
        // now assign the children again
57
0
        std::vector< SdStyleSheetVector >::iterator childlistiter( maListOfChildLists.begin() );
58
0
        for (const auto& a : maStyles)
59
0
        {
60
0
            OUString aParent(a.m_xStyleSheet->GetName());
61
0
            for( auto& rxChild : *childlistiter )
62
0
            {
63
0
                rxChild->SetParent(aParent);
64
0
            }
65
0
            ++childlistiter;
66
0
        }
67
0
    }
68
0
    else
69
0
    {
70
        // remove the styles again from the pool
71
0
        for (auto& a : maStyles)
72
0
        {
73
0
            if (!a.m_bCreatedByCopy) // tdf#119259, existed before this action, so leave it alone
74
0
                continue;
75
0
            pPool->Remove(a.m_xStyleSheet.get());
76
0
        }
77
0
    }
78
0
    mbMySheets = !mbMySheets;
79
0
}
80
81
void SdMoveStyleSheetsUndoAction::Redo()
82
0
{
83
0
    Undo();
84
0
}
85
86
SdMoveStyleSheetsUndoAction::~SdMoveStyleSheetsUndoAction()
87
0
{
88
0
}
89
90
OUString SdMoveStyleSheetsUndoAction::GetComment() const
91
0
{
92
0
    return OUString();
93
0
}
94
95
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */