bool UMLClipboard::pasteChildren(UMLListViewItem *parent, IDChangeLog *chgLog) { if (!parent) { kWarning() << "Paste Children Error, parent missing" << endl; return false; } UMLDoc *doc = UMLApp::app()->getDocument(); UMLListView *listView = UMLApp::app()->getListView(); UMLListViewItem *childItem = static_cast<UMLListViewItem*>(parent->firstChild()); while (childItem) { Uml::IDType oldID = childItem->getID(); Uml::IDType newID = chgLog->findNewID(oldID); UMLListViewItem *shouldNotExist = listView->findItem(newID); if (shouldNotExist) { kError() << "UMLClipboard::pasteChildren: new list view item " << ID2STR(newID) << " already exists (internal error)" << endl; childItem = static_cast<UMLListViewItem*>(childItem->nextSibling()); continue; } UMLObject *newObj = doc->findObjectById(newID); if (newObj) { kDebug() << "UMLClipboard::pasteChildren: adjusting lvitem(" << ID2STR(oldID) << ") to new UMLObject(" << ID2STR(newID) << ")" << endl; childItem->setUMLObject(newObj); childItem->setText(newObj->getName()); } else { kDebug() << "UMLClipboard::pasteChildren: no UMLObject found for lvitem " << ID2STR(newID) << endl; } childItem = static_cast<UMLListViewItem*>(childItem->nextSibling()); } return true; }
bool UMLClipboard::paste(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); bool result = false; doc->beginPaste(); switch(UMLDrag::getCodingType(data)) { case 1: result = pasteClip1(data); break; case 2: result = pasteClip2(data); break; case 3: result = pasteClip3(data); break; case 4: result = pasteClip4(data); break; case 5: result = pasteClip5(data); break; default: break; } doc->endPaste(); return result; }
/** * Inserts @p type into the type-combobox as well as its completion object. */ void UMLEntityAttributeDialog::insertTypesSorted(const QString& type) { QStringList types; // add the data types UMLDoc * pDoc = UMLApp::app()->document(); UMLClassifierList dataTypes = pDoc->datatypes(); if (dataTypes.count() == 0) { // Switch to SQL as the active language if no datatypes are set. UMLApp::app()->setActiveLanguage(Uml::ProgrammingLanguage::SQL); pDoc->addDefaultDatatypes(); qApp->processEvents(); dataTypes = pDoc->datatypes(); } foreach (UMLClassifier* dat, dataTypes) { types << dat->name(); } // add the given parameter if (!types.contains(type)) { types << type; } types.sort(); m_pTypeCB->clear(); m_pTypeCB->insertItems(-1, types); // select the given parameter int currentIndex = m_pTypeCB->findText(type); if (currentIndex > -1) { m_pTypeCB->setCurrentIndex(currentIndex); } m_pTypeCB->completionObject()->addItem(type); }
/** If clipboard has mime type application/x-uml-clip3, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip3(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); UMLListViewItemList itemdatalist; UMLListViewItem* item = 0; UMLListViewItem* itemdata = 0; IDChangeLog* idchanges = doc->getChangeLog(); if(!idchanges) { return false; } UMLListView *listView = UMLApp::app()->getListView(); bool result = UMLDrag::decodeClip3(data, itemdatalist, listView); if(!result) { return false; } UMLListViewItemListIt it(itemdatalist); while ( (itemdata=it.current()) != 0 ) { item = listView->createItem(*itemdata, *idchanges); if(itemdata -> childCount()) { if(!pasteChildren(item, idchanges)) { return false; } } ++it; } return result; }
/** * Analyzes the given QDomElement for a reference to a stereotype. * * @param element QDomElement to analyze. * @return True if a stereotype reference was found, else false. */ bool UMLObject::loadStereotype(QDomElement & element) { QString tag = element.tagName(); if (!UMLDoc::tagEq(tag, QLatin1String("stereotype"))) return false; QString stereo = element.attribute(QLatin1String("xmi.value")); if (stereo.isEmpty() && element.hasChildNodes()) { /* like so: <UML:ModelElement.stereotype> <UML:Stereotype xmi.idref = '07CD'/> </UML:ModelElement.stereotype> */ QDomNode stereoNode = element.firstChild(); QDomElement stereoElem = stereoNode.toElement(); tag = stereoElem.tagName(); if (UMLDoc::tagEq(tag, QLatin1String("Stereotype"))) { stereo = stereoElem.attribute(QLatin1String("xmi.idref")); } } if (stereo.isEmpty()) return false; Uml::ID::Type stereoID = Uml::ID::fromString(stereo); UMLDoc *pDoc = UMLApp::app()->document(); m_pStereotype = pDoc->findStereotypeById(stereoID); if (m_pStereotype) m_pStereotype->incrRefCount(); else m_SecondaryId = stereo; // leave it to resolveRef() return true; }
/** * Slot for the generate button. Starts the code generation. */ void CodeGenStatusPage::generateCode() { ui_pushButtonGenerate->setEnabled(false); setCommitPage(true); //:TODO: disable back and cancel button ? CodeGenerator* codeGenerator = UMLApp::app()->generator(); UMLDoc* doc = UMLApp::app()->document(); if (codeGenerator) { connect(codeGenerator, SIGNAL(codeGenerated(UMLClassifier*,bool)), this, SLOT(classGenerated(UMLClassifier*,bool))); connect(codeGenerator, SIGNAL(showGeneratedFile(QString)), this, SLOT(showFileGenerated(QString))); UMLClassifierList cList; for (int row = 0; row < ui_tableWidgetStatus->rowCount(); ++row) { QTableWidgetItem* item = ui_tableWidgetStatus->item(row, 0); UMLClassifier *concept = doc->findUMLClassifier(item->text()); if (concept == NULL) { uError() << "Could not find classifier " << item->text() << " - not included in generated code."; continue; } cList.append(concept); } codeGenerator->writeCodeToFile(cList); m_generationDone = true; setFinalPage(true); emit completeChanged(); } }
/** * Inserts @p type into the type-combobox. * The combobox is cleared and all types together with the optional new one * sorted and then added again. * @param type a new type to add and selected */ void UMLTemplateDialog::insertTypesSorted(const QString& type) { QStringList types; // "class" is the nominal type of template parameter types << "class"; // add the active data types to combo box UMLDoc *pDoc = UMLApp::app()->document(); UMLClassifierList namesList( pDoc->concepts() ); foreach (UMLClassifier* obj, namesList) { types << obj->name(); } // add the given parameter if ( !types.contains(type) ) { types << type; } types.sort(); m_pTypeCB->clear(); m_pTypeCB->insertItems(-1, types); // select the given parameter int currentIndex = m_pTypeCB->findText(type); if (currentIndex > -1) { m_pTypeCB->setCurrentIndex(currentIndex); } }
void UMLClipboard::checkItemForCopyType(UMLListViewItem* Item, bool & WithDiagrams, bool &WithObjects, bool &OnlyAttsOps) { if(!Item) { return; } UMLDoc *doc = UMLApp::app()->getDocument(); OnlyAttsOps = true; UMLView * view = 0; UMLListViewItem * child = 0; Uml::ListView_Type type = Item->getType(); if ( Model_Utils::typeIsCanvasWidget(type) ) { WithObjects = true; OnlyAttsOps = false; } else if ( Model_Utils::typeIsDiagram(type) ) { WithDiagrams = true; OnlyAttsOps = false; view = doc->findView( Item->getID() ); m_ViewList.append( view ); } else if ( Model_Utils::typeIsFolder(type) ) { OnlyAttsOps = false; if(Item->childCount()) { child = (UMLListViewItem*)Item->firstChild(); while(child) { checkItemForCopyType(child, WithDiagrams, WithObjects, OnlyAttsOps); child = (UMLListViewItem*)child->nextSibling(); } } } }
void Docbook2XhtmlGeneratorJob::run() { UMLDoc* umlDoc = UMLApp::app()->document(); xsltStylesheetPtr cur = NULL; xmlDocPtr doc, res; const char *params[16 + 1]; int nbparams = 0; params[nbparams] = NULL; umlDoc->writeToStatusBar(i18n("Exporting to XHTML...")); QString xsltFileName(KGlobal::dirs()->findResource("appdata", QLatin1String("docbook2xhtml.xsl"))); uDebug() << "XSLT file is'" << xsltFileName << "'"; QFile xsltFile(xsltFileName); xsltFile.open(QIODevice::ReadOnly); QString xslt = QString::fromLatin1(xsltFile.readAll()); uDebug() << "XSLT is'" << xslt << "'"; xsltFile.close(); QString localXsl = KGlobal::dirs()->findResource("data", QLatin1String("ksgmltools2/docbook/xsl/html/docbook.xsl")); uDebug() << "Local xsl is'" << localXsl << "'"; if (!localXsl.isEmpty()) { localXsl = QLatin1String("href=\"file://") + localXsl + QLatin1String("\""); xslt.replace(QRegExp(QLatin1String("href=\"http://[^\"]*\"")), localXsl); } KTemporaryFile tmpXsl; tmpXsl.setAutoRemove(false); tmpXsl.open(); QTextStream str (&tmpXsl); str << xslt; str.flush(); xmlSubstituteEntitiesDefault(1); xmlLoadExtDtdDefaultValue = 1; uDebug() << "Parsing stylesheet " << tmpXsl.fileName(); cur = xsltParseStylesheetFile((const xmlChar *)tmpXsl.fileName().toLatin1().constData()); uDebug() << "Parsing file " << m_docbookUrl.path(); doc = xmlParseFile((const char*)(m_docbookUrl.path().toUtf8())); uDebug() << "Applying stylesheet "; res = xsltApplyStylesheet(cur, doc, params); KTemporaryFile tmpXhtml; tmpXhtml.setAutoRemove(false); tmpXhtml.open(); uDebug() << "Writing HTML result to temp file: " << tmpXhtml.fileName(); xsltSaveResultToFd(tmpXhtml.handle(), res, cur); xsltFreeStylesheet(cur); xmlFreeDoc(res); xmlFreeDoc(doc); xsltCleanupGlobals(); xmlCleanupParser(); emit xhtmlGenerated(tmpXhtml.fileName()); }
void NoteWidgetController::doMouseDoubleClick(QMouseEvent *me) { //TODO Copied from old code. What it does? if (m_noteWidget->m_DiagramLink == Uml::id_None) { m_noteWidget->slotMenuSelection(ListPopupMenu::mt_Rename); } else { UMLDoc *umldoc = UMLApp::app()->getDocument(); umldoc->changeCurrentView(m_noteWidget->m_DiagramLink); } }
/** * Add C++ stereotypes. */ void createCppStereotypes() { UMLDoc *umldoc = UMLApp::app()->document(); umldoc->findOrCreateStereotype("constructor"); // declares an operation as friend umldoc->findOrCreateStereotype("friend"); // to use in methods that aren't abstract umldoc->findOrCreateStereotype("virtual"); }
UMLObject* CmdBaseObjectCommand::object() { UMLDoc *doc = UMLApp::app()->document(); UMLObject *umlObject = doc->findObjectById(m_objectId); if (!umlObject) umlObject = m_object; return umlObject; }
void UMLObject::setStereotypeCmd(const QString& name) { if (name.isEmpty()) { setUMLStereotype(NULL); return; } UMLDoc *pDoc = UMLApp::app()->document(); UMLStereotype *s = pDoc->findOrCreateStereotype(name); setUMLStereotype(s); }
/** * Calls UMLDoc::signalUMLObjectCreated() if m_BaseType affords * doing so. */ void UMLObject::maybeSignalObjectCreated() { if (!m_bCreationWasSignalled && m_BaseType != ot_Stereotype && m_BaseType != ot_Association && m_BaseType != ot_Role) { m_bCreationWasSignalled = true; UMLDoc* umldoc = UMLApp::app()->document(); umldoc->signalUMLObjectCreated(this); } }
/** If clipboard has mime type application/x-uml-clip2, Pastes the data from the clipboard into the current Doc */ bool UMLClipboard::pasteClip2(QMimeSource* data) { UMLDoc *doc = UMLApp::app()->getDocument(); UMLListViewItemList itemdatalist; UMLObjectList objects; objects.setAutoDelete(false); UMLViewList views; IDChangeLog* idchanges = 0; bool result = UMLDrag::decodeClip2(data, objects, itemdatalist, views); if(!result) { return false; } UMLObject *obj = 0; UMLObjectListIt object_it(objects); idchanges = doc->getChangeLog(); if(!idchanges) { return false; } while ( (obj=object_it.current()) != 0 ) { ++object_it; if(!doc->assignNewIDs(obj)) { kDebug()<<"UMLClipboard: error adding umlobject"<<endl; return false; } } UMLView * pView = 0; UMLViewListIt view_it( views ); while ( ( pView =view_it.current()) != 0 ) { ++view_it; if( !doc->addUMLView( pView ) ) { return false; } } UMLListView *listView = UMLApp::app()->getListView(); UMLListViewItem* item = 0; UMLListViewItem* itemdata = 0; UMLListViewItemListIt it(itemdatalist); while ( (itemdata=it.current()) != 0 ) { item = listView->createItem(*itemdata, *idchanges); if(!item) { return false; } if(itemdata -> childCount()) { if(!pasteChildren(item, idchanges)) { return false; } } ++it; } return result; }
/** * Sets the classes stereotype name. * Internally uses setUMLStereotype(). * * @param _name Sets the classes stereotype name. */ void UMLObject::setStereotype(const QString &_name) { // UMLDoc* pDoc = UMLApp::app()->document(); // pDoc->executeCommand(new cmdSetStereotype(this,_name)); if (_name.isEmpty()) { setUMLStereotype(NULL); return; } UMLDoc *pDoc = UMLApp::app()->document(); UMLStereotype *s = pDoc->findOrCreateStereotype(_name); setUMLStereotype(s); }
/** * Set the ID of the diagram hyperlinked to this note. * To switch off the hyperlink, set this to Uml::id_None. * * @param viewID ID of an UMLScene. */ void NoteWidget::setDiagramLink(Uml::ID::Type viewID) { UMLDoc *umldoc = UMLApp::app()->document(); UMLView *view = umldoc->findView(viewID); if (view == NULL) { uError() << "no view found for viewID " << Uml::ID::toString(viewID); return; } QString linkText(QLatin1String("Diagram: ") + view->umlScene()->name()); setDocumentation(linkText); m_diagramLink = viewID; update(); }
/** * Import files. * @param fileNames List of files to import. */ bool ClassImport::importFiles(const QStringList& fileNames) { initialize(); UMLDoc *umldoc = UMLApp::app()->document(); uint processedFilesCount = 0; bool result = true; umldoc->setLoading(true); foreach (const QString& fileName, fileNames) { umldoc->writeToStatusBar(i18n("Importing file: %1 Progress: %2/%3", fileName, processedFilesCount, fileNames.size())); if (!importFile(fileName)) result = false; processedFilesCount++; }
/** * Creates a Unique Constraint for this Entity. * @param name an optional name * @return the UniqueConstraint created */ UMLUniqueConstraint* UMLEntity::createUniqueConstraint(const QString &name ) { Uml::IDType id = UniqueID::gen(); QString currentName; if (name.isNull()) { /** * @todo check parameter */ currentName = uniqChildName(UMLObject::ot_UniqueConstraint); } else { currentName = name; } UMLUniqueConstraint* newUniqueConstraint = new UMLUniqueConstraint(this, currentName, id); int button = KDialog::Accepted; bool goodName = false; //check for name.isNull() stops dialog being shown //when creating attribute via list view while (button == KDialog::Accepted && !goodName && name.isNull()) { QPointer<UMLUniqueConstraintDialog> dialog = new UMLUniqueConstraintDialog(0, newUniqueConstraint); button = dialog->exec(); QString name = newUniqueConstraint->name(); if (name.length() == 0) { KMessageBox::error(0, i18n("That is an invalid name."), i18n("Invalid Name")); } else if ( findChildObject(name) != NULL ) { KMessageBox::error(0, i18n("That name is already being used."), i18n("Not a Unique Name")); } else { goodName = true; } delete dialog; } if (button != KDialog::Accepted) { delete newUniqueConstraint; return NULL; } addConstraint(newUniqueConstraint); UMLDoc *umldoc = UMLApp::app()->document(); umldoc->signalUMLObjectCreated(newUniqueConstraint); emitModified(); return newUniqueConstraint; }
// Create the UMLObject void CmdCreateUMLObject::redo() { // This object was removed from it's package when it was deleted // so add it back to it's package ( if it belonged to one ) UMLPackage *pkg = m_obj->umlPackage(); if (pkg) { // add this object to its parent package pkg->addObject(m_obj); } else { // object does not belong to any package } UMLDoc *doc = UMLApp::app()->document(); doc->signalUMLObjectCreated(m_obj); }
void UMLAttribute::setTemplateParams(const QString& templateParam, UMLClassifierList &templateParamList) { if (templateParam.isEmpty()) return; QString type = templateParam.simplifyWhiteSpace(); int start = type.find(QChar('<')); if (start >= 0 ) { int end = start; int count = 1; int len = type.length(); while (count != 0 && ++end < len) { QChar c = type.at(end); if (c == QChar('<')) { count++; } if (c == QChar('>')) { count--; } } if (count != 0) { //The template is ill-formated, let's quit return; } setTemplateParams(type.mid(start + 1, end - start - 1), templateParamList); setTemplateParams(type.left(start) + type.right(len - end - 1), templateParamList); } else { QStringList paramsList = QStringList::split(QChar(','), type); for ( QStringList::Iterator it = paramsList.begin(); it != paramsList.end(); ++it ) { QString param = *it; if (!param.isEmpty()) { UMLDoc *pDoc = UMLApp::app()->getDocument(); UMLObject* obj = pDoc->findUMLObject(param); if (obj == NULL ) { obj = pDoc->findUMLObject(param.remove(QChar(' '))); } if (obj != NULL ) { //We want to list only the params that already exist in this document //If the param doesnt't already exist, we couldn't draw an association anyway UMLClassifier* tmpClassifier = static_cast<UMLClassifier*>(obj); if (templateParamList.findRef(tmpClassifier) == -1) { templateParamList.append(tmpClassifier); } } } } } }
/** * Create an UMLAttribute. * @param name an optional name for the attribute * @param type an optional type object for the attribute * @param vis the visibility of the attribute * @param iv the initial value for the attribute * @return the just created attribute or null */ UMLAttribute* UMLEntity::createAttribute(const QString &name /*= QString()*/, UMLObject *type /*= 0*/, Uml::Visibility vis /* = Uml::Visibility::Private*/, const QString& iv /* = QString()*/) { Uml::IDType id = UniqueID::gen(); QString currentName; if (name.isNull()) { currentName = uniqChildName(UMLObject::ot_EntityAttribute); } else { currentName = name; } UMLEntityAttribute* newAttribute = new UMLEntityAttribute(this, currentName, id, vis, type, iv); int button = KDialog::Accepted; bool goodName = false; //check for name.isNull() stops dialog being shown //when creating attribute via list view while (button == KDialog::Accepted && !goodName && name.isNull()) { QPointer<UMLEntityAttributeDialog> dialog = new UMLEntityAttributeDialog(0, newAttribute); button = dialog->exec(); QString name = newAttribute->name(); if (name.length() == 0) { KMessageBox::error(0, i18n("That is an invalid name."), i18n("Invalid Name")); } else if ( findChildObject(name) != NULL ) { KMessageBox::error(0, i18n("That name is already being used."), i18n("Not a Unique Name")); } else { goodName = true; } delete dialog; } if (button != KDialog::Accepted) { delete newAttribute; return 0; } addEntityAttribute(newAttribute); UMLDoc *umldoc = UMLApp::app()->document(); umldoc->signalUMLObjectCreated(newAttribute); return newAttribute; }
/** * Sets the class' UMLStereotype. Adjusts the reference counts * at the previously set stereotype and at the new stereotype. * If the previously set UMLStereotype's reference count drops * to zero then the UMLStereotype is removed at the UMLDoc and * it is then physically deleted. * * @param stereo Sets the classes UMLStereotype. */ void UMLObject::setUMLStereotype(UMLStereotype *stereo) { if (stereo == m_pStereotype) return; if (stereo) { stereo->incrRefCount(); } if (m_pStereotype) { m_pStereotype->decrRefCount(); if (m_pStereotype->refCount() == 0) { UMLDoc *pDoc = UMLApp::app()->document(); pDoc->removeStereotype(m_pStereotype); delete m_pStereotype; } } m_pStereotype = stereo; // TODO: don't emit modified() if predefined folder emitModified(); }
/** * Adds an AssociationWidget to the association list and creates the * corresponding UMLAssociation in the current UMLDoc. * If the association can't be added, is deleted. * * @param assoc The AssociationWidget to add. * @return True on success */ bool ToolBarStateAssociation::addAssociationInViewAndDoc(AssociationWidget* assoc) { // append in view if (m_pUMLScene->addAssociation(assoc, false)) { // if view went ok, then append in document UMLAssociation *umla = assoc->association(); if (umla) { // association with model representation in UMLDoc Uml::ModelType::Enum m = Model_Utils::convert_DT_MT(m_pUMLScene->type()); UMLDoc *umldoc = UMLApp::app()->document(); umla->setUMLPackage(umldoc->rootFolder(m)); umldoc->addAssociation(umla); } return true; } else { uError() << "cannot addAssocInViewAndDoc(), deleting"; delete assoc; return false; } }
/** * Sets the classes Package. * DEPRECATED - use SetUMLPackage instead. * * @param _name The classes Package name. */ void UMLObject::setPackage(const QString &_name) { UMLObject *pkgObj = NULL; if (!_name.isEmpty()) { UMLDoc* umldoc = UMLApp::app()->document(); pkgObj = umldoc->findUMLObject(_name); if (pkgObj == NULL) { uDebug() << "creating UMLPackage " << _name << " for " << m_name; pkgObj = Import_Utils::createUMLObject(ot_Package, _name); } else { const ObjectType ot = pkgObj->baseType(); if (ot != ot_Package && ot != ot_Folder && ot != ot_Component) { uError() << m_name << ": " << "existing " << _name << " is not a container"; // This should not happen - if it does, there may be further problems. // A container name should not overlap with another name in the same scope. pkgObj = Import_Utils::createUMLObject(ot_Package, _name); } } } setUMLPackage(static_cast<UMLPackage *>(pkgObj)); }
/** * This is really an auxiliary method for loadFromMDL() but is kept in a * separate file to reflect that it is not coupled with the parser * (other than by the PetalNode.) * * @param root the root of the tree * @return true for success. */ bool petalTree2Uml(PetalNode *root) { if (root == NULL) { uError() << "petalTree2Uml: root is NULL"; return false; } if (root->name() != "Design") { uError() << "petalTree2Uml: expecting root name Design"; return false; } //*************************** import Logical View ******************************** PetalNode *root_category = root->findAttribute("root_category").node; if (root_category == NULL) { uError() << "petalTree2Uml: cannot find root_category"; return false; } if (root_category->name() != "Class_Category") { uError() << "petalTree2Uml: expecting root_category object Class_Category"; return false; } PetalNode *logical_models = root_category->findAttribute("logical_models").node; if (logical_models == NULL) { uError() << "petalTree2Uml: cannot find logical_models"; return false; } UMLDoc *umldoc = UMLApp::app()->document(); umldoc->setCurrentRoot(Uml::ModelType::Logical); Import_Utils::assignUniqueIdOnCreation(false); PetalNode::NameValueList atts = logical_models->attributes(); for (int i = 0; i < atts.count(); ++i) { umbrellify(atts[i].second.node); } // Shorthand for UMLApp::app()->listView() UMLListView *lv = UMLApp::app()->listView(); //*************************** import Use Case View ******************************** umldoc->setCurrentRoot(Uml::ModelType::UseCase); importView(root, "root_usecase_package", "logical_models", lv->theUseCaseView()); //*************************** import Component View ******************************* umldoc->setCurrentRoot(Uml::ModelType::Component); importView(root, "root_subsystem", "physical_models", lv->theComponentView()); //*************************** import Deployment View ****************************** umldoc->setCurrentRoot(Uml::ModelType::Deployment); importView(root, "process_structure", "ProcsNDevs", lv->theDeploymentView()); //*************************** wrap up ******************************** umldoc->setCurrentRoot(Uml::ModelType::Logical); Import_Utils::assignUniqueIdOnCreation(true); umldoc->resolveTypes(); return true; }
/** * Checks if changes are valid and applies them if they are, * else returns false */ bool UMLTemplateDialog::apply() { QString typeName = m_pTypeCB->currentText(); UMLDoc *pDoc = UMLApp::app()->document(); UMLClassifierList namesList( pDoc->concepts() ); foreach (UMLClassifier* obj, namesList) { if (typeName == obj->name()) { m_pTemplate->setType(obj); } } if (namesList.isEmpty()) { // not found. // FIXME: This implementation is not good yet. m_pTemplate->setTypeName( typeName ); } QString name = m_pNameLE->text(); if( name.length() == 0 ) { KMessageBox::error(this, i18n("You have entered an invalid template name."), i18n("Template Name Invalid"), false); m_pNameLE->setText( m_pTemplate->name() ); return false; } UMLClassifier * pClass = dynamic_cast<UMLClassifier *>( m_pTemplate->parent() ); if (pClass) { UMLObject *o = pClass->findChildObject(name); if (o && o != m_pTemplate) { KMessageBox::error(this, i18n("The template parameter name you have chosen is already being used in this operation."), i18n("Template Name Not Unique"), false); m_pNameLE->setText( m_pTemplate->name() ); return false; } } m_pTemplate->setName(name); m_pTemplate->setStereotype( m_pStereoTypeLE->text() ); return true; }
/** * Create the UMLObject. */ void CmdCreateUMLObject::redo() { // This object was removed from its package when it was deleted // so add it back to its package (if it belonged to one) if (m_package) { if (m_package->baseType() != UMLObject::ot_Association) { // add this object to its parent package m_package->addObject(m_obj); } else uError() << "Try to use an unsupported Association as parent"; } // The first call to redo, the object was created and signalled by the // caller (umlscene). On subsequent calls we use the "umlobject created" // signal to update Umbrello with the re-added object. if (m_skipSignal) { m_skipSignal = false; } else { UMLDoc *doc = UMLApp::app()->document(); doc->signalUMLObjectCreated(m_obj); } }
/** * Returns the fully qualified name, i.e. all package prefixes and then m_name. * * @param separator The separator string to use (optional.) * If not given then the separator is chosen according * to the currently selected active programming language * of import and code generation. * @param includeRoot Whether to prefix the root folder name to the FQN. * See UMLDoc::getRootFolder(). Default: false. * @return The fully qualified name of this UMLObject. */ QString UMLObject::fullyQualifiedName(const QString& separator, bool includeRoot /* = false */) const { QString fqn; if (m_pUMLPackage && m_pUMLPackage != this) { bool skipPackage = false; if (!includeRoot) { UMLDoc *umldoc = UMLApp::app()->document(); if (umldoc->rootFolderType(m_pUMLPackage) != Uml::ModelType::N_MODELTYPES || m_pUMLPackage == umldoc->datatypeFolder()) skipPackage = true; } if (!skipPackage) { QString tempSeparator = separator; if (tempSeparator.isEmpty()) tempSeparator = UMLApp::app()->activeLanguageScopeSeparator(); fqn = m_pUMLPackage->fullyQualifiedName(tempSeparator, includeRoot); fqn.append(tempSeparator); } } fqn.append(m_name); return fqn; }
/** * This method loads the generic parts of the XMI common to most model * classes. It is not usually reimplemented by child classes. * Instead, it invokes the load() method which implements the loading * of the specifics of each child class. * * @param element The QDomElement from which to load. */ bool UMLObject::loadFromXMI(QDomElement & element) { UMLDoc* umldoc = UMLApp::app()->document(); if (umldoc == 0) { uError() << "umldoc is NULL"; return false; } // Read the name first so that if we encounter a problem, the error // message can say the name. m_name = element.attribute(QLatin1String("name")); QString id = Model_Utils::getXmiId(element); if (id.isEmpty() || id == QLatin1String("-1")) { // Before version 1.4, Umbrello did not save the xmi.id of UMLRole objects. // Some tools (such as Embarcadero's) do not have an xmi.id on all attributes. m_nId = UniqueID::gen(); uWarning() << m_name << ": xmi.id not present, generating a new one"; } else { Uml::ID::Type nId = Uml::ID::fromString(id); if (m_BaseType == ot_Role) { // Some older Umbrello versions had a problem with xmi.id's // of other objects being reused for the UMLRole, see e.g. // attachment 21179 at http://bugs.kde.org/147988 . // If the xmi.id is already being used then we generate a new one. UMLObject *o = umldoc->findObjectById(nId); if (o) { uError() << "loadFromXMI(UMLRole): id " << id << " is already in use!!! Please fix your XMI file."; } } m_nId = nId; } if (element.hasAttribute(QLatin1String("documentation"))) // for bkwd compat. m_Doc = element.attribute(QLatin1String("documentation")); else m_Doc = element.attribute(QLatin1String("comment")); //CHECK: need a UML:Comment? m_visibility = Uml::Visibility::Public; if (element.hasAttribute(QLatin1String("scope"))) { // for bkwd compat. QString scope = element.attribute(QLatin1String("scope")); if (scope == QLatin1String("instance_level")) // nsuml compat. m_bStatic = false; else if (scope == QLatin1String("classifier_level")) // nsuml compat. m_bStatic = true; else { int nScope = scope.toInt(); switch (nScope) { case 200: m_visibility = Uml::Visibility::Public; break; case 201: m_visibility = Uml::Visibility::Private; break; case 202: m_visibility = Uml::Visibility::Protected; break; default: uError() << m_name << ": illegal scope " << nScope; } } } else { QString visibility = element.attribute(QLatin1String("visibility"), QLatin1String("public")); if (visibility == QLatin1String("private") || visibility == QLatin1String("private_vis")) // for compatibility with other programs m_visibility = Uml::Visibility::Private; else if (visibility == QLatin1String("protected") || visibility == QLatin1String("protected_vis")) // for compatibility with other programs m_visibility = Uml::Visibility::Protected; else if (visibility == QLatin1String("implementation")) m_visibility = Uml::Visibility::Implementation; } QString stereo = element.attribute(QLatin1String("stereotype")); if (!stereo.isEmpty()) { Uml::ID::Type stereoID = Uml::ID::fromString(stereo); m_pStereotype = umldoc->findStereotypeById(stereoID); if (m_pStereotype) { m_pStereotype->incrRefCount(); } else { uDebug() << m_name << ": UMLStereotype " << Uml::ID::toString(stereoID) << " not found, creating now."; setStereotypeCmd(stereo); } } if (element.hasAttribute(QLatin1String("abstract"))) { // for bkwd compat. QString abstract = element.attribute(QLatin1String("abstract"), QLatin1String("0")); m_bAbstract = (bool)abstract.toInt(); } else { QString isAbstract = element.attribute(QLatin1String("isAbstract"), QLatin1String("false")); m_bAbstract = (isAbstract == QLatin1String("true")); } if (element.hasAttribute(QLatin1String("static"))) { // for bkwd compat. QString staticScope = element.attribute(QLatin1String("static"), QLatin1String("0")); m_bStatic = (bool)staticScope.toInt(); } else { QString ownerScope = element.attribute(QLatin1String("ownerScope"), QLatin1String("instance")); m_bStatic = (ownerScope == QLatin1String("classifier")); } // If the node has child nodes, check whether attributes can be // extracted from them. if (element.hasChildNodes()) { QDomNode node = element.firstChild(); if (node.isComment()) node = node.nextSibling(); QDomElement elem = node.toElement(); while (!elem.isNull()) { QString tag = elem.tagName(); if (UMLDoc::tagEq(tag, QLatin1String("name"))) { m_name = elem.attribute(QLatin1String("xmi.value")); if (m_name.isEmpty()) m_name = elem.text(); } else if (UMLDoc::tagEq(tag, QLatin1String("visibility"))) { QString vis = elem.attribute(QLatin1String("xmi.value")); if (vis.isEmpty()) vis = elem.text(); if (vis == QLatin1String("private") || vis == QLatin1String("private_vis")) m_visibility = Uml::Visibility::Private; else if (vis == QLatin1String("protected") || vis == QLatin1String("protected_vis")) m_visibility = Uml::Visibility::Protected; else if (vis == QLatin1String("implementation")) m_visibility = Uml::Visibility::Implementation; } else if (UMLDoc::tagEq(tag, QLatin1String("isAbstract"))) { QString isAbstract = elem.attribute(QLatin1String("xmi.value")); if (isAbstract.isEmpty()) isAbstract = elem.text(); m_bAbstract = (isAbstract == QLatin1String("true")); } else if (UMLDoc::tagEq(tag, QLatin1String("ownerScope"))) { QString ownerScope = elem.attribute(QLatin1String("xmi.value")); if (ownerScope.isEmpty()) ownerScope = elem.text(); m_bStatic = (ownerScope == QLatin1String("classifier")); } else { loadStereotype(elem); } node = node.nextSibling(); if (node.isComment()) node = node.nextSibling(); elem = node.toElement(); } } // Operations, attributes, enum literals, templates, stereotypes, // and association role objects get added and signaled elsewhere. if (m_BaseType != ot_Operation && m_BaseType != ot_Attribute && m_BaseType != ot_EnumLiteral && m_BaseType != ot_EntityAttribute && m_BaseType != ot_Template && m_BaseType != ot_Stereotype && m_BaseType != ot_Role && m_BaseType != ot_UniqueConstraint && m_BaseType != ot_ForeignKeyConstraint && m_BaseType != ot_CheckConstraint) { if (m_pUMLPackage) { m_pUMLPackage->addObject(this); } else if (umldoc->rootFolderType(this) == Uml::ModelType::N_MODELTYPES) { // m_pUMLPackage is not set on the root folders. uDebug() << m_name << ": m_pUMLPackage is not set"; } } return load(element); }