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>
This commit is contained in:
Ulf Hermann
2018-11-15 16:42:25 +01:00
parent d29e7a0371
commit 2e6aa7a0ed
2 changed files with 38 additions and 53 deletions

View File

@@ -164,27 +164,27 @@ void QmlInspectorAgent::watchDataSelected(int id)
} }
} }
bool QmlInspectorAgent::selectObjectInTree(int debugId) void QmlInspectorAgent::selectObjectsInTree(const QList<int> &debugIds)
{ {
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')' << endl qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugIds << ')';
<< " " << debugId << "already fetched? "
<< m_debugIdToIname.contains(debugId);
if (m_debugIdToIname.contains(debugId)) { for (int debugId : debugIds) {
QString iname = m_debugIdToIname.value(debugId); if (m_debugIdToIname.contains(debugId)) {
QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname); const QString iname = m_debugIdToIname.value(debugId);
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree"; QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
m_qmlEngine->watchHandler()->setCurrentItem(iname); qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
m_objectToSelect = WatchItem::InvalidId;
return true; // 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);
} }
// we may have to fetch it
m_objectToSelect = debugId;
using namespace QmlDebug::Constants;
fetchObject(debugId);
return false;
} }
void QmlInspectorAgent::addObjectWatch(int objectDebugId) void QmlInspectorAgent::addObjectWatch(int objectDebugId)
@@ -470,17 +470,16 @@ void QmlInspectorAgent::insertObjectInTree(const ObjectReference &object)
qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Insertion took " qCDebug(qmlInspectorLog) << __FUNCTION__ << "Time: Insertion took "
<< timeElapsed.elapsed() << " ms"; << timeElapsed.elapsed() << " ms";
if (object.debugId() == m_debugIdToSelect) { for (auto it = m_objectsToSelect.begin(); it != m_objectsToSelect.end();) {
m_debugIdToSelect = WatchItem::InvalidId; if (m_debugIdToIname.contains(*it)) {
selectObject(object.debugId(), object.source(), m_targetToSync); // select item in view
} QString iname = m_debugIdToIname.value(*it);
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
if (m_debugIdToIname.contains(m_objectToSelect)) { m_qmlEngine->watchHandler()->setCurrentItem(iname);
// select item in view it = m_objectsToSelect.erase(it);
QString iname = m_debugIdToIname.value(m_objectToSelect); } else {
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree"; ++it;
m_qmlEngine->watchHandler()->setCurrentItem(iname); }
m_objectToSelect = WatchItem::InvalidId;
} }
m_qmlEngine->watchHandler()->updateLocalsWindow(); m_qmlEngine->watchHandler()->updateLocalsWindow();
m_qmlEngine->watchHandler()->reexpandItems(); m_qmlEngine->watchHandler()->reexpandItems();
@@ -505,7 +504,8 @@ void QmlInspectorAgent::buildDebugIdHashRecursive(const ObjectReference &ref)
const QString filePath = m_qmlEngine->toFileInProject(fileUrl); const QString filePath = m_qmlEngine->toFileInProject(fileUrl);
m_debugIdLocations.insert(ref.debugId(), FileReference(filePath, lineNum, colNum)); 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); buildDebugIdHashRecursive(it);
} }
@@ -670,12 +670,8 @@ void QmlInspectorAgent::toolsClientStateChanged(QmlDebugClient::State state)
void QmlInspectorAgent::selectObjectsFromToolsClient(const QList<int> &debugIds) void QmlInspectorAgent::selectObjectsFromToolsClient(const QList<int> &debugIds)
{ {
if (debugIds.isEmpty()) if (!debugIds.isEmpty())
return; selectObjects(debugIds, m_debugIdLocations.value(debugIds.first()));
m_targetToSync = EditorTarget;
m_debugIdToSelect = debugIds.first();
selectObject(m_debugIdToSelect, m_debugIdLocations.value(m_debugIdToSelect), EditorTarget);
} }
void QmlInspectorAgent::onSelectActionTriggered(bool checked) void QmlInspectorAgent::onSelectActionTriggered(bool checked)
@@ -701,16 +697,11 @@ void QmlInspectorAgent::jumpToObjectDefinitionInEditor(const FileReference &objS
Core::EditorManager::openEditorAt(fileName, objSource.lineNumber()); Core::EditorManager::openEditorAt(fileName, objSource.lineNumber());
} }
void QmlInspectorAgent::selectObject(int debugId, const QmlDebug::FileReference &source, void QmlInspectorAgent::selectObjects(const QList<int> &debugIds,
SelectionTarget target) const QmlDebug::FileReference &source)
{ {
if (target == ToolTarget) jumpToObjectDefinitionInEditor(source);
m_toolsClient->selectObjects({debugId}); selectObjectsInTree(debugIds);
if (target == EditorTarget)
jumpToObjectDefinitionInEditor(source);
selectObjectInTree(debugId);
} }
void QmlInspectorAgent::enableTools(const bool enable) void QmlInspectorAgent::enableTools(const bool enable)

View File

@@ -61,7 +61,7 @@ public:
void enableTools(bool enable); void enableTools(bool enable);
private: private:
bool selectObjectInTree(int debugId); void selectObjectsInTree(const QList<int> &debugIds);
void addObjectWatch(int objectDebugId); void addObjectWatch(int objectDebugId);
void reloadEngines(); void reloadEngines();
@@ -99,11 +99,8 @@ private:
void onReloaded(); void onReloaded();
void jumpToObjectDefinitionInEditor(const QmlDebug::FileReference &objSource); void jumpToObjectDefinitionInEditor(const QmlDebug::FileReference &objSource);
enum SelectionTarget { NoTarget, ToolTarget, EditorTarget }; void selectObjects(const QList<int> &debugIds, const QmlDebug::FileReference &source);
void selectObject(int debugId, const QmlDebug::FileReference &source,
SelectionTarget target);
private:
QPointer<QmlEngine> m_qmlEngine; QPointer<QmlEngine> m_qmlEngine;
QmlDebug::QmlEngineDebugClient *m_engineClient = nullptr; QmlDebug::QmlEngineDebugClient *m_engineClient = nullptr;
QmlDebug::QmlToolsClient *m_toolsClient = nullptr; QmlDebug::QmlToolsClient *m_toolsClient = nullptr;
@@ -111,8 +108,7 @@ private:
quint32 m_engineQueryId = 0; quint32 m_engineQueryId = 0;
quint32 m_rootContextQueryId = 0; quint32 m_rootContextQueryId = 0;
int m_objectToSelect = WatchItem::InvalidId; QList<int> m_objectsToSelect;
int m_debugIdToSelect = WatchItem::InvalidId;
QList<quint32> m_objectTreeQueryIds; QList<quint32> m_objectTreeQueryIds;
QStack<QmlDebug::ObjectReference> m_objectStack; QStack<QmlDebug::ObjectReference> m_objectStack;
@@ -124,8 +120,6 @@ private:
QList<int> m_fetchDataIds; QList<int> m_fetchDataIds;
QTimer m_delayQueryTimer; QTimer m_delayQueryTimer;
SelectionTarget m_targetToSync = NoTarget;
// toolbar // toolbar
Core::Context m_inspectorToolsContext; Core::Context m_inspectorToolsContext;
QAction *m_selectAction = nullptr; QAction *m_selectAction = nullptr;