[Uml-devel] branches/work/soc-umbrello/umbrello
Gopala Krishna A
krishna.ggk at gmail.com
Sat Aug 29 19:01:21 UTC 2009
SVN commit 1017131 by gopala:
* Improvised load/save code of WidgetBase, UMLWidget a bit.
* Implement activate() method for UMLWidget and WidgetBase.
M +10 -16 umlscene.cpp
M +7 -5 widgets/associationwidget.cpp
M +1 -1 widgets/associationwidget.h
M +12 -1 widgets/umlwidget.cpp
M +1 -0 widgets/umlwidget.h
M +81 -37 widgets/widgetbase.cpp
M +1 -1 widgets/widgetbase.h
--- branches/work/soc-umbrello/umbrello/umlscene.cpp #1017130:1017131
@@ -1507,15 +1507,16 @@
//Activate Regular widgets then activate messages
foreach(UMLWidget* obj , m_WidgetList) {
//If this UMLWidget is already activated or is a MessageWidget then skip it
- if (/* [PORT] obj->isActivated() || */ obj->baseType() == wt_Message)
+ if (obj->isActivated() || obj->baseType() == wt_Message) {
continue;
+ }
-// [PORT] if (obj->activate(0)) {
- obj->setVisible(true);
-// } else {
-// m_WidgetList.removeAll(obj);
-// delete obj;
-// }
+ if (obj->activate()) {
+ obj->setVisible(true);
+ } else {
+ m_WidgetList.removeAll(obj);
+ delete obj;
+ }
}//end foreach
//Activate Message widgets
@@ -1532,21 +1533,14 @@
// Activate all association widgets
- // [PORT]
-#if 0
foreach(AssociationWidget* aw , m_AssociationList) {
if (aw->activate()) {
- if (m_PastePoint.x() != 0.) {
- qreal x = m_PastePoint.x() - m_Pos.x();
- qreal y = m_PastePoint.y() - m_Pos.y();
- aw->moveEntireAssoc(x, y);
- }
+ aw->setVisible(true);
} else {
m_AssociationList.removeAll(aw);
- delete aw;
+ delete aw;
}
}
-#endif
}
/**
--- branches/work/soc-umbrello/umbrello/widgets/associationwidget.cpp #1017130:1017131
@@ -898,16 +898,17 @@
return m_associationLine;
}
-void AssociationWidget::activate()
+bool AssociationWidget::activate()
{
Q_ASSERT(umlScene());
setActivatedFlag(false);
- if (!umlObject() &&
- UMLAssociation::assocTypeHasUMLRepresentation(associationType())) {
+ bool hasUMLRepresentation =
+ UMLAssociation::assocTypeHasUMLRepresentation(associationType());
+ if (!umlObject() && hasUMLRepresentation) {
UMLObject *myObj = umlDoc()->findObjectById(id());
if (!myObj) {
uError() << "cannot find UMLObject " << ID2STR(id());
- return;
+ return false;
} else {
setUMLObject(myObj);
setAssociationType(associationType());
@@ -924,7 +925,7 @@
if (!widgetForRole(Uml::A) || !widgetForRole(Uml::B)) {
- return;
+ return false;
}
// TODO: Check whether this comment should be removed.
@@ -967,6 +968,7 @@
m_associationLine->calculateAssociationClassLine();
setActivatedFlag(true);
+ return true;
}
QRectF AssociationWidget::boundingRect() const
--- branches/work/soc-umbrello/umbrello/widgets/associationwidget.h #1017130:1017131
@@ -132,7 +132,7 @@
AssociationLine* associationLine() const;
- virtual void activate();
+ virtual bool activate();
virtual QRectF boundingRect() const;
virtual QPainterPath shape() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem* opt, QWidget*);
--- branches/work/soc-umbrello/umbrello/widgets/umlwidget.cpp #1017130:1017131
@@ -219,6 +219,17 @@
return m_associationSpaceManager;
}
+bool UMLWidget::activate()
+{
+ bool activated = WidgetBase::activate();
+ if (!activated) {
+ return false;
+ }
+ setSize(m_size);
+ updateGeometry();
+ return true;
+}
+
/**
* Adjusts the position and lines of connected association
* widgets. This method is used usually after this widget moves
@@ -251,7 +262,7 @@
}
m_size.setWidth(w);
m_size.setHeight(h);
- updateGeometry(); // Force updation of the shape as well.
+ setSize(m_size);
QString instName = qElement.attribute("instancename", QString());
setInstanceName(instName);
--- branches/work/soc-umbrello/umbrello/widgets/umlwidget.h #1017130:1017131
@@ -150,6 +150,7 @@
AssociationSpaceManager* associationSpaceManager() const;
AssociationWidgetList associationWidgetList() const;
+ virtual bool activate();
virtual void adjustAssociations();
virtual void showPropertiesDialog();
--- branches/work/soc-umbrello/umbrello/widgets/widgetbase.cpp #1017130:1017131
@@ -564,12 +564,28 @@
*
* By default, this method just sets the flag to true.
*
+ * @return The new activation status.
+ *
* @see WidgetBase::m_activated to understand what activation means.
* @sa WidgetBase::setActivatedFlag
*/
-void WidgetBase::activate()
+bool WidgetBase::activate()
{
- m_activated = true;
+ Q_ASSERT(umlScene());
+ // Reset flag, because you might be "reactivating" this widget in which case
+ // the new activation status needs to be held.
+ m_activated = false;
+ if (widgetHasUMLObject(baseType()) && !m_umlObject) {
+ m_umlObject = umlDoc()->findObjectById(id());
+ if (!m_umlObject) {
+ uError() << "cannot find UMLObject with id=" << ID2STR(id());
+ } else {
+ m_activated = true;
+ }
+ } else {
+ m_activated = true;
+ }
+ return m_activated;
}
/**
@@ -596,64 +612,88 @@
bool WidgetBase::loadFromXMI(QDomElement &qElement)
{
Q_ASSERT(umlScene());
- // NOTE:
- // The "none" is used by kde3 version of umbrello. The current
- // technique to determine whether a property is being used from
- // the diagram or not is just to compare the same, rather than
- // having flags for them.
- //
- // This way, there is no burden to update the flags and the code
- // is more robust.
const QLatin1String none("none");
// Load the line color first
// Workaround for old "linecolour" usage.
- QString lineColor = qElement.attribute("linecolour");
+ QString lineColor = qElement.attribute("linecolour", none);
lineColor = qElement.attribute("linecolor", lineColor);
- if(!lineColor.isEmpty() && lineColor != none) {
+ if (lineColor != none) {
+ m_usesDiagramLineColor = false;
setLineColor(QColor(lineColor));
- }
- else if(umlScene()) {
+ } else {
+ m_usesDiagramLineColor = true;
setLineColor(umlScene()->getLineColor());
}
// Load the line width.
- QString lineWidth = qElement.attribute("linewidth");
- if(!lineWidth.isEmpty() && lineWidth != none) {
+ QString lineWidth = qElement.attribute("linewidth", none);
+ if(lineWidth != none) {
+ m_usesDiagramLineWidth = false;
setLineWidth(lineWidth.toInt());
}
- else if(umlScene()) {
+ else {
+ m_usesDiagramLineWidth = true;
setLineWidth(umlScene()->getLineWidth());
}
// Load the font color, if invalid black is used.
- QString textColor = qElement.attribute("textcolor");
- setTextColor(QColor(textColor));
+ QString textColor = qElement.attribute("textcolor", none);
+ if (textColor != none) {
+ m_usesDiagramTextColor = false;
+ setTextColor(QColor(textColor));
+ } else {
+ m_usesDiagramTextColor = true;
+ setTextColor(umlScene()->getTextColor());
+ }
// Load the brush.
- QBrush newBrush;
QDomElement brushElement = qElement.firstChildElement("brush");
- bool brushSet = Widget_Utils::loadBrushFromXMI(brushElement, newBrush);
+ int usesDiagramBrush = qElement.attribute("usesdiagrambrush", "-1").toInt();
+ if (!brushElement.isNull() || usesDiagramBrush != -1) {
+ if (usesDiagramBrush == 0 || brushElement.isNull()) {
+ m_usesDiagramBrush = true;
+ setBrush(umlScene()->brush());
+ } else {
+ QBrush newBrush;
+ bool brushSet = Widget_Utils::loadBrushFromXMI(brushElement, newBrush);
+ if (!brushSet) {
+ uError() << "Could not load brush from XMI file";
+ m_usesDiagramBrush = true;
+ setBrush(umlScene()->brush());
+ } else {
+ m_usesDiagramBrush = false;
+ }
+ }
+ } else {
+ // If control is here,
+ // we are loading a file saved using older version mostly.
- // If this fails, we try to load fillColor attribute which is used in kde3 version of umbrello.
- if(!brushSet) {
- // Workaround for old "fillcolour" usage.
- QString fillColor = qElement.attribute("fillcolour");
- fillColor = qElement.attribute("fillcolor");
+ bool useFillColor = false;
+ QString usesDiagramUseFillColor = qElement.attribute("usesdiagramusefillcolour", "1");
+ usesDiagramUseFillColor = qElement.attribute("usesdiagramusefillcolor", usesDiagramUseFillColor);
+ if (usesDiagramUseFillColor.toInt()) {
+ useFillColor = (umlScene()->brush().style() != Qt::NoBrush);
+ } else {
+ useFillColor = (qElement.attribute("usefillcolor", "1").toInt() != 0);
+ }
- if(!fillColor.isEmpty() && fillColor != none) {
- setBrush(QColor(fillColor));
- brushSet = true;
+ if (useFillColor == false) {
+ m_usesDiagramBrush = false;
+ setBrush(QBrush(Qt::NoBrush));
+ } else {
+ QString fillColor = qElement.attribute("fillcolour", "none");
+ fillColor = qElement.attribute("fillcolor", fillColor);
+ if (fillColor != none) {
+ m_usesDiagramBrush = false;
+ setBrush(QBrush(QColor(fillColor)));
+ } else {
+ m_usesDiagramBrush = true;
+ setBrush(umlScene()->brush());
+ }
}
}
- else {
- setBrush(newBrush);
- }
- // Set the diagram's brush if it is not yet set.
- if(!brushSet && umlScene()) {
- setBrush(umlScene()->brush());
- }
// Load the font.
QString font = qElement.attribute(QLatin1String("font"));
@@ -661,6 +701,7 @@
if(!font.isEmpty()) {
fontSet = m_font.fromString(font);
if(fontSet) {
+ m_usesDiagramFont = false;
setFont(m_font);
}
else {
@@ -668,7 +709,8 @@
}
}
// Set diagram's default font if font is not yet set.
- if(!fontSet && umlScene()) {
+ if(!fontSet) {
+ m_usesDiagramFont = true;
setFont(umlScene()->font());
}
@@ -678,9 +720,11 @@
if(id != ID2STR(this->id())) {
uWarning() << "ID mismatch between UMLWidget and its UMLObject"
<< "So the id read will be ignored.";
+ // Do not set mismatching id.
}
}
else {
+ // store it to possibly load associated UMLObject if any while activation.
setID(STR2ID(id));
}
--- branches/work/soc-umbrello/umbrello/widgets/widgetbase.h #1017130:1017131
@@ -140,7 +140,7 @@
bool isActivated() const;
void setActivatedFlag(bool value);
- virtual void activate();
+ virtual bool activate();
virtual void showPropertiesDialog();
More information about the umbrello-devel
mailing list