[Uml-devel] branches/work/soc-umbrello/umbrello
Gopala Krishna A
krishna.ggk at gmail.com
Sun Jun 14 17:13:42 UTC 2009
SVN commit 981992 by gopala:
* Added New::AssociationWidget::isSelf() method to detect self associations.
* Renamed referencePoint() to referencePoints() and make it return PointPair,
which will be useful to handle self associations arrangement.
M +36 -25 associationspacemanager.cpp
M +3 -1 associationspacemanager.h
M +5 -0 widgets/newassociationwidget.cpp
M +1 -0 widgets/newassociationwidget.h
--- branches/work/soc-umbrello/umbrello/associationspacemanager.cpp #981991:981992
@@ -104,40 +104,51 @@
}
/**
- * This method returns the point for given \a assoc which acts as reference
+ * This method returns the points for given \a assoc which acts as reference
* for arranging the association widget lines of particular region.
*
- * The reference point is either the penultimate point or other widget's center
+ * In case of non-self association,
+ * the reference point is either the penultimate point or other widget's center
* based on whether number of points is greater than two or equal to two
- * respectively.
+ * respectively, and is stored in PointPair.first.
+ *
+ * In case of self associations,
+ * the reference point pair is always the penultimate points from both ends as
+ * a self association line has atleast 4 points.
*/
-QPointF AssociationSpaceManager::referencePoint(New::AssociationWidget *assoc) const
+PointPair AssociationSpaceManager::referencePoints(New::AssociationWidget *assoc) const
{
UMLWidget *widA = assoc->widgetForRole(Uml::A);
UMLWidget *widB = assoc->widgetForRole(Uml::B);
- QPointF retVal;
- const int pointCount = assoc->associationLine()->count();
- Q_ASSERT(pointCount >= 2);
- if (pointCount == 2) {
- if (widA == m_umlWidget) {
- retVal = widB->sceneRect().center();
- } else if (widB == m_umlWidget) {
- retVal = widA->sceneRect().center();
+ New::AssociationLine *line = assoc->associationLine();
+ if (!assoc->isSelf()) {
+ QPointF retVal;
+ Q_ASSERT(line->count() >= 2);
+ if (line->count() == 2) {
+ if (widA == m_umlWidget) {
+ retVal = widB->sceneRect().center();
+ } else if (widB == m_umlWidget) {
+ retVal = widA->sceneRect().center();
+ } else {
+ uWarning() << "Passed association " << assoc->name()
+ << " is not managed by this AssociationSpaceManager";
+ }
} else {
- uWarning() << "Passed association " << assoc->name()
- << " is not managed by this AssociationSpaceManager";
+ if (widA == m_umlWidget) {
+ retVal = assoc->mapToScene(line->point(1));
+ } else if (widB == m_umlWidget) {
+ retVal = assoc->mapToScene(line->point(line->count()-2));
+ } else {
+ uWarning() << "Passed association " << assoc->name()
+ << " is not managed by this AssociationSpaceManager";
+ }
}
+
+ return PointPair(retVal, QPointF());
} else {
- if (widA == m_umlWidget) {
- retVal = assoc->mapToScene(assoc->associationLine()->point(1));
- } else if (widB == m_umlWidget) {
- retVal = assoc->mapToScene(assoc->associationLine()->point(pointCount-2));
- } else {
- uWarning() << "Passed association " << assoc->name()
- << " is not managed by this AssociationSpaceManager";
- }
+ Q_ASSERT(line->count() >= 4);
+ return PointPair(line->point(1), line->point(line->count()-2));
}
- return retVal;
}
/**
@@ -145,7 +156,7 @@
* regions based on its x or y value of the reference point depending upon
* the region.
*
- * @see AssociationSpaceManager::referencePoint
+ * @see AssociationSpaceManager::referencePoints
* @note Refer @ref RegionPair to understand why pair is used.
*/
void AssociationSpaceManager::arrange(RegionPair regions)
@@ -169,7 +180,7 @@
// manner based on pair.second variable.
foreach (New::AssociationWidget* assoc, listRef) {
// Obtain reference point first.
- QPointF lineStart = referencePoint(assoc);
+ QPointF lineStart = referencePoints(assoc).first;
// Get x or y coord based on xBasis variable.
qreal distance = (xBasis ? lineStart.x() : lineStart.y());
int i = 0;
--- branches/work/soc-umbrello/umbrello/associationspacemanager.h #981991:981992
@@ -53,6 +53,8 @@
int id() const;
};
+typedef QPair<QPointF, QPointF> PointPair;
+
/**
* @short A class to manage distribution of AssociationWidget around UMLWidget.
*
@@ -82,7 +84,7 @@
QSet<New::AssociationWidget*> associationWidgets() const;
private:
- QPointF referencePoint(New::AssociationWidget *assoc) const;
+ PointPair referencePoints(New::AssociationWidget *assoc) const;
QMap<RegionPair, QList<New::AssociationWidget*> > m_regionsAssociationsMap;
QSet<New::AssociationWidget*> m_registeredAssociationSet;
--- branches/work/soc-umbrello/umbrello/widgets/newassociationwidget.cpp #981991:981992
@@ -465,6 +465,11 @@
return Uml::A; // unreachable.
}
+ bool AssociationWidget::isSelf() const
+ {
+ return widgetForRole(Uml::A) == widgetForRole(Uml::B);
+ }
+
UMLWidget* AssociationWidget::widgetForRole(Uml::Role_Type role) const
{
return m_widgetRole[role].umlWidget;
--- branches/work/soc-umbrello/umbrello/widgets/newassociationwidget.h #981991:981992
@@ -107,6 +107,7 @@
void setRoleName (const QString &strRole, Uml::Role_Type role);
Uml::Role_Type roleForWidget(UMLWidget *widget) const;
+ bool isSelf() const;
UMLWidget* widgetForRole(Uml::Role_Type role) const;
void setWidgetForRole(UMLWidget *widget, Uml::Role_Type role);
More information about the umbrello-devel
mailing list