diff --git a/src/plugins/debugger/basewindow.h b/src/plugins/debugger/basewindow.h index 733d3ddd50433735679a6cf86d4f33dfdc453fad..58987041781574024a51983c80c7e354039b3b9a 100644 --- a/src/plugins/debugger/basewindow.h +++ b/src/plugins/debugger/basewindow.h @@ -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; diff --git a/src/plugins/debugger/localsandexpressionswindow.cpp b/src/plugins/debugger/localsandexpressionswindow.cpp index 0211c3c6cadad52a175d933e09119340c05d3003..5e1bf28006e8ff793d046cf7f4c65b689ef4b9e0 100644 --- a/src/plugins/debugger/localsandexpressionswindow.cpp +++ b/src/plugins/debugger/localsandexpressionswindow.cpp @@ -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 diff --git a/src/plugins/debugger/localsandexpressionswindow.h b/src/plugins/debugger/localsandexpressionswindow.h index bf59a2618fecec8dda4659733b14112877ba21bf..ec7df5dcfedf76caf6a5723c9d373a62a16bed95 100644 --- a/src/plugins/debugger/localsandexpressionswindow.h +++ b/src/plugins/debugger/localsandexpressionswindow.h @@ -50,6 +50,7 @@ public: QWidget *returnWidget, QWidget *watchers, QWidget *parent = 0); void setShowLocals(bool showLocals); + QWidget *inspectorWidget() const; private slots: void showLocals(); diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp index d16c71c2a70b986e8752d71f74c9471965d7b145..cb1c86e472f57d2aff42571153157d517ef77b42 100644 --- a/src/plugins/debugger/qml/qmlengine.cpp +++ b/src/plugins/debugger/qml/qmlengine.cpp @@ -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); diff --git a/src/plugins/debugger/qml/qmlengine.h b/src/plugins/debugger/qml/qmlengine.h index 7f515403332091ef648a77f7ba3deef84bd368c6..fa1f3123838e2ca031f2524b0fd30768f424a125 100644 --- a/src/plugins/debugger/qml/qmlengine.h +++ b/src/plugins/debugger/qml/qmlengine.h @@ -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; diff --git a/src/plugins/debugger/qml/qmlinspectoradapter.cpp b/src/plugins/debugger/qml/qmlinspectoradapter.cpp index 8a4f2b064acccd9b0110715268e46977f234bfda..c2e51c76a04d8fdab668d4e9db6cf38b6e0a34fd 100644 --- a/src/plugins/debugger/qml/qmlinspectoradapter.cpp +++ b/src/plugins/debugger/qml/qmlinspectoradapter.cpp @@ -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() diff --git a/src/plugins/debugger/qml/qmlinspectoradapter.h b/src/plugins/debugger/qml/qmlinspectoradapter.h index dc5272d782899823ecdc7055e494bef660bd853b..11833e3173259c4185902dafe11354c2500c6f4f 100644 --- a/src/plugins/debugger/qml/qmlinspectoradapter.h +++ b/src/plugins/debugger/qml/qmlinspectoradapter.h @@ -75,7 +75,6 @@ public: signals: void expressionResult(); - void selectionChanged(); private slots: void clientStatusChanged(QmlDebug::ClientStatus status); diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp index 9a199d72bea815d57e81a6efe0c74d837690d1f3..331e5a8758a87b9396c01c46749af888d5b453d7 100644 --- a/src/plugins/debugger/watchwindow.cpp +++ b/src/plugins/debugger/watchwindow.cpp @@ -972,6 +972,11 @@ bool WatchTreeView::event(QEvent *ev) return BaseTreeView::event(ev); } +void WatchTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &) +{ + emit currentIndexChanged(current); +} + void WatchTreeView::editItem(const QModelIndex &idx) { Q_UNUSED(idx) // FIXME diff --git a/src/plugins/debugger/watchwindow.h b/src/plugins/debugger/watchwindow.h index 72912cd2809829dc485ff1bfbc23c5bc8ce30aa7..16aaf5c9e2c78057704e3404fa0a9d4b28da03ce 100644 --- a/src/plugins/debugger/watchwindow.h +++ b/src/plugins/debugger/watchwindow.h @@ -58,6 +58,9 @@ public slots: void watchExpression(const QString &exp, const QString &name); void handleItemIsExpanded(const QModelIndex &idx); +signals: + void currentIndexChanged(const QModelIndex ¤tIndex); + 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 ¤t, const QModelIndex &previous); void editItem(const QModelIndex &idx); void resetHelper(const QModelIndex &idx);