bool UMLOperationDialog::apply() { QString name = m_pNameLE -> text(); if( name.length() == 0 ) { KMessageBox::error(this, i18n("You have entered an invalid operation name."), i18n("Operation Name Invalid"), false); m_pNameLE -> setText( m_pOperation -> getName() ); return false; } UMLClassifier *classifier = dynamic_cast<UMLClassifier*>( m_pOperation->parent() ); if( classifier != 0L && classifier->checkOperationSignature(name, m_pOperation->getParmList(), m_pOperation) ) { QString msg = QString(i18n("An operation with that signature already exists in %1.\n")).arg(classifier->getName()) + QString(i18n("Choose a different name or parameter list." )); KMessageBox::error(this, msg, i18n("Operation Name Invalid"), false); return false; } m_pOperation -> setName( name ); if( m_pPublicRB -> isChecked() ) m_pOperation -> setVisibility( Uml::Visibility::Public ); else if( m_pPrivateRB -> isChecked() ) m_pOperation -> setVisibility( Uml::Visibility::Private ); else if (m_pProtectedRB -> isChecked() ) m_pOperation -> setVisibility( Uml::Visibility::Protected ); else if (m_pImplementationRB -> isChecked() ) m_pOperation -> setVisibility( Uml::Visibility::Implementation ); QString typeName = m_pRtypeCB->currentText(); UMLTemplate *tmplParam = classifier->findTemplate(typeName); if (tmplParam) m_pOperation->setType(tmplParam); else m_pOperation->setTypeName(typeName); m_pOperation->setStereotype( m_pStereoTypeCB->currentText() ); bool isAbstract = m_pAbstractCB->isChecked(); m_pOperation -> setAbstract( isAbstract ); if (isAbstract) { /* If any operation is abstract then the owning class needs to be made abstract. The inverse is not true: The fact that no operation is abstract does not mean that the class must be non-abstract. */ classifier->setAbstract(true); } m_pOperation->setStatic( m_pStaticCB->isChecked() ); m_pOperation->setConst( m_pQueryCB->isChecked() ); return true; }
/** If clipboard has mime type application/x-uml-clip5, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip5(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); UMLListView *listView = UMLApp::app()->getListView(); UMLListViewItem* lvitem = dynamic_cast<UMLListViewItem *>( listView->currentItem() ); if (!lvitem || (lvitem->getType() != Uml::lvt_Class && lvitem->getType() != Uml::lvt_Interface)) { return false; } UMLClassifier *parent = dynamic_cast<UMLClassifier *>(lvitem->getUMLObject()); if (parent == NULL) { kError() << "UMLClipboard::pasteClip5: parent is not a UMLClassifier" << endl; return false; } UMLObjectList objects; objects.setAutoDelete(false); IDChangeLog* idchanges = 0; bool result = UMLDrag::decodeClip5(data, objects, parent); if(!result) { return false; } UMLObject *obj = 0; doc->setModified(true); idchanges = doc->getChangeLog(); // Assume success if at least one child object could be pasted if (objects.count()) result = false; for (UMLObjectListIt it(objects); (obj = it.current()) != NULL; ++it) { obj->setID(doc->assignNewID(obj->getID())); switch(obj->getBaseType()) { case Uml::ot_Attribute : { UMLObject *exist = parent->findChildObject(obj->getName(), Uml::ot_Attribute); if (exist) { QString newName = parent->uniqChildName(Uml::ot_Attribute, obj->getName()); obj->setName(newName); } UMLAttribute *att = static_cast<UMLAttribute*>(obj); if (parent->addAttribute(att, idchanges)) { result = true; } else { kError() << "UMLClipboard::pasteClip5: " << parent->getName() << "->addAttribute(" << att->getName() << ") failed" << endl; } break; } case Uml::ot_Operation : { UMLOperation *op = static_cast<UMLOperation*>(obj); UMLOperation *exist = parent->checkOperationSignature(op->getName(), op->getParmList()); if (exist) { QString newName = parent->uniqChildName(Uml::ot_Operation, obj->getName()); op->setName(newName); } if (parent->addOperation(op, idchanges)) { result = true; } else { kError() << "UMLClipboard::pasteClip5: " << parent->getName() << "->addOperation(" << op->getName() << ") failed" << endl; } break; } default : kWarning() << "pasting unknown children type in clip type 5" << endl; return false; } } return result; }
void RefactoringAssistant::movableDropEvent (QListViewItem* parentItem, QListViewItem* afterme) { //when dropping on a class, we have to put the item in the appropriate folder! UMLObject *movingObject; UMLClassifier *newClassifier; QListViewItem *movingItem; for( movingItem = firstChild(); movingItem != 0; movingItem = movingItem->itemBelow() ) { if( movingItem->isSelected() ) break; } if( !movingItem || (movingItem == afterme) || !(movingObject = findUMLObject(movingItem)) ) { kWarning()<<"Moving item not found or dropping after itself or item not found in uml obj map. aborting. (drop had already been accepted)"<<endl; return; } Uml::Object_Type t = movingObject->getBaseType(); newClassifier = dynamic_cast<UMLClassifier*>( findUMLObject( parentItem ) ); if(!newClassifier) { if ((parentItem->text(1) == "operations" && t == Uml::ot_Operation) || (parentItem->text(1) == "attributes" && t == Uml::ot_Attribute)) { newClassifier = dynamic_cast<UMLClassifier*>( findUMLObject( parentItem->parent() ) ); } if(!newClassifier) { kWarning()<<"New parent of object is not a Classifier - Drop had already been accepted - check!"<<endl; return; } } if (t == Uml::ot_Operation) {kDebug()<<"moving operation"<<endl; UMLOperation *op = static_cast<UMLOperation*>(movingObject); if(newClassifier->checkOperationSignature(op->getName(), op->getParmList())) { QString msg = QString(i18n("An operation with that signature already exists in %1.\n")).arg(newClassifier->getName()) + QString(i18n("Choose a different name or parameter list." )); KMessageBox::error(this, msg, i18n("Operation Name Invalid"), false); return; } UMLClassifier *oldClassifier = dynamic_cast<UMLClassifier*>(op->parent()); if(oldClassifier) oldClassifier->removeOperation( op ); newClassifier->addOperation( op ); } else if (t == Uml::ot_Attribute) {kDebug()<<"moving attribute - not implemented"<<endl; // UMLAttribute *att = static_cast<UMLAttribute*>(movingObject); // if(!newClassifier->checkAttributeSignature(att)) // { // QString msg = QString(i18n("An attribute with that signature already exists in %1.\n")).arg(newClassifier->getName()) // + // QString(i18n("Choose a different name or parameter list." )); // KMessageBox::error(this, msg, i18n("Operation Name Invalid"), false); // return; // } // oldClassifier->removeAttribute( att ); // newClassifier->addAttribute( att ); } //emit moved(moving, afterFirst, afterme); emit moved(); }