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

Andi Fischer andi.fischer at hispeed.ch
Tue May 4 15:38:52 UTC 2010


SVN commit 1122747 by fischer:

Tool tip on operation items in the list view fixed and old code removed.

 M  +21 -39    umllistview.cpp  
 M  +1 -0      umllistview.h  
 M  +20 -2     umllistviewitem.cpp  
 M  +6 -7      umllistviewitem.h  


--- branches/work/soc-umbrello/umbrello/umllistview.cpp #1122746:1122747
@@ -21,6 +21,7 @@
 #include <QtGui/QKeyEvent>
 #include <QtGui/QDropEvent>
 #include <QtGui/QMouseEvent>
+#include <QtGui/QToolTip>
 
 // kde includes
 #include <kdebug.h>
@@ -72,38 +73,7 @@
 #include "umlcheckconstraintdialog.h"
 #include "umlscene.h"
 
-#ifdef WANT_LVTOOLTIP
-class LVToolTip : public QToolTip
-{
-public:
-    LVToolTip(QWidget* parent) : QToolTip(parent) {}
-    virtual ~LVToolTip() {}
-protected:
     /**
-     * Reimplemented from QToolTip for internal reasons.
-     * At classifiers, only the method names are shown in the list view -
-     * we use a tooltip for the full signature display.
-     * Once K3ListView's tooltip overriding mechanism works, we can kick
-     * this class out (TODO).
-     */
-    virtual void maybeTip(const QPoint& pos) {
-        UMLListView *lv = UMLApp::app()->getListView();
-        UMLListViewItem * item = (UMLListViewItem*)lv->itemAt(pos);
-        if (item == 0)
-            return;
-        UMLObject *obj = item->getUMLObject();
-        if (obj == 0 || obj->getBaseType() != Uml::ot_Operation)
-            return;
-        UMLOperation *op = static_cast<UMLOperation*>(obj);
-        QString text = op->toString(Uml::st_ShowSig);
-        QRect rect = lv->itemRect(item);
-        tip(rect, text);
-    }
-};
-#endif
-
-
-/**
  * Constructs the tree view.
  *
  * @param parent   The parent to this.
@@ -133,14 +103,6 @@
 
     setEditTriggers(QAbstractItemView::EditKeyPressed);
 
-#ifdef WANT_LVTOOLTIP
-    /* In KDE-3.3, we cannot use K3ListView's builtin mechanism for
-       overriding the tooltips. Instead, see the above class LVToolTip.
-    setShowToolTips( true );
-    setTooltipColumn( 0 );
-     */
-    (void) new LVToolTip(viewport());
-#endif
     m_pMenu = 0;
     m_bStartedCut = m_bStartedCopy = false;
     m_bIgnoreCancelRename = true;
@@ -185,6 +147,26 @@
     }
 }
 
+/**
+ * Event handler for the tool tip event.
+ * Works only for operations to show the signature.
+ */
+bool UMLListView::event(QEvent *e)
+{
+    if (e->type() == QEvent::ToolTip) {
+        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(e);
+        UMLListViewItem * item = (UMLListViewItem*)itemAt(helpEvent->pos());
+        if (item) {
+            QToolTip::showText(helpEvent->globalPos(), item->toolTip());
+        } else {
+            QToolTip::hideText();
+            e->ignore();
+        }
+        return true;
+    }
+    return QTreeWidget::event(e);
+}
+
 bool UMLListView::eventFilter(QObject *o, QEvent *e)
 {
     if (e->type() != QEvent::MouseButtonPress || qstrcmp("QHeader", metaObject()->className()) != 0)
--- branches/work/soc-umbrello/umbrello/umllistview.h #1122746:1122747
@@ -147,6 +147,7 @@
      */
     bool m_bCreatingChildObject;
 
+    bool event(QEvent *e);
     bool eventFilter(QObject *o, QEvent *e);
     void mouseReleaseEvent(QMouseEvent * me);
     void mousePressEvent(QMouseEvent *me);
--- branches/work/soc-umbrello/umbrello/umllistviewitem.cpp #1122746:1122747
@@ -14,11 +14,13 @@
 // system includes
 #include <cstdlib>
 
-// qt/kde includes
+// qt includes
 #include <QtCore/QTextStream>
 #include <QtCore/QFile>
+#include <QtCore/QRegExp>
 #include <QtGui/QDrag>
-#include <QtCore/QRegExp>
+
+// kde includes
 #include <klocale.h>
 #include <kmessagebox.h>
 #include <kdebug.h>
@@ -191,6 +193,22 @@
 }
 
 /**
+ * Returns the signature of items that are operations.
+ * @return signature of an operation item, else an empty string
+ */
+QString UMLListViewItem::toolTip()
+{
+    UMLObject *obj = getUMLObject();
+    if (obj && obj->getBaseType() == Uml::ot_Operation) {
+        UMLOperation *op = static_cast<UMLOperation*>(obj);
+        return op->toString(Uml::st_ShowSig);
+    }
+    else {
+        return QString();
+    }
+}
+
+/**
  * Returns the type this instance represents.
  *
  * @return  The type this instance represents.
--- branches/work/soc-umbrello/umbrello/umllistviewitem.h #1122746:1122747
@@ -4,7 +4,7 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2002-2009                                               *
+ *   copyright (C) 2002-2010                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 
@@ -13,7 +13,8 @@
 
 #include <QtGui/QTreeWidget>
 #include <QtCore/QMap>
-#include <qdom.h>
+#include <QtXml/QDomDocument>
+#include <QtXml/QDomElement>
 
 #include "umlnamespace.h"
 #include "icon_utils.h"
@@ -64,6 +65,8 @@
     QString getText() const;
     void setVisible(bool state);
 
+    QString toolTip();
+
     void setCreating(bool creating);
 
     void setIcon(Icon_Utils::Icon_Type iconType);
@@ -103,11 +106,6 @@
     static UMLListView * s_pListView;
 
     /**
-     * Flag used to set the state of creating.
-     */
-    bool m_bCreating;
-
-    /**
      * Auxiliary map of child UMLLisViewItems keyed by UMLClassifierListItem.
      * Used by findChildObject() for efficiency instead of looping using
      * firstChild()/nextSibling() because the latter incur enforceItemVisible()
@@ -115,6 +113,7 @@
      */
     typedef QMap<UMLClassifierListItem*, UMLListViewItem*> ChildObjectMap;
 
+    bool               m_bCreating;  ///< flag to set the state of creating
     Uml::ListView_Type m_Type;
     Uml::IDType m_nId;
     int m_nChildren;




More information about the umbrello-devel mailing list