[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [umbrello] umbrello: Integration of PinWidget's floating-text name display in PortWidget
From:       Oliver Kellogg <okellogg () users ! sourceforge ! net>
Date:       2014-05-31 21:36:39
Message-ID: E1WqqxD-00088U-5S () scm ! kde ! org
[Download RAW message or body]

Git commit ca646e952dd24c588c16908467df31d442010d7a by Oliver Kellogg.
Committed on 31/05/2014 at 21:36.
Pushed by okellogg into branch 'master'.

Integration of PinWidget's floating-text name display in PortWidget
(see "BTW" at https://bugs.kde.org/show_bug.cgi?id=335399#c1)

umbrello/listpopupmenu.h
- At enum MenuType add new value, mt_NameAsTooltip.

umbrello/widgets/portwidget.h
- Add protected member m_pName of type pointer-to-FloatingTextWidget with
  corresponding public getter and setter method.
  The intention is that the FloatingTextWidget may be used as an
  alternative to the tooltip for displaying the port name on a diagram.
- Override UMLWidget::slotMenuSelection() for adding handling of
  ListPopupMenu::mt_NameAsTooltip.

umbrello/listpopupmenu.cpp
- In function insertSingleSelectionMenu() case wt_Port, insert
  mt_NameAsTooltip as checkable. If the PortWidget's floatingTextWidget()
  is NULL then setChecked(true) on m_actions[mt_NameAsTooltip].
  This is the default case as the PortWidget does not automatically
  construct its FloatingTextWidget.

umbrello/widgets/portwidget.cpp
- In function updateWidget(), if m_pName is non NULL then update the text
  in the FloatingTextWidget; else update the text in the ToolTip.
- In function slotMenuSelection(), handle ListPopupMenu::mt_NameAsTooltip
  as follows: If m_pName is non NULL then toggle the name display from
  FloatingText to ToolTip; else toggle the name display from ToolTip to
  FloatingText.
- In functions loadFromXMI() and saveToXMI(), implement loading/saving of
  the optional FloatingTextWidget *m_pName.

M  +8    -0    umbrello/listpopupmenu.cpp
M  +1    -0    umbrello/listpopupmenu.h
M  +108  -2    umbrello/widgets/portwidget.cpp
M  +6    -0    umbrello/widgets/portwidget.h

http://commits.kde.org/umbrello/ca646e952dd24c588c16908467df31d442010d7a

diff --git a/umbrello/listpopupmenu.cpp b/umbrello/listpopupmenu.cpp
index 738247a..a9c20bd 100644
--- a/umbrello/listpopupmenu.cpp
+++ b/umbrello/listpopupmenu.cpp
@@ -27,6 +27,7 @@
 #include "model_utils.h"
 #include "objectnodewidget.h"
 #include "objectwidget.h"
+#include "portwidget.h"
 #include "preconditionwidget.h"
 #include "signalwidget.h"
 #include "statewidget.h"
@@ -386,6 +387,13 @@ void ListPopupMenu::insertSingleSelectionMenu(WidgetBase* \
object)  insertSubMenuColor(object->useFillColor());
         insertStdItems(false, type);
         insert(mt_Rename);
+        insert(mt_NameAsTooltip, "Name as Tooltip", CHECKABLE);
+        {
+            PortWidget *portW = static_cast<PortWidget*>(object);
+            FloatingTextWidget *ft = portW->floatingTextWidget();
+            if (ft == NULL)
+                m_actions[mt_NameAsTooltip]->setChecked(true);
+        }
         insert(mt_Properties);
         break;
 
diff --git a/umbrello/listpopupmenu.h b/umbrello/listpopupmenu.h
index fcb3cb5..ed11b89 100644
--- a/umbrello/listpopupmenu.h
+++ b/umbrello/listpopupmenu.h
@@ -168,6 +168,7 @@ public:
         mt_Anchor,
         mt_Properties,
         mt_Rename,
+        mt_NameAsTooltip,
         mt_Show,
         mt_Delete,
         mt_Export_Image,
diff --git a/umbrello/widgets/portwidget.cpp b/umbrello/widgets/portwidget.cpp
index c12eb52..d1fd866 100644
--- a/umbrello/widgets/portwidget.cpp
+++ b/umbrello/widgets/portwidget.cpp
@@ -19,9 +19,11 @@
 #include "umlscene.h"
 #include "umlview.h"
 #include "componentwidget.h"
+#include "floatingtextwidget.h"
 
 // qt includes
 #include <QPainter>
+#include <QToolTip>
 
 // sys includes
 #include <cmath>
@@ -40,6 +42,7 @@ PortWidget::PortWidget(UMLScene *scene, UMLPort *d)
     m_ignoreSnapToGrid = true;
     m_ignoreSnapComponentSizeToGrid = true;
     m_resizable = false;
+    m_pName = NULL;
     setMinimumSize(FixedSize);
     setMaximumSize(FixedSize);
     setSize(FixedSize);
@@ -72,7 +75,11 @@ void PortWidget::updateWidget()
 {
     QString strName = m_umlObject->name();
     uDebug() << " port name is " << strName;
-    setToolTip(strName);
+    if (m_pName) {
+        m_pName->setText(strName);
+    } else {
+        setToolTip(strName);
+    }
 }
 
 /**
@@ -180,11 +187,106 @@ void PortWidget::slotCompMoved(qreal diffX, qreal diffY)
 }
 
 /**
+ * Captures any popup menu signals for menus it created.
+ */
+void PortWidget::slotMenuSelection(QAction* action)
+{
+    ListPopupMenu::MenuType sel = ListPopupMenu::typeFromAction(action);
+    switch(sel) {
+    case ListPopupMenu::mt_NameAsTooltip:
+        if (m_pName) {
+            action->setChecked(true);
+            m_scene->removeWidget(m_pName);
+            delete m_pName;
+            m_pName = NULL;
+            setToolTip(m_umlObject->name());
+        } else {
+            action->setChecked(false);
+            m_pName = new FloatingTextWidget(m_scene, Uml::TextRole::Floating, \
m_umlObject->name()); +            m_pName->activate();
+            const Uml::ID::Type compWidgetId = m_umlObject->umlPackage()->id();
+            UMLWidget* owner = m_scene->widgetOnDiagram(compWidgetId);
+            if (owner == NULL) {
+                uError() << "m_scene->widgetOnDiagram(" << \
Uml::ID::toString(compWidgetId) << ") returns NULL"; +                setX(x());
+                setY(y());
+            } else {
+                if (x() < owner->x())
+                    m_pName->setX(x() - m_pName->width());
+                else if (x() >= owner->x() + owner->width())
+                    m_pName->setX(x() + 15);
+                else
+                    m_pName->setX(x() - m_pName->width() / 2.0 + 7);
+                if (y() < owner->y())
+                    m_pName->setY(y() - m_pName->height() - 2);
+                else if (y() >= owner->y() + owner->height())
+                    m_pName->setY(y() + 15);
+                else
+                    m_pName->setY(y() - m_pName->height() / 2.0 + 7);
+            }
+            m_scene->addFloatingTextWidget(m_pName);
+            setToolTip(QString());
+            QToolTip::hideText();
+        }
+        break;
+
+    default:
+        UMLWidget::slotMenuSelection(action);
+    }
+}
+
+FloatingTextWidget *PortWidget::floatingTextWidget() {
+    return m_pName;
+}
+
+void PortWidget::setFloatingTextWidget(FloatingTextWidget *ft) {
+    m_pName = ft;
+}
+
+
+/**
  * Loads from a "portwidget" XMI element.
  */
 bool PortWidget::loadFromXMI(QDomElement & qElement)
 {
-    return UMLWidget::loadFromXMI(qElement);
+    if (!UMLWidget::loadFromXMI(qElement))
+        return false;
+
+    QString textid = qElement.attribute("textid", "-1");
+    Uml::ID::Type textId = Uml::ID::fromString(textid);
+    if (textId != Uml::ID::None) {
+        UMLWidget *flotext = m_scene -> findWidget(textId);
+        if (flotext != NULL) {
+            if (flotext->baseType() == WidgetBase::wt_Text) {
+                uWarning() << "Check XMI file: floatingtext " << textid
+                           << " is already defined";
+                m_pName = static_cast<FloatingTextWidget*>(flotext);
+                return true;
+            } else {
+                uError() << "floatingtext xmi.id" << textid
+                         << " conflicts with existing " << flotext->baseType();
+                return false;
+            }
+        }
+    }
+
+    // Optional child element: floatingtext
+    QDomNode node = qElement.firstChild();
+    QDomElement element = node.toElement();
+    if (!element.isNull()) {
+        QString tag = element.tagName();
+        if (tag == "floatingtext") {
+            m_pName = new FloatingTextWidget(m_scene, Uml::TextRole::Floating, \
m_umlObject->name(), textId); +            if (!m_pName->loadFromXMI(element)) {
+                // Most likely cause: The FloatingTextWidget is empty.
+                delete m_pName;
+                m_pName = NULL;
+            }
+        } else {
+            uError() << "unknown tag " << tag;
+        }
+    }
+    return true;
 }
 
 /**
@@ -194,6 +296,10 @@ void PortWidget::saveToXMI(QDomDocument & qDoc, QDomElement & \
qElement)  {
     QDomElement conceptElement = qDoc.createElement("portwidget");
     UMLWidget::saveToXMI(qDoc, conceptElement);
+    if (m_pName && !m_pName->text().isEmpty()) {
+        conceptElement.setAttribute("textid", Uml::ID::toString(m_pName->id()));
+        m_pName -> saveToXMI(qDoc, conceptElement);
+    }
     qElement.appendChild(conceptElement);
 }
 
diff --git a/umbrello/widgets/portwidget.h b/umbrello/widgets/portwidget.h
index 11648e2..ec59b33 100644
--- a/umbrello/widgets/portwidget.h
+++ b/umbrello/widgets/portwidget.h
@@ -14,6 +14,7 @@
 #include "umlwidget.h"
 
 class UMLPort;
+class FloatingTextWidget;
 
 /**
  * Defines a graphical version of the port.  Most of the functionality
@@ -37,15 +38,20 @@ public:
     virtual void moveWidgetBy(qreal diffX, qreal diffY);
     void attachToOwningComponent();
 
+    FloatingTextWidget *floatingTextWidget();
+    void setFloatingTextWidget(FloatingTextWidget *ft);
+
     bool loadFromXMI(QDomElement& qElement);
     void saveToXMI(QDomDocument& qDoc, QDomElement& qElement);
 
 public slots:
     void slotCompMoved(qreal diffX, qreal diffY);
+    void slotMenuSelection(QAction* action);
 
 protected:
 
     static const QSizeF FixedSize;
+    FloatingTextWidget *m_pName;
 
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic