[Uml-devel] branches/work/isi-umbrello/umbrello/umbrello

Florence Mattler florence.mattler at libertysurf.fr
Mon Jan 29 00:14:40 UTC 2007


SVN commit 628078 by mattler:

A precondition widget will now be drawn only by clicking on the line of an object widget. When the object widget is moved, the 
precondition widget move too. It can be saved and loaded with an XMI file.



 M  +1 -0      CMakeLists.txt  
 M  +137 -6    preconditionwidget.cpp  
 M  +48 -1     preconditionwidget.h  
 M  +5 -1      toolbarstatefactory.cpp  
 M  +1 -1      toolbarstatefactory.h  
 M  +4 -3      toolbarstateother.cpp  
 A             toolbarstatesequence.cpp   [License: GPL (v2+)]
 A             toolbarstatesequence.h   [License: GPL (v2+)]
 M  +2 -2      umlnamespace.h  
 M  +34 -2     umlview.cpp  
 M  +5 -0      umlwidget.cpp  


--- branches/work/isi-umbrello/umbrello/umbrello/CMakeLists.txt #628077:628078
@@ -325,6 +325,7 @@
    toolbarstatemessages.cpp 
    toolbarstateother.cpp 
    toolbarstatepool.cpp 
+   toolbarstatesequence.cpp 
    uml.cpp 
    umlattributelist.cpp 
    umlentityattributelist.cpp 
--- branches/work/isi-umbrello/umbrello/umbrello/preconditionwidget.cpp #628077:628078
@@ -27,24 +27,53 @@
 #include "umlview.h"
 #include "listpopupmenu.h"
 #include "dialogs/activitydialog.h"
+#include "objectwidget.h"
+#include "classifier.h"
+#include "uniqueid.h"
 
 //Added by qt3to4:
+//Added by qt3to4:
 #include <QMouseEvent>
 #include <QPolygon>
+#include <QMoveEvent>
+#include <QResizeEvent>
 
-PreconditionWidget::PreconditionWidget(UMLView * view, Uml::IDType id )
+PreconditionWidget::PreconditionWidget(UMLView * view, ObjectWidget* a, Uml::IDType id )
         : UMLWidget(view, id)
 {
-    UMLWidget::setBaseType( Uml::wt_Precondition );
+    init();
+    m_pOw[Uml::A] = a;
+    int y = getY();
+    m_nY = y;
+    //updateResizability();
     updateComponentSize();
+   // calculateWidget();
+    y = y < getMinY() ? getMinY() : y;
+    y = y > getMaxY() ? getMaxY() : y;
+    m_nY = y;
+    this->activate();
+    
 }
 
 PreconditionWidget::~PreconditionWidget() {}
 
+void PreconditionWidget::init() {
+    UMLWidget::setBaseType(Uml::wt_Precondition);
+    m_bIgnoreSnapToGrid = true;
+    m_bIgnoreSnapComponentSizeToGrid = true;
+    m_pOw[Uml::A] = NULL;
+    m_nY = 0;
+    setVisible(true);
+}
+
 void PreconditionWidget::draw(QPainter & p, int offsetX, int offsetY) {
     int w = width();
     int h = height();
-   
+
+    int x = m_pOw[Uml::A]->getX() + m_pOw[Uml::A]->getWidth() / 2;
+
+    x -= w/2;
+   // setX(x);
     UMLWidget::setPen(p);
     if ( UMLWidget::getUseFillColour() ) {
         p.setBrush( UMLWidget::getFillColour() );
@@ -55,15 +84,15 @@
 	const QString precondition_value = "{ " + getName() + " }";
         //int middleX = w / 2;
         int textStartY = (h / 2) - (fontHeight / 2);
-        p.drawRoundRect(offsetX, offsetY, w, h, (h * 60) / w, 60);
+        p.drawRoundRect(x, offsetY, w, h, (h * 60) / w, 60);
         p.setPen(Qt::black);
         p.setFont( UMLWidget::getFont() );
-        p.drawText(offsetX + PRECONDITION_MARGIN, offsetY + textStartY,
+        p.drawText(x + PRECONDITION_MARGIN, offsetY + textStartY,
                        w - PRECONDITION_MARGIN * 2, fontHeight, Qt::AlignCenter, precondition_value);
     }
     UMLWidget::setPen(p);
     if(m_bSelected)
-        drawSelected(&p, offsetX, offsetY);
+        drawSelected(&p, x, offsetY);
 }
 
 QSize PreconditionWidget::calculateSize() {
@@ -93,6 +122,7 @@
         if( ok && name.length() > 0 )
             m_Text = name;
         done = true;
+        calculateWidget();
         break;
 
     case ListPopupMenu::mt_Properties:
@@ -105,6 +135,88 @@
         UMLWidget::slotMenuSelection( sel );
 }
 
+void PreconditionWidget::calculateWidget() {
+    calculateDimensions();
+
+    setVisible(true);
+
+    setX(m_nPosX);
+    setY(m_nY);
+}
+
+void PreconditionWidget::activate(IDChangeLog * Log /*= 0*/) {
+    m_pView->resetPastePoint();
+    UMLWidget::activate(Log);
+    if (m_pOw[Uml::A] == NULL) {
+        kDebug() << "PreconditionWidget::activate: can't make precondition" << endl;
+        return;
+    }
+    
+    connect(m_pOw[Uml::A], SIGNAL(sigWidgetMoved(Uml::IDType)), this, SLOT(slotWidgetMoved(Uml::IDType)));
+    
+    calculateDimensions();
+}
+
+void PreconditionWidget::calculateDimensions() {
+    int x = 0;
+    int w = 0;
+    int h = 0;
+    int x1 = m_pOw[Uml::A]->getX();
+    int w1 = m_pOw[Uml::A]->getWidth() / 2;
+
+    x1 += w1;
+
+    QSize q = calculateSize();
+    w = q.width() > width() ? q.width() : width();
+    h = q.height() > height() ? q.height() : height();
+
+    x = x1 - w/2;
+
+    m_nPosX = x;
+    setSize(w,h);
+
+}
+
+void PreconditionWidget::slotWidgetMoved(Uml::IDType id) {
+    const Uml::IDType idA = m_pOw[Uml::A]->getLocalID();
+    if (idA != id ) {
+        kDebug() << "MessageWidget::slotWidgetMoved(" << ID2STR(id)
+            << "): ignoring for idA=" << ID2STR(idA) << endl;
+        return;
+    }
+    m_nY = getY();
+    if (m_nY < getMinY())
+        m_nY = getMinY();
+    if (m_nY > getMaxY())
+        m_nY = getMaxY();
+    calculateWidget();
+      if (m_pView->getSelectCount(true) > 1)
+        return;
+   // setTextPosition();
+}
+
+
+int PreconditionWidget::getMinY() {
+    if (!m_pOw[Uml::A]) {
+        return 0;
+    }
+
+    int heightA = m_pOw[Uml::A]->getY() + m_pOw[Uml::A]->getHeight();
+    int height = heightA;
+    return height;
+}
+
+int PreconditionWidget::getMaxY() {
+    if( !m_pOw[Uml::A]) {
+        return 0;
+    }
+
+    int heightA = (int)((ObjectWidget*)m_pOw[Uml::A])->getEndLineY();
+    int height = heightA;
+    return (height - this->height());
+}
+
+
 bool PreconditionWidget::showProperties() {
     /*DocWindow *docwindow = UMLApp::app()->getDocWindow();
     docwindow->updateDocumentation(false);
@@ -124,6 +236,7 @@
 void PreconditionWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
     QDomElement preconditionElement = qDoc.createElement( "preconditionwidget" );
     UMLWidget::saveToXMI( qDoc, preconditionElement );
+    preconditionElement.setAttribute( "widgetaid", ID2STR(m_pOw[Uml::A]->getLocalID()) );
     preconditionElement.setAttribute( "preconditionname", m_Text );
     preconditionElement.setAttribute( "documentation", m_Doc );
     qElement.appendChild( preconditionElement );
@@ -132,8 +245,26 @@
 bool PreconditionWidget::loadFromXMI( QDomElement & qElement ) {
     if( !UMLWidget::loadFromXMI( qElement ) )
         return false;
+    QString widgetaid = qElement.attribute( "widgetaid", "-1" );
     m_Text = qElement.attribute( "preconditionname", "" );
     m_Doc = qElement.attribute( "documentation", "" );
+
+    Uml::IDType aId = STR2ID(widgetaid);
+    
+    UMLWidget *pWA = m_pView -> findWidget( aId );
+    if (pWA == NULL) {
+        kDebug() << "PreconditionWidget::loadFromXMI: role A object "
+        << ID2STR(aId) << " not found" << endl;
+        return false;
+    }
+
+    m_pOw[Uml::A] = dynamic_cast<ObjectWidget*>(pWA);
+    if (m_pOw[Uml::A] == NULL) {
+        kDebug() << "PreconditionWidget::loadFromXMI: role A widget "
+        << ID2STR(aId) << " is not an ObjectWidget" << endl;
+        return false;
+    }
+
     return true;
 }
 
--- branches/work/isi-umbrello/umbrello/umbrello/preconditionwidget.h #628077:628078
@@ -19,6 +19,9 @@
 #define PRECONDITION_WIDTH 30
 #define PRECONDITION_HEIGHT 10
 
+class ObjectWidget;
+class UMLOperation;
+
 /**
  * This class is the graphical version of a UML Precondition.  A PreconditionWidget is created
  * by a @ref UMLView.  An PreconditionWidget belongs to only one @ref UMLView instance.
@@ -40,9 +43,10 @@
      * Creates a Precondition widget.
      *
      * @param view              The parent of the widget.
+     * @param a			The role A widget for this precondition.
      * @param id                The ID to assign (-1 will prompt a new ID.)
      */
-    PreconditionWidget( UMLView * view, Uml::IDType id = Uml::id_None );
+    PreconditionWidget( UMLView * view, ObjectWidget* a, Uml::IDType id = Uml::id_None );
 
 
     /**
@@ -51,6 +55,11 @@
     virtual ~PreconditionWidget();
 
     /**
+     * Initializes key variables of the class.
+     */
+    void init();
+
+    /**
      * Overrides the standard paint event.
      */
     void draw(QPainter & p, int offsetX, int offsetY);
@@ -63,8 +72,41 @@
      */
     bool showProperties();
 
+    /**
+     * Calculate the geometry of the widget.
+     */
+    void calculateWidget();
 
     /**
+     * Activates a MessageWidget.  Connects its m_pOw[] pointers
+     * to UMLObjects and also send signals about its FloatingTextWidget.
+     */
+    void activate(IDChangeLog * Log = 0);
+
+    /**
+     * Calculates the size of the widget by calling
+     * calculateDimenstionsSynchronous(),
+     * calculateDimenstionsAsynchronous(), or
+     * calculateDimensionsCreation()
+     */
+     void calculateDimensions();
+
+
+    /**
+     * Returns the minimum height this widget should be set at on
+     * a sequence diagrams.  Takes into account the widget positions
+     * it is related to.
+     */
+    int getMinY();
+
+    /**
+     * Returns the maximum height this widget should be set at on
+     * a sequence diagrams.  Takes into account the widget positions
+     * it is related to.
+     */
+    int getMaxY();
+
+    /**
      * Saves the widget to the <preconditionwidget> XMI element.
      */
     void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
@@ -87,6 +129,11 @@
      * Captures any popup menu signals for menus it created.
      */
     void slotMenuSelection(int sel);
+    void slotWidgetMoved(Uml::IDType id);
+
+private:
+    ObjectWidget * m_pOw[1];
+    int m_nY;
 };
 
 #endif
--- branches/work/isi-umbrello/umbrello/umbrello/toolbarstatefactory.cpp #628077:628078
@@ -16,6 +16,7 @@
 #include "toolbarstatearrow.h"
 #include "toolbarstatemessages.h"
 #include "toolbarstateassociation.h"
+#include "toolbarstatesequence.h"
 
 #include "umlview.h"
 
@@ -54,11 +55,12 @@
 
             // This case has no pool.
         case 3: states[3] = new ToolBarStateArrow(m_pUMLView); break;
+	case 4: states[4] = new ToolBarStateSequence(m_pUMLView); break;
         }
     }
 
     // Make explicit the selected button. This is only necessary for states with a pool.
-    if (key <= 2) ((ToolBarStatePool *) states[key])->setButton(toolbarButton);
+    if (key != 3) ((ToolBarStatePool *) states[key])->setButton(toolbarButton);
 
     return states[key];
 }
@@ -88,6 +90,8 @@
     case WorkToolBar::tbb_Seq_Message_Found: 	    return 2;
     case WorkToolBar::tbb_Seq_Message_Lost: 	    return 2;
     
+    case WorkToolBar::tbb_Seq_Precondition: return 4;
+    
     	// Arrow pointer
     case WorkToolBar::tbb_Arrow: return 3;
 
--- branches/work/isi-umbrello/umbrello/umbrello/toolbarstatefactory.h #628077:628078
@@ -16,7 +16,7 @@
 
 #include "worktoolbar.h"
 
-#define NR_OF_TOOLBAR_STATES 4
+#define NR_OF_TOOLBAR_STATES 5
 
 class UMLView;
 
--- branches/work/isi-umbrello/umbrello/umbrello/toolbarstateother.cpp #628077:628078
@@ -31,6 +31,7 @@
 #include "uml.h"
 #include "umlview.h"
 #include "umldoc.h"
+#include "objectwidget.h"
 
 using namespace Uml;
 
@@ -105,9 +106,9 @@
             umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::Normal);
             break;
 
-	case WorkToolBar::tbb_Seq_Precondition:
-            umlWidget = new PreconditionWidget(m_pUMLView);
-            break;
+	//case WorkToolBar::tbb_Seq_Precondition:
+         //   umlWidget = new PreconditionWidget(m_pUMLView,static_cast<ObjectWidget*>(getCurrentWidget()));
+          //  break;
 
         case WorkToolBar::tbb_End_Activity:
             umlWidget = new ActivityWidget(m_pUMLView, ActivityWidget::End);
--- branches/work/isi-umbrello/umbrello/umbrello/umlnamespace.h #628077:628078
@@ -279,8 +279,8 @@
     sequence_message_synchronous = 1000,
     sequence_message_asynchronous,
     sequence_message_creation,
-    sequence_message_found,
-    sequence_message_lost
+    sequence_message_lost,
+    sequence_message_found
 };
 
 enum DBIndex_Type
--- branches/work/isi-umbrello/umbrello/umbrello/umlview.cpp #628077:628078
@@ -98,6 +98,7 @@
 #include "object_factory.h"
 #include "umlwidget.h"
 #include "toolbarstatefactory.h"
+#include "preconditionwidget.h"
 
 
 // control the manual DoubleBuffering of QCanvas
@@ -1594,6 +1595,32 @@
         }
         break;
 
+    case wt_Precondition:
+        {
+            ObjectWidget* pObjectWidget = static_cast<ObjectWidget*>(pWidget);
+            if (pObjectWidget == NULL) {
+                kDebug() << "UMLView::addWidget(): pObjectWidget is NULL" << endl;
+                return false;
+            }
+            Uml::IDType newID = log->findNewID( pWidget -> getID() );
+            if (newID == Uml::id_None) {
+                return false;
+            }
+            pObjectWidget -> setID( newID );
+            Uml::IDType nNewLocalID = getLocalID();
+            Uml::IDType nOldLocalID = pObjectWidget -> getLocalID();
+            m_pIDChangesLog->addIDChange( nOldLocalID, nNewLocalID );
+            pObjectWidget -> setLocalID( nNewLocalID );
+            UMLObject *pObject = m_pDoc -> findObjectById( newID );
+            if( !pObject ) {
+                kDebug() << "addWidget::Can't find UMLObject" << endl;
+                return false;
+            }
+            pWidget -> setUMLObject( pObject );
+            m_WidgetList.append( pWidget );
+        }
+        break;
+
     default:
         kDebug() << "Trying to add an invalid widget type" << endl;
         return false;
@@ -3090,7 +3117,7 @@
 }
 
 UMLWidget* UMLView::loadWidgetFromXMI(QDomElement& widgetElement) {
-
+    UMLWidget* widget = 0;
     if ( !m_pDoc ) {
         kWarning() << "UMLView::loadWidgetFromXMI(): m_pDoc is NULL" << endl;
         return 0L;
@@ -3098,7 +3125,12 @@
 
     QString tag  = widgetElement.tagName();
     QString idstr  = widgetElement.attribute( "xmi.id", "-1" );
-    UMLWidget* widget = Widget_Factory::makeWidgetFromXMI(tag, idstr, this);
+    if (tag == "preconditionwidget") {
+	widget = new PreconditionWidget(this,NULL,Uml::id_Reserved);
+    }
+    else {
+	widget = Widget_Factory::makeWidgetFromXMI(tag, idstr, this);
+    }
     if (widget == NULL)
         return NULL;
     if (!widget->loadFromXMI(widgetElement)) {
--- branches/work/isi-umbrello/umbrello/umbrello/umlwidget.cpp #628077:628078
@@ -500,6 +500,11 @@
         if( m_pView -> getType() == dt_Sequence ) {
             switch( getBaseType() ) {
             case wt_Object:
+	    case wt_Precondition : 
+		setY( getY() );
+                setX( x );
+                break; 
+
             case wt_Message:
                 setY( getY() );
                 setX( x );




More information about the umbrello-devel mailing list