Inspector: Update Editor on object selection

When an object is selected in the Inspector, the
Editor is updated to show the relevant code.

Task-number: QTCREATORBUG-8246

Change-Id: I4f7fbcccdeb22849682fa72c63e87a78f48d185b
Reviewed-by: hjk <qthjk@ovi.com>
Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
This commit is contained in:
Aurindam Jana
2012-11-23 13:35:44 +01:00
committed by hjk
parent 62b20005dd
commit 46101b0bb2
14 changed files with 51 additions and 4 deletions

View File

@@ -50,6 +50,8 @@ BaseTreeView::BaseTreeView(QWidget *parent)
connect(this, SIGNAL(activated(QModelIndex)), connect(this, SIGNAL(activated(QModelIndex)),
SLOT(rowActivatedHelper(QModelIndex))); SLOT(rowActivatedHelper(QModelIndex)));
connect(this, SIGNAL(clicked(QModelIndex)),
SLOT(rowClickedHelper(QModelIndex)));
connect(header(), SIGNAL(sectionClicked(int)), connect(header(), SIGNAL(sectionClicked(int)),
SLOT(headerSectionClicked(int))); SLOT(headerSectionClicked(int)));

View File

@@ -49,6 +49,7 @@ public:
void setModel(QAbstractItemModel *model); void setModel(QAbstractItemModel *model);
virtual void rowActivated(const QModelIndex &) {} virtual void rowActivated(const QModelIndex &) {}
virtual void rowClicked(const QModelIndex &) {}
void mousePressEvent(QMouseEvent *ev); void mousePressEvent(QMouseEvent *ev);
public slots: public slots:
@@ -61,6 +62,7 @@ protected slots:
private slots: private slots:
void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); } void rowActivatedHelper(const QModelIndex &index) { rowActivated(index); }
void rowClickedHelper(const QModelIndex &index) { rowClicked(index); }
void headerSectionClicked(int logicalIndex); void headerSectionClicked(int logicalIndex);
private: private:

View File

@@ -1431,6 +1431,10 @@ void DebuggerEngine::updateWatchData(const WatchData &, const WatchUpdateFlags &
{ {
} }
void DebuggerEngine::watchDataSelected(const QByteArray &iname)
{
}
void DebuggerEngine::watchPoint(const QPoint &) void DebuggerEngine::watchPoint(const QPoint &)
{ {
} }

View File

@@ -149,6 +149,8 @@ public:
virtual void updateWatchData(const Internal::WatchData &data, virtual void updateWatchData(const Internal::WatchData &data,
const Internal::WatchUpdateFlags & flags = Internal::WatchUpdateFlags()); const Internal::WatchUpdateFlags & flags = Internal::WatchUpdateFlags());
virtual void watchDataSelected(const QByteArray &iname);
virtual void startDebugger(DebuggerRunControl *runControl); virtual void startDebugger(DebuggerRunControl *runControl);
virtual void watchPoint(const QPoint &); virtual void watchPoint(const QPoint &);

View File

@@ -35,6 +35,7 @@
#include "qmlengine.h" #include "qmlengine.h"
#include "qtmessageloghandler.h" #include "qtmessageloghandler.h"
#include "watchdata.h" #include "watchdata.h"
#include "watchhandler.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -135,6 +136,13 @@ void QmlCppEngine::updateWatchData(const WatchData &data,
d->m_activeEngine->updateWatchData(data, flags); d->m_activeEngine->updateWatchData(data, flags);
} }
void QmlCppEngine::watchDataSelected(const QByteArray &iname)
{
const WatchData *wd = watchHandler()->findData(iname);
if (wd && wd->isInspect())
d->m_qmlEngine->watchDataSelected(iname);
}
void QmlCppEngine::watchPoint(const QPoint &point) void QmlCppEngine::watchPoint(const QPoint &point)
{ {
d->m_cppEngine->watchPoint(point); d->m_cppEngine->watchPoint(point);

View File

@@ -50,6 +50,7 @@ public:
TextEditor::ITextEditor * editor, const DebuggerToolTipContext &); TextEditor::ITextEditor * editor, const DebuggerToolTipContext &);
void updateWatchData(const WatchData &data, void updateWatchData(const WatchData &data,
const WatchUpdateFlags &flags); const WatchUpdateFlags &flags);
void watchDataSelected(const QByteArray &iname);
void watchPoint(const QPoint &); void watchPoint(const QPoint &);
void fetchMemory(MemoryAgent *, QObject *, quint64 addr, quint64 length); void fetchMemory(MemoryAgent *, QObject *, quint64 addr, quint64 length);

View File

@@ -1021,6 +1021,13 @@ void QmlEngine::updateWatchData(const WatchData &data,
watchHandler()->insertData(data); watchHandler()->insertData(data);
} }
void QmlEngine::watchDataSelected(const QByteArray &iname)
{
const WatchData *wd = watchHandler()->findData(iname);
if (wd && wd->isInspect())
m_inspectorAdapter.agent()->watchDataSelected(wd);
}
void QmlEngine::synchronizeWatchers() void QmlEngine::synchronizeWatchers()
{ {
QStringList watchedExpressions = watchHandler()->watchedExpressions(); QStringList watchedExpressions = watchHandler()->watchedExpressions();

View File

@@ -161,6 +161,7 @@ private:
bool supportsThreads() const { return false; } bool supportsThreads() const { return false; }
void updateWatchData(const WatchData &data, void updateWatchData(const WatchData &data,
const WatchUpdateFlags &flags); const WatchUpdateFlags &flags);
void watchDataSelected(const QByteArray &iname);
void executeDebuggerCommand(const QString &command, DebuggerLanguages languages); void executeDebuggerCommand(const QString &command, DebuggerLanguages languages);
bool evaluateScriptExpression(const QString &expression); bool evaluateScriptExpression(const QString &expression);

View File

@@ -81,6 +81,8 @@ QmlInspectorAdapter::QmlInspectorAdapter(QmlAdapter *debugAdapter,
{ {
connect(m_agent, SIGNAL(objectFetched(QmlDebug::ObjectReference)), connect(m_agent, SIGNAL(objectFetched(QmlDebug::ObjectReference)),
SLOT(onObjectFetched(QmlDebug::ObjectReference))); SLOT(onObjectFetched(QmlDebug::ObjectReference)));
connect(m_agent, SIGNAL(jumpToObjectDefinition(QmlDebug::FileReference)),
SLOT(jumpToObjectDefinitionInEditor(QmlDebug::FileReference)));
QmlDebugConnection *connection = m_debugAdapter->connection(); QmlDebugConnection *connection = m_debugAdapter->connection();
DeclarativeEngineDebugClient *engineClient1 DeclarativeEngineDebugClient *engineClient1
@@ -467,7 +469,7 @@ void QmlInspectorAdapter::showConnectionStatusMessage(const QString &message)
m_engine->showMessage(_("QML Inspector: ") + message, LogStatus); m_engine->showMessage(_("QML Inspector: ") + message, LogStatus);
} }
void QmlInspectorAdapter::gotoObjectReferenceDefinition( void QmlInspectorAdapter::jumpToObjectDefinitionInEditor(
const FileReference &objSource) const FileReference &objSource)
{ {
if (m_cursorPositionChangedExternally) { if (m_cursorPositionChangedExternally) {
@@ -502,7 +504,7 @@ void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
QList<ObjectReference>() << obj); QList<ObjectReference>() << obj);
if (target == EditorTarget) if (target == EditorTarget)
gotoObjectReferenceDefinition(obj.source()); jumpToObjectDefinitionInEditor(obj.source());
if (!agent()->selectObjectInTree(obj.debugId())) if (!agent()->selectObjectInTree(obj.debugId()))
return; return;

View File

@@ -97,6 +97,7 @@ private slots:
void onReload(); void onReload();
void onReloaded(); void onReloaded();
void onDestroyedObject(int); void onDestroyedObject(int);
void jumpToObjectDefinitionInEditor(const QmlDebug::FileReference &objSource);
private: private:
void setActiveEngineClient(QmlDebug::BaseEngineDebugClient *client); void setActiveEngineClient(QmlDebug::BaseEngineDebugClient *client);
@@ -104,8 +105,6 @@ private:
void initializePreviews(); void initializePreviews();
void showConnectionStatusMessage(const QString &message); void showConnectionStatusMessage(const QString &message);
void gotoObjectReferenceDefinition(const QmlDebug::FileReference &objSource);
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget }; enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
void selectObject( void selectObject(
const QmlDebug::ObjectReference &objectReference, const QmlDebug::ObjectReference &objectReference,

View File

@@ -121,6 +121,17 @@ void QmlInspectorAgent::updateWatchData(const WatchData &data)
} }
} }
void QmlInspectorAgent::watchDataSelected(const WatchData *data)
{
if (debug)
qDebug() << __FUNCTION__ << '(' << data->id << ')';
if (data->id) {
QTC_ASSERT(m_debugIdLocations.keys().contains(data->id), return);
emit jumpToObjectDefinition(m_debugIdLocations.value(data->id));
}
}
bool QmlInspectorAgent::selectObjectInTree(int debugId) bool QmlInspectorAgent::selectObjectInTree(int debugId)
{ {
if (debug) { if (debug) {

View File

@@ -60,6 +60,7 @@ public:
void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV); void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV);
void updateWatchData(const WatchData &data); void updateWatchData(const WatchData &data);
void watchDataSelected(const WatchData *data);
bool selectObjectInTree(int debugId); bool selectObjectInTree(int debugId);
quint32 setBindingForObject(int objectDebugId, quint32 setBindingForObject(int objectDebugId,
@@ -101,6 +102,7 @@ signals:
void propertyChanged(int debugId, const QByteArray &propertyName, void propertyChanged(int debugId, const QByteArray &propertyName,
const QVariant &propertyValue); const QVariant &propertyValue);
void automaticUpdateFailed(); void automaticUpdateFailed();
void jumpToObjectDefinition(const QmlDebug::FileReference &objSource);
private slots: private slots:
void updateStatus(); void updateStatus();

View File

@@ -995,6 +995,11 @@ void WatchTreeView::setModel(QAbstractItemModel *model)
SLOT(handleItemIsExpanded(QModelIndex))); SLOT(handleItemIsExpanded(QModelIndex)));
} }
void WatchTreeView::rowClicked(const QModelIndex &index)
{
currentEngine()->watchDataSelected(currentEngine()->watchHandler()->watchData(index)->iname);
}
void WatchTreeView::handleItemIsExpanded(const QModelIndex &idx) void WatchTreeView::handleItemIsExpanded(const QModelIndex &idx)
{ {
bool on = idx.data(LocalsExpandedRole).toBool(); bool on = idx.data(LocalsExpandedRole).toBool();

View File

@@ -51,6 +51,7 @@ public:
explicit WatchTreeView(Type type, QWidget *parent = 0); explicit WatchTreeView(Type type, QWidget *parent = 0);
Type type() const { return m_type; } Type type() const { return m_type; }
void setModel(QAbstractItemModel *model); void setModel(QAbstractItemModel *model);
void rowClicked(const QModelIndex &index);
void reset(); void reset();
public slots: public slots: