Commit 2b3e00e4 authored by Ralf Habacker's avatar Ralf Habacker

Refactor out data type property widget related code from entity attribute...

Refactor out data type property widget related code from entity attribute parameter dialog into class UMLDatatypeWidget.

CCBUG:60452
parent 0a45d00d
......@@ -16,6 +16,7 @@
#include "classifier.h"
#include "umldoc.h"
#include "uml.h"
#include "umldatatypewidget.h"
#include "umlstereotypewidget.h"
#include "codegenerator.h"
#include "dialog_utils.h"
......@@ -67,12 +68,8 @@ void UMLEntityAttributeDialog::setupDialog()
valuesLayout->setMargin(margin);
valuesLayout->setSpacing(10);
m_pTypeL = new QLabel(i18n("&Type:"), m_pValuesGB);
valuesLayout->addWidget(m_pTypeL, 0, 0);
m_pTypeCB = new KComboBox(true, m_pValuesGB);
valuesLayout->addWidget(m_pTypeCB, 0, 1);
m_pTypeL->setBuddy(m_pTypeCB);
m_datatypeWidget = new UMLDatatypeWidget(m_pEntityAttribute);
m_datatypeWidget->addToLayout(valuesLayout, 0);
Dialog_Utils::makeLabeledEditField(valuesLayout, 1,
m_pNameL, i18nc("name of entity attribute", "&Name:"),
......@@ -108,7 +105,7 @@ void UMLEntityAttributeDialog::setupDialog()
m_pAttributesCB->setCompletionMode(KGlobalSettings::CompletionPopup);
#endif
valuesLayout->addWidget(m_pAttributesCB, 7, 1);
m_pTypeL->setBuddy(m_pAttributesCB);
m_pAttributesL->setBuddy(m_pAttributesCB);
insertAttribute(m_pEntityAttribute->getAttributes());
insertAttribute(QString::fromLatin1("binary"), m_pAttributesCB->count());
......@@ -151,12 +148,6 @@ void UMLEntityAttributeDialog::setupDialog()
m_pNoneRB->setChecked(true);
}
m_pTypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
#if QT_VERSION < 0x050000
m_pTypeCB->setCompletionMode(KGlobalSettings::CompletionPopup);
#endif
insertTypesSorted(m_pEntityAttribute->getTypeName());
m_pNameLE->setFocus();
connect(m_pNameLE, SIGNAL(textChanged(QString)), SLOT(slotNameChanged(QString)));
connect(m_pAutoIncrementCB, SIGNAL(clicked(bool)), this, SLOT(slotAutoIncrementStateChanged(bool)));
......@@ -211,7 +202,7 @@ bool UMLEntityAttributeDialog::apply()
m_pEntityAttribute->setIndexType(UMLEntityAttribute::None);
}
QString typeName = m_pTypeCB->currentText();
QString typeName = m_datatypeWidget->currentText();
UMLDoc *pDoc = UMLApp::app()->document();
UMLClassifierList dataTypes = pDoc->datatypes();
foreach (UMLClassifier* dat, dataTypes) {
......@@ -237,42 +228,6 @@ bool UMLEntityAttributeDialog::apply()
return true;
}
/**
* 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);
}
/**
* Inserts @p type into the type-combobox as well as its completion object.
*/
......
......@@ -17,6 +17,7 @@ class QCheckBox;
class QGroupBox;
class QLabel;
class QRadioButton;
class UMLDatatypeWidget;
class UMLEntityAttribute;
class UMLStereotypeWidget;
class KComboBox;
......@@ -39,8 +40,6 @@ protected:
virtual bool apply();
void insertTypesSorted(const QString& type = QString());
void insertAttribute(const QString& type, int index = -1);
/**
......@@ -52,12 +51,12 @@ 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_pValuesL, * m_pAttributesL ;
KComboBox * m_pTypeCB;
QLabel * m_pNameL, * m_pInitialL, * m_pValuesL, * m_pAttributesL ;
KComboBox * m_pAttributesCB;
KLineEdit * m_pNameLE, * m_pInitialLE, * m_pValuesLE;
QCheckBox* m_pAutoIncrementCB;
QCheckBox* m_pNullCB;
UMLDatatypeWidget *m_datatypeWidget;
UMLStereotypeWidget *m_stereotypeWidget;
public slots:
......
......@@ -13,6 +13,7 @@
#include "classifierlistitem.h"
#include "classifier.h"
#include "debug_utils.h"
#include "entityattribute.h"
#include "operation.h"
#include "template.h"
#include "uml.h"
......@@ -21,6 +22,7 @@
#include <KComboBox>
#include <KLocalizedString>
#include <QApplication>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
......@@ -30,6 +32,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLAttribute *attribute, QWidget *parent)
: QWidget(parent),
m_attribute(attribute),
m_datatype(0),
m_entityAttribute(0),
m_operation(0)
{
init();
......@@ -39,15 +42,27 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLClassifierListItem *datatype, QWidget *p
: QWidget(parent),
m_attribute(0),
m_datatype(datatype),
m_entityAttribute(0),
m_operation(0)
{
init();
}
UMLDatatypeWidget::UMLDatatypeWidget(UMLEntityAttribute *entityAttribute, QWidget *parent)
: QWidget(parent),
m_attribute(0),
m_datatype(0),
m_entityAttribute(entityAttribute),
m_operation(0)
{
init();
}
UMLDatatypeWidget::UMLDatatypeWidget(UMLOperation *operation, QWidget *parent)
: QWidget(parent),
m_attribute(0),
m_datatype(0),
m_entityAttribute(0),
m_operation(operation)
{
init();
......@@ -73,6 +88,8 @@ void UMLDatatypeWidget::init()
insertTypesSortedOperation(m_operation->getTypeName());
else if (m_attribute)
insertTypesSortedParameter(m_attribute->getTypeName());
else if (m_entityAttribute)
insertTypesSortedEntityAttribute(m_entityAttribute->getTypeName());
else if (m_datatype)
insertTypesSortedAttribute(m_datatype->getTypeName());
setLayout(layout);
......@@ -113,6 +130,41 @@ void UMLDatatypeWidget::insertTypesSortedAttribute(const QString& type)
m_comboBox->completionObject()->addItem(type);
}
/**
* Inserts @p type into the type-combobox as well as its completion object.
*/
void UMLDatatypeWidget::insertTypesSortedEntityAttribute(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_comboBox->clear();
m_comboBox->insertItems(-1, types);
// select the given parameter
int currentIndex = m_comboBox->findText(type);
if (currentIndex > -1) {
m_comboBox->setCurrentIndex(currentIndex);
}
m_comboBox->completionObject()->addItem(type);
}
/**
* Inserts @p type into the type-combobox.
......
......@@ -17,6 +17,7 @@ class KComboBox;
class QGridLayout;
class QLabel;
class UMLAttribute;
class UMLEntityAttribute;
class UMLClassifierListItem;
class UMLOperation;
......@@ -25,6 +26,7 @@ class UMLDatatypeWidget : public QWidget
public:
UMLDatatypeWidget(UMLAttribute *attribute, QWidget *parent=0);
UMLDatatypeWidget(UMLClassifierListItem *datatype, QWidget *parent=0);
UMLDatatypeWidget(UMLEntityAttribute *entityAttribute, QWidget *parent=0);
UMLDatatypeWidget(UMLOperation *operation, QWidget *parent=0);
~UMLDatatypeWidget();
......@@ -38,9 +40,11 @@ protected:
KComboBox *m_comboBox;
UMLAttribute *m_attribute;
UMLClassifierListItem *m_datatype;
UMLEntityAttribute *m_entityAttribute;
UMLOperation *m_operation;
void init();
void insertTypesSortedAttribute(const QString &type);
void insertTypesSortedEntityAttribute(const QString &type);
void insertTypesSortedOperation(const QString &type);
void insertTypesSortedParameter(const QString &type);
};
......
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