Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SDK
Umbrello
Commits
7cf3550f
Commit
7cf3550f
authored
Nov 27, 2019
by
Ralf Habacker
Browse files
Let class UMLStereotypeWidget use ComboBoxWidgetBase as base class
Followup for commit
f0b38d10
.
parent
b795aa90
Changes
2
Hide whitespace changes
Inline
Side-by-side
umbrello/dialogs/widgets/umlstereotypewidget.cpp
View file @
7cf3550f
...
...
@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2002-2014
*
* copyright (C) 2002-2014
,2019
*
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
...
...
@@ -26,17 +26,11 @@
Q_DECLARE_METATYPE
(
UMLStereotype
*
);
UMLStereotypeWidget
::
UMLStereotypeWidget
(
UMLObject
*
object
,
QWidget
*
parent
)
:
QWidget
(
parent
)
,
m_object
(
object
)
:
ComboBoxWidgetBase
(
i18n
(
"Stereotype &name:"
),
QString
(),
parent
)
,
m_object
(
object
)
{
Q_ASSERT
(
m_object
);
init
();
}
UMLStereotypeWidget
::~
UMLStereotypeWidget
()
{
delete
m_comboBox
;
delete
m_label
;
insertItems
(
m_object
->
umlStereotype
());
}
/**
...
...
@@ -45,19 +39,7 @@ UMLStereotypeWidget::~UMLStereotypeWidget()
*/
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
);
m_editField
->
setEditable
(
state
);
}
/**
...
...
@@ -65,50 +47,27 @@ void UMLStereotypeWidget::addToLayout(QGridLayout *layout, int row)
*/
void
UMLStereotypeWidget
::
apply
()
{
if
(
m_
comboBox
->
currentText
().
isEmpty
())
{
if
(
m_
editField
->
currentText
().
isEmpty
())
{
m_object
->
setUMLStereotype
(
0
);
return
;
}
QVariant
v
=
m_
comboBox
->
itemData
(
m_
comboBox
->
currentIndex
());
QVariant
v
=
m_
editField
->
itemData
(
m_
editField
->
currentIndex
());
if
(
v
.
canConvert
<
UMLStereotype
*>
())
{
UMLStereotype
*
selected
=
v
.
value
<
UMLStereotype
*>
();
if
(
m_object
->
umlStereotype
())
{
if
(
m_object
->
umlStereotype
()
->
name
()
!=
m_
comboBox
->
currentText
())
if
(
m_object
->
umlStereotype
()
->
name
()
!=
m_
editField
->
currentText
())
m_object
->
setUMLStereotype
(
selected
);
}
else
m_object
->
setUMLStereotype
(
selected
);
}
else
{
UMLStereotype
*
stereotype
=
new
UMLStereotype
(
m_
comboBox
->
currentText
());
UMLStereotype
*
stereotype
=
new
UMLStereotype
(
m_
editField
->
currentText
());
UMLApp
::
app
()
->
document
()
->
addStereotype
(
stereotype
);
m_object
->
setUMLStereotype
(
stereotype
);
}
}
/**
* 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
#if QT_VERSION < 0x050000
m_comboBox
->
setCompletionMode
(
KGlobalSettings
::
CompletionPopup
);
#endif
insertItems
(
m_object
->
umlStereotype
());
setLayout
(
layout
);
}
/**
* Insert stereotypes into combo box and select the currently used stereotype.
* @param type currently used stereotype
...
...
@@ -126,18 +85,18 @@ void UMLStereotypeWidget::insertItems(UMLStereotype *type)
types
[
type
->
name
()]
=
type
;
}
m_
comboBox
->
clear
();
m_
comboBox
->
addItem
(
QLatin1String
(
""
),
QVariant
(
0
));
m_
editField
->
clear
();
m_
editField
->
addItem
(
QLatin1String
(
""
),
QVariant
(
0
));
foreach
(
const
QString
&
key
,
types
.
keys
())
{
// krazy:exclude=foreach
m_
comboBox
->
addItem
(
key
,
QVariant
::
fromValue
((
types
[
key
])));
m_
editField
->
addItem
(
key
,
QVariant
::
fromValue
((
types
[
key
])));
}
// select the given parameter
if
(
type
)
{
int
currentIndex
=
m_
comboBox
->
findText
(
type
->
name
());
int
currentIndex
=
m_
editField
->
findText
(
type
->
name
());
if
(
currentIndex
>
-
1
)
{
m_
comboBox
->
setCurrentIndex
(
currentIndex
);
m_
editField
->
setCurrentIndex
(
currentIndex
);
}
m_
comboBox
->
completionObject
()
->
addItem
(
type
->
name
());
m_
editField
->
completionObject
()
->
addItem
(
type
->
name
());
}
}
umbrello/dialogs/widgets/umlstereotypewidget.h
View file @
7cf3550f
...
...
@@ -4,39 +4,29 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2002-2014
*
* copyright (C) 2002-2014
,2019
*
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
#ifndef UMLSTEREOTYPEWIDGET_H
#define UMLSTEREOTYPEWIDGET_H
#include
<QWidget>
#include
"comboboxwidgetbase.h"
class
UMLObject
;
class
UMLStereotype
;
class
KComboBox
;
class
QGridLayout
;
class
QLabel
;
class
UMLStereotypeWidget
:
public
QWidget
class
UMLStereotypeWidget
:
public
ComboBoxWidgetBase
{
public:
explicit
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
);
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment