From 56be6cc2c8b4558b18ff06c1b36a557e14ee3228 Mon Sep 17 00:00:00 2001 From: Jochen Becher Date: Wed, 2 Aug 2017 09:44:21 +0200 Subject: [PATCH] ModelEditor: Improve custom items The default name for a new custom item can be set. The display of any text of a custom icon can be suppressed (e.g. start element in activity diagrams). Change-Id: Iaaefda3a6795e0b2a63d96fd001948d302906b7a Reviewed-by: Tobias Hunger --- share/qtcreator/modeleditor/standard.def | 15 +++- .../qmt/config/stereotypedefinitionparser.cpp | 7 +- .../qmt/diagram_scene/items/classitem.cpp | 12 ++-- .../qmt/diagram_scene/items/componentitem.cpp | 2 +- .../qmt/diagram_scene/items/itemitem.cpp | 2 +- .../qmt/diagram_scene/items/objectitem.cpp | 68 +++++++++++-------- .../qmt/diagram_scene/items/objectitem.h | 7 +- .../qmt/diagram_scene/items/packageitem.cpp | 2 +- .../qmt/diagram_scene/items/relationitem.cpp | 2 +- .../items/stereotypedisplayvisitor.cpp | 13 ++++ .../items/stereotypedisplayvisitor.h | 5 +- .../qmt/stereotype/stereotypeicon.cpp | 10 +++ .../qmt/stereotype/stereotypeicon.h | 9 ++- .../qmt/tasks/diagramscenecontroller.cpp | 9 +-- src/plugins/modeleditor/dragtool.cpp | 6 +- src/plugins/modeleditor/dragtool.h | 4 +- src/plugins/modeleditor/modeleditor.cpp | 24 ++++--- 17 files changed, 131 insertions(+), 66 deletions(-) diff --git a/share/qtcreator/modeleditor/standard.def b/share/qtcreator/modeleditor/standard.def index 662bee8e487..d2d9210a998 100644 --- a/share/qtcreator/modeleditor/standard.def +++ b/share/qtcreator/modeleditor/standard.def @@ -15,6 +15,7 @@ // display: +// name: ".> // width: // height: // minwidth: @@ -22,9 +23,9 @@ // lockSize: -// textAlignment: +// textAlignment: // baseColor: // Shape { // Line { x1: ; y1: ; x2:; y2: } @@ -345,6 +346,8 @@ Icon { elements: item stereotype: 'start' display: icon + name: "" + textAlignment: none width: 20 height: 20 lockSize: ratio @@ -391,6 +394,8 @@ Icon { elements: item stereotype: 'horizontalbar' display: icon + name: "" + textAlignment: none width: 20 height: 5 minWidth: 20 @@ -408,6 +413,8 @@ Icon { elements: item stereotype: 'verticalbar' display: icon + name: "" + textAlignment: none width: 5 height: 20 minWidth: 5 @@ -424,6 +431,8 @@ Icon { elements: item stereotype: 'termination' display: icon + name: "" + textAlignment: none width: 20 height: 20 lockSize: ratio diff --git a/src/libs/modelinglib/qmt/config/stereotypedefinitionparser.cpp b/src/libs/modelinglib/qmt/config/stereotypedefinitionparser.cpp index 8c28e638382..f73d4afc3b8 100644 --- a/src/libs/modelinglib/qmt/config/stereotypedefinitionparser.cpp +++ b/src/libs/modelinglib/qmt/config/stereotypedefinitionparser.cpp @@ -424,7 +424,8 @@ void StereotypeDefinitionParser::parseIcon() const static QHash alignNames = QHash() << qMakePair(QString("below"), StereotypeIcon::TextalignBelow) << qMakePair(QString("center"), StereotypeIcon::TextalignCenter) - << qMakePair(QString("none"), StereotypeIcon::TextalignNone); + << qMakePair(QString("none"), StereotypeIcon::TextalignNone) + << qMakePair(QString("top"), StereotypeIcon::TextalignTop); parseEnum( parseIdentifierProperty(), alignNames, token.sourcePos(), [&](StereotypeIcon::TextAlignment align) { stereotypeIcon.setTextAlignment(align); }); @@ -436,6 +437,10 @@ void StereotypeDefinitionParser::parseIcon() case KEYWORD_SHAPE: stereotypeIcon.setIconShape(parseIconShape()); break; + case KEYWORD_NAME: + stereotypeIcon.setName(parseStringProperty()); + stereotypeIcon.setHasName(true); + break; default: throwUnknownPropertyError(token); } diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp index fe459338a17..958643dfe29 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp +++ b/src/libs/modelinglib/qmt/diagram_scene/items/classitem.cpp @@ -131,7 +131,7 @@ void ClassItem::update() updateStereotypes(stereotypeIconId(), stereotypeIconDisplay(), style); // namespace - if (!diagramClass->umlNamespace().isEmpty()) { + if (!suppressTextDisplay() && !diagramClass->umlNamespace().isEmpty()) { if (!m_namespace) m_namespace = new QGraphicsSimpleTextItem(this); m_namespace->setFont(style->smallFont()); @@ -147,7 +147,7 @@ void ClassItem::update() updateNameItem(style); // context - if (showContext()) { + if (!suppressTextDisplay() && showContext()) { if (!m_contextLabel) m_contextLabel = new ContextLabelItem(this); m_contextLabel->setFont(style->smallFont()); @@ -160,7 +160,7 @@ void ClassItem::update() } // attributes separator - if (m_shape || !m_attributesText.isEmpty() || !m_methodsText.isEmpty()) { + if (m_shape || (!suppressTextDisplay() && (!m_attributesText.isEmpty() || !m_methodsText.isEmpty()))) { if (!m_attributesSeparator) m_attributesSeparator = new QGraphicsLineItem(this); m_attributesSeparator->setPen(style->innerLinePen()); @@ -172,7 +172,7 @@ void ClassItem::update() } // attributes - if (!m_attributesText.isEmpty()) { + if (!suppressTextDisplay() && !m_attributesText.isEmpty()) { if (!m_attributes) m_attributes = new QGraphicsTextItem(this); m_attributes->setFont(style->normalFont()); @@ -186,7 +186,7 @@ void ClassItem::update() } // methods separator - if (m_shape || !m_attributesText.isEmpty() || !m_methodsText.isEmpty()) { + if (m_shape || (!suppressTextDisplay() && (!m_attributesText.isEmpty() || !m_methodsText.isEmpty()))) { if (!m_methodsSeparator) m_methodsSeparator = new QGraphicsLineItem(this); m_methodsSeparator->setPen(style->innerLinePen()); @@ -198,7 +198,7 @@ void ClassItem::update() } // methods - if (!m_methodsText.isEmpty()) { + if (!suppressTextDisplay() && !m_methodsText.isEmpty()) { if (!m_methods) m_methods = new QGraphicsTextItem(this); m_methods->setFont(style->normalFont()); diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp index 98aa69c5c3f..00ab655c259 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp +++ b/src/libs/modelinglib/qmt/diagram_scene/items/componentitem.cpp @@ -140,7 +140,7 @@ void ComponentItem::update() updateNameItem(style); // context - if (showContext()) { + if (!suppressTextDisplay() && showContext()) { if (!m_contextLabel) m_contextLabel = new ContextLabelItem(this); m_contextLabel->setFont(style->smallFont()); diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/itemitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/itemitem.cpp index dba8f7822fd..1837b63b576 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/itemitem.cpp +++ b/src/libs/modelinglib/qmt/diagram_scene/items/itemitem.cpp @@ -110,7 +110,7 @@ void ItemItem::update() updateNameItem(style); // context - if (showContext()) { + if (!suppressTextDisplay() && showContext()) { if (!m_contextLabel) m_contextLabel = new ContextLabelItem(this); m_contextLabel->setFont(style->smallFont()); diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp index 104d374ee8b..fac3e046d38 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp +++ b/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.cpp @@ -470,6 +470,7 @@ void ObjectItem::updateStereotypeIconDisplay() m_object->accept(&stereotypeDisplayVisitor); m_stereotypeIconId = stereotypeDisplayVisitor.stereotypeIconId(); m_shapeIconId = stereotypeDisplayVisitor.shapeIconId(); + m_shapeIcon = stereotypeDisplayVisitor.shapeIcon(); m_stereotypeIconDisplay = stereotypeDisplayVisitor.stereotypeIconDisplay(); } @@ -493,16 +494,16 @@ void ObjectItem::updateStereotypes(const QString &stereotypeIconId, StereotypeIc delete m_stereotypeIcon; m_stereotypeIcon = nullptr; } - if (stereotypeDisplay != StereotypeIcon::DisplayNone && !stereotypes.isEmpty()) { - if (!m_stereotypes) - m_stereotypes = new StereotypesItem(this); - m_stereotypes->setFont(style->smallFont()); - m_stereotypes->setBrush(style->textBrush()); - m_stereotypes->setStereotypes(stereotypes); - } else if (m_stereotypes) { - m_stereotypes->scene()->removeItem(m_stereotypes); - delete m_stereotypes; - m_stereotypes = nullptr; + if (stereotypeDisplay != StereotypeIcon::DisplayNone && !suppressTextDisplay() && !stereotypes.isEmpty()) { + if (!m_stereotypesItem) + m_stereotypesItem = new StereotypesItem(this); + m_stereotypesItem->setFont(style->smallFont()); + m_stereotypesItem->setBrush(style->textBrush()); + m_stereotypesItem->setStereotypes(stereotypes); + } else if (m_stereotypesItem) { + m_stereotypesItem->scene()->removeItem(m_stereotypesItem); + delete m_stereotypesItem; + m_stereotypesItem = nullptr; } } @@ -545,26 +546,37 @@ QSizeF ObjectItem::stereotypeIconMinimumSize(const StereotypeIcon &stereotypeIco return QSizeF(width, height); } +bool ObjectItem::suppressTextDisplay() const +{ + return m_shapeIcon.textAlignment() == StereotypeIcon::TextalignNone; +} + void ObjectItem::updateNameItem(const Style *style) { - if (!m_nameItem) { - m_nameItem = new EditableTextItem(this); - m_nameItem->setShowFocus(true); - m_nameItem->setFilterReturnKey(true); - m_nameItem->setFilterTabKey(true); - QObject::connect(m_nameItem->document(), &QTextDocument::contentsChanged, m_nameItem, - [=]() { this->setFromDisplayName(m_nameItem->toPlainText()); }); - QObject::connect(m_nameItem, &EditableTextItem::returnKeyPressed, m_nameItem, - [=]() { this->m_nameItem->clearFocus(); }); - } - if (style->headerFont() != m_nameItem->font()) - m_nameItem->setFont(style->headerFont()); - if (style->textBrush().color() != m_nameItem->defaultTextColor()) - m_nameItem->setDefaultTextColor(style->textBrush().color()); - if (!m_nameItem->hasFocus()) { - QString name = buildDisplayName(); - if (name != m_nameItem->toPlainText()) - m_nameItem->setPlainText(name); + if (!suppressTextDisplay()) { + if (!m_nameItem) { + m_nameItem = new EditableTextItem(this); + m_nameItem->setShowFocus(true); + m_nameItem->setFilterReturnKey(true); + m_nameItem->setFilterTabKey(true); + QObject::connect(m_nameItem->document(), &QTextDocument::contentsChanged, m_nameItem, + [=]() { this->setFromDisplayName(m_nameItem->toPlainText()); }); + QObject::connect(m_nameItem, &EditableTextItem::returnKeyPressed, m_nameItem, + [=]() { this->m_nameItem->clearFocus(); }); + } + if (style->headerFont() != m_nameItem->font()) + m_nameItem->setFont(style->headerFont()); + if (style->textBrush().color() != m_nameItem->defaultTextColor()) + m_nameItem->setDefaultTextColor(style->textBrush().color()); + if (!m_nameItem->hasFocus()) { + QString name = buildDisplayName(); + if (name != m_nameItem->toPlainText()) + m_nameItem->setPlainText(name); + } + } else if (m_nameItem ){ + m_nameItem->scene()->removeItem(m_nameItem); + delete m_nameItem; + m_nameItem = nullptr; } } diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.h b/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.h index 89bf89ea576..39fdee38656 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.h +++ b/src/libs/modelinglib/qmt/diagram_scene/items/objectitem.h @@ -136,13 +136,15 @@ protected: void updateStereotypeIconDisplay(); QString stereotypeIconId() const { return m_stereotypeIconId; } QString shapeIconId() const { return m_shapeIconId; } + StereotypeIcon shapeIcon() const { return m_shapeIcon; } StereotypeIcon::Display stereotypeIconDisplay() const { return m_stereotypeIconDisplay; } void updateStereotypes(const QString &stereotypeIconId, StereotypeIcon::Display stereotypeDisplay, const Style *style); - StereotypesItem *stereotypesItem() const { return m_stereotypes; } + StereotypesItem *stereotypesItem() const { return m_stereotypesItem; } CustomIconItem *stereotypeIconItem() const { return m_stereotypeIcon; } QSizeF stereotypeIconMinimumSize(const StereotypeIcon &stereotypeIcon, qreal minimumWidth, qreal minimumHeight) const; + bool suppressTextDisplay() const; void updateNameItem(const Style *style); EditableTextItem *nameItem() const { return m_nameItem; } virtual QString buildDisplayName() const; @@ -185,8 +187,9 @@ private: bool m_isFocusSelected = false; QString m_stereotypeIconId; QString m_shapeIconId; + StereotypeIcon m_shapeIcon; StereotypeIcon::Display m_stereotypeIconDisplay = StereotypeIcon::DisplayLabel; - StereotypesItem *m_stereotypes = nullptr; + StereotypesItem *m_stereotypesItem = nullptr; CustomIconItem *m_stereotypeIcon = nullptr; EditableTextItem *m_nameItem = nullptr; RectangularSelectionItem *m_selectionMarker = nullptr; diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp index 97ff26f00ad..3b61e4e5493 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp +++ b/src/libs/modelinglib/qmt/diagram_scene/items/packageitem.cpp @@ -121,7 +121,7 @@ void PackageItem::update() updateNameItem(style); // context - if (showContext()) { + if (!suppressTextDisplay() && showContext()) { if (!m_contextLabel) m_contextLabel = new ContextLabelItem(this); m_contextLabel->setFont(style->smallFont()); diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/relationitem.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/relationitem.cpp index 6904bc2a041..c383a21a329 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/relationitem.cpp +++ b/src/libs/modelinglib/qmt/diagram_scene/items/relationitem.cpp @@ -80,7 +80,7 @@ public: stereotypeDisplayVisitor.setModelController(m_diagramSceneModel->diagramSceneController()->modelController()); stereotypeDisplayVisitor.setStereotypeController(m_diagramSceneModel->stereotypeController()); baseObject->accept(&stereotypeDisplayVisitor); - lollipopDisplay = stereotypeDisplayVisitor.stereotypeDisplay() == DObject::StereotypeIcon; + lollipopDisplay = stereotypeDisplayVisitor.stereotypeIconDisplay() == StereotypeIcon::DisplayIcon; } } if (lollipopDisplay) { diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/stereotypedisplayvisitor.cpp b/src/libs/modelinglib/qmt/diagram_scene/items/stereotypedisplayvisitor.cpp index dae666a3eb5..0fdb273c0b4 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/stereotypedisplayvisitor.cpp +++ b/src/libs/modelinglib/qmt/diagram_scene/items/stereotypedisplayvisitor.cpp @@ -114,6 +114,7 @@ void StereotypeDisplayVisitor::visitDPackage(const DPackage *package) m_stereotypeIconElement = StereotypeIcon::ElementPackage; m_stereotypeSmartDisplay = DObject::StereotypeDecoration; visitDObject(package); + updateShapeIcon(); } void StereotypeDisplayVisitor::visitDClass(const DClass *klass) @@ -125,6 +126,7 @@ void StereotypeDisplayVisitor::visitDClass(const DClass *klass) hasMembers = true; m_stereotypeSmartDisplay = hasMembers ? DObject::StereotypeDecoration : DObject::StereotypeIcon; visitDObject(klass); + updateShapeIcon(); } void StereotypeDisplayVisitor::visitDComponent(const DComponent *component) @@ -132,6 +134,7 @@ void StereotypeDisplayVisitor::visitDComponent(const DComponent *component) m_stereotypeIconElement = StereotypeIcon::ElementComponent; m_stereotypeSmartDisplay = DObject::StereotypeIcon; visitDObject(component); + updateShapeIcon(); } void StereotypeDisplayVisitor::visitDDiagram(const DDiagram *diagram) @@ -139,6 +142,7 @@ void StereotypeDisplayVisitor::visitDDiagram(const DDiagram *diagram) m_stereotypeIconElement = StereotypeIcon::ElementDiagram; m_stereotypeSmartDisplay = DObject::StereotypeDecoration; visitDObject(diagram); + updateShapeIcon(); } void StereotypeDisplayVisitor::visitDItem(const DItem *item) @@ -150,6 +154,15 @@ void StereotypeDisplayVisitor::visitDItem(const DItem *item) m_stereotypeIconId = m_stereotypeController->findStereotypeIconId(StereotypeIcon::ElementItem, QStringList(item->shape())); if (m_shapeIconId.isEmpty() && !item->variety().isEmpty()) m_shapeIconId = m_stereotypeController->findStereotypeIconId(StereotypeIcon::ElementItem, QStringList(item->variety())); + updateShapeIcon(); +} + +void StereotypeDisplayVisitor::updateShapeIcon() +{ + if (!m_shapeIconId.isEmpty()) + m_shapeIcon = m_stereotypeController->findStereotypeIcon(m_shapeIconId); + else if (!m_stereotypeIconId.isEmpty()) + m_shapeIcon = m_stereotypeController->findStereotypeIcon(m_stereotypeIconId); } } // namespace qmt diff --git a/src/libs/modelinglib/qmt/diagram_scene/items/stereotypedisplayvisitor.h b/src/libs/modelinglib/qmt/diagram_scene/items/stereotypedisplayvisitor.h index feb83c07520..81034c0fdf5 100644 --- a/src/libs/modelinglib/qmt/diagram_scene/items/stereotypedisplayvisitor.h +++ b/src/libs/modelinglib/qmt/diagram_scene/items/stereotypedisplayvisitor.h @@ -43,10 +43,10 @@ public: void setModelController(ModelController *modelController); void setStereotypeController(StereotypeController *stereotypeController); - DObject::StereotypeDisplay stereotypeDisplay() const { return m_stereotypeDisplay; } StereotypeIcon::Display stereotypeIconDisplay() const; QString stereotypeIconId() const { return m_stereotypeIconId; } QString shapeIconId() const { return m_shapeIconId; } + StereotypeIcon shapeIcon() const { return m_shapeIcon; } void visitDObject(const DObject *object) override; void visitDPackage(const DPackage *package) override; @@ -56,11 +56,14 @@ public: void visitDItem(const DItem *item) override; private: + void updateShapeIcon(); + ModelController *m_modelController = nullptr; StereotypeController *m_stereotypeController = nullptr; DObject::StereotypeDisplay m_stereotypeDisplay = DObject::StereotypeNone; QString m_stereotypeIconId; QString m_shapeIconId; + StereotypeIcon m_shapeIcon; StereotypeIcon::Element m_stereotypeIconElement = StereotypeIcon::ElementAny; DObject::StereotypeDisplay m_stereotypeSmartDisplay = DObject::StereotypeDecoration; }; diff --git a/src/libs/modelinglib/qmt/stereotype/stereotypeicon.cpp b/src/libs/modelinglib/qmt/stereotype/stereotypeicon.cpp index d3cc9d606bb..d11cace46bc 100644 --- a/src/libs/modelinglib/qmt/stereotype/stereotypeicon.cpp +++ b/src/libs/modelinglib/qmt/stereotype/stereotypeicon.cpp @@ -54,6 +54,16 @@ void StereotypeIcon::setStereotypes(const QSet &stereotypes) m_stereotypes = stereotypes; } +void StereotypeIcon::setHasName(bool hasName) +{ + m_hasName = hasName; +} + +void StereotypeIcon::setName(const QString &name) +{ + m_name = name; +} + void StereotypeIcon::setWidth(qreal width) { m_width = width; diff --git a/src/libs/modelinglib/qmt/stereotype/stereotypeicon.h b/src/libs/modelinglib/qmt/stereotype/stereotypeicon.h index acdeb3f07e8..4465734cfdd 100644 --- a/src/libs/modelinglib/qmt/stereotype/stereotypeicon.h +++ b/src/libs/modelinglib/qmt/stereotype/stereotypeicon.h @@ -64,7 +64,8 @@ public: enum TextAlignment { TextalignBelow, TextalignCenter, - TextalignNone + TextalignNone, + TextalignTop }; QString id() const { return m_id; } @@ -75,6 +76,10 @@ public: void setElements(const QSet &elements); QSet stereotypes() const { return m_stereotypes; } void setStereotypes(const QSet &stereotypes); + bool hasName() const { return m_hasName; } + void setHasName(bool hasName); + QString name() const { return m_name; } + void setName(const QString &name); qreal width() const { return m_width; } void setWidth(qreal width); qreal height() const { return m_height; } @@ -101,6 +106,8 @@ private: QString m_title; QSet m_elements; QSet m_stereotypes; + bool m_hasName = false; + QString m_name; qreal m_width = 100.0; qreal m_height = 100.0; qreal m_minWidth = -1; diff --git a/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp b/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp index 3ae964bbcfb..246b5a18c6c 100644 --- a/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp +++ b/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp @@ -397,28 +397,23 @@ void DiagramSceneController::dropNewElement(const QString &newElementId, const Q } else { MPackage *parentPackage = findSuitableParentPackage(topMostElementAtPos, diagram); MObject *newObject = nullptr; - QString newName; if (newElementId == QLatin1String(ELEMENT_TYPE_PACKAGE)) { auto package = new MPackage(); - newName = tr("New Package"); if (!stereotype.isEmpty()) package->setStereotypes({stereotype}); newObject = package; } else if (newElementId == QLatin1String(ELEMENT_TYPE_COMPONENT)) { auto component = new MComponent(); - newName = tr("New Component"); if (!stereotype.isEmpty()) component->setStereotypes({stereotype}); newObject = component; } else if (newElementId == QLatin1String(ELEMENT_TYPE_CLASS)) { auto klass = new MClass(); - newName = tr("New Class"); if (!stereotype.isEmpty()) klass->setStereotypes({stereotype}); newObject = klass; } else if (newElementId == QLatin1String(ELEMENT_TYPE_ITEM)) { auto item = new MItem(); - newName = tr("New Item"); if (!stereotype.isEmpty()) { item->setVariety(stereotype); item->setVarietyEditable(false); @@ -426,9 +421,7 @@ void DiagramSceneController::dropNewElement(const QString &newElementId, const Q newObject = item; } if (newObject) { - if (!name.isEmpty()) - newName = tr("New %1").arg(name); - newObject->setName(newName); + newObject->setName(name); dropNewModelElement(newObject, parentPackage, pos, diagram); } } diff --git a/src/plugins/modeleditor/dragtool.cpp b/src/plugins/modeleditor/dragtool.cpp index 657d1101077..2e343e37213 100644 --- a/src/plugins/modeleditor/dragtool.cpp +++ b/src/plugins/modeleditor/dragtool.cpp @@ -41,13 +41,14 @@ public: QIcon icon; QSize iconSize; QString title; + QString newElementName; QString newElementId; QString stereotype; bool disableFrame = false; bool framePainted = false; }; -DragTool::DragTool(const QIcon &icon, const QString &title, const QString &newElementId, +DragTool::DragTool(const QIcon &icon, const QString &title, const QString &newElementName, const QString &newElementId, const QString &stereotype, QWidget *parent) : QWidget(parent), d(new DragToolPrivate) @@ -55,6 +56,7 @@ DragTool::DragTool(const QIcon &icon, const QString &title, const QString &newEl d->icon = icon; d->iconSize = QSize(32, 32); d->title = title; + d->newElementName = newElementName; d->newElementId = newElementId; d->stereotype = stereotype; QMargins margins = contentsMargins(); @@ -144,7 +146,7 @@ void DragTool::mousePressEvent(QMouseEvent *event) auto mimeData = new QMimeData; QByteArray data; QDataStream dataStream(&data, QIODevice::WriteOnly); - dataStream << d->newElementId << d->title << d->stereotype; + dataStream << d->newElementId << d->newElementName << d->stereotype; mimeData->setData(QLatin1String(qmt::MIME_TYPE_NEW_MODEL_ELEMENTS), data); drag->setMimeData(mimeData); diff --git a/src/plugins/modeleditor/dragtool.h b/src/plugins/modeleditor/dragtool.h index 844b8189c2b..4de18b195bd 100644 --- a/src/plugins/modeleditor/dragtool.h +++ b/src/plugins/modeleditor/dragtool.h @@ -38,8 +38,8 @@ class DragTool : class DragToolPrivate; public: - DragTool(const QIcon &icon, const QString &title, const QString &newElementId, - const QString &stereotype, QWidget *parent = nullptr); + DragTool(const QIcon &icon, const QString &title, const QString &newElementName, + const QString &newElementId, const QString &stereotype, QWidget *parent = nullptr); ~DragTool(); QSize sizeHint() const override; diff --git a/src/plugins/modeleditor/modeleditor.cpp b/src/plugins/modeleditor/modeleditor.cpp index 9602c72c153..9d92d6f1904 100644 --- a/src/plugins/modeleditor/modeleditor.cpp +++ b/src/plugins/modeleditor/modeleditor.cpp @@ -1051,16 +1051,24 @@ void ModelEditor::initToolbars() styleEngineElementType = qmt::StyleEngine::TypeSwimlane; } QIcon icon; + QString newElementName = tr("New %1").arg(tool.m_name); if (!tool.m_stereotype.isEmpty() && stereotypeIconElement != qmt::StereotypeIcon::ElementAny) { const qmt::Style *style = documentController->styleController()->adaptStyle(styleEngineElementType); icon = stereotypeController->createIcon( stereotypeIconElement, QStringList() << tool.m_stereotype, QString(), style, QSize(48, 48), QMarginsF(3.0, 2.0, 3.0, 4.0)); + if (!icon.isNull()) { + QString stereotypeIconId = stereotypeController->findStereotypeIconId( + stereotypeIconElement, QStringList() << tool.m_stereotype); + qmt::StereotypeIcon stereotypeIcon = stereotypeController->findStereotypeIcon(stereotypeIconId); + if (stereotypeIcon.hasName()) + newElementName = stereotypeIcon.name(); + } } if (icon.isNull()) icon = QIcon(iconPath); if (!icon.isNull()) { - toolBarLayout->addWidget(new DragTool(icon, tool.m_name, tool.m_elementType, + toolBarLayout->addWidget(new DragTool(icon, tool.m_name, newElementName, tool.m_elementType, tool.m_stereotype, toolBar)); } break; @@ -1088,34 +1096,34 @@ void ModelEditor::initToolbars() toolBars.insert(generalId, toolBar); toolBarLayout->addWidget( new DragTool(QIcon(":/modelinglib/48x48/package.png"), - tr("Package"), QLatin1String(qmt::ELEMENT_TYPE_PACKAGE), + tr("Package"), tr("New Package"), QLatin1String(qmt::ELEMENT_TYPE_PACKAGE), QString(), toolBar)); toolBarLayout->addWidget( new DragTool(QIcon(":/modelinglib/48x48/component.png"), - tr("Component"), QLatin1String(qmt::ELEMENT_TYPE_COMPONENT), + tr("Component"), tr("New Component"), QLatin1String(qmt::ELEMENT_TYPE_COMPONENT), QString(), toolBar)); toolBarLayout->addWidget( new DragTool(QIcon(":/modelinglib/48x48/class.png"), - tr("Class"), QLatin1String(qmt::ELEMENT_TYPE_CLASS), + tr("Class"), tr("New Class"), QLatin1String(qmt::ELEMENT_TYPE_CLASS), QString(), toolBar)); toolBarLayout->addWidget( new DragTool(QIcon(":/modelinglib/48x48/item.png"), - tr("Item"), QLatin1String(qmt::ELEMENT_TYPE_ITEM), + tr("Item"), tr("New Item"), QLatin1String(qmt::ELEMENT_TYPE_ITEM), QString(), toolBar)); auto horizLine1 = new QFrame(d->leftToolBox); horizLine1->setFrameShape(QFrame::HLine); toolBarLayout->addWidget(horizLine1); toolBarLayout->addWidget( new DragTool(QIcon(":/modelinglib/48x48/annotation.png"), - tr("Annotation"), QLatin1String(qmt::ELEMENT_TYPE_ANNOTATION), + tr("Annotation"), QString(), QLatin1String(qmt::ELEMENT_TYPE_ANNOTATION), QString(), toolBar)); toolBarLayout->addWidget( new DragTool(QIcon(":/modelinglib/48x48/boundary.png"), - tr("Boundary"), QLatin1String(qmt::ELEMENT_TYPE_BOUNDARY), + tr("Boundary"), QString(), QLatin1String(qmt::ELEMENT_TYPE_BOUNDARY), QString(), toolBar)); toolBarLayout->addWidget( new DragTool(QIcon(":/modelinglib/48x48/swimlane.png"), - tr("Swimlane"), QLatin1String(qmt::ELEMENT_TYPE_SWIMLANE), + tr("Swimlane"), QString(), QLatin1String(qmt::ELEMENT_TYPE_SWIMLANE), QString(), toolBar)); }