JIoMapPage.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include "JIoMapPage.h"
  2. #include <Machine.h>
  3. #include <QJsonObject>
  4. JIoMapPage::JIoMapPage() {}
  5. QWidget* JIoMapPage::CreateIoPage(const CONFIG_BASE_STRUCT& control)
  6. {
  7. // 1.用到表中的变量
  8. QString strName = control.strName.c_str();
  9. // 2. 创建垂直布局
  10. QHBoxLayout* pHLayout = new QHBoxLayout();
  11. IoStateLab* pIoState = new IoStateLab();
  12. pIoState->setIoName(strName);
  13. QLabel* pAxisNmae = new QLabel();
  14. QString strAxisName = tr("AxisNmae:", "轴名称:");
  15. strAxisName += strName;
  16. pAxisNmae->setText(strAxisName);
  17. //QLabel* pLow = new QLabel();
  18. //pLow->setText(tr("Voltage status", "电压状态"));
  19. //QComboBox* pComBox = new QComboBox();
  20. //pComBox->addItem(tr("Low", "低电平"));
  21. //pComBox->addItem(tr("High","高电平"));
  22. //pComBox->setCurrentIndex(1);
  23. //// 连接信号和槽
  24. //connect(pComBox, &QComboBox::currentTextChanged, []() {
  25. // });
  26. // 轴名称
  27. pHLayout->addWidget(pAxisNmae);
  28. //// 电平组合
  29. //pHLayout->addWidget(pLow);
  30. //pHLayout->addWidget(pComBox);
  31. // 改变状态标记
  32. pHLayout->addWidget(pIoState);
  33. QWidget* pWidget = new QWidget;
  34. pWidget->setLayout(pHLayout);
  35. return pWidget;
  36. }
  37. QWidget* JIoMapPage::CreateAxisTestPage(const CONFIG_BASE_STRUCT& control)
  38. {
  39. // 1.用到表中的变量
  40. QString strName = control.strName.c_str();
  41. QHBoxLayout* pHLayout = new QHBoxLayout();
  42. QLabel* pAxisNmae = new QLabel();
  43. QString strAxisName = tr("AxisNmae:", "轴名称:");
  44. strAxisName += strName;
  45. pAxisNmae->setText(strAxisName);
  46. pHLayout->addWidget(pAxisNmae);
  47. QLineEdit* pCardNumberType = new QLineEdit(tr("Card Number Type", "卡号类型"));
  48. pCardNumberType->setText("0");
  49. pHLayout->addWidget(pCardNumberType);
  50. QLineEdit* pCardNumber = new QLineEdit(tr("Card Number", "卡号"));
  51. pCardNumber->setText("0");
  52. pHLayout->addWidget(pCardNumberType);
  53. QPushButton* pTest = new QPushButton(tr("Axis Test","轴测试"));
  54. QObject::connect(pTest, &QPushButton::clicked, [strName]()
  55. {
  56. ns_module::CViewMotion::GetInstance()->ShowMotionAdjustPage(strName.toStdString());
  57. });
  58. pHLayout->addWidget(pTest);
  59. QWidget* pWidget = new QWidget;
  60. pWidget->setLayout(pHLayout);
  61. return pWidget;
  62. }
  63. void JIoMapPage::JCreateMenu(QWidget* pWidget)
  64. {
  65. // 设置上下文菜单策略
  66. pWidget->setContextMenuPolicy(Qt::CustomContextMenu);
  67. // 连接信号到槽函数
  68. connect(pWidget, &QWidget::customContextMenuRequested, [=](const QPoint& pos)
  69. {
  70. QMenu menu;
  71. QAction* pGetAct = menu.addAction(tr("Get","获取"));
  72. QAction* pSetUpAct = menu.addAction(tr("set up","设置"));
  73. QAction* pDefValUpAct = menu.addAction(tr("default value", "默认值"));
  74. // 连接动作的触发信号
  75. connect(pGetAct, &QAction::triggered, []() { qDebug() << "Get"; });
  76. connect(pSetUpAct, &QAction::triggered, []() { qDebug() << "set up"; });
  77. connect(pDefValUpAct, &QAction::triggered, []() { qDebug() << "default value"; });
  78. // 显示菜单
  79. menu.exec(pWidget->mapToGlobal(pos));
  80. });
  81. }
  82. void JIoMapPage::JCreateMenu(QWidget* pWidget, ST_DEFAULT_VAL defaultVal)
  83. {
  84. pWidget->setContextMenuPolicy(Qt::CustomContextMenu);
  85. connect(pWidget, &QWidget::customContextMenuRequested, [=](const QPoint& pos)
  86. {
  87. QMenu menu;
  88. QAction* pDefValUpAct = menu.addAction(tr("default value", "默认值"));
  89. connect(pDefValUpAct, &QAction::triggered, [defaultVal]()
  90. {
  91. if (!defaultVal.fieldDefult.isEmpty())
  92. {
  93. defaultVal.lineEdit->setText(defaultVal.fieldDefult);
  94. }
  95. });
  96. menu.exec(pWidget->mapToGlobal(pos));
  97. });
  98. }
  99. QLabel* JIoMapPage::JCreateName0(const QString& fieldDescribe, const QString& fieldDescribe_Eng, int nlanguage)
  100. {
  101. QLabel* pNameLable = new QLabel();
  102. if (nlanguage == 0)
  103. {
  104. pNameLable->setText(fieldDescribe_Eng);
  105. if (fieldDescribe_Eng.isEmpty())
  106. {
  107. pNameLable->setText(fieldDescribe);
  108. }
  109. }
  110. else
  111. {
  112. pNameLable->setText(fieldDescribe);
  113. if (fieldDescribe.isEmpty())
  114. {
  115. pNameLable->setText(fieldDescribe_Eng);
  116. }
  117. }
  118. pNameLable->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
  119. pNameLable->setFixedHeight(24);
  120. pNameLable->setMinimumWidth(120);
  121. return pNameLable;
  122. }
  123. AutoResizeLabel* JIoMapPage::JCreateJText(const QString& name)
  124. {
  125. AutoResizeLabel* pLabel = new AutoResizeLabel();
  126. pLabel->setText(name);
  127. pLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
  128. //pLabel->setFixedHeight(24);
  129. //pLabel->setMinimumWidth(120);
  130. return pLabel;
  131. }
  132. QList<ST_DATA_ITEM> JIoMapPage::parseJsonToDataList(const QString& jsonString)
  133. {
  134. QList<ST_DATA_ITEM> dataList;
  135. QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8());
  136. if (jsonDoc.isNull() || !jsonDoc.isArray())
  137. {
  138. qWarning() << "解析失败或JSON不是数组";
  139. return dataList;
  140. }
  141. QJsonArray jsonArray = jsonDoc.array();
  142. // 遍历数组
  143. for (const QJsonValue& val : jsonArray)
  144. {
  145. if (val.isObject())
  146. {
  147. QJsonObject obj = val.toObject();
  148. ST_DATA_ITEM item;
  149. item.key = obj.value("key").toString();
  150. item.value = obj.value("value").toString();
  151. dataList.append(item);
  152. }
  153. }
  154. return dataList;
  155. }