/** * Delete an item from the tree. * @param item the tree widget item * @param obj the uml object */ void RefactoringAssistant::deleteItem(QTreeWidgetItem *item, UMLObject *obj) { UMLObject::ObjectType t = obj->baseType(); if (t == UMLObject::ot_Class || t == UMLObject::ot_Interface) { DEBUG(DBG_SRC) << "Delete class or interface - not yet implemented!"; //:TODO: } else if (t == UMLObject::ot_Operation) { QTreeWidgetItem *opNode = item->parent(); if (opNode) { QTreeWidgetItem *parent = opNode->parent(); UMLClassifier* c = static_cast<UMLClassifier*>(findUMLObject(parent)); if (!c) { uWarning() << "No classifier - cannot delete!"; return; } UMLOperation* op = static_cast<UMLOperation*>(obj); c->removeOperation(op); } } else if (t == UMLObject::ot_Attribute) { QTreeWidgetItem *attrNode = item->parent(); if (attrNode) { QTreeWidgetItem *parent = attrNode->parent(); UMLClassifier* c = static_cast<UMLClassifier*>(findUMLObject(parent)); if (!c) { uWarning() << "No classifier - cannot delete!"; return; } UMLAttribute* attr = static_cast<UMLAttribute*>(obj); c->removeAttribute(attr); } } else { uWarning() << "Called for unknown type " << typeid(*obj).name(); } }
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(); }