void BrowserClassInstance::compute_referenced_by(QList<BrowserNode *> & l,
                                                 BrowserNode * target)
{
    IdIterator<BrowserClassInstance> it(all);
    while(it.hasNext()){
        it.next();
        if(it.value()) {
        if (!it.value()->deletedp()) {
            ClassInstanceData * data = it.value()->def;
            bool add = (data->get_class() == target);

            if (!add && (target->get_type() == UmlAttribute)) {
                const QList<SlotAttr> & attrs = data->get_attributes();
                QList<SlotAttr>::ConstIterator it_a;

                for (it_a = attrs.begin(); it_a != attrs.end(); ++it_a) {
                    if ((*it_a).att == target) {
                        add = TRUE;
                        break;
                    }
                }
            }

            if (!add) {
                const QList<SlotRel> & rels = data->get_relations();
                QList<SlotRel>::ConstIterator it_r;

                for (it_r = rels.begin(); it_r != rels.end(); ++it_r) {
                    const SlotRel & slot = *it_r;

                    if ((slot.is_a) ? (slot.rel->get_start() == target)
                            : (slot.rel->get_end() == target)) {
                        add = TRUE;
                        break;
                    }

                    if (slot.value == target) {
                        add = TRUE;
                        break;
                    }
                }
            }

            if (add)
                l.append(it.value());
        }
    }
    }
}
void OdClassInstCanvas::compute_size()
{
    UmlCanvas * canvas = the_canvas();
    ClassInstanceData * data = (ClassInstanceData *) browser_node->get_data();

    used_color = (itscolor == UmlDefaultColor)
                 ? canvas->browser_diagram()->get_color(UmlClass)
                 : itscolor;

    switch (show_stereotype_properties) {
    case UmlYes:
        show_properties = TRUE;
        break;

    case UmlNo:
        show_properties = FALSE;
        break;

    default:
        // right arg set by the diagram itself
        show_properties = canvas->browser_diagram()->get_show_stereotype_properties();
    }

    QFontMetrics fm(canvas->get_font(UmlNormalUnderlinedFont));
    double zoom = canvas->zoom();
    const int two = (int)(2 * zoom);
    int wi, he;

    horiz = TRUE;

    if (!get_name().isEmpty()) {
        switch (write_horizontally) {
        case UmlYes:
            horiz = TRUE;
            break;

        case UmlNo:
            horiz = FALSE;
            break;

        default:
            // right get_classinstwritehorizontally arg set by the diagram itself
            horiz = canvas->browser_diagram()->get_classinstwritehorizontally();
        }
    }

    he = fm.height() + two + two;

    used_show_context_mode = (show_context_mode == DefaultShowContextMode)
                             ? canvas->browser_diagram()->get_classinstshowmode()
                             : show_context_mode;

    if (horiz)
        wi = fm.width(full_name());
    else {
        he += fm.height();

        int w = fm.width(get_name() + ":");

        wi = fm.width(data->get_class()->contextual_name(used_show_context_mode));

        if (w > wi)
            wi = w;
    }

    const Q3ValueList<SlotAttr> & attributes = data->get_attributes();

    if (! attributes.isEmpty()) {
        Q3ValueList<SlotAttr>::ConstIterator it = attributes.begin();
        QString egal = " = ";

        do {
            QString s = (*it).att->get_name() + egal + (*it).value;
            int w = fm.width(s);

            if (w > wi)
                wi = w;

            ++it;
        }
        while (it != attributes.end());

        he += (fm.height() + two) * attributes.count() + two + two;
    }

    if (used_color != UmlTransparent) {
        const int shadow = canvas->shadow();

        wi += shadow;
        he += shadow;
    }

    const int eight = (int)(8 * zoom);

    wi += (((ClassData *) data->get_class()->get_data())->get_is_active())
          ? eight * 3 : eight;

    int minw = (int)(zoom * CLASSINST_CANVAS_MIN_SIZE);

    if (wi < minw)
        wi = minw;

    // force odd width and height for line alignment
    DiagramCanvas::resize(wi | 1, he | 1);
}
Beispiel #3
0
void OdClassInstCanvas::draw_all_relations(OdClassInstCanvas * end) {
  QCanvasItemList all = canvas()->allItems();
  QCanvasItemList::Iterator cit;
  ClassInstanceData * d = (ClassInstanceData *) browser_node->get_data();
  const QValueList<SlotRel> & rels = d->get_relations();
  QValueList<SlotRel>::ConstIterator it_rel;
  
  for (it_rel = rels.begin(); it_rel != rels.end(); it_rel++) {
    const SlotRel & slot_rel = *it_rel;
    
    if (!has_relation(slot_rel)) {
      BrowserClassInstance * end_inst = slot_rel.value;
      DiagramItem * di;
      
      if (end_inst == browser_node)
	di = this;
      else {	
	di = 0;
	for (cit = all.begin(); cit != all.end(); ++cit) {
	  DiagramItem * adi = QCanvasItemToDiagramItem(*cit);
	  
	  if ((adi != 0) &&		// an uml canvas item
	      (adi->type() == UmlClassInstance) &&
	      (((OdClassInstCanvas *) adi)->browser_node == end_inst) &&
	      ((((OdClassInstCanvas *) adi) == end) || (*cit)->visible())) {
	    // other class canvas find
	    di = adi;
	    break;
	  }
	}
      }
      if (di != 0) {
	if (slot_rel.is_a)
	  (new ObjectLinkCanvas(the_canvas(), this, di,
				slot_rel.rel->get_type(),
				0, -1.0, -1.0, slot_rel.rel))
	    ->show();
	else
	  (new ObjectLinkCanvas(the_canvas(), di, this,
				slot_rel.rel->get_type(),
				0, -1.0, -1.0, slot_rel.rel))
	    ->show();
      }
    }
  }
  
  if ((end == 0) &&
      !DrawingSettings::just_modified() &&
      !on_load_diagram()) {
    for (cit = all.begin(); cit != all.end(); ++cit) {
      DiagramItem * di = QCanvasItemToDiagramItem(*cit);
      
      if ((di != 0) &&	// an uml canvas item
	  (di->type() == UmlClassInstance) &&
	  (((OdClassInstCanvas *) di) != this) &&
	  !((OdClassInstCanvas *) di)->browser_node->deletedp() &&
	  ((OdClassInstCanvas *) di)->visible())
	((OdClassInstCanvas *) di)->draw_all_relations(this);
    }
  }
}