aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-11-15 16:42:25 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-11-20 14:05:08 +0000
commit2e6aa7a0eda53bd3440c10b6facf504558e19c70 (patch)
tree1b2080b5feb16e0c7b359ed89a0161a68fb9224e
parentd29e7a03715ffd8e20a3047b9221d4863605fcd0 (diff)
QML Inspector: Use lists of int as selections
The inspector service natively supports multi-selection. Instead of converting between multi and single selection all the time, just use the multi selections and only collapse to one row when interacting with the view. Change-Id: Ie969225f955c61b306cfbec4973ffc724ef1e224 Reviewed-by: hjk <hjk@qt.io>
-rw-r--r--src/plugins/debugger/qml/qmlinspectoragent.cpp83
-rw-r--r--src/plugins/debugger/qml/qmlinspectoragent.h12
2 files changed, 40 insertions, 55 deletions
diff --git a/src/plugins/debugger/qml/qmlinspectoragent.cpp b/src/plugins/debugger/qml/qmlinspectoragent.cpp
index 8d5cea730f..8383b0c70e 100644
--- a/src/plugins/debugger/qml/qmlinspectoragent.cpp
+++ b/src/plugins/debugger/qml/qmlinspectoragent.cpp
@@ -164,26 +164,26 @@ void QmlInspectorAgent::watchDataSelected(int id)
}
}
-bool QmlInspectorAgent::selectObjectInTree(int debugId)
-{
- qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')' << endl
- << " " << debugId << "already fetched? "
- << m_debugIdToIname.contains(debugId);
-
- if (m_debugIdToIname.contains(debugId)) {
- QString iname = m_debugIdToIname.value(debugId);
- QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
- qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
- m_qmlEngine->watchHandler()->setCurrentItem(iname);
- m_objectToSelect = WatchItem::InvalidId;
- return true;
- }
+void QmlInspectorAgent::selectObjectsInTree(const QList<int> &debugIds)
+{
+ qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugIds << ')';
+
+ for (int debugId : debugIds) {
+ if (m_debugIdToIname.contains(debugId)) {
+ const QString iname = m_debugIdToIname.value(debugId);
+ QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
+ qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
- // we may have to fetch it
- m_objectToSelect = debugId;
- using namespace QmlDebug::Constants;
- fetchObject(debugId);
- return false;
+ // We can't multi-select in the watch handler for now ...
+ m_qmlEngine->watchHandler()->setCurrentItem(iname);
+ m_objectsToSelect.removeOne(debugId);
+ continue;
+ }
+
+ // we may have to fetch it
+ m_objectsToSelect.append(debugId);
+ fetchObject(debugId);
+ }
}
@@ -470,17 +470,16 @@ void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object)
qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Insertion took "
<< timeElapsed.elapsed() << " ms";
- if (object.debugId() == m_debugIdToSelect) {
- m_debugIdToSelect = WatchItem::InvalidId;
- selectObject(object.debugId(), object.source(), m_targetToSync);
- }
-
- if (m_debugIdToIname.contains(m_objectToSelect)) {
- // select item in view
- QString iname = m_debugIdToIname.value(m_objectToSelect);
- qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
- m_qmlEngine->watchHandler()->setCurrentItem(iname);
- m_objectToSelect = WatchItem::InvalidId;
+ for (auto it = m_objectsToSelect.begin(); it != m_objectsToSelect.end();) {
+ if (m_debugIdToIname.contains(*it)) {
+ // select item in view
+ QString iname = m_debugIdToIname.value(*it);
+ qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
+ m_qmlEngine->watchHandler()->setCurrentItem(iname);
+ it = m_objectsToSelect.erase(it);
+ } else {
+ ++it;
+ }
}
m_qmlEngine->watchHandler()->updateLocalsWindow();
m_qmlEngine->watchHandler()->reexpandItems();
@@ -505,7 +504,8 @@ void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
const QString filePath = m_qmlEngine->toFileInProject(fileUrl);
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum));
- foreach (const ObjectReference &it, ref.children())
+ const auto children = ref.children();
+ for (const ObjectReference &it : children)
buildDebugIdHashRecursive(it);
}
@@ -670,12 +670,8 @@ void QmlInspectorAgent::toolsClientStateChanged(QmlDebugClient::State state)
void QmlInspectorAgent::selectObjectsFromToolsClient(const QList<int> &debugIds)
{
- if (debugIds.isEmpty())
- return;
-
- m_targetToSync = EditorTarget;
- m_debugIdToSelect = debugIds.first();
- selectObject(m_debugIdToSelect, m_debugIdLocations.value(m_debugIdToSelect), EditorTarget);
+ if (!debugIds.isEmpty())
+ selectObjects(debugIds, m_debugIdLocations.value(debugIds.first()));
}
void QmlInspectorAgent::onSelectActionTriggered(bool checked)
@@ -701,16 +697,11 @@ void QmlInspectorAgent::jumpToObjectDefinitionInEditor(const FileReference &objS
Core::EditorManager::openEditorAt(fileName, objSource.lineNumber());
}
-void QmlInspectorAgent::selectObject(int debugId, const QmlDebug::FileReference &source,
- SelectionTarget target)
+void QmlInspectorAgent::selectObjects(const QList<int> &debugIds,
+ const QmlDebug::FileReference &source)
{
- if (target == ToolTarget)
- m_toolsClient->selectObjects({debugId});
-
- if (target == EditorTarget)
- jumpToObjectDefinitionInEditor(source);
-
- selectObjectInTree(debugId);
+ jumpToObjectDefinitionInEditor(source);
+ selectObjectsInTree(debugIds);
}
void QmlInspectorAgent::enableTools(const bool enable)
diff --git a/src/plugins/debugger/qml/qmlinspectoragent.h b/src/plugins/debugger/qml/qmlinspectoragent.h
index 244c054be6..dd0e999e5b 100644
--- a/src/plugins/debugger/qml/qmlinspectoragent.h
+++ b/src/plugins/debugger/qml/qmlinspectoragent.h
@@ -61,7 +61,7 @@ public:
void enableTools(bool enable);
private:
- bool selectObjectInTree(int debugId);
+ void selectObjectsInTree(const QList<int> &debugIds);
void addObjectWatch(int objectDebugId);
void reloadEngines();
@@ -99,11 +99,8 @@ private:
void onReloaded();
void jumpToObjectDefinitionInEditor(const QmlDebug::FileReference &objSource);
- enum SelectionTarget { NoTarget, ToolTarget, EditorTarget };
- void selectObject(int debugId, const QmlDebug::FileReference &source,
- SelectionTarget target);
+ void selectObjects(const QList<int> &debugIds, const QmlDebug::FileReference &source);
-private:
QPointer<QmlEngine> m_qmlEngine;
QmlDebug::QmlEngineDebugClient *m_engineClient = nullptr;
QmlDebug::QmlToolsClient *m_toolsClient = nullptr;
@@ -111,8 +108,7 @@ private:
quint32 m_engineQueryId = 0;
quint32 m_rootContextQueryId = 0;
- int m_objectToSelect = WatchItem::InvalidId;
- int m_debugIdToSelect = WatchItem::InvalidId;
+ QList<int> m_objectsToSelect;
QList<quint32> m_objectTreeQueryIds;
QStack<QmlDebug::ObjectReference> m_objectStack;
@@ -124,8 +120,6 @@ private:
QList<int> m_fetchDataIds;
QTimer m_delayQueryTimer;
- SelectionTarget m_targetToSync = NoTarget;
-
// toolbar
Core::Context m_inspectorToolsContext;
QAction *m_selectAction = nullptr;