From d89b7ecb730dac9b1b38cffd8d381c96d3a40f48 Mon Sep 17 00:00:00 2001
From: Erik Verbruggen <erik.verbruggen@nokia.com>
Date: Wed, 27 Jan 2010 14:00:18 +0100
Subject: [PATCH] Changed hovering to use the new interpreter & binding code.

Done-with: Roberto Raggi
---
 src/plugins/qmljseditor/qmlhoverhandler.cpp | 21 ++++++++++++++++++++-
 src/plugins/qmljseditor/qmlhoverhandler.h   |  8 ++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/plugins/qmljseditor/qmlhoverhandler.cpp b/src/plugins/qmljseditor/qmlhoverhandler.cpp
index 7b2d9666f21..1ab41a544fb 100644
--- a/src/plugins/qmljseditor/qmlhoverhandler.cpp
+++ b/src/plugins/qmljseditor/qmlhoverhandler.cpp
@@ -202,7 +202,7 @@ void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
         Interpreter::ObjectValue *scope = bind(declaringMember);
         Check check(&interp);
         const Interpreter::Value *value = check(expression, scope);
-        m_toolTip = interp.typeId(value);
+        m_toolTip = prettyPrint(value, &interp);
 
 #if 0
         QmlLookupContext context(expressionUnderCursor.expressionScopes(), doc, m_modelManager->snapshot(), typeSystem);
@@ -241,3 +241,22 @@ void QmlHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
         m_toolTip = QString(QLatin1String("<nobr>No help available for \"%1\"")).arg(symbolName);
     }
 }
+
+QString QmlHoverHandler::prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Engine *interp) const
+{
+    if (!value)
+        return QString();
+
+    if (const Interpreter::ObjectValue *objectValue = value->asObjectValue()) {
+        QString className = objectValue->className();
+
+        while (objectValue && objectValue->prototype() && className.isEmpty()) {
+            objectValue = objectValue->prototype();
+            className = objectValue->className();
+        }
+
+        return className;
+    }
+
+    return interp->typeId(value);
+}
diff --git a/src/plugins/qmljseditor/qmlhoverhandler.h b/src/plugins/qmljseditor/qmlhoverhandler.h
index 7d3012b398e..abfabe6071f 100644
--- a/src/plugins/qmljseditor/qmlhoverhandler.h
+++ b/src/plugins/qmljseditor/qmlhoverhandler.h
@@ -43,6 +43,13 @@ namespace Core {
 class IEditor;
 }
 
+namespace QmlJS {
+    namespace Interpreter {
+        class Engine;
+        class Value;
+    }
+}
+
 namespace TextEditor {
 class ITextEditor;
 }
@@ -66,6 +73,7 @@ private slots:
 
 private:
     void updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, int pos);
+    QString prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Engine *interp) const;
 
 private:
     QmlModelManagerInterface *m_modelManager;
-- 
GitLab