// if elt parent is present, force inside it bool ActivityContainerCanvas::force_inside(DiagramCanvas * elt, bool part) { // if its parent is present, force inside it QList<QGraphicsItem*> all = elt->the_canvas()->items(); QList<QGraphicsItem*>::Iterator cit; BrowserNode * parent = (BrowserNode *) elt->get_bn()->parent(); for (cit = all.begin(); cit != all.end(); ++cit) { if ((*cit)->isVisible()) { DiagramItem * di = QCanvasItemToDiagramItem(*cit); if ((di != 0) && IsaActivityContainer(di->typeUmlCode(), part) && (((ActivityContainerCanvas *) di)->get_bn() == parent)) { BooL under = FALSE; ((ActivityContainerCanvas *) di)->force_inside(elt, elt, under); if (under) elt->upper(); return TRUE; } } } elt->upper(); return FALSE; }
void SeqDiagramView::toOverlapping() { QList<QGraphicsItem*> all = canvas()->items(); QList<QGraphicsItem*>::Iterator cit; for (cit = all.begin(); cit != all.end(); ++cit) { DiagramItem * it = QCanvasItemToDiagramItem(*cit); if ((it != 0) && // an uml canvas item (*cit)->isVisible() && (it->typeUmlCode() == UmlLifeLine)) ((SdLifeLineCanvas *) it)->toOverlapping(); } }
// update sub nodes to be upper this, recursively void ActivityContainerCanvas::force_sub_upper(QList<QGraphicsItem*> & all) { QList<QGraphicsItem*>::Iterator cit; BrowserNode * browser_node = get_bn(); for (cit = all.begin(); cit != all.end(); ++cit) { if ((*cit)->isVisible()) { DiagramItem * di = QCanvasItemToDiagramItem(*cit); if ((di != 0) && (di->get_bn() != 0) && (((BrowserNode *) di->get_bn())->parent() == browser_node)) { // must look at the type because some canvas items have browser_node // attr equals to the diagram and the parent of the diagram is the activity switch (di->typeUmlCode()) { case UmlActivityObject: case UmlActivityAction: case UmlActivityPartition: case UmlExpansionRegion: case UmlInterruptibleActivityRegion: case InitialAN: case FlowFinalAN: case ActivityFinalAN: case DecisionAN: case MergeAN: case ForkAN: case JoinAN: if ((*cit)->zValue() <= zValue()) ((DiagramCanvas *) di)->upper(); { ActivityContainerCanvas * cntr = dynamic_cast<ActivityContainerCanvas *>(di); if (cntr != 0) cntr->force_sub_upper(all); } break; default: break; } } } } }
void TextCanvas::send(ToolCom * com, QList<QGraphicsItem*> & all) { QList<QGraphicsItem*>::Iterator cit; for (cit = all.begin(); cit != all.end(); ++cit) { DiagramItem * di = QCanvasItemToDiagramItem(*cit); if ((di != 0) && (*cit)->isVisible() && (di->typeUmlCode() == UmlText)) { TextCanvas * tx = (TextCanvas *) di; WrapperStr s = fromUnicode(tx->text); com->write_bool(TRUE); // one more com->write_string((const char *) s); com->write(tx->rect()); } } com->write_bool(FALSE); // done }
// update sub nodes position to be inside this void ActivityContainerCanvas::force_sub_inside(QList<QGraphicsItem*> & all, BooL & need_sub_upper) { QList<QGraphicsItem*>::Iterator cit; BrowserNode * browser_node = get_bn(); for (cit = all.begin(); cit != all.end(); ++cit) { if ((*cit)->isVisible()/* && !(*cit)->isSelected()*/) { DiagramItem * di = QCanvasItemToDiagramItem(*cit); if ((di != 0) && (di->get_bn() != 0) && (((BrowserNode *) di->get_bn())->parent() == browser_node)) { // must look at the type because some canvas items have browser_node // attr equals to the diagram and the parent of the diagram is the activity switch (di->typeUmlCode()) { case UmlActivityObject: case UmlActivityAction: case UmlActivityPartition: case UmlExpansionRegion: case UmlInterruptibleActivityRegion: case InitialAN: case FlowFinalAN: case ActivityFinalAN: case DecisionAN: case MergeAN: case ForkAN: case JoinAN: force_inside(di, *cit, need_sub_upper); break; default: break; } } } } }
void StateDiagramView::mousePressEvent(QMouseEvent * e) { QPoint diagramPoint(e->x(), e->y()); QPointF scenePoint = mapToScene(diagramPoint); if (!window()->frozen()) { UmlCode action = window()->buttonOn(); switch (action) { case UmlState: { history_protected = TRUE; unselect_all(); window()->selectOn(); history_save(); QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint()); DiagramItem * di; bool specified = ((ci != 0) && ((di = QCanvasItemToDiagramItem(ci)) != 0) && (di->typeUmlCode() == UmlState) && ((BrowserState *)((StateCanvas *) di)->get_bn())->may_contains(action)); BrowserNode * parent; if (specified) { if ((parent = ((StateCanvas *) di)->pointed_region(scenePoint.toPoint())) == 0) parent = ((StateCanvas *) di)->get_bn(); } else parent = (BrowserNode *) window()->browser_diagram()->parent(); BrowserNode * b = BrowserState::get_state(parent); if (b != 0) { if (the_canvas()->already_drawn(b)) { msg_information("Douml", TR("already drawn")); history_protected = FALSE; return; } // may be added in a the state's region rather than the state StateCanvas * c = new StateCanvas(b, the_canvas(), scenePoint.x(), scenePoint.y()); c->show(); c->upper(); canvas()->update(); StateCanvas::force_inside(c, TRUE); canvas()->update(); history_protected = FALSE; window()->package_modified(); return; // canvas already updated } } break; case UmlRegion: { history_protected = TRUE; unselect_all(); window()->selectOn(); history_save(); QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint()); DiagramItem * di; if ((ci != 0) && ((di = QCanvasItemToDiagramItem(ci)) != 0) && (di->typeUmlCode() == UmlState) && ((BrowserState *)((StateCanvas *) di)->get_bn())->may_contains(action)) { BrowserRegion::add_region(((StateCanvas *) di)->get_bn()); window()->package_modified(); } } break; case InitialPS: case EntryPointPS: case FinalPS: case TerminatePS: case ExitPointPS: case DeepHistoryPS: case ShallowHistoryPS: case JunctionPS: case ChoicePS: case ForkPS: case JoinPS: { history_protected = TRUE; unselect_all(); window()->selectOn(); history_save(); QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint()); DiagramItem * di; bool specified = ((ci != 0) && ((di = QCanvasItemToDiagramItem(ci)) != 0) && (di->typeUmlCode() == UmlState) && ((BrowserState *)((StateCanvas *) di)->get_bn())->may_contains(action)); BrowserNode * parent; if (specified) { if ((parent = ((StateCanvas *) di)->pointed_region(scenePoint.toPoint())) == 0) parent = ((StateCanvas *) di)->get_bn(); } else parent = (BrowserNode *) window()->browser_diagram()->parent(); BrowserNode * b = BrowserPseudoState::get_pseudostate(parent, action); if (b != 0) { PseudoStateCanvas * c = // may be added in a the state's region rather than the state new PseudoStateCanvas(b, the_canvas(), scenePoint.x(), scenePoint.y()); c->show(); c->upper(); StateCanvas::force_inside(c, FALSE); window()->package_modified(); } } break; case UmlStateAction: case UmlSignalIn: case UmlSignalOut: { history_protected = TRUE; unselect_all(); window()->selectOn(); history_save(); QGraphicsItem * ci = the_canvas()->collision(scenePoint.toPoint()); DiagramItem * di; bool specified = ((ci != 0) && ((di = QCanvasItemToDiagramItem(ci)) != 0) && (di->typeUmlCode() == UmlState) && ((BrowserState *)((StateCanvas *) di)->get_bn())->may_contains(UmlStateAction)); BrowserNode * parent; if (specified) { if ((parent = ((StateCanvas *) di)->pointed_region(scenePoint.toPoint())) == 0) parent = ((StateCanvas *) di)->get_bn(); } else parent = (BrowserNode *) window()->browser_diagram()->parent(); BrowserNode * b = BrowserStateAction::add_stateaction(parent); switch (action) { case UmlSignalIn: ((StateActionData *) b->get_data())->set_stereotype("receive-signal"); break; case UmlSignalOut: ((StateActionData *) b->get_data())->set_stereotype("send-signal"); break; default: // to avoid warning break; } StateActionCanvas * c = // may be added in a the state's region rather than the state new StateActionCanvas(b, the_canvas(), scenePoint.x(), scenePoint.y()); c->show(); c->upper(); StateCanvas::force_inside(c, FALSE); window()->package_modified(); } break; default: DiagramView::mousePressEvent(e); return; } canvas()->update(); history_protected = FALSE; } else DiagramView::mousePressEvent(e); }
// resize this to contain its sub elements void ActivityContainerCanvas::resize_to_contain(QList<QGraphicsItem*> & all, BooL & need_sub_upper) { QList<QGraphicsItem*>::Iterator cit; BrowserNode * browser_node = get_bn(); QRect r = rect(); int resize_left = 0; int resize_right = 0; int resize_top = 0; int resize_bottom = 0; for (cit = all.begin(); cit != all.end(); ++cit) { if ((*cit)->isVisible() && !(*cit)->isSelected()) { DiagramItem * di = QCanvasItemToDiagramItem(*cit); if ((di != 0) && (di->get_bn() != 0) && (((BrowserNode *) di->get_bn())->parent() == browser_node)) { // must look at the type because some canvas items have browser_node // attr equals to the diagram and the parent of the diagram is the activity switch (di->typeUmlCode()) { case UmlActivityObject: case UmlActivityAction: case UmlActivityPartition: case UmlExpansionRegion: case UmlInterruptibleActivityRegion: case InitialAN: case FlowFinalAN: case ActivityFinalAN: case DecisionAN: case MergeAN: case ForkAN: case JoinAN: { QRect di_r = di->rect(); int dx = 0; int dy = 0; if (di_r.left() < r.left()) { dx = r.left() - di_r.left(); if (dx > resize_left) resize_left = dx; } if (di_r.right() > r.right()) { dx = di_r.right() - r.right(); if (dx > resize_right) resize_right = dx; } if (di_r.top() < r.top()) { dy = r.top() - di_r.top(); if (dy > resize_top) resize_top = dy; } if (di_r.bottom() > r.bottom()) { dy = di_r.bottom() - r.bottom(); if (dy > resize_bottom) resize_bottom = dy; } } need_sub_upper |= ((*cit)->zValue() <= zValue()); break; default: break; } } } } int dx = 0; int dy = 0; int dw = 0; int dh = 0; if (resize_top != 0) { dy = -resize_top; dh = resize_top; } if (resize_bottom != 0) dh += resize_bottom; if (resize_left != 0) { dx = -resize_left; dw = resize_left; } if (resize_right != 0) dw += resize_right; if ((dx != 0) || (dy != 0)) { moveBy(dx, dy); moveSelfRelsBy(dx, dy); } if ((dw != 0) || (dh != 0)) DiagramCanvas::resize(width() + dw, height() + dh); }
void ActivityContainerCanvas::prepare_for_move(bool on_resize) { if (! on_resize) { // select all sub nodes QList<QGraphicsItem*> all = canvas()->items(); QList<QGraphicsItem*>::Iterator cit; UmlCanvas * canvas = the_canvas(); for (cit = all.begin(); cit != all.end(); ++cit) { if ((*cit)->isVisible() && !(*cit)->isSelected()) { DiagramItem * di = QCanvasItemToDiagramItem(*cit); if ((di != 0) && (di->get_bn() != 0) && (((BrowserNode *) di->get_bn()->parent()) == browser_node)) { // must look at the type because some canvas items have browser_node // attr set to the diagram and the parent of the diagram is the activity switch (di->typeUmlCode()) { case UmlActivityObject: case UmlActivityAction: case UmlActivityPartition: case InitialAN: case FlowFinalAN: case ActivityFinalAN: case DecisionAN: case MergeAN: case ForkAN: case JoinAN: case UmlExpansionRegion: case UmlInterruptibleActivityRegion: canvas->select(*cit); ((DiagramCanvas *) di)->prepare_for_move(on_resize); break; default: break; } } } } // select points on lines having the two extremities selected or // connecting pin/parameter/expansion node of element selected for (cit = all.begin(); cit != all.end(); ++cit) { if ((*cit)->isVisible() && !(*cit)->isSelected() && isa_arrow(*cit)) { ArrowCanvas * ar = (ArrowCanvas *) *cit; DiagramItem * b; DiagramItem * e; ar->extremities(b, e); if (!b->isSelected() || !e->isSelected()) { DiagramItem * start = ar->get_start(); DiagramItem * dest = ar->get_end(); if ((start->isSelected() || indirectly_selected(start)) && (dest->isSelected() || indirectly_selected(dest))) { while (b->typeUmlCode() == UmlArrowPoint) { canvas->select((ArrowPointCanvas *) b); ar = ((ArrowPointCanvas *) b)->get_other(ar); ar->extremities(b, e); } ar = (ArrowCanvas *) *cit; ar->extremities(b, e); while (e->typeUmlCode() == UmlArrowPoint) { canvas->select((ArrowPointCanvas *) e); ar = ((ArrowPointCanvas *) e)->get_other(ar); ar->extremities(b, e); } } } } } } }