DialogNewGVL.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #include "DialogNewGVL.h"
  2. #include "Common.h"
  3. #include "WindowAppMdiFrame.h"
  4. #include "PouManager.h"
  5. DialogNewGVL::DialogNewGVL(QWidget *parent)
  6. : QDialog(parent)
  7. , m_pSelHdwTool(nullptr)
  8. {
  9. ui.setupUi(this);
  10. // 对话框初始化
  11. initUI();
  12. }
  13. DialogNewGVL::~DialogNewGVL()
  14. {
  15. }
  16. /// <summary>
  17. /// 对话框初始化
  18. /// </summary>
  19. void DialogNewGVL::initUI()
  20. {
  21. this->setWindowTitle(("Add New GVL"));
  22. this->setAttribute(Qt::WA_QuitOnClose);
  23. this->setWindowModality(Qt::ApplicationModal);
  24. // 设置默认的GVL名称
  25. ui.editName->setText(("GVL2"));
  26. // 初始化Gvl类型的下拉选项(要跳过最后一个)
  27. for (int i=0 ;i< gvlTypeString.size() ;i++ )
  28. {
  29. if ("系统变量" != gvlTypeString.at(i))
  30. {
  31. ui.comboGvlType->addItem(gvlTypeString.at(i));
  32. }
  33. }
  34. ui.comboGvlType->setCurrentIndex(0);
  35. // 初始化硬件组态下拉框
  36. this->initCommboHdw();
  37. // 槽函数
  38. connect(ui.createButton, SIGNAL(clicked()), this, SLOT(onButtonCreateClicked()));
  39. connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
  40. connect(ui.comboGvlType, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboTypeChanged(int)));
  41. // 设置固定窗体大小
  42. this->setFixedSize(375, 303);
  43. //this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
  44. ui.comboHdw->hide();
  45. ui.label_Hdw->hide();
  46. }
  47. /// <summary>
  48. /// 硬件组态下拉框初始化
  49. /// </summary>
  50. void DialogNewGVL::initCommboHdw()
  51. {
  52. // 获取硬件Pou
  53. POU* hdwPou = g_pPouManager->getHdwPou();
  54. // 获取所有的硬件Tool
  55. const QVector<TOOL*>& hdwTools = hdwPou->GetAllStandardTools();
  56. // 添加至下拉框中
  57. for (TOOL* tool : hdwTools)
  58. {
  59. ui.comboHdw->addItem(tool->strInstanceName);
  60. // 并且保存下拉框选项序号和工具的对应关系
  61. m_HdwTools.push_back(tool);
  62. }
  63. }
  64. /// <summary>
  65. /// Create按钮
  66. /// </summary>
  67. void DialogNewGVL::onButtonCreateClicked()
  68. {
  69. // 标签名字全局不允许重复
  70. if (VPGlobal::getMdiFrame()->findSubView(ui.editName->text())!=nullptr)
  71. {
  72. Utility::VPCriticalMessageBox(("The GVL name is duplicated!"));
  73. return;
  74. }
  75. if (ui.editName->text().isEmpty())
  76. {
  77. Utility::VPCriticalMessageBox(("The GVL name is invalid!"));
  78. return;
  79. }
  80. // 保存用户输入的内容
  81. m_gvlName = ui.editName->text();
  82. switch (ui.comboGvlType->currentIndex())
  83. {
  84. case 0:
  85. m_gvlType = GVL_MODE::GVL_BASIC;
  86. break;
  87. case 1:
  88. m_gvlType = GVL_MODE::GVL_STANDARD;
  89. break;
  90. case 2:
  91. m_gvlType = GVL_MODE::GVL_DB;
  92. break;
  93. default:
  94. break;
  95. }
  96. // 2022-3-2,如果是DB类型的话,需要保存当前选择的Dll指针
  97. if (m_gvlType == GVL_MODE::GVL_DB)
  98. {
  99. if ( ui.comboHdw->count() == 0)
  100. {
  101. return;
  102. }
  103. int nIndex = ui.comboHdw->currentIndex();
  104. if (!m_HdwTools[nIndex]->strHdwInstName.isEmpty())
  105. {
  106. qWarning() << "The Tool " << m_HdwTools[nIndex] << "Bound to DB" << m_HdwTools[nIndex]->strHdwInstName;
  107. return;
  108. }
  109. m_pSelHdwTool = m_HdwTools[nIndex];
  110. }
  111. else
  112. {
  113. m_pSelHdwTool = nullptr;
  114. }
  115. this->accept();
  116. }
  117. /// <summary>
  118. /// Type选择框变更
  119. /// </summary>
  120. /// <param name="index"></param>
  121. void DialogNewGVL::onComboTypeChanged(int index)
  122. {
  123. switch (index)
  124. {
  125. case 0:
  126. ui.comboHdw->hide();
  127. ui.label_Hdw->hide();
  128. break;
  129. case 1:
  130. ui.comboHdw->hide();
  131. ui.label_Hdw->hide();
  132. break;
  133. case 2:
  134. ui.comboHdw->show();
  135. ui.label_Hdw->show();
  136. break;
  137. default:
  138. break;
  139. }
  140. }
  141. /// <summary>
  142. ///
  143. /// </summary>
  144. /// <param name="strName"></param>
  145. void DialogNewGVL::setDefaultName(QString strName)
  146. {
  147. ui.editName->setText(strName);
  148. }