Commit 66da747f authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

Add default value capability at stereotype attribute:

umbrello/uml1model/stereotype.h
- In class AttributeDef,
  - add member defaultVal of type QString;
  - extend constructor for externally provided defaultVal.

umbrello/uml1model/stereotype.cpp
- In function saveToXMI1 loop over m_attrDefs, if ad.defaultVal is
  non empty then setAttribute "initialValue" on attElement.
- In function load1 traversal of QDomNodes tag "UML:Stereotype.feature"
  while-loop over attElem tag "UML:Attribute" retrieve attElem attribute
  "initialValue" into local dfltVal of type QString.
  Pass dfltVal into AttributeDef constructor.

umbrello/dialogs/stereoattributedialog.h
- Add member m_pDefaultValueLabel[N_STEREOATTRS] of type QLabel*.
- Add member m_pDefaultValueEdit [N_STEREOATTRS] of type KLineEdit*.

umbrello/dialogs/stereoattributedialog.cpp
- In function setupDialog() for-loop of row,
  - place m_pDefaultValueLabel[row], m_pDefaultValueEdit[row] into
    columns 4, 5 using Dialog_Utils::makeLabeledEditField();
  - in case (adefs.count() > row) initialize m_pDefaultValueEdit[row]
    from adefs.at(row).defaultVal.
- In function apply() pass m_pDefaultValueEdit[i]->text().trimmed()
  into UMLStereotype::AttributeDef constructor argument dfltVal.

CCBUG: 73847
parent c7fdfefc
......@@ -77,7 +77,7 @@ void StereoAttributeDialog::setupDialog()
m_pNameLabel[row], i18nc("attribute name", "&Name:"),
m_pNameEdit[row]); // columns 0, 1
m_pTypeLabel[row] = new QLabel(i18nc("attribute type", "Type:"));
m_pTypeLabel[row] = new QLabel(i18nc("attribute type", "&Type:"));
valuesLayout->addWidget(m_pTypeLabel[row], row, 2); // column 2
m_pTypeCombo[row] = new QComboBox(this);
for (int type = 0; type < Uml::PrimitiveTypes::n_types; type++) {
......@@ -86,6 +86,10 @@ void StereoAttributeDialog::setupDialog()
valuesLayout->addWidget(m_pTypeCombo[row], row, 3); // column 3
m_pTypeLabel[row]->setBuddy(m_pTypeCombo[row]);
Dialog_Utils::makeLabeledEditField(valuesLayout, row,
m_pDefaultValueLabel[row], i18nc("default value", "&Default:"),
m_pDefaultValueEdit[row], QString(), 4); // columns 4, 5
if (adefs.count() > row) {
const UMLStereotype::AttributeDef& adef = adefs.at(row);
if (!adef.name.isEmpty()) {
......@@ -95,6 +99,9 @@ void StereoAttributeDialog::setupDialog()
m_pTypeCombo[row]->setCurrentIndex(type);
else
uDebug() << "StereoAttributeDialog::setupDialog: Illegal type " << type;
const QString& dfltVal = adef.defaultVal;
if (!dfltVal.isEmpty())
m_pDefaultValueEdit[row]->setText(dfltVal);
}
}
}
......@@ -114,7 +121,9 @@ bool StereoAttributeDialog::apply()
int typeIndex = m_pTypeCombo[i]->currentIndex();
if (typeIndex < 0)
typeIndex = 0;
UMLStereotype::AttributeDef attrDef(name, Uml::PrimitiveTypes::Enum(typeIndex));
Uml::PrimitiveTypes::Enum type = Uml::PrimitiveTypes::Enum(typeIndex);
QString dfltVal = m_pDefaultValueEdit[i]->text().trimmed();
UMLStereotype::AttributeDef attrDef(name, type, dfltVal);
adefs.append(attrDef);
}
}
......
......@@ -28,7 +28,7 @@ class StereoAttributeDialog : public SinglePageDialogBase
Q_OBJECT
public:
StereoAttributeDialog(QWidget *parent, UMLStereotype *stereotype);
~StereoAttributeDialog();
virtual ~StereoAttributeDialog();
protected:
void setupDialog();
......@@ -43,10 +43,12 @@ protected:
//GUI Widgets
QGroupBox * m_pValuesGB;
QLabel * m_pNameLabel[N_STEREOATTRS];
QLabel * m_pNameLabel [N_STEREOATTRS];
KLineEdit * m_pNameEdit [N_STEREOATTRS];
QLabel * m_pTypeLabel[N_STEREOATTRS];
QComboBox * m_pTypeCombo[N_STEREOATTRS];
QLabel * m_pTypeLabel [N_STEREOATTRS];
QComboBox * m_pTypeCombo [N_STEREOATTRS];
QLabel * m_pDefaultValueLabel[N_STEREOATTRS];
KLineEdit * m_pDefaultValueEdit [N_STEREOATTRS];
};
......
......@@ -137,6 +137,8 @@ void UMLStereotype::saveToXMI1(QDomDocument& qDoc, QDomElement& qElement)
QDomElement attElement = qDoc.createElement(QLatin1String("UML:Attribute"));
attElement.setAttribute(QLatin1String("name"), ad.name);
attElement.setAttribute(QLatin1String("type"), Uml::PrimitiveTypes::toString(ad.type));
if (!ad.defaultVal.isEmpty())
attElement.setAttribute(QLatin1String("initialValue"), ad.defaultVal);
featureElement.appendChild(attElement);
}
stereotypeElement.appendChild(featureElement);
......@@ -167,7 +169,8 @@ bool UMLStereotype::load1(QDomElement& element)
QString name = attElem.attribute(QLatin1String("name"));
QString typeStr = attElem.attribute(QLatin1String("type"));
Uml::PrimitiveTypes::Enum type = Uml::PrimitiveTypes::fromString(typeStr);
AttributeDef ad(name, type);
QString dfltVal = attElem.attribute(QLatin1String("initialValue"));
AttributeDef ad(name, type, dfltVal);
m_attrDefs.append(ad);
} else {
uDebug() << "UMLStereotype::::load1(" << m_name
......
......@@ -64,8 +64,10 @@ public:
public:
QString name;
Uml::PrimitiveTypes::Enum type;
QString defaultVal;
AttributeDef() : type(Uml::PrimitiveTypes::String) {}
AttributeDef(QString nm, Uml::PrimitiveTypes::Enum t) : name(nm), type(t) {}
AttributeDef(QString nm, Uml::PrimitiveTypes::Enum t, QString dfltVal = QString())
: name(nm), type(t), defaultVal(dfltVal) {}
virtual ~AttributeDef() {}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment