WindowRuntime.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #include <QMainWindow>
  3. #include "ui_WindowRuntime.h"
  4. #include "Common.h"
  5. #include "WindowAppUiView.h"
  6. #include "selectwidget.h"
  7. /// <summary>
  8. /// Runtime界面
  9. /// </summary>
  10. class WindowAppUiView;
  11. class WindowRuntime : public QMainWindow
  12. {
  13. Q_OBJECT
  14. public:
  15. WindowRuntime(QWidget *parent = nullptr);
  16. ~WindowRuntime();
  17. // 启动所有的UI界面
  18. bool publishAllPages(WindowAppUiView* pMainPage, QMap<QString, WindowAppUiView*> allPages);
  19. // 执行指令
  20. bool runCmd(const QString& strCmd, const QString& strParam = "");
  21. // 执行Dll中的Tool Interface
  22. bool runDllInterface(
  23. const QString& strPouName,
  24. const QString& strToolName,
  25. const QString& strInfName,
  26. VALUE_TYPE controlType
  27. );
  28. // 系统命令 - 切换到指定页面
  29. bool switchToPage(const QString& strPageName);
  30. // 添加一个新的索引和控件对应关系
  31. void registerNewIndex(VARIABLE* pIndex, QWidget* pControl);
  32. // 为控件添加一个变量
  33. void registerNewVariable(QWidget* pControl, const QString& strPropertyName, const VARIABLE* pVariable);
  34. // 释放对应控件关系
  35. void releaseControl(QWidget* pWidget);
  36. //=======================================================================
  37. // 同步相关代码
  38. // 从复杂控件的触发源头同步(一般都是Pou中的Execute,每轮执行会触发更新一遍Runtime)
  39. void syncFromComplexSource(const VARIABLE* syncVal);
  40. // 同步到Table控件中
  41. void syncToTableControl(QWidget* pControl, int nRowIndex);
  42. //// 刷新Table控件中的值
  43. //void updateTableControl(QTableWidget* pTableWidget, const SYNC_VARS& vars, int nRowIndex);
  44. // 同步到CustomPlot控件中
  45. void syncToCustomPlot(QWidget* pControl, int nSliceIndex);
  46. // 同步到Pie控件中
  47. void syncToPieChart(QWidget* pControl, int nSliceIndex);
  48. //// 刷新Pie控件中的值
  49. //void updatePieChart(VPieChart* pPieChart, const SYNC_VARS& vars, int nIndex);
  50. // 同步到Image控件中
  51. void syncToImageControl(QWidget* pControl);
  52. // 重置所有数据结构,准备执行新的发布动作
  53. void reset();
  54. private:
  55. Ui::WindowRuntime ui;
  56. protected slots:
  57. //// 绘制界面背景
  58. //void paintEvent(QPaintEvent*);
  59. // 接收来自变量到复杂控件单向同步的Event
  60. // 备注:复杂控件只需要在Execute的时候一次性向Runtime直接推送数据变动即可,不需要做其他同步操作
  61. virtual void customEvent(QEvent* event) override;
  62. protected:
  63. // 界面初始化
  64. void initUI();
  65. // 发布对应的页面
  66. bool publishPage(WindowAppUiView* pPage, bool bMainPage = false);
  67. protected:
  68. // 所有发布页面的Stack
  69. QStackedWidget* m_pRuntimeViews;
  70. // 发布的页面名字和对应的View序号
  71. QMap<QString, int> m_AllViews;
  72. // 复杂控件的索引变量 和 复杂控件指针之间的对应关系
  73. // 2021-12-28,为了支持一个索引刷新多个Table,增加了一对多的关系
  74. QMultiHash<const VARIABLE*, QWidget*> m_IndexToComplexControls;
  75. // 复杂控件的指针 和 每个数值对象的对应关系
  76. QHash<QWidget*, RUNTIME_SYNC_VARS> m_ComplexControlToVariables;
  77. };