forked from qt-creator/qt-creator
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:
@@ -164,26 +164,26 @@ void QmlInspectorAgent::watchDataSelected(int id)
|
||||
}
|
||||
}
|
||||
|
||||
bool QmlInspectorAgent::selectObjectInTree(int debugId)
|
||||
void QmlInspectorAgent::selectObjectsInTree(const QList<int> &debugIds)
|
||||
{
|
||||
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugId << ')' << endl
|
||||
<< " " << debugId << "already fetched? "
|
||||
<< m_debugIdToIname.contains(debugId);
|
||||
qCDebug(qmlInspectorLog) << __FUNCTION__ << '(' << debugIds << ')';
|
||||
|
||||
for (int debugId : debugIds) {
|
||||
if (m_debugIdToIname.contains(debugId)) {
|
||||
QString iname = m_debugIdToIname.value(debugId);
|
||||
const QString iname = m_debugIdToIname.value(debugId);
|
||||
QTC_ASSERT(iname.startsWith("inspect."), qDebug() << iname);
|
||||
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
|
||||
|
||||
// We can't multi-select in the watch handler for now ...
|
||||
m_qmlEngine->watchHandler()->setCurrentItem(iname);
|
||||
m_objectToSelect = WatchItem::InvalidId;
|
||||
return true;
|
||||
m_objectsToSelect.removeOne(debugId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// we may have to fetch it
|
||||
m_objectToSelect = debugId;
|
||||
using namespace QmlDebug::Constants;
|
||||
m_objectsToSelect.append(debugId);
|
||||
fetchObject(debugId);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
for (auto it = m_objectsToSelect.begin(); it != m_objectsToSelect.end();) {
|
||||
if (m_debugIdToIname.contains(*it)) {
|
||||
// select item in view
|
||||
QString iname = m_debugIdToIname.value(m_objectToSelect);
|
||||
QString iname = m_debugIdToIname.value(*it);
|
||||
qCDebug(qmlInspectorLog) << " selecting" << iname << "in tree";
|
||||
m_qmlEngine->watchHandler()->setCurrentItem(iname);
|
||||
m_objectToSelect = WatchItem::InvalidId;
|
||||
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);
|
||||
selectObjectsInTree(debugIds);
|
||||
}
|
||||
|
||||
void QmlInspectorAgent::enableTools(const bool enable)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user