void ClassData::send_uml_def(ToolCom * com, BrowserNode * bn, const QString & comment) { int api = com->api_format(true); BasicData::send_uml_def(com, bn, comment); com->write_bool(FALSE); // class member if (api >= 13) com->write_bool(FALSE); // volatile com->write_char(((api >= 23) || (uml_visibility != UmlPackageVisibility)) ? uml_visibility : UmlPublic); if (api >= 30) com->write_string(constraint); com->write_bool(is_abstract); if (stereotype == "typedef") { BrowserNodeList inh; browser_node->children(inh, UmlGeneralisation, UmlRealize); if (inh.count() != 0) // first inheritance is taken in all cases ((RelationData *) inh.at(0)->get_data())->get_end_class()->write_id(com); else if (base_type.type != 0) base_type.type->write_id(com); else if (!base_type.explicit_type.isEmpty()) { com->write_id(0); com->write_string(base_type.explicit_type); } else { // no base_type, try with a dependency browser_node->children(inh, UmlDependency); if (inh.count() != 0) ((RelationData *) inh.at(0)->get_data())->get_end_class()->write_id(com); else { com->write_id(0); com->write_string(""); } } } if (api >= 48) com->write_bool(is_active); }
void BrowserOperation::instances(BrowserNodeList & result) { IdIterator<BrowserOperation> it(all); BrowserOperation * op; while(it.hasNext()){ it.next(); if ((op = it.value()) != 0) if (!op->deletedp()) result.append(op); } result.sort_it(); }
QString type(const QString & t, const QStringList & types, BrowserNodeList & nodes) { int rank = types.findIndex(t); return (rank != -1) ? QString(((BrowserClass *) nodes.at(rank))->get_name()) : t; }
void BrowserNode::children(BrowserNodeList & nodes, UmlCode kind1, UmlCode kind2) const { Q3ListViewItem * child; for (child = firstChild(); child; child = child->nextSibling()) if (!((BrowserNode *) child)->is_deleted && ((((BrowserNode *) child)->get_type() == kind1) || (((BrowserNode *) child)->get_type() == kind2))) nodes.append((BrowserNode *) child); }
void AttributeData::set_type(const QString &value) { QStringList list; BrowserNodeList nodes; BrowserClass::instances(nodes); nodes.full_names(list); AType t; if (!value.isEmpty()) { int rank = list.indexOf(value); if (rank != -1) t.type = (BrowserClass *) nodes.at(rank); else t.explicit_type = value; } set_type(t); }
bool BrowserNode::enter_child_name(QString & r, const QString & msg, UmlCode type, BrowserNodeList & nodes, BrowserNode ** old, bool allow_spaces, bool allow_empty, bool existing) { if (existing && nodes.isEmpty()) { msg_warning(TR("Error"), TR("nothing available")); return FALSE; } QStringList list; nodes.full_names(list); list.prepend(QString::null); *old = 0; for (;;) { BooL ok = FALSE; r = (list.count() == 1) ? MyInputDialog::getText("Uml", msg, QString::null, ok) : MyInputDialog::getText("Uml", msg, list, QString::null, existing, ok); if (! ok) return FALSE; if (!r.isEmpty()) { int index = list.findIndex(r); if (index != -1) { *old = nodes.at(index - 1); return TRUE; } } if (wrong_child_name(r, type, allow_spaces, allow_empty)) msg_critical(TR("Error"), r + "\n\n" + TR("illegal name or already used")); else return TRUE; } }
void QuickEdit::TypeDelegateSetup() { GenericDelegate* delegate = new GenericDelegate(ui->tvEditor, false); delegate->widgetCreator = [](QWidget* parent) { BrowserNodeList result; QStringList classes; BrowserClass::instances(result); result.full_names(classes); QStringList basics = GenerationSettings::basic_types(); classes+=basics; QCompleter* completer = new QCompleter(classes, parent); completer->setCaseSensitivity(Qt::CaseSensitive); QComboBox* box = new QComboBox(parent); QStringListModel* model = new QStringListModel; model->setStringList(classes); box->setModel(model); box->setEditable(true); box->setCompleter(completer); return box; }; delegate->dataAccessor = [](QWidget* editor, const QModelIndex& index) { QString value = index.model()->data(index, Qt::EditRole).toString(); QComboBox* box = static_cast<QComboBox*>(editor); box->setCurrentText(value); }; delegate->dataSetter = [](QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) { QComboBox* box = static_cast<QComboBox*>(editor); QString value = box->currentText(); model->setData(index, value, Qt::EditRole); }; ui->tvEditor->setItemDelegateForColumn(columns.indexOf("type"), delegate); }
AType the_type(const QString & t, const QStringList & types, BrowserNodeList & nodes) { AType result; int rank = types.findIndex(t); if (rank != -1) result.type = ((BrowserClass *) nodes.at(rank)); else result.explicit_type = t; return result; }
void ClassDiagramView::add_related_elements(DiagramItem * di, QString what, bool inh, bool assoc) { BrowserNodeList l; RelatedElementsDialog dialog(di->get_bn(), what, inh, assoc, l); dialog.raise(); if ((dialog.exec() == QDialog::Accepted) && !l.isEmpty()) { QApplication::setOverrideCursor(Qt::waitCursor); DiagramItemList items(canvas()->allItems()); Q3PtrDict<DiagramItem> drawn; get_drawn(items, drawn); history_save(); history_protected = TRUE; int xmax = canvas()->width() - Diagram_Margin; int ymax = canvas()->height() - Diagram_Margin; QRect re = di->rect(); int x = re.x(); int y = re.bottom() + Diagram_Margin; int future_y = y; Q3PtrListIterator<BrowserNode> it(l); BrowserNode * bn; for (; (bn = it.current()) != 0; ++it) { if (drawn[bn->get_data()] == 0) { DiagramCanvas * dc; switch (bn->get_type()) { case UmlClass: dc = new CdClassCanvas(bn, the_canvas(), x, y); break; case UmlPackage: dc = new PackageCanvas(bn, the_canvas(), x, y, 0); break; default: continue; } drawn.replace(dc->get_bn()->get_data(), dc); if ((x + dc->width()) > xmax) dc->move(x = Diagram_Margin, y = future_y); if (y + dc->height() > ymax) { dc->move(x = Diagram_Margin, y = Diagram_Margin); future_y = y + dc->height() + Diagram_Margin; } else { int bot = y + dc->height() + Diagram_Margin; if (bot > future_y) future_y = bot; } x = x + dc->width() + Diagram_Margin; dc->show(); dc->upper(); } } canvas()->update(); history_protected = FALSE; window()->package_modified(); QApplication::restoreOverrideCursor(); } }
bool ClassInstanceData::tool_cmd(ToolCom * com, const char * args, BrowserNode * bn, const QString & comment) { if (((unsigned char) args[-1]) >= firstSetCmd) { if (!bn->is_writable() && !root_permission()) com->write_ack(FALSE); else { switch ((unsigned char) args[-1]) { case setTypeCmd: set_class((BrowserClass *) com->get_id(args)); break; case setAttributeCmd: { BrowserAttribute * at = (BrowserAttribute *) com->get_id(args); bool find = FALSE; Q3ValueList<SlotAttr>::Iterator it_attr; for (it_attr = attributes.begin(); it_attr != attributes.end(); ++it_attr) { SlotAttr & slot_attr = *it_attr; if (slot_attr.att == at) { find = TRUE; if (*args == 0) // remove it attributes.remove(it_attr); else // replace it slot_attr.value = args; break; } } if (! find) { // add it Q3PtrList<BrowserClass> l; cl->get_all_parents(l); l.append(cl); if (at->deletedp() || (l.findRef((BrowserClass *) at->parent()) == -1)) { // illegal com->write_ack(FALSE); return TRUE; } attributes.append(SlotAttr(at, args)); } } break; case addRelationCmd: if (! change_rel(com, args, TRUE)) return TRUE; break; case removeRelationCmd: if (! change_rel(com, args, FALSE)) return TRUE; break; default: return BasicData::tool_cmd(com, args, bn, comment); } // ok case bn->modified(); modified(); com->write_ack(TRUE); } } else { switch ((unsigned char) args[-1]) { case attributesCmd: if (args[0] == 0) { com->write_unsigned(attributes.count()); Q3ValueList<SlotAttr>::Iterator it; for (it = attributes.begin(); it != attributes.end(); ++it) { const SlotAttr & slot = *it; slot.att->write_id(com); com->write_string(slot.value); } } else { // get all available attributes BrowserNodeList l; BrowserNode * bn; cl->get_attrs(l); com->write_unsigned(l.count()); for (bn = l.first(); bn != 0; bn = l.next()) bn->write_id(com); } break; case relationsCmd: { BrowserClassInstance * other = (BrowserClassInstance *) com->get_id(args); if (other == 0) { com->write_unsigned(relations.count()); Q3ValueList<SlotRel>::Iterator it; for (it = relations.begin(); it != relations.end(); ++it) { const SlotRel & slot = *it; ((slot.is_a) ? slot.rel->get_start() : slot.rel->get_end()) ->write_id(com); slot.value->write_id(com); } } else { // get all available relations Q3PtrList<BrowserRelation> l; BrowserRelation * r; cl->get_rels(((ClassInstanceData *)other->get_data())->cl, l); com->write_unsigned(l.count()); for (r = l.first(); r != 0; r = l.next()) r->write_id(com); } } break; default: return BasicData::tool_cmd(com, args, bn, comment); } } return TRUE; }
bool BrowserNode::tool_cmd(ToolCom * com, const char * args) { switch ((unsigned char) args[-1]) { case applyCmd: { QLOG_FATAL() << Q_FUNC_INFO << "If this got called then we have a logic flaw going on and BrowserNode needs to have Q_OBJECT in it to properly catch ToolCom::Run execution result"; Q_ASSERT_X(0, "applyCmd happened", "very bad"); int runResult = ToolCom::run(args, this, FALSE, FALSE); com->write_unsigned(runResult); break; } case createCmd: // invalid creation com->write_id(0); break; case parentCmd: if (this != BrowserView::get_project()) ((BrowserNode *) parent())->write_id(com); else com->write_id(0); break; case childrenCmd: { unsigned v = com->api_format(); unsigned n = 0; Q3ListViewItem * child; for (child = firstChild(); child != 0; child = child->nextSibling()) if (!((BrowserNode *) child)->deletedp() && ((BrowserNode *) child)->api_compatible(v)) n += 1; com->write_unsigned(n); for (child = firstChild(); child != 0; child = child->nextSibling()) if (!((BrowserNode *) child)->deletedp() && ((BrowserNode *) child)->api_compatible(v)) ((BrowserNode *) child)->write_id(com); } break; case getDefCmd: case getUmlDefCmd: case getCppDefCmd: case getJavaDefCmd: case getPhpDefCmd: case getPythonDefCmd: case getIdlDefCmd: get_data()->send_uml_def(com, this, comment); break; case isWritableCmd: com->write_bool(!is_read_only); break; case supportFileCmd: // goes up to the package return ((BrowserNode *) parent())->tool_cmd(com, args); case isOpenCmd: com->write_bool(isOpen()); break; case referencedByCmd: { BrowserNodeList targetof; referenced_by(targetof); // remove duplicats targetof.sort_it(); BrowserNode * bn; targetof.first(); while ((bn = targetof.current()) != 0) if (bn == targetof.next()) targetof.remove(); com->write_unsigned(targetof.count()); for (bn = targetof.first(); bn != 0; bn = targetof.next()) bn->write_id(com); } break; case setCoupleValueCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { set_value(args, args + strlen(args) + 1); package_modified(); get_data()->modified(); com->write_ack(TRUE); } break; case setDescriptionCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { set_comment(args); package_modified(); com->write_ack(TRUE); } break; case setNameCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { if (name != args) { if (((BrowserNode *) parent())->wrong_child_name(args, get_type(), allow_spaces(), allow_empty())) { com->write_ack(FALSE); return TRUE; } else { set_name(args); update_stereotype(); package_modified(); get_data()->modified(); } } com->write_ack(TRUE); } break; case setOpenCmd: BrowserView::select(this); setOpen(*args); com->write_ack(TRUE); break; case setMarkedCmd: if (*args) { if (this == BrowserView::get_project()) com->write_ack(FALSE); else { if (!is_marked) toggle_mark(); com->write_ack(TRUE); } } else { if (is_marked) toggle_mark(); com->write_ack(TRUE); } break; case moveAfterCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { BrowserNode * p = (BrowserNode *) parent(); BrowserNode * after = (BrowserNode *) com->get_id(args); if (after == 0) { if (p == 0) com->write_ack(FALSE); else { p->takeItem(this); p->insertItem(this); com->write_ack(TRUE); p->package_modified(); } } else if ((after->parent() != p) || (after == this)) { com->write_ack(FALSE); } else { moveItem(after); com->write_ack(TRUE); p->package_modified(); } } break; case moveInCmd: // plug-out upgrade, limited checks if (is_read_only && !root_permission()) com->write_ack(FALSE); else { BrowserNode * newparent = (BrowserNode *) com->get_id(args); BrowserNode * oldparent = (BrowserNode *) parent(); if ((newparent == oldparent) || (newparent == this)) { com->write_ack(FALSE); } else { oldparent->takeItem(this); newparent->insertItem(this); com->write_ack(TRUE); oldparent->package_modified(); newparent->package_modified(); } } break; case old_deleteCmd: case deleteCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { delete_it(); ((BrowserNode *) parent())->get_data()->modified(); package_modified(); com->write_ack(TRUE); } break; case applyStereotypeCmd: if (is_read_only && !root_permission()) com->write_ack(FALSE); else { ProfiledStereotypes::applyStereotype(this); // call package_modified() if needed com->write_ack(TRUE); } break; default: return FALSE; } return TRUE; }
void RelatedElementsDialog::accept() { bool inh = (inh_rb != 0) && inh_rb->isChecked(); bool dep = dep_rb->isChecked(); bool assoc = (assoc_rb != 0) && assoc_rb->isChecked(); if (!inh && !dep && !assoc) return; bool sametype = sametype_rb->isChecked(); UmlCode k = elt->get_type(); elts.clear(); Q3PtrDict<BrowserNode> d(71); BrowserNodeList added; int lvl = sb_level->value(); added.append(elt); d.insert(elt, elt); do { BrowserNodeList newones; Q3PtrListIterator<BrowserNode> it(added); for (; it.current() != 0; ++it) { BrowserNode * e = (BrowserNode *) it.current(); BrowserNode * bn; if (referenced_rb->isChecked()) { for (bn = (BrowserNode *) e->firstChild(); bn != 0; bn = (BrowserNode *) bn->nextSibling()) { if (! bn->deletedp()) { BrowserNode * target; switch (bn->get_type()) { case UmlAssociation: case UmlDirectionalAssociation: case UmlAggregation: case UmlAggregationByValue: case UmlDirectionalAggregation: case UmlDirectionalAggregationByValue: if (! assoc) continue; target = ((RelationData *) bn->get_data())->get_end_class(); break; case UmlDependency: if (! dep) continue; target = ((RelationData *) bn->get_data())->get_end_class(); break; case UmlGeneralisation: case UmlRealize: if (! inh) continue; target = ((RelationData *) bn->get_data())->get_end_class(); break; case UmlDependOn: if (! dep) continue; target = ((SimpleRelationData *) bn->get_data())->get_end_node(); break; case UmlInherit: if (! inh) continue; target = ((SimpleRelationData *) bn->get_data())->get_end_node(); break; default: continue; } if ((sametype && (target->get_type() != k)) || (d[target] != 0)) continue; d.insert(target, target); newones.append(target); } } } if (referencing_rb->isChecked()) { if (e->get_type() == UmlClass) BrowserRelation::get_relating(e, d, newones, inh, dep, assoc); BrowserSimpleRelation::get_relating(e, d, newones, inh, dep, sametype, k); } } added = newones; } while (--lvl != 0); d.remove(elt); Q3PtrDictIterator<BrowserNode> it(d); while (it.current()) { elts.append(it.current()); ++it; } QDialog::accept(); }