WindowAppVariableTable.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #pragma once
  2. #include "Common.h"
  3. #include "ui_WindowAppVariableTable.h"
  4. /// <summary>
  5. /// 用来处理变量显示和交互逻辑的表格
  6. /// </summary>
  7. class WindowAppVariableTable : public QTableWidget
  8. {
  9. Q_OBJECT
  10. public:
  11. WindowAppVariableTable(QWidget *parent = Q_NULLPTR);
  12. ~WindowAppVariableTable();
  13. public:
  14. // 初始化变量表格
  15. void initTable(const QString& strGroup, GVL_MODE gvlMode = GVL_MODE::GVL_BASIC);
  16. // 按标准模式初始化变量表格Header
  17. void initStandardTableHeader();
  18. // 按DB模式初始化变量表格Header
  19. void initDBTableHeader();
  20. // 表格中添加新的一行(标准/普通模式)
  21. int insertTableLine(
  22. bool bSerialized,
  23. QString strName,
  24. QString strFullName,
  25. QString strType,
  26. QString strValue,
  27. QString strComment
  28. );
  29. // 表格中添加新的一行(DB模式)
  30. int insertTableLine(
  31. QString strName,
  32. QString strFullName,
  33. QString strType,
  34. QString strValue,
  35. QString strCommAddress,
  36. VPEnum::GVL_ACCESS_MODE accessMode,
  37. QString strComment
  38. );
  39. //// 添加全局变量(界面录入方式)
  40. //void addGlobalVariable(
  41. // bool bSerialized,
  42. // QString strName,
  43. // QString strType,
  44. // QString strValue,
  45. // QString strComment
  46. // );
  47. //// 添加全局变量(序列化方式)
  48. //void addGlobalVariable( const VARIABLE& newVar);
  49. //// 添加局部变量
  50. //void addLocalVariable(
  51. // bool bSerialized,
  52. // QString strName,
  53. // QString strType,
  54. // QString strValue,
  55. // QString strComment
  56. //);
  57. // 更新表格中指定变量的值
  58. void updateTableValue(const QString& strVarFullName, const QString& strNewValue);
  59. //// 将指定的表格设置为错误状态
  60. //void setItemError(int row, int col);
  61. //// 将指定的表格设置为正常状态
  62. //void setItemOK(int row, int col);
  63. //// Toolbar - New
  64. //void onToolNew();
  65. // Toolbar - MoveUp
  66. void onVariableMoveUp();
  67. // Toolbar - MoveDown
  68. void onVariableMoveDown();
  69. // Toolbar - Delete
  70. void onVariableDelete();
  71. // 交换两行的数据
  72. void swapRows(int selectRow, int targetRow);
  73. //// 设置分组名称
  74. //void setTitle(const QString& strTitle)
  75. //{
  76. // this->m_strTitle = strTitle;
  77. //}
  78. private slots:
  79. //// 当Type下拉框改变时
  80. //void onTableTypeChanged(int nIndex);
  81. // 当Serialized状态发生改变时
  82. void onTableSerializedChanged(bool bChecked);
  83. // 当表格单元改变时
  84. void onTableCellChanged(int row, int col);
  85. // 调整大小的消息中改变表格栏的宽度
  86. virtual void resizeEvent(QResizeEvent* event) override;
  87. private:
  88. Ui::WindowAppVariableTable ui;
  89. //private:
  90. //
  91. // // 表格中添加一行
  92. // void addNewLine(
  93. // bool bSerialized,
  94. // QString strName,
  95. // QString strType,
  96. // QString strValue,
  97. // QString strComment,
  98. // TOOL_TYPE varType
  99. // );
  100. private:
  101. // 用来保存表格中插入的控件及其对应的序号,否则获取不到
  102. QHash<QCheckBox*, int> m_cellCheckbox;
  103. // 上一次输入的Value值和Comment值(用于处理消息被重复多次触发)
  104. QVector<QString> m_LastValues;
  105. // 变量全名和表格行数的对应关系
  106. QHash<QString, int> m_VariablesRows;
  107. // 本Gvl分组的名称
  108. QString m_strGroup;
  109. // 本Gvl分组的模式(用于切换编辑和不可编辑,以及表格头目)
  110. GVL_MODE m_gvlMode;
  111. };