Commit b795aa90 authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Let class UMLDatatypeWidget use ComboBoxWidgetBase as base class

Followup for commit f0b38d10.
parent 345fb25b
......@@ -46,11 +46,12 @@ ComboBoxWidgetBase::ComboBoxWidgetBase(const QString &title, const QString &post
* 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
* @param startColumn The first column in the grid layout where the widget should be placed
*/
void ComboBoxWidgetBase::addToLayout(QGridLayout *layout, int row)
void ComboBoxWidgetBase::addToLayout(QGridLayout *layout, int row, int startColumn)
{
layout->addWidget(m_label, row, 0);
layout->addWidget(m_editField, row, 1);
layout->addWidget(m_label, row, startColumn);
layout->addWidget(m_editField, row, startColumn + 1);
if (m_postLabel)
layout->addWidget(m_postLabel, row, 2);
layout->addWidget(m_postLabel, row, startColumn + 2);
}
......@@ -22,7 +22,7 @@ class ComboBoxWidgetBase : public QWidget
Q_OBJECT
public:
explicit ComboBoxWidgetBase(const QString &title, const QString &postLabel = QString(), QWidget *parent = nullptr);
void addToLayout(QGridLayout *layout, int row);
void addToLayout(QGridLayout *layout, int row, int startColumn = 0);
protected:
QLabel *m_label;
......
......@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2016 *
* copyright (C) 2016,2019 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
......@@ -31,7 +31,7 @@
#include <QWidget>
UMLDatatypeWidget::UMLDatatypeWidget(UMLAttribute *attribute, QWidget *parent)
: QWidget(parent),
: ComboBoxWidgetBase(i18n("&Type:"), QString(), parent),
m_attribute(attribute),
m_datatype(0),
m_entityAttribute(0),
......@@ -44,7 +44,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLAttribute *attribute, QWidget *parent)
}
UMLDatatypeWidget::UMLDatatypeWidget(UMLClassifierListItem *datatype, QWidget *parent)
: QWidget(parent),
: ComboBoxWidgetBase(i18n("&Type:"), QString(), parent),
m_attribute(0),
m_datatype(datatype),
m_entityAttribute(0),
......@@ -57,7 +57,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLClassifierListItem *datatype, QWidget *p
}
UMLDatatypeWidget::UMLDatatypeWidget(UMLEntityAttribute *entityAttribute, QWidget *parent)
: QWidget(parent),
: ComboBoxWidgetBase(i18n("&Type:"), QString(), parent),
m_attribute(0),
m_datatype(0),
m_entityAttribute(entityAttribute),
......@@ -70,7 +70,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLEntityAttribute *entityAttribute, QWidge
}
UMLDatatypeWidget::UMLDatatypeWidget(UMLOperation *operation, QWidget *parent)
: QWidget(parent),
: ComboBoxWidgetBase(i18n("&Type:"), QString(), parent),
m_attribute(0),
m_datatype(0),
m_entityAttribute(0),
......@@ -83,7 +83,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLOperation *operation, QWidget *parent)
}
UMLDatatypeWidget::UMLDatatypeWidget(UMLTemplate *_template, QWidget *parent)
: QWidget(parent),
: ComboBoxWidgetBase(i18n("&Type:"), QString(), parent),
m_attribute(0),
m_datatype(0),
m_entityAttribute(0),
......@@ -97,27 +97,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLTemplate *_template, QWidget *parent)
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
setLayout(layout);
connect(m_comboBox, SIGNAL(editTextChanged(QString)), this, SIGNAL(editTextChanged(QString)));
}
UMLDatatypeWidget::~UMLDatatypeWidget()
{
delete m_comboBox;
delete m_label;
connect(m_editField, SIGNAL(editTextChanged(QString)), this, SIGNAL(editTextChanged(QString)));
}
bool UMLDatatypeWidget::apply()
......@@ -137,7 +117,7 @@ bool UMLDatatypeWidget::apply()
bool UMLDatatypeWidget::applyAttribute()
{
QString typeName = m_comboBox->currentText();
QString typeName = m_editField->currentText();
UMLTemplate *tmplParam = m_parent->findTemplate(typeName);
if (tmplParam) {
m_datatype->setType(tmplParam);
......@@ -183,7 +163,7 @@ bool UMLDatatypeWidget::applyAttribute()
bool UMLDatatypeWidget::applyEntityAttribute()
{
QString typeName = m_comboBox->currentText();
QString typeName = m_editField->currentText();
UMLDoc *pDoc = UMLApp::app()->document();
UMLClassifierList dataTypes = pDoc->datatypes();
foreach (UMLClassifier* dat, dataTypes) {
......@@ -211,7 +191,7 @@ bool UMLDatatypeWidget::applyEntityAttribute()
bool UMLDatatypeWidget::applyOperation()
{
QString typeName = m_comboBox->currentText();
QString typeName = m_editField->currentText();
UMLTemplate *tmplParam = 0;
if (m_parent) {
tmplParam = m_parent->findTemplate(typeName);
......@@ -226,7 +206,7 @@ bool UMLDatatypeWidget::applyOperation()
bool UMLDatatypeWidget::applyParameter()
{
// set the type name
QString typeName = m_comboBox->currentText();
QString typeName = m_editField->currentText();
if (m_parent == 0) {
uError() << "grandparent of " << m_attribute->name() << " is not a UMLClassifier";
} else {
......@@ -261,7 +241,7 @@ bool UMLDatatypeWidget::applyParameter()
bool UMLDatatypeWidget::applyTemplate()
{
QString typeName = m_comboBox->currentText();
QString typeName = m_editField->currentText();
UMLDoc *pDoc = UMLApp::app()->document();
UMLClassifierList namesList(pDoc->concepts());
foreach (UMLClassifier* obj, namesList) {
......@@ -288,14 +268,14 @@ void UMLDatatypeWidget::initTypesBox(QStringList &types, const QString& type)
}
types.sort();
m_comboBox->clear();
m_comboBox->insertItems(-1, types);
m_editField->clear();
m_editField->insertItems(-1, types);
int currentIndex = m_comboBox->findText(type);
int currentIndex = m_editField->findText(type);
if (currentIndex > -1) {
m_comboBox->setCurrentIndex(currentIndex);
m_editField->setCurrentIndex(currentIndex);
}
m_comboBox->completionObject()->addItem(type);
m_editField->completionObject()->addItem(type);
}
/**
......@@ -420,15 +400,3 @@ void UMLDatatypeWidget::insertTypesSortedTemplate(const QString& type)
insertTypesFromConcepts(types, false);
initTypesBox(types, type);
}
/**
* 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);
}
......@@ -4,18 +4,15 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2016 *
* copyright (C) 2016,2019 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#ifndef UMLDATATYPEWIDGET_H
#define UMLDATATYPEWIDGET_H
#include <QWidget>
#include "comboboxwidgetbase.h"
class KComboBox;
class QGridLayout;
class QLabel;
class UMLAttribute;
class UMLEntityAttribute;
class UMLClassifier;
......@@ -23,7 +20,7 @@ class UMLClassifierListItem;
class UMLOperation;
class UMLTemplate;
class UMLDatatypeWidget : public QWidget
class UMLDatatypeWidget : public ComboBoxWidgetBase
{
Q_OBJECT
public:
......@@ -32,9 +29,7 @@ public:
UMLDatatypeWidget(UMLEntityAttribute *entityAttribute, QWidget *parent=0);
UMLDatatypeWidget(UMLOperation *operation, QWidget *parent=0);
UMLDatatypeWidget(UMLTemplate *_template, QWidget *parent=0);
~UMLDatatypeWidget();
void addToLayout(QGridLayout *layout, int row, int startColumn = 0);
bool apply();
void reset();
......@@ -42,8 +37,6 @@ Q_SIGNALS:
void editTextChanged(const QString &);
protected:
QLabel *m_label;
KComboBox *m_comboBox;
UMLAttribute *m_attribute;
UMLClassifierListItem *m_datatype;
UMLEntityAttribute *m_entityAttribute;
......
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