JReLineEdit.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "JReLineEdit.h"
  2. #include <QGroupBox>
  3. #include <QComboBox>
  4. #include <QCheckBox>
  5. #include <qDebug>
  6. JReLineEdit::JReLineEdit(QWidget* parent /*= nullptr*/)
  7. : QLineEdit(parent)
  8. {
  9. }
  10. void JReLineEdit::upDataValLine(const ST_DEF_VAL _val)
  11. {
  12. m_stSavedefVal = _val;
  13. }
  14. void JReLineEdit::CheckVal()
  15. {
  16. // 获取按钮所在的父窗口
  17. QWidget* parentWindow = this->window();
  18. QList<QGroupBox*> pListBox = parentWindow->findChildren<QGroupBox*>();
  19. QList<QComboBox*> pListQComboBox = parentWindow->findChildren<QComboBox*>();
  20. // 遍历所有QLineEdit
  21. foreach(QGroupBox * p, pListBox)
  22. {
  23. if (p->objectName() == "axisGroupBox")
  24. {
  25. // 获取所有子控件
  26. QList<QWidget*> children = p->findChildren<QWidget*>();
  27. std::vector<ns_module::MODULE_COORD_MOVE> vecPos;
  28. int nNum = 0;
  29. // 总共没几个
  30. ns_module::MODULE_COORD_MOVE axisPos = {};
  31. foreach(QWidget * child, children)
  32. {
  33. if (child->metaObject()->className() == "QCheckBox")
  34. {
  35. QCheckBox* checkBox = qobject_cast<QCheckBox*>(child);
  36. if (checkBox)
  37. {
  38. // 转换成功,可以安全使用 checkBox
  39. if (checkBox->isChecked())
  40. {
  41. nNum += 1;
  42. if (checkBox->objectName() == "forceCheckBox")
  43. {
  44. }
  45. else if (checkBox->objectName() == "forceCheckBox")
  46. {
  47. }
  48. else if (checkBox->objectName() == "forceCheckBox")
  49. {
  50. }
  51. else if (checkBox->objectName() == "forceCheckBox")
  52. {
  53. }
  54. break;
  55. }
  56. }
  57. else
  58. {
  59. // 转换失败,widget 不是 QCheckBox 类型
  60. //qDebug() << "该 widget 不是 QCheckBox";
  61. }
  62. }
  63. // 表示是另一个控件
  64. if (nNum == 1)
  65. {
  66. QCheckBox* checkBox = qobject_cast<QCheckBox*>(child);
  67. axisPos.pos = checkBox->text().toDouble();
  68. vecPos.push_back(axisPos);
  69. nNum = 0;
  70. }
  71. //qDebug() << "name :" << child->objectName()
  72. // << " type::" << child->metaObject()->className();
  73. }
  74. break;
  75. }
  76. }
  77. // 获取选中
  78. foreach(QComboBox* p, pListQComboBox)
  79. {
  80. if (p->objectName() == "modeComboBox")
  81. {
  82. m_stSavedefVal.strMode = p->currentText();
  83. }
  84. }
  85. CreateSpeedAdjPage();
  86. }
  87. void JReLineEdit::CreateSpeedAdjPage()
  88. {
  89. if (m_pSpeedWnd)
  90. {
  91. m_pSpeedWnd->close();
  92. m_pSpeedWnd->deleteLater();
  93. }
  94. m_pSpeedWnd = new SpeedAdjPage(this);
  95. m_pSpeedWnd->updateDefVal(m_stSavedefVal);
  96. m_pSpeedWnd->setAttribute(Qt::WA_DeleteOnClose);
  97. {
  98. QPoint mousePos = QCursor::pos();
  99. QPoint newPos = QPoint(mousePos.x() - m_pSpeedWnd->width() / 2,
  100. mousePos.y() - m_pSpeedWnd->height() - 10);
  101. m_pSpeedWnd->move(newPos);
  102. }
  103. connect(m_pSpeedWnd, &SpeedAdjPage::CloseWnd, this, &JReLineEdit::GetCloseWndSlots);
  104. m_pSpeedWnd->show();
  105. }
  106. void JReLineEdit::GetCloseWndSlots(int nVal)
  107. {
  108. double doVal = text().toDouble();
  109. doVal = doVal + nVal;
  110. setText(QString::number(doVal, 'f', 2));
  111. }
  112. void JReLineEdit::mousePressEvent(QMouseEvent* event)
  113. {
  114. if (event->button() == Qt::LeftButton)
  115. {
  116. CheckVal();
  117. }
  118. QLineEdit::mousePressEvent(event);
  119. }