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

Florence Mattler florence.mattler at libertysurf.fr
Mon Jan 29 22:23:17 UTC 2007


SVN commit 628376 by mattler:

Lost messages and found messages in sequence diagram are now only linked with one widget. the user click on a widget and on a point in uml view for 
a lost message and he click first on a point in the UML view and then on a widget for found message.


 M  +36 -55    messagewidget.cpp  
 M  +7 -0      messagewidget.h  
 M  +63 -6     toolbarstatemessages.cpp  
 M  +7 -0      toolbarstatemessages.h  
 M  +13 -0     toolbarstatesequence.cpp  
 M  +6 -2      widget_factory.cpp  


--- branches/work/isi-umbrello/umbrello/umbrello/messagewidget.cpp #628375:628376
@@ -19,6 +19,7 @@
 //kde includes
 #include <kdebug.h>
 #include <kcursor.h>
+#include <kmessagebox.h>
 //app includes
 #include "messagewidget.h"
 #include "messagewidgetcontroller.h"
@@ -263,47 +264,35 @@
 
 void MessageWidget::drawLost(QPainter& p, int offsetX, int offsetY){
     int x1 = m_pOw[Uml::A]->getX();
-    int x2 = m_pOw[Uml::B]->getX();
-    int w = getWidth() - 1;
+    int x2 = xclicked;
+    int w1 = m_pOw[Uml::A]->getWidth() / 2;
+    x1 += w1;
+
+    int w = x1 < x2 ? x2 - x1 : x1 - x2 ;
+
     int h = getHeight() - 1;
     bool messageOverlapsA = m_pOw[Uml::A] -> messageOverlap( getY(), this );
     //bool messageOverlapsB = m_pOw[Uml::B] -> messageOverlap( getY(), this );
 
-    if(m_pOw[Uml::A] == m_pOw[Uml::B]) {
-        if (messageOverlapsA)  {
+    if(x1 < x2) {
+	if (messageOverlapsA)  {
             offsetX += 7;
             w -= 7;
         }
-        const int lowerLineY = offsetY + h - 3;
-        // draw upper line segment (leaving the life line)
-        p.drawLine(offsetX, offsetY, offsetX + w, offsetY);
-        // draw line segment parallel to (and at the right of) the life line
-        p.drawLine(offsetX + w, offsetY, offsetX + w, lowerLineY);
-        // draw lower line segment (back to the life line)
-        drawArrow(p, offsetX, lowerLineY, w, Qt::LeftArrow);
-        if (messageOverlapsA)  {
-            offsetX -= 7; //reset for drawSelected()
-        }
-    } else if(x1 < x2) {
-        if (messageOverlapsA)  {
-            offsetX += 7;
-            w -= 7;
-        }
-	UMLWidget::setPen(p);
+
+        UMLWidget::setPen(p);
         p.setBrush( WidgetBase::getLineColor() );
-        drawArrow(p, offsetX, offsetY + 4, w, Qt::RightArrow);
-	p.drawEllipse(offsetX + w , offsetY - 3, h + 6, h + 6);
+        drawArrow(p,offsetX, offsetY, w, Qt::RightArrow);
+	p.drawEllipse(x1 + w , offsetY - h/4, h/2, h/2);
         if (messageOverlapsA)  {
             offsetX -= 7;
         }
     } else      {
-        if (messageOverlapsA)  {
-            w -= 7;
-        }
-        drawArrow(p, offsetX , offsetY + 4, w, Qt::LeftArrow);
+       
+        drawArrow(p, offsetX - w , offsetY, w, Qt::LeftArrow);
 	UMLWidget::setPen(p);
         p.setBrush( WidgetBase::getLineColor() );
-	p.drawEllipse(offsetX - 12 , offsetY - 3, h + 6, h + 6);
+	p.drawEllipse(offsetX - w - h/2, offsetY - h/4, h/2, h/2);
     }
 
     if (m_bSelected)
@@ -312,36 +301,21 @@
 
 void MessageWidget::drawFound(QPainter& p, int offsetX, int offsetY){
     int x1 = m_pOw[Uml::A]->getX();
-    int x2 = m_pOw[Uml::B]->getX();
-    int w = getWidth() - 1;
+    int x2 = xclicked;
+    int w = x1 < x2 ? x2 - x1 : x1 - x2 ;
     int h = getHeight() - 1;
     bool messageOverlapsA = m_pOw[Uml::A] -> messageOverlap( getY(), this );
     //bool messageOverlapsB = m_pOw[Uml::B] -> messageOverlap( getY(), this );
 
-    if(m_pOw[Uml::A] == m_pOw[Uml::B]) {
+    if(x1 < x2) {
         if (messageOverlapsA)  {
             offsetX += 7;
             w -= 7;
         }
-        const int lowerLineY = offsetY + h - 3;
-        // draw upper line segment (leaving the life line)
-        p.drawLine(offsetX, offsetY, offsetX + w, offsetY);
-        // draw line segment parallel to (and at the right of) the life line
-        p.drawLine(offsetX + w, offsetY, offsetX + w, lowerLineY);
-        // draw lower line segment (back to the life line)
-        drawArrow(p, offsetX, lowerLineY, w, Qt::LeftArrow);
-        if (messageOverlapsA)  {
-            offsetX -= 7; //reset for drawSelected()
-        }
-    } else if(x1 < x2) {
-        if (messageOverlapsA)  {
-            offsetX += 7;
-            w -= 7;
-        }
 	UMLWidget::setPen(p);
         p.setBrush( WidgetBase::getLineColor() );
-	p.drawEllipse(offsetX, offsetY - 3, h + 6, h + 6);
-        drawArrow(p, offsetX, offsetY + 4, w, Qt::RightArrow);
+	p.drawEllipse(offsetX + w, offsetY - h/4, h/2, h/2);
+        drawArrow(p, offsetX, offsetY, w, Qt::LeftArrow);
         if (messageOverlapsA)  {
             offsetX -= 7;
         }
@@ -351,8 +325,8 @@
         }
         UMLWidget::setPen(p);
         p.setBrush( WidgetBase::getLineColor() );
-	p.drawEllipse(offsetX + w , offsetY - 3, h + 6, h + 6);
-	drawArrow(p, offsetX , offsetY + 4, w, Qt::LeftArrow);
+	p.drawEllipse(offsetX - w - h/2 , offsetY - h/4, h/2, h/2);
+	drawArrow(p, offsetX - w , offsetY, w, Qt::RightArrow);
     }
 
     if (m_bSelected)
@@ -733,11 +707,10 @@
     int x = 0;
 
     int x1 = m_pOw[Uml::A]->getX();
-    int x2 = m_pOw[Uml::B]->getX();
+    int x2 = xclicked;
     int w1 = m_pOw[Uml::A]->getWidth() / 2;
-    int w2 = m_pOw[Uml::B]->getWidth() / 2;
+
     x1 += w1;
-    x2 += w2;
 
     int widgetWidth = 0;
     int widgetHeight = 8;
@@ -766,12 +739,11 @@
     int x = 0;
 
     int x1 = m_pOw[Uml::A]->getX();
-    int x2 = m_pOw[Uml::B]->getX();
+    int x2 = xclicked;
     int w1 = m_pOw[Uml::A]->getWidth() / 2;
-    int w2 = m_pOw[Uml::B]->getWidth() / 2;
     x1 += w1;
-    x2 += w2;
 
+
     int widgetWidth = 0;
     int widgetHeight = 8;
     if( m_pOw[Uml::A] == m_pOw[Uml::B] ) {
@@ -863,6 +835,15 @@
     return m_pOw[role];
 }
 
+void MessageWidget::setxclicked (int xclick){
+	xclicked = xclick;
+}
+
+
+void MessageWidget::setyclicked (int yclick){
+	yclicked = yclick;
+}
+
 void MessageWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
     QDomElement messageElement = qDoc.createElement( "messagewidget" );
     UMLWidget::saveToXMI( qDoc, messageElement );
--- branches/work/isi-umbrello/umbrello/umbrello/messagewidget.h #628375:628376
@@ -359,6 +359,9 @@
      */
     bool loadFromXMI( QDomElement & qElement );
 
+    void setxclicked (int xclick);
+    void setyclicked (int yclick);
+
 protected:
     /**
      * Shortcut for calling m_pFText->setLink() followed by
@@ -408,6 +411,10 @@
     ObjectWidget * m_pOw[2];
     FloatingTextWidget * m_pFText;
     int m_nY;
+
+    int xclicked;
+    int yclicked;
+
 public slots:
     void slotWidgetMoved(Uml::IDType id);
     void slotMenuSelection(int sel);
--- branches/work/isi-umbrello/umbrello/umbrello/toolbarstatemessages.cpp #628375:628376
@@ -29,6 +29,8 @@
 ToolBarStateMessages::ToolBarStateMessages(UMLView *umlView) : ToolBarStatePool(umlView) {
     m_firstObject = 0;
     m_messageLine = 0;
+    xclick = 0;
+    yclick = 0;
 }
 
 ToolBarStateMessages::~ToolBarStateMessages() {
@@ -111,19 +113,74 @@
 }
 
 void ToolBarStateMessages::mouseReleaseEmpty() {
-    cleanMessage();
+    Uml::Sequence_Message_Type msgType = getMessageType();
+
+    int y = m_pMouseEvent->y();
+
+    if (m_firstObject && msgType ==  Uml::sequence_message_lost) {
+	xclick = m_pMouseEvent->x();
+	yclick = m_pMouseEvent->y();
+	
+	MessageWidget* message = new MessageWidget(m_pUMLView, m_firstObject,m_firstObject, y, msgType);
+	message->setxclicked(xclick);
+	message->setyclicked(yclick);
+	cleanMessage();
+ 	m_pUMLView->getMessageList().append(message);
+
+   	FloatingTextWidget *ft = message->getFloatingTextWidget();
+    	//TODO cancel doesn't cancel the creation of the message, only cancels setting an operation.
+    	//Shouldn't it cancel also the whole creation?
+    	ft->showOpDlg();
+    	message->setTextPosition();
+    	m_pUMLView->getWidgetList().append(ft);
+
+    	UMLApp::app()->getDocument()->setModified();
+    }
+    else if (!m_firstObject && msgType == Uml::sequence_message_found) {
+	xclick = m_pMouseEvent->x();
+	yclick = m_pMouseEvent->y();
+
+	m_messageLine = new Q3CanvasLine(m_pUMLView->canvas());
+    	m_messageLine->setPoints(m_pMouseEvent->x(), m_pMouseEvent->y(), m_pMouseEvent->x(), m_pMouseEvent->y());
+    	m_messageLine->setPen(QPen(m_pUMLView->getLineColor(), m_pUMLView->getLineWidth(), Qt::DashLine));
+
+    	m_messageLine->setVisible(true);
+
+    	m_pUMLView->viewport()->setMouseTracking(true);
+    }
+    else
+    	cleanMessage();
 }
 
 void ToolBarStateMessages::setFirstWidget(ObjectWidget* firstObject) {
     m_firstObject = firstObject;
+    Uml::Sequence_Message_Type msgType = getMessageType();
+    int y = m_pMouseEvent->y();
+    if (msgType ==  Uml::sequence_message_found) {
+	MessageWidget* message = new MessageWidget(m_pUMLView, m_firstObject,m_firstObject, y, msgType);
+	message->setxclicked(xclick);
+	message->setyclicked(yclick);
+	cleanMessage();
+ 	m_pUMLView->getMessageList().append(message);
 
-    m_messageLine = new Q3CanvasLine(m_pUMLView->canvas());
-    m_messageLine->setPoints(m_pMouseEvent->x(), m_pMouseEvent->y(), m_pMouseEvent->x(), m_pMouseEvent->y());
-    m_messageLine->setPen(QPen(m_pUMLView->getLineColor(), m_pUMLView->getLineWidth(), Qt::DashLine));
+   	FloatingTextWidget *ft = message->getFloatingTextWidget();
+    	//TODO cancel doesn't cancel the creation of the message, only cancels setting an operation.
+    	//Shouldn't it cancel also the whole creation?
+    	ft->showOpDlg();
+    	message->setTextPosition();
+    	m_pUMLView->getWidgetList().append(ft);
 
-    m_messageLine->setVisible(true);
+    	UMLApp::app()->getDocument()->setModified();
+    }
+    else {
+    	m_messageLine = new Q3CanvasLine(m_pUMLView->canvas());
+    	m_messageLine->setPoints(m_pMouseEvent->x(), m_pMouseEvent->y(), m_pMouseEvent->x(), m_pMouseEvent->y());
+    	m_messageLine->setPen(QPen(m_pUMLView->getLineColor(), m_pUMLView->getLineWidth(), Qt::DashLine));
 
-    m_pUMLView->viewport()->setMouseTracking(true);
+    	m_messageLine->setVisible(true);
+
+    	m_pUMLView->viewport()->setMouseTracking(true);
+    }
 }
 
 void ToolBarStateMessages::setSecondWidget(ObjectWidget* secondObject, MessageType messageType) {
--- branches/work/isi-umbrello/umbrello/umbrello/toolbarstatemessages.h #628375:628376
@@ -186,6 +186,13 @@
      */
     bool m_isObjectWidgetLine;
 
+private:
+    /**
+    * x and y clicked for lost and found messages
+    */
+    int xclick;
+    int yclick;
+
 };
 
 #endif //TOOLBARSTATEMESSAGES_H
--- branches/work/isi-umbrello/umbrello/umbrello/toolbarstatesequence.cpp #628375:628376
@@ -100,6 +100,16 @@
             m_pUMLView->setupNewWidget(precondition);
     	}
     }
+
+    if (getWidgetType() == Uml::wt_End_Of_Life) {
+   	 UMLWidget * precondition = new PreconditionWidget(m_pUMLView, m_firstObject);
+
+	Dialog_Utils::askNameForWidget(precondition, i18n("Enter Precondition Name"), i18n("Enter the precondition"), i18n("new precondition"));
+    	    // Create the widget. Some setup functions can remove the widget.
+    	if (precondition != NULL) {
+            m_pUMLView->setupNewWidget(precondition);
+    	}
+    }
 }
 
 
@@ -107,6 +117,9 @@
     if (getButton() == WorkToolBar::tbb_Seq_Precondition) {
         return Uml::wt_Precondition;
     }
+    if (getButton() == WorkToolBar::tbb_Seq_End_Of_Life) {
+        return Uml::wt_End_Of_Life;
+    }
 }
 
 
--- branches/work/isi-umbrello/umbrello/umbrello/widget_factory.cpp #628375:628376
@@ -50,8 +50,10 @@
 #include "forkjoinwidget.h"
 #include "activitywidget.h"
 #include "seqlinewidget.h"
+#include "preconditionwidget.h"
 #include "cmds.h"
 
+
 namespace Widget_Factory {
 
 UMLWidget *createWidget(UMLView *view, UMLObject *o) {
@@ -158,7 +160,7 @@
                              const QString& idStr, UMLView *view) {
     UMLWidget *widget = NULL;
     if (tag == "statewidget" || tag == "notewidget" || tag == "boxwidget" ||
-        tag == "floatingtext" || tag == "activitywidget" || tag == "forkjoin" ||
+        tag == "floatingtext" || tag == "activitywidget" || tag == "forkjoin" || tag == "preconditionwidget" ||
             // tests for backward compatibility:
             tag == "UML:StateWidget" || tag == "UML:NoteWidget" ||
             tag == "UML:FloatingTextWidget" || tag == "UML:ActivityWidget") {
@@ -182,7 +184,9 @@
             widget = new ActivityWidget(view, ActivityWidget::Initial, Uml::id_Reserved);
         } else if (tag == "forkjoin") {
             widget = new ForkJoinWidget(view, false, Uml::id_Reserved);
-        }
+        } else if (tag == "preconditionwidget") {
+            widget = new PreconditionWidget(view, NULL, Uml::id_Reserved);
+	}
     } else {
         // Find the UMLObject and create the Widget to represent it
         Uml::IDType id = STR2ID(idStr);




More information about the umbrello-devel mailing list