[Uml-devel] branches/work/soc-umbrello/umbrello
Gopala Krishna A
krishna.ggk at gmail.com
Mon Aug 24 18:25:05 UTC 2009
SVN commit 1015166 by gopala:
Fixed some differences in loading code of AssociationLine. Umbrello soc now
loads models/Overview.xmi files (there are lots of variations though).
M +1 -0 umlscene.cpp
M +52 -16 widgets/associationline.cpp
M +6 -0 widgets/associationwidget.cpp
--- branches/work/soc-umbrello/umbrello/umlscene.cpp #1015165:1015166
@@ -3747,6 +3747,7 @@
tag == "UML:AssocWidget") { // for bkwd compatibility
countr++;
AssociationWidget *assoc = new AssociationWidget();
+ addItem(assoc);
if (!assoc->loadFromXMI(assocElement)) {
uError() << "could not loadFromXMI association widget:"
<< (void*)assoc << ", bad XMI file? Deleting from umlview.";
--- branches/work/soc-umbrello/umbrello/widgets/associationline.cpp #1015165:1015166
@@ -293,7 +293,6 @@
/// Destructor
AssociationLine::~AssociationLine()
{
- uDebug() << "Destroyed";
}
/// @return The point at given index.
@@ -502,19 +501,46 @@
*/
bool AssociationLine::loadFromXMI(QDomElement &qElement)
{
- if (!qElement.hasChildNodes()) {
+ QDomNode node = qElement.firstChild();
+
+ m_points.clear();
+
+ QDomElement startElement = node.toElement();
+ if(startElement.isNull() || startElement.tagName() != "startpoint") {
return false;
}
+ QPointF startPoint;
+ startPoint.rx() = startElement.attribute("startx", "0").toDouble();
+ startPoint.ry() = startElement.attribute("starty", "0").toDouble();
+ startPoint = m_associationWidget->mapFromScene(startPoint);
- QDomNodeList domNodes = qElement.childNodes();
- for (int i = 0; i < domNodes.size(); ++i) {
- QDomElement ele = domNodes.at(i).toElement();
- qreal x = ele.attribute("x", "0").toDouble();
- qreal y = ele.attribute("y", "0").toDouble();
- insertPoint(i, QPointF(x, y));
- ++i;
+ node = startElement.nextSibling();
+
+ QDomElement endElement = node.toElement();
+ if(endElement.isNull() || endElement.tagName() != "endpoint") {
+ return false;
}
+ QPointF endPoint;
+ endPoint.rx() = endElement.attribute("endx", "0").toDouble();
+ endPoint.ry() = endElement.attribute("endy", "0").toDouble();
+ endPoint = m_associationWidget->mapFromScene(endPoint);
+ setEndPoints(startPoint, endPoint);
+
+ QPointF point;
+ node = endElement.nextSibling();
+ QDomElement element = node.toElement();
+ int i = 1;
+ while(!element.isNull()) {
+ if(element.tagName() == "point") {
+ point.rx() = element.attribute("x", "0").toDouble();
+ point.ry() = element.attribute("y", "0").toDouble();
+ insertPoint(i++, m_associationWidget->mapFromScene(point));
+ }
+ node = element.nextSibling();
+ element = node.toElement();
+ }
+
return true;
}
@@ -524,15 +550,25 @@
*/
void AssociationLine::saveToXMI(QDomDocument &qDoc, QDomElement &qElement)
{
- QDomElement pathElement = qDoc.createElement("linepath");
- for (int i = 0; i < m_points.size(); ++i ) {
+ QPointF point = m_associationWidget->mapToScene(startPoint());
+ QDomElement lineElement = qDoc.createElement("linepath");
+ QDomElement startElement = qDoc.createElement("startpoint");
+ startElement.setAttribute("startx", point.x());
+ startElement.setAttribute("starty", point.y());
+ lineElement.appendChild(startElement);
+ QDomElement endElement = qDoc.createElement("endpoint");
+ point = m_associationWidget->mapToScene(endPoint());
+ endElement.setAttribute("endx", point.x());
+ endElement.setAttribute("endy", point.y());
+ lineElement.appendChild(endElement);
+ for(int i = 1; i < count()-1; ++i) {
QDomElement pointElement = qDoc.createElement("point");
- const QPointF &point = m_points.at(i);
- pointElement.setAttribute( "x", point.x() );
- pointElement.setAttribute( "y", point.y() );
- pathElement.appendChild(pointElement);
+ point = m_associationWidget->mapToScene(this->point(i));
+ pointElement.setAttribute("x", point.x());
+ pointElement.setAttribute("y", point.y());
+ lineElement.appendChild(pointElement);
}
- qElement.appendChild(pathElement);
+ qElement.appendChild(lineElement);
}
QPen AssociationLine::pen() const
--- branches/work/soc-umbrello/umbrello/widgets/associationwidget.cpp #1015165:1015166
@@ -380,6 +380,10 @@
const uint numSegments = m_associationLine->count()-1;
const uint lastSegmentIndex = numSegments-1;
+ if (numSegments == 0) {
+ uError() << "Called when it had zero segments";
+ return;
+ }
QPointF p0, p1;
switch (tr) {
case Uml::tr_RoleAName:
@@ -458,6 +462,8 @@
s->addItem(eellipse);
s->addItem(lline);
}
+ eellipse->hide();
+ lline->hide();
QRectF r(0, 0, 2 * radius, 2 * radius);
r.moveCenter(mid);
More information about the umbrello-devel
mailing list