From c88317d7adeeb266e356ca4d550d30ef49e01271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Fri, 28 Jun 2024 10:41:51 +0200 Subject: [PATCH] feat(MonitoringTool): Search improved Closes: #15181 --- monitoring/ModelInspectionPane.qml | 2 + monitoring/MonitorEntryPoint.qml | 69 ++++++++----------- ui/include/StatusDesktop/Monitoring/Monitor.h | 2 +- ui/src/StatusDesktop/Monitoring/Monitor.cpp | 31 ++++++++- 4 files changed, 61 insertions(+), 43 deletions(-) diff --git a/monitoring/ModelInspectionPane.qml b/monitoring/ModelInspectionPane.qml index 4e9efabd47..553dcce357 100644 --- a/monitoring/ModelInspectionPane.qml +++ b/monitoring/ModelInspectionPane.qml @@ -83,6 +83,8 @@ Pane { } Label { + visible: listView.count + text: "Hint: use right/left button click on a column " + "header to adjust width, press cell content to " + "see full value" diff --git a/monitoring/MonitorEntryPoint.qml b/monitoring/MonitorEntryPoint.qml index e85ad503b0..230388b1b5 100644 --- a/monitoring/MonitorEntryPoint.qml +++ b/monitoring/MonitorEntryPoint.qml @@ -17,7 +17,6 @@ Component { Settings { property alias tabIndex: tabBar.currentIndex property alias modelObjectName: objectNameTextFiled.text - property alias modelObjectRootName: rootTextField.text } TabBar { @@ -287,28 +286,10 @@ Component { } } - Item { + Pane { ColumnLayout { anchors.fill: parent - Label { - Layout.fillWidth: true - wrapMode: Text.Wrap - - text: "Note: 'applicationWindow' is good root object in" - + " most cases. 'WalletStores.RootStore' and" - + " `SharedStores.RootStore` are also exposed for" - + " convenience for models created within those singletons. \n\n" - + " Hack (see #15181): If you want to inspect a model that is not" - + " from the root object (under a repeater), add objectName to a dummy object in AppMain.qml: \n" - + " property var modelIWantToInspect: SortFilterProxyModel { \n" - + " objectName: \"YYY\" \n" - + " } \n" - + " and inside your item add something like this: \n" - + " Component.onCompleted: appMain.modelIWantToInspect.sourceModel = this.model \n" - + " Then you can use 'YYY' as the object name in this search." - } - RowLayout { Layout.fillHeight: false Layout.fillWidth: true @@ -320,38 +301,46 @@ Component { TextField { id: objectNameTextFiled + Layout.fillWidth: true + selectByMouse: true - } - - Label { - text: "Root:" - } - - TextField { - id: rootTextField - - text: "applicationWindow" - selectByMouse: true + onAccepted: searchButton.clicked() } Button { + id: searchButton + text: "Search" onClicked: { - let rootObj = null + const roots = [ + applicationWindow, + WalletStores.RootStore, + SharedStores.RootStore + ] - try { - rootObj = eval(rootTextField.text) - } catch (error) { - objLabel.objStr = "Root object not found!" + let obj = null + + for (let root of roots) { + obj = Monitor.findChild(root, objectNameTextFiled.text) + + if (obj) + break + } + + if (!obj) { + objLabel.objStr = "Model not found" + rolesModelContent.model = null return } - const obj = Monitor.findChild( - rootObj, objectNameTextFiled.text) + if (!Monitor.isModel(obj)) { + objLabel.objStr = "Found object is not a model" + rolesModelContent.model = null + return + } - objLabel.objStr = obj && Monitor.isModel(obj) - ? obj.toString() : "Model not found!" + objLabel.objStr = obj.toString() rolesModelContent.model = obj } } diff --git a/ui/include/StatusDesktop/Monitoring/Monitor.h b/ui/include/StatusDesktop/Monitoring/Monitor.h index 69620d607b..52e8b244d3 100644 --- a/ui/include/StatusDesktop/Monitoring/Monitor.h +++ b/ui/include/StatusDesktop/Monitoring/Monitor.h @@ -26,7 +26,7 @@ public: Q_INVOKABLE QString typeName(const QVariant &obj) const; Q_INVOKABLE QJSValue modelRoles(QAbstractItemModel *model) const; - Q_INVOKABLE QObject* findChild(QObject* obj, const QString& name) const; + Q_INVOKABLE QObject* findChild(QObject* parent, const QString& name) const; static Monitor& instance(); static QObject* qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine); diff --git a/ui/src/StatusDesktop/Monitoring/Monitor.cpp b/ui/src/StatusDesktop/Monitoring/Monitor.cpp index d8fa838981..a3177154da 100644 --- a/ui/src/StatusDesktop/Monitoring/Monitor.cpp +++ b/ui/src/StatusDesktop/Monitoring/Monitor.cpp @@ -4,7 +4,9 @@ #include #include #include +#include #include +#include void Monitor::initialize(QQmlApplicationEngine* engine) { @@ -47,9 +49,34 @@ bool Monitor::isModel(const QVariant &obj) const return qobject_cast(obj.value()) != nullptr; } -QObject* Monitor::findChild(QObject* obj, const QString& name) const +QObject* Monitor::findChild(QObject* parent, const QString& name) const { - return obj == nullptr ? nullptr : obj->findChild(name); + if (!parent) + return nullptr; + + QSet children(parent->children().cbegin(), + parent->children().cend()); + + if (auto quickItem = qobject_cast(parent)) { + QList visualChildren = quickItem->childItems(); + + for (auto c : visualChildren) + children << c; + } + + for (auto c : qAsConst(children)) { + if (c->objectName() == name) + return c; + } + + for (auto c : qAsConst(children)) { + auto obj = findChild(c, name); + + if (obj) + return obj; + } + + return nullptr; } QString Monitor::typeName(const QVariant &obj) const