[Uml-devel] KDE/kdesdk/umbrello/umbrello/dialogs
Sharan Rao
sharanrao at gmail.com
Sun Dec 14 16:03:42 UTC 2008
SVN commit 896872 by sharan:
1. Fix display of parameter names in the operation properties dialog.
2. Change interaction between the operation properties dialog box and
the param properties dialog.
M +30 -4 parmpropdlg.cpp
M +18 -4 parmpropdlg.h
M +34 -56 umloperationdialog.cpp
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/parmpropdlg.cpp #896871:896872
@@ -23,6 +23,7 @@
// kde includes
#include <klocale.h>
#include <kdebug.h>
+#include <kmessagebox.h>
// qt includes
#include <QtGui/QLayout>
@@ -226,11 +227,36 @@
return pk;
}
+bool ParmPropDlg::validate()
+{
+ // currently only validates whether the name is not null.
+ if ( getName().trimmed().length() == 0 ) {
+ KMessageBox::error(this, i18n("You have entered an invalid parameter name."),
+ i18n("Parameter Name Invalid"), false);
+ return false;
+ }
+ return true;
+}
+
+void ParmPropDlg::slotButtonClicked(int button)
+{
+ if ( button == KDialog::Ok ) {
+ if ( !validate() ) {
+ return;
+ }
+ }
+ KDialog::slotButtonClicked( button );
+}
+
void ParmPropDlg::slotOk()
{
if (m_pAtt != NULL) {
- m_pAtt->setParmKind( getParmKind() );
- m_pAtt->setStereotype( m_pStereoTypeCB->currentText() );
+
+ m_pAtt->setName( getName() ); // set the name
+ m_pAtt->setParmKind( getParmKind() ); // set the direction
+ m_pAtt->setStereotype( m_pStereoTypeCB->currentText() ); // set the stereotype
+
+ // set the type name
QString typeName = m_pTypeCB->currentText();
UMLClassifier * pConcept = dynamic_cast<UMLClassifier*>( m_pAtt->parent()->parent() );
if (pConcept == NULL) {
@@ -239,7 +265,6 @@
UMLTemplate *tmplParam = pConcept->findTemplate(typeName);
if (tmplParam) {
m_pAtt->setType(tmplParam);
- accept();
return;
}
}
@@ -263,8 +288,9 @@
m_pAtt->setType(newObj);
}
+ m_pAtt->setDoc( getDoc() ); // set the documentation
+ m_pAtt->setInitialValue( getInitialValue() ); // set the initial value
}
- accept();
}
#include "parmpropdlg.moc"
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/parmpropdlg.h #896871:896872
@@ -49,6 +49,11 @@
*/
~ParmPropDlg();
+public slots:
+ void slotOk();
+
+protected:
+
/**
* Returns the documentation.
* @return Returns the documentation.
@@ -88,10 +93,6 @@
*/
Uml::Parameter_Direction getParmKind();
-public slots:
- void slotOk();
-
-protected:
/**
* Inserts @p type into the type-combobox as well as its completion object.
* The combobox is cleared and all types together with the optional new one
@@ -108,6 +109,19 @@
*/
void insertStereotypesSorted(const QString& type = "");
+ /**
+ * Validates the fields in the dialog box.
+ */
+ bool validate();
+
+protected slots:
+
+ /**
+ * Activated when a button is clicked
+ * @param button The button that was clicked
+ */
+ virtual void slotButtonClicked(int button);
+
private:
QGroupBox * m_pParmGB, * m_pDocGB;
QGroupBox *m_pKind;
--- trunk/KDE/kdesdk/umbrello/umbrello/dialogs/umloperationdialog.cpp #896871:896872
@@ -48,7 +48,7 @@
#include <QtGui/QGridLayout>
UMLOperationDialog::UMLOperationDialog( QWidget * parent, UMLOperation * pOperation )
- : KDialog( parent)
+ : KDialog( parent)
{
setCaption( i18n("Operation Properties") );
setButtons( Help | Ok | Cancel );
@@ -178,7 +178,7 @@
// fill in parm list box
UMLAttributeList list = m_operation->getParmList();
foreach (UMLAttribute* pAtt, list ) {
- m_pParmsLW->addItem( pAtt->getName() );
+ m_pParmsLW->addItem( pAtt->toString( Uml::st_SigNoVis ) );
}
// set scope
@@ -282,24 +282,14 @@
ParmPropDlg dlg(this, m_doc, newAttribute);
result = dlg.exec();
- QString name = dlg.getName();
- pAtt = m_operation -> findParm( name );
+
if ( result ) {
- if ( name.length() == 0 ) {
- KMessageBox::error(this, i18n("You have entered an invalid parameter name."),
- i18n("Parameter Name Invalid"), false);
- delete newAttribute;
- return;
- }
+ pAtt = m_operation -> findParm( newAttribute->getName() );
+
if ( !pAtt ) {
newAttribute->setID( UniqueID::gen() );
- newAttribute->setName( name );
- newAttribute->setTypeName( dlg.getTypeName() );
- newAttribute->setInitialValue( dlg.getInitialValue() );
- newAttribute->setDoc( dlg.getDoc() );
- newAttribute->setParmKind( dlg.getParmKind() );
m_operation->addParm( newAttribute );
- m_pParmsLW->addItem( name );
+ m_pParmsLW->addItem( newAttribute->toString( Uml::st_SigNoVis ) );
m_doc->setModified( true );
} else {
KMessageBox::sorry(this, i18n("The parameter name you have chosen\nis already being used in this operation."),
@@ -313,7 +303,7 @@
void UMLOperationDialog::slotDeleteParameter()
{
- UMLAttribute* pOldAtt = m_operation->findParm( m_pParmsLW->currentItem()->text() );
+ UMLAttribute* pOldAtt = m_operation->getParmList().at( m_pParmsLW->row( m_pParmsLW->currentItem() ) );
m_operation->removeParm( pOldAtt );
m_pParmsLW->takeItem( m_pParmsLW->currentRow() );
@@ -329,53 +319,41 @@
{
int result = 0;
UMLAttribute* pAtt = 0, * pOldAtt = 0;
- pOldAtt = m_operation->findParm( m_pParmsLW->currentItem()->text() );
+ int position = m_pParmsLW->row( m_pParmsLW->currentItem() );
+ pOldAtt = m_operation->getParmList().at( position );
if ( !pOldAtt ) {
uDebug() << "THE impossible has occurred for:" << m_pParmsLW->currentItem()->text();
return;
} // should never occur
- ParmPropDlg dlg(this, m_doc, pOldAtt);
+
+ QString oldAttName = pOldAtt->getName();
+ UMLAttribute* tempAttribute = static_cast<UMLAttribute*>( pOldAtt->clone() ); // create a clone of the parameter
+
+ ParmPropDlg dlg(this, m_doc, tempAttribute); // send the clone to the properties dialog box. it will fill in the new parameters.
result = dlg.exec();
- QString name = dlg.getName();
- pAtt = m_operation->findParm( name );
+
if ( result ) {
- if ( name.length() == 0 ) {
- KMessageBox::error(this, i18n("You have entered an invalid parameter name."),
- i18n("Parameter Name Invalid"), false);
- return;
- }
- if ( !pAtt || pOldAtt->getTypeName() != dlg.getTypeName() ||
- pOldAtt->getDoc() != dlg.getDoc() ||
- pOldAtt->getInitialValue() != dlg.getInitialValue() ) {
- pOldAtt->setName( name );
- QString typeName = dlg.getTypeName();
- if (pOldAtt->getTypeName() != typeName) {
- UMLClassifierList namesList( m_doc->getConcepts() );
- bool breakFlag = false;
- foreach (UMLObject* obj, namesList) {
- if (typeName == obj->getFullyQualifiedName()) {
- pOldAtt->setType(obj);
- breakFlag = true;
- break;
- }
- }
- if (!breakFlag) {
- // Nothing found: set type name directly. Bad.
- uDebug() << typeName << " not found.";
- pOldAtt->setTypeName( typeName ); // Bad.
- }
- }
- QListWidgetItem* item = m_pParmsLW->currentItem();
- item->setText( dlg.getName() );
- pOldAtt->setDoc( dlg.getDoc() );
- pOldAtt->setInitialValue( dlg.getInitialValue() );
- m_doc->setModified( true );
- } else if( pAtt != pOldAtt ) {
+ bool namingConflict = false;
+ QString newName = tempAttribute->getName();
+
+ pAtt = m_operation->findParm( newName ); // search whether a parameter with this name already exists
+ if( pAtt && pAtt != pOldAtt ) {
KMessageBox::error(this, i18n("The parameter name you have chosen is already being used in this operation."),
i18n("Parameter Name Not Unique"), false);
+ namingConflict = true;
}
+
+ tempAttribute->copyInto( pOldAtt ); // copy all attributes from the clone
+ if ( namingConflict ) {
+ pOldAtt->setName( oldAttName ); // reset the name if there was a naming conflict
+ }
+
+ QListWidgetItem* item = m_pParmsLW->currentItem();
+ item->setText( pOldAtt->toString(Uml::st_SigNoVis) );
+ m_doc->setModified( true );
}
+ delete tempAttribute;
}
void UMLOperationDialog::slotParameterUp()
@@ -383,7 +361,7 @@
int row = m_pParmsLW->currentRow();
QListWidgetItem* item = m_pParmsLW->currentItem();
if (item) {
- UMLAttribute* pOldAtt = m_operation->findParm(item->text());
+ UMLAttribute* pOldAtt = m_operation->getParmList().at( m_pParmsLW->row( item ) );
m_operation->moveParmLeft( pOldAtt );
m_pParmsLW->takeItem(row);
@@ -402,7 +380,7 @@
int row = m_pParmsLW->currentRow();
QListWidgetItem* item = m_pParmsLW->currentItem();
if (item) {
- UMLAttribute* pOldAtt = m_operation->findParm(item->text());
+ UMLAttribute* pOldAtt = m_operation->getParmList().at( m_pParmsLW->row( item ) );
m_operation->moveParmRight( pOldAtt );
m_pParmsLW->takeItem(row);
@@ -500,7 +478,7 @@
apply();
}
-void UMLOperationDialog::slotOk()
+void UMLOperationDialog::slotOk()
{
if ( apply() ) {
accept();
More information about the umbrello-devel
mailing list