/** * Slot for adding an attribute to the tree. * @param listItem the new attribute to add */ void RefactoringAssistant::attributeAdded(UMLClassifierListItem *listItem) { UMLAttribute *att = static_cast<UMLAttribute*>(listItem); DEBUG(DBG_SRC) << "attribute = " << att->name(); //:TODO: UMLClassifier *parent = dynamic_cast<UMLClassifier*>(att->parent()); if (!parent) { uWarning() << att->name() << " - Parent of attribute is not a classifier!"; return; } QTreeWidgetItem *item = findListViewItem(parent); if (!item) { uWarning() << "Parent is not in tree!"; return; } for (int i = 0; i < item->childCount(); ++i) { QTreeWidgetItem *folder = item->child(i); if (folder->text(1) == QLatin1String("attributes")) { item = new QTreeWidgetItem(folder, QStringList(att->name())); m_umlObjectMap[item] = att; connect(att, SIGNAL(modified()), this, SLOT(objectModified())); setVisibilityIcon(item, att); DEBUG(DBG_SRC) << "attribute = " << att->name() << " added!"; //:TODO: break; } } }
/** * Slot for adding an operation to the tree. * @param listItem the new operation to add */ void RefactoringAssistant::operationAdded(UMLClassifierListItem *listItem) { UMLOperation *op = static_cast<UMLOperation*>(listItem); DEBUG(DBG_SRC) << "operation = " << op->name(); //:TODO: UMLClassifier *parent = dynamic_cast<UMLClassifier*>(op->parent()); if (!parent) { uWarning() << op->name() << " - Parent of operation is not a classifier!"; return; } QTreeWidgetItem *item = findListViewItem(parent); if (!item) { return; } for (int i = 0; i < item->childCount(); ++i) { QTreeWidgetItem *folder = item->child(i); if (folder->text(1) == QLatin1String("operations")) { item = new QTreeWidgetItem(folder, QStringList(op->name())); m_umlObjectMap[item] = op; connect(op, SIGNAL(modified()), this, SLOT(objectModified())); setVisibilityIcon(item, op); DEBUG(DBG_SRC) << "operation = " << op->name() << " added!"; //:TODO: break; } } }
/** * Show the dialog with data from the given UML object. * @param obj the UML object to edit */ void RefactoringAssistant::editProperties(UMLObject *obj) { #if QT_VERSION >= 0x050000 QDialog *dia(0); #else KDialog *dia(0); #endif UMLObject::ObjectType t = obj->baseType(); if (t == UMLObject::ot_Class || t == UMLObject::ot_Interface) { ClassPropertiesDialog *dialog = new ClassPropertiesDialog(this, obj, true); if (dialog && dialog->exec()) { // need to update something? } delete dialog; } else if (t == UMLObject::ot_Operation) { dia = new UMLOperationDialog(this, static_cast<UMLOperation*>(obj)); } else if (t == UMLObject::ot_Attribute) { dia = new UMLAttributeDialog(this, static_cast<UMLAttribute*>(obj)); } else { uWarning() << "Called for unknown type " << typeid(*obj).name(); return; } if (dia && dia->exec()) { // need to update something? } delete dia; }
/** * Add a classifier to the data structure. * @param classifier the classifier to add * @param parent the tree item under which the classifier is placed * @param addSuper add it to the base classifier folder * @param addSub add it to the derived classifier folder * @param recurse ... */ void RefactoringAssistant::addClassifier(UMLClassifier *classifier, QTreeWidgetItem *parent, bool addSuper, bool addSub, bool recurse) { if (!classifier) { uWarning() << "No classifier given - do nothing!"; return; } DEBUG(DBG_SRC) << classifier->name() << " added."; QTreeWidgetItem *classifierItem, *item; if (parent) { classifierItem = parent; } else { classifierItem = new QTreeWidgetItem(this, QStringList(classifier->name())); m_umlObjectMap[classifierItem] = classifier; } m_alreadySeen << classifier; connect(classifier, SIGNAL(modified()), this, SLOT(objectModified())); // add attributes connect(classifier, SIGNAL(attributeAdded(UMLClassifierListItem*)), this, SLOT(attributeAdded(UMLClassifierListItem*))); connect(classifier, SIGNAL(attributeRemoved(UMLClassifierListItem*)), this, SLOT(attributeRemoved(UMLClassifierListItem*))); QStringList itemTextAt; itemTextAt << i18n("Attributes") << QLatin1String("attributes"); QTreeWidgetItem *attsFolder = new QTreeWidgetItem(classifierItem, itemTextAt); attsFolder->setIcon(0, Icon_Utils::SmallIcon(Icon_Utils::it_Folder_Orange)); attsFolder->setExpanded(true); UMLAttributeList atts(classifier->getAttributeList()); foreach(UMLAttribute* att, atts) { attributeAdded(att); }
/** * Returns the point at the point index. * @return point at given index */ QPointF AssociationLine::point(int index) const { if ((index < 0) | (index >= m_points.size())) { uWarning() << "Index " << index << " out of range [0.." << m_points.size() - 1 << "]."; return QPointF(-1.0, -1.0); } return m_points.at(index); }
/** * Create new attribute. */ void RefactoringAssistant::createAttribute() { QTreeWidgetItem *item = currentItem(); if (!item) { uWarning() << "Called with no item selected."; return; } UMLClassifier *c = dynamic_cast<UMLClassifier*>(findUMLObject(item)); if (!c) { // find parent QTreeWidgetItem *parent = item->parent(); c = dynamic_cast<UMLClassifier*>(findUMLObject(parent)); if (!c) { uWarning() << "No classifier - cannot create!"; return; } } c->createAttribute(); }
/** * Slot for adding a base classifier. */ void RefactoringAssistant::addBaseClassifier() { QTreeWidgetItem *item = currentItem(); if (!item) { uWarning() << "Called with no item selected"; return; } UMLObject *obj = findUMLObject(item); if (!dynamic_cast<UMLClassifier*>(obj)) { uWarning() << "Called for a non-classifier object."; return; } //classes have classes and interfaces interfaces as super/derived classifiers UMLObject::ObjectType t = obj->baseType(); UMLClassifier *super = static_cast<UMLClassifier*>(Object_Factory::createUMLObject(t)); if (!super) { return; } m_doc->createUMLAssociation(obj, super, Uml::AssociationType::Generalization); ////////////////////// Manually add the classifier to the assitant - would be nicer to do it with ///////////////////// a signal, like operations and attributes QTreeWidgetItem *baseFolder = 0; for (int i = 0; i < item->childCount(); ++i) { baseFolder = item->child(i); if (!baseFolder) { uWarning() << "Cannot find base folder!"; return; } if (baseFolder->text(0) == i18n("Base Classifiers")) { item = new QTreeWidgetItem(baseFolder, QStringList(super->name())); item->setIcon(0, Icon_Utils::SmallIcon(Icon_Utils::it_Generalisation)); item->setExpanded(true); m_umlObjectMap[item] = super; addClassifier(super, item, true, false, true); break; } } ///////////////////////// }
/** * Find UML object from tree item. * @param item the item from the tree widget * @return the UML object behind the item */ UMLObject* RefactoringAssistant::findUMLObject(const QTreeWidgetItem *item) { if (!item) { return 0; } QTreeWidgetItem *i = const_cast<QTreeWidgetItem*>(item); if (m_umlObjectMap.find(i) == m_umlObjectMap.end()) { uWarning() << "Item with text " << item->text(0) << "not found in uml map!"; return 0; } return m_umlObjectMap[i]; }
/** * Sets up the list group. * @param margin The margin of the group. */ void ClassifierListPage::setupListGroup(int margin) { QString typeName; QString newItemType; switch (m_itemType) { case UMLObject::ot_Attribute: typeName = i18n("Attributes"); newItemType = i18n("N&ew Attribute..."); break; case UMLObject::ot_Operation: typeName = i18n("Operations"); newItemType = i18n("N&ew Operation..."); break; case UMLObject::ot_Template: typeName = i18n("Templates"); newItemType = i18n("N&ew Template..."); break; case UMLObject::ot_EnumLiteral: typeName = i18n("Enum Literals"); newItemType = i18n("N&ew Enum Literal..."); break; case UMLObject::ot_EntityAttribute: typeName = i18n("Entity Attributes"); newItemType = i18n("N&ew Entity Attribute..."); break; case UMLObject::ot_EntityConstraint: typeName = i18n("Constraints"); newItemType = i18n("N&ew Constraint..."); break; default: uWarning() << "unknown listItem type in ClassifierListPage"; break; } //top group box, contains a vertical layout with list box above and buttons below m_pItemListGB = new QGroupBox(typeName, this); QVBoxLayout* listVBoxLayout = new QVBoxLayout(m_pItemListGB); listVBoxLayout->setMargin(margin); listVBoxLayout->setSpacing(10); //horizontal box contains the list box and the move up/down buttons QHBoxLayout* listHBoxLayout = new QHBoxLayout(); listHBoxLayout->setSpacing(10); listVBoxLayout->addItem(listHBoxLayout); m_pItemListLB = new QListWidget(m_pItemListGB); m_pItemListLB->setSelectionMode(QAbstractItemView::SingleSelection); m_pItemListLB->setContextMenuPolicy(Qt::CustomContextMenu); listHBoxLayout->addWidget(m_pItemListLB); setupMoveButtons(listHBoxLayout); setupActionButtons(newItemType, listVBoxLayout); }
/** * Find tree item from UML object. * @param obj the UML object to search in tree * @return the found tree widget item or 0 */ QTreeWidgetItem* RefactoringAssistant::findListViewItem(const UMLObject *obj) { QMapIterator<QTreeWidgetItem*, UMLObject*> it(m_umlObjectMap); while (it.hasNext()) { it.next(); if (it.value() == obj) { return it.key(); } } uWarning() << "Object id " << Uml::ID::toString(obj->id()) << "does not have an item in the tree"; return 0; }
/** * Sets the point value at given index to \a point. */ bool AssociationLine::setPoint(int index, const QPointF &point) { if ((index < 0) | (index >= m_points.size())) { uWarning() << "Index " << index << " out of range [0.." << m_points.size() - 1 << "]."; return false; } if (m_points.at(index) == point) { return false; // nothing to change } prepareGeometryChange(); m_points[index] = point; alignSymbols(); return true; }
/** * Slot for removing an attribute from the tree. * @param listItem the attribute to be removed */ void RefactoringAssistant::attributeRemoved(UMLClassifierListItem *listItem) { UMLAttribute *att = static_cast<UMLAttribute*>(listItem); DEBUG(DBG_SRC) << "attribute = " << att->name(); //:TODO: QTreeWidgetItem *item = findListViewItem(att); if (!item) { uWarning() << "Attribute is not in tree!"; return; } disconnect(att, SIGNAL(modified()), this, SLOT(objectModified())); m_umlObjectMap.remove(item); delete item; DEBUG(DBG_SRC) << "attribute = " << att->name() << " deleted!"; //:TODO: }
/** * Load codegenerator data from xmi. * @param qElement the element from which to load */ void CodeGenerator::loadFromXMI(QDomElement & qElement) { // look for our particular child element QDomNode node = qElement.firstChild(); QDomElement element = node.toElement(); QString langType = Model_Utils::progLangToString( language() ); if (qElement.tagName() != "codegenerator" || qElement.attribute("language", "UNKNOWN") != langType) { return; } // got our code generator element, now load // codedocuments QDomNode codeDocNode = qElement.firstChild(); QDomElement codeDocElement = codeDocNode.toElement(); while (!codeDocElement.isNull()) { QString docTag = codeDocElement.tagName(); QString id = codeDocElement.attribute( "id", "-1" ); if (docTag == "sourcecode") { loadCodeForOperation(id, codeDocElement); } else if (docTag == "codedocument" || docTag == "classifiercodedocument") { CodeDocument * codeDoc = findCodeDocumentByID(id); if (codeDoc) { codeDoc->loadFromXMI(codeDocElement); } else { uWarning() << "missing code document for id:" << id; } } else { uWarning() << "got strange codegenerator child node:" << docTag << ", ignoring."; } codeDocNode = codeDocElement.nextSibling(); codeDocElement = codeDocNode.toElement(); } }
/** * Slot for adding an interface implementation. * @todo not yet implemented, needs addSuperClassifier() first */ void RefactoringAssistant::addInterfaceImplementation() { uWarning() << "Not implemented... finish addSuperClassifier() first!!"; return; // QTreeWidgetItem *item = selectedListViewItem(); // UMLObject *obj = findUMLObject(item); // if(!dynamic_cast<UMLClassifier*>(obj)) // return; // UMLObject *n = Object_Factory::createUMLObject(UMLObject::ot_Interface)); // if (!n) { // return; // } // m_doc->createUMLAssociation(n, obj, UMLObject::at_Realization); // //refresh, add classifier to assistant }
/** * Delete an item from the tree. * @param item the tree widget item * @param obj the uml object */ void RefactoringAssistant::deleteItem(QTreeWidgetItem *item, UMLObject *obj) { UMLObject::ObjectType t = obj->baseType(); if (t == UMLObject::ot_Class || t == UMLObject::ot_Interface) { DEBUG(DBG_SRC) << "Delete class or interface - not yet implemented!"; //:TODO: } else if (t == UMLObject::ot_Operation) { QTreeWidgetItem *opNode = item->parent(); if (opNode) { QTreeWidgetItem *parent = opNode->parent(); UMLClassifier* c = static_cast<UMLClassifier*>(findUMLObject(parent)); if (!c) { uWarning() << "No classifier - cannot delete!"; return; } UMLOperation* op = static_cast<UMLOperation*>(obj); c->removeOperation(op); } } else if (t == UMLObject::ot_Attribute) { QTreeWidgetItem *attrNode = item->parent(); if (attrNode) { QTreeWidgetItem *parent = attrNode->parent(); UMLClassifier* c = static_cast<UMLClassifier*>(findUMLObject(parent)); if (!c) { uWarning() << "No classifier - cannot delete!"; return; } UMLAttribute* attr = static_cast<UMLAttribute*>(obj); c->removeAttribute(attr); } } else { uWarning() << "Called for unknown type " << typeid(*obj).name(); } }
/** * Overrides method from UMLWidget. */ QSizeF MessageWidget::minimumSize() const { if (m_sequenceMessageType == Uml::SequenceMessage::Synchronous) { return QSizeF(width(), 20); } else if (m_sequenceMessageType == Uml::SequenceMessage::Asynchronous) { return isSelf() ? QSizeF(width(), 20) : QSizeF(width(), 8); } else if (m_sequenceMessageType == Uml::SequenceMessage::Creation) { return QSizeF(width(), 8); } else if (m_sequenceMessageType == Uml::SequenceMessage::Lost) { return QSizeF(width(), 10); } else if (m_sequenceMessageType == Uml::SequenceMessage::Found) { return QSizeF(width(), 10); } else { uWarning() << "Unknown message type"; } return QSize(width(), height()); }
/** * Slot for the context menu by right clicking in the tree widget. * @param p point of the right click inside the tree widget */ void RefactoringAssistant::showContextMenu(const QPoint& p) { QTreeWidgetItem* item = itemAt(p); if (!item) { return; } m_menu->clear(); UMLObject *obj = findUMLObject(item); if (obj) { // Menu for UMLObjects UMLObject::ObjectType t = obj->baseType(); if (t == UMLObject::ot_Class) { m_menu->addAction(createAction(i18n("Add Base Class"), SLOT(addBaseClassifier()), Icon_Utils::it_Generalisation)); m_menu->addAction(createAction(i18n("Add Derived Class"), SLOT(addDerivedClassifier()), Icon_Utils::it_Uniassociation)); // m_menu->addAction(createAction(i18n("Add Interface Implementation"), SLOT(addInterfaceImplementation()), Icon_Utils::it_Implementation)); m_menu->addAction(createAction(i18n("Add Operation"), SLOT(createOperation()), Icon_Utils::it_Public_Method)); m_menu->addAction(createAction(i18n("Add Attribute"), SLOT(createAttribute()), Icon_Utils::it_Public_Attribute)); } else if (t == UMLObject::ot_Interface) { m_menu->addAction(createAction(i18n("Add Base Interface"), SLOT(addSuperClassifier()), Icon_Utils::it_Generalisation)); m_menu->addAction(createAction(i18n("Add Derived Interface"), SLOT(addDerivedClassifier()), Icon_Utils::it_Uniassociation)); m_menu->addAction(createAction(i18n("Add Operation"), SLOT(createOperation()), Icon_Utils::it_Public_Method)); } // else { // DEBUG(DBG_SRC) << "No context menu for objects of type " << typeid(*obj).name(); // return; // } m_menu->addSeparator(); m_menu->addAction(createAction(i18n("Properties"), SLOT(editProperties()), Icon_Utils::it_Properties)); m_menu->addAction(createAction(i18n("Delete"), SLOT(deleteItem()), Icon_Utils::it_Delete)); } else { //menu for other ViewItems if (item->text(1) == QLatin1String("operations")) { m_menu->addAction(createAction(i18n("Add Operation"), SLOT(createOperation()), Icon_Utils::it_Public_Method)); } else if (item->text(1) == QLatin1String("attributes")) { m_menu->addAction(createAction(i18n("Add Attribute"), SLOT(createAttribute()), Icon_Utils::it_Public_Attribute)); } else { uWarning() << "Called for unsupported item."; return; } } m_menu->exec(mapToGlobal(p) + QPoint(0, 20)); }
/** * Calculates the size of the widget by calling * calculateDimensionsSynchronous(), * calculateDimensionsAsynchronous(), or * calculateDimensionsCreation() */ void MessageWidget::calculateDimensions() { if (m_sequenceMessageType == Uml::SequenceMessage::Synchronous) { calculateDimensionsSynchronous(); } else if (m_sequenceMessageType == Uml::SequenceMessage::Asynchronous) { calculateDimensionsAsynchronous(); } else if (m_sequenceMessageType == Uml::SequenceMessage::Creation) { calculateDimensionsCreation(); } else if (m_sequenceMessageType == Uml::SequenceMessage::Lost) { calculateDimensionsLost(); } else if (m_sequenceMessageType == Uml::SequenceMessage::Found) { calculateDimensionsFound(); } else { uWarning() << "Unknown message type"; } if (! UMLApp::app()->document()->loading()) { adjustAssocs(x(), y()); // adjust assoc lines } }
/** * This will setup the class ready to display the line correctly. * This MUST be called before you can use this class. */ void AssociationLine::setAssociation(AssociationWidget * association) { if( !association ) return; cleanup(); m_pAssociation = association; createHeadLines(); createSubsetSymbol(); if( getAssocType() == Uml::AssociationType::Coll_Message ) setupParallelLine(); UMLView * view = (UMLView *)m_pAssociation->parent(); if (view) { connect(view, SIGNAL(sigColorChanged(Uml::IDType)), this, SLOT(slotLineColorChanged(Uml::IDType))); connect(view, SIGNAL(sigLineWidthChanged(Uml::IDType)), this, SLOT(slotLineWidthChanged(Uml::IDType))); } else { uWarning() << "Parent is null. Can not connect SIGNAL/SLOT."; } }
/** * Reimplemented from UMLWidget and calls other paint...() methods * depending on the message type. */ void MessageWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); if(!m_pOw[Uml::RoleType::A] || !m_pOw[Uml::RoleType::B]) { return; } setPenFromSettings(painter); if (m_sequenceMessageType == Uml::SequenceMessage::Synchronous) { paintSynchronous(painter, option); } else if (m_sequenceMessageType == Uml::SequenceMessage::Asynchronous) { paintAsynchronous(painter, option); } else if (m_sequenceMessageType == Uml::SequenceMessage::Creation) { paintCreation(painter, option); } else if (m_sequenceMessageType == Uml::SequenceMessage::Lost) { paintLost(painter, option); } else if (m_sequenceMessageType == Uml::SequenceMessage::Found) { paintFound(painter, option); } else { uWarning() << "Unknown message type"; } }
static Bool parseArgs(int argc, char *argv[]) { register int i; args.copies= 1; args.grid= 0; args.level1= True; args.scaleToFit= True; args.wantColor= False; args.wantSymbols= COMMON_SYMBOLS; args.wantKeycodes= True; args.wantDiffs= False; args.wantEPS= False; args.label= LABEL_AUTO; args.baseLabelGroup=0; args.nLabelGroups= 1; args.nTotalGroups= 0; args.nKBPerPage= 0; args.labelLevel= 0; for (i=1;i<argc;i++) { if ((argv[i][0]!='-')||(uStringEqual(argv[i],"-"))) { if (inputFile==NULL) { inputFile= argv[i]; } else if (outputFile==NULL) { outputFile= argv[i]; } else { uWarning("Too many file names on command line\n"); uAction("Compiling %s, writing to %s, ignoring %s\n", inputFile,outputFile,argv[i]); } } else if ((strcmp(argv[i],"-?")==0)||(strcmp(argv[i],"-help")==0)) { Usage(argc,argv); exit(0); } else if (strcmp(argv[i],"-color")==0) { args.wantColor= True; } #ifdef DEBUG else if (strcmp(argv[i],"-d")==0) { if ((i>=(argc-1))||(!isdigit(argv[i+1][0]))) { debugFlags= 1; } else { sscanf(argv[++i],"%i",&debugFlags); } uInformation("Setting debug flags to %d\n",debugFlags); } #endif else if (strcmp(argv[i],"-dflts")==0) { #ifdef NOTYET computeDflts= True; #endif uWarning("Compute defaults not implemented yet\n"); } else if (strcmp(argv[i],"-diffs")==0) { args.wantDiffs= True; } else if (strcmp(argv[i],"-eps")==0) { args.wantEPS= True; } else if (strcmp(argv[i],"-fit")==0) { args.scaleToFit= True; } else if (strcmp(argv[i],"-full")==0) { args.scaleToFit= False; } else if (strcmp(argv[i],"-grid")==0) { int tmp; if (++i>=argc) { uWarning("Grid frequency not specified\n"); uAction("Trailing \"-grid\" option ignored\n"); } else if ((sscanf(argv[i],"%i",&tmp)!=1)||(tmp<1)) { uWarning("Grid frequency must be an integer > zero\n"); uAction("Illegal frequency %d ignored\n",tmp); } else args.grid= tmp; } #ifdef NOTYET else if (strncmp(argv[i],"-I",2)==0) { if (!XkbAddDirectoryToPath(&argv[i][2])) { uAction("Exiting\n"); exit(1); } uInternalError("Includes not implemented yet\n"); } #endif else if (strcmp(argv[i],"-if")==0) { if (++i>=argc) { uWarning("Internal Font name not specified\n"); uAction("Trailing \"-if\" option ignored\n"); } else outputFont= argv[i]; } else if (strcmp(argv[i],"-kc")==0) { args.wantKeycodes= True; } else if (strcmp(argv[i],"-label")==0) { if (++i>=argc) { uWarning("Label type not specified\n"); uAction("Trailing \"-label\" option ignored\n"); } else if (uStrCaseEqual(argv[i],"none")) args.label= LABEL_NONE; else if (uStrCaseEqual(argv[i],"name")) args.label= LABEL_KEYNAME; else if (uStrCaseEqual(argv[i],"code")) args.label= LABEL_KEYCODE; else if (uStrCaseEqual(argv[i],"symbols")) args.label= LABEL_SYMBOLS; else { uWarning("Unknown label type \"%s\" specified\n",argv[i]); uAction("Ignored\n"); } } else if (strcmp(argv[i],"-lc")==0) { if (++i>=argc) { uWarning("Locale not specified\n"); uAction("Trailing \"-lc\" option ignored\n"); } else wantLocale= argv[i]; } else if (strcmp(argv[i],"-lg")==0) { int tmp; if (++i>=argc) { uWarning("Label group not specified\n"); uAction("Trailing \"-lg\" option ignored\n"); } else if ((sscanf(argv[i],"%i",&tmp)!=1)||(tmp<1)||(tmp>4)) { uWarning("Label group must be an integer in the range 1..4\n"); uAction("Illegal group %d ignored\n",tmp); } else args.baseLabelGroup= tmp-1; } else if (strcmp(argv[i],"-ll")==0) { int tmp; if (++i>=argc) { uWarning("Label level not specified\n"); uAction("Trailing \"-ll\" option ignored\n"); } else if ((sscanf(argv[i],"%i",&tmp)!=1)||(tmp<1)||(tmp>255)) { uWarning("Label level must be in the range 1..255\n"); uAction("Illegal level %d ignored\n",tmp); } else args.labelLevel= tmp-1; } else if (strcmp(argv[i],"-level1")==0) args.level1= True; else if (strcmp(argv[i],"-level2")==0) args.level1= False; else if (strcmp(argv[i],"-mono")==0) { args.wantColor= False; } else if (strcmp(argv[i],"-n")==0) { int tmp; if (++i>=argc) { uWarning("Number of copies not specified\n"); uAction("Trailing \"-n\" option ignored\n"); } else if ((sscanf(argv[i],"%i",&tmp)!=1)||(tmp<1)) { uWarning("Number of copies must be an integer > zero\n"); uAction("Illegal count %d ignored\n",tmp); } else args.copies= tmp; } else if (strcmp(argv[i],"-nokc")==0) { args.wantKeycodes= False; } else if (strcmp(argv[i],"-nkg")==0) { int tmp; if (++i>=argc) { uWarning("Number of groups per key not specified\n"); uAction("Trailing \"-nkg\" option ignored\n"); } else if ((sscanf(argv[i],"%i",&tmp)!=1)||(tmp<1)||(tmp>2)) { uWarning("Groups per key must be in the range 1..2\n"); uAction("Illegal number of groups %d ignored\n",tmp); } else args.nLabelGroups= tmp; } else if (strcmp(argv[i],"-npk")==0) { int tmp; if (++i>=argc) { uWarning("Number of keyboards per page not specified\n"); uAction("Trailing \"-npk\" option ignored\n"); } else if ((sscanf(argv[i],"%i",&tmp)!=1)||(tmp<1)||(tmp>2)) { uWarning("Keyboards per page must be in the range 1..2\n"); uAction("Illegal number of keyboards %d ignored\n",tmp); } else args.nKBPerPage= tmp; } else if (strcmp(argv[i],"-ntg")==0) { int tmp; if (++i>=argc) { uWarning("Total number of groups not specified\n"); uAction("Trailing \"-ntg\" option ignored\n"); } else if ((sscanf(argv[i],"%i",&tmp)!=1)||(tmp<1)||(tmp>4)) { uWarning("Total number of groups must be in the range 1..4\n"); uAction("Illegal number of groups %d ignored\n",tmp); } else args.nTotalGroups= tmp; } else if (strcmp(argv[i],"-o")==0) { if (++i>=argc) { uWarning("No output file specified\n"); uAction("Trailing \"-o\" option ignored\n"); } else if (outputFile!=NULL) { uWarning("Multiple output files specified\n"); uAction("Compiling %s, ignoring %s\n",outputFile,argv[i]); } else outputFile= argv[i]; } else if (strncmp(argv[i],"-R",2)==0) { if (argv[i][2]=='\0') { uWarning("No root directory specified\n"); uAction("Ignoring -R option\n"); } else if (rootDir!=NULL) { uWarning("Multiple root directories specified\n"); uAction("Using %s, ignoring %s\n",rootDir,argv[i]); } else rootDir= &argv[i][2]; } else if (strcmp(argv[i],"-pict")==0) { if (++i>=argc) { uWarning("No level of pictographs specified\n"); uAction("Trailing \"-pict\" option ignored\n"); } else if (strcmp(argv[i],"none")==0) args.wantSymbols= NO_SYMBOLS; else if (strcmp(argv[i],"common")==0) args.wantSymbols= COMMON_SYMBOLS; else if (strcmp(argv[i],"all")==0) args.wantSymbols= ALL_SYMBOLS; else if (outputFile!=NULL) { uWarning("Unknown pictograph level specified\n"); uAction("Ignoring illegal value %s\n",argv[i]); } } else if ((strcmp(argv[i],"-synch")==0)||(strcmp(argv[i],"-s")==0)) { synch= True; } else if (strcmp(argv[i],"-w")==0) { if ((i>=(argc-1))||(!isdigit(argv[i+1][0]))) { warningLevel= 0; } else { int itmp; if (sscanf(argv[++i],"%i",&itmp)) warningLevel = itmp; } } else { uError("Unknown flag \"%s\" on command line\n",argv[i]); Usage(argc,argv); return False; } } if (rootDir) { if (warningLevel>8) { uWarning("Changing root directory to \"%s\"\n",rootDir); } if ((chdir(rootDir)<0) && (warningLevel>0)) { uWarning("Couldn't change root directory to \"%s\"\n",rootDir); uAction("Root directory (-R) option ignored\n"); } } if (outputFont!=NULL) { Bool ok; FILE *file= NULL; if (outputFile==NULL) { outputFile= uAlloc(strlen(outputFont)+5); sprintf(outputFile,"%s.pfa",outputFont); } else if (uStringEqual(outputFile,"-")) file= stdout; if (file==NULL) file= fopen(outputFile,"w"); if (!file) { uError("Couldn't open \"%s\" to dump internal font \"%s\"\n", outputFile,outputFont); uAction("Exiting\n"); exit(1); } ok= DumpInternalFont(file,outputFont); if (file!=stdout) fclose(file); if (!ok) { uWarning("No internal font to dump\n"); if (file!=stdout) { uAction("Removing \"%s\"\n",outputFile); unlink(outputFile); } } exit((ok!=0)); } if (inputFile==NULL) { uError("No input file specified\n"); Usage(argc,argv); return False; } else if (uStringEqual(inputFile,"-")) { /* Nothing */ } else if (strchr(inputFile,':')==NULL) { int len= strlen(inputFile); if ((len>4)&&(strcmp(&inputFile[len-4],".xkm")==0)) { /* Nothing */ } else { FILE *file; file= fopen(inputFile,"r"); if (file) { fclose(file); } else { fprintf(stderr,"Cannot open \"%s\" for reading\n",inputFile); return False; } } } else { inDpyName= inputFile; inputFile= NULL; } if (outputFormat==WANT_DEFAULT) outputFormat= WANT_PS_FILE; if ((outputFile==NULL)&&(inputFile!=NULL)&&uStringEqual(inputFile,"-")) { int len; len= strlen("stdin.eps")+2; outputFile= uTypedCalloc(len,char); if (outputFile==NULL) { uInternalError("Cannot allocate space for output file name\n"); uAction("Exiting\n"); exit(1); } if (args.wantEPS) sprintf(outputFile,"stdin.eps"); else sprintf(outputFile,"stdin.ps"); }
/** * Sets up the general page of the dialog. */ void ObjectNodeDialog::setupGeneralPage() { QStringList types; types << i18n("Central Buffer") << i18n("Data Store") << i18n("ObjectFlow"); ObjectNodeWidget::ObjectNodeType type = m_pObjectNodeWidget->objectNodeType(); KVBox *page = new KVBox(); pageItemGeneral = new KPageWidgetItem( page, i18n("General") ); pageItemGeneral->setHeader(i18n("General Properties")); pageItemGeneral->setIcon( Icon_Utils::DesktopIcon(Icon_Utils::it_Properties_General) ); addPage( pageItemGeneral ); m_GenPageWidgets.generalGB = new QGroupBox( i18nc("properties group title", "Properties"), (QWidget *)page ); QGridLayout * generalLayout = new QGridLayout( m_GenPageWidgets.generalGB ); generalLayout->setSpacing( spacingHint() ); generalLayout->setMargin( fontMetrics().height() ); QString objType; if (type < types.count()) { objType = types.at((int)type); } else { uWarning() << "type of ObjectNodeWidget is out of range! Value = " << type; } Dialog_Utils::makeLabeledEditField( m_GenPageWidgets.generalGB, generalLayout, 0, m_GenPageWidgets.typeL, i18n("Object Node type:"), m_GenPageWidgets.typeLE, objType ); m_GenPageWidgets.typeLE->setEnabled( false ); Dialog_Utils::makeLabeledEditField( m_GenPageWidgets.generalGB, generalLayout, 1, m_GenPageWidgets.nameL, i18n("Object Node name:"), m_GenPageWidgets.nameLE ); Dialog_Utils::makeLabeledEditField( m_GenPageWidgets.generalGB, generalLayout, 2, m_GenPageWidgets.stateL, i18nc("enter state label", "State :"), m_GenPageWidgets.stateLE ); m_GenPageWidgets.stateL->hide(); m_GenPageWidgets.stateLE->hide(); m_GenPageWidgets.bufferRB = new QRadioButton( i18n("&Central Buffer"),(QWidget *)page); generalLayout->addWidget( m_GenPageWidgets.bufferRB ); m_GenPageWidgets.dataRB = new QRadioButton( i18n("&Data Store "),(QWidget *)page); generalLayout->addWidget( m_GenPageWidgets.dataRB ); m_GenPageWidgets.flowRB = new QRadioButton( i18n("&Object Flow"),(QWidget *)page); generalLayout->addWidget( m_GenPageWidgets.flowRB ); if (type == ObjectNodeWidget::Flow) { showState(); } connect(m_GenPageWidgets.bufferRB,SIGNAL(clicked()),this,SLOT(slotHideState())); connect(m_GenPageWidgets.dataRB,SIGNAL(clicked()),this,SLOT(slotHideState())); connect(m_GenPageWidgets.flowRB,SIGNAL(clicked()),this,SLOT(slotShowState())); ObjectNodeWidget::ObjectNodeType newType = m_pObjectNodeWidget->objectNodeType() ; m_GenPageWidgets.bufferRB->setChecked(newType == ObjectNodeWidget::Buffer); m_GenPageWidgets.dataRB->setChecked (newType == ObjectNodeWidget::Data); m_GenPageWidgets.flowRB->setChecked (newType == ObjectNodeWidget::Flow); m_GenPageWidgets.docGB = new QGroupBox( i18n( "Documentation"), (QWidget *)page ); QHBoxLayout * docLayout = new QHBoxLayout( m_GenPageWidgets.docGB ); docLayout->setSpacing( spacingHint() ); docLayout->setMargin( fontMetrics().height() ); m_GenPageWidgets.docMLE = new KTextEdit( m_GenPageWidgets.docGB ); m_GenPageWidgets.docMLE->setText( m_pObjectNodeWidget->documentation() ); docLayout->addWidget( m_GenPageWidgets.docMLE ); if (type != ObjectNodeWidget::Buffer && type != ObjectNodeWidget::Data && type != ObjectNodeWidget::Flow) { m_GenPageWidgets.nameLE->setEnabled( false ); m_GenPageWidgets.nameLE->setText( "" ); } else m_GenPageWidgets.nameLE->setText( m_pObjectNodeWidget->name() ); }
/** * Parse a file into the PetalNode internal tree representation * and then create Umbrello objects by traversing the tree. * * @return In case of error: NULL * In case of success with non NULL parentPkg: pointer to UMLPackage created for controlled unit * In case of success with NULL parentPkg: pointer to root folder of Logical View */ UMLPackage* loadFromMDL(QFile& file, UMLPackage *parentPkg /* = 0 */) { if (parentPkg == NULL) { QString fName = file.fileName(); int lastSlash = fName.lastIndexOf(QLatin1Char('/')); if (lastSlash > 0) { dirPrefix = fName.left(lastSlash + 1); } } QTextStream stream(&file); stream.setCodec("ISO 8859-1"); QString line; PetalNode *root = NULL; uint nClosures_sav = nClosures; uint linum_sav = linum; nClosures = 0; linum = 0; while (!(line = stream.readLine()).isNull()) { linum++; if (line.contains(QRegExp(QLatin1String("^\\s*\\(object Petal")))) { bool finish = false; // Nested loop determines character set to use while (!(line = stream.readLine()).isNull()) { linum++; // CHECK: do we need petal version info? if (line.contains(QLatin1Char(')'))) { finish = true; line = line.replace(QLatin1String(QLatin1String(")")), QString()); } QStringList a = line.trimmed().split(QRegExp(QLatin1String("\\s+"))); if (a.size() == 2 && a[0] == QLatin1String("charSet")) { const QString& charSet = a[1]; if (!charSet.contains(QRegExp(QLatin1String("^\\d+$")))) { uWarning() << "Unimplemented charSet " << charSet; if (finish) break; continue; } const int charSetNum = charSet.toInt(); switch (charSetNum) { case 0: // ASCII ; case 1: // Default SETCODEC("System"); case 2: // Symbol ; // @todo SETCODEC("what"); case 77: // Mac SETCODEC("macintosh"); case 128: // ShiftJIS (Japanese) SETCODEC("Shift_JIS"); case 129: // Hangul (Korean) SETCODEC("EUC-KR"); case 130: // Johab (Korean) SETCODEC("EUC-KR"); case 134: // GB2312 (Chinese) SETCODEC("GB18030"); // "Don't use GB2312 here" (Ralf H.) case 136: // ChineseBig5 SETCODEC("Big5"); case 161: // Greek SETCODEC("windows-1253"); case 162: // Turkish SETCODEC("windows-1254"); case 163: // Vietnamese SETCODEC("windows-1258"); case 177: // Hebrew SETCODEC("windows-1255"); case 178: // Arabic SETCODEC("windows-1256"); case 186: // Baltic SETCODEC("windows-1257"); case 204: // Russian SETCODEC("windows-1251"); case 222: // Thai SETCODEC("TIS-620"); case 238: // EastEurope SETCODEC("windows-1250"); case 255: // OEM (extended ASCII) SETCODEC("windows-1252"); default: uWarning() << "Unimplemented charSet number" << charSetNum; } } if (finish) break; } if (line.isNull()) break; } else { QRegExp objectRx(QLatin1String("^\\s*\\(object ")); if (line.contains(objectRx)) { nClosures = 0; QStringList initialArgs = scan(line); initialArgs.pop_front(); // remove opening parenthesis root = readAttributes(initialArgs, stream); break; } } } file.close(); nClosures = nClosures_sav; linum = linum_sav; if (root == NULL) return NULL; if (parentPkg) { UMLPackage *child = petalTree2Uml(root, parentPkg); delete root; return child; } if (root->name() != QLatin1String("Design")) { uError() << "expecting root name Design"; delete root; return NULL; } Import_Utils::assignUniqueIdOnCreation(false); UMLDoc *umldoc = UMLApp::app()->document(); //*************************** import Logical View ********************************* umldoc->setCurrentRoot(Uml::ModelType::Logical); UMLPackage *logicalView = umldoc->rootFolder(Uml::ModelType::Logical); importView(root, logicalView, QLatin1String("root_category"), QLatin1String("logical_models"), QLatin1String("Class_Category"), QLatin1String("logical_presentations")); //*************************** import Use Case View ******************************** umldoc->setCurrentRoot(Uml::ModelType::UseCase); UMLPackage *useCaseView = umldoc->rootFolder(Uml::ModelType::UseCase); importView(root, useCaseView, QLatin1String("root_usecase_package"), QLatin1String("logical_models"), QLatin1String("Class_Category"), QLatin1String("logical_presentations")); //*************************** import Component View ******************************* umldoc->setCurrentRoot(Uml::ModelType::Component); UMLPackage *componentView = umldoc->rootFolder(Uml::ModelType::Component); importView(root, componentView, QLatin1String("root_subsystem"), QLatin1String("physical_models"), QLatin1String("SubSystem"), QLatin1String("physical_presentations")); //*************************** import Deployment View ****************************** umldoc->setCurrentRoot(Uml::ModelType::Deployment); UMLPackage *deploymentView = umldoc->rootFolder(Uml::ModelType::Deployment); importView(root, deploymentView, QLatin1String("process_structure"), QLatin1String("ProcsNDevs"), QLatin1String("Processes")); //*************************** wrap up ******************************** delete root; umldoc->setCurrentRoot(Uml::ModelType::Logical); Import_Utils::assignUniqueIdOnCreation(true); umldoc->resolveTypes(); return logicalView; }
CodeGenerator* createObject(Uml::ProgrammingLanguage::Enum pl) { CodeGenerator* obj = 0; Settings::OptionState optionState = Settings::optionState(); switch (pl) { case Uml::ProgrammingLanguage::Ada: obj = new AdaWriter(); break; case Uml::ProgrammingLanguage::ActionScript: obj = new ASWriter(); break; case Uml::ProgrammingLanguage::Cpp: if (optionState.generalState.newcodegen) { obj = new CPPCodeGenerator(); obj->connect_newcodegen_slots(); } else { obj = new CppWriter(); } break; case Uml::ProgrammingLanguage::CSharp: obj = new CSharpWriter(); break; case Uml::ProgrammingLanguage::D: if (optionState.generalState.newcodegen) { obj = new DCodeGenerator(); obj->connect_newcodegen_slots(); } else { obj = new DWriter(); } break; case Uml::ProgrammingLanguage::IDL: obj = new IDLWriter(); break; case Uml::ProgrammingLanguage::Java: if (optionState.generalState.newcodegen) { obj = new JavaCodeGenerator(); obj->connect_newcodegen_slots(); } else { obj = new JavaWriter(); } break; case Uml::ProgrammingLanguage::JavaScript: obj = new JSWriter(); break; case Uml::ProgrammingLanguage::MySQL: obj = new MySQLWriter(); break; case Uml::ProgrammingLanguage::PHP: obj = new PhpWriter(); break; case Uml::ProgrammingLanguage::PHP5: obj = new Php5Writer(); break; case Uml::ProgrammingLanguage::Pascal: obj = new PascalWriter(); break; case Uml::ProgrammingLanguage::Perl: obj = new PerlWriter(); break; case Uml::ProgrammingLanguage::PostgreSQL: obj = new PostgreSQLWriter(); break; case Uml::ProgrammingLanguage::Python: obj = new PythonWriter(); break; case Uml::ProgrammingLanguage::Ruby: if (optionState.generalState.newcodegen) { obj = new RubyCodeGenerator(); obj->connect_newcodegen_slots(); } else { obj = new RubyWriter(); } break; case Uml::ProgrammingLanguage::SQL: obj = new SQLWriter(); break; case Uml::ProgrammingLanguage::Tcl: obj = new TclWriter(); break; case Uml::ProgrammingLanguage::Vala: obj = new ValaWriter(); break; case Uml::ProgrammingLanguage::XMLSchema: obj = new XMLSchemaWriter(); break; default: uWarning() << "cannot create object of type " << Uml::ProgrammingLanguage::toString(pl) << ". Type unknown"; break; } UMLApp::app()->setPolicyExt(CodeGenFactory::newCodeGenPolicyExt(pl)); if (obj) { obj->initFromParentDocument(); } return obj; }
void DCodeAccessorMethod::updateMethodDeclaration() { DCodeClassField * dfield = dynamic_cast<DCodeClassField*>(getParentClassField()); // Check for dynamic casting failure! if (dfield == 0) { uError() << "dfield: invalid dynamic cast"; return; } CodeGenerationPolicy *commonpolicy = UMLApp::app()->commonPolicy(); // gather defs Uml::Visibility::Enum scopePolicy = commonpolicy->getAttributeAccessorScope(); QString strVis = Uml::Visibility::toString(dfield->getVisibility()); QString fieldName = dfield->getFieldName(); QString fieldType = dfield->getTypeName(); QString objectType = dfield->getListObjectType(); if(objectType.isEmpty()) objectType = fieldName; QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars(); // set scope of this accessor appropriately..if its an attribute, // we need to be more sophisticated if (dfield->parentIsAttribute()) { switch (scopePolicy) { case Uml::Visibility::Public: case Uml::Visibility::Private: case Uml::Visibility::Protected: strVis = Uml::Visibility::toString(scopePolicy); break; default: case Uml::Visibility::FromParent: // do nothing..already have taken parent value break; } } // some variables we will need to populate QString headerText; QString methodReturnType; QString methodName; QString methodParams; switch(getType()) { case CodeAccessorMethod::ADD: methodName = QLatin1String("add") + Codegen_Utils::capitalizeFirstLetter(fieldType); methodReturnType = QLatin1String("void"); methodParams = objectType + QLatin1String(" value "); headerText = QLatin1String("Add an object of type ") + objectType + QLatin1String(" to the List ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return void"); break; case CodeAccessorMethod::GET: methodName = QLatin1String("get") + Codegen_Utils::capitalizeFirstLetter(fieldName); methodReturnType = fieldType; headerText = QLatin1String("Get the value of ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return the value of ") + fieldName; break; case CodeAccessorMethod::LIST: methodName = QLatin1String("get") + Codegen_Utils::capitalizeFirstLetter(fieldType) + QLatin1String("List"); methodReturnType = QLatin1String("List"); headerText = QLatin1String("Get the list of ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return List of ") + fieldName; break; case CodeAccessorMethod::REMOVE: methodName = QLatin1String("remove") + Codegen_Utils::capitalizeFirstLetter(fieldType); methodReturnType = QLatin1String("void"); methodParams = objectType + QLatin1String(" value "); headerText = QLatin1String("Remove an object of type ") + objectType + QLatin1String(" from the List ") + fieldName + endLine + getParentObject()->doc(); break; case CodeAccessorMethod::SET: methodName = QLatin1String("set") + Codegen_Utils::capitalizeFirstLetter(fieldName); methodReturnType = QLatin1String("void"); methodParams = fieldType + QLatin1String(" value "); headerText = QLatin1String("Set the value of ") + fieldName + endLine + getParentObject()->doc() + endLine; break; default: // do nothing..no idea what this is uWarning()<<"Warning: cant generate DCodeAccessorMethod for type: "<<getType(); break; } // set header once. if(getComment()->getText().isEmpty()) getComment()->setText(headerText); // set start/end method text setStartMethodText(strVis + QLatin1Char(' ') + methodReturnType + QLatin1Char(' ') + methodName + QLatin1String(" (") + methodParams + QLatin1String(") {")); setEndMethodText(QLatin1String("}")); }
/** * Overrides the standard paint event. */ void StateWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); const qreal w = width(); const qreal h = height(); if (w == 0 || h == 0) return; setPenFromSettings(painter); switch (m_stateType) { case StateWidget::Normal: { if (UMLWidget::useFillColor()) { painter->setBrush(UMLWidget::fillColor()); } const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing(); int textStartY = (h / 2) - (fontHeight / 2); const int count = m_Activities.count(); if (count == 0) { painter->drawRoundRect(0, 0, w, h, (h*40)/w, (w*40)/h); painter->setPen(textColor()); QFont font = UMLWidget::font(); font.setBold(false); painter->setFont(font); painter->drawText(STATE_MARGIN, textStartY, w - STATE_MARGIN * 2, fontHeight, Qt::AlignCenter, name()); setPenFromSettings(painter); } else { painter->drawRoundRect(0, 0, w, h, (h*40)/w, (w*40)/h); textStartY = STATE_MARGIN; painter->setPen(textColor()); QFont font = UMLWidget::font(); font.setBold(true); painter->setFont(font); painter->drawText(STATE_MARGIN, textStartY, w - STATE_MARGIN * 2, fontHeight, Qt::AlignCenter, name()); font.setBold(false); painter->setFont(font); setPenFromSettings(painter); int linePosY = textStartY + fontHeight; QStringList::Iterator end(m_Activities.end()); for(QStringList::Iterator it(m_Activities.begin()); it != end; ++it) { textStartY += fontHeight; painter->drawLine(0, linePosY, w, linePosY); painter->setPen(textColor()); painter->drawText(STATE_MARGIN, textStartY, w - STATE_MARGIN * 2, fontHeight, Qt::AlignCenter, *it); setPenFromSettings(painter); linePosY += fontHeight; }//end for }//end else } break; case StateWidget::Initial : painter->setBrush(WidgetBase::lineColor()); painter->drawEllipse(0, 0, w, h); break; case StateWidget::End : painter->setBrush(WidgetBase::lineColor()); painter->drawEllipse(0, 0, w, h); painter->setBrush(Qt::white); painter->drawEllipse(1, 1, w - 2, h - 2); painter->setBrush(WidgetBase::lineColor()); painter->drawEllipse(3, 3, w - 6, h - 6); break; case StateWidget::Fork: case StateWidget::Join: { painter->setPen(Qt::black); painter->setBrush(Qt::black); painter->drawRect(rect()); } break; case StateWidget::Junction: { painter->setPen(Qt::black); painter->setBrush(Qt::black); painter->drawEllipse(rect()); } break; case StateWidget::DeepHistory: { painter->setBrush(Qt::white); painter->drawEllipse(rect()); painter->setPen(Qt::black); painter->setFont(UMLWidget::font()); const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing() / 2; const int xStar = fm.boundingRect(QLatin1String("H")).width(); const int yStar = fontHeight / 4; painter->drawText((w / 6), (h / 4) + fontHeight, QLatin1String("H")); painter->drawText((w / 6) + xStar, (h / 4) + fontHeight - yStar, QLatin1String("*")); } break; case StateWidget::ShallowHistory: { painter->setBrush(Qt::white); painter->drawEllipse(rect()); painter->setPen(Qt::black); painter->setFont(UMLWidget::font()); const QFontMetrics &fm = getFontMetrics(FT_NORMAL); const int fontHeight = fm.lineSpacing() / 2; painter->drawText((w / 6), (h / 4) + fontHeight, QLatin1String("H")); } break; case StateWidget::Choice: { const qreal x = w / 2; const qreal y = h / 2; QPolygonF polygon; polygon << QPointF(x, 0) << QPointF(w, y) << QPointF(x, h) << QPointF(0, y); painter->setBrush(UMLWidget::fillColor()); painter->drawPolygon(polygon); } break; default: uWarning() << "Unknown state type: " << stateTypeStr(); break; } UMLWidget::paint(painter, option, widget); }
UMLWidget* makeWidgetFromXMI(const QString& tag, const QString& idStr, UMLView *view) { UMLWidget *widget = NULL; // Loading of widgets which do NOT represent any UMLObject, // just graphic stuff with no real model information //FIXME while boxes and texts are just diagram objects, activities and // states should be UMLObjects if (tag == "statewidget" || tag == "UML:StateWidget") { widget = new StateWidget(view, StateWidget::Normal, Uml::id_Reserved); } else if (tag == "notewidget" || tag == "UML:NoteWidget") { widget = new NoteWidget(view, NoteWidget::Normal, Uml::id_Reserved); } else if (tag == "boxwidget") { widget = new BoxWidget(view, Uml::id_Reserved); } else if (tag == "floatingtext" || tag == "UML:FloatingTextWidget") { widget = new FloatingTextWidget(view, Uml::tr_Floating, "", Uml::id_Reserved); } else if (tag == "activitywidget" || tag == "UML:ActivityWidget") { widget = new ActivityWidget(view, ActivityWidget::Initial, Uml::id_Reserved); } else if (tag == "messagewidget") { widget = new MessageWidget(view, Uml::sequence_message_asynchronous, Uml::id_Reserved); } else if (tag == "forkjoin") { widget = new ForkJoinWidget(view, false, Uml::id_Reserved); } else if (tag == "preconditionwidget") { widget = new PreconditionWidget(view, NULL, Uml::id_Reserved); } else if (tag == "combinedFragmentwidget") { widget = new CombinedFragmentWidget(view, CombinedFragmentWidget::Ref, Uml::id_Reserved); } else if (tag == "signalwidget") { widget = new SignalWidget(view, SignalWidget::Send, Uml::id_Reserved); } else if (tag == "floatingdashlinewidget") { widget = new FloatingDashLineWidget(view, Uml::id_Reserved); } else if (tag == "objectnodewidget") { widget = new ObjectNodeWidget(view, ObjectNodeWidget::Normal, Uml::id_Reserved); } else if (tag == "regionwidget") { widget = new RegionWidget(view, Uml::id_Reserved); } else if (tag == "pinwidget") { widget = new PinWidget(view, NULL, Uml::id_Reserved); } else { // Loading of widgets which represent an UMLObject // Find the UMLObject and create the Widget to represent it Uml::IDType id = STR2ID(idStr); UMLDoc *umldoc = UMLApp::app()->document(); UMLObject *o = umldoc->findObjectById(id); if (o == NULL) { uDebug() << "makeWidgetFromXMI: cannot find object with id " << ID2STR(id) << endl; } if (tag == "actorwidget" || tag == "UML:ActorWidget") { if (validateObjType(Uml::ot_Actor, o, id)) widget = new ActorWidget(view, static_cast<UMLActor*>(o)); } else if (tag == "usecasewidget" || tag == "UML:UseCaseWidget") { if (validateObjType(Uml::ot_UseCase, o, id)) widget = new UseCaseWidget(view, static_cast<UMLUseCase*>(o)); } else if (tag == "classwidget" || tag == "UML:ClassWidget") { if (validateObjType(Uml::ot_Class, o, id)) widget = new ClassifierWidget(view, static_cast<UMLClassifier*>(o)); } else if (tag == "packagewidget") { if (validateObjType(Uml::ot_Package, o, id)) widget = new PackageWidget(view, static_cast<UMLPackage*>(o)); } else if (tag == "componentwidget") { if (validateObjType(Uml::ot_Component, o, id)) widget = new ComponentWidget(view, static_cast<UMLComponent*>(o)); } else if (tag == "nodewidget") { if (validateObjType(Uml::ot_Node, o, id)) widget = new NodeWidget(view, static_cast<UMLNode*>(o)); } else if (tag == "artifactwidget") { if (validateObjType(Uml::ot_Artifact, o, id)) widget = new ArtifactWidget(view, static_cast<UMLArtifact*>(o)); } else if (tag == "interfacewidget") { if (validateObjType(Uml::ot_Interface, o, id)) widget = new ClassifierWidget(view, static_cast<UMLClassifier*>(o)); } else if (tag == "datatypewidget") { if (validateObjType(Uml::ot_Datatype, o, id)) widget = new DatatypeWidget(view, static_cast<UMLClassifier*>(o)); } else if (tag == "enumwidget") { if (validateObjType(Uml::ot_Enum, o, id)) widget = new EnumWidget(view, static_cast<UMLEnum*>(o)); } else if (tag == "entitywidget") { if (validateObjType(Uml::ot_Entity, o, id)) widget = new EntityWidget(view, static_cast<UMLEntity*>(o)); } else if (tag == "categorywidget") { if (validateObjType(Uml::ot_Category, o, id)) widget = new CategoryWidget(view, static_cast<UMLCategory*>(o)); } else if (tag == "objectwidget" || tag == "UML:ObjectWidget") { widget = new ObjectWidget(view, o ); } else { uWarning() << "Trying to create an unknown widget:" << tag; } } return widget; }
/** * Loads the <UML:AssociationEnd> XMI element. * Auxiliary to UMLObject::loadFromXMI. */ bool UMLRole::load(QDomElement & element) { UMLDoc * doc = UMLApp::app()->document(); QString type = element.attribute(QLatin1String("type")); if (!type.isEmpty()) { if (!m_SecondaryId.isEmpty()) uWarning() << "overwriting old m_SecondaryId \"" << m_SecondaryId << " with new value \"" << type << "\""; m_SecondaryId = type; } // Inspect child nodes - for multiplicity (and type if not set above.) for (QDomNode node = element.firstChild(); !node.isNull(); node = node.nextSibling()) { if (node.isComment()) continue; QDomElement tempElement = node.toElement(); QString tag = tempElement.tagName(); if (UMLDoc::tagEq(tag, QLatin1String("name"))) { m_name = tempElement.text(); } else if (UMLDoc::tagEq(tag, QLatin1String("AssociationEnd.multiplicity"))) { /* * There are different ways in which the multiplicity might be given: * - direct value in the <AssociationEnd.multiplicity> tag, * - attributes "lower" and "upper" of a subordinate <MultiplicityRange>, * - direct value in subordinate <MultiplicityRange.lower> and * <MultiplicityRange.upper> tags */ QDomNode n = tempElement.firstChild(); if (node.isNull() || tempElement.isNull() || n.isNull() || n.toElement().isNull()) { m_Multi = tempElement.text().trimmed(); continue; } tempElement = n.toElement(); tag = tempElement.tagName(); if (!UMLDoc::tagEq(tag, QLatin1String("Multiplicity"))) { m_Multi = tempElement.text().trimmed(); continue; } n = tempElement.firstChild(); tempElement = n.toElement(); tag = tempElement.tagName(); if (!UMLDoc::tagEq(tag, QLatin1String("Multiplicity.range"))) { m_Multi = tempElement.text().trimmed(); continue; } n = tempElement.firstChild(); tempElement = n.toElement(); tag = tempElement.tagName(); if (!UMLDoc::tagEq(tag, QLatin1String("MultiplicityRange"))) { m_Multi = tempElement.text().trimmed(); continue; } QString multiUpper; if (tempElement.hasAttribute(QLatin1String("lower"))) { m_Multi = tempElement.attribute(QLatin1String("lower")); multiUpper = tempElement.attribute(QLatin1String("upper")); if (!multiUpper.isEmpty()) { if (!m_Multi.isEmpty()) m_Multi.append(QLatin1String("..")); m_Multi.append(multiUpper); } continue; } n = tempElement.firstChild(); while (!n.isNull()) { tempElement = n.toElement(); tag = tempElement.tagName(); if (UMLDoc::tagEq(tag, QLatin1String("MultiplicityRange.lower"))) { m_Multi = tempElement.text(); } else if (UMLDoc::tagEq(tag, QLatin1String("MultiplicityRange.upper"))) { multiUpper = tempElement.text(); } n = n.nextSibling(); } if (!multiUpper.isEmpty()) { if (!m_Multi.isEmpty()) m_Multi.append(QLatin1String("..")); m_Multi.append(multiUpper); } } else if (m_SecondaryId.isEmpty() && (UMLDoc::tagEq(tag, QLatin1String("type")) || UMLDoc::tagEq(tag, QLatin1String("participant")))) { m_SecondaryId = tempElement.attribute(QLatin1String("xmi.id")); if (m_SecondaryId.isEmpty()) m_SecondaryId = tempElement.attribute(QLatin1String("xmi.idref")); if (m_SecondaryId.isEmpty()) { QDomNode inner = tempElement.firstChild(); QDomElement innerElem = inner.toElement(); m_SecondaryId = innerElem.attribute(QLatin1String("xmi.id")); if (m_SecondaryId.isEmpty()) m_SecondaryId = innerElem.attribute(QLatin1String("xmi.idref")); } } } if (!m_Multi.isEmpty()) uDebug() << name() << ": m_Multi is " << m_Multi; if (m_SecondaryId.isEmpty()) { uError() << name() << ": type not given or illegal"; return false; } UMLObject * obj; obj = doc->findObjectById(Uml::ID::fromString(m_SecondaryId)); if (obj) { m_pSecondary = obj; m_SecondaryId = QString(); } // block signals to prevent needless updating blockSignals(true); // Here comes the handling of the association type. // This is open for discussion - I'm pretty sure there are better ways.. // Yeah, for one, setting the *parent* object parameters from here is sucky // as hell. Why are we using roleA to store what is essentially a parent (association) // parameter, eh? The UML13.dtd is pretty silly, but since that is what // is driving us to that point, we have to go with it. Some analysis of // the component roles/linked items needs to be done in order to get things // right. *sigh* -b.t. // Setting association type from the role (A) // Determination of the "aggregation" attribute used to be done only // when (m_role == Uml::RoleType::A) but some XMI writers (e.g. StarUML) place // the aggregation attribute at role B. // The role end with the aggregation unequal to "none" wins. QString aggregation = element.attribute(QLatin1String("aggregation"), QLatin1String("none")); if (aggregation == QLatin1String("composite")) m_pAssoc->setAssociationType(Uml::AssociationType::Composition); else if (aggregation == QLatin1String("shared") // UML1.3 || aggregation == QLatin1String("aggregate")) // UML1.4 m_pAssoc->setAssociationType(Uml::AssociationType::Aggregation); if (!element.hasAttribute(QLatin1String("isNavigable"))) { // Backward compatibility mode: In Umbrello version 1.3.x the // logic for saving the isNavigable flag was wrong. // May happen on loading role A. m_pAssoc->setOldLoadMode(true); } else if (m_pAssoc->getOldLoadMode() == true) { // Here is the original logic: // "Role B: // If isNavigable is not given, we make no change to the // association type. // If isNavigable is given, and is "true", then we assume that // the association's other end (role A) is not navigable, and // therefore we change the association type to UniAssociation. // The case that isNavigable is given as "false" is ignored. // Combined with the association type logic for role A, this // allows us to support at_Association and at_UniAssociation." if (element.attribute(QLatin1String("isNavigable")) == QLatin1String("true")) m_pAssoc->setAssociationType(Uml::AssociationType::UniAssociation); } else if (element.attribute(QLatin1String("isNavigable")) == QLatin1String("false")) { m_pAssoc->setAssociationType(Uml::AssociationType::UniAssociation); } //FIXME not standard XMI if (element.hasAttribute(QLatin1String("relationship"))) { if (element.attribute(QLatin1String("relationship")) == QLatin1String("true")) { m_pAssoc->setAssociationType(Uml::AssociationType::Relationship); } } if (m_Multi.isEmpty()) m_Multi = element.attribute(QLatin1String("multiplicity")); // Changeability defaults to Changeable if it cant set it here.. m_Changeability = Uml::Changeability::Changeable; QString changeability = element.attribute(QLatin1String("changeability")); if (changeability.isEmpty()) element.attribute(QLatin1String("changeable")); // for backward compatibility if (changeability == QLatin1String("frozen")) m_Changeability = Uml::Changeability::Frozen; else if (changeability == QLatin1String("addOnly")) m_Changeability = Uml::Changeability::AddOnly; // finished config, now unblock blockSignals(false); return true; }
/** * Need to overwrite this for ruby since we need to pick up the * ruby class declaration block. * Sigh. NOT optimal. The only reason that we need to have this * is so we can create the RubyClassDeclarationBlock. * would be better if we could create a handler interface that each * codeblock used so all we have to do here is add the handler * for "rubyclassdeclarationblock". */ void RubyClassifierCodeDocument::loadChildTextBlocksFromNode(QDomElement & root) { QDomNode tnode = root.firstChild(); QDomElement telement = tnode.toElement(); bool loadCheckForChildrenOK = false; while (!telement.isNull()) { QString nodeName = telement.tagName(); if (nodeName == QLatin1String("textblocks")) { QDomNode node = telement.firstChild(); QDomElement element = node.toElement(); // if there is nothing to begin with, then we don't worry about it loadCheckForChildrenOK = element.isNull() ? true : false; while (!element.isNull()) { QString name = element.tagName(); if (name == QLatin1String("codecomment")) { CodeComment * block = new RubyCodeComment(this); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"loadFromXMI : unable to add codeComment to :"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeaccessormethod") || name == QLatin1String("ccfdeclarationcodeblock")) { QString acctag = element.attribute(QLatin1String("tag")); // search for our method in the TextBlock * tb = findCodeClassFieldTextBlockByTag(acctag); if (!tb || !addTextBlock(tb)) { uError()<<"loadFromXMI : unable to add codeclassfield child method to:"<<this; // DON'T delete } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeblock")) { CodeBlock * block = newCodeBlock(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"loadFromXMI : unable to add codeBlock to :"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeblockwithcomments")) { CodeBlockWithComments * block = newCodeBlockWithComments(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"loadFromXMI : unable to add codeBlockwithcomments to:"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("header")) { // do nothing.. this is treated elsewhere } else if (name == QLatin1String("hierarchicalcodeblock")) { HierarchicalCodeBlock * block = newHierarchicalCodeBlock(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add hierarchicalcodeBlock to:"<<this; delete block; } else { loadCheckForChildrenOK= true; } } else if (name == QLatin1String("codeoperation")) { // find the code operation by id QString id = element.attribute(QLatin1String("parent_id"), QLatin1String("-1")); UMLObject * obj = UMLApp::app()->document()->findObjectById(Uml::ID::fromString(id)); UMLOperation * op = dynamic_cast<UMLOperation*>(obj); if (op) { CodeOperation * block = new RubyCodeOperation(this, op); block->loadFromXMI(element); if (addTextBlock(block)) { loadCheckForChildrenOK= true; } else { uError()<<"Unable to add codeoperation to:"<<this; block->deleteLater(); } } else { uError()<<"Unable to find operation create codeoperation for:"<<this; } } else if (name == QLatin1String("rubyclassdeclarationblock")) { RubyClassDeclarationBlock * block = getClassDecl(); block->loadFromXMI(element); if (!addTextBlock(block)) { uError()<<"Unable to add ruby code declaration block to:"<<this; // DON'T delete. // block->deleteLater(); } else { loadCheckForChildrenOK= true; } } else { uDebug()<<" LoadFromXMI: Got strange tag in text block stack:"<<name<<", ignoring"; } node = element.nextSibling(); element = node.toElement(); } break; } tnode = telement.nextSibling(); telement = tnode.toElement(); } if (!loadCheckForChildrenOK) { CodeDocument * test = dynamic_cast<CodeDocument*>(this); if (test) { uWarning()<<" loadChildBlocks : unable to initialize any child blocks in doc: "<<test->getFileName()<<" "<<this; } else { HierarchicalCodeBlock * hb = dynamic_cast<HierarchicalCodeBlock*>(this); if (hb) uWarning()<<" loadChildBlocks : unable to initialize any child blocks in Hblock: "<<hb->getTag()<<" "<<this; else uDebug()<<" loadChildBlocks : unable to initialize any child blocks in UNKNOWN OBJ:"<<this; } } }
UMLWidget *createWidget(UMLView *view, UMLObject *o) { QPoint pos = view->getPos(); int y = pos.y(); Uml::Diagram_Type diagramType = view->getType(); Uml::Object_Type type = o->baseType(); UMLWidget *newWidget = NULL; switch (type) { case Uml::ot_Actor: if (diagramType == Uml::dt_Sequence) { ObjectWidget *ow = new ObjectWidget(view, o, view->getLocalID()); ow->setDrawAsActor(true); y = ow->topMargin(); newWidget = ow; } else newWidget = new ActorWidget(view, static_cast<UMLActor*>(o)); break; case Uml::ot_UseCase: newWidget = new UseCaseWidget(view, static_cast<UMLUseCase*>(o)); break; case Uml::ot_Package: newWidget = new PackageWidget(view, static_cast<UMLPackage*>(o)); break; case Uml::ot_Component: newWidget = new ComponentWidget(view, static_cast<UMLComponent*>(o)); if (diagramType == Uml::dt_Deployment) { newWidget->setIsInstance(true); } break; case Uml::ot_Node: newWidget = new NodeWidget(view, static_cast<UMLNode*>(o)); break; case Uml::ot_Artifact: newWidget = new ArtifactWidget(view, static_cast<UMLArtifact*>(o)); break; case Uml::ot_Datatype: newWidget = new DatatypeWidget(view, static_cast<UMLClassifier*>(o)); break; case Uml::ot_Enum: newWidget = new EnumWidget(view, static_cast<UMLEnum*>(o)); break; case Uml::ot_Entity: newWidget = new EntityWidget(view, static_cast<UMLEntity*>(o)); break; case Uml::ot_Interface: if (diagramType == Uml::dt_Sequence || diagramType == Uml::dt_Collaboration) { ObjectWidget *ow = new ObjectWidget(view, o, view->getLocalID() ); if (diagramType == Uml::dt_Sequence) { y = ow->topMargin(); } newWidget = ow; } else { UMLClassifier *c = static_cast<UMLClassifier*>(o); ClassifierWidget* interfaceWidget = new ClassifierWidget(view, c); if (diagramType == Uml::dt_Component || diagramType == Uml::dt_Deployment) { interfaceWidget->setDrawAsCircle(true); } newWidget = interfaceWidget; } break; case Uml::ot_Class: //see if we really want an object widget or class widget if (diagramType == Uml::dt_Class || diagramType == Uml::dt_Component) { UMLClassifier *c = static_cast<UMLClassifier*>(o); ClassifierWidget *cw = new ClassifierWidget(view, c); if (diagramType == Uml::dt_Component) cw->setDrawAsCircle(true); newWidget = cw; } else { ObjectWidget *ow = new ObjectWidget(view, o, view->getLocalID() ); if (diagramType == Uml::dt_Sequence) { y = ow->topMargin(); } newWidget = ow; } break; case Uml::ot_Category: newWidget = new CategoryWidget(view, static_cast<UMLCategory*>(o)); break; default: uWarning() << "trying to create an invalid widget"; } if (newWidget) { newWidget->setX( pos.x() ); newWidget->setY( y ); } return newWidget; }