Commit f74ed161 authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Cleanup usage of WidgetBase::m_nID

The class variable m_nID is in the WidgetBase class, but initialization
and usage took place in UMLWidget, which has now been cleaned up.

CCBUG:413579
parent 0ff187e4
......@@ -665,8 +665,10 @@ AssociationLine* AssociationWidget::associationLine() const
*
* @return true for success
*/
bool AssociationWidget::activate()
bool AssociationWidget::activate(IDChangeLog *changeLog)
{
Q_UNUSED(changeLog);
if (m_umlObject == 0 &&
AssociationType::hasUMLRepresentation(m_associationType)) {
UMLObject *myObj = umlDoc()->findObjectById(m_nId);
......@@ -4042,9 +4044,8 @@ bool AssociationWidget::loadFromXMI1(QDomElement& qElement,
QString type = qElement.attribute(QLatin1String("type"), QLatin1String("-1"));
Uml::AssociationType::Enum aType = Uml::AssociationType::fromInt(type.toInt());
QString id = qElement.attribute(QLatin1String("xmi.id"), QLatin1String("-1"));
bool oldStyleLoad = false;
if (id == QLatin1String("-1")) {
if (m_nId == Uml::ID::None) {
// xmi.id not present, ergo either a pure widget association,
// or old (pre-1.2) style:
// Everything is loaded from the AssociationWidget.
......@@ -4128,7 +4129,6 @@ bool AssociationWidget::loadFromXMI1(QDomElement& qElement,
// New style: The xmi.id is a reference to the UMLAssociation.
// If the UMLObject is not found right now, we try again later
// during the type resolution pass - see activate().
m_nId = Uml::ID::fromString(id);
UMLObject *myObj = umlDoc()->findObjectById(m_nId);
if (myObj) {
const UMLObject::ObjectType ot = myObj->baseType();
......
......@@ -144,7 +144,7 @@ public:
AssociationLine* associationLine() const;
virtual bool activate();
virtual bool activate(IDChangeLog *changeLog = 0);
virtual QRectF boundingRect() const;
virtual QPainterPath shape() const;
......
......@@ -82,14 +82,14 @@ const int UMLWidget::resizeMarkerLineCount = 3;
* @param o The UMLObject to represent.
*/
UMLWidget::UMLWidget(UMLScene * scene, WidgetType type, UMLObject * o)
: WidgetBase(scene, type)
: WidgetBase(scene, type, o ? m_umlObject->id() : Uml::ID::None)
, DiagramProxyWidget(this)
{
init();
m_umlObject = o;
if (m_umlObject) {
// TODO: calling WidgetBase::setUMLObject does not add this connection
connect(m_umlObject, SIGNAL(modified()), this, SLOT(updateWidget()));
m_nId = m_umlObject->id();
}
}
......@@ -103,14 +103,10 @@ UMLWidget::UMLWidget(UMLScene * scene, WidgetType type, UMLObject * o)
* The default value (id_None) will prompt generation of a new ID.
*/
UMLWidget::UMLWidget(UMLScene *scene, WidgetType type, Uml::ID::Type id)
: WidgetBase(scene, type)
: WidgetBase(scene, type, id)
, DiagramProxyWidget(this)
{
init();
if (id == Uml::ID::None)
m_nId = UniqueID::gen();
else
m_nId = id;
}
/**
......@@ -696,7 +692,6 @@ void UMLWidget::constrain(qreal& width, qreal& height)
*/
void UMLWidget::init()
{
m_nId = Uml::ID::None;
m_isInstance = false;
setMinimumSize(DefaultMinimumSize);
setMaximumSize(DefaultMaximumSize);
......@@ -1168,21 +1163,17 @@ void UMLWidget::setFillColorCmd(const QColor &color)
}
/**
* Activate the object after serializing it from a QDataStream
* Reimplemented from class WidgetBase
*
* @param ChangeLog
* @return true for success
*/
bool UMLWidget::activate(IDChangeLog* changeLog)
{
if (!WidgetBase::activate(changeLog))
return false;
DiagramProxyWidget::activate(changeLog);
if (widgetHasUMLObject(baseType()) && m_umlObject == 0) {
m_umlObject = m_doc->findObjectById(m_nId);
if (m_umlObject == 0) {
uError() << "cannot find UMLObject with id=" << Uml::ID::toString(m_nId);
return false;
}
}
setFontCmd(m_font);
setSize(width(), height());
m_activated = true;
......@@ -1709,29 +1700,6 @@ void UMLWidget::slotSnapToGrid()
}
}
/**
* Returns whether the widget type has an associated UMLObject
*/
bool UMLWidget::widgetHasUMLObject(WidgetBase::WidgetType type)
{
if (type == WidgetBase::wt_Actor ||
type == WidgetBase::wt_UseCase ||
type == WidgetBase::wt_Class ||
type == WidgetBase::wt_Interface ||
type == WidgetBase::wt_Enum ||
type == WidgetBase::wt_Datatype ||
type == WidgetBase::wt_Package ||
type == WidgetBase::wt_Component ||
type == WidgetBase::wt_Port ||
type == WidgetBase::wt_Node ||
type == WidgetBase::wt_Artifact ||
type == WidgetBase::wt_Object) {
return true;
} else {
return false;
}
}
/**
* Set m_ignoreSnapToGrid.
*/
......@@ -2059,7 +2027,6 @@ void UMLWidget::saveToXMI1(QDomDocument & qDoc, QDomElement & qElement)
*/
WidgetBase::saveToXMI1(qDoc, qElement);
DiagramProxyWidget::saveToXMI1(qDoc, qElement);
qElement.setAttribute(QLatin1String("xmi.id"), Uml::ID::toString(id()));
qreal dpiScale = UMLApp::app()->document()->dpiScale();
qElement.setAttribute(QLatin1String("x"), QString::number(x() / dpiScale));
......@@ -2076,9 +2043,6 @@ void UMLWidget::saveToXMI1(QDomDocument & qDoc, QDomElement & qElement)
bool UMLWidget::loadFromXMI1(QDomElement & qElement)
{
QString id = qElement.attribute(QLatin1String("xmi.id"), QLatin1String("-1"));
m_nId = Uml::ID::fromString(id);
WidgetBase::loadFromXMI1(qElement);
DiagramProxyWidget::loadFromXMI1(qElement);
QString x = qElement.attribute(QLatin1String("x"), QLatin1String("0"));
......
......@@ -179,8 +179,6 @@ public:
virtual void cleanup();
static bool widgetHasUMLObject(WidgetBase::WidgetType type);
void updateGeometry(bool withAssocs = true);
void clipSize();
......
......@@ -42,11 +42,12 @@
* @param type The WidgetType to construct. This must be set to the appropriate
* value by the constructors of inheriting classes.
*/
WidgetBase::WidgetBase(UMLScene *scene, WidgetType type)
WidgetBase::WidgetBase(UMLScene *scene, WidgetType type, Uml::ID::Type id)
: QGraphicsObject(),
m_baseType(type),
m_scene(scene),
m_umlObject(0),
m_nId(id == Uml::ID::None ? UniqueID::gen() : id),
m_nLocalID(UniqueID::gen()),
m_textColor(QColor("black")),
m_fillColor(QColor("yellow")),
......@@ -592,6 +593,7 @@ void WidgetBase::saveToXMI1(QDomDocument& qDoc, QDomElement& qElement)
{
Q_UNUSED(qDoc)
qElement.setAttribute(QLatin1String("xmi.id"), Uml::ID::toString(id()));
// Unique identifier for widget (todo: id() should be unique, new attribute
// should indicate the UMLObject's ID it belongs to)
qElement.setAttribute(QLatin1String("localid"), Uml::ID::toString(m_nLocalID));
......@@ -621,6 +623,50 @@ void WidgetBase::saveToXMI1(QDomDocument& qDoc, QDomElement& qElement)
qElement.setAttribute(QLatin1String("autoresize"), m_autoResize ? 1 : 0);
}
/**
* Returns whether the widget type has an associated UMLObject
*/
bool WidgetBase::widgetHasUMLObject(WidgetBase::WidgetType type)
{
if (type == WidgetBase::wt_Actor ||
type == WidgetBase::wt_UseCase ||
type == WidgetBase::wt_Class ||
type == WidgetBase::wt_Interface ||
type == WidgetBase::wt_Enum ||
type == WidgetBase::wt_Datatype ||
type == WidgetBase::wt_Package ||
type == WidgetBase::wt_Component ||
type == WidgetBase::wt_Port ||
type == WidgetBase::wt_Node ||
type == WidgetBase::wt_Artifact ||
type == WidgetBase::wt_Object) {
return true;
} else {
return false;
}
}
/**
* Activate the object after serializing it from a QDataStream
*
* @param ChangeLog
* @return true for success
*/
bool WidgetBase::activate(IDChangeLog* changeLog)
{
Q_UNUSED(changeLog);
if (widgetHasUMLObject(baseType()) && m_umlObject == nullptr) {
m_umlObject = UMLApp::app()->document()->findObjectById(m_nId);
if (m_umlObject == nullptr) {
uError() << "cannot find UMLObject with id=" << Uml::ID::toString(m_nId);
return false;
}
}
return true;
}
/**
* Adds an already created association to the list of
* associations that include this UMLWidget
......@@ -653,6 +699,9 @@ void WidgetBase::removeAssoc(AssociationWidget *pAssoc)
*/
bool WidgetBase::loadFromXMI1(QDomElement& qElement)
{
QString id = qElement.attribute(QLatin1String("xmi.id"), QLatin1String("-1"));
m_nId = Uml::ID::fromString(id);
QString localid = qElement.attribute(QLatin1String("localid"), QLatin1String("0"));
if (localid != QLatin1String("0")) {
m_nLocalID = Uml::ID::fromString(localid);
......
......@@ -39,6 +39,7 @@ class EnumWidget;
class FloatingDashLineWidget;
class FloatingTextWidget;
class ForkJoinWidget;
class IDChangeLog;
class InterfaceWidget;
class MessageWidget;
class NodeWidget;
......@@ -112,7 +113,7 @@ public:
static QString toI18nString(WidgetType wt);
static Icon_Utils::IconType toIcon(WidgetType wt);
explicit WidgetBase(UMLScene * scene, WidgetType type= wt_UMLWidget);
explicit WidgetBase(UMLScene * scene, WidgetType type= wt_UMLWidget, Uml::ID::Type id = Uml::ID::None);
virtual ~WidgetBase();
UMLObject* umlObject() const;
......@@ -264,6 +265,9 @@ public:
UseCaseWidget* asUseCaseWidget();
UMLWidget* asUMLWidget();
static bool widgetHasUMLObject(WidgetBase::WidgetType type);
virtual bool activate(IDChangeLog *changeLog = 0);
public Q_SLOTS:
virtual void slotMenuSelection(QAction *trigger);
......
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