Commit 6ea47c98 authored by Jochen Becher's avatar Jochen Becher

ModelEditor: Refactor relationables into common parent class

Change-Id: Id863a5004cb903cbc2929745e818e5810ff70dd2
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 81008125
......@@ -227,23 +227,7 @@ void ClassItem::update()
}
updateSelectionMarker(m_customIcon);
// relation starters
if (isFocusSelected()) {
if (!m_relationStarter) {
m_relationStarter = new RelationStarter(this, diagramSceneModel(), 0);
scene()->addItem(m_relationStarter);
m_relationStarter->setZValue(RELATION_STARTER_ZVALUE);
m_relationStarter->addArrow(QLatin1String("inheritance"), ArrowItem::ShaftSolid, ArrowItem::HeadTriangle);
m_relationStarter->addArrow(QLatin1String("dependency"), ArrowItem::ShaftDashed, ArrowItem::HeadOpen);
m_relationStarter->addArrow(QLatin1String("association"), ArrowItem::ShaftSolid, ArrowItem::HeadFilledTriangle);
}
} else if (m_relationStarter) {
scene()->removeItem(m_relationStarter);
delete m_relationStarter;
m_relationStarter = 0;
}
updateRelationStarter();
updateAlignmentButtons();
updateGeometry();
}
......@@ -263,11 +247,6 @@ QSizeF ClassItem::minimumSize() const
return calcMinimumGeometry();
}
QPointF ClassItem::relationStartPos() const
{
return pos();
}
void ClassItem::relationDrawn(const QString &id, const QPointF &toScenePos, const QList<QPointF> &intermediatePoints)
{
DElement *targetElement = diagramSceneModel()->findTopmostElement(toScenePos);
......@@ -359,6 +338,13 @@ void ClassItem::setFromDisplayName(const QString &displayName)
}
}
void ClassItem::updateRelationStarterTools(RelationStarter *relationStarter)
{
relationStarter->addArrow("dependency", ArrowItem::ShaftDashed, ArrowItem::HeadOpen);
relationStarter->addArrow("inheritance", ArrowItem::ShaftSolid, ArrowItem::HeadTriangle);
relationStarter->addArrow("association", ArrowItem::ShaftSolid, ArrowItem::HeadFilledTriangle);
}
DClass::TemplateDisplay ClassItem::templateDisplay() const
{
auto diagramClass = dynamic_cast<DClass *>(object());
......@@ -535,10 +521,7 @@ void ClassItem::updateGeometry()
}
updateSelectionMarkerGeometry(rect);
if (m_relationStarter)
m_relationStarter->setPos(mapToScene(QPointF(right + 8.0, top)));
updateRelationStarterGeometry(rect);
updateAlignmentButtonsGeometry(rect);
updateDepth();
}
......
......@@ -27,7 +27,6 @@
#include "objectitem.h"
#include "qmt/diagram_scene/capabilities/relationable.h"
#include "qmt/diagram/dclass.h"
QT_BEGIN_NAMESPACE
......@@ -43,10 +42,9 @@ class DiagramSceneModel;
class CustomIconItem;
class ContextLabelItem;
class TemplateParameterBox;
class RelationStarter;
class Style;
class ClassItem : public ObjectItem, public IRelationable
class ClassItem : public ObjectItem
{
Q_DECLARE_TR_FUNCTIONS(qmt::ClassItem)
......@@ -61,7 +59,6 @@ public:
QSizeF minimumSize() const override;
QPointF relationStartPos() const override;
void relationDrawn(const QString &id, const QPointF &toScenePos,
const QList<QPointF> &intermediatePoints) override;
......@@ -70,6 +67,7 @@ protected:
bool handleSelectedContextMenuAction(const QString &id) override;
QString buildDisplayName() const override;
void setFromDisplayName(const QString &displayName) override;
void updateRelationStarterTools(RelationStarter *relationStarter) override;
private:
DClass::TemplateDisplay templateDisplay() const;
......@@ -88,7 +86,6 @@ private:
QString m_methodsText;
QGraphicsTextItem *m_methods = 0;
TemplateParameterBox *m_templateParameterBox = 0;
RelationStarter *m_relationStarter = 0;
};
} // namespace qmt
......@@ -217,23 +217,6 @@ QList<ILatchable::Latch> ComponentItem::verticalLatches(ILatchable::Action actio
return ObjectItem::verticalLatches(action, grabbedItem);
}
QPointF ComponentItem::relationStartPos() const
{
return pos();
}
void ComponentItem::relationDrawn(const QString &id, const QPointF &toScenePos, const QList<QPointF> &intermediatePoints)
{
DElement *targetElement = diagramSceneModel()->findTopmostElement(toScenePos);
if (targetElement) {
if (id == QStringLiteral("dependency")) {
auto dependantObject = dynamic_cast<DObject *>(targetElement);
if (dependantObject)
diagramSceneModel()->diagramSceneController()->createDependency(object(), dependantObject, intermediatePoints, diagramSceneModel()->diagram());
}
}
}
bool ComponentItem::hasPlainShape() const
{
auto diagramComponent = dynamic_cast<DComponent *>(object());
......
......@@ -27,8 +27,6 @@
#include "objectitem.h"
#include "qmt/diagram_scene/capabilities/relationable.h"
QT_BEGIN_NAMESPACE
class QGraphicsRectItem;
class QGraphicsSimpleTextItem;
......@@ -43,7 +41,7 @@ class CustomIconItem;
class ContextLabelItem;
class RelationStarter;
class ComponentItem : public ObjectItem, public IRelationable
class ComponentItem : public ObjectItem
{
public:
ComponentItem(DComponent *component, DiagramSceneModel *diagramSceneModel,
......@@ -60,10 +58,6 @@ public:
QList<Latch> horizontalLatches(Action action, bool grabbedItem) const override;
QList<Latch> verticalLatches(Action action, bool grabbedItem) const override;
QPointF relationStartPos() const override;
void relationDrawn(const QString &id, const QPointF &toScenePos, const
QList<QPointF> &intermediatePoints) override;
private:
bool hasPlainShape() const;
QSizeF calcMinimumGeometry() const;
......
......@@ -175,23 +175,6 @@ QList<ILatchable::Latch> ItemItem::verticalLatches(ILatchable::Action action, bo
return ObjectItem::verticalLatches(action, grabbedItem);
}
QPointF ItemItem::relationStartPos() const
{
return pos();
}
void ItemItem::relationDrawn(const QString &id, const QPointF &toScenePos, const QList<QPointF> &intermediatePoints)
{
DElement *targetElement = diagramSceneModel()->findTopmostElement(toScenePos);
if (targetElement) {
if (id == QStringLiteral("dependency")) {
auto dependantObject = dynamic_cast<DObject *>(targetElement);
if (dependantObject)
diagramSceneModel()->diagramSceneController()->createDependency(object(), dependantObject, intermediatePoints, diagramSceneModel()->diagram());
}
}
}
QSizeF ItemItem::calcMinimumGeometry() const
{
double width = 0.0;
......
......@@ -27,8 +27,6 @@
#include "objectitem.h"
#include "qmt/diagram_scene/capabilities/relationable.h"
QT_BEGIN_NAMESPACE
class QGraphicsRectItem;
class QGraphicsSimpleTextItem;
......@@ -43,7 +41,7 @@ class CustomIconItem;
class ContextLabelItem;
class RelationStarter;
class ItemItem : public ObjectItem, public IRelationable
class ItemItem : public ObjectItem
{
public:
ItemItem(DItem *item, DiagramSceneModel *diagramSceneModel, QGraphicsItem *parent = 0);
......@@ -59,10 +57,6 @@ public:
QList<Latch> horizontalLatches(Action action, bool grabbedItem) const override;
QList<Latch> verticalLatches(Action action, bool grabbedItem) const override;
QPointF relationStartPos() const override;
void relationDrawn(const QString &id, const QPointF &toScenePos,
const QList<QPointF> &intermediatePoints) override;
private:
QSizeF calcMinimumGeometry() const;
void updateGeometry();
......
......@@ -34,6 +34,7 @@
#include "qmt/diagram_scene/parts/alignbuttonsitem.h"
#include "qmt/diagram_scene/parts/editabletextitem.h"
#include "qmt/diagram_scene/parts/rectangularselectionitem.h"
#include "qmt/diagram_scene/parts/relationstarter.h"
#include "qmt/diagram_scene/parts/customiconitem.h"
#include "qmt/diagram_scene/parts/stereotypesitem.h"
#include "qmt/infrastructure/contextmenuaction.h"
......@@ -301,6 +302,23 @@ QList<ILatchable::Latch> ObjectItem::verticalLatches(ILatchable::Action action,
return result;
}
QPointF ObjectItem::relationStartPos() const
{
return pos();
}
void ObjectItem::relationDrawn(const QString &id, const QPointF &toScenePos, const QList<QPointF> &intermediatePoints)
{
DElement *targetElement = diagramSceneModel()->findTopmostElement(toScenePos);
if (targetElement) {
if (id == QLatin1String("dependency")) {
auto dependantObject = dynamic_cast<DObject *>(targetElement);
if (dependantObject)
diagramSceneModel()->diagramSceneController()->createDependency(object(), dependantObject, intermediatePoints, diagramSceneModel()->diagram());
}
}
}
void ObjectItem::align(IAlignable::AlignType alignType, const QString &identifier)
{
Q_UNUSED(identifier); // avoid warning in release mode
......@@ -569,6 +587,34 @@ void ObjectItem::updateSelectionMarkerGeometry(const QRectF &objectRect)
m_selectionMarker->setRect(objectRect);
}
void ObjectItem::updateRelationStarter()
{
if (isFocusSelected()) {
if (!m_relationStarter) {
m_relationStarter = new RelationStarter(this, diagramSceneModel(), 0);
scene()->addItem(m_relationStarter);
m_relationStarter->setZValue(RELATION_STARTER_ZVALUE);
updateRelationStarterTools(m_relationStarter);
}
} else if (m_relationStarter) {
scene()->removeItem(m_relationStarter);
delete m_relationStarter;
m_relationStarter = 0;
}
}
void ObjectItem::updateRelationStarterTools(RelationStarter *relationStarter)
{
relationStarter->addArrow(QLatin1String("dependency"), ArrowItem::ShaftDashed, ArrowItem::HeadOpen);
}
void ObjectItem::updateRelationStarterGeometry(const QRectF &objectRect)
{
if (m_relationStarter)
m_relationStarter->setPos(mapToScene(QPointF(objectRect.right() + 8.0, objectRect.top())));
}
void ObjectItem::updateAlignmentButtons()
{
if (isFocusSelected() && m_diagramSceneModel->hasMultiObjectsSelection()) {
......
......@@ -32,6 +32,7 @@
#include "qmt/diagram_scene/capabilities/moveable.h"
#include "qmt/diagram_scene/capabilities/selectable.h"
#include "qmt/diagram_scene/capabilities/latchable.h"
#include "qmt/diagram_scene/capabilities/relationable.h"
#include "qmt/diagram_scene/capabilities/alignable.h"
#include "qmt/diagram_scene/capabilities/editable.h"
......@@ -51,6 +52,7 @@ class StereotypesItem;
class CustomIconItem;
class EditableTextItem;
class RectangularSelectionItem;
class RelationStarter;
class AlignButtonsItem;
class Style;
......@@ -66,6 +68,7 @@ class ObjectItem :
public IMoveable,
public ISelectable,
public ILatchable,
public IRelationable,
public IAlignable,
public IEditable
{
......@@ -113,6 +116,10 @@ public:
QList<Latch> horizontalLatches(Action action, bool grabbedItem) const override;
QList<Latch> verticalLatches(Action action, bool grabbedItem) const override;
QPointF relationStartPos() const override;
void relationDrawn(const QString &id, const QPointF &toScenePos,
const QList<QPointF> &intermediatePoints) override;
void align(AlignType alignType, const QString &identifier) override;
bool isEditable() const override;
......@@ -139,6 +146,9 @@ protected:
void updateSelectionMarker(CustomIconItem *customIconItem);
void updateSelectionMarker(ResizeFlags resizeFlags);
void updateSelectionMarkerGeometry(const QRectF &objectRect);
void updateRelationStarter();
virtual void updateRelationStarterTools(RelationStarter *relationStarter);
void updateRelationStarterGeometry(const QRectF &objectRect);
void updateAlignmentButtons();
void updateAlignmentButtonsGeometry(const QRectF &objectRect);
......@@ -169,6 +179,7 @@ private:
CustomIconItem *m_stereotypeIcon = 0;
EditableTextItem *m_nameItem = 0;
RectangularSelectionItem *m_selectionMarker = 0;
RelationStarter *m_relationStarter = 0;
AlignButtonsItem *m_horizontalAlignButtons = 0;
AlignButtonsItem *m_verticalAlignButtons = 0;
};
......
......@@ -190,23 +190,6 @@ QList<ILatchable::Latch> PackageItem::verticalLatches(ILatchable::Action action,
return ObjectItem::verticalLatches(action, grabbedItem);
}
QPointF PackageItem::relationStartPos() const
{
return pos();
}
void PackageItem::relationDrawn(const QString &id, const QPointF &toScenePos, const QList<QPointF> &intermediatePoints)
{
DElement *targetElement = diagramSceneModel()->findTopmostElement(toScenePos);
if (targetElement) {
if (id == QStringLiteral("dependency")) {
auto dependantObject = dynamic_cast<DObject *>(targetElement);
if (dependantObject)
diagramSceneModel()->diagramSceneController()->createDependency(object(), dependantObject, intermediatePoints, diagramSceneModel()->diagram());
}
}
}
PackageItem::ShapeGeometry PackageItem::calcMinimumGeometry() const
{
double width = 0.0;
......
......@@ -27,8 +27,6 @@
#include "objectitem.h"
#include "qmt/diagram_scene/capabilities/relationable.h"
QT_BEGIN_NAMESPACE
class QGraphicsPolygonItem;
class QGraphicsSimpleTextItem;
......@@ -42,7 +40,7 @@ class CustomIconItem;
class ContextLabelItem;
class RelationStarter;
class PackageItem : public ObjectItem, public IRelationable
class PackageItem : public ObjectItem
{
class ShapeGeometry;
......@@ -60,10 +58,6 @@ public:
QList<Latch> horizontalLatches(Action action, bool grabbedItem) const override;
QList<Latch> verticalLatches(Action action, bool grabbedItem) const override;
QPointF relationStartPos() const override;
void relationDrawn(const QString &id, const QPointF &toScenePos,
const QList<QPointF> &intermediatePoints) override;
private:
ShapeGeometry calcMinimumGeometry() const;
void updateGeometry();
......
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