//! [11]
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (line != 0 && myMode == InsertLine) {
        QList<QGraphicsItem *> startItems = items(line->line().p1());
        if (startItems.count() && startItems.first() == line)
            startItems.removeFirst();
        QList<QGraphicsItem *> endItems = items(line->line().p2());
        if (endItems.count() && endItems.first() == line)
            endItems.removeFirst();

        removeItem(line);
        delete line;
//! [11] //! [12]

        if (startItems.count() > 0 && endItems.count() > 0 &&
            startItems.first()->type() == DiagramItem::Type &&
            endItems.first()->type() == DiagramItem::Type &&
            startItems.first() != endItems.first()) {
            DiagramItem *startItem =
                qgraphicsitem_cast<DiagramItem *>(startItems.first());
            DiagramItem *endItem =
                qgraphicsitem_cast<DiagramItem *>(endItems.first());
            Arrow *arrow = new Arrow(startItem, endItem);
            arrow->setColor(myLineColor);
            startItem->addArrow(arrow);
            endItem->addArrow(arrow);
            arrow->setZValue(-1000.0);
            addItem(arrow);
            arrow->updatePosition();
        }
    }
//! [12] //! [13]
    line = 0;
    QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
Exemple #2
0
void ArtifactCanvas::draw_all_relations() {
  if (strcmp(browser_node->get_stereotype(), "source") != 0)
    // may start association
    update_relations();
  else if (!DrawingSettings::just_modified() &&
	   !on_load_diagram()) {
    // remove all association starting from 'this'
    Q3PtrListIterator<ArrowCanvas> it(lines);
    
    while (it.current()) {
      if ((it.current()->type() == UmlContain) &&
	  (((AssocContainCanvas *) it.current())->get_start() == this))
	it.current()->delete_it();
      else
	++it;
    }
    
    // update non source artifact vis a vis 'this'
    Q3CanvasItemList all = canvas()->allItems();
    Q3CanvasItemList::Iterator cit;
    
    for (cit = all.begin(); cit != all.end(); ++cit) {
      if ((*cit)->visible()) {
	DiagramItem * adi = QCanvasItemToDiagramItem(*cit);
	
	if ((adi != 0) &&		// an uml canvas item
	    (adi->type() == UmlArtifact) &&
	    strcmp(((ArtifactCanvas *) adi)->browser_node->get_stereotype(), "source"))
	  ((ArtifactCanvas *) adi)->update_relations(this);
      }
    }
  }
}
Exemple #3
0
uint TreeDiagram::computeRows()
{
  //printf("TreeDiagram::computeRows()=%d\n",count());
  int count=0;
  QListIterator<DiagramRow> it(*this);
  DiagramRow *row;
  for (;(row=it.current()) && !row->getFirst()->isInList();++it)
  {
    count++;
  }
  //printf("count=%d row=%p\n",count,row);
  if (row)
  {
    int maxListLen=0;
    int curListLen=0;
    DiagramItem *opi=0;
    QListIterator<DiagramItem> rit(*row);
    DiagramItem *di;
    for (;(di=rit.current());++rit)
    {
      if (di->parentItem()!=opi) curListLen=1; else curListLen++; 
      if (curListLen>maxListLen) maxListLen=curListLen;
      opi=di->parentItem();
    }
    //printf("maxListLen=%d\n",maxListLen);
    count+=maxListLen;
  }
  return count;
}
Action* ActionMoveResize::apply()
{
    ActionMoveResize* undo = NULL;
    
    DiagramItem* item = NULL;
    
    if (m_revertItemID != -1)
        item = m_pItemCollector->getItemByID( m_revertItemID);
    
    if (item == NULL)
        return NULL;
    
    if (m_pPosAndSize != NULL)
    {
        undo = new ActionMoveResize (m_pItemCollector, item, item->getPosAndSize());
        item->setPosAndSize(m_pPosAndSize);
        
        // update box connections
        DiagramBox *box = dynamic_cast<DiagramBox*> (item);
        
        if (box != 0)
        {
            box->updateConnections();
            
            // item is a DiagramBox, action with DiagramBox have high priority
            undo->setHightPriority( false);
        }
    }
    
    return undo;
}
void SeqDiagramView::keyPressEvent(QKeyEvent * e)
{
    if (!window()->frozen()) {
        DiagramView::keyPressEvent(e);

        if (e->modifiers() != ::Qt::ControlModifier) {
            switch (e->key()) {
            case ::Qt::Key_Left:
            case ::Qt::Key_Up:
            case ::Qt::Key_Right:
            case ::Qt::Key_Down: {
                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->update();
                }
            }
                break;

            default:
                break;
            }
        }
    }
}
void ColDiagramView::update_msg_supports()
{
    Q3CanvasItemList l = canvas()->allItems();
    Q3CanvasItemList::Iterator it;

    for (it = l.begin(); it != l.end(); ++it) {
        if ((*it)->visible()) { // at least not deleted
            DiagramItem * di = QCanvasItemToDiagramItem(*it);

            if (di != 0) {
                switch (di->type()) {
                case UmlSelfLink:
                    ((CodSelfLinkCanvas *) di)->update_msgs();
                    break;

                case UmlLinkDirs:
                    ((CodDirsCanvas *) di)->update_msgs();
                    break;

                default:	// to avoid compiler warning
                    break;
                }
            }
        }
    }
}
Exemple #7
0
void SubjectCanvas::send(ToolCom * com, Q3CanvasItemList & all)
{
  Q3PtrList<SubjectCanvas> subjects;
  Q3CanvasItemList::Iterator cit;

  for (cit = all.begin(); cit != all.end(); ++cit) {
    DiagramItem *di = QCanvasItemToDiagramItem(*cit);
    
    if ((di != 0) && 
	(*cit)->visible() &&
	(di->type() == UmlSubject))
      subjects.append((SubjectCanvas *) di);
  }
  
  com->write_unsigned(subjects.count());
  
  SubjectCanvas * sc;
  
  for (sc = subjects.first(); sc != 0; sc = subjects.next()) {
    Q3CString s = fromUnicode(sc->name);
    
    com->write_string((const char *) s);
    com->write(sc->rect());
  }
}
Exemple #8
0
void PackageCanvas::prepare_for_move(bool on_resize) {
  if (! on_resize) {
    DiagramCanvas::prepare_for_move(on_resize);
    
    Q3CanvasItemList l = collisions(TRUE);
    Q3CanvasItemList::ConstIterator it;
    Q3CanvasItemList::ConstIterator end = l.end();
    DiagramItem * di;
    BrowserNode * p = get_bn();
  
    for (it = l.begin(); it != end; ++it) {
      if ((*it)->visible() && // at least not deleted
	  !(*it)->selected() &&
	  ((di = QCanvasItemToDiagramItem(*it)) != 0) &&
	  di->move_with_its_package()) {
	BrowserNode * bn = di->get_bn();
	
	do
	  bn = (BrowserNode *) bn->parent();
	while (bn->get_type() != UmlPackage);
	
	if (bn == p) {
	  the_canvas()->select(*it);
	  di->prepare_for_move(FALSE);
	}
      }
    }
  }
}
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (mouseEvent->button() != Qt::LeftButton)
        return;

    DiagramItem *item;
    switch (myMode) {
        case InsertItem:
            item = new DiagramItem(myItemType, myItemMenu);
            addItem(item);
            connect(item, SIGNAL(itemSelected(DiagramItem*)), this, SIGNAL(itemSelected(DiagramItem*)));
            connect(item, SIGNAL(PropertiesRequest(DiagramItem*)), this, SIGNAL(propertiesRequest(DiagramItem*)));
            item->setPos(mouseEvent->scenePos());
            emit itemInserted(item);
            break;
        case InsertLine:
            line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
                                        mouseEvent->scenePos()));
            addItem(line);
            break;
    default:
        ;
    }
    QGraphicsScene::mousePressEvent(mouseEvent);
}
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (mouseEvent->button() != Qt::LeftButton)
        return;

    DiagramItem *item;
    DiagramNode nod;
    QDomNode xmlNode;
    switch (myMode)
    {
        case InsertItem:
            if(((DiagramWindow*)parent())->itemListEmpty(myItemType))
                return;
            nod  = ((DiagramWindow*)parent())->returnCurrentItem(myItemType);
            xmlNode = createItemXml(nod,mouseEvent->scenePos());
            item = new DiagramItem(myItemType, myItemMenu,nod.name,
                                   xmlNode,itemCount,
                                   nod.inputs);
            itemCount++;
            addItem(item);
            item->setPos(mouseEvent->scenePos());
            diagItems.append(item);
            emit itemInserted(item);
            break;
        case InsertLine:
            line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(),
                                            mouseEvent->scenePos()));
            line->setPen(QPen(myLineColor, 2));
            addItem(line);
        break;
    default:
        ;
    }
    QGraphicsScene::mousePressEvent(mouseEvent);
}
// if elt parent is present, force inside it
bool ActivityContainerCanvas::force_inside(DiagramCanvas * elt, bool part)
{
  // if its parent is present, force inside it  
  Q3CanvasItemList all = elt->the_canvas()->allItems();
  Q3CanvasItemList::Iterator cit;
  BrowserNode * parent = (BrowserNode *) elt->get_bn()->parent();

  for (cit = all.begin(); cit != all.end(); ++cit) {
    if ((*cit)->visible()) {
      DiagramItem * di = QCanvasItemToDiagramItem(*cit);
      
      if ((di != 0) &&
	  IsaActivityContainer(di->type(), 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;
}
//! [3]
void DiagramScene::setItemColor(const QColor &color)
{
    myItemColor = color;
    if (isItemChange(DiagramItem::Type)) {
        DiagramItem *item = qgraphicsitem_cast<DiagramItem *>(selectedItems().first());
        item->setBrush(myItemColor);
    }
}
Exemple #13
0
bool SelectMode::onMouseDoubleClick(DiagramView* view, QMouseEvent* event) {
    if (view->scene()) {
        DiagramItem* item = dynamic_cast<DiagramItem*>(view->itemAt(event->pos()));
        if (item) {
            item->showSettings();
        }
    }
    return true;
}
Exemple #14
0
void ClassDiagramView::save(QTextStream & st, QString & warning,
			    bool copy) const {
  DiagramItemList items(canvas()->allItems());
  DiagramItem * di;
  
  if (!copy)
    // sort is useless for a copy
    items.sort();
    
  st << "format " << FILEFORMAT << "\n";
  
  // save first the classes packages fragment notes and icons
  
  for (di = items.first(); di != 0; di = items.next()) {
    switch (di->type()) {
    case UmlClass:
    case UmlNote:
    case UmlText:
    case UmlImage:
    case UmlPackage:
    case UmlFragment:
    case UmlIcon:
      if (!copy || di->copyable())
	di->save(st, FALSE, warning);
      // no break
    default:
      break;
    }
  }

  // then saves relations
  
  for (di = items.first(); di != 0; di = items.next()) {
    if (!copy || di->copyable()) {
      UmlCode k = di->type();
      
      if (IsaRelation(k) || IsaSimpleRelation(k) || (k == UmlInner))
	di->save(st, FALSE, warning);
    }
  }
  
  // then saves anchors
  
  for (di = items.first(); di != 0; di = items.next())
    if ((!copy || di->copyable()) && (di->type() == UmlAnchor))
      di->save(st, FALSE, warning);
  
  if (!copy && (preferred_zoom != 0)) {
    nl_indent(st);
    st << "preferred_whz " << preferred_size.width() << ' '
      << preferred_size.height() << ' ' << preferred_zoom;
  }
  
  nl_indent(st);
  st << "end\n";
}
Exemple #15
0
bool SelectMode::onKeyPress(DiagramView* view, QKeyEvent* event) {
    if (view->scene() && view->scene()->isActive()) {
        DiagramItem* item = dynamic_cast<DiagramItem*>(view->scene()->focusItem());
        if (item && event->key() == Qt::Key_Delete) {
            item->killSelf();
            return false;
        }
    }
    return true;
}
Exemple #16
0
void UmlCanvas::del(Q3CanvasItem * i) {
  // do not delete, just hide because of a Qt's bug (?)
  i->hide();
  selected.remove(i);
  
  DiagramItem * it = QCanvasItemToDiagramItem(i);
  
  if (it != 0)
    all_items.remove(it->get_ident());
}
DiagramItem* DiagramScene::getItemById(int id)
{

    for(int i=0;i<diagItems.count();i++)
    {
        DiagramItem* tmp = diagItems.at(i);
        if(tmp->id() == id)
            return tmp;
    }
    return 0; // Null
}
Exemple #18
0
void TreeDiagram::moveChildren(DiagramItem *root,int dx)
{
  DiagramItemList *dil=root->getChildren();
  QListIterator<DiagramItem> it(*dil);
  DiagramItem *di;
  for (;(di=it.current());++it)
  {
    di->move(dx,0);
    moveChildren(di,dx);
  }
}
BrowserNode * ActivityDiagramView::container(const QPoint & p, bool part)
{
    Q3CanvasItem * ci = the_canvas()->collision(p);
    DiagramItem * di;

    return ((ci != 0) &&
            ((di = QCanvasItemToDiagramItem(ci)) != 0) &&
            IsaActivityContainer(di->type(), part))
           ? ((ActivityContainerCanvas *) di)->get_bn()
           : (BrowserNode *) window()->browser_diagram()->parent();
}
Exemple #20
0
bool SelectMode::onContextMenu(DiagramView* view, QContextMenuEvent* event) {
    if (view->scene()) {
        DiagramItem* item = dynamic_cast<DiagramItem*>(view->itemAt(event->pos()));
        if (item) {
            QMenu* menu = item->menu(view->mapToScene(event->pos()));
            menu->exec(view->viewport()->mapToGlobal(event->pos()));
            delete menu;
            return false;
        }
    }
    return true;
}
Exemple #21
0
void
DiagramBox::messageDropped(
	BPoint point,
	BMessage *message) {
	D_METHOD(("DiagramBox::messageDropped()\n"));

	DiagramItem *item = itemUnder(point);
	if (item) {
		item->messageDropped(point, message);
		return;
	}
}
Exemple #22
0
int DiagramItem::avgChildPos() const
{
  DiagramItem *di;
  int c=children->count();
  if (c==0) // no children -> don't move
    return xPos();
  if ((di=children->getFirst())->isInList()) // children should be in a list
    return di->xPos();
  if (c&1) // odd number of children -> get pos of middle child
    return children->at(c/2)->xPos();
  else // even number of children -> get middle of most middle children
    return (children->at(c/2-1)->xPos()+children->at(c/2)->xPos())/2;
}
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();
    }
}
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (line != 0 && myMode == InsertLine)
    {
        QList<QGraphicsItem *> startItems = items(line->line().p1());
        if (startItems.count() && startItems.first() == line)
            startItems.removeFirst();
        QList<QGraphicsItem *> endItems = items(line->line().p2());
        if (endItems.count() && endItems.first() == line)
            endItems.removeFirst();

        removeItem(line);
        delete line;

        if (startItems.count() > 0 && endItems.count() > 0 &&
                startItems.first()->type() == Connector::Type &&
                endItems.first()->type() == Connector::Type &&
                startItems.first() != endItems.first())
        {
            Connector *startItem =
                    qgraphicsitem_cast<Connector *>(startItems.first());
            Connector *endItem =
                    qgraphicsitem_cast<Connector *>(endItems.first());
            QDomNode arrowXml =  createArrowXml(startItem,endItem);
            Arrow *arrow = new Arrow(startItem, endItem,arrowXml);

            arrowList.append(arrow);
            arrow->setColor(myLineColor);
            startItem->addArrow(arrow);
            endItem->addArrow(arrow);
            arrow->setZValue(-1000.0);
            addItem(arrow);
            arrow->updatePosition();

        }
    }

    line = 0;
    QGraphicsScene::mouseReleaseEvent(mouseEvent);
    if(myMode == MoveItem)
    {
        DiagramItem* item =(DiagramItem*)itemAt(mouseEvent->scenePos());
        if(item == 0)
            return;
        if(item->type() == DiagramItem::Type)
            {
                item->updatePoz();
                ((DiagramWindow*)parent())->updateXml();
            }
    }
}
Exemple #25
0
void
DiagramBox::_setOwner(
	DiagramView *owner) {
	D_METHOD(("DiagramBox::_setOwner()\n"));

	m_view = owner;
	for (uint32 i = 0; i < countItems(DiagramItem::M_ENDPOINT); i++) {
		DiagramItem *item = itemAt(i);
		item->_setOwner(m_view);
		if (m_view) {
			item->attachedToDiagram();
		}
	}
}
//! [1]
bool MoveCommand::mergeWith(const QUndoCommand *command)
{
    const MoveCommand *moveCommand = static_cast<const MoveCommand *>(command);
    DiagramItem *item = moveCommand->myDiagramItem;

    if (myDiagramItem != item)
    return false;

    newPos = item->pos();
    setText(QObject::tr("Move %1")
        .arg(createCommandString(myDiagramItem, newPos)));

    return true;
}
Exemple #27
0
bool UmlCanvas::already_drawn(BrowserNode * bn) {
  Q3CanvasItemList all = allItems();
  Q3CanvasItemList::Iterator cit;
  UmlCode k = bn->get_type();

  for (cit = all.begin(); cit != all.end(); ++cit) {
    if ((*cit)->visible()) {
      DiagramItem * di = QCanvasItemToDiagramItem(*cit);
    
      if ((di != 0) && (di->type() == k) && (di->get_bn() == bn))
	return TRUE;
    }
  }

  return FALSE;
}
void SeqDiagramView::mouseMoveEvent(QMouseEvent * e)
{
    if (!window()->frozen()) {
        DiagramView::mouseMoveEvent(e);

        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->update();
        }
    }
}
void SimpleRelationCanvas::drop(BrowserNode * bn, UmlCanvas * canvas)
{
    SimpleRelationData * def = (SimpleRelationData *) bn->get_data();
    BrowserNode * from = def->get_start_node();
    BrowserNode * to = def->get_end_node();
    DiagramItem * ccfrom = 0;
    DiagramItem * ccto = 0;
    Q3CanvasItemList all = canvas->allItems();
    Q3CanvasItemList::Iterator cit;

    // the two classes are drawn ?
    for (cit = all.begin(); cit != all.end(); ++cit) {
        if ((*cit)->visible()) {
            DiagramItem * adi = QCanvasItemToDiagramItem(*cit);

            if (adi != 0) {
                if (adi->get_bn() == from) {
                    ccfrom = adi;

                    if (ccto != 0)
                        break;
                }

                if (adi->get_bn() == to) {
                    ccto = adi;

                    if (ccfrom != 0)
                        break;
                }
            }
        }
    }

    if ((ccfrom != 0) && (ccto != 0)) {
        if (ccfrom->has_relation(def))
            msg_information("Douml", "relation already drawn");
        else {
            SimpleRelationCanvas * rel =
                new SimpleRelationCanvas(canvas, ccfrom, ccto, from,
                                         bn->get_type(), 0, -1.0, -1.0, def);

            rel->show();
            rel->package_modified();
        }
    }
}
// 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;
                }
            }
        }
    }
}