Commit c2c58fec authored by Aurindam Jana's avatar Aurindam Jana

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: default avatarhjk <qthjk@ovi.com>
Reviewed-by: default avatarKai Koehne <kai.koehne@digia.com>
parent c90e1267
......@@ -53,6 +53,7 @@ public:
void setModel(QAbstractItemModel *model) { m_treeView->setModel(model); }
QHeaderView *header() const { return m_treeView->header(); }
QAbstractItemModel *model() const { return m_treeView->model(); }
QTreeView *treeView() const { return m_treeView; }
private:
QTreeView *m_treeView;
......
......@@ -35,6 +35,9 @@
#include <QSplitter>
#include <QStackedWidget>
const int LOCAL_WIDGET_INDEX = 0;
const int INSPECTOR_WIDGET_INDEX = 1;
namespace Debugger {
namespace Internal {
......@@ -79,7 +82,13 @@ void LocalsAndExpressionsWindow::setShowLocals(bool 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
......
......@@ -50,6 +50,7 @@ public:
QWidget *returnWidget, QWidget *watchers, QWidget *parent = 0);
void setShowLocals(bool showLocals);
QWidget *inspectorWidget() const;
private slots:
void showLocals();
......
......@@ -41,6 +41,8 @@
#include "debuggerrunner.h"
#include "debuggerstringutils.h"
#include "debuggertooltipmanager.h"
#include "localsandexpressionswindow.h"
#include "watchwindow.h"
#include "breakhandler.h"
#include "moduleshandler.h"
......@@ -82,6 +84,8 @@
#include <QTcpSocket>
#include <QHostAddress>
#include <QDockWidget>
#define DEBUG_QML 1
#if DEBUG_QML
# define SDEBUG(s) qDebug() << s
......@@ -292,7 +296,7 @@ QmlEngine::QmlEngine(const DebuggerStartParameters &startParameters)
SLOT(updateCurrentContext()));
connect(this->stackHandler(), SIGNAL(currentIndexChanged()),
SLOT(updateCurrentContext()));
connect(&m_inspectorAdapter, SIGNAL(selectionChanged()),
connect(inspectorTreeView(), SIGNAL(currentIndexChanged(QModelIndex)),
SLOT(updateCurrentContext()));
connect(m_inspectorAdapter.agent(), SIGNAL(
expressionResult(quint32,QVariant)),
......@@ -1137,9 +1141,23 @@ void QmlEngine::documentUpdated(QmlJS::Document::Ptr doc)
void QmlEngine::updateCurrentContext()
{
const QString context = state() == InferiorStopOk ?
stackHandler()->currentFrame().function
: m_inspectorAdapter.currentSelectedDisplayName();
QString context;
if (state() == InferiorStopOk) {
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();
if (consoleManager)
consoleManager->setContext(tr("Context: ").append(context));
......@@ -1187,8 +1205,9 @@ bool QmlEngine::evaluateScript(const QString &expression)
// Evaluate expression based on engine state
// When engine->state() == InferiorStopOk, the expression is sent to debuggerClient.
if (state() != InferiorStopOk) {
QModelIndex currentIndex = inspectorTreeView()->currentIndex();
QmlInspectorAgent *agent = m_inspectorAdapter.agent();
quint32 queryId = agent->queryExpressionResult(m_inspectorAdapter.currentSelectedDebugId(),
quint32 queryId = agent->queryExpressionResult(watchHandler()->watchData(currentIndex)->id,
expression);
if (queryId) {
queryIds << queryId;
......@@ -1333,6 +1352,15 @@ bool QmlEngine::adjustBreakpointLineAndColumn(
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)
{
return new QmlEngine(sp);
......
......@@ -53,6 +53,7 @@ namespace Debugger {
namespace Internal {
class QmlAdapter;
class WatchTreeView;
class QmlEngine : public DebuggerEngine, QmlJS::IScriptEvaluator
{
......@@ -183,6 +184,8 @@ private:
bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
quint32 *column, bool *valid);
WatchTreeView *inspectorTreeView() const;
QmlAdapter m_adapter;
QmlInspectorAdapter m_inspectorAdapter;
ProjectExplorer::ApplicationLauncher m_applicationLauncher;
......
......@@ -509,12 +509,7 @@ void QmlInspectorAdapter::selectObject(const ObjectReference &obj,
if (target == EditorTarget)
gotoObjectReferenceDefinition(obj.source());
if (!agent()->selectObjectInTree(obj.debugId()))
return;
m_currentSelectedDebugId = obj.debugId();
m_currentSelectedDebugName = agent()->displayName(obj.debugId());
emit selectionChanged();
agent()->selectObjectInTree(obj.debugId());
}
void QmlInspectorAdapter::deletePreviews()
......
......@@ -75,7 +75,6 @@ public:
signals:
void expressionResult();
void selectionChanged();
private slots:
void clientStatusChanged(QmlDebug::ClientStatus status);
......
......@@ -972,6 +972,11 @@ bool WatchTreeView::event(QEvent *ev)
return BaseTreeView::event(ev);
}
void WatchTreeView::currentChanged(const QModelIndex &current, const QModelIndex &)
{
emit currentIndexChanged(current);
}
void WatchTreeView::editItem(const QModelIndex &idx)
{
Q_UNUSED(idx) // FIXME
......
......@@ -58,6 +58,9 @@ public slots:
void watchExpression(const QString &exp, const QString &name);
void handleItemIsExpanded(const QModelIndex &idx);
signals:
void currentIndexChanged(const QModelIndex &currentIndex);
private:
Q_SLOT void resetHelper();
Q_SLOT void expandNode(const QModelIndex &idx);
......@@ -70,6 +73,7 @@ private:
void dragMoveEvent(QDragMoveEvent *ev);
void mouseDoubleClickEvent(QMouseEvent *ev);
bool event(QEvent *ev);
void currentChanged(const QModelIndex &current, const QModelIndex &previous);
void editItem(const QModelIndex &idx);
void resetHelper(const QModelIndex &idx);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment