summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/dialogs/assocrolepage.cpp
blob: a44a5f052909bfeaf1b78645dd70332e168b339e (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/***************************************************************************
 *                                                                         *
 *   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) 2003-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

// own header
#include "assocrolepage.h"

// qt includes
#include <tqlayout.h>

// kde includes
#include <klocale.h>
#include <kmessagebox.h>
#include <kdebug.h>

// local includes
#include "../dialog_utils.h"

AssocRolePage::AssocRolePage (UMLDoc *d, TQWidget *parent, AssociationWidget *assoc)
        : TQWidget(parent)
{

    m_pAssociationWidget = assoc;
    m_pWidget = 0;
    m_pUmldoc = d;

    m_pRoleALE = 0;
    m_pRoleBLE = 0;
    m_pMultiALE = 0;
    m_pMultiBLE = 0;

    constructWidget();

}

AssocRolePage::~AssocRolePage() {}

void AssocRolePage::constructWidget() {

    // underlying roles and objects
    TQString nameA = m_pAssociationWidget->getRoleName(Uml::A);
    TQString nameB = m_pAssociationWidget->getRoleName(Uml::B);
    TQString titleA = i18n("Role A Properties");
    TQString titleB = i18n("Role B Properties");
    TQString widgetNameA = m_pAssociationWidget->getWidget(Uml::A)->getName();
    TQString widgetNameB = m_pAssociationWidget->getWidget(Uml::B)->getName();
    if(!widgetNameA.isEmpty())
        titleA.append(" (" + widgetNameA + ')');
    if(!widgetNameB.isEmpty())
        titleB.append(" (" + widgetNameB + ')');

    // general configuration of the GUI
    int margin = fontMetrics().height();
    
    TQGridLayout * mainLayout = new TQGridLayout(this, 4, 2);
    mainLayout -> setSpacing(6);

    // group boxes for role, documentation properties
    TQGroupBox *propsAGB = new TQGroupBox(this);
    TQGroupBox *propsBGB = new TQGroupBox(this);
    TQButtonGroup * scopeABG = new TQButtonGroup(i18n("Role A Visibility"), this );
    TQButtonGroup * scopeBBG = new TQButtonGroup(i18n("Role B Visibility"), this );
    TQButtonGroup * changeABG = new TQButtonGroup(i18n("Role A Changeability"), this );
    TQButtonGroup * changeBBG = new TQButtonGroup(i18n("Role B Changeability"), this );
    TQGroupBox *docAGB = new TQGroupBox(this);
    TQGroupBox *docBGB = new TQGroupBox(this);
    propsAGB -> setTitle(titleA);
    propsBGB -> setTitle(titleB);
    docAGB -> setTitle(i18n("Documentation"));
    docBGB -> setTitle(i18n("Documentation"));
    
    TQGridLayout * propsALayout = new TQGridLayout(propsAGB, 2, 2);
    propsALayout -> setSpacing(6);
    propsALayout -> setMargin(margin);

    TQGridLayout * propsBLayout = new TQGridLayout(propsBGB, 3, 2);
    propsBLayout -> setSpacing(6);
    propsBLayout -> setMargin(margin);

    // Properties
    //

    // Rolename A
    TQLabel *pRoleAL = NULL;
    Dialog_Utils::makeLabeledEditField( propsAGB, propsALayout, 0,
                                    pRoleAL, i18n("Rolename:"),
                                    m_pRoleALE, nameA );

    // Multi A
    TQLabel *pMultiAL = NULL;
    Dialog_Utils::makeLabeledEditField( propsAGB, propsALayout, 1,
                                    pMultiAL, i18n("Multiplicity:"),
                                    m_pMultiALE, m_pAssociationWidget->getMulti(Uml::A) );

    // Visibility A
    TQHBoxLayout * scopeALayout = new TQHBoxLayout(scopeABG);
    scopeALayout -> setMargin(margin);

    m_PublicARB = new TQRadioButton(i18n("Public"), scopeABG);
    scopeALayout -> addWidget(m_PublicARB);

    m_PrivateARB = new TQRadioButton(i18n("Private"), scopeABG);
    scopeALayout -> addWidget(m_PrivateARB);

    m_ProtectedARB = new TQRadioButton(i18n("Protected"), scopeABG);
    scopeALayout -> addWidget(m_ProtectedARB);

    m_ImplementationARB = new TQRadioButton(i18n("Implementation"), scopeABG);
    scopeALayout -> addWidget(m_ImplementationARB);

    Uml::Visibility scope = m_pAssociationWidget->getVisibility(Uml::A);
    if( scope == Uml::Visibility::Public )
        m_PublicARB -> setChecked( true );
    else if( scope == Uml::Visibility::Private )
      m_PrivateARB -> setChecked( true );
    else if( scope == Uml::Visibility::Implementation )
      m_PrivateARB -> setChecked( true );
    else
      m_ProtectedARB -> setChecked( true );

    // Changeability A
    TQHBoxLayout * changeALayout = new TQHBoxLayout(changeABG);
    changeALayout -> setMargin(margin);

    m_ChangeableARB = new TQRadioButton(i18n("Changeable"), changeABG);
    changeALayout -> addWidget(m_ChangeableARB);

    m_FrozenARB = new TQRadioButton(i18n("Frozen"), changeABG);
    changeALayout -> addWidget(m_FrozenARB);

    m_AddOnlyARB = new TQRadioButton(i18n("Add only"), changeABG);
    changeALayout -> addWidget(m_AddOnlyARB);

    Uml::Changeability_Type changeability = m_pAssociationWidget->getChangeability(Uml::A);
    if( changeability == Uml::chg_Changeable )
        m_ChangeableARB -> setChecked( true );
    else if( changeability == Uml::chg_Frozen )
        m_FrozenARB -> setChecked( true );
    else
        m_AddOnlyARB -> setChecked( true );

    // Rolename B
    TQLabel * pRoleBL = NULL;
    Dialog_Utils::makeLabeledEditField( propsBGB, propsBLayout, 0,
                                    pRoleBL, i18n("Rolename:"),
                                    m_pRoleBLE, nameB );

    // Multi B
    TQLabel * pMultiBL = NULL;
    Dialog_Utils::makeLabeledEditField( propsBGB, propsBLayout, 1,
                                    pMultiBL, i18n("Multiplicity:"),
                                    m_pMultiBLE, m_pAssociationWidget->getMulti(Uml::B) );

    // Visibility B

    TQHBoxLayout * scopeBLayout = new TQHBoxLayout(scopeBBG);
    scopeBLayout -> setMargin(margin);

    m_PublicBRB = new TQRadioButton(i18n("Public"), scopeBBG);
    scopeBLayout -> addWidget(m_PublicBRB);

    m_PrivateBRB = new TQRadioButton(i18n("Private"), scopeBBG);
    scopeBLayout -> addWidget(m_PrivateBRB);

    m_ProtectedBRB = new TQRadioButton(i18n("Protected"), scopeBBG);
    scopeBLayout -> addWidget(m_ProtectedBRB);

    m_ImplementationBRB = new TQRadioButton(i18n("Implementation"), scopeBBG);
    scopeBLayout -> addWidget(m_ImplementationBRB);

    scope = m_pAssociationWidget->getVisibility(Uml::B);
    if( scope == Uml::Visibility::Public )
        m_PublicBRB -> setChecked( true );
    else if( scope == Uml::Visibility::Private )
        m_PrivateBRB -> setChecked( true );
    else if( scope == Uml::Visibility::Protected )
          m_ProtectedBRB -> setChecked( true );
    else
        m_ImplementationBRB -> setChecked( true );

    // Changeability B
    TQHBoxLayout * changeBLayout = new TQHBoxLayout(changeBBG);
    changeBLayout -> setMargin(margin);

    m_ChangeableBRB = new TQRadioButton(i18n("Changeable"), changeBBG);
    changeBLayout -> addWidget(m_ChangeableBRB);

    m_FrozenBRB = new TQRadioButton(i18n("Frozen"), changeBBG);
    changeBLayout -> addWidget(m_FrozenBRB);

    m_AddOnlyBRB = new TQRadioButton(i18n("Add only"), changeBBG);
    changeBLayout -> addWidget(m_AddOnlyBRB);

    changeability = m_pAssociationWidget->getChangeability(Uml::B);
    if( changeability == Uml::chg_Changeable )
        m_ChangeableBRB -> setChecked( true );
    else if( changeability == Uml::chg_Frozen )
        m_FrozenBRB -> setChecked( true );
    else
        m_AddOnlyBRB -> setChecked( true );

    // Documentation
    //

    // Document A
    TQHBoxLayout * docALayout = new TQHBoxLayout(docAGB);
    docALayout -> setMargin(margin);
    m_pDocA = new TQMultiLineEdit(docAGB);
    docALayout -> addWidget(m_pDocA);
    m_pDocA-> setText(m_pAssociationWidget-> getRoleDoc(Uml::A));
    // m_pDocA-> setText("<<not implemented yet>>");
    // m_pDocA-> setEnabled(false);
    m_pDocA->setWordWrap(TQMultiLineEdit::WidgetWidth);

    // Document B
    TQHBoxLayout * docBLayout = new TQHBoxLayout(docBGB);
    docBLayout -> setMargin(margin);
    m_pDocB = new TQMultiLineEdit(docBGB);
    docBLayout -> addWidget(m_pDocB);
    m_pDocB-> setText(m_pAssociationWidget-> getRoleDoc(Uml::B));
    // m_pDocB-> setEnabled(false);
    m_pDocB->setWordWrap(TQMultiLineEdit::WidgetWidth);

    // add group boxes to main tqlayout 
    mainLayout -> addWidget( propsAGB, 0, 0);
    mainLayout -> addWidget( scopeABG, 1, 0);
    mainLayout -> addWidget(changeABG, 2, 0);
    mainLayout -> addWidget(   docAGB, 3, 0);
    mainLayout -> addWidget( propsBGB, 0, 1);
    mainLayout -> addWidget( scopeBBG, 1, 1);
    mainLayout -> addWidget(changeBBG, 2, 1);
    mainLayout -> addWidget(   docBGB, 3, 1);

}

void AssocRolePage::updateObject() {

    if(m_pAssociationWidget) {

        // set props
        m_pAssociationWidget->setRoleName(m_pRoleALE->text(), Uml::A);
        m_pAssociationWidget->setRoleName(m_pRoleBLE->text(), Uml::B);
        m_pAssociationWidget->setMulti(m_pMultiALE->text(), Uml::A);
        m_pAssociationWidget->setMulti(m_pMultiBLE->text(), Uml::B);

        if(m_PrivateARB->isChecked())
              m_pAssociationWidget->setVisibility(Uml::Visibility::Private, Uml::A);
        else if(m_ProtectedARB->isChecked())
              m_pAssociationWidget->setVisibility(Uml::Visibility::Protected, Uml::A);
        else if(m_PublicARB->isChecked())
            m_pAssociationWidget->setVisibility(Uml::Visibility::Public, Uml::A);
        else if(m_ImplementationARB->isChecked())
              m_pAssociationWidget->setVisibility(Uml::Visibility::Implementation, Uml::A);

        if(m_PrivateBRB->isChecked())
              m_pAssociationWidget->setVisibility(Uml::Visibility::Private, Uml::B);
        else if(m_ProtectedBRB->isChecked())
              m_pAssociationWidget->setVisibility(Uml::Visibility::Protected, Uml::B);
        else if(m_PublicBRB->isChecked())
              m_pAssociationWidget->setVisibility(Uml::Visibility::Public, Uml::B);
        else if(m_ImplementationBRB->isChecked())
              m_pAssociationWidget->setVisibility(Uml::Visibility::Implementation, Uml::B);

        if(m_FrozenARB->isChecked())
            m_pAssociationWidget->setChangeability(Uml::chg_Frozen, Uml::A);
        else if(m_AddOnlyARB->isChecked())
            m_pAssociationWidget->setChangeability(Uml::chg_AddOnly, Uml::A);
        else
            m_pAssociationWidget->setChangeability(Uml::chg_Changeable, Uml::A);

        if(m_FrozenBRB->isChecked())
            m_pAssociationWidget->setChangeability(Uml::chg_Frozen, Uml::B);
        else if(m_AddOnlyBRB->isChecked())
            m_pAssociationWidget->setChangeability(Uml::chg_AddOnly, Uml::B);
        else
            m_pAssociationWidget->setChangeability(Uml::chg_Changeable, Uml::B);

        m_pAssociationWidget->setRoleDoc(m_pDocA->text(), Uml::A);
        m_pAssociationWidget->setRoleDoc(m_pDocB->text(), Uml::B);

    } //end if m_pAssociationWidget

}


#include "assocrolepage.moc"