umbrello API Documentation

assocrolepage.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2003-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "assocrolepage.h"
00014 
00015 // qt includes
00016 #include <qlayout.h>
00017 
00018 // kde includes
00019 #include <klocale.h>
00020 #include <kmessagebox.h>
00021 #include <kdebug.h>
00022 
00023 // local includes
00024 #include "../dialog_utils.h"
00025 
00026 AssocRolePage::AssocRolePage (UMLDoc *d, QWidget *parent, AssociationWidget *assoc)
00027         : QWidget(parent)
00028 {
00029 
00030     m_pAssociationWidget = assoc;
00031     m_pWidget = 0;
00032     m_pUmldoc = d;
00033 
00034     m_pRoleALE = 0;
00035     m_pRoleBLE = 0;
00036     m_pMultiALE = 0;
00037     m_pMultiBLE = 0;
00038 
00039     constructWidget();
00040 
00041 }
00042 
00043 AssocRolePage::~AssocRolePage() {}
00044 
00045 void AssocRolePage::constructWidget() {
00046 
00047     // underlying roles and objects
00048     QString nameA = m_pAssociationWidget->getRoleName(Uml::A);
00049     QString nameB = m_pAssociationWidget->getRoleName(Uml::B);
00050     QString titleA = i18n("Role A Properties");
00051     QString titleB = i18n("Role B Properties");
00052     QString widgetNameA = m_pAssociationWidget->getWidget(Uml::A)->getName();
00053     QString widgetNameB = m_pAssociationWidget->getWidget(Uml::B)->getName();
00054     if(!widgetNameA.isEmpty())
00055         titleA.append(" (" + widgetNameA + ')');
00056     if(!widgetNameB.isEmpty())
00057         titleB.append(" (" + widgetNameB + ')');
00058 
00059     // general configuration of the GUI
00060     int margin = fontMetrics().height();
00061     
00062     QGridLayout * mainLayout = new QGridLayout(this, 4, 2);
00063     mainLayout -> setSpacing(6);
00064 
00065     // group boxes for role, documentation properties
00066     QGroupBox *propsAGB = new QGroupBox(this);
00067     QGroupBox *propsBGB = new QGroupBox(this);
00068     QButtonGroup * scopeABG = new QButtonGroup(i18n("Role A Visibility"), this );
00069     QButtonGroup * scopeBBG = new QButtonGroup(i18n("Role B Visibility"), this );
00070     QButtonGroup * changeABG = new QButtonGroup(i18n("Role A Changeability"), this );
00071     QButtonGroup * changeBBG = new QButtonGroup(i18n("Role B Changeability"), this );
00072     QGroupBox *docAGB = new QGroupBox(this);
00073     QGroupBox *docBGB = new QGroupBox(this);
00074     propsAGB -> setTitle(titleA);
00075     propsBGB -> setTitle(titleB);
00076     docAGB -> setTitle(i18n("Documentation"));
00077     docBGB -> setTitle(i18n("Documentation"));
00078     
00079     QGridLayout * propsALayout = new QGridLayout(propsAGB, 2, 2);
00080     propsALayout -> setSpacing(6);
00081     propsALayout -> setMargin(margin);
00082 
00083     QGridLayout * propsBLayout = new QGridLayout(propsBGB, 3, 2);
00084     propsBLayout -> setSpacing(6);
00085     propsBLayout -> setMargin(margin);
00086 
00087     // Properties
00088     //
00089 
00090     // Rolename A
00091     QLabel *pRoleAL = NULL;
00092     Dialog_Utils::makeLabeledEditField( propsAGB, propsALayout, 0,
00093                                     pRoleAL, i18n("Rolename:"),
00094                                     m_pRoleALE, nameA );
00095 
00096     // Multi A
00097     QLabel *pMultiAL = NULL;
00098     Dialog_Utils::makeLabeledEditField( propsAGB, propsALayout, 1,
00099                                     pMultiAL, i18n("Multiplicity:"),
00100                                     m_pMultiALE, m_pAssociationWidget->getMulti(Uml::A) );
00101 
00102     // Visibility A
00103     QHBoxLayout * scopeALayout = new QHBoxLayout(scopeABG);
00104     scopeALayout -> setMargin(margin);
00105 
00106     m_PublicARB = new QRadioButton(i18n("Public"), scopeABG);
00107     scopeALayout -> addWidget(m_PublicARB);
00108 
00109     m_PrivateARB = new QRadioButton(i18n("Private"), scopeABG);
00110     scopeALayout -> addWidget(m_PrivateARB);
00111 
00112     m_ProtectedARB = new QRadioButton(i18n("Protected"), scopeABG);
00113     scopeALayout -> addWidget(m_ProtectedARB);
00114 
00115     m_ImplementationARB = new QRadioButton(i18n("Implementation"), scopeABG);
00116     scopeALayout -> addWidget(m_ImplementationARB);
00117 
00118     Uml::Visibility scope = m_pAssociationWidget->getVisibility(Uml::A);
00119     if( scope == Uml::Visibility::Public )
00120         m_PublicARB -> setChecked( true );
00121     else if( scope == Uml::Visibility::Private )
00122       m_PrivateARB -> setChecked( true );
00123     else if( scope == Uml::Visibility::Implementation )
00124       m_PrivateARB -> setChecked( true );
00125     else
00126       m_ProtectedARB -> setChecked( true );
00127 
00128     // Changeability A
00129     QHBoxLayout * changeALayout = new QHBoxLayout(changeABG);
00130     changeALayout -> setMargin(margin);
00131 
00132     m_ChangeableARB = new QRadioButton(i18n("Changeable"), changeABG);
00133     changeALayout -> addWidget(m_ChangeableARB);
00134 
00135     m_FrozenARB = new QRadioButton(i18n("Frozen"), changeABG);
00136     changeALayout -> addWidget(m_FrozenARB);
00137 
00138     m_AddOnlyARB = new QRadioButton(i18n("Add only"), changeABG);
00139     changeALayout -> addWidget(m_AddOnlyARB);
00140 
00141     Uml::Changeability_Type changeability = m_pAssociationWidget->getChangeability(Uml::A);
00142     if( changeability == Uml::chg_Changeable )
00143         m_ChangeableARB -> setChecked( true );
00144     else if( changeability == Uml::chg_Frozen )
00145         m_FrozenARB -> setChecked( true );
00146     else
00147         m_AddOnlyARB -> setChecked( true );
00148 
00149     // Rolename B
00150     QLabel * pRoleBL = NULL;
00151     Dialog_Utils::makeLabeledEditField( propsBGB, propsBLayout, 0,
00152                                     pRoleBL, i18n("Rolename:"),
00153                                     m_pRoleBLE, nameB );
00154 
00155     // Multi B
00156     QLabel * pMultiBL = NULL;
00157     Dialog_Utils::makeLabeledEditField( propsBGB, propsBLayout, 1,
00158                                     pMultiBL, i18n("Multiplicity:"),
00159                                     m_pMultiBLE, m_pAssociationWidget->getMulti(Uml::B) );
00160 
00161     // Visibility B
00162 
00163     QHBoxLayout * scopeBLayout = new QHBoxLayout(scopeBBG);
00164     scopeBLayout -> setMargin(margin);
00165 
00166     m_PublicBRB = new QRadioButton(i18n("Public"), scopeBBG);
00167     scopeBLayout -> addWidget(m_PublicBRB);
00168 
00169     m_PrivateBRB = new QRadioButton(i18n("Private"), scopeBBG);
00170     scopeBLayout -> addWidget(m_PrivateBRB);
00171 
00172     m_ProtectedBRB = new QRadioButton(i18n("Protected"), scopeBBG);
00173     scopeBLayout -> addWidget(m_ProtectedBRB);
00174 
00175     m_ImplementationBRB = new QRadioButton(i18n("Implementation"), scopeBBG);
00176     scopeBLayout -> addWidget(m_ImplementationBRB);
00177 
00178     scope = m_pAssociationWidget->getVisibility(Uml::B);
00179     if( scope == Uml::Visibility::Public )
00180         m_PublicBRB -> setChecked( true );
00181     else if( scope == Uml::Visibility::Private )
00182         m_PrivateBRB -> setChecked( true );
00183     else if( scope == Uml::Visibility::Protected )
00184           m_ProtectedBRB -> setChecked( true );
00185     else
00186         m_ImplementationBRB -> setChecked( true );
00187 
00188     // Changeability B
00189     QHBoxLayout * changeBLayout = new QHBoxLayout(changeBBG);
00190     changeBLayout -> setMargin(margin);
00191 
00192     m_ChangeableBRB = new QRadioButton(i18n("Changeable"), changeBBG);
00193     changeBLayout -> addWidget(m_ChangeableBRB);
00194 
00195     m_FrozenBRB = new QRadioButton(i18n("Frozen"), changeBBG);
00196     changeBLayout -> addWidget(m_FrozenBRB);
00197 
00198     m_AddOnlyBRB = new QRadioButton(i18n("Add only"), changeBBG);
00199     changeBLayout -> addWidget(m_AddOnlyBRB);
00200 
00201     changeability = m_pAssociationWidget->getChangeability(Uml::B);
00202     if( changeability == Uml::chg_Changeable )
00203         m_ChangeableBRB -> setChecked( true );
00204     else if( changeability == Uml::chg_Frozen )
00205         m_FrozenBRB -> setChecked( true );
00206     else
00207         m_AddOnlyBRB -> setChecked( true );
00208 
00209     // Documentation
00210     //
00211 
00212     // Document A
00213     QHBoxLayout * docALayout = new QHBoxLayout(docAGB);
00214     docALayout -> setMargin(margin);
00215     m_pDocA = new QMultiLineEdit(docAGB);
00216     docALayout -> addWidget(m_pDocA);
00217     m_pDocA-> setText(m_pAssociationWidget-> getRoleDoc(Uml::A));
00218     // m_pDocA-> setText("<<not implemented yet>>");
00219     // m_pDocA-> setEnabled(false);
00220     m_pDocA->setWordWrap(QMultiLineEdit::WidgetWidth);
00221 
00222     // Document B
00223     QHBoxLayout * docBLayout = new QHBoxLayout(docBGB);
00224     docBLayout -> setMargin(margin);
00225     m_pDocB = new QMultiLineEdit(docBGB);
00226     docBLayout -> addWidget(m_pDocB);
00227     m_pDocB-> setText(m_pAssociationWidget-> getRoleDoc(Uml::B));
00228     // m_pDocB-> setEnabled(false);
00229     m_pDocB->setWordWrap(QMultiLineEdit::WidgetWidth);
00230 
00231     // add group boxes to main layout 
00232     mainLayout -> addWidget( propsAGB, 0, 0);
00233     mainLayout -> addWidget( scopeABG, 1, 0);
00234     mainLayout -> addWidget(changeABG, 2, 0);
00235     mainLayout -> addWidget(   docAGB, 3, 0);
00236     mainLayout -> addWidget( propsBGB, 0, 1);
00237     mainLayout -> addWidget( scopeBBG, 1, 1);
00238     mainLayout -> addWidget(changeBBG, 2, 1);
00239     mainLayout -> addWidget(   docBGB, 3, 1);
00240 
00241 }
00242 
00243 void AssocRolePage::updateObject() {
00244 
00245     if(m_pAssociationWidget) {
00246 
00247         // set props
00248         m_pAssociationWidget->setRoleName(m_pRoleALE->text(), Uml::A);
00249         m_pAssociationWidget->setRoleName(m_pRoleBLE->text(), Uml::B);
00250         m_pAssociationWidget->setMulti(m_pMultiALE->text(), Uml::A);
00251         m_pAssociationWidget->setMulti(m_pMultiBLE->text(), Uml::B);
00252 
00253         if(m_PrivateARB->isChecked())
00254               m_pAssociationWidget->setVisibility(Uml::Visibility::Private, Uml::A);
00255         else if(m_ProtectedARB->isChecked())
00256               m_pAssociationWidget->setVisibility(Uml::Visibility::Protected, Uml::A);
00257         else if(m_PublicARB->isChecked())
00258             m_pAssociationWidget->setVisibility(Uml::Visibility::Public, Uml::A);
00259         else if(m_ImplementationARB->isChecked())
00260               m_pAssociationWidget->setVisibility(Uml::Visibility::Implementation, Uml::A);
00261 
00262         if(m_PrivateBRB->isChecked())
00263               m_pAssociationWidget->setVisibility(Uml::Visibility::Private, Uml::B);
00264         else if(m_ProtectedBRB->isChecked())
00265               m_pAssociationWidget->setVisibility(Uml::Visibility::Protected, Uml::B);
00266         else if(m_PublicBRB->isChecked())
00267               m_pAssociationWidget->setVisibility(Uml::Visibility::Public, Uml::B);
00268         else if(m_ImplementationBRB->isChecked())
00269               m_pAssociationWidget->setVisibility(Uml::Visibility::Implementation, Uml::B);
00270 
00271         if(m_FrozenARB->isChecked())
00272             m_pAssociationWidget->setChangeability(Uml::chg_Frozen, Uml::A);
00273         else if(m_AddOnlyARB->isChecked())
00274             m_pAssociationWidget->setChangeability(Uml::chg_AddOnly, Uml::A);
00275         else
00276             m_pAssociationWidget->setChangeability(Uml::chg_Changeable, Uml::A);
00277 
00278         if(m_FrozenBRB->isChecked())
00279             m_pAssociationWidget->setChangeability(Uml::chg_Frozen, Uml::B);
00280         else if(m_AddOnlyBRB->isChecked())
00281             m_pAssociationWidget->setChangeability(Uml::chg_AddOnly, Uml::B);
00282         else
00283             m_pAssociationWidget->setChangeability(Uml::chg_Changeable, Uml::B);
00284 
00285         m_pAssociationWidget->setRoleDoc(m_pDocA->text(), Uml::A);
00286         m_pAssociationWidget->setRoleDoc(m_pDocB->text(), Uml::B);
00287 
00288     } //end if m_pAssociationWidget
00289 
00290 }
00291 
00292 
00293 #include "assocrolepage.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:54 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003