00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "parmpropdlg.h"
00014
00015
00016 #include <qlayout.h>
00017 #include <qtooltip.h>
00018
00019
00020 #include <klocale.h>
00021 #include <kdebug.h>
00022
00023
00024 #include "../classifier.h"
00025 #include "../umltemplatelist.h"
00026 #include "../template.h"
00027 #include "../umldoc.h"
00028 #include "../dialog_utils.h"
00029 #include "../object_factory.h"
00030 #include "../stereotype.h"
00031
00032 #include "parmpropdlg.moc"
00033
00034 ParmPropDlg::ParmPropDlg(QWidget * parent, UMLDoc * doc, UMLAttribute * a)
00035 : KDialogBase(Plain, i18n("Parameter Properties"), Help | Ok | Cancel , Ok, parent, "_PARMPROPDLG_", true, true)
00036 {
00037 m_pUmldoc = doc;
00038 m_pAtt = a;
00039 QString type, text, name, initialValue;
00040 if(!a) {
00041 type = text = name = initialValue = "";
00042 } else {
00043 type = a -> getTypeName();
00044 name = a -> getName();
00045 initialValue = a -> getInitialValue();
00046 text = a -> getDoc();
00047 }
00048 int margin = fontMetrics().height();
00049 setMinimumSize(300, 400);
00050
00051 QVBoxLayout * topLayout = new QVBoxLayout(plainPage());
00052 topLayout -> setSpacing(10);
00053 topLayout -> setMargin(margin);
00054
00055 m_pParmGB = new QGroupBox(i18n("Properties"), plainPage());
00056 topLayout -> addWidget(m_pParmGB);
00057
00058 QGridLayout * propLayout = new QGridLayout(m_pParmGB, 4, 2);
00059 propLayout -> setSpacing(10);
00060 propLayout -> setMargin(margin);
00061
00062 m_pTypeL = new QLabel(i18n("&Type:"), m_pParmGB);
00063 propLayout -> addWidget(m_pTypeL, 0, 0);
00064
00065 m_pTypeCB = new KComboBox(m_pParmGB);
00066 propLayout -> addWidget(m_pTypeCB, 0, 1);
00067 m_pTypeL->setBuddy(m_pTypeCB);
00068
00069 Dialog_Utils::makeLabeledEditField( m_pParmGB, propLayout, 1,
00070 m_pNameL, i18n("&Name:"),
00071 m_pNameLE, name );
00072
00073 Dialog_Utils::makeLabeledEditField( m_pParmGB, propLayout, 2,
00074 m_pInitialL, i18n("&Initial value:"),
00075 m_pInitialLE, initialValue );
00076
00077 m_pStereoTypeL = new QLabel( i18n("Stereotype name:"), m_pParmGB );
00078 propLayout -> addWidget(m_pStereoTypeL, 3, 0);
00079 m_pStereoTypeCB = new KComboBox(true, m_pParmGB );
00080 propLayout -> addWidget(m_pStereoTypeCB, 3, 1);
00081
00082 m_pKind = new QButtonGroup(i18n("Passing Direction"), plainPage());
00083 m_pKind->setExclusive(true);
00084 QToolTip::add(m_pKind, i18n("\"in\" is a readonly parameter, \"out\" is a writeonly parameter and \"inout\" is a parameter for reading and writing."));
00085
00086 QHBoxLayout * kindLayout = new QHBoxLayout( m_pKind );
00087 kindLayout->setMargin(margin);
00088
00089 m_pIn = new QRadioButton( "in", m_pKind );
00090 kindLayout->addWidget( m_pIn );
00091
00092 m_pInOut = new QRadioButton( "inout", m_pKind );
00093 kindLayout->addWidget( m_pInOut );
00094
00095 m_pOut = new QRadioButton( "out", m_pKind );
00096 kindLayout->addWidget( m_pOut );
00097
00098 topLayout -> addWidget(m_pKind);
00099
00100 m_pDocGB = new QGroupBox(i18n("Documentation"), plainPage());
00101 QHBoxLayout * docLayout = new QHBoxLayout(m_pDocGB);
00102 docLayout -> setMargin(margin);
00103
00104 m_pDoc = new QMultiLineEdit(m_pDocGB);
00106 m_pDoc->setWordWrap(QMultiLineEdit::WidgetWidth);
00108 m_pDoc -> setText(text);
00109 docLayout -> addWidget(m_pDoc);
00110 topLayout -> addWidget(m_pDocGB);
00111
00112
00113 if (a) {
00114 Uml::Parameter_Direction kind = a->getParmKind();
00115 if (kind == Uml::pd_Out)
00116 m_pOut->setChecked(true);
00117 else if (kind == Uml::pd_InOut)
00118 m_pInOut->setChecked(true);
00119 else
00120 m_pIn->setChecked(true);
00121 } else
00122 m_pIn->setChecked(true);
00123
00124 m_pTypeCB->setDuplicatesEnabled(false);
00125 m_pTypeCB->setEditable(true);
00126 m_pTypeCB->setCompletionMode( KGlobalSettings::CompletionPopup );
00127
00128
00129
00130 UMLClassifier *pConcept = dynamic_cast<UMLClassifier*>( m_pAtt->parent()->parent() );
00131 if (pConcept == NULL) {
00132 kError() << "ParmPropDlg: grandparent of " << m_pAtt->getName()
00133 << " is not a UMLClassifier" << endl;
00134 } else {
00135 UMLTemplateList tmplParams( pConcept->getTemplateList() );
00136 for (UMLTemplate *t = tmplParams.first(); t; t = tmplParams.next())
00137 insertType( t->getName() );
00138 }
00139
00140 UMLClassifierList namesList( m_pUmldoc->getConcepts() );
00141 UMLClassifier * obj;
00142 for(obj=namesList.first(); obj!=0 ;obj=namesList.next()) {
00143 insertType( obj->getFullyQualifiedName() );
00144 }
00145
00146
00147 int typeBoxCount = 0;
00148 bool foundType = false;
00149 while (typeBoxCount < m_pTypeCB->count() && foundType == false) {
00150 QString typeBoxString = m_pTypeCB->text(typeBoxCount);
00151 if ( typeBoxString == type ) {
00152 foundType = true;
00153 m_pTypeCB->setCurrentItem(typeBoxCount);
00154 } else {
00155 typeBoxCount++;
00156 }
00157 }
00158
00159 if (!foundType) {
00160 insertType( type, 0 );
00161 m_pTypeCB->setCurrentItem(0);
00162 }
00163
00164
00165 m_pStereoTypeCB->setDuplicatesEnabled(false);
00166 m_pStereoTypeCB->setCompletionMode( KGlobalSettings::CompletionPopup );
00167 insertStereotype (QString(""));
00168 int defaultStereotype=0;
00169 bool foundDefaultStereotype = false;
00170 for (UMLStereotypeListIt it(m_pUmldoc->getStereotypes()); it.current(); ++it) {
00171 if (!foundDefaultStereotype) {
00172 if ( m_pAtt->getStereotype() == it.current()->getName()) {
00173 foundDefaultStereotype = true;
00174 }
00175 defaultStereotype++;
00176 }
00177 insertStereotype (it.current()->getName());
00178 }
00179
00180 if (foundDefaultStereotype)
00181 m_pStereoTypeCB->setCurrentItem(defaultStereotype);
00182 else
00183 m_pStereoTypeCB->setCurrentItem(-1);
00184
00185
00186 setTabOrder(m_pKind, m_pTypeCB);
00187 setTabOrder(m_pTypeCB, m_pNameLE);
00188 setTabOrder(m_pNameLE, m_pInitialLE);
00189 setTabOrder(m_pInitialLE, m_pStereoTypeCB);
00190 setTabOrder(m_pStereoTypeCB, m_pIn);
00191 setTabOrder(m_pIn, m_pDoc);
00192
00193 m_pNameLE->setFocus();
00194 }
00195
00196 void ParmPropDlg::insertType( const QString& type, int index )
00197 {
00198 m_pTypeCB->insertItem( type, index );
00199 m_pTypeCB->completionObject()->addItem( type );
00200 }
00201
00202 void ParmPropDlg::insertStereotype( const QString& type, int index )
00203 {
00204 m_pStereoTypeCB->insertItem( type, index );
00205 m_pStereoTypeCB->completionObject()->addItem( type );
00206 }
00207
00208 Uml::Parameter_Direction ParmPropDlg::getParmKind() {
00209 Uml::Parameter_Direction pk = Uml::pd_In;
00210 if (m_pOut->isChecked())
00211 pk = Uml::pd_Out;
00212 else if (m_pInOut->isChecked())
00213 pk = Uml::pd_InOut;
00214 return pk;
00215 }
00216
00217 void ParmPropDlg::slotOk() {
00218 if (m_pAtt != NULL) {
00219 m_pAtt->setParmKind( getParmKind() );
00220 m_pAtt->setStereotype( m_pStereoTypeCB->currentText() );
00221 QString typeName = m_pTypeCB->currentText();
00222 UMLClassifier * pConcept = dynamic_cast<UMLClassifier*>( m_pAtt->parent()->parent() );
00223 if (pConcept == NULL) {
00224 kError() << "ParmPropDlg::slotOk: grandparent of " << m_pAtt->getName()
00225 << " is not a UMLClassifier" << endl;
00226 } else {
00227 UMLTemplate *tmplParam = pConcept->findTemplate(typeName);
00228 if (tmplParam) {
00229 m_pAtt->setType(tmplParam);
00230 accept();
00231 return;
00232 }
00233 }
00234 UMLClassifierList namesList( m_pUmldoc->getConcepts() );
00235 UMLClassifier * obj;
00236 for (obj = namesList.first(); obj; obj = namesList.next()) {
00237 if (obj->getFullyQualifiedName() == typeName) {
00238 m_pAtt->setType( obj );
00239 break;
00240 }
00241 }
00242 if (obj == NULL) {
00243
00244
00245
00246 kDebug() << "ParmPropDlg::slotOk: " << typeName << " not found."
00247 << " Creating a new class for the type." << endl;
00248 UMLObject *o = Object_Factory::createUMLObject(Uml::ot_Class, typeName);
00249 m_pAtt->setType(o);
00250 }
00251
00252 }
00253 accept();
00254 }
00255
00256 ParmPropDlg::~ParmPropDlg() {}
00257