summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codeclassfielddeclarationblock.cpp
blob: ba7c6878634927eff885b594a8b2d85e36516dec (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

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

/*  This code generated by:
 *      Author : thomas
 *      Date   : Fri Jul 25 2003
 */

/** basicially a class to allow for syncronization of the contents based on the
 *  values of the parentClassField's parentObject
 */
#include "codeclassfielddeclarationblock.h"

#include "codeclassfield.h"
#include "umlrole.h"

// Constructors/Destructors
//

CodeClassFieldDeclarationBlock::CodeClassFieldDeclarationBlock ( CodeClassField * parentCF )
        : CodeBlockWithComments ( (CodeDocument*) parentCF->getParentDocument() ),
        OwnedCodeBlock ((UMLObject*) parentCF->getParentObject())
{
    init(parentCF);
}

CodeClassFieldDeclarationBlock::~CodeClassFieldDeclarationBlock ( ) {
    // Q: is this needed??
    //      m_parentclassfield->getParentObject()->disconnect(this);
}

//
// Methods
//

// Accessor methods
//

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

/** Get the parent object of the parentCodeClassfield
 */
UMLObject * CodeClassFieldDeclarationBlock::getParentObject ( ) {
    return m_parentclassfield->getParentObject();
}

CodeDocument * CodeClassFieldDeclarationBlock::getParentDocument ( ) {
    return TextBlock::getParentDocument();
}

// Other methods
//

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

void CodeClassFieldDeclarationBlock::forceRelease () {
    if(m_parentclassfield)
    {
        //              m_parentclassfield->getParentObject()->disconnect(this);
        m_parentclassfield->disconnect(this);
    }
    m_parentclassfield = 0;
    OwnedCodeBlock::release();
    TextBlock::release();
}

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

    setAttributesOnNode(doc, docElement);

    elem.appendChild( docElement );
}

void CodeClassFieldDeclarationBlock::loadFromXMI ( TQDomElement & root )
{
    setAttributesFromNode(root);
}

void CodeClassFieldDeclarationBlock::setAttributesOnNode (TQDomDocument & doc, TQDomElement & elem ) {

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

}

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

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

    syncToParent();
}

/** set the class attributes from a passed object
 */
void CodeClassFieldDeclarationBlock::setAttributesFromObject (TextBlock * obj) {

    CodeBlockWithComments::setAttributesFromObject(obj);

    CodeClassFieldDeclarationBlock * ccb = dynamic_cast<CodeClassFieldDeclarationBlock*>(obj);
    if(ccb)
    {
        m_parentclassfield->disconnect(this);
        init(ccb->getParentClassField());

        syncToParent();
    }

}

void CodeClassFieldDeclarationBlock::syncToParent () {

    // for role-based accessors, we DONT write ourselves out when
    // the name of the role is not defined.
    if(!(getParentClassField()->parentIsAttribute()))
    {
        UMLRole * parent = dynamic_cast<UMLRole*>(getParentObject());
        if (parent == NULL)
            return;
        if(parent->getName().isEmpty())
        {
            getComment()->setWriteOutText(false);
            setWriteOutText(false);
        } else {
            getComment()->setWriteOutText(true);
            setWriteOutText(true);
        }
    }

    // only update IF we are NOT AutoGenerated
    if(getContentType() != AutoGenerated)
        return;

    updateContent();

}

void CodeClassFieldDeclarationBlock::init (CodeClassField * parentCF)
{
    m_parentclassfield = parentCF;
    m_canDelete = false;
    connect(m_parentclassfield,TQT_SIGNAL(modified()),this,TQT_SLOT(syncToParent()));
}

#include "codeclassfielddeclarationblock.moc"