]> AND Private Git Repository - blast.git/blobdiff - ConnectionItem.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
added impl xsd + patterns in impls
[blast.git] / ConnectionItem.cpp
index dee71ba7e16d8d6ad552edae85086edf0a218867..eaf46c22482f751fd926dae6b02dd068f0fc60ec 100644 (file)
@@ -85,7 +85,7 @@ ConnectionItem::ConnectionItem(InterfaceItem* _iface1,
   setCursor(Qt::PointingHandCursor);
   setZValue(0);
 
   setCursor(Qt::PointingHandCursor);
   setZValue(0);
 
-  setPathes();
+  setPath();
 }
 
 
 }
 
 
@@ -145,8 +145,9 @@ void ConnectionItem::addInterPoint(QPointF point) {
 
 }
 
 
 }
 
-void ConnectionItem::setPathes() {
+void ConnectionItem::setPath() {
 
 
+  // signals to the scene that this connection is going to change of shape.
   prepareGeometryChange();
 
   pointFrom = fromInterfaceItem->getEndPointInGroup();
   prepareGeometryChange();
 
   pointFrom = fromInterfaceItem->getEndPointInGroup();
@@ -726,13 +727,37 @@ void ConnectionItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
 }
 
 void ConnectionItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
 }
 
 void ConnectionItem::contextMenuEvent(QGraphicsSceneContextMenuEvent * event) {
-  QMenu menu;
-  QAction* removeAction = menu.addAction("Remove");
-  QAction * selectedAction= menu.exec(event->screenPos());
+  /* have to check if the connection can be removed.
+     If the from or to InterfaceItem is owned by a group item, and this item
+     is both connected to and from, thus it is impossible to remove this connection
+   */
+  bool canRemove = true;
+  InterfaceItem* groupIfaceItem = NULL;
+  if (fromInterfaceItem->getOwner()->isGroupItem()) {
+    groupIfaceItem = fromInterfaceItem;
+  }
+  else if (toInterfaceItem->getOwner()->isGroupItem()) {
+    groupIfaceItem = toInterfaceItem;
+  }
+
+  if (groupIfaceItem != NULL) {
+    ConnectedInterface* ref = groupIfaceItem->refInter;
+    if ((ref->isConnectedFrom()) && (ref->isConnectedTo())) {
+      canRemove = false;
+    }
+  }
 
 
-  if(selectedAction == removeAction){
-    dispatcher->removeConnection(this);
-    dispatcher->removeUselessGroupInterfaces();
+  if (canRemove) {
+    QMenu menu;
+    QAction* titleAction = menu.addAction("Connection operations");
+    titleAction->setEnabled(false);
+    menu.addSeparator();
+    QAction* removeAction = menu.addAction("Remove");
+    QAction * selectedAction= menu.exec(event->screenPos());
+
+    if(selectedAction == removeAction){
+      dispatcher->removeConnection(this);
+    }
   }
 }
 
   }
 }