XNSim/XNEditor/mainwindow.h
2025-04-28 12:25:20 +08:00

292 lines
6.2 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file mainwindow.h
* @author jinchao
* @brief 主窗口类
* @version 1.0
* @date 2025-02-14
*
* @copyright Copyright (c) 2025 COMAC
*
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QXmlStreamAttributes>
#include <QVector>
#include <QLineEdit>
#include <QCloseEvent>
#include <QTableWidget>
#include <QSharedPointer>
#include <QTreeWidgetItem>
#include <QDomDocument>
QT_BEGIN_NAMESPACE
namespace Ui
{
class MainWindow;
}
QT_END_NAMESPACE
/**
* @brief 成员变量结构体
*/
struct MemberVariable {
QString dataType;
QString variableName;
bool isArray;
QVector<int> arraySizes;
QString description;
};
/**
* @brief 结构体定义结构体
*/
struct StructDefinition {
QString structName;
QVector<QSharedPointer<MemberVariable>> memberVariables;
};
/**
* @brief 命名空间定义结构体
*/
struct NamespaceDefinition {
QString namespaceName;
QVector<QSharedPointer<StructDefinition>> structDefinitions;
QVector<QSharedPointer<NamespaceDefinition>> childNamespaces;
};
/**
* @brief 主窗口类
*/
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
/**
* @brief 构造函数
* @param parent 父窗口
*/
MainWindow(QWidget *parent = nullptr);
/**
* @brief 构造函数
* @param fileName 文件名
* @param parent 父窗口
*/
MainWindow(QString fileName, QWidget *parent = nullptr);
/**
* @brief 析构函数
*/
~MainWindow();
public slots:
/**
* @brief 新建文件槽函数
*/
void onNewFileTriggered();
/**
* @brief 打开文件槽函数
*/
void onOpenFileTriggered();
/**
* @brief 关闭文件槽函数
*/
void onCloseFileTriggered();
/**
* @brief IDL树型结构元素点击响应
* @param item: 树型结构元素
*/
void onTreeWidgetItemClicked(QTreeWidgetItem *item);
private:
/**
* @brief 初始化菜单
*/
void initMenu();
/**
* @brief 初始化文件菜单
*/
void initFileMenu();
/**
* @brief 初始化编辑菜单
*/
void initEditMenu();
/**
* @brief 初始化中心组件
* @param style: 中心组件类型 0运行环境配置文件类型 1模型/服务配置文件类型 2IDL文件类型
*/
void initCentralWidget(int style = 0);
/**
* @brief 初始化IDL树形控件
*/
void initIDLTreeWidget();
/**
* @brief 打开场景配置文件
*/
void openScenarioFile();
/**
* @brief 打开模型配置文件
*/
void openModelFile();
/**
* @brief 打开服务配置文件
*/
void openServiceFile();
/**
* @brief 打开IDL文件
*/
void openIDLFile();
/**
* @brief 保存文件
*/
void saveFile(QString filePath);
/**
* @brief 保存场景配置文件
*/
void saveScenarioFile(QString filePath);
/**
* @brief 保存模型配置文件
*/
void saveModelFile(QString filePath);
/**
* @brief 保存服务配置文件
*/
void saveServiceFile(QString filePath);
/**
* @brief 保存IDL文件
*/
void saveIDLFile(QString filePath);
/**
* @brief 添加组框1labellineEdit类型
* @param layout 布局
* @param name 名称
* @param attributes 属性
*/
void addGroupBox(QVBoxLayout *layout, QString name, QDomNamedNodeMap attributes);
/**
* @brief 添加组框2comboBox类型
* @param layout 布局
* @param name 名称
* @param attributes 属性
*/
void addGroupBox2(QVBoxLayout *layout, QString name, QDomNamedNodeMap attributes);
/**
* @brief 添加组框3tabwidget类型
* @param layout 布局
* @param name 名称
* @param groupAttributes 组属性
* @param vecAttributes 属性
* @param type 类型
*/
void addGroupBox3(QVBoxLayout *layout, QString name, QDomNamedNodeMap groupAttributes,
QVector<QDomNamedNodeMap> vecAttributes, int type);
/**
* @brief 向组框1中添加item
* @param gridLayout 布局
* @param itemName 名称
* @param itemValue 值
* @param itemStyle 样式
*/
void addItemIntoGroupBox(QGridLayout *gridLayout, QString itemName, QString itemValue,
int itemStyle);
/**
* @brief 设置lineEdit的规则
* @param lineEdit lineEdit
* @param name 名称
*/
void setLineEditRules(QLineEdit *lineEdit, QString name);
/**
* @brief 查找模型
* @param modelName 模型名称
* @param ModelPath 模型路径
* @return true 找到
* @return false 未找到
*/
bool findModel(QString modelName, QString ModelPath);
/**
* @brief 查找服务
* @param serviceName 服务名称
* @param ServicePath 服务路径
* @return true 找到
* @return false 未找到
*/
bool findService(QString serviceName, QString ServicePath);
/**
* @brief 更新模型列表
* @param tabWidget 表格
*/
void UpdateModelList(QTableWidget *tabWidget);
/**
* @brief 更新服务列表
* @param tabWidget 表格
*/
void UpdateServiceList(QTableWidget *tabWidget);
/**
* @brief 在新的窗口中打开文件
* @param fileName 文件名
*/
void openFileInNewWindow(QString fileName);
/**
* @brief 连接修改信号
* @param widget 窗口
*/
void connectModificationSignals(QWidget *widget);
/**
* @brief 更新窗口标题
*/
void updateWindowTitle();
/**
* @brief 添加加号按钮
* @param layout 布局
*/
void addPlusButton(QGridLayout *layout);
public:
/**
* @brief 当前文件路径
*/
QString currentFilePath;
/**
* @brief 当前文件类型 0: 场景配置文件 1: 模型配置文件 2: 服务配置文件 3: IDL文件
*/
int currentFileType;
private:
/**
* @brief 主窗口ui
*/
Ui::MainWindow *ui;
/**
* @brief 模型路径
*/
QString modelPath;
/**
* @brief 服务路径
*/
QString ServicePath;
/**
* @brief 是否修改
*/
bool isModified;
/**
* @brief 命名空间定义
*/
QVector<QSharedPointer<NamespaceDefinition>> namespaces;
/**
* @brief 根据namespaces更新IDL树形控件
*/
void updateIDLTreeWidget();
protected:
/**
* @brief 关闭事件
* @param event 事件
*/
void closeEvent(QCloseEvent *event) override;
};
#endif // MAINWINDOW_H