Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 66ed3476 authored by Ralf Habacker's avatar Ralf Habacker

Refactor code checking valid uml object type for a given diagram type into a...

Refactor code checking valid uml object type for a given diagram type into a new function Moodel_Utils::typeIsAllowedInDiagram().

This makes the function callable from different locations.

CCBUG:345571
parent 23ff1767
......@@ -1785,5 +1785,84 @@ QString updateDeleteActionToString(UMLForeignKeyConstraint::UpdateDeleteAction u
}
}
/**
* Return true if the object type is allowed in the related diagram
* @param o UML object instance
* @param scene diagram instance
* @return true type is allowed
* @return false type is not allowed
*/
bool typeIsAllowedInDiagram(UMLObject* o, UMLScene *scene)
{
//make sure dragging item onto correct diagram
// concept - class, seq, coll diagram
// actor, usecase - usecase diagram
UMLObject::ObjectType ot = o->baseType();
Uml::ID::Type id = o->id();
Uml::DiagramType::Enum diagramType = scene->type();
bool bAccept = true;
switch (diagramType) {
case Uml::DiagramType::UseCase:
if ((scene->widgetOnDiagram(id) && ot == UMLObject::ot_Actor) ||
(ot != UMLObject::ot_Actor && ot != UMLObject::ot_UseCase))
bAccept = false;
break;
case Uml::DiagramType::Class:
if (scene->widgetOnDiagram(id) ||
(ot != UMLObject::ot_Class &&
ot != UMLObject::ot_Package &&
ot != UMLObject::ot_Interface &&
ot != UMLObject::ot_Enum &&
ot != UMLObject::ot_Datatype)) {
bAccept = false;
}
break;
case Uml::DiagramType::Sequence:
case Uml::DiagramType::Collaboration:
if (ot != UMLObject::ot_Class &&
ot != UMLObject::ot_Interface &&
ot != UMLObject::ot_Actor)
bAccept = false;
break;
case Uml::DiagramType::Deployment:
if (scene->widgetOnDiagram(id))
bAccept = false;
else if (ot != UMLObject::ot_Interface &&
ot != UMLObject::ot_Package &&
ot != UMLObject::ot_Component &&
ot != UMLObject::ot_Class &&
ot != UMLObject::ot_Node)
bAccept = false;
else if (ot == UMLObject::ot_Package &&
o->stereotype() != QLatin1String("subsystem"))
bAccept = false;
break;
case Uml::DiagramType::Component:
if (scene->widgetOnDiagram(id) ||
(ot != UMLObject::ot_Interface &&
ot != UMLObject::ot_Package &&
ot != UMLObject::ot_Component &&
ot != UMLObject::ot_Port &&
ot != UMLObject::ot_Artifact &&
ot != UMLObject::ot_Class))
bAccept = false;
else if (ot == UMLObject::ot_Class && !o->isAbstract())
bAccept = false;
else if (ot == UMLObject::ot_Port) {
const bool componentOnDiagram = scene->widgetOnDiagram(o->umlPackage()->id());
bAccept = componentOnDiagram;
}
break;
case Uml::DiagramType::EntityRelationship:
if (ot != UMLObject::ot_Entity && ot != UMLObject::ot_Category)
bAccept = false;
break;
default:
break;
}
return bAccept;
}
} // namespace Model_Utils
......@@ -76,6 +76,7 @@ bool typeIsClassifierList(UMLListViewItem::ListViewType type);
bool typeIsClassifier(UMLListViewItem::ListViewType type);
bool typeIsAllowedInType(UMLListViewItem::ListViewType childType,
UMLListViewItem::ListViewType parentType);
bool typeIsAllowedInDiagram(UMLObject *o, UMLScene *scene);
Uml::ModelType::Enum convert_DT_MT(Uml::DiagramType::Enum dt);
UMLListViewItem::ListViewType convert_MT_LVT(Uml::ModelType::Enum mt);
......
......@@ -730,71 +730,7 @@ void UMLScene::dragEnterEvent(QGraphicsSceneDragDropEvent *e)
e->ignore();
return;
}
//make sure dragging item onto correct diagram
// concept - class, seq, coll diagram
// actor, usecase - usecase diagram
UMLObject::ObjectType ot = temp->baseType();
bool bAccept = true;
switch (diagramType) {
case DiagramType::UseCase:
if ((widgetOnDiagram(id) && ot == UMLObject::ot_Actor) ||
(ot != UMLObject::ot_Actor && ot != UMLObject::ot_UseCase))
bAccept = false;
break;
case DiagramType::Class:
if (widgetOnDiagram(id) ||
(ot != UMLObject::ot_Class &&
ot != UMLObject::ot_Package &&
ot != UMLObject::ot_Interface &&
ot != UMLObject::ot_Enum &&
ot != UMLObject::ot_Datatype)) {
bAccept = false;
}
break;
case DiagramType::Sequence:
case DiagramType::Collaboration:
if (ot != UMLObject::ot_Class &&
ot != UMLObject::ot_Interface &&
ot != UMLObject::ot_Actor)
bAccept = false;
break;
case DiagramType::Deployment:
if (widgetOnDiagram(id))
bAccept = false;
else if (ot != UMLObject::ot_Interface &&
ot != UMLObject::ot_Package &&
ot != UMLObject::ot_Component &&
ot != UMLObject::ot_Class &&
ot != UMLObject::ot_Node)
bAccept = false;
else if (ot == UMLObject::ot_Package &&
temp->stereotype() != QLatin1String("subsystem"))
bAccept = false;
break;
case DiagramType::Component:
if (widgetOnDiagram(id) ||
(ot != UMLObject::ot_Interface &&
ot != UMLObject::ot_Package &&
ot != UMLObject::ot_Component &&
ot != UMLObject::ot_Port &&
ot != UMLObject::ot_Artifact &&
ot != UMLObject::ot_Class))
bAccept = false;
else if (ot == UMLObject::ot_Class && !temp->isAbstract())
bAccept = false;
else if (ot == UMLObject::ot_Port) {
const bool componentOnDiagram = widgetOnDiagram(temp->umlPackage()->id());
DEBUG(DBG_SRC) << "ot_Port: componentOnDiagram = " << componentOnDiagram;
bAccept = componentOnDiagram;
}
break;
case DiagramType::EntityRelationship:
if (ot != UMLObject::ot_Entity && ot != UMLObject::ot_Category)
bAccept = false;
break;
default:
break;
}
bool bAccept = Model_Utils::typeIsAllowedInDiagram(temp, this);
if (bAccept) {
e->accept();
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment