🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
PilotAgent.hpp
浏览该文件的文档.
1
19
20#pragma once
21
22#include "AstGlobal.h"
23#include <QObject>
24#include <QHash>
25#include <string>
26#include <sstream>
27#include <functional>
28
29class QWidget;
30class QAction;
31class QMenu;
32class QRubberBand;
33
34AST_NAMESPACE_BEGIN
35
45class AST_UIPILOT_API PilotAgent : public QObject
46{
47 Q_OBJECT
48
49public:
51 static PilotAgent* instance();
52
54 explicit PilotAgent(QObject* parent = nullptr);
55
57 ~PilotAgent() override;
58
59 // ---- ref 管理 ----
60
62 int ref(QWidget* widget);
63
65 int ref(QAction* action);
66
68 QWidget* widget(int refId) const;
69
71 QAction* action(int refId) const;
72
74 QObject* object(int refId) const;
75
77 std::string objectType(int refId) const;
78
80 bool isValidRef(int refId) const;
81
82 // ---- 快照 ----
83
85 std::string snapshot(int maxDepth = 8);
86
88 std::string snapshotOf(QWidget* root, int maxDepth = 8);
89
91 QWidget* activeModalDialog() const;
92
93 // ---- 操作 ----
94
96 void highlight(QWidget* widget, int durationMs = 2000);
97
99 void waitForIdle(int timeoutMs = 5000);
100
102 QList<QWidget*> topLevelWidgets() const;
103
105 bool triggerAction(QAction* action);
106
109 QList<QAction*> expandMenu(QMenu* menu);
110
112 bool isAutoSnapshot() const{return autoSnapshot_;}
113
114protected:
115 bool eventFilter(QObject* obj, QEvent* event) override;
116
117private:
118 // ---- 剪枝 ----
119 static bool isWorthReporting(QWidget* w);
120 static bool isInteractive(QWidget* w);
121
122 // ---- 快照输出 ----
123 void formatWidget(QWidget* w, int depth, std::ostringstream& out);
124 void formatAction(QAction* a, int depth, std::ostringstream& out);
125 void walkWidgetTree(QWidget* root, int depth, int maxDepth, std::ostringstream& out);
126 void formatWidgetValue(QWidget* w, std::ostringstream& out);
127 static QString statusTags(QWidget* w);
128 static QString friendlyName(QWidget* w);
129
130 // ---- 内存清理 ----
131 void cleanupRef(int refId);
132
133 bool autoSnapshot_ = false;
134
135 // ---- ref 映射 ----
136 QHash<QWidget*, int> widgetToRef_;
137 QHash<int, QWidget*> refToWidget_;
138 QHash<QAction*, int> actionToRef_;
139 QHash<int, QAction*> refToAction_;
140
141 int nextRef_ = 1;
142 static PilotAgent* s_instance;
143};
144
147AST_NAMESPACE_END
Qt控件生命周期管理与界面快照生成
定义 PilotAgent.hpp:46
bool isAutoSnapshot() const
是否自动生成快照
定义 PilotAgent.hpp:112