summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <[email protected]>2014-12-05 12:39:51 +0100
committerAndi Fischer <[email protected]>2014-12-11 21:15:02 +0100
commit334c1250e94bd995c15d27ec4875c0c33babc002 (patch)
tree0888ee379d3adbfd7927a116a5d5f8de32add065
parent357378e4c703a54b5c01a49ae4360fd2a07b3281 (diff)
Add class UMLStereotypeWidget for editing stereotypes.
Use this widget in - general page of classifer widget dialog - in parameter properties dialog - in template dialog - in uml attribute dialog - in entity attribute dialog - in uml operation dialog Having common widgets gives unique user experience and makes it possible to suppport different layouts. CCBUG:73847
-rw-r--r--umbrello/CMakeLists.txt2
-rw-r--r--umbrello/dialogs/pages/classgeneralpage.cpp124
-rw-r--r--umbrello/dialogs/pages/classgeneralpage.h4
-rw-r--r--umbrello/dialogs/parameterpropertiesdialog.cpp48
-rw-r--r--umbrello/dialogs/parameterpropertiesdialog.h8
-rw-r--r--umbrello/dialogs/umlattributedialog.cpp8
-rw-r--r--umbrello/dialogs/umlattributedialog.h7
-rw-r--r--umbrello/dialogs/umlentityattributedialog.cpp9
-rw-r--r--umbrello/dialogs/umlentityattributedialog.h6
-rw-r--r--umbrello/dialogs/umloperationdialog.cpp42
-rw-r--r--umbrello/dialogs/umloperationdialog.h5
-rw-r--r--umbrello/dialogs/umltemplatedialog.cpp10
-rw-r--r--umbrello/dialogs/umltemplatedialog.h6
-rw-r--r--umbrello/dialogs/widgets/umlstereotypewidget.cpp140
-rw-r--r--umbrello/dialogs/widgets/umlstereotypewidget.h43
-rw-r--r--umbrello/stereotype.cpp10
-rw-r--r--umbrello/stereotype.h2
-rw-r--r--umbrello/umlobject.cpp7
-rw-r--r--umbrello/umlobject.h2
19 files changed, 303 insertions, 180 deletions
diff --git a/umbrello/CMakeLists.txt b/umbrello/CMakeLists.txt
index d7bcf29..1fec7d4 100644
--- a/umbrello/CMakeLists.txt
+++ b/umbrello/CMakeLists.txt
@@ -51,6 +51,7 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/debug/
${CMAKE_CURRENT_SOURCE_DIR}/dialogs/
${CMAKE_CURRENT_SOURCE_DIR}/dialogs/pages/
+ ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/widgets/
${CMAKE_CURRENT_SOURCE_DIR}/docgenerators/
${CMAKE_CURRENT_SOURCE_DIR}/finder/
${CMAKE_CURRENT_SOURCE_DIR}/refactoring/
@@ -221,6 +222,7 @@ set(libdialogs_SRCS
dialogs/pages/diagramprintpage.cpp
dialogs/pages/umlroleproperties.cpp
dialogs/pages/umlwidgetstylepage.cpp
+ dialogs/widgets/umlstereotypewidget.cpp
)
qt5_wrap_ui( libdialogs_SRCS
diff --git a/umbrello/dialogs/pages/classgeneralpage.cpp b/umbrello/dialogs/pages/classgeneralpage.cpp
index 9e3b2ed..9c15ff3 100644
--- a/umbrello/dialogs/pages/classgeneralpage.cpp
+++ b/umbrello/dialogs/pages/classgeneralpage.cpp
@@ -29,6 +29,7 @@
#include "folder.h"
#include "import_utils.h"
#include "umlscene.h"
+#include "umlstereotypewidget.h"
// kde includes
#include <KLocalizedString>
@@ -101,6 +102,9 @@ ClassGeneralPage::ClassGeneralPage(UMLDoc* d, QWidget* parent, UMLObject* o)
case UMLObject::ot_Entity:
name = i18n("Entity &name:");
break;
+ case UMLObject::ot_Stereotype:
+ name = i18n("Stereotype &name:");
+ break;
default:
name = QLatin1String("<unknown> &name:");
uWarning() << "creating class gen page for unknown widget type";
@@ -118,22 +122,16 @@ ClassGeneralPage::ClassGeneralPage(UMLDoc* d, QWidget* parent, UMLObject* o)
m_pClassNameLE->setFocus();
m_pNameL->setBuddy(m_pClassNameLE);
- m_pStereoTypeCB = 0;
m_pPackageLE = 0;
m_pAbstractCB = 0;
m_pDeconCB = 0;
- m_pStereoTypeL = new QLabel(i18n("&Stereotype name:"), this);
- m_pNameLayout->addWidget(m_pStereoTypeL, 1, 0);
-
- m_pStereoTypeCB = new KComboBox(true, this);
- m_pNameLayout->addWidget(m_pStereoTypeCB, 1, 1);
-
- m_pStereoTypeCB->setItemText(m_pStereoTypeCB->currentIndex(), m_pObject->stereotype());
- m_pStereoTypeL->setBuddy(m_pStereoTypeCB);
-
- if (t == UMLObject::ot_Interface || t == UMLObject::ot_Datatype || t == UMLObject::ot_Enum) {
- m_pStereoTypeCB->setEditable(false);
+ if (t != UMLObject::ot_Stereotype) {
+ m_stereotypeWidget = new UMLStereotypeWidget(m_pObject);
+ if (t == UMLObject::ot_Interface || t == UMLObject::ot_Datatype || t == UMLObject::ot_Enum) {
+ m_stereotypeWidget->setEditable(false);
+ }
+ m_stereotypeWidget->addToLayout(m_pNameLayout, 1);
}
int row = 2;
@@ -229,23 +227,40 @@ ClassGeneralPage::ClassGeneralPage(UMLDoc* d, QWidget* parent, UMLObject* o)
}
// setup scope
- m_pButtonGB = new QGroupBox(i18n("Visibility"), this);
- QHBoxLayout * scopeLayout = new QHBoxLayout(m_pButtonGB);
- scopeLayout->setMargin(margin);
-
- m_pPublicRB = new QRadioButton(i18nc("public visibility", "P&ublic"), m_pButtonGB);
- scopeLayout->addWidget(m_pPublicRB);
-
- m_pPrivateRB = new QRadioButton(i18nc("private visibility", "P&rivate"), m_pButtonGB);
- scopeLayout->addWidget(m_pPrivateRB);
-
- m_pProtectedRB = new QRadioButton(i18nc("protected visibility", "Pro&tected"), m_pButtonGB);
- scopeLayout->addWidget(m_pProtectedRB);
- topLayout->addWidget(m_pButtonGB);
-
- m_pImplementationRB = new QRadioButton(i18n("Imple&mentation"), m_pButtonGB);
- scopeLayout->addWidget(m_pImplementationRB);
- topLayout->addWidget(m_pButtonGB);
+ if (t != UMLObject::ot_Stereotype) {
+ m_pButtonGB = new QGroupBox(i18n("Visibility"), this);
+ QHBoxLayout * scopeLayout = new QHBoxLayout(m_pButtonGB);
+ scopeLayout->setMargin(margin);
+
+ m_pPublicRB = new QRadioButton(i18nc("public visibility", "P&ublic"), m_pButtonGB);
+ scopeLayout->addWidget(m_pPublicRB);
+
+ m_pPrivateRB = new QRadioButton(i18nc("private visibility", "P&rivate"), m_pButtonGB);
+ scopeLayout->addWidget(m_pPrivateRB);
+
+ m_pProtectedRB = new QRadioButton(i18nc("protected visibility", "Pro&tected"), m_pButtonGB);
+ scopeLayout->addWidget(m_pProtectedRB);
+ topLayout->addWidget(m_pButtonGB);
+
+ m_pImplementationRB = new QRadioButton(i18n("Imple&mentation"), m_pButtonGB);
+ scopeLayout->addWidget(m_pImplementationRB);
+ topLayout->addWidget(m_pButtonGB);
+
+ switch (m_pObject->visibility()) {
+ case Uml::Visibility::Public:
+ m_pPublicRB->setChecked(true);
+ break;
+ case Uml::Visibility::Private:
+ m_pPrivateRB->setChecked(true);
+ break;
+ case Uml::Visibility::Protected:
+ m_pProtectedRB->setChecked(true);
+ break;
+ default:
+ m_pImplementationRB->setChecked(true);
+ break;
+ }
+ }
// setup documentation
m_docGB = new QGroupBox(this);
@@ -261,25 +276,6 @@ ClassGeneralPage::ClassGeneralPage(UMLDoc* d, QWidget* parent, UMLObject* o)
m_pClassNameLE->setText(m_pObject->name());
m_doc->setText(m_pObject->doc());
- switch (m_pObject->visibility()) {
- case Uml::Visibility::Public:
- m_pPublicRB->setChecked(true);
- break;
- case Uml::Visibility::Private:
- m_pPrivateRB->setChecked(true);
- break;
- case Uml::Visibility::Protected:
- m_pProtectedRB->setChecked(true);
- break;
- default:
- m_pImplementationRB->setChecked(true);
- break;
- }
-
- // manage stereotypes
- m_pStereoTypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
- Dialog_Utils::insertStereotypesSorted(m_pStereoTypeCB, m_pObject->stereotype());
-
m_doc->setLineWrapMode(QTextEdit::WidgetWidth);
}
@@ -384,13 +380,8 @@ ClassGeneralPage::ClassGeneralPage(UMLDoc* d, QWidget* parent, UMLWidget* widget
m_pClassNameLE->setText(widget->name());
m_pNameLayout->addWidget(m_pClassNameLE, 0, 1);
- m_pStereoTypeL = new QLabel(i18n("Stereotype name:"), this);
- m_pNameLayout->addWidget(m_pStereoTypeL, 1, 0);
-
- m_pStereoTypeCB = new KComboBox(true, this);
- m_pNameLayout->addWidget(m_pStereoTypeCB, 1, 1);
-
- m_pStereoTypeCB->setItemText(m_pStereoTypeCB->currentIndex(), widget->umlObject()->stereotype());
+ m_stereotypeWidget = new UMLStereotypeWidget(widget->umlObject());
+ m_pNameLayout->addWidget(m_stereotypeWidget, 1, 0, 1, 2);
m_pInstanceL = new QLabel(this);
m_pInstanceL->setText(i18n("Instance name:"));
@@ -428,8 +419,8 @@ void ClassGeneralPage::updateObject()
m_pObject->setDoc(m_doc->toPlainText());
- if (m_pStereoTypeCB) {
- m_pObject->setStereotype(m_pStereoTypeCB->currentText());
+ if (m_stereotypeWidget) {
+ m_stereotypeWidget->apply();
}
UMLObject::ObjectType t = m_pObject->baseType();
@@ -463,14 +454,16 @@ void ClassGeneralPage::updateObject()
m_pObject->setName(name);
}
- Uml::Visibility::Enum s = Uml::Visibility::Implementation;
- if (m_pPublicRB->isChecked())
- s = Uml::Visibility::Public;
- else if (m_pPrivateRB->isChecked())
- s = Uml::Visibility::Private;
- else if (m_pProtectedRB->isChecked())
- s = Uml::Visibility::Protected;
- m_pObject->setVisibility(s);
+ if (t != UMLObject::ot_Stereotype) {
+ Uml::Visibility::Enum s = Uml::Visibility::Implementation;
+ if (m_pPublicRB->isChecked())
+ s = Uml::Visibility::Public;
+ else if (m_pPrivateRB->isChecked())
+ s = Uml::Visibility::Private;
+ else if (m_pProtectedRB->isChecked())
+ s = Uml::Visibility::Protected;
+ m_pObject->setVisibility(s);
+ }
if (m_pObject->baseType() == UMLObject::ot_Component) {
(static_cast<UMLComponent*>(m_pObject))->setExecutable(m_pExecutableCB->isChecked());
@@ -523,7 +516,6 @@ void ClassGeneralPage::updateObject()
} else {
o->setName(name);
}
- o->setStereotype(m_pStereoTypeCB->currentText());
} // end if m_pInstanceWidget
}
diff --git a/umbrello/dialogs/pages/classgeneralpage.h b/umbrello/dialogs/pages/classgeneralpage.h
index a71facc..3252be7 100644
--- a/umbrello/dialogs/pages/classgeneralpage.h
+++ b/umbrello/dialogs/pages/classgeneralpage.h
@@ -25,6 +25,7 @@ class UMLObject;
class UMLWidget;
class ObjectWidget;
class UMLDoc;
+class UMLStereotypeWidget;
/**
* Displays properties of a UMLObject in a dialog box. This is not usually directly
@@ -82,13 +83,14 @@ private:
QGroupBox * m_pButtonGB;
QLabel * m_pNameL, * m_pInstanceL, * m_pStereoTypeL, * m_pPackageL;
KLineEdit * m_pClassNameLE, * m_pInstanceLE, * m_pPackageLE;
- KComboBox * m_pStereoTypeCB, * m_pPackageCB ;
+ KComboBox * m_pPackageCB ;
QRadioButton * m_pPublicRB, * m_pPrivateRB, * m_pProtectedRB, * m_pImplementationRB;
QCheckBox * m_pMultiCB, * m_pDrawActorCB, * m_pAbstractCB, * m_pDeconCB;
KTextEdit * m_doc;
QGroupBox * m_pDrawAsGB;
QRadioButton * m_pDefaultRB, * m_pFileRB, * m_pLibraryRB, * m_pTableRB;
QCheckBox * m_pExecutableCB;
+ UMLStereotypeWidget *m_stereotypeWidget;
void insertStereotypesSorted(const QString& type);
diff --git a/umbrello/dialogs/parameterpropertiesdialog.cpp b/umbrello/dialogs/parameterpropertiesdialog.cpp
index d292f32..c439c27 100644
--- a/umbrello/dialogs/parameterpropertiesdialog.cpp
+++ b/umbrello/dialogs/parameterpropertiesdialog.cpp
@@ -15,6 +15,7 @@
#include "attribute.h"
#include "classifier.h"
#include "debug_utils.h"
+#include "umlstereotypewidget.h"
#include "umltemplatelist.h"
#include "template.h"
#include "umldoc.h"
@@ -91,10 +92,8 @@ ParameterPropertiesDialog::ParameterPropertiesDialog(QWidget * parent, UMLDoc *
m_pInitialL, i18n("&Initial value:"),
m_pInitialLE, initialValue);
- m_pStereoTypeL = new QLabel(i18n("Stereotype name:"), m_pParmGB);
- propLayout->addWidget(m_pStereoTypeL, 3, 0);
- m_pStereoTypeCB = new KComboBox(true, m_pParmGB);
- propLayout->addWidget(m_pStereoTypeCB, 3, 1);
+ m_stereotypeWidget = new UMLStereotypeWidget(m_pAtt);
+ m_stereotypeWidget->addToLayout(propLayout, 3);
m_pKindGB = new QGroupBox(i18n("Passing Direction"));
m_pKindGB->setToolTip(i18n("\"in\" is a readonly parameter, \"out\" is a writeonly parameter and \"inout\" is a parameter for reading and writing."));
@@ -151,18 +150,12 @@ ParameterPropertiesDialog::ParameterPropertiesDialog(QWidget * parent, UMLDoc *
insertTypesSorted(attr->getTypeName());
}
- // manage stereotypes
- m_pStereoTypeCB->setDuplicatesEnabled(false); //only allow one of each type in box
- if (m_pAtt) {
- insertStereotypesSorted(m_pAtt->stereotype());
- }
-
// set tab order
setTabOrder(m_pKindGB, m_pTypeCB);
setTabOrder(m_pTypeCB, m_pNameLE);
setTabOrder(m_pNameLE, m_pInitialLE);
- setTabOrder(m_pInitialLE, m_pStereoTypeCB);
- setTabOrder(m_pStereoTypeCB, m_pIn);
+ setTabOrder(m_pInitialLE, m_stereotypeWidget);
+ setTabOrder(m_stereotypeWidget, m_pIn);
setTabOrder(m_pIn, m_doc);
m_pNameLE->setFocus();
}
@@ -240,35 +233,6 @@ void ParameterPropertiesDialog::insertTypesSorted(const QString& type)
}
/**
- * Inserts @p type into the stereotype-combobox as well as its completion object.
- * 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 ParameterPropertiesDialog::insertStereotypesSorted(const QString& type)
-{
- QStringList types;
- types << QString(); // an empty stereotype is the default
- foreach (UMLStereotype* currentSt, m_pUmldoc->stereotypes()) {
- types << currentSt->name();
- }
- // add the given parameter
- if (!types.contains(type)) {
- types << type;
- }
- types.sort();
-
- m_pStereoTypeCB->clear();
- m_pStereoTypeCB->insertItems(-1, types);
-
- // select the given parameter
- int currentIndex = m_pStereoTypeCB->findText(type);
- if (currentIndex > -1) {
- m_pStereoTypeCB->setCurrentIndex(currentIndex);
- }
-}
-
-/**
* Return the kind of the parameter (in, out, or inout).
* @return The Uml::ParameterDirection::Enum corresponding to
* the selected "Kind" radiobutton.
@@ -333,7 +297,7 @@ void ParameterPropertiesDialog::slotOk()
m_pAtt->setName(getName()); // set the name
m_pAtt->setParmKind(getParmKind()); // set the direction
- m_pAtt->setStereotype(m_pStereoTypeCB->currentText()); // set the stereotype
+ m_stereotypeWidget->apply();
// set the type name
QString typeName = m_pTypeCB->currentText();
diff --git a/umbrello/dialogs/parameterpropertiesdialog.h b/umbrello/dialogs/parameterpropertiesdialog.h
index 7c4fa24..50de17d 100644
--- a/umbrello/dialogs/parameterpropertiesdialog.h
+++ b/umbrello/dialogs/parameterpropertiesdialog.h
@@ -25,6 +25,7 @@ class QLabel;
class QRadioButton;
class UMLAttribute;
class UMLDoc;
+class UMLStereotypeWidget;
/**
* Displays a dialog box that displays properties of a parameter.
@@ -54,8 +55,6 @@ protected:
void insertTypesSorted(const QString& type = QString());
- void insertStereotypesSorted(const QString& type = QString());
-
bool validate();
protected slots:
@@ -66,13 +65,14 @@ private:
QGroupBox *m_docGB;
QGroupBox *m_pKindGB;
QRadioButton *m_pIn, *m_pOut, *m_pInOut;
- QLabel *m_pTypeL, *m_pNameL, *m_pInitialL, *m_pStereoTypeL;
- KComboBox *m_pTypeCB, *m_pStereoTypeCB;
+ QLabel *m_pTypeL, *m_pNameL, *m_pInitialL;
+ KComboBox *m_pTypeCB;
KLineEdit *m_pNameLE, *m_pInitialLE;
KTextEdit *m_doc;
QDialogButtonBox *m_buttonBox;
UMLDoc *m_pUmldoc;
UMLAttribute *m_pAtt;
+ UMLStereotypeWidget *m_stereotypeWidget;
};
#endif
diff --git a/umbrello/dialogs/umlattributedialog.cpp b/umbrello/dialogs/umlattributedialog.cpp
index ff8d556..d2fb7b5 100644
--- a/umbrello/dialogs/umlattributedialog.cpp
+++ b/umbrello/dialogs/umlattributedialog.cpp
@@ -17,6 +17,7 @@
#include "template.h"
#include "umldoc.h"
#include "uml.h"
+#include "umlstereotypewidget.h"
#include "dialog_utils.h"
#include "object_factory.h"
#include "import_utils.h"
@@ -81,9 +82,8 @@ void UMLAttributeDialog::setupDialog()
m_pInitialL, i18n("&Initial value:"),
m_pInitialLE, m_pAttribute->getInitialValue());
- Dialog_Utils::makeLabeledEditField(valuesLayout, 3,
- m_pStereoTypeL, i18n("Stereotype name:"),
- m_pStereoTypeLE, m_pAttribute->stereotype());
+ m_stereotypeWidget = new UMLStereotypeWidget(m_pAttribute);
+ m_stereotypeWidget->addToLayout(valuesLayout, 3);
m_pStaticCB = new QCheckBox(i18n("Classifier &scope (\"static\")"), m_pValuesGB);
m_pStaticCB->setChecked(m_pAttribute->isStatic());
@@ -177,7 +177,7 @@ bool UMLAttributeDialog::apply()
Settings::setOptionState(optionState);
m_pAttribute->setInitialValue(m_pInitialLE->text());
- m_pAttribute->setStereotype(m_pStereoTypeLE->text());
+ m_stereotypeWidget->apply();
m_pAttribute->setStatic(m_pStaticCB->isChecked());
QString typeName = m_pTypeCB->currentText();
diff --git a/umbrello/dialogs/umlattributedialog.h b/umbrello/dialogs/umlattributedialog.h
index 8e46b0a..7ef1e6b 100644
--- a/umbrello/dialogs/umlattributedialog.h
+++ b/umbrello/dialogs/umlattributedialog.h
@@ -18,8 +18,10 @@ class QGroupBox;
class QRadioButton;
class QLabel;
class UMLAttribute;
+class UMLStereotypeWidget;
class KComboBox;
class KLineEdit;
+class UMLStereotypeWidget;
/**
* @author Paul Hensgen
@@ -45,10 +47,11 @@ protected:
QGroupBox * m_pValuesGB;
QGroupBox * m_pScopeGB;
QRadioButton * m_pPublicRB, * m_pPrivateRB, * m_pProtectedRB, * m_pImplementationRB;
- QLabel * m_pTypeL, * m_pNameL, * m_pInitialL, * m_pStereoTypeL;
+ QLabel * m_pTypeL, * m_pNameL, * m_pInitialL;
KComboBox * m_pTypeCB;
- KLineEdit * m_pNameLE, * m_pInitialLE, * m_pStereoTypeLE;
+ KLineEdit * m_pNameLE, * m_pInitialLE;
QCheckBox* m_pStaticCB;
+ UMLStereotypeWidget *m_stereotypeWidget;
public slots:
void slotOk();
diff --git a/umbrello/dialogs/umlentityattributedialog.cpp b/umbrello/dialogs/umlentityattributedialog.cpp
index 73e83b3..b122848 100644
--- a/umbrello/dialogs/umlentityattributedialog.cpp
+++ b/umbrello/dialogs/umlentityattributedialog.cpp
@@ -16,10 +16,12 @@
#include "classifier.h"
#include "umldoc.h"
#include "uml.h"
+#include "umlstereotypewidget.h"
#include "codegenerator.h"
#include "dialog_utils.h"
#include "object_factory.h"
#include "umlclassifierlist.h"
+#include "umlstereotypewidget.h"
// kde includes
#include <klineedit.h>
@@ -83,9 +85,8 @@ void UMLEntityAttributeDialog::setupDialog()
m_pInitialL, i18n("&Default value:"),
m_pInitialLE, m_pEntityAttribute->getInitialValue());
- Dialog_Utils::makeLabeledEditField(valuesLayout, 3,
- m_pStereoTypeL, i18n("Stereotype name:"),
- m_pStereoTypeLE, m_pEntityAttribute->stereotype());
+ m_stereotypeWidget = new UMLStereotypeWidget(m_pEntityAttribute);
+ m_stereotypeWidget->addToLayout(valuesLayout, 3);
Dialog_Utils::makeLabeledEditField(valuesLayout, 4,
m_pValuesL, i18n("Length/Values:"),
@@ -186,7 +187,7 @@ bool UMLEntityAttributeDialog::apply()
}
m_pEntityAttribute->setName(name);
m_pEntityAttribute->setInitialValue(m_pInitialLE->text());
- m_pEntityAttribute->setStereotype(m_pStereoTypeLE->text());
+ m_stereotypeWidget->apply();
m_pEntityAttribute->setValues(m_pValuesLE->text());
m_pEntityAttribute->setAttributes(m_pAttributesCB->currentText());
m_pEntityAttribute->setAutoIncrement(m_pAutoIncrementCB->isChecked());
diff --git a/umbrello/dialogs/umlentityattributedialog.h b/umbrello/dialogs/umlentityattributedialog.h
index 179a092..85f2145 100644
--- a/umbrello/dialogs/umlentityattributedialog.h
+++ b/umbrello/dialogs/umlentityattributedialog.h
@@ -18,6 +18,7 @@ class QGroupBox;
class QLabel;
class QRadioButton;
class UMLEntityAttribute;
+class UMLStereotypeWidget;
class KComboBox;
class KLineEdit;
@@ -46,12 +47,13 @@ protected:
QGroupBox * m_pAttsGB, * m_pValuesGB;
QGroupBox * m_pScopeGB;
QRadioButton * m_pPublicRB, * m_pPrivateRB, * m_pProtectedRB, * m_pNoneRB;
- QLabel * m_pTypeL, * m_pNameL, * m_pInitialL, * m_pStereoTypeL, * m_pValuesL, * m_pAttributesL ;
+ QLabel * m_pTypeL, * m_pNameL, * m_pInitialL, * m_pValuesL, * m_pAttributesL ;
KComboBox * m_pTypeCB;
KComboBox * m_pAttributesCB;
- KLineEdit * m_pNameLE, * m_pInitialLE, * m_pStereoTypeLE, * m_pValuesLE;
+ KLineEdit * m_pNameLE, * m_pInitialLE, * m_pValuesLE;
QCheckBox* m_pAutoIncrementCB;
QCheckBox* m_pNullCB;
+ UMLStereotypeWidget *m_stereotypeWidget;
public slots:
void slotAutoIncrementStateChanged(bool checked);
diff --git a/umbrello/dialogs/umloperationdialog.cpp b/umbrello/dialogs/umloperationdialog.cpp
index 95f7a45..5c217f0 100644
--- a/umbrello/dialogs/umloperationdialog.cpp
+++ b/umbrello/dialogs/umloperationdialog.cpp
@@ -20,6 +20,7 @@
#include "template.h"
#include "listpopupmenu.h"
#include "umlattributelist.h"
+#include "umlstereotypewidget.h"
#include "classifierlistitem.h"
#include "umlclassifierlistitemlist.h"
#include "dialog_utils.h"
@@ -102,10 +103,8 @@ void UMLOperationDialog::setupDialog()
genLayout->addWidget(m_pRtypeCB, 0, 3);
m_pRtypeL->setBuddy(m_pRtypeCB);
- m_pStereoTypeL = new QLabel(i18n("Stereotype name:"), m_pGenGB);
- genLayout->addWidget(m_pStereoTypeL, 1, 0);
- m_pStereoTypeCB = new KComboBox(true, m_pGenGB);
- genLayout->addWidget(m_pStereoTypeCB, 1, 1);
+ m_stereotypeWidget = new UMLStereotypeWidget(m_operation);
+ m_stereotypeWidget->addToLayout(genLayout, 1);
m_pAbstractCB = new QCheckBox(i18n("&Abstract operation"), m_pGenGB);
m_pAbstractCB->setChecked(m_operation->isAbstract());
@@ -208,10 +207,6 @@ void UMLOperationDialog::setupDialog()
break;
}
- // manage stereotypes
- m_pStereoTypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
- insertStereotypesSorted(m_operation->stereotype());
-
// setup parm list box signals
connect(m_pUpButton, SIGNAL(clicked()), this, SLOT(slotParameterUp()));
connect(m_pDownButton, SIGNAL(clicked()), this, SLOT(slotParameterDown()));
@@ -463,7 +458,7 @@ bool UMLOperationDialog::apply()
else
m_operation->setTypeName(typeName);
- m_operation->setStereotype(m_pStereoTypeCB->currentText());
+ m_stereotypeWidget->apply();
bool isAbstract = m_pAbstractCB->isChecked();
m_operation->setAbstract(isAbstract);
@@ -569,32 +564,3 @@ void UMLOperationDialog::insertTypesSorted(const QString& type)
m_pRtypeCB->setCurrentIndex(currentIndex);
}
}
-
-/**
- * Inserts @p stereotype into the stereotype-combobox as well as its completion object.
- * 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 UMLOperationDialog::insertStereotypesSorted(const QString& type)
-{
- QStringList types;
- foreach (UMLStereotype* currentSt, m_doc->stereotypes()) {
- types << currentSt->name();
- }
- // add the given parameter
- if (!types.contains(type)) {
- types << type;
- }
- types.sort();
-
- m_pStereoTypeCB->clear();
- m_pStereoTypeCB->insertItems(-1, types);
-
- // select the given parameter
- int currentIndex = m_pStereoTypeCB->findText(type);
- if (currentIndex > -1) {
- m_pStereoTypeCB->setCurrentIndex(currentIndex);
- }
- m_pStereoTypeCB->completionObject()->addItem(type);
-}
diff --git a/umbrello/dialogs/umloperationdialog.h b/umbrello/dialogs/umloperationdialog.h
index 99183b0..7786a84 100644
--- a/umbrello/dialogs/umloperationdialog.h
+++ b/umbrello/dialogs/umloperationdialog.h
@@ -29,6 +29,7 @@ class QToolButton;
class KLineEdit;
class UMLDoc;
class UMLOperation;
+class UMLStereotypeWidget;
/**
* @author Paul Hensgen
@@ -49,7 +50,6 @@ protected:
bool apply();
void insertTypesSorted(const QString& type = QString());
- void insertStereotypesSorted(const QString& type);
UMLOperation* m_operation; ///< The operation to represent.
UMLDoc* m_doc; ///< The UMLDocument where all objects live.
@@ -66,9 +66,8 @@ protected:
QRadioButton* m_pImplementationRB;
QLabel* m_pRtypeL;
QLabel* m_pNameL;
- QLabel* m_pStereoTypeL;
KComboBox* m_pRtypeCB;
- KComboBox* m_pStereoTypeCB;
+ UMLStereotypeWidget* m_stereotypeWidget;
KLineEdit* m_pNameLE;
QCheckBox* m_pAbstractCB;
QCheckBox* m_pStaticCB;
diff --git a/umbrello/dialogs/umltemplatedialog.cpp b/umbrello/dialogs/umltemplatedialog.cpp
index 84eaf63..5de70a2 100644
--- a/umbrello/dialogs/umltemplatedialog.cpp
+++ b/umbrello/dialogs/umltemplatedialog.cpp
@@ -17,6 +17,7 @@
#include "umldoc.h"
#include "uml.h"
#include "dialog_utils.h"
+#include "umlstereotypewidget.h"
// kde includes
#include <klineedit.h>
@@ -71,10 +72,8 @@ void UMLTemplateDialog::setupDialog()
Dialog_Utils::makeLabeledEditField(valuesLayout, 1,
m_pNameL, i18nc("template name", "&Name:"),
m_pNameLE, m_pTemplate->name());
-
- Dialog_Utils::makeLabeledEditField(valuesLayout, 2,
- m_pStereoTypeL, i18n("&Stereotype name:"),
- m_pStereoTypeLE, m_pTemplate->stereotype());
+ m_stereotypeWidget = new UMLStereotypeWidget(m_pTemplate);
+ m_stereotypeWidget->addToLayout(valuesLayout, 2);
mainLayout->addWidget(m_pValuesGB);
@@ -162,8 +161,7 @@ bool UMLTemplateDialog::apply()
}
}
m_pTemplate->setName(name);
-
- m_pTemplate->setStereotype(m_pStereoTypeLE->text());
+ m_stereotypeWidget->apply();
return true;
}
diff --git a/umbrello/dialogs/umltemplatedialog.h b/umbrello/dialogs/umltemplatedialog.h
index 8186434..cf3b044 100644
--- a/umbrello/dialogs/umltemplatedialog.h
+++ b/umbrello/dialogs/umltemplatedialog.h
@@ -18,6 +18,7 @@ class KLineEdit;
class QGroupBox;
class QLabel;
class UMLTemplate;
+class UMLStereotypeWidget;
/**
* A dialog to edit the properties of a class template (paramaterised class)
@@ -41,9 +42,10 @@ protected:
// GUI Widgets
QGroupBox *m_pValuesGB;
- QLabel *m_pTypeL, *m_pNameL, *m_pStereoTypeL;
+ QLabel *m_pTypeL, *m_pNameL;
KComboBox *m_pTypeCB;
- KLineEdit *m_pNameLE, *m_pStereoTypeLE;
+ KLineEdit *m_pNameLE;
+ UMLStereotypeWidget *m_stereotypeWidget;
public slots:
void slotOk();
diff --git a/umbrello/dialogs/widgets/umlstereotypewidget.cpp b/umbrello/dialogs/widgets/umlstereotypewidget.cpp
new file mode 100644
index 0000000..7f9d64c
--- /dev/null
+++ b/umbrello/dialogs/widgets/umlstereotypewidget.cpp
@@ -0,0 +1,140 @@
+/***************************************************************************
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * copyright (C) 2002-2014 *
+ * Umbrello UML Modeller Authors <[email protected]> *
+ ***************************************************************************/
+
+#include "umlstereotypewidget.h"
+
+#include "basictypes.h"
+#include "stereotype.h"
+#include "uml.h"
+#include "umldoc.h"
+
+#include <KComboBox>
+#include <KLocalizedString>
+
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QWidget>
+
+Q_DECLARE_METATYPE(UMLStereotype*);
+
+UMLStereotypeWidget::UMLStereotypeWidget(UMLObject *object, QWidget *parent)
+ : QWidget(parent),
+ m_object(object)
+{
+ Q_ASSERT(m_object);
+ init();
+}
+
+UMLStereotypeWidget::~UMLStereotypeWidget()
+{
+ delete m_comboBox;
+ delete m_label;
+}
+
+/**
+ * Set state if stereotypes could be edited. By default stereotypes could be edited.
+ * @param state edit state
+ */
+void UMLStereotypeWidget::setEditable(bool state)
+{
+ m_comboBox->setEditable(state);
+}
+
+/**
+ * Add this widget to a given grid layout. Umbrello dialogs places labels in column 0
+ * and the editable field in column 1.
+ * @param layout The layout to which the widget should be added
+ * @param row The row in the grid layout where the widget should be placed
+ */
+void UMLStereotypeWidget::addToLayout(QGridLayout *layout, int row)
+{
+ layout->addWidget(m_label, row, 0);
+ layout->addWidget(m_comboBox, row, 1);
+}
+
+/**
+ * Apply changes to the related UMLObject.
+ */
+void UMLStereotypeWidget::apply()
+{
+ QVariant v = m_comboBox->itemData(m_comboBox->currentIndex());
+ if (v.canConvert<UMLStereotype*>()) {
+ UMLStereotype *selected = v.value<UMLStereotype*>();
+ if (m_object->umlStereotype()) {
+ if (m_object->umlStereotype()->name() != m_comboBox->currentText())
+ m_object->setUMLStereotype(selected);
+ }
+ else
+ m_object->setUMLStereotype(selected);
+ }
+ else if (!m_comboBox->currentText().isEmpty()) {
+ UMLStereotype *stereotype = new UMLStereotype(m_comboBox->currentText());
+ UMLApp::app()->document()->addStereotype(stereotype);
+ m_object->setUMLStereotype(stereotype);
+ }
+ else
+ m_object->setUMLStereotype(0);
+}
+
+/**
+ * setup widgets
+ */
+void UMLStereotypeWidget::init()
+{
+ QHBoxLayout *layout = new QHBoxLayout;
+ layout->setContentsMargins(0,0,0,0);
+ m_label = new QLabel(i18n("&Stereotype name:"), this);
+ layout->addWidget(m_label);
+
+ m_comboBox = new KComboBox(true, this);
+ layout->addWidget(m_comboBox, 2);
+
+ m_label->setBuddy(m_comboBox);
+
+ m_comboBox->setDuplicatesEnabled(false); // only allow one of each type in box
+ m_comboBox->setCompletionMode(KGlobalSettings::CompletionPopup);
+
+ insertItems(m_object->umlStereotype());
+ setLayout(layout);
+}
+
+/**
+ * Insert stereotypes into combo box and select the currently used stereotype.
+ * @param type currently used stereotype
+ */
+void UMLStereotypeWidget::insertItems(UMLStereotype *type)
+{
+ UMLDoc *umldoc = UMLApp::app()->document();
+ QMap<QString, UMLStereotype*> types;
+
+ foreach(UMLStereotype* ust, umldoc->stereotypes()) {
+ types[ust->name()] = ust;
+ }
+ // add the given parameter
+ if (type && !types.keys().contains(type->name())) {
+ types[type->name()] = type;
+ }
+
+ m_comboBox->clear();
+ m_comboBox->addItem(QLatin1String(""), QVariant(0));
+ foreach(const QString &key, types.keys()) {
+ m_comboBox->addItem(key, QVariant::fromValue((types[key])));
+ }
+
+ // select the given parameter
+ if (type) {
+ int currentIndex = m_comboBox->findText(type->name());
+ if (currentIndex > -1) {
+ m_comboBox->setCurrentIndex(currentIndex);
+ }
+ m_comboBox->completionObject()->addItem(type->name());
+ }
+}
diff --git a/umbrello/dialogs/widgets/umlstereotypewidget.h b/umbrello/dialogs/widgets/umlstereotypewidget.h
new file mode 100644
index 0000000..aa98005
--- /dev/null
+++ b/umbrello/dialogs/widgets/umlstereotypewidget.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * copyright (C) 2002-2014 *
+ * Umbrello UML Modeller Authors <[email protected]> *
+ ***************************************************************************/
+
+#ifndef UMLSTEREOTYPEWIDGET_H
+#define UMLSTEREOTYPEWIDGET_H
+
+#include <QWidget>
+
+class UMLObject;
+class UMLStereotype;
+
+class KComboBox;
+
+class QGridLayout;
+class QLabel;
+
+class UMLStereotypeWidget : public QWidget
+{
+public:
+ UMLStereotypeWidget(UMLObject *object, QWidget *parent=0);
+ ~UMLStereotypeWidget();
+
+ void setEditable(bool state);
+ void addToLayout(QGridLayout *layout, int row);
+ void apply();
+
+protected:
+ QLabel *m_label;
+ KComboBox *m_comboBox;
+ UMLObject *m_object;
+
+ void init();
+ void insertItems(UMLStereotype *type);
+};
+
+#endif // UMLSTEREOTYPEWIDGET_H
diff --git a/umbrello/stereotype.cpp b/umbrello/stereotype.cpp
index 4d8d865..46bf661 100644
--- a/umbrello/stereotype.cpp
+++ b/umbrello/stereotype.cpp
@@ -144,3 +144,13 @@ int UMLStereotype::refCount() const
return m_refCount;
}
+/**
+ * Returns the name as string
+ */
+QString UMLStereotype::name(bool includeAdornments) const
+{
+ if (includeAdornments)
+ return QString::fromUtf8("«") + UMLObject::name() + QString::fromUtf8("»");
+ else
+ return UMLObject::name();
+}
diff --git a/umbrello/stereotype.h b/umbrello/stereotype.h
index e829431..a957cec 100644
--- a/umbrello/stereotype.h
+++ b/umbrello/stereotype.h
@@ -56,6 +56,8 @@ public:
int refCount() const;
+ QString name(bool includeAdornments=false) const;
+
void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
bool showPropertiesDialog(QWidget* parent);
diff --git a/umbrello/umlobject.cpp b/umbrello/umlobject.cpp
index 3606eba..7049aa9 100644
--- a/umbrello/umlobject.cpp
+++ b/umbrello/umlobject.cpp
@@ -568,7 +568,7 @@ bool UMLObject::setUMLPackage(UMLPackage* pPkg)
*
* @return Returns the classes UMLStereotype object.
*/
-const UMLStereotype * UMLObject::umlStereotype()
+UMLStereotype * UMLObject::umlStereotype()
{
return m_pStereotype;
}
@@ -580,10 +580,7 @@ QString UMLObject::stereotype(bool includeAdornments /* = false */) const
{
if (m_pStereotype == NULL)
return QString();
- QString name = m_pStereotype->name();
- if (includeAdornments)
- name = QString::fromUtf8("«") + name + QString::fromUtf8("»");
- return name;
+ return m_pStereotype->name(includeAdornments);
}
/**
diff --git a/umbrello/umlobject.h b/umbrello/umlobject.h
index 3795ed0..30e7b2e 100644
--- a/umbrello/umlobject.h
+++ b/umbrello/umlobject.h
@@ -109,7 +109,7 @@ public:
QString stereotype(bool includeAdornments = false) const;
void setUMLStereotype(UMLStereotype *stereo);
- const UMLStereotype * umlStereotype();
+ UMLStereotype *umlStereotype();
void setPackage(const QString &_name);
QString package(const QString& separator = QString(),