Inspector: Set the context of console

The current selected item in the inspector view
is set as the context of the console.

Task-number: QTCREATORBUG-7439

Change-Id: Ibc980218751ce4afacf714cf1ab34f0a36550b2c
Reviewed-by: hjk <qthjk@ovi.com>
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Aurindam Jana
2012-10-05 13:42:14 +02:00
parent c90e1267c8
commit c2c58fecd7
9 changed files with 58 additions and 13 deletions

View File

@@ -53,6 +53,7 @@ public:
void setModel(QAbstractItemModel *model) { m_treeView->setModel(model); } void setModel(QAbstractItemModel *model) { m_treeView->setModel(model); }
QHeaderView *header() const { return m_treeView->header(); } QHeaderView *header() const { return m_treeView->header(); }
QAbstractItemModel *model() const { return m_treeView->model(); } QAbstractItemModel *model() const { return m_treeView->model(); }
QTreeView *treeView() const { return m_treeView; }
private: private:
QTreeView *m_treeView; QTreeView *m_treeView;

View File

@@ -35,6 +35,9 @@
#include <QSplitter> #include <QSplitter>
#include <QStackedWidget> #include <QStackedWidget>
const int LOCAL_WIDGET_INDEX = 0;
const int INSPECTOR_WIDGET_INDEX = 1;
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
@@ -79,7 +82,13 @@ void LocalsAndExpressionsWindow::setShowLocals(bool showLocals)
void LocalsAndExpressionsWindow::showLocals() void LocalsAndExpressionsWindow::showLocals()
{ {
m_localsAndInspector->setCurrentIndex(m_showLocals ? 0 : 1); m_localsAndInspector->setCurrentIndex(m_showLocals ? LOCAL_WIDGET_INDEX
: INSPECTOR_WIDGET_INDEX);
}
QWidget *LocalsAndExpressionsWindow::inspectorWidget() const
{
return m_localsAndInspector->widget(INSPECTOR_WIDGET_INDEX);
} }
} // namespace Internal } // namespace Internal

View File

@@ -50,6 +50,7 @@ public:
QWidget *returnWidget, QWidget *watchers, QWidget *parent = 0); QWidget *returnWidget, QWidget *watchers, QWidget *parent = 0);
void setShowLocals(bool showLocals); void setShowLocals(bool showLocals);
QWidget *inspectorWidget() const;
private slots: private slots:
void showLocals(); void showLocals();

View File

@@ -41,6 +41,8 @@
#include "debuggerrunner.h" #include "debuggerrunner.h"
#include "debuggerstringutils.h" #include "debuggerstringutils.h"
#include "debuggertooltipmanager.h" #include "debuggertooltipmanager.h"
#include "localsandexpressionswindow.h"
#include "watchwindow.h"
#include "breakhandler.h" #include "breakhandler.h"
#include "moduleshandler.h" #include "moduleshandler.h"
@@ -82,6 +84,8 @@
#include <QTcpSocket> #include <QTcpSocket>
#include <QHostAddress> #include <QHostAddress>
#include <QDockWidget>
#define DEBUG_QML 1 #define DEBUG_QML 1
#if DEBUG_QML #if DEBUG_QML
# define SDEBUG(s) qDebug() << s # define SDEBUG(s) qDebug() << s
@@ -292,7 +296,7 @@ QmlEngine::QmlEngine(const DebuggerStartParameters &startParameters)
SLOT(updateCurrentContext())); SLOT(updateCurrentContext()));
connect(this->stackHandler(), SIGNAL(currentIndexChanged()), connect(this->stackHandler(), SIGNAL(currentIndexChanged()),
SLOT(updateCurrentContext())); SLOT(updateCurrentContext()));
connect(&m_inspectorAdapter, SIGNAL(selectionChanged()), connect(inspectorTreeView(), SIGNAL(currentIndexChanged(QModelIndex)),
SLOT(updateCurrentContext())); SLOT(updateCurrentContext()));
connect(m_inspectorAdapter.agent(), SIGNAL( connect(m_inspectorAdapter.agent(), SIGNAL(
expressionResult(quint32,QVariant)), expressionResult(quint32,QVariant)),
@@ -1137,9 +1141,23 @@ void QmlEngine::documentUpdated(QmlJS::Document::Ptr doc)
void QmlEngine::updateCurrentContext() void QmlEngine::updateCurrentContext()
{ {
const QString context = state() == InferiorStopOk ? QString context;
stackHandler()->currentFrame().function if (state() == InferiorStopOk) {
: m_inspectorAdapter.currentSelectedDisplayName(); context = stackHandler()->currentFrame().function;
} else {
QModelIndex currentIndex = inspectorTreeView()->currentIndex();
const WatchData *currentData = watchHandler()->watchData(currentIndex);
const WatchData *parentData = watchHandler()->watchData(currentIndex.parent());
const WatchData *grandParentData = watchHandler()->watchData(
currentIndex.parent().parent());
if (currentData->id != parentData->id)
context = currentData->name;
else if (parentData->id != grandParentData->id)
context = parentData->name;
else
context = grandParentData->name;
}
QmlJS::ConsoleManagerInterface *consoleManager = qmlConsoleManager(); QmlJS::ConsoleManagerInterface *consoleManager = qmlConsoleManager();
if (consoleManager) if (consoleManager)
consoleManager->setContext(tr("Context: ").append(context)); consoleManager->setContext(tr("Context: ").append(context));
@@ -1187,8 +1205,9 @@ bool QmlEngine::evaluateScript(const QString &expression)
// Evaluate expression based on engine state // Evaluate expression based on engine state
// When engine->state() == InferiorStopOk, the expression is sent to debuggerClient. // When engine->state() == InferiorStopOk, the expression is sent to debuggerClient.
if (state() != InferiorStopOk) { if (state() != InferiorStopOk) {
QModelIndex currentIndex = inspectorTreeView()->currentIndex();
QmlInspectorAgent *agent = m_inspectorAdapter.agent(); QmlInspectorAgent *agent = m_inspectorAdapter.agent();
quint32 queryId = agent->queryExpressionResult(m_inspectorAdapter.currentSelectedDebugId(), quint32 queryId = agent->queryExpressionResult(watchHandler()->watchData(currentIndex)->id,
expression); expression);
if (queryId) { if (queryId) {
queryIds << queryId; queryIds << queryId;
@@ -1333,6 +1352,15 @@ bool QmlEngine::adjustBreakpointLineAndColumn(
return success; return success;
} }
WatchTreeView *QmlEngine::inspectorTreeView() const
{
DebuggerMainWindow *dw = qobject_cast<DebuggerMainWindow *>(debuggerCore()->mainWindow());
LocalsAndExpressionsWindow *leW = qobject_cast<LocalsAndExpressionsWindow *>(
dw->dockWidget(QLatin1String(Constants::DOCKWIDGET_WATCHERS))->widget());
WatchWindow *inspectorWindow = qobject_cast<WatchWindow *>(leW->inspectorWidget());
return qobject_cast<WatchTreeView *>(inspectorWindow->treeView());
}
DebuggerEngine *createQmlEngine(const DebuggerStartParameters &sp) DebuggerEngine *createQmlEngine(const DebuggerStartParameters &sp)
{ {
return new QmlEngine(sp); return new QmlEngine(sp);

View File

@@ -53,6 +53,7 @@ namespace Debugger {
namespace Internal { namespace Internal {
class QmlAdapter; class QmlAdapter;
class WatchTreeView;
class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator
{ {
@@ -183,6 +184,8 @@ private:
bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line, bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
quint32 *column, bool *valid); quint32 *column, bool *valid);
WatchTreeView *inspectorTreeView() const;
QmlAdapter m_adapter; QmlAdapter m_adapter;
QmlInspectorAdapter m_inspectorAdapter; QmlInspectorAdapter m_inspectorAdapter;
ProjectExplorer::ApplicationLauncher m_applicationLauncher; ProjectExplorer::ApplicationLauncher m_applicationLauncher;

View File

@@ -509,12 +509,7 @@ void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
if (target == EditorTarget) if (target == EditorTarget)
gotoObjectReferenceDefinition(obj.source()); gotoObjectReferenceDefinition(obj.source());
if (!agent()->selectObjectInTree(obj.debugId())) agent()->selectObjectInTree(obj.debugId());
return;
m_currentSelectedDebugId = obj.debugId();
m_currentSelectedDebugName = agent()->displayName(obj.debugId());
emit selectionChanged();
} }
void QmlInspectorAdapter::deletePreviews() void QmlInspectorAdapter::deletePreviews()

View File

@@ -75,7 +75,6 @@ public:
signals: signals:
void expressionResult(); void expressionResult();
void selectionChanged();
private slots: private slots:
void clientStatusChanged(QmlDebug::ClientStatus status); void clientStatusChanged(QmlDebug::ClientStatus status);

View File

@@ -972,6 +972,11 @@ bool WatchTreeView::event(QEvent *ev)
return BaseTreeView::event(ev); return BaseTreeView::event(ev);
} }
void WatchTreeView::currentChanged(const QModelIndex &current, const QModelIndex &)
{
emit currentIndexChanged(current);
}
void WatchTreeView::editItem(const QModelIndex &idx) void WatchTreeView::editItem(const QModelIndex &idx)
{ {
Q_UNUSED(idx) // FIXME Q_UNUSED(idx) // FIXME

View File

@@ -58,6 +58,9 @@ public slots:
void watchExpression(const QString &exp, const QString &name); void watchExpression(const QString &exp, const QString &name);
void handleItemIsExpanded(const QModelIndex &idx); void handleItemIsExpanded(const QModelIndex &idx);
signals:
void currentIndexChanged(const QModelIndex &currentIndex);
private: private:
Q_SLOT void resetHelper(); Q_SLOT void resetHelper();
Q_SLOT void expandNode(const QModelIndex &idx); Q_SLOT void expandNode(const QModelIndex &idx);
@@ -70,6 +73,7 @@ private:
void dragMoveEvent(QDragMoveEvent *ev); void dragMoveEvent(QDragMoveEvent *ev);
void mouseDoubleClickEvent(QMouseEvent *ev); void mouseDoubleClickEvent(QMouseEvent *ev);
bool event(QEvent *ev); bool event(QEvent *ev);
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
void editItem(const QModelIndex &idx); void editItem(const QModelIndex &idx);
void resetHelper(const QModelIndex &idx); void resetHelper(const QModelIndex &idx);