Commit 0340c1bc authored by Ralf Habacker's avatar Ralf Habacker

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

Refactor out data type property widget related code from attribute and operation dialog into class UMLDatatypeWidget.

This makes it easier to implemented further data type widget related extensions.

CCBUG:60452
parent 63b43160
......@@ -235,6 +235,7 @@ set(libdialogs_SRCS
dialogs/widgets/imagetypewidget.cpp
dialogs/widgets/resolutionwidget.cpp
dialogs/widgets/umlartifacttypewidget.cpp
dialogs/widgets/umldatatypewidget.cpp
dialogs/widgets/umlobjectnamewidget.cpp
dialogs/widgets/umlpackagewidget.cpp
dialogs/widgets/umlstereotypewidget.cpp
......
......@@ -18,6 +18,7 @@
#include "template.h"
#include "umldoc.h"
#include "uml.h"
#include "umldatatypewidget.h"
#include "umlstereotypewidget.h"
#include "visibilityenumwidget.h"
#include "dialog_utils.h"
......@@ -69,12 +70,8 @@ void UMLAttributeDialog::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_pAttribute);
m_datatypeWidget->addToLayout(valuesLayout, 0);
Dialog_Utils::makeLabeledEditField(valuesLayout, 1,
m_pNameL, i18nc("attribute name", "&Name:"),
......@@ -95,13 +92,6 @@ void UMLAttributeDialog::setupDialog()
m_visibilityEnumWidget = new VisibilityEnumWidget(m_pAttribute, this);
m_visibilityEnumWidget->addToLayout(mainLayout);
m_pTypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
#if QT_VERSION < 0x050000
m_pTypeCB->setCompletionMode(KGlobalSettings::CompletionPopup);
#endif
//now add the Concepts
insertTypesSorted(m_pAttribute->getTypeName());
m_docWidget = new DocumentationWidget(m_pAttribute, this);
mainLayout->addWidget(m_docWidget);
......@@ -146,7 +136,7 @@ bool UMLAttributeDialog::apply()
m_stereotypeWidget->apply();
m_pAttribute->setStatic(m_pStaticCB->isChecked());
QString typeName = m_pTypeCB->currentText();
QString typeName = m_datatypeWidget->currentText();
UMLTemplate *tmplParam = pConcept->findTemplate(typeName);
if (tmplParam) {
m_pAttribute->setType(tmplParam);
......@@ -191,33 +181,3 @@ bool UMLAttributeDialog::apply()
return true;
}
/**
* Inserts @p type into the type-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
*/
void UMLAttributeDialog::insertTypesSorted(const QString& type)
{
UMLDoc * uDoc = UMLApp::app()->document();
UMLClassifierList namesList(uDoc->concepts());
QStringList types;
foreach (UMLClassifier* obj, namesList) {
types << obj->fullyQualifiedName();
}
if (!types.contains(type)) {
types << type;
}
types.sort();
m_pTypeCB->clear();
m_pTypeCB->insertItems(-1, types);
int currentIndex = m_pTypeCB->findText(type);
if (currentIndex > -1) {
m_pTypeCB->setCurrentIndex(currentIndex);
}
m_pTypeCB->completionObject()->addItem(type);
}
......@@ -19,9 +19,8 @@ class QGroupBox;
class QRadioButton;
class QLabel;
class UMLAttribute;
class UMLStereotypeWidget;
class KComboBox;
class KLineEdit;
class UMLDatatypeWidget;
class UMLStereotypeWidget;
class VisibilityEnumWidget;
......@@ -37,13 +36,9 @@ public:
~UMLAttributeDialog();
protected:
void setupDialog();
bool apply();
void insertTypesSorted(const QString& type = QString());
/**
* The Attribute to represent
*/
......@@ -51,10 +46,10 @@ protected:
//GUI Widgets
QGroupBox * m_pValuesGB;
QLabel * m_pTypeL, * m_pNameL, * m_pInitialL;
KComboBox * m_pTypeCB;
QLabel * m_pNameL, * m_pInitialL;
KLineEdit * m_pNameLE, * m_pInitialLE;
QCheckBox* m_pStaticCB;
UMLDatatypeWidget *m_datatypeWidget;
UMLStereotypeWidget *m_stereotypeWidget;
VisibilityEnumWidget *m_visibilityEnumWidget;
DocumentationWidget *m_docWidget;
......
......@@ -20,6 +20,7 @@
#include "template.h"
#include "listpopupmenu.h"
#include "umlattributelist.h"
#include "umldatatypewidget.h"
#include "umlstereotypewidget.h"
#include "classifierlistitem.h"
#include "documentationwidget.h"
......@@ -96,12 +97,8 @@ void UMLOperationDialog::setupDialog()
m_pNameL, i18nc("operation name", "&Name:"),
m_pNameLE, m_operation->name());
m_pRtypeL = new QLabel(i18n("&Type:"), m_pGenGB);
genLayout->addWidget(m_pRtypeL, 0, 2);
m_pRtypeCB = new KComboBox(true, m_pGenGB);
genLayout->addWidget(m_pRtypeCB, 0, 3);
m_pRtypeL->setBuddy(m_pRtypeCB);
m_datatypeWidget = new UMLDatatypeWidget(m_operation);
m_datatypeWidget->addToLayout(genLayout, 0, 2);
m_stereotypeWidget = new UMLStereotypeWidget(m_operation);
m_stereotypeWidget->addToLayout(genLayout, 1);
......@@ -177,13 +174,6 @@ void UMLOperationDialog::setupDialog()
m_pUpButton->setEnabled(false);
m_pDownButton->setEnabled(false);
m_pRtypeCB->setDuplicatesEnabled(false); // only allow one of each type in box
#if QT_VERSION < 0x050000
m_pRtypeCB->setCompletionMode(KGlobalSettings::CompletionPopup);
#endif
// add the return types
insertTypesSorted(m_operation->getTypeName());
// fill in parm list box
UMLAttributeList list = m_operation->getParmList();
foreach (UMLAttribute* pAtt, list) {
......@@ -425,7 +415,7 @@ bool UMLOperationDialog::apply()
m_visibilityEnumWidget->apply();
QString typeName = m_pRtypeCB->currentText();
QString typeName = m_datatypeWidget->currentText();
UMLTemplate *tmplParam = 0;
if (classifier) {
tmplParam = classifier->findTemplate(typeName);
......@@ -456,47 +446,4 @@ bool UMLOperationDialog::apply()
return true;
}
/**
* 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 UMLOperationDialog::insertTypesSorted(const QString& type)
{
QStringList types;
// Add "void". We use this for denoting "no return type" independent
// of the programming language.
// For example, the Ada generator would interpret the return type
// "void" as an instruction to generate a procedure instead of a
// function.
types << QLatin1String("void");
// add template parameters
UMLClassifier *classifier = dynamic_cast<UMLClassifier*>(m_operation->parent());
if (classifier) {
UMLClassifierListItemList tmplParams(classifier->getFilteredList(UMLOperation::ot_Template));
foreach (UMLClassifierListItem* li, tmplParams) {
types << li->name();
}
}
// add the Classes and Interfaces (both are Concepts)
UMLClassifierList namesList(m_doc->concepts());
foreach (UMLClassifier* obj, namesList) {
types << obj->fullyQualifiedName();
}
// add the given parameter
if (!types.contains(type)) {
types << type;
}
types.sort();
m_pRtypeCB->clear();
m_pRtypeCB->insertItems(-1, types);
// select the given parameter
int currentIndex = m_pRtypeCB->findText(type);
if (currentIndex > -1) {
m_pRtypeCB->setCurrentIndex(currentIndex);
}
}
......@@ -29,6 +29,7 @@ class QToolButton;
class KLineEdit;
class UMLDoc;
class UMLOperation;
class UMLDatatypeWidget;
class UMLStereotypeWidget;
class VisibilityEnumWidget;
......@@ -65,9 +66,8 @@ protected:
QRadioButton* m_pPrivateRB;
QRadioButton* m_pProtectedRB;
QRadioButton* m_pImplementationRB;
QLabel* m_pRtypeL;
QLabel* m_pNameL;
KComboBox* m_pRtypeCB;
UMLDatatypeWidget* m_datatypeWidget;
UMLStereotypeWidget* m_stereotypeWidget;
KLineEdit* m_pNameLE;
QCheckBox* m_pAbstractCB;
......
/***************************************************************************
* 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) 2016 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#include "umldatatypewidget.h"
#include "classifierlistitem.h"
#include "classifier.h"
#include "operation.h"
#include "uml.h"
#include "umldoc.h"
#include <KComboBox>
#include <KLocalizedString>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QWidget>
UMLDatatypeWidget::UMLDatatypeWidget(UMLOperation *operation, QWidget *parent)
: QWidget(parent),
m_datatype(0),
m_operation(operation)
{
init();
}
UMLDatatypeWidget::UMLDatatypeWidget(UMLClassifierListItem *datatype, QWidget *parent)
: QWidget(parent),
m_datatype(datatype),
m_operation(0)
{
init();
}
void UMLDatatypeWidget::init()
{
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(0,0,0,0);
m_label = new QLabel(i18n("&Type:"), this);
layout->addWidget(m_label);
m_comboBox = new KComboBox(true, this);
layout->addWidget(m_comboBox);
m_label->setBuddy(m_comboBox);
m_comboBox->setDuplicatesEnabled(false); // only allow one of each type in box
#if QT_VERSION < 0x050000
m_comboBox->setCompletionMode(KGlobalSettings::CompletionPopup);
#endif
//now add the Concepts
if (m_operation)
insertTypesSortedOperation(m_operation->getTypeName());
else
insertTypesSortedAttribute(m_datatype->getTypeName());
setLayout(layout);
}
UMLDatatypeWidget::~UMLDatatypeWidget()
{
delete m_comboBox;
delete m_label;
}
/**
* Inserts @p type into the type-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
*/
void UMLDatatypeWidget::insertTypesSortedAttribute(const QString& type)
{
UMLDoc * uDoc = UMLApp::app()->document();
UMLClassifierList namesList(uDoc->concepts());
QStringList types;
foreach (UMLClassifier* obj, namesList) {
types << obj->fullyQualifiedName();
}
if (!types.contains(type)) {
types << type;
}
types.sort();
m_comboBox->clear();
m_comboBox->insertItems(-1, types);
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.
* 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 UMLDatatypeWidget::insertTypesSortedOperation(const QString& type)
{
QStringList types;
// Add "void". We use this for denoting "no return type" independent
// of the programming language.
// For example, the Ada generator would interpret the return type
// "void" as an instruction to generate a procedure instead of a
// function.
types << QLatin1String("void");
// add template parameters
UMLClassifier *classifier = dynamic_cast<UMLClassifier*>(m_operation->parent());
if (classifier) {
UMLClassifierListItemList tmplParams(classifier->getFilteredList(UMLOperation::ot_Template));
foreach (UMLClassifierListItem* li, tmplParams) {
types << li->name();
}
}
// add the Classes and Interfaces (both are Concepts)
UMLDoc * uDoc = UMLApp::app()->document();
UMLClassifierList namesList(uDoc->concepts());
foreach (UMLClassifier* obj, namesList) {
types << obj->fullyQualifiedName();
}
// 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);
}
}
/**
* 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 UMLDatatypeWidget::addToLayout(QGridLayout *layout, int row, int startColumn)
{
layout->addWidget(m_label, row, startColumn);
layout->addWidget(m_comboBox, row, startColumn + 1);
}
/**
* Return currently selected text of the widget.
* @return string
*/
QString UMLDatatypeWidget::currentText() const
{
return m_comboBox->currentText();
}
/***************************************************************************
* 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) 2016 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#ifndef UMLDATATYPEWIDGET_H
#define UMLDATATYPEWIDGET_H
#include <QWidget>
class KComboBox;
class QGridLayout;
class QLabel;
class UMLClassifierListItem;
class UMLOperation;
class UMLDatatypeWidget : public QWidget
{
public:
UMLDatatypeWidget(UMLOperation *operation, QWidget *parent=0);
UMLDatatypeWidget(UMLClassifierListItem *datatype, QWidget *parent=0);
~UMLDatatypeWidget();
void addToLayout(QGridLayout *layout, int row, int startColumn = 0);
QString currentText() const;
bool apply();
void reset();
protected:
QLabel *m_label;
KComboBox *m_comboBox;
UMLClassifierListItem *m_datatype;
UMLOperation *m_operation;
void init();
void insertTypesSortedOperation(const QString &type);
void insertTypesSortedAttribute(const QString &type);
};
#endif
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