1 /*
2     SPDX-License-Identifier: GPL-2.0-or-later
3     SPDX-FileCopyrightText: 2002-2020 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4 */
5 
6 #include "idchangelog.h"
7 
8 /**
9  * Constructor.
10  */
IDChangeLog()11 IDChangeLog::IDChangeLog()
12 {
13 }
14 
15 /**
16  * Copy constructor.
17  */
IDChangeLog(const IDChangeLog & Other)18 IDChangeLog::IDChangeLog(const IDChangeLog& Other)
19 {
20     m_LogArray = Other.m_LogArray;
21 }
22 
23 /**
24  * Deconstructor.
25  */
~IDChangeLog()26 IDChangeLog::~IDChangeLog()
27 {
28     for (uint i = 0; i < m_LogArray.size(); i++) {
29         delete m_LogArray.point(i);
30     }
31 }
32 
33 /**
34  * Overloaded '=' operator.
35  */
operator =(const IDChangeLog & Other)36 IDChangeLog& IDChangeLog::operator=(const IDChangeLog& Other)
37 {
38     m_LogArray = Other.m_LogArray;
39 
40     return *this;
41 }
42 
43 /**
44  * Overloaded '==' operator.
45  */
operator ==(const IDChangeLog & Other) const46 bool IDChangeLog::operator==(const IDChangeLog& Other) const
47 {
48     Q_UNUSED(Other);
49     /*It needs to be Implemented*/
50     return false;
51 }
52 
53 /**
54  * Returns the new assigned ID of the object that had OldID as its
55  * previous id.
56  */
findNewID(Uml::ID::Type OldID)57 Uml::ID::Type IDChangeLog::findNewID(Uml::ID::Type OldID)
58 {
59     for (uint i = 0; i < m_LogArray.size(); i++) {
60         if ((m_LogArray.point(i))->y() ==  OldID) {
61             return  (m_LogArray.point(i))->x();
62         }
63     }
64 
65     return Uml::ID::None;
66 }
67 
68 /**
69  * Appends another IDChangeLog to this instance of IDChangeLog and
70  * returns a reference to itself.
71  */
operator +=(const IDChangeLog & Other)72 IDChangeLog& IDChangeLog::operator+=(const IDChangeLog& Other)
73 {
74     //m_LogArray.putpoints(m_LogArray.size(), Other.m_LogArray.size(), Other)
75     uint count = Other.m_LogArray.size();
76     for (uint i = 0; i < count; i++) {
77         addIDChange((Other.m_LogArray.point(i))->y(), (Other.m_LogArray.point(i))->x());
78     }
79 
80     return *this;
81 }
82 
addIDChange(Uml::ID::Type OldID,Uml::ID::Type NewID)83 void IDChangeLog::addIDChange(Uml::ID::Type OldID, Uml::ID::Type NewID)
84 {
85     uint pos = 0;
86     if (!findIDChange(OldID, NewID, pos)) {
87         pos = m_LogArray.size();
88         m_LogArray.setPoint(pos, NewID, OldID);
89     } else {
90         m_LogArray.setPoint(pos, NewID, OldID);
91     }
92 }
93 
findOldID(Uml::ID::Type NewID)94 Uml::ID::Type IDChangeLog::findOldID(Uml::ID::Type NewID)
95 {
96     uint count = m_LogArray.size();
97     for (uint i = 0; i < count; i++) {
98         if ((m_LogArray.point(i))->x() ==  NewID) {
99             return (m_LogArray.point(i))->y();
100         }
101     }
102 
103     return Uml::ID::None;
104 }
105 
findIDChange(Uml::ID::Type OldID,Uml::ID::Type NewID,uint & pos)106 bool IDChangeLog::findIDChange(Uml::ID::Type OldID, Uml::ID::Type NewID, uint& pos)
107 {
108     uint count = m_LogArray.size();
109     for (uint i = 0; i < count; i++) {
110         if (((m_LogArray.point(i))->y() ==  OldID) && ((m_LogArray.point(i))->x() ==  NewID)) {
111             pos = i;
112             return  true;
113         }
114     }
115 
116     return false;
117 }
118 
removeChangeByNewID(Uml::ID::Type OldID)119 void IDChangeLog::removeChangeByNewID(Uml::ID::Type OldID)
120 {
121     uint count = m_LogArray.size();
122     for (uint i = 0; i < count; i++) {
123         if ((m_LogArray.point(i))->y() ==  OldID) {
124             m_LogArray.setPoint(i, Uml::ID::None, OldID);
125         }
126     }
127 }
128