Commit 7556a8a3 authored by Ralf Habacker's avatar Ralf Habacker

Add show stereotype and attribute signatures support to entity widgets

BUG:391087
FIXED-IN:2.24.80 (KDE Applications 18.03.80)
parent b8969ebb
......@@ -167,6 +167,7 @@
<!ELEMENT entitywidget ANY >
<!ATTLIST entitywidget
%UMLWidgetAtts;
showattsig CDATA #IMPLIED
>
<!ELEMENT floatingdashlinewidget ANY >
<!ATTLIST floatingdashlinewidget
......
......@@ -223,6 +223,8 @@ void ClassPropertiesDialog::setupPages(bool assoc)
if (ot == UMLObject::ot_Entity) {
setupEntityAttributesPage();
setupEntityConstraintsPage();
if (m_pWidget && m_pWidget->isEntityWidget())
setupEntityDisplayPage(m_pWidget->asEntityWidget());
}
if (ot == UMLObject::ot_Package) {
setupContentsPage();
......@@ -246,7 +248,7 @@ void ClassPropertiesDialog::setupGeneralPage()
else
m_pGenPage = new ClassGeneralPage(m_doc, 0, m_pObject);
createPage(i18nc("general settings page name", "General"), i18n("General Settings"),
Icon_Utils::it_Properties_General, m_pGenPage)->setMinimumSize(310, 330);
Icon_Utils::it_Properties_General, m_pGenPage)->widget()->setMinimumSize(310, 330);
}
/**
......@@ -255,7 +257,17 @@ void ClassPropertiesDialog::setupGeneralPage()
void ClassPropertiesDialog::setupDisplayPage()
{
ClassifierWidget *cw = m_pWidget->asClassifierWidget();
m_pOptionsPage = new ClassOptionsPage(page, cw);
m_pOptionsPage = new ClassOptionsPage(0, cw);
createPage(i18nc("display option page name", "Display"), i18n("Display Options"),
Icon_Utils::it_Properties_Display, m_pOptionsPage);
}
/**
* Sets up the page "Display" for the component.
*/
void ClassPropertiesDialog::setupEntityDisplayPage(EntityWidget *widget)
{
m_pOptionsPage = new ClassOptionsPage(0, widget);
createPage(i18nc("display option page name", "Display"), i18n("Display Options"),
Icon_Utils::it_Properties_Display, m_pOptionsPage);
}
......
......@@ -18,6 +18,7 @@ class ClassGeneralPage;
class ClassifierListPage;
class ClassOptionsPage;
class ConstraintListPage;
class EntityWidget;
class PackageContentsPage;
class ObjectWidget;
class UMLDoc;
......@@ -57,6 +58,7 @@ protected:
void setupOperationsPage();
void setupTemplatesPage();
void setupEnumLiteralsPage();
void setupEntityDisplayPage(EntityWidget *widget);
void setupEntityAttributesPage();
void setupEntityConstraintsPage();
void setupContentsPage();
......
......@@ -15,6 +15,7 @@
#include "umlscene.h"
#include "umlview.h"
#include "classifierwidget.h"
#include "entitywidget.h"
#include "widgetbase.h"
// kde includes
......@@ -75,6 +76,15 @@ ClassOptionsPage::ClassOptionsPage(QWidget* pParent, Settings::OptionState *opti
setupClassPageOption();
}
ClassOptionsPage::ClassOptionsPage(QWidget *pParent, EntityWidget *widget)
: QWidget(pParent),
m_isDiagram(false)
{
init();
m_entityWidget = widget;
setupPageFromEntityWidget();
}
/**
* Destructor
*/
......@@ -110,6 +120,8 @@ void ClassOptionsPage::apply()
applyScene();
} else if (m_options) {
applyOptionState();
} else if (m_entityWidget) {
applyEntityWidget();
}
}
......@@ -315,6 +327,29 @@ void ClassOptionsPage::setupClassPageOption()
}
}
void ClassOptionsPage::setupPageFromEntityWidget()
{
int margin = fontMetrics().height();
QVBoxLayout * topLayout = new QVBoxLayout(this);
topLayout->setSpacing(6);
m_visibilityGB = new QGroupBox(i18n("Show"), this);
topLayout->addWidget(m_visibilityGB);
QGridLayout * visibilityLayout = new QGridLayout(m_visibilityGB);
visibilityLayout->setSpacing(10);
visibilityLayout->setMargin(margin);
visibilityLayout->setRowStretch(3, 1);
m_showAttSigCB = new QCheckBox(i18n("Attribute Signatures"), m_visibilityGB);
m_showAttSigCB->setChecked(m_entityWidget->showAttributeSignature());
visibilityLayout->addWidget(m_showAttSigCB, 1, 0);
m_showStereotypeCB = new QCheckBox(i18n("Stereot&ype"), m_visibilityGB);
m_showStereotypeCB->setChecked(m_entityWidget->showStereotype());
visibilityLayout->addWidget(m_showStereotypeCB, 2, 0);
}
/**
* Sets the ClassifierWidget's properties to those selected in this dialog page.
*/
......@@ -379,6 +414,13 @@ void ClassOptionsPage::applyScene()
m_scene->setShowOpSig(m_showOpSigCB->isChecked());
}
void ClassOptionsPage::applyEntityWidget()
{
Q_ASSERT(m_entityWidget);
m_entityWidget->setShowStereotype(m_showStereotypeCB->isChecked());
m_entityWidget->setShowAttributeSignature(m_showAttSigCB->isChecked());
}
/**
* Initialize optional items
*/
......@@ -387,6 +429,7 @@ void ClassOptionsPage::init()
m_scene = 0;
m_options = 0;
m_pWidget = 0;
m_entityWidget = 0;
m_showStereotypeCB = 0;
m_showAttsCB = 0;
m_showAttSigCB = 0;
......
......@@ -17,6 +17,7 @@
#include <QWidget>
class ClassifierWidget;
class EntityWidget;
class UMLScene;
class KComboBox;
class QCheckBox;
......@@ -41,6 +42,7 @@ public:
ClassOptionsPage(QWidget* pParent, ClassifierWidget* pWidget);
ClassOptionsPage(QWidget* pParent, UMLScene *scene);
ClassOptionsPage(QWidget* pParent, Settings::OptionState *options, bool isDiagram=true);
ClassOptionsPage(QWidget* pParent, EntityWidget* widget);
virtual ~ClassOptionsPage();
void setDefaults();
......@@ -54,10 +56,12 @@ protected:
void setupPage();
void setupPageFromScene();
void setupClassPageOption();
void setupPageFromEntityWidget();
void applyWidget();
void applyOptionState();
void applyScene();
void applyEntityWidget();
void insertAttribScope(const QString& type, int index = -1);
void insertOperationScope(const QString& type, int index = -1);
......@@ -78,6 +82,7 @@ protected:
KComboBox * m_operationScopeCB;
ClassifierWidget* m_pWidget; ///< The classifier widget to represent in the dialog page.
EntityWidget* m_entityWidget; ///< The entity widget to represent in the dialog page.
UMLScene* m_scene; ///< The scene to represent in the dialog page.
Settings::OptionState *m_options; ///< The OptionState structure to represent in the dialog page.
bool m_isDiagram; ///< Flag indicating that page is for diagram property dialog
......
......@@ -20,6 +20,7 @@
#include "classifierwidget.h"
#include "combinedfragmentwidget.h"
#include "debug_utils.h"
#include "entitywidget.h"
#include "floatingtextwidget.h"
#include "folder.h"
#include "forkjoinwidget.h"
......@@ -460,6 +461,7 @@ void ListPopupMenu::insertSingleSelectionMenu(WidgetBase* object)
case WidgetBase::wt_Entity:
insertSubMenuNew(mt_Entity);
insertSubMenuShowEntity(object->asEntityWidget());
insertSubMenuColor(object->useFillColor());
insertStdItems(true, type);
insert(mt_Rename);
......@@ -1426,6 +1428,23 @@ ListPopupMenu::MenuType ListPopupMenu::typeFromAction(QAction *action)
}
}
void ListPopupMenu::insertSubMenuShowEntity(EntityWidget *widget)
{
#if QT_VERSION >= 0x050000
QMenu* show = new QMenu(i18n("Show"), this);
#else
KMenu* show = new KMenu(i18n("Show"), this);
#endif
show->setIcon(Icon_Utils::SmallIcon(Icon_Utils::it_Show));
insert(mt_Show_Attribute_Signature, show, i18n("Attribute Signature"), CHECKABLE);
setActionChecked(mt_Show_Attribute_Signature, widget->showAttributeSignature());
insert(mt_Show_Stereotypes, show, i18n("Stereotype"), CHECKABLE);
setActionChecked(mt_Show_Stereotypes, widget->showStereotype());
addMenu(show);
}
/**
* Add the align actions submenu
*/
......
......@@ -362,6 +362,7 @@ private:
#endif
void insertSubMenuNew(MenuType type);
void insertSubMenuShowEntity(EntityWidget *widget);
void insertSubMenuAlign();
void insertSubMenuColor(bool fc);
......
......@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2003-2014 *
* copyright (C) 2003-2018 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
......@@ -46,6 +46,54 @@ EntityWidget::~EntityWidget()
{
}
/**
* calculate content related size of widget.
*
* @return calculated widget size
*/
QSizeF EntityWidget::calculateSize(bool withExtensions /* = true */) const
{
Q_UNUSED(withExtensions)
const QFontMetrics &fm = getFontMetrics(UMLWidget::FT_NORMAL);
const int fontHeight = fm.lineSpacing();
if (!m_umlObject)
return QSizeF(width(), height());
qreal width = 0, height = defaultMargin;
if (showStereotype() && !m_umlObject->stereotype().isEmpty()) {
const QFontMetrics &bfm = UMLWidget::getFontMetrics(UMLWidget::FT_BOLD);
const int stereoWidth = bfm.size(0, m_umlObject->stereotype(true)).width();
if (stereoWidth > width)
width = stereoWidth;
height += fontHeight;
}
const QFontMetrics &bfm = UMLWidget::getFontMetrics(UMLWidget::FT_BOLD);
const int nameWidth = bfm.size(0, name()).width();
if (nameWidth > width)
width = nameWidth;
height += fontHeight;
UMLClassifier *classifier = m_umlObject->asUMLClassifier();
UMLClassifierListItemList list = classifier->getFilteredList(UMLObject::ot_EntityAttribute);
foreach (UMLClassifierListItem* entityattribute, list) {
QString text = entityattribute->name();
UMLEntityAttribute* casted = entityattribute->asUMLEntityAttribute();
if (showAttributeSignature()) {
text.append(QLatin1String(" : ") + casted->getTypeName());
text.append(QLatin1String(" [") + casted->getAttributes() + QLatin1String("]"));
}
if (showStereotype()) {
text.append(QLatin1String(" ") + casted->stereotype(true));
}
const int nameWidth = bfm.size(0, text).width();
if (nameWidth > width)
width = nameWidth;
height += fontHeight;
}
return QSizeF(width + 2*defaultMargin, height);
}
/**
* Draws the entity as a rectangle with a box underneith with a list of literals
*/
......@@ -74,7 +122,7 @@ void EntityWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
font.setBold(true);
painter->setFont(font);
int y = 0;
if (!m_umlObject->stereotype().isEmpty()) {
if (showStereotype() && !m_umlObject->stereotype().isEmpty()) {
painter->drawText(ENTITY_MARGIN, 0,
w - ENTITY_MARGIN * 2, fontHeight,
Qt::AlignCenter, m_umlObject->stereotype(true));
......@@ -110,6 +158,13 @@ void EntityWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
QString text = entityattribute->name();
painter->setPen(textColor());
UMLEntityAttribute* casted = entityattribute->asUMLEntityAttribute();
if (showAttributeSignature()) {
text.append(QLatin1String(" : ") + casted->getTypeName());
text.append(QLatin1String(" [") + casted->getAttributes() + QLatin1String("]"));
}
if (showStereotype()) {
text.append(QLatin1String(" ") + casted->stereotype(true));
}
if(casted && casted->indexType() == UMLEntityAttribute::Primary)
{
font.setUnderline(true);
......@@ -125,6 +180,15 @@ void EntityWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
UMLWidget::paint(painter, option, widget);
}
bool EntityWidget::loadFromXMI1(QDomElement & qElement)
{
if (!UMLWidget::loadFromXMI1(qElement))
return false;
QString showAttributeSignatures = qElement.attribute(QLatin1String("showattsigs"), QLatin1String("0"));
m_showAttributeSignatures = (bool)showAttributeSignatures.toInt();
return true;
}
/**
* Saves to the "entitywidget" XMI element.
*/
......@@ -132,6 +196,8 @@ void EntityWidget::saveToXMI1(QDomDocument& qDoc, QDomElement& qElement)
{
QDomElement conceptElement = qDoc.createElement(QLatin1String("entitywidget"));
UMLWidget::saveToXMI1(qDoc, conceptElement);
conceptElement.setAttribute(QLatin1String("showattsigs"), m_showAttributeSignatures);
qElement.appendChild(conceptElement);
}
......@@ -181,6 +247,14 @@ void EntityWidget::slotMenuSelection(QAction* action)
}
break;
case ListPopupMenu::mt_Show_Attribute_Signature:
setShowAttributeSignature(!showAttributeSignature());
break;
case ListPopupMenu::mt_Show_Stereotypes:
setShowStereotype(!showStereotype());
break;
default:
UMLWidget::slotMenuSelection(action);
}
......@@ -195,52 +269,27 @@ QSizeF EntityWidget::minimumSize() const
return UMLWidget::minimumSize();
}
int width, height;
QFont font = UMLWidget::font();
font.setItalic(false);
font.setUnderline(false);
font.setBold(false);
const QFontMetrics fm(font);
const int fontHeight = fm.lineSpacing();
int lines = 1;//always have one line - for name
if (!m_umlObject->stereotype().isEmpty()) {
lines++;
}
const int numberOfEntityAttributes = m_umlObject->asUMLEntity()->entityAttributes();
height = width = 0;
//set the height of the entity
lines += numberOfEntityAttributes;
if (numberOfEntityAttributes == 0) {
height += fontHeight / 2; //no entity literals, so just add a bit of space
}
height += lines * fontHeight;
//now set the width of the concept
//set width to name to start with
// FIXME spaces to get round beastie with font width,
// investigate UMLWidget::getFontMetrics()
width = getFontMetrics(FT_BOLD_ITALIC).boundingRect(QLatin1Char(' ') + name() +
QLatin1Char(' ')).width();
const int w = getFontMetrics(FT_BOLD).boundingRect(m_umlObject->stereotype(true)).width();
width = w > width ? w : width;
UMLClassifier* classifier = m_umlObject->asUMLClassifier();
UMLClassifierListItemList list = classifier->getFilteredList(UMLObject::ot_EntityAttribute);
UMLClassifierListItem* listItem = 0;
foreach (listItem, list) {
int w = fm.width(listItem->name());
width = w > width?w:width;
}
return calculateSize();
}
//allow for width margin
width += ENTITY_MARGIN * 2;
/**
* Set the status of whether to show attributes.
*
* @param flag True if attributes shall be shown.
*/
void EntityWidget::setShowAttributeSignature(bool flag)
{
m_showAttributeSignatures = flag;
updateGeometry();
update();
}
return QSizeF(width, height);
/**
* Returns the status of whether to show attributes.
*
* @return True if attributes are shown.
*/
bool EntityWidget::showAttributeSignature() const
{
return m_showAttributeSignatures;
}
......@@ -4,7 +4,7 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* copyright (C) 2003-2014 *
* copyright (C) 2003-2018 *
* Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
***************************************************************************/
......@@ -35,15 +35,20 @@ public:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
// UMLWidget::loadFromXMI1 is used to load this widget.
virtual bool loadFromXMI1(QDomElement &qElement);
virtual void saveToXMI1(QDomDocument& qDoc, QDomElement& qElement);
void setShowAttributeSignature(bool flag);
bool showAttributeSignature() const;
public Q_SLOTS:
virtual void slotMenuSelection(QAction* action);
protected:
QSizeF minimumSize() const;
bool m_showAttributeSignatures;
QSizeF minimumSize() const;
QSizeF calculateSize(bool withExtensions=true) const;
};
#endif
......@@ -30,9 +30,9 @@ inline QByteArray umbrelloVersion()
// Update this version and dtd's in doc/xml when changing the XMI file format
#if defined(ENABLE_WIDGET_SHOW_DOC) || defined(ENABLE_XMIRESOLUTION)
#define XMI_FILE_VERSION "1.6.14"
#define XMI_FILE_VERSION "1.6.15"
#else
#define XMI_FILE_VERSION "1.6.13"
#define XMI_FILE_VERSION "1.6.14"
#endif
#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