diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp index f0b3577..3f7843a 100644 --- a/src/plugins/debugger/qml/qmlengine.cpp +++ b/src/plugins/debugger/qml/qmlengine.cpp @@ -30,6 +30,7 @@ #include "qmlengine.h" #include "qmladapter.h" +#include "debuggertooltip.h" #include "debuggerconstants.h" #include "debuggerplugin.h" #include "debuggerdialogs.h" @@ -142,6 +143,7 @@ void QmlEngine::connectionEstablished() ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance(); pluginManager->addObject(m_adapter); + pluginManager->addObject(this); m_addedAdapterToObjectPool = true; plugin()->showMessage(tr("QML Debugger connected."), StatusBar); @@ -202,6 +204,7 @@ void QmlEngine::shutdownEngineAsSlave() if (m_addedAdapterToObjectPool) { ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance(); pluginManager->removeObject(m_adapter); + pluginManager->removeObject(this); } if (m_attachToRunningExternalApp) { @@ -409,9 +412,8 @@ static QHash m_toolTipCache; void QmlEngine::setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos) { - Q_UNUSED(mousePos) - Q_UNUSED(editor) - Q_UNUSED(cursorPos) + // this is processed by QML inspector, which has deps to qml js editor. Makes life easier. + emit tooltipRequested(mousePos, editor, cursorPos); } ////////////////////////////////////////////////////////////////////// diff --git a/src/plugins/debugger/qml/qmlengine.h b/src/plugins/debugger/qml/qmlengine.h index 2a25a0e..207db13 100644 --- a/src/plugins/debugger/qml/qmlengine.h +++ b/src/plugins/debugger/qml/qmlengine.h @@ -46,6 +46,10 @@ #include +namespace Core { + class TextEditor; +} + namespace Debugger { namespace Internal { @@ -117,6 +121,7 @@ private: signals: void sendMessage(const QByteArray &msg); + void tooltipRequested(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos); private slots: void connectionEstablished(); diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 058f5e6..1463ba3 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -112,7 +112,7 @@ public: // attributes QTextCursor end; }; -class SemanticInfo +class QMLJSEDITOR_EXPORT SemanticInfo { public: SemanticInfo() {} diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.cpp b/src/plugins/qmljsinspector/qmljsclientproxy.cpp index 2a81eda..191758c 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.cpp +++ b/src/plugins/qmljsinspector/qmljsclientproxy.cpp @@ -196,6 +196,18 @@ QDeclarativeDebugObjectReference ClientProxy::objectReferenceForId(int debugId, return QDeclarativeDebugObjectReference(); } +QDeclarativeDebugObjectReference ClientProxy::objectReferenceForId(const QString &objectId) const +{ + if (!objectId.isEmpty() && objectId[0].isLower()) { + const QList refs = objectReferences(); + foreach (const QDeclarativeDebugObjectReference &ref, refs) { + if (ref.idString() == objectId) + return ref; + } + } + return QDeclarativeDebugObjectReference(); +} + QList ClientProxy::objectReferences(const QUrl &url) const { QList result; diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.h b/src/plugins/qmljsinspector/qmljsclientproxy.h index f7e6179..7e6d964 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.h +++ b/src/plugins/qmljsinspector/qmljsclientproxy.h @@ -66,6 +66,7 @@ public: // returns the object references for the given url. QList objectReferences(const QUrl &url = QUrl()) const; QDeclarativeDebugObjectReference objectReferenceForId(int debugId) const; + QDeclarativeDebugObjectReference objectReferenceForId(const QString &objectId) const; QList rootObjectReference() const; bool isConnected() const; diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp index f119747..d8d537b 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.cpp +++ b/src/plugins/qmljsinspector/qmljsinspector.cpp @@ -37,10 +37,11 @@ #include "qmljsobjecttree.h" #include - +#include #include #include #include +#include #include #include @@ -50,6 +51,7 @@ #include #include #include +#include #include #include @@ -132,6 +134,7 @@ InspectorUi::InspectorUi(QObject *parent) , m_inspectorDockWidget(0) , m_settings(new InspectorSettings(this)) , m_clientProxy(0) + , m_qmlEngine(0) , m_debugProject(0) { m_instance = this; @@ -158,6 +161,48 @@ void InspectorUi::restoreSettings() m_settings->restoreSettings(Core::ICore::instance()->settings()); } +void InspectorUi::setDebuggerEngine(Debugger::Internal::QmlEngine *qmlEngine) +{ + if (m_qmlEngine && !qmlEngine) { + disconnect(m_qmlEngine, SIGNAL(tooltipRequested(QPoint, TextEditor::ITextEditor*, int)), + this, SLOT(showDebuggerTooltip(QPoint, TextEditor::ITextEditor*, int))); + } + + m_qmlEngine = qmlEngine; + if (m_qmlEngine) { + connect(m_qmlEngine, SIGNAL(tooltipRequested(QPoint, TextEditor::ITextEditor*, int)), + this, SLOT(showDebuggerTooltip(QPoint, TextEditor::ITextEditor*, int))); + } +} + +Debugger::Internal::QmlEngine *InspectorUi::debuggerEngine() const +{ + return m_qmlEngine; +} + +#include + +void InspectorUi::showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos) +{ + if (editor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { + qDebug() << "showing tooltip at" << mousePos << "w/ editor" << editor << "at cursor pos" << cursorPos; + QmlJSEditor::Internal::QmlJSTextEditor *qmlEditor = static_cast(editor->widget()); + + QTextCursor tc(qmlEditor->document()); + tc.setPosition(cursorPos); + tc.movePosition(QTextCursor::StartOfWord); + tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + + QString wordAtCursor = tc.selectedText(); + QDeclarativeDebugObjectReference ref = m_clientProxy->objectReferenceForId(wordAtCursor); + if (ref.debugId() == -1) { + QmlJS::AST::Node *node = qmlEditor->semanticInfo().declaringMemberNoProperties(cursorPos); + qDebug() << typeid(*node).name(); + } + qDebug() << "current word:" << wordAtCursor; + } +} + void InspectorUi::connected(ClientProxy *clientProxy) { m_clientProxy = clientProxy; @@ -204,6 +249,7 @@ void InspectorUi::disconnected() m_crumblePath, SLOT(updateContextPath(QStringList))); m_debugProject = 0; + m_qmlEngine = 0; resetViews(); setupToolbar(false); diff --git a/src/plugins/qmljsinspector/qmljsinspector.h b/src/plugins/qmljsinspector/qmljsinspector.h index 3c53ce2..310e57f 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.h +++ b/src/plugins/qmljsinspector/qmljsinspector.h @@ -47,6 +47,10 @@ namespace ProjectExplorer { class Environment; } +namespace TextEditor { + class ITextEditor; +} + namespace Core { class IContext; } @@ -55,6 +59,12 @@ namespace QmlJS { class ModelManagerInterface; } +namespace Debugger { +namespace Internal { + class QmlEngine; +} +} + QT_FORWARD_DECLARE_CLASS(QDockWidget) namespace QmlJSInspector { @@ -97,6 +107,8 @@ public: void setupUi(); void connected(ClientProxy *clientProxy); void disconnected(); + void setDebuggerEngine(Debugger::Internal::QmlEngine *qmlEngine); + Debugger::Internal::QmlEngine *debuggerEngine() const; signals: void statusMessage(const QString &text); @@ -116,7 +128,6 @@ private slots: void updateEngineList(); - void removePreviewForEditor(Core::IEditor *newEditor); QmlJSLiveTextPreview *createPreviewForEditor(Core::IEditor *newEditor); @@ -125,6 +136,7 @@ private slots: void currentDebugProjectRemoved(); void updatePendingPreviewDocuments(QmlJS::Document::Ptr doc); + void showDebuggerTooltip(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos); private: bool addQuotesForData(const QVariant &value) const; @@ -146,6 +158,7 @@ private: InspectorSettings *m_settings; ClientProxy *m_clientProxy; + Debugger::Internal::QmlEngine *m_qmlEngine; // Qml/JS integration QHash m_textPreviews; diff --git a/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp b/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp index befce48..bff091a 100644 --- a/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp +++ b/src/plugins/qmljsinspector/qmljsinspectorplugin.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -130,6 +131,12 @@ void InspectorPlugin::objectAdded(QObject *object) if (adapter) { m_clientProxy = new ClientProxy(adapter); m_inspectorUi->connected(m_clientProxy); + return; + } + + Debugger::Internal::QmlEngine *engine = qobject_cast(object); + if (engine) { + m_inspectorUi->setDebuggerEngine(engine); } } @@ -140,6 +147,10 @@ void InspectorPlugin::aboutToRemoveObject(QObject *obj) delete m_clientProxy; m_clientProxy = 0; } + + if (m_inspectorUi->debuggerEngine() == obj) { + m_inspectorUi->setDebuggerEngine(0); + } } Q_EXPORT_PLUGIN(InspectorPlugin) diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp index ff6c778..8654bec 100644 --- a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp +++ b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp @@ -247,15 +247,7 @@ void QmlJSLiveTextPreview::changeSelectedElements(QList offsets, const QStr return; QDeclarativeDebugObjectReference objectRefUnderCursor; - if (!wordAtCursor.isEmpty() && wordAtCursor[0].isLower()) { - QList refs = m_clientProxy.data()->objectReferences(); - foreach (const QDeclarativeDebugObjectReference &ref, refs) { - if (ref.idString() == wordAtCursor) { - objectRefUnderCursor = ref; - break; - } - } - } + m_clientProxy.data()->objectReferenceForId(wordAtCursor); QList selectedReferences; bool containsReferenceUnderCursor = false;