diff --git a/umbrello/dialogs/pages/classgeneralpage.h b/umbrello/dialogs/pages/classgeneralpage.h --- a/umbrello/dialogs/pages/classgeneralpage.h +++ b/umbrello/dialogs/pages/classgeneralpage.h @@ -95,7 +95,10 @@ UMLArtifactTypeWidget *m_artifactTypeWidget; VisibilityEnumWidget *m_visibilityEnumWidget; - void insertStereotypesSorted(const QString& type); + bool canApplyToUMLObject() const; + void setUMLObjectName(const QString& name); + bool canApplyToUMLWidget() const; + void setWidgetName(const QString& name) const; public slots: diff --git a/umbrello/dialogs/pages/classgeneralpage.cpp b/umbrello/dialogs/pages/classgeneralpage.cpp --- a/umbrello/dialogs/pages/classgeneralpage.cpp +++ b/umbrello/dialogs/pages/classgeneralpage.cpp @@ -359,24 +359,59 @@ } // end if m_pObjectWidget else if (m_pUMLWidget) { m_pUMLWidget->setInstanceName(m_instanceNameWidget->text()); - UMLObject* o = m_pUMLWidget->umlObject(); - if (!o) { - uError() << "UML object of instance widget is zero."; - return; - } - - UMLObject* old = m_pUMLDoc->findUMLObject(name); - if (old && o != old) { - KMessageBox::sorry(this, i18n("The name you have chosen\nis already being used.\nThe name has been reset."), - i18n("Name is Not Unique"), 0); - m_nameWidget->reset(); - } else { - o->setName(name); + if (canApplyToUMLObject()) { + setUMLObjectName(name); + } else if (canApplyToUMLWidget()) { + setWidgetName(name); } } // end if m_pUMLWidget } /** + * @return True if the UML widget accepts changes in the text field + */ +bool ClassGeneralPage::canApplyToUMLWidget() const { + return m_pUMLWidget->isCombinedFragmentWidget() || m_pUMLWidget->isFloatingDashLineWidget(); +} + +/** + * Sets the widget text + * @param name The name of the widget + */ +void ClassGeneralPage::setWidgetName(const QString& name) const { + m_pUMLWidget->setName(name); +} + +/** + * @return True if the widget has a uml object to which the name should be changed + */ +bool ClassGeneralPage::canApplyToUMLObject() const { + UMLObject *pUMLObject = m_pUMLWidget->umlObject(); + if (!pUMLObject) { + uError() << "UML object of instance widget is zero."; + return false; + } + return true; +} + +/** + * Changes the name of the associated UML object, if present and if the + * name is not already assigned. + * @param name New name of the UML object + */ +void ClassGeneralPage::setUMLObjectName(const QString& name) { + UMLObject *pUMLObject = m_pUMLWidget->umlObject(); + UMLObject *pDocUMLObject = m_pUMLDoc->findUMLObject(name); + if (pDocUMLObject && pUMLObject != pDocUMLObject) { + KMessageBox::sorry(this, i18n("The name you have chosen\nis already being used.\nThe name has been reset."), + i18n("Name is Not Unique"), 0); + m_nameWidget->reset(); + } else { + pUMLObject->setName(name); + } +} + +/** * When the draw as actor check box is toggled, the draw * as multi instance need to be enabled/disabled. They * both can't be available at the same time.