forked from qt-creator/qt-creator
ModelEditor: Show base class names
The names of bases classes that are not related on a diagram are listed in the class' top left edge. Change-Id: I60198a0401adacf5abb6e1f6bf7bb36e67c9c7ca Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -765,6 +765,7 @@ void DiagramSceneModel::onEndUpdateElement(int row, const MDiagram *diagram)
|
|||||||
if (diagram == m_diagram) {
|
if (diagram == m_diagram) {
|
||||||
QGraphicsItem *item = m_graphicsItems.at(row);
|
QGraphicsItem *item = m_graphicsItems.at(row);
|
||||||
updateGraphicsItem(item, diagram->diagramElements().at(row));
|
updateGraphicsItem(item, diagram->diagramElements().at(row));
|
||||||
|
// TODO update all relations and their other end's (e.g. class name may have changed)
|
||||||
recalcSceneRectSize();
|
recalcSceneRectSize();
|
||||||
}
|
}
|
||||||
m_busyState = NotBusy;
|
m_busyState = NotBusy;
|
||||||
@@ -789,6 +790,15 @@ void DiagramSceneModel::onEndInsertElement(int row, const MDiagram *diagram)
|
|||||||
updateGraphicsItem(item, element);
|
updateGraphicsItem(item, element);
|
||||||
m_graphicsScene->invalidate();
|
m_graphicsScene->invalidate();
|
||||||
updateGraphicsItem(item, element);
|
updateGraphicsItem(item, element);
|
||||||
|
// if element is relation update ends
|
||||||
|
if (DRelation *dRelation = dynamic_cast<DRelation *>(element)) {
|
||||||
|
DElement *dEnd = m_diagramController->findElement(dRelation->endAUid(), diagram);
|
||||||
|
if (dEnd)
|
||||||
|
updateGraphicsItem(graphicsItem(dEnd), dEnd);
|
||||||
|
dEnd = m_diagramController->findElement(dRelation->endBUid(), diagram);
|
||||||
|
if (dEnd)
|
||||||
|
updateGraphicsItem(graphicsItem(dEnd), dEnd);
|
||||||
|
}
|
||||||
recalcSceneRectSize();
|
recalcSceneRectSize();
|
||||||
}
|
}
|
||||||
m_busyState = NotBusy;
|
m_busyState = NotBusy;
|
||||||
@@ -798,6 +808,12 @@ void DiagramSceneModel::onBeginRemoveElement(int row, const MDiagram *diagram)
|
|||||||
{
|
{
|
||||||
QMT_CHECK(m_busyState == NotBusy);
|
QMT_CHECK(m_busyState == NotBusy);
|
||||||
if (diagram == m_diagram) {
|
if (diagram == m_diagram) {
|
||||||
|
// if element is relation store end's uid
|
||||||
|
m_relationEndsUid.clear();
|
||||||
|
if (DRelation *relation = dynamic_cast<DRelation *>(diagram->diagramElements().at(row))) {
|
||||||
|
m_relationEndsUid.append(relation->endAUid());
|
||||||
|
m_relationEndsUid.append(relation->endBUid());
|
||||||
|
}
|
||||||
QGraphicsItem *item = m_graphicsItems.takeAt(row);
|
QGraphicsItem *item = m_graphicsItems.takeAt(row);
|
||||||
deleteGraphicsItem(item, diagram->diagramElements().at(row));
|
deleteGraphicsItem(item, diagram->diagramElements().at(row));
|
||||||
recalcSceneRectSize();
|
recalcSceneRectSize();
|
||||||
@@ -810,6 +826,12 @@ void DiagramSceneModel::onEndRemoveElement(int row, const MDiagram *diagram)
|
|||||||
Q_UNUSED(row);
|
Q_UNUSED(row);
|
||||||
Q_UNUSED(diagram);
|
Q_UNUSED(diagram);
|
||||||
QMT_CHECK(m_busyState == RemoveElement);
|
QMT_CHECK(m_busyState == RemoveElement);
|
||||||
|
// update elements from store (see above)
|
||||||
|
for (const Uid &end_uid : m_relationEndsUid) {
|
||||||
|
DElement *dEnd = m_diagramController->findElement(end_uid, diagram);
|
||||||
|
if (dEnd)
|
||||||
|
updateGraphicsItem(graphicsItem(dEnd), dEnd);
|
||||||
|
}
|
||||||
m_busyState = NotBusy;
|
m_busyState = NotBusy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -190,6 +190,7 @@ private:
|
|||||||
OriginItem *m_originItem = nullptr;
|
OriginItem *m_originItem = nullptr;
|
||||||
QGraphicsItem *m_focusItem = nullptr;
|
QGraphicsItem *m_focusItem = nullptr;
|
||||||
QRectF m_sceneRect;
|
QRectF m_sceneRect;
|
||||||
|
QList<Uid> m_relationEndsUid;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace qmt
|
} // namespace qmt
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include "qmt/controller/namecontroller.h"
|
#include "qmt/controller/namecontroller.h"
|
||||||
#include "qmt/diagram/dclass.h"
|
#include "qmt/diagram/dclass.h"
|
||||||
|
#include "qmt/diagram/dinheritance.h"
|
||||||
|
#include "qmt/diagram_controller/diagramcontroller.h"
|
||||||
#include "qmt/diagram_scene/diagramsceneconstants.h"
|
#include "qmt/diagram_scene/diagramsceneconstants.h"
|
||||||
#include "qmt/diagram_scene/diagramscenemodel.h"
|
#include "qmt/diagram_scene/diagramscenemodel.h"
|
||||||
#include "qmt/diagram_scene/parts/contextlabelitem.h"
|
#include "qmt/diagram_scene/parts/contextlabelitem.h"
|
||||||
@@ -41,6 +43,7 @@
|
|||||||
#include "qmt/model/mclass.h"
|
#include "qmt/model/mclass.h"
|
||||||
#include "qmt/model/mclassmember.h"
|
#include "qmt/model/mclassmember.h"
|
||||||
#include "qmt/model/massociation.h"
|
#include "qmt/model/massociation.h"
|
||||||
|
#include "qmt/model/minheritance.h"
|
||||||
#include "qmt/model_controller/modelcontroller.h"
|
#include "qmt/model_controller/modelcontroller.h"
|
||||||
#include "qmt/stereotype/stereotypecontroller.h"
|
#include "qmt/stereotype/stereotypecontroller.h"
|
||||||
#include "qmt/stereotype/stereotypeicon.h"
|
#include "qmt/stereotype/stereotypeicon.h"
|
||||||
@@ -71,6 +74,7 @@ static const qreal MINIMUM_AUTO_WIDTH = 80.0;
|
|||||||
static const qreal MINIMUM_AUTO_HEIGHT = 60.0;
|
static const qreal MINIMUM_AUTO_HEIGHT = 60.0;
|
||||||
static const qreal BODY_VERT_BORDER = 4.0;
|
static const qreal BODY_VERT_BORDER = 4.0;
|
||||||
static const qreal BODY_HORIZ_BORDER = 4.0;
|
static const qreal BODY_HORIZ_BORDER = 4.0;
|
||||||
|
static const qreal BODY_HORIZ_DISTANCE = 4.0;
|
||||||
|
|
||||||
ClassItem::ClassItem(DClass *klass, DiagramSceneModel *diagramSceneModel, QGraphicsItem *parent)
|
ClassItem::ClassItem(DClass *klass, DiagramSceneModel *diagramSceneModel, QGraphicsItem *parent)
|
||||||
: ObjectItem("class", klass, diagramSceneModel, parent)
|
: ObjectItem("class", klass, diagramSceneModel, parent)
|
||||||
@@ -130,6 +134,46 @@ void ClassItem::update()
|
|||||||
// stereotypes
|
// stereotypes
|
||||||
updateStereotypes(stereotypeIconId(), stereotypeIconDisplay(), style);
|
updateStereotypes(stereotypeIconId(), stereotypeIconDisplay(), style);
|
||||||
|
|
||||||
|
// base classes
|
||||||
|
DiagramController *diagramController = diagramSceneModel()->diagramController();
|
||||||
|
ModelController *modelController = diagramController->modelController();
|
||||||
|
MClass *klass = modelController->findElement<MClass>(diagramClass->modelUid());
|
||||||
|
if (klass) {
|
||||||
|
// TODO cache relation's Uids and check for change
|
||||||
|
QList<QString> baseClasses;
|
||||||
|
for (const auto &handle : klass->relations()) {
|
||||||
|
if (MInheritance *mInheritance = dynamic_cast<MInheritance *>(handle.target())) {
|
||||||
|
if (mInheritance->base() != klass->uid()) {
|
||||||
|
DInheritance *dInheritance = diagramController->findDelegate<DInheritance>(mInheritance, diagramSceneModel()->diagram());
|
||||||
|
if (dInheritance) {
|
||||||
|
DClass *dBaseClass = diagramController->findElement<DClass>(dInheritance->base(), diagramSceneModel()->diagram());
|
||||||
|
if (dBaseClass)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MClass *mBaseClass = diagramController->modelController()->findElement<MClass>(mInheritance->base());
|
||||||
|
if (mBaseClass) {
|
||||||
|
QString baseClassName;
|
||||||
|
baseClassName += mBaseClass->name();
|
||||||
|
baseClasses.append(baseClassName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!baseClasses.isEmpty()) {
|
||||||
|
if (!m_baseClasses)
|
||||||
|
m_baseClasses = new QGraphicsSimpleTextItem(this);
|
||||||
|
QFont font = style->smallFont();
|
||||||
|
font.setItalic(true);
|
||||||
|
m_baseClasses->setFont(font);
|
||||||
|
m_baseClasses->setBrush(style->textBrush());
|
||||||
|
m_baseClasses->setText(baseClasses.join('\n'));
|
||||||
|
} else if (m_baseClasses) {
|
||||||
|
m_baseClasses->scene()->removeItem(m_baseClasses);
|
||||||
|
delete m_baseClasses;
|
||||||
|
m_baseClasses = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// namespace
|
// namespace
|
||||||
if (!suppressTextDisplay() && !diagramClass->umlNamespace().isEmpty()) {
|
if (!suppressTextDisplay() && !diagramClass->umlNamespace().isEmpty()) {
|
||||||
if (!m_namespace)
|
if (!m_namespace)
|
||||||
@@ -487,10 +531,18 @@ QSizeF ClassItem::calcMinimumGeometry() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
height += BODY_VERT_BORDER;
|
height += BODY_VERT_BORDER;
|
||||||
|
double top_row_width = BODY_HORIZ_DISTANCE;
|
||||||
|
double top_row_height = 0;
|
||||||
if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
|
if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
|
||||||
width = std::max(width, stereotypeIconItem->boundingRect().width());
|
top_row_width += stereotypeIconItem->boundingRect().width();
|
||||||
height += stereotypeIconItem->boundingRect().height();
|
top_row_height = stereotypeIconItem->boundingRect().height();
|
||||||
}
|
}
|
||||||
|
if (m_baseClasses) {
|
||||||
|
top_row_width += m_baseClasses->boundingRect().width();
|
||||||
|
top_row_height = std::max(top_row_height, m_baseClasses->boundingRect().height());
|
||||||
|
}
|
||||||
|
width = std::max(width, top_row_width);
|
||||||
|
height += top_row_height;
|
||||||
if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
|
if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
|
||||||
width = std::max(width, stereotypesItem->boundingRect().width());
|
width = std::max(width, stereotypesItem->boundingRect().width());
|
||||||
height += stereotypesItem->boundingRect().height();
|
height += stereotypesItem->boundingRect().height();
|
||||||
@@ -604,10 +656,16 @@ void ClassItem::updateGeometry()
|
|||||||
} else {
|
} else {
|
||||||
y += BODY_VERT_BORDER;
|
y += BODY_VERT_BORDER;
|
||||||
}
|
}
|
||||||
|
double first_row_height = 0;
|
||||||
|
if (m_baseClasses) {
|
||||||
|
m_baseClasses->setPos(left + BODY_HORIZ_BORDER, y);
|
||||||
|
first_row_height = m_baseClasses->boundingRect().height();
|
||||||
|
}
|
||||||
if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
|
if (CustomIconItem *stereotypeIconItem = this->stereotypeIconItem()) {
|
||||||
stereotypeIconItem->setPos(right - stereotypeIconItem->boundingRect().width() - BODY_HORIZ_BORDER, y);
|
stereotypeIconItem->setPos(right - stereotypeIconItem->boundingRect().width() - BODY_HORIZ_BORDER, y);
|
||||||
y += stereotypeIconItem->boundingRect().height();
|
first_row_height = std::max(first_row_height, stereotypeIconItem->boundingRect().height());
|
||||||
}
|
}
|
||||||
|
y += first_row_height;
|
||||||
if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
|
if (StereotypesItem *stereotypesItem = this->stereotypesItem()) {
|
||||||
stereotypesItem->setPos(-stereotypesItem->boundingRect().width() / 2.0, y);
|
stereotypesItem->setPos(-stereotypesItem->boundingRect().width() / 2.0, y);
|
||||||
y += stereotypesItem->boundingRect().height();
|
y += stereotypesItem->boundingRect().height();
|
||||||
|
@@ -79,6 +79,7 @@ private:
|
|||||||
|
|
||||||
CustomIconItem *m_customIcon = nullptr;
|
CustomIconItem *m_customIcon = nullptr;
|
||||||
QGraphicsRectItem *m_shape = nullptr;
|
QGraphicsRectItem *m_shape = nullptr;
|
||||||
|
QGraphicsSimpleTextItem *m_baseClasses = nullptr;
|
||||||
QGraphicsSimpleTextItem *m_namespace = nullptr;
|
QGraphicsSimpleTextItem *m_namespace = nullptr;
|
||||||
ContextLabelItem *m_contextLabel = nullptr;
|
ContextLabelItem *m_contextLabel = nullptr;
|
||||||
QGraphicsLineItem *m_attributesSeparator = nullptr;
|
QGraphicsLineItem *m_attributesSeparator = nullptr;
|
||||||
|
Reference in New Issue
Block a user