|
- /**
- * @file project_workspace_controller.h
- * @brief 定义工程树和当前编辑对象控制器
- * @version 1.0.0
- * @author suyu
- * @date 2026-08-22
- */
-
- #pragma once
-
- #include "domain/hmi_model.h"
- #include "domain/runtime_state.h"
-
- #include <QString>
-
- #include <functional>
- #include <string>
-
- class HmiEditorService;
- class HmiEditorWidget;
- class HmiNavigationService;
- class LogicEditorService;
- class LogicEditorWidget;
- class ProjectService;
- class RuntimeModeService;
- class RuntimeMonitorWidget;
- class QWidget;
- class QAction;
-
- namespace Ui {
- class MainWindow;
- }
-
- /**
- * 组织工程树、当前页面/逻辑选择和工程对象的界面刷新
- *
- * 它不直接改 Project,所有增删改都转发给对应服务
- */
- class ProjectWorkspaceController final
- {
- public:
- /** 报告工程操作结果,参数依次为操作名、消息和是否成功 */
- using ResultReporter = std::function<void(
- const QString &action, const QString &message, bool succeeded)>;
- /** 向状态栏报告一条带超时的消息 */
- using StatusReporter = std::function<void(
- const QString &message, int timeout_ms)>;
- /** 通知主窗口编辑状态已经发生变化 */
- using EditStateChanged = std::function<void()>;
-
- /** 创建工程树控制器并绑定主窗口服务和编辑器 */
- ProjectWorkspaceController(
- QWidget &parent,
- Ui::MainWindow &ui,
- ProjectService &project_service,
- HmiEditorService &hmi_editor_service,
- LogicEditorService &logic_editor_service,
- RuntimeModeService &runtime_mode_service,
- HmiNavigationService &hmi_navigation_service,
- HmiEditorWidget &hmi_editor_widget,
- LogicEditorWidget &logic_editor_widget,
- RuntimeMonitorWidget &runtime_monitor_widget,
- std::string ¤t_hmi_page_id,
- std::string ¤t_logic_id,
- std::function<void(const std::string &)> show_control_properties,
- std::function<void(const std::string &)> show_logic_properties,
- ResultReporter result_reporter,
- StatusReporter status_reporter,
- EditStateChanged edit_state_changed);
-
- /** 连接工程树动作和选择变化信号 */
- void configure();
- /** 根据当前工程重新生成工程树和编辑器内容 */
- void refresh();
- /** 根据当前选中对象更新工程树动作的可用状态 */
- void updateActions();
- /** 新增一个 HMI 页面 */
- void addPage();
- /** 新增一个控制逻辑 */
- void addLogic();
- /** 重命名当前选中的工程树项目 */
- void renameSelectedItem();
- /** 删除当前选中的工程树项目 */
- void deleteSelectedItem();
- /** 按偏移量移动当前选中的工程树项目 */
- void moveSelectedItem(int offset);
- /** 把当前选中的 HMI 页面设为初始页面 */
- void setSelectedPageAsInitial();
- /** 启用或停用当前选中的控制逻辑 */
- void toggleSelectedLogicEnabled();
-
- /** 返回当前 HMI 页面标识 */
- const std::string ¤tHmiPageId() const;
- /** 返回当前控制逻辑标识 */
- const std::string ¤tLogicId() const;
-
- private:
- /** 工程树项目的三种业务类型 */
- enum class ItemKind
- {
- Root = 0, // 工程树根节点
- HmiPage = 1, // HMI 页面节点
- ControlLogic = 2 // 控制逻辑节点
- };
-
- /** 处理工程树选择变化并刷新当前编辑器 */
- void handleSelectionChanged();
- /** 统一报告工程操作失败 */
- void reportFailure(
- const QString &action, const std::string &message) const;
-
- /** 主窗口父对象,不由控制器拥有 */
- QWidget &parent_;
- /** 主窗口的 Designer 界面对象 */
- Ui::MainWindow &ui_;
- /** 工程服务,不由控制器拥有 */
- ProjectService &project_service_;
- /** HMI 编辑服务,不由控制器拥有 */
- HmiEditorService &hmi_editor_service_;
- /** 梯形图编辑服务,不由控制器拥有 */
- LogicEditorService &logic_editor_service_;
- /** 运行模式服务,不由控制器拥有 */
- RuntimeModeService &runtime_mode_service_;
- /** HMI 页面导航服务,不由控制器拥有 */
- HmiNavigationService &hmi_navigation_service_;
- /** 主窗口中的 HMI 编辑器 */
- HmiEditorWidget &hmi_editor_widget_;
- /** 主窗口中的梯形图编辑器 */
- LogicEditorWidget &logic_editor_widget_;
- /** 运行监控控件 */
- RuntimeMonitorWidget &runtime_monitor_widget_;
- /** 主窗口保存的当前 HMI 页面标识 */
- std::string ¤t_hmi_page_id_;
- /** 主窗口保存的当前控制逻辑标识 */
- std::string ¤t_logic_id_;
- /** 显示 HMI 控件属性的回调 */
- std::function<void(const std::string &)> show_control_properties_;
- /** 显示梯形图节点属性的回调 */
- std::function<void(const std::string &)> show_logic_properties_;
- /** 工程操作结果回调 */
- ResultReporter result_reporter_;
- /** 状态栏消息回调 */
- StatusReporter status_reporter_;
- /** 编辑状态变化回调 */
- EditStateChanged edit_state_changed_;
-
- /** 新增页面动作 */
- QAction *add_page_action_ = nullptr;
- /** 新增逻辑动作 */
- QAction *add_logic_action_ = nullptr;
- /** 重命名动作 */
- QAction *rename_item_action_ = nullptr;
- /** 删除工程树项目动作 */
- QAction *delete_item_action_ = nullptr;
- /** 上移工程树项目动作 */
- QAction *move_item_up_action_ = nullptr;
- /** 下移工程树项目动作 */
- QAction *move_item_down_action_ = nullptr;
- /** 设置初始页面动作 */
- QAction *set_initial_page_action_ = nullptr;
- /** 启停控制逻辑动作 */
- QAction *toggle_logic_enabled_action_ = nullptr;
- };
|