summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/clipboard/idchangelog.cpp
blob: 1521c1ccfcef5c84ed13d7191461fff65b34fa11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2002-2007                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

#include "idchangelog.h"

#include <kdebug.h>

IDChangeLog::IDChangeLog() {}

IDChangeLog::IDChangeLog(const IDChangeLog& Other) {
    m_LogArray = Other.m_LogArray;
}

IDChangeLog::~IDChangeLog() {}

IDChangeLog& IDChangeLog::operator=(const IDChangeLog& Other) {
    m_LogArray = Other.m_LogArray;

    return *this;
}

bool IDChangeLog::operator==(const IDChangeLog& /*Other*/) {
    /*It needs to be Implemented*/
    return false;
}

Uml::IDType IDChangeLog::findNewID(Uml::IDType OldID) {
    uint count = m_LogArray.size();
    for(uint i = 0; i < count; i++) {
        if((m_LogArray.point(i)).y() ==  OldID) {
            return  (m_LogArray.point(i)).x();
        }
    }

    return Uml::id_None;
}

IDChangeLog& IDChangeLog::operator+=(const IDChangeLog& Other) {
    //m_LogArray.putpoints(m_LogArray.size(), Other.m_LogArray.size(), Other)
    uint count = Other.m_LogArray.size();
    for(uint i = 0; i < count; i++) {
        addIDChange((Other.m_LogArray.point(i)).y(), (Other.m_LogArray.point(i)).x());
    }

    return *this;
}

void IDChangeLog::addIDChange(Uml::IDType OldID, Uml::IDType NewID) {
    uint pos;
    if(!findIDChange(OldID, NewID, pos)) {
        pos = m_LogArray.size();
        m_LogArray.resize(pos + 1);
        m_LogArray.setPoint(pos, NewID, OldID);
    } else {
        m_LogArray.setPoint(pos, NewID, OldID);
    }
}

Uml::IDType IDChangeLog::findOldID(Uml::IDType NewID) {
    uint count = m_LogArray.size();
    for(uint i = 0; i < count; i++) {
        if((m_LogArray.point(i)).x() ==  NewID) {
            return  (m_LogArray.point(i)).y();
        }
    }

    return Uml::id_None;
}

bool IDChangeLog::findIDChange(Uml::IDType OldID, Uml::IDType NewID, uint& pos) {
    uint count = m_LogArray.size();
    for(uint i = 0; i < count; i++) {
        if(((m_LogArray.point(i)).y() ==  OldID) && ((m_LogArray.point(i)).x() ==  NewID)) {
            pos = i;
            return  true;
        }
    }

    return false;
}

void IDChangeLog::removeChangeByNewID(Uml::IDType OldID) {
    uint count = m_LogArray.size();
    for(uint i = 0; i < count; i++) {
        if((m_LogArray.point(i)).y() ==  OldID) {
            m_LogArray.setPoint(i, Uml::id_None, OldID);
        }
    }
}