From 5fede0d497e2cab7455329cb4ef93a420bccd200 Mon Sep 17 00:00:00 2001
From: Christiaan Janssen <christiaan.janssen@nokia.com>
Date: Wed, 11 Jan 2012 14:46:05 +0100
Subject: [PATCH] QmlProfiler: tooltips for the labels column

Due to space restrictions, the descriptive text of events
in the labels column of the timeline view are elided.  This
patch adds tooltips on mouseover with location and details.

Change-Id: I229988e114f21e4d9575dff137aa91918ad1afa3
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
---
 src/libs/qmljsdebugclient/qmlprofilereventlist.cpp | 6 ++++++
 src/libs/qmljsdebugclient/qmlprofilereventlist.h   | 1 +
 src/plugins/qmlprofiler/qml/Label.qml              | 8 ++++++++
 src/plugins/qmlprofiler/qml/MainView.qml           | 2 ++
 src/plugins/qmlprofiler/tracewindow.cpp            | 6 ++++++
 src/plugins/qmlprofiler/tracewindow.h              | 1 +
 6 files changed, 24 insertions(+)

diff --git a/src/libs/qmljsdebugclient/qmlprofilereventlist.cpp b/src/libs/qmljsdebugclient/qmlprofilereventlist.cpp
index b337c2552bd..a7e02cc4032 100644
--- a/src/libs/qmljsdebugclient/qmlprofilereventlist.cpp
+++ b/src/libs/qmljsdebugclient/qmlprofilereventlist.cpp
@@ -1672,6 +1672,12 @@ QString QmlProfilerEventList::eventTextForType(int type, int index) const {
     return d->m_eventDescriptions.values().at(d->m_typeCounts[type]->eventIds[index])->details;
 }
 
+QString QmlProfilerEventList::eventDisplayNameForType(int type, int index) const {
+    if (!d->m_typeCounts.contains(type))
+        return QString();
+    return d->m_eventDescriptions.values().at(d->m_typeCounts[type]->eventIds[index])->displayname;
+}
+
 int QmlProfilerEventList::eventIdForType(int type, int index) const {
     if (!d->m_typeCounts.contains(type))
         return -1;
diff --git a/src/libs/qmljsdebugclient/qmlprofilereventlist.h b/src/libs/qmljsdebugclient/qmlprofilereventlist.h
index ff52c87b170..a9fc0454b9c 100644
--- a/src/libs/qmljsdebugclient/qmlprofilereventlist.h
+++ b/src/libs/qmljsdebugclient/qmlprofilereventlist.h
@@ -150,6 +150,7 @@ public:
     Q_INVOKABLE int uniqueEventsOfType(int type) const;
     Q_INVOKABLE int maxNestingForType(int type) const;
     Q_INVOKABLE QString eventTextForType(int type, int index) const;
+    Q_INVOKABLE QString eventDisplayNameForType(int type, int index) const;
     Q_INVOKABLE int eventIdForType(int type, int index) const;
     Q_INVOKABLE int eventPosInType(int index) const;
 
diff --git a/src/plugins/qmlprofiler/qml/Label.qml b/src/plugins/qmlprofiler/qml/Label.qml
index ac6a47ccae4..9d639820ca0 100644
--- a/src/plugins/qmlprofiler/qml/Label.qml
+++ b/src/plugins/qmlprofiler/qml/Label.qml
@@ -39,6 +39,7 @@ Item {
     property int typeIndex: index
 
     property variant descriptions: []
+    property variant extdescriptions: []
     property variant eventIds: []
 
     height: root.singleRowHeight
@@ -67,17 +68,21 @@ Item {
         onDataReady: {
             var desc=[];
             var ids=[];
+            var extdesc=[];
             for (var i=0; i<qmlEventList.uniqueEventsOfType(typeIndex); i++) {
                 desc[i] = qmlEventList.eventTextForType(typeIndex, i);
                 ids[i] = qmlEventList.eventIdForType(typeIndex, i);
+                extdesc[i] = qmlEventList.eventDisplayNameForType(typeIndex, i) + " : " + desc[i];
             }
             descriptions = desc;
             eventIds = ids;
+            extdescriptions = extdesc;
             updateHeight();
         }
         onDataClear: {
             descriptions = [];
             eventIds = [];
+            extdescriptions = [];
             updateHeight();
         }
     }
@@ -121,6 +126,9 @@ Item {
                 }
                 MouseArea {
                     anchors.fill: parent
+                    hoverEnabled: true
+                    onEntered: changeToolTip(extdescriptions[index]);
+                    onExited: changeToolTip("");
                     onClicked: {
                         if (mouse.modifiers & Qt.ShiftModifier)
                             view.selectPrevFromId(eventIds[index]);
diff --git a/src/plugins/qmlprofiler/qml/MainView.qml b/src/plugins/qmlprofiler/qml/MainView.qml
index 158030811b3..06e60ccde99 100644
--- a/src/plugins/qmlprofiler/qml/MainView.qml
+++ b/src/plugins/qmlprofiler/qml/MainView.qml
@@ -73,6 +73,8 @@ Rectangle {
     property variant selectionRangeStart: selectionRange.startTime
     property variant selectionRangeEnd: selectionRange.startTime + selectionRange.duration
 
+    signal changeToolTip(string text)
+
     // ***** connections with external objects
     Connections {
         target: zoomControl
diff --git a/src/plugins/qmlprofiler/tracewindow.cpp b/src/plugins/qmlprofiler/tracewindow.cpp
index 15ebad97cb2..0903ce7b095 100644
--- a/src/plugins/qmlprofiler/tracewindow.cpp
+++ b/src/plugins/qmlprofiler/tracewindow.cpp
@@ -296,6 +296,7 @@ void TraceWindow::reset(QDeclarativeDebugConnection *conn)
     connect(this, SIGNAL(globalZoom()), m_mainView->rootObject(), SLOT(globalZoom()));
     connect(this, SIGNAL(selectNextEventInDisplay(QVariant)), m_mainView->rootObject(), SLOT(selectNextWithId(QVariant)));
     connect(m_mainView->rootObject(), SIGNAL(selectedEventIdChanged(int)), this, SIGNAL(selectedEventIdChanged(int)));
+    connect(m_mainView->rootObject(), SIGNAL(changeToolTip(QString)), this, SLOT(updateToolTip(QString)));
 
     connect(this, SIGNAL(internalClearDisplay()), m_mainView->rootObject(), SLOT(clearAll()));
     connect(this,SIGNAL(internalClearDisplay()), m_overview->rootObject(), SLOT(clearDisplay()));
@@ -563,5 +564,10 @@ void TraceWindow::updateProfilerState()
     emit profilerStateChanged(qmlActive, v8Active);
 }
 
+void TraceWindow::updateToolTip(QString text)
+{
+    setToolTip(text);
+}
+
 } // namespace Internal
 } // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/tracewindow.h b/src/plugins/qmlprofiler/tracewindow.h
index 9e72faf5c5d..26be955d483 100644
--- a/src/plugins/qmlprofiler/tracewindow.h
+++ b/src/plugins/qmlprofiler/tracewindow.h
@@ -126,6 +126,7 @@ public slots:
     void v8Complete();
     void selectNextEvent(int eventId);
     void updateProfilerState();
+    void updateToolTip(QString text);
 
 signals:
     void viewUpdated();
-- 
GitLab