forked from qt-creator/qt-creator
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 <tobias.hunger@qt.io>
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
// display: <default display of element.
|
// display: <default display of element.
|
||||||
// One of: none, label, decoration, icon, smart.
|
// One of: none, label, decoration, icon, smart.
|
||||||
// Default is smart.>
|
// Default is smart.>
|
||||||
|
// name: <Name of new element. Defaults to "New <Toolbar entry title>".>
|
||||||
// width: <width of icon in pixels. The width defines the width of the icon as decoration.>
|
// width: <width of icon in pixels. The width defines the width of the icon as decoration.>
|
||||||
// height: <height of icon in pixels. The height defines the height of the icon as decoration.>
|
// height: <height of icon in pixels. The height defines the height of the icon as decoration.>
|
||||||
// minwidth: <minimum width of custom icon in pixels.>
|
// minwidth: <minimum width of custom icon in pixels.>
|
||||||
@@ -22,9 +23,9 @@
|
|||||||
// lockSize: <lock resizing.
|
// lockSize: <lock resizing.
|
||||||
// One of: none, width, height, size, ratio.
|
// One of: none, width, height, size, ratio.
|
||||||
// Default is none.>
|
// Default is none.>
|
||||||
// textAlignment: <alignment of text.
|
// textAlignment: <alignment of text (stereotype label, name and context).
|
||||||
// One of: top, center, below.
|
// One of: top, center, below, none.
|
||||||
// Defaults to center.>
|
// Defaults to below. None means no text will be displayed>
|
||||||
// baseColor: <color #rrggbb>
|
// baseColor: <color #rrggbb>
|
||||||
// Shape {
|
// Shape {
|
||||||
// Line { x1: <x1>; y1: <y1>; x2:<x2>; y2: <y2> }
|
// Line { x1: <x1>; y1: <y1>; x2:<x2>; y2: <y2> }
|
||||||
@@ -345,6 +346,8 @@ Icon {
|
|||||||
elements: item
|
elements: item
|
||||||
stereotype: 'start'
|
stereotype: 'start'
|
||||||
display: icon
|
display: icon
|
||||||
|
name: ""
|
||||||
|
textAlignment: none
|
||||||
width: 20
|
width: 20
|
||||||
height: 20
|
height: 20
|
||||||
lockSize: ratio
|
lockSize: ratio
|
||||||
@@ -391,6 +394,8 @@ Icon {
|
|||||||
elements: item
|
elements: item
|
||||||
stereotype: 'horizontalbar'
|
stereotype: 'horizontalbar'
|
||||||
display: icon
|
display: icon
|
||||||
|
name: ""
|
||||||
|
textAlignment: none
|
||||||
width: 20
|
width: 20
|
||||||
height: 5
|
height: 5
|
||||||
minWidth: 20
|
minWidth: 20
|
||||||
@@ -408,6 +413,8 @@ Icon {
|
|||||||
elements: item
|
elements: item
|
||||||
stereotype: 'verticalbar'
|
stereotype: 'verticalbar'
|
||||||
display: icon
|
display: icon
|
||||||
|
name: ""
|
||||||
|
textAlignment: none
|
||||||
width: 5
|
width: 5
|
||||||
height: 20
|
height: 20
|
||||||
minWidth: 5
|
minWidth: 5
|
||||||
@@ -424,6 +431,8 @@ Icon {
|
|||||||
elements: item
|
elements: item
|
||||||
stereotype: 'termination'
|
stereotype: 'termination'
|
||||||
display: icon
|
display: icon
|
||||||
|
name: ""
|
||||||
|
textAlignment: none
|
||||||
width: 20
|
width: 20
|
||||||
height: 20
|
height: 20
|
||||||
lockSize: ratio
|
lockSize: ratio
|
||||||
|
@@ -424,7 +424,8 @@ void StereotypeDefinitionParser::parseIcon()
|
|||||||
const static QHash<QString, StereotypeIcon::TextAlignment> alignNames = QHash<QString, StereotypeIcon::TextAlignment>()
|
const static QHash<QString, StereotypeIcon::TextAlignment> alignNames = QHash<QString, StereotypeIcon::TextAlignment>()
|
||||||
<< qMakePair(QString("below"), StereotypeIcon::TextalignBelow)
|
<< qMakePair(QString("below"), StereotypeIcon::TextalignBelow)
|
||||||
<< qMakePair(QString("center"), StereotypeIcon::TextalignCenter)
|
<< qMakePair(QString("center"), StereotypeIcon::TextalignCenter)
|
||||||
<< qMakePair(QString("none"), StereotypeIcon::TextalignNone);
|
<< qMakePair(QString("none"), StereotypeIcon::TextalignNone)
|
||||||
|
<< qMakePair(QString("top"), StereotypeIcon::TextalignTop);
|
||||||
parseEnum<StereotypeIcon::TextAlignment>(
|
parseEnum<StereotypeIcon::TextAlignment>(
|
||||||
parseIdentifierProperty(), alignNames, token.sourcePos(),
|
parseIdentifierProperty(), alignNames, token.sourcePos(),
|
||||||
[&](StereotypeIcon::TextAlignment align) { stereotypeIcon.setTextAlignment(align); });
|
[&](StereotypeIcon::TextAlignment align) { stereotypeIcon.setTextAlignment(align); });
|
||||||
@@ -436,6 +437,10 @@ void StereotypeDefinitionParser::parseIcon()
|
|||||||
case KEYWORD_SHAPE:
|
case KEYWORD_SHAPE:
|
||||||
stereotypeIcon.setIconShape(parseIconShape());
|
stereotypeIcon.setIconShape(parseIconShape());
|
||||||
break;
|
break;
|
||||||
|
case KEYWORD_NAME:
|
||||||
|
stereotypeIcon.setName(parseStringProperty());
|
||||||
|
stereotypeIcon.setHasName(true);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throwUnknownPropertyError(token);
|
throwUnknownPropertyError(token);
|
||||||
}
|
}
|
||||||
|
@@ -131,7 +131,7 @@ void ClassItem::update()
|
|||||||
updateStereotypes(stereotypeIconId(), stereotypeIconDisplay(), style);
|
updateStereotypes(stereotypeIconId(), stereotypeIconDisplay(), style);
|
||||||
|
|
||||||
// namespace
|
// namespace
|
||||||
if (!diagramClass->umlNamespace().isEmpty()) {
|
if (!suppressTextDisplay() && !diagramClass->umlNamespace().isEmpty()) {
|
||||||
if (!m_namespace)
|
if (!m_namespace)
|
||||||
m_namespace = new QGraphicsSimpleTextItem(this);
|
m_namespace = new QGraphicsSimpleTextItem(this);
|
||||||
m_namespace->setFont(style->smallFont());
|
m_namespace->setFont(style->smallFont());
|
||||||
@@ -147,7 +147,7 @@ void ClassItem::update()
|
|||||||
updateNameItem(style);
|
updateNameItem(style);
|
||||||
|
|
||||||
// context
|
// context
|
||||||
if (showContext()) {
|
if (!suppressTextDisplay() && showContext()) {
|
||||||
if (!m_contextLabel)
|
if (!m_contextLabel)
|
||||||
m_contextLabel = new ContextLabelItem(this);
|
m_contextLabel = new ContextLabelItem(this);
|
||||||
m_contextLabel->setFont(style->smallFont());
|
m_contextLabel->setFont(style->smallFont());
|
||||||
@@ -160,7 +160,7 @@ void ClassItem::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// attributes separator
|
// attributes separator
|
||||||
if (m_shape || !m_attributesText.isEmpty() || !m_methodsText.isEmpty()) {
|
if (m_shape || (!suppressTextDisplay() && (!m_attributesText.isEmpty() || !m_methodsText.isEmpty()))) {
|
||||||
if (!m_attributesSeparator)
|
if (!m_attributesSeparator)
|
||||||
m_attributesSeparator = new QGraphicsLineItem(this);
|
m_attributesSeparator = new QGraphicsLineItem(this);
|
||||||
m_attributesSeparator->setPen(style->innerLinePen());
|
m_attributesSeparator->setPen(style->innerLinePen());
|
||||||
@@ -172,7 +172,7 @@ void ClassItem::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
if (!m_attributesText.isEmpty()) {
|
if (!suppressTextDisplay() && !m_attributesText.isEmpty()) {
|
||||||
if (!m_attributes)
|
if (!m_attributes)
|
||||||
m_attributes = new QGraphicsTextItem(this);
|
m_attributes = new QGraphicsTextItem(this);
|
||||||
m_attributes->setFont(style->normalFont());
|
m_attributes->setFont(style->normalFont());
|
||||||
@@ -186,7 +186,7 @@ void ClassItem::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// methods separator
|
// methods separator
|
||||||
if (m_shape || !m_attributesText.isEmpty() || !m_methodsText.isEmpty()) {
|
if (m_shape || (!suppressTextDisplay() && (!m_attributesText.isEmpty() || !m_methodsText.isEmpty()))) {
|
||||||
if (!m_methodsSeparator)
|
if (!m_methodsSeparator)
|
||||||
m_methodsSeparator = new QGraphicsLineItem(this);
|
m_methodsSeparator = new QGraphicsLineItem(this);
|
||||||
m_methodsSeparator->setPen(style->innerLinePen());
|
m_methodsSeparator->setPen(style->innerLinePen());
|
||||||
@@ -198,7 +198,7 @@ void ClassItem::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
if (!m_methodsText.isEmpty()) {
|
if (!suppressTextDisplay() && !m_methodsText.isEmpty()) {
|
||||||
if (!m_methods)
|
if (!m_methods)
|
||||||
m_methods = new QGraphicsTextItem(this);
|
m_methods = new QGraphicsTextItem(this);
|
||||||
m_methods->setFont(style->normalFont());
|
m_methods->setFont(style->normalFont());
|
||||||
|
@@ -140,7 +140,7 @@ void ComponentItem::update()
|
|||||||
updateNameItem(style);
|
updateNameItem(style);
|
||||||
|
|
||||||
// context
|
// context
|
||||||
if (showContext()) {
|
if (!suppressTextDisplay() && showContext()) {
|
||||||
if (!m_contextLabel)
|
if (!m_contextLabel)
|
||||||
m_contextLabel = new ContextLabelItem(this);
|
m_contextLabel = new ContextLabelItem(this);
|
||||||
m_contextLabel->setFont(style->smallFont());
|
m_contextLabel->setFont(style->smallFont());
|
||||||
|
@@ -110,7 +110,7 @@ void ItemItem::update()
|
|||||||
updateNameItem(style);
|
updateNameItem(style);
|
||||||
|
|
||||||
// context
|
// context
|
||||||
if (showContext()) {
|
if (!suppressTextDisplay() && showContext()) {
|
||||||
if (!m_contextLabel)
|
if (!m_contextLabel)
|
||||||
m_contextLabel = new ContextLabelItem(this);
|
m_contextLabel = new ContextLabelItem(this);
|
||||||
m_contextLabel->setFont(style->smallFont());
|
m_contextLabel->setFont(style->smallFont());
|
||||||
|
@@ -470,6 +470,7 @@ void ObjectItem::updateStereotypeIconDisplay()
|
|||||||
m_object->accept(&stereotypeDisplayVisitor);
|
m_object->accept(&stereotypeDisplayVisitor);
|
||||||
m_stereotypeIconId = stereotypeDisplayVisitor.stereotypeIconId();
|
m_stereotypeIconId = stereotypeDisplayVisitor.stereotypeIconId();
|
||||||
m_shapeIconId = stereotypeDisplayVisitor.shapeIconId();
|
m_shapeIconId = stereotypeDisplayVisitor.shapeIconId();
|
||||||
|
m_shapeIcon = stereotypeDisplayVisitor.shapeIcon();
|
||||||
m_stereotypeIconDisplay = stereotypeDisplayVisitor.stereotypeIconDisplay();
|
m_stereotypeIconDisplay = stereotypeDisplayVisitor.stereotypeIconDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,16 +494,16 @@ void ObjectItem::updateStereotypes(const QString &stereotypeIconId, StereotypeIc
|
|||||||
delete m_stereotypeIcon;
|
delete m_stereotypeIcon;
|
||||||
m_stereotypeIcon = nullptr;
|
m_stereotypeIcon = nullptr;
|
||||||
}
|
}
|
||||||
if (stereotypeDisplay != StereotypeIcon::DisplayNone && !stereotypes.isEmpty()) {
|
if (stereotypeDisplay != StereotypeIcon::DisplayNone && !suppressTextDisplay() && !stereotypes.isEmpty()) {
|
||||||
if (!m_stereotypes)
|
if (!m_stereotypesItem)
|
||||||
m_stereotypes = new StereotypesItem(this);
|
m_stereotypesItem = new StereotypesItem(this);
|
||||||
m_stereotypes->setFont(style->smallFont());
|
m_stereotypesItem->setFont(style->smallFont());
|
||||||
m_stereotypes->setBrush(style->textBrush());
|
m_stereotypesItem->setBrush(style->textBrush());
|
||||||
m_stereotypes->setStereotypes(stereotypes);
|
m_stereotypesItem->setStereotypes(stereotypes);
|
||||||
} else if (m_stereotypes) {
|
} else if (m_stereotypesItem) {
|
||||||
m_stereotypes->scene()->removeItem(m_stereotypes);
|
m_stereotypesItem->scene()->removeItem(m_stereotypesItem);
|
||||||
delete m_stereotypes;
|
delete m_stereotypesItem;
|
||||||
m_stereotypes = nullptr;
|
m_stereotypesItem = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,8 +546,14 @@ QSizeF ObjectItem::stereotypeIconMinimumSize(const StereotypeIcon &stereotypeIco
|
|||||||
return QSizeF(width, height);
|
return QSizeF(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ObjectItem::suppressTextDisplay() const
|
||||||
|
{
|
||||||
|
return m_shapeIcon.textAlignment() == StereotypeIcon::TextalignNone;
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectItem::updateNameItem(const Style *style)
|
void ObjectItem::updateNameItem(const Style *style)
|
||||||
{
|
{
|
||||||
|
if (!suppressTextDisplay()) {
|
||||||
if (!m_nameItem) {
|
if (!m_nameItem) {
|
||||||
m_nameItem = new EditableTextItem(this);
|
m_nameItem = new EditableTextItem(this);
|
||||||
m_nameItem->setShowFocus(true);
|
m_nameItem->setShowFocus(true);
|
||||||
@@ -566,6 +573,11 @@ void ObjectItem::updateNameItem(const Style *style)
|
|||||||
if (name != m_nameItem->toPlainText())
|
if (name != m_nameItem->toPlainText())
|
||||||
m_nameItem->setPlainText(name);
|
m_nameItem->setPlainText(name);
|
||||||
}
|
}
|
||||||
|
} else if (m_nameItem ){
|
||||||
|
m_nameItem->scene()->removeItem(m_nameItem);
|
||||||
|
delete m_nameItem;
|
||||||
|
m_nameItem = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ObjectItem::buildDisplayName() const
|
QString ObjectItem::buildDisplayName() const
|
||||||
|
@@ -136,13 +136,15 @@ protected:
|
|||||||
void updateStereotypeIconDisplay();
|
void updateStereotypeIconDisplay();
|
||||||
QString stereotypeIconId() const { return m_stereotypeIconId; }
|
QString stereotypeIconId() const { return m_stereotypeIconId; }
|
||||||
QString shapeIconId() const { return m_shapeIconId; }
|
QString shapeIconId() const { return m_shapeIconId; }
|
||||||
|
StereotypeIcon shapeIcon() const { return m_shapeIcon; }
|
||||||
StereotypeIcon::Display stereotypeIconDisplay() const { return m_stereotypeIconDisplay; }
|
StereotypeIcon::Display stereotypeIconDisplay() const { return m_stereotypeIconDisplay; }
|
||||||
void updateStereotypes(const QString &stereotypeIconId,
|
void updateStereotypes(const QString &stereotypeIconId,
|
||||||
StereotypeIcon::Display stereotypeDisplay, const Style *style);
|
StereotypeIcon::Display stereotypeDisplay, const Style *style);
|
||||||
StereotypesItem *stereotypesItem() const { return m_stereotypes; }
|
StereotypesItem *stereotypesItem() const { return m_stereotypesItem; }
|
||||||
CustomIconItem *stereotypeIconItem() const { return m_stereotypeIcon; }
|
CustomIconItem *stereotypeIconItem() const { return m_stereotypeIcon; }
|
||||||
QSizeF stereotypeIconMinimumSize(const StereotypeIcon &stereotypeIcon, qreal minimumWidth,
|
QSizeF stereotypeIconMinimumSize(const StereotypeIcon &stereotypeIcon, qreal minimumWidth,
|
||||||
qreal minimumHeight) const;
|
qreal minimumHeight) const;
|
||||||
|
bool suppressTextDisplay() const;
|
||||||
void updateNameItem(const Style *style);
|
void updateNameItem(const Style *style);
|
||||||
EditableTextItem *nameItem() const { return m_nameItem; }
|
EditableTextItem *nameItem() const { return m_nameItem; }
|
||||||
virtual QString buildDisplayName() const;
|
virtual QString buildDisplayName() const;
|
||||||
@@ -185,8 +187,9 @@ private:
|
|||||||
bool m_isFocusSelected = false;
|
bool m_isFocusSelected = false;
|
||||||
QString m_stereotypeIconId;
|
QString m_stereotypeIconId;
|
||||||
QString m_shapeIconId;
|
QString m_shapeIconId;
|
||||||
|
StereotypeIcon m_shapeIcon;
|
||||||
StereotypeIcon::Display m_stereotypeIconDisplay = StereotypeIcon::DisplayLabel;
|
StereotypeIcon::Display m_stereotypeIconDisplay = StereotypeIcon::DisplayLabel;
|
||||||
StereotypesItem *m_stereotypes = nullptr;
|
StereotypesItem *m_stereotypesItem = nullptr;
|
||||||
CustomIconItem *m_stereotypeIcon = nullptr;
|
CustomIconItem *m_stereotypeIcon = nullptr;
|
||||||
EditableTextItem *m_nameItem = nullptr;
|
EditableTextItem *m_nameItem = nullptr;
|
||||||
RectangularSelectionItem *m_selectionMarker = nullptr;
|
RectangularSelectionItem *m_selectionMarker = nullptr;
|
||||||
|
@@ -121,7 +121,7 @@ void PackageItem::update()
|
|||||||
updateNameItem(style);
|
updateNameItem(style);
|
||||||
|
|
||||||
// context
|
// context
|
||||||
if (showContext()) {
|
if (!suppressTextDisplay() && showContext()) {
|
||||||
if (!m_contextLabel)
|
if (!m_contextLabel)
|
||||||
m_contextLabel = new ContextLabelItem(this);
|
m_contextLabel = new ContextLabelItem(this);
|
||||||
m_contextLabel->setFont(style->smallFont());
|
m_contextLabel->setFont(style->smallFont());
|
||||||
|
@@ -80,7 +80,7 @@ public:
|
|||||||
stereotypeDisplayVisitor.setModelController(m_diagramSceneModel->diagramSceneController()->modelController());
|
stereotypeDisplayVisitor.setModelController(m_diagramSceneModel->diagramSceneController()->modelController());
|
||||||
stereotypeDisplayVisitor.setStereotypeController(m_diagramSceneModel->stereotypeController());
|
stereotypeDisplayVisitor.setStereotypeController(m_diagramSceneModel->stereotypeController());
|
||||||
baseObject->accept(&stereotypeDisplayVisitor);
|
baseObject->accept(&stereotypeDisplayVisitor);
|
||||||
lollipopDisplay = stereotypeDisplayVisitor.stereotypeDisplay() == DObject::StereotypeIcon;
|
lollipopDisplay = stereotypeDisplayVisitor.stereotypeIconDisplay() == StereotypeIcon::DisplayIcon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lollipopDisplay) {
|
if (lollipopDisplay) {
|
||||||
|
@@ -114,6 +114,7 @@ void StereotypeDisplayVisitor::visitDPackage(const DPackage *package)
|
|||||||
m_stereotypeIconElement = StereotypeIcon::ElementPackage;
|
m_stereotypeIconElement = StereotypeIcon::ElementPackage;
|
||||||
m_stereotypeSmartDisplay = DObject::StereotypeDecoration;
|
m_stereotypeSmartDisplay = DObject::StereotypeDecoration;
|
||||||
visitDObject(package);
|
visitDObject(package);
|
||||||
|
updateShapeIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StereotypeDisplayVisitor::visitDClass(const DClass *klass)
|
void StereotypeDisplayVisitor::visitDClass(const DClass *klass)
|
||||||
@@ -125,6 +126,7 @@ void StereotypeDisplayVisitor::visitDClass(const DClass *klass)
|
|||||||
hasMembers = true;
|
hasMembers = true;
|
||||||
m_stereotypeSmartDisplay = hasMembers ? DObject::StereotypeDecoration : DObject::StereotypeIcon;
|
m_stereotypeSmartDisplay = hasMembers ? DObject::StereotypeDecoration : DObject::StereotypeIcon;
|
||||||
visitDObject(klass);
|
visitDObject(klass);
|
||||||
|
updateShapeIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StereotypeDisplayVisitor::visitDComponent(const DComponent *component)
|
void StereotypeDisplayVisitor::visitDComponent(const DComponent *component)
|
||||||
@@ -132,6 +134,7 @@ void StereotypeDisplayVisitor::visitDComponent(const DComponent *component)
|
|||||||
m_stereotypeIconElement = StereotypeIcon::ElementComponent;
|
m_stereotypeIconElement = StereotypeIcon::ElementComponent;
|
||||||
m_stereotypeSmartDisplay = DObject::StereotypeIcon;
|
m_stereotypeSmartDisplay = DObject::StereotypeIcon;
|
||||||
visitDObject(component);
|
visitDObject(component);
|
||||||
|
updateShapeIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StereotypeDisplayVisitor::visitDDiagram(const DDiagram *diagram)
|
void StereotypeDisplayVisitor::visitDDiagram(const DDiagram *diagram)
|
||||||
@@ -139,6 +142,7 @@ void StereotypeDisplayVisitor::visitDDiagram(const DDiagram *diagram)
|
|||||||
m_stereotypeIconElement = StereotypeIcon::ElementDiagram;
|
m_stereotypeIconElement = StereotypeIcon::ElementDiagram;
|
||||||
m_stereotypeSmartDisplay = DObject::StereotypeDecoration;
|
m_stereotypeSmartDisplay = DObject::StereotypeDecoration;
|
||||||
visitDObject(diagram);
|
visitDObject(diagram);
|
||||||
|
updateShapeIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StereotypeDisplayVisitor::visitDItem(const DItem *item)
|
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()));
|
m_stereotypeIconId = m_stereotypeController->findStereotypeIconId(StereotypeIcon::ElementItem, QStringList(item->shape()));
|
||||||
if (m_shapeIconId.isEmpty() && !item->variety().isEmpty())
|
if (m_shapeIconId.isEmpty() && !item->variety().isEmpty())
|
||||||
m_shapeIconId = m_stereotypeController->findStereotypeIconId(StereotypeIcon::ElementItem, QStringList(item->variety()));
|
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
|
} // namespace qmt
|
||||||
|
@@ -43,10 +43,10 @@ public:
|
|||||||
|
|
||||||
void setModelController(ModelController *modelController);
|
void setModelController(ModelController *modelController);
|
||||||
void setStereotypeController(StereotypeController *stereotypeController);
|
void setStereotypeController(StereotypeController *stereotypeController);
|
||||||
DObject::StereotypeDisplay stereotypeDisplay() const { return m_stereotypeDisplay; }
|
|
||||||
StereotypeIcon::Display stereotypeIconDisplay() const;
|
StereotypeIcon::Display stereotypeIconDisplay() const;
|
||||||
QString stereotypeIconId() const { return m_stereotypeIconId; }
|
QString stereotypeIconId() const { return m_stereotypeIconId; }
|
||||||
QString shapeIconId() const { return m_shapeIconId; }
|
QString shapeIconId() const { return m_shapeIconId; }
|
||||||
|
StereotypeIcon shapeIcon() const { return m_shapeIcon; }
|
||||||
|
|
||||||
void visitDObject(const DObject *object) override;
|
void visitDObject(const DObject *object) override;
|
||||||
void visitDPackage(const DPackage *package) override;
|
void visitDPackage(const DPackage *package) override;
|
||||||
@@ -56,11 +56,14 @@ public:
|
|||||||
void visitDItem(const DItem *item) override;
|
void visitDItem(const DItem *item) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateShapeIcon();
|
||||||
|
|
||||||
ModelController *m_modelController = nullptr;
|
ModelController *m_modelController = nullptr;
|
||||||
StereotypeController *m_stereotypeController = nullptr;
|
StereotypeController *m_stereotypeController = nullptr;
|
||||||
DObject::StereotypeDisplay m_stereotypeDisplay = DObject::StereotypeNone;
|
DObject::StereotypeDisplay m_stereotypeDisplay = DObject::StereotypeNone;
|
||||||
QString m_stereotypeIconId;
|
QString m_stereotypeIconId;
|
||||||
QString m_shapeIconId;
|
QString m_shapeIconId;
|
||||||
|
StereotypeIcon m_shapeIcon;
|
||||||
StereotypeIcon::Element m_stereotypeIconElement = StereotypeIcon::ElementAny;
|
StereotypeIcon::Element m_stereotypeIconElement = StereotypeIcon::ElementAny;
|
||||||
DObject::StereotypeDisplay m_stereotypeSmartDisplay = DObject::StereotypeDecoration;
|
DObject::StereotypeDisplay m_stereotypeSmartDisplay = DObject::StereotypeDecoration;
|
||||||
};
|
};
|
||||||
|
@@ -54,6 +54,16 @@ void StereotypeIcon::setStereotypes(const QSet<QString> &stereotypes)
|
|||||||
m_stereotypes = 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)
|
void StereotypeIcon::setWidth(qreal width)
|
||||||
{
|
{
|
||||||
m_width = width;
|
m_width = width;
|
||||||
|
@@ -64,7 +64,8 @@ public:
|
|||||||
enum TextAlignment {
|
enum TextAlignment {
|
||||||
TextalignBelow,
|
TextalignBelow,
|
||||||
TextalignCenter,
|
TextalignCenter,
|
||||||
TextalignNone
|
TextalignNone,
|
||||||
|
TextalignTop
|
||||||
};
|
};
|
||||||
|
|
||||||
QString id() const { return m_id; }
|
QString id() const { return m_id; }
|
||||||
@@ -75,6 +76,10 @@ public:
|
|||||||
void setElements(const QSet<Element> &elements);
|
void setElements(const QSet<Element> &elements);
|
||||||
QSet<QString> stereotypes() const { return m_stereotypes; }
|
QSet<QString> stereotypes() const { return m_stereotypes; }
|
||||||
void setStereotypes(const QSet<QString> &stereotypes);
|
void setStereotypes(const QSet<QString> &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; }
|
qreal width() const { return m_width; }
|
||||||
void setWidth(qreal width);
|
void setWidth(qreal width);
|
||||||
qreal height() const { return m_height; }
|
qreal height() const { return m_height; }
|
||||||
@@ -101,6 +106,8 @@ private:
|
|||||||
QString m_title;
|
QString m_title;
|
||||||
QSet<Element> m_elements;
|
QSet<Element> m_elements;
|
||||||
QSet<QString> m_stereotypes;
|
QSet<QString> m_stereotypes;
|
||||||
|
bool m_hasName = false;
|
||||||
|
QString m_name;
|
||||||
qreal m_width = 100.0;
|
qreal m_width = 100.0;
|
||||||
qreal m_height = 100.0;
|
qreal m_height = 100.0;
|
||||||
qreal m_minWidth = -1;
|
qreal m_minWidth = -1;
|
||||||
|
@@ -397,28 +397,23 @@ void DiagramSceneController::dropNewElement(const QString &newElementId, const Q
|
|||||||
} else {
|
} else {
|
||||||
MPackage *parentPackage = findSuitableParentPackage(topMostElementAtPos, diagram);
|
MPackage *parentPackage = findSuitableParentPackage(topMostElementAtPos, diagram);
|
||||||
MObject *newObject = nullptr;
|
MObject *newObject = nullptr;
|
||||||
QString newName;
|
|
||||||
if (newElementId == QLatin1String(ELEMENT_TYPE_PACKAGE)) {
|
if (newElementId == QLatin1String(ELEMENT_TYPE_PACKAGE)) {
|
||||||
auto package = new MPackage();
|
auto package = new MPackage();
|
||||||
newName = tr("New Package");
|
|
||||||
if (!stereotype.isEmpty())
|
if (!stereotype.isEmpty())
|
||||||
package->setStereotypes({stereotype});
|
package->setStereotypes({stereotype});
|
||||||
newObject = package;
|
newObject = package;
|
||||||
} else if (newElementId == QLatin1String(ELEMENT_TYPE_COMPONENT)) {
|
} else if (newElementId == QLatin1String(ELEMENT_TYPE_COMPONENT)) {
|
||||||
auto component = new MComponent();
|
auto component = new MComponent();
|
||||||
newName = tr("New Component");
|
|
||||||
if (!stereotype.isEmpty())
|
if (!stereotype.isEmpty())
|
||||||
component->setStereotypes({stereotype});
|
component->setStereotypes({stereotype});
|
||||||
newObject = component;
|
newObject = component;
|
||||||
} else if (newElementId == QLatin1String(ELEMENT_TYPE_CLASS)) {
|
} else if (newElementId == QLatin1String(ELEMENT_TYPE_CLASS)) {
|
||||||
auto klass = new MClass();
|
auto klass = new MClass();
|
||||||
newName = tr("New Class");
|
|
||||||
if (!stereotype.isEmpty())
|
if (!stereotype.isEmpty())
|
||||||
klass->setStereotypes({stereotype});
|
klass->setStereotypes({stereotype});
|
||||||
newObject = klass;
|
newObject = klass;
|
||||||
} else if (newElementId == QLatin1String(ELEMENT_TYPE_ITEM)) {
|
} else if (newElementId == QLatin1String(ELEMENT_TYPE_ITEM)) {
|
||||||
auto item = new MItem();
|
auto item = new MItem();
|
||||||
newName = tr("New Item");
|
|
||||||
if (!stereotype.isEmpty()) {
|
if (!stereotype.isEmpty()) {
|
||||||
item->setVariety(stereotype);
|
item->setVariety(stereotype);
|
||||||
item->setVarietyEditable(false);
|
item->setVarietyEditable(false);
|
||||||
@@ -426,9 +421,7 @@ void DiagramSceneController::dropNewElement(const QString &newElementId, const Q
|
|||||||
newObject = item;
|
newObject = item;
|
||||||
}
|
}
|
||||||
if (newObject) {
|
if (newObject) {
|
||||||
if (!name.isEmpty())
|
newObject->setName(name);
|
||||||
newName = tr("New %1").arg(name);
|
|
||||||
newObject->setName(newName);
|
|
||||||
dropNewModelElement(newObject, parentPackage, pos, diagram);
|
dropNewModelElement(newObject, parentPackage, pos, diagram);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,13 +41,14 @@ public:
|
|||||||
QIcon icon;
|
QIcon icon;
|
||||||
QSize iconSize;
|
QSize iconSize;
|
||||||
QString title;
|
QString title;
|
||||||
|
QString newElementName;
|
||||||
QString newElementId;
|
QString newElementId;
|
||||||
QString stereotype;
|
QString stereotype;
|
||||||
bool disableFrame = false;
|
bool disableFrame = false;
|
||||||
bool framePainted = 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)
|
const QString &stereotype, QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
d(new DragToolPrivate)
|
d(new DragToolPrivate)
|
||||||
@@ -55,6 +56,7 @@ DragTool::DragTool(const QIcon &icon, const QString &title, const QString &newEl
|
|||||||
d->icon = icon;
|
d->icon = icon;
|
||||||
d->iconSize = QSize(32, 32);
|
d->iconSize = QSize(32, 32);
|
||||||
d->title = title;
|
d->title = title;
|
||||||
|
d->newElementName = newElementName;
|
||||||
d->newElementId = newElementId;
|
d->newElementId = newElementId;
|
||||||
d->stereotype = stereotype;
|
d->stereotype = stereotype;
|
||||||
QMargins margins = contentsMargins();
|
QMargins margins = contentsMargins();
|
||||||
@@ -144,7 +146,7 @@ void DragTool::mousePressEvent(QMouseEvent *event)
|
|||||||
auto mimeData = new QMimeData;
|
auto mimeData = new QMimeData;
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
QDataStream dataStream(&data, QIODevice::WriteOnly);
|
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);
|
mimeData->setData(QLatin1String(qmt::MIME_TYPE_NEW_MODEL_ELEMENTS), data);
|
||||||
drag->setMimeData(mimeData);
|
drag->setMimeData(mimeData);
|
||||||
|
|
||||||
|
@@ -38,8 +38,8 @@ class DragTool :
|
|||||||
class DragToolPrivate;
|
class DragToolPrivate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DragTool(const QIcon &icon, const QString &title, const QString &newElementId,
|
DragTool(const QIcon &icon, const QString &title, const QString &newElementName,
|
||||||
const QString &stereotype, QWidget *parent = nullptr);
|
const QString &newElementId, const QString &stereotype, QWidget *parent = nullptr);
|
||||||
~DragTool();
|
~DragTool();
|
||||||
|
|
||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
|
@@ -1051,16 +1051,24 @@ void ModelEditor::initToolbars()
|
|||||||
styleEngineElementType = qmt::StyleEngine::TypeSwimlane;
|
styleEngineElementType = qmt::StyleEngine::TypeSwimlane;
|
||||||
}
|
}
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
|
QString newElementName = tr("New %1").arg(tool.m_name);
|
||||||
if (!tool.m_stereotype.isEmpty() && stereotypeIconElement != qmt::StereotypeIcon::ElementAny) {
|
if (!tool.m_stereotype.isEmpty() && stereotypeIconElement != qmt::StereotypeIcon::ElementAny) {
|
||||||
const qmt::Style *style = documentController->styleController()->adaptStyle(styleEngineElementType);
|
const qmt::Style *style = documentController->styleController()->adaptStyle(styleEngineElementType);
|
||||||
icon = stereotypeController->createIcon(
|
icon = stereotypeController->createIcon(
|
||||||
stereotypeIconElement, QStringList() << tool.m_stereotype,
|
stereotypeIconElement, QStringList() << tool.m_stereotype,
|
||||||
QString(), style, QSize(48, 48), QMarginsF(3.0, 2.0, 3.0, 4.0));
|
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())
|
if (icon.isNull())
|
||||||
icon = QIcon(iconPath);
|
icon = QIcon(iconPath);
|
||||||
if (!icon.isNull()) {
|
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));
|
tool.m_stereotype, toolBar));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1088,34 +1096,34 @@ void ModelEditor::initToolbars()
|
|||||||
toolBars.insert(generalId, toolBar);
|
toolBars.insert(generalId, toolBar);
|
||||||
toolBarLayout->addWidget(
|
toolBarLayout->addWidget(
|
||||||
new DragTool(QIcon(":/modelinglib/48x48/package.png"),
|
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));
|
QString(), toolBar));
|
||||||
toolBarLayout->addWidget(
|
toolBarLayout->addWidget(
|
||||||
new DragTool(QIcon(":/modelinglib/48x48/component.png"),
|
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));
|
QString(), toolBar));
|
||||||
toolBarLayout->addWidget(
|
toolBarLayout->addWidget(
|
||||||
new DragTool(QIcon(":/modelinglib/48x48/class.png"),
|
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));
|
QString(), toolBar));
|
||||||
toolBarLayout->addWidget(
|
toolBarLayout->addWidget(
|
||||||
new DragTool(QIcon(":/modelinglib/48x48/item.png"),
|
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));
|
QString(), toolBar));
|
||||||
auto horizLine1 = new QFrame(d->leftToolBox);
|
auto horizLine1 = new QFrame(d->leftToolBox);
|
||||||
horizLine1->setFrameShape(QFrame::HLine);
|
horizLine1->setFrameShape(QFrame::HLine);
|
||||||
toolBarLayout->addWidget(horizLine1);
|
toolBarLayout->addWidget(horizLine1);
|
||||||
toolBarLayout->addWidget(
|
toolBarLayout->addWidget(
|
||||||
new DragTool(QIcon(":/modelinglib/48x48/annotation.png"),
|
new DragTool(QIcon(":/modelinglib/48x48/annotation.png"),
|
||||||
tr("Annotation"), QLatin1String(qmt::ELEMENT_TYPE_ANNOTATION),
|
tr("Annotation"), QString(), QLatin1String(qmt::ELEMENT_TYPE_ANNOTATION),
|
||||||
QString(), toolBar));
|
QString(), toolBar));
|
||||||
toolBarLayout->addWidget(
|
toolBarLayout->addWidget(
|
||||||
new DragTool(QIcon(":/modelinglib/48x48/boundary.png"),
|
new DragTool(QIcon(":/modelinglib/48x48/boundary.png"),
|
||||||
tr("Boundary"), QLatin1String(qmt::ELEMENT_TYPE_BOUNDARY),
|
tr("Boundary"), QString(), QLatin1String(qmt::ELEMENT_TYPE_BOUNDARY),
|
||||||
QString(), toolBar));
|
QString(), toolBar));
|
||||||
toolBarLayout->addWidget(
|
toolBarLayout->addWidget(
|
||||||
new DragTool(QIcon(":/modelinglib/48x48/swimlane.png"),
|
new DragTool(QIcon(":/modelinglib/48x48/swimlane.png"),
|
||||||
tr("Swimlane"), QLatin1String(qmt::ELEMENT_TYPE_SWIMLANE),
|
tr("Swimlane"), QString(), QLatin1String(qmt::ELEMENT_TYPE_SWIMLANE),
|
||||||
QString(), toolBar));
|
QString(), toolBar));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user