summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codeaccessormethod.cpp
blob: 435e575f4c51e5f91d7571264057ddf4da63951b (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/***************************************************************************
 *                                                                         *
 *   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) 2004-2007                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

/*  This code generated by:
 *      Author : thomas
 *      Date   : Tue Jul 1 2003
 */

// own header
#include "codeaccessormethod.h"

// qt/kde includes
#include <kdebug.h>

// local includes
#include "classifiercodedocument.h"
#include "codeclassfield.h"
#include "attribute.h"
#include "umlobject.h"
#include "umlrole.h"

// Constructors/Destructors
//

CodeAccessorMethod::CodeAccessorMethod ( CodeClassField * parentCF )
        : CodeMethodBlock ( parentCF->getParentDocument(), parentCF->getParentObject() )
{
    initFields(parentCF);
}

CodeAccessorMethod::~CodeAccessorMethod ( ) { }

//
// Methods
//


// Accessor methods
//

/**
 * Get the value of m_parentclassfield
 * @return the value of m_parentclassfield
 */
CodeClassField * CodeAccessorMethod::getParentClassField ( ) {
    return m_parentclassfield;
}

bool CodeAccessorMethod::parentIsAttribute( ) {
    return getParentClassField()->parentIsAttribute();
}

/**
 * Utility method to get the value of the parent object of the parent classifield.
 * @return the value of the parent of the parent classfield
 */
/*
UMLObject * CodeAccessorMethod::getParentObject ( ) {
    return getParentClassField()->getParentObject();
}
*/

/** return the type of accessor method this is
 */
CodeAccessorMethod::AccessorType CodeAccessorMethod::getType( ) {
    return m_accessorType;
}

/** Set the type of accessor method this is
 */
void CodeAccessorMethod::setType ( CodeAccessorMethod::AccessorType atype) {
    m_accessorType = atype;
}

// Other methods
//


// this type of textblock is special
// we DON'T release it when resetTextBlocks is
// called because we re-use it over and over
// until the codeclassfield is released.
void CodeAccessorMethod::release () {
    // do nothing
}

// ok, a method so the parent can force it to release
void CodeAccessorMethod::forceRelease () {
    if(m_parentclassfield)
        m_parentclassfield->disconnect(this);
    CodeMethodBlock::release();
}

/**
 * load params from the appropriate XMI element node.
 */
void CodeAccessorMethod::loadFromXMI ( TQDomElement & root ) {
    setAttributesFromNode(root);
}

/**
 * Save the XMI representation of this object
 */
void CodeAccessorMethod::saveToXMI ( TQDomDocument & doc, TQDomElement & root ) {
    TQDomElement docElement = doc.createElement( "codeaccessormethod" );

    setAttributesOnNode(doc, docElement);

    root.appendChild( docElement );
}

/** set attributes of the node that represents this class
  * in the XMI document.
  */
void CodeAccessorMethod::setAttributesOnNode ( TQDomDocument & doc, TQDomElement & elem)
{

    // set super-class attributes
    CodeMethodBlock::setAttributesOnNode(doc, elem);

    // set local class attributes
    elem.setAttribute("accessType",getType());
    elem.setAttribute("classfield_id",getParentClassField()->getID());

}

/** set the class attributes of this object from
 * the passed element node.
 */
void CodeAccessorMethod::setAttributesFromNode ( TQDomElement & root) {

    // set attributes from the XMI
    CodeMethodBlock::setAttributesFromNode(root); // superclass load

    /*
        // I don't believe this is needed for a load from XMI. We never delete
        // accessor methods from the parent classfield.. they are essentially
        // in composition with the parent class and are arent meant to be out
        // on their own. Well, this is fine for now, but IF we start allowing
        // clipping and pasting of these methods between classes/ classfields
        // then we may have problems (ugh.. I cant imagine allowing this, but
        // perhaps someone will see a need to allow it. -b.t.)
        TQString id = root.attribute("classfield_id","-1");
        CodeClassField * newCF = 0;
        ClassifierCodeDocument * cdoc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
        if(cdoc)
                newCF = cdoc->findCodeClassFieldFromParentID (STR2ID(id));

        m_parentclassfield->disconnect(this); // always disconnect
        if(newCF)
                initFields(newCF);
        else
                kError()<<"ERROR: code accessor method cant load parent codeclassfield, corrupt file?"<<endl;

    */
    // now load/set other local attributes
    setType((AccessorType) root.attribute("accessType","0").toInt());

}

void CodeAccessorMethod::setAttributesFromObject(TextBlock * obj)
{

    CodeMethodBlock::setAttributesFromObject(obj);

    CodeAccessorMethod * mb = dynamic_cast<CodeAccessorMethod*>(obj);
    if(mb)
    {
        m_parentclassfield->disconnect(this); // always disconnect

        initFields(mb->getParentClassField());

        setType(mb->getType());
    }

}

void CodeAccessorMethod::initFields(CodeClassField * parentClassField ) {

    m_parentclassfield = parentClassField;
    m_accessorType = GET;
    m_canDelete = false; // we cant delete these with the codeeditor, delete the UML operation instead.

    connect(m_parentclassfield,TQ_SIGNAL(modified()),this,TQ_SLOT(syncToParent()));
}

#include "codeaccessormethod.moc"