Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svx/source/svdraw/clonelist.cxx
Line
Count
Source (jump to first uncovered line)
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
21
// #i13033#
22
// New mechanism to hold a list of all original and cloned objects for later
23
// re-creating the connections for contained connectors
24
#include <clonelist.hxx>
25
#include <svx/svdoedge.hxx>
26
#include <svx/svdpage.hxx>
27
28
void CloneList::AddPair(const SdrObject* pOriginal, SdrObject* pClone)
29
18.2k
{
30
18.2k
    maOriginalList.push_back(pOriginal);
31
18.2k
    maCloneList.push_back(pClone);
32
33
    // look for subobjects, too.
34
18.2k
    bool bOriginalIsGroup(pOriginal->IsGroupObject());
35
18.2k
    bool bCloneIsGroup(pClone->IsGroupObject());
36
37
18.2k
    if(bOriginalIsGroup && DynCastE3dObject(pOriginal) != nullptr && DynCastE3dScene(pOriginal) == nullptr )
38
0
        bOriginalIsGroup = false;
39
40
18.2k
    if(bCloneIsGroup && DynCastE3dObject(pClone) != nullptr && DynCastE3dScene(pClone) == nullptr)
41
0
        bCloneIsGroup = false;
42
43
18.2k
    if(!(bOriginalIsGroup && bCloneIsGroup))
44
18.0k
        return;
45
46
156
    const SdrObjList* pOriginalList = pOriginal->GetSubList();
47
156
    SdrObjList* pCloneList = pClone->GetSubList();
48
49
156
    if(pOriginalList && pCloneList
50
156
        && pOriginalList->GetObjCount() == pCloneList->GetObjCount())
51
156
    {
52
373
        for(size_t a = 0; a < pOriginalList->GetObjCount(); ++a)
53
217
        {
54
            // recursive call
55
217
            AddPair(pOriginalList->GetObj(a), pCloneList->GetObj(a));
56
217
        }
57
156
    }
58
156
}
59
60
const SdrObject* CloneList::GetOriginal(sal_uInt32 nIndex) const
61
18.2k
{
62
18.2k
    return maOriginalList[nIndex];
63
18.2k
}
64
65
SdrObject* CloneList::GetClone(sal_uInt32 nIndex) const
66
18.2k
{
67
18.2k
    return maCloneList[nIndex];
68
18.2k
}
69
70
void CloneList::CopyConnections() const
71
6.91k
{
72
6.91k
    sal_uInt32 cloneCount = maCloneList.size();
73
74
25.1k
    for(size_t a = 0; a < maOriginalList.size(); a++)
75
18.2k
    {
76
18.2k
        const SdrEdgeObj* pOriginalEdge = dynamic_cast<const SdrEdgeObj*>( GetOriginal(a) );
77
18.2k
        SdrEdgeObj* pCloneEdge = dynamic_cast<SdrEdgeObj*>( GetClone(a) );
78
79
18.2k
        if(pOriginalEdge && pCloneEdge)
80
32
        {
81
32
            for (bool bTail1 : { true, false })
82
64
            {
83
64
                SdrObject* pOriginalNode = pOriginalEdge->GetConnectedNode(bTail1);
84
64
                if (pOriginalNode)
85
0
                {
86
0
                    std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
87
0
                                                                     maOriginalList.end(),
88
0
                                                                     pOriginalNode);
89
90
0
                    if(it != maOriginalList.end())
91
0
                    {
92
0
                        sal_uInt32 nPos = it - maOriginalList.begin();
93
0
                        SdrObject *cObj = nullptr;
94
95
0
                        if (nPos < cloneCount)
96
0
                            cObj = GetClone(nPos);
97
98
0
                        if(pOriginalNode != cObj)
99
0
                            pCloneEdge->ConnectToNode(bTail1, cObj);
100
0
                    }
101
0
                }
102
64
            }
103
32
        }
104
18.2k
    }
105
6.91k
}
106
107
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */