123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #include "JReLineEdit.h"
- #include <QGroupBox>
- #include <QComboBox>
- #include <QCheckBox>
- #include <qDebug>
- JReLineEdit::JReLineEdit(QWidget* parent /*= nullptr*/)
- : QLineEdit(parent)
- {
- }
- void JReLineEdit::upDataValLine(const ST_DEF_VAL _val)
- {
- m_stSavedefVal = _val;
- }
- void JReLineEdit::CheckVal()
- {
- // 获取按钮所在的父窗口
- QWidget* parentWindow = this->window();
- QList<QGroupBox*> pListBox = parentWindow->findChildren<QGroupBox*>();
- QList<QComboBox*> pListQComboBox = parentWindow->findChildren<QComboBox*>();
- // 遍历所有QLineEdit
- foreach(QGroupBox * p, pListBox)
- {
- if (p->objectName() == "axisGroupBox")
- {
- // 获取所有子控件
- QList<QWidget*> children = p->findChildren<QWidget*>();
- std::vector<ns_module::MODULE_COORD_MOVE> vecPos;
- int nNum = 0;
- // 总共没几个
- ns_module::MODULE_COORD_MOVE axisPos = {};
- foreach(QWidget * child, children)
- {
- if (child->metaObject()->className() == "QCheckBox")
- {
- QCheckBox* checkBox = qobject_cast<QCheckBox*>(child);
- if (checkBox)
- {
- // 转换成功,可以安全使用 checkBox
- if (checkBox->isChecked())
- {
- nNum += 1;
- if (checkBox->objectName() == "forceCheckBox")
- {
-
- }
- else if (checkBox->objectName() == "forceCheckBox")
- {
- }
- else if (checkBox->objectName() == "forceCheckBox")
- {
- }
- else if (checkBox->objectName() == "forceCheckBox")
- {
- }
- break;
- }
- }
- else
- {
- // 转换失败,widget 不是 QCheckBox 类型
- //qDebug() << "该 widget 不是 QCheckBox";
- }
- }
- // 表示是另一个控件
- if (nNum == 1)
- {
- QCheckBox* checkBox = qobject_cast<QCheckBox*>(child);
-
- axisPos.pos = checkBox->text().toDouble();
- vecPos.push_back(axisPos);
- nNum = 0;
- }
-
- //qDebug() << "name :" << child->objectName()
- // << " type::" << child->metaObject()->className();
- }
- break;
- }
- }
- // 获取选中
- foreach(QComboBox* p, pListQComboBox)
- {
- if (p->objectName() == "modeComboBox")
- {
- m_stSavedefVal.strMode = p->currentText();
- }
- }
- CreateSpeedAdjPage();
- }
- void JReLineEdit::CreateSpeedAdjPage()
- {
- if (m_pSpeedWnd)
- {
- m_pSpeedWnd->close();
- m_pSpeedWnd->deleteLater();
- }
- m_pSpeedWnd = new SpeedAdjPage(this);
- m_pSpeedWnd->updateDefVal(m_stSavedefVal);
- m_pSpeedWnd->setAttribute(Qt::WA_DeleteOnClose);
- {
- QPoint mousePos = QCursor::pos();
- QPoint newPos = QPoint(mousePos.x() - m_pSpeedWnd->width() / 2,
- mousePos.y() - m_pSpeedWnd->height() - 10);
- m_pSpeedWnd->move(newPos);
- }
- connect(m_pSpeedWnd, &SpeedAdjPage::CloseWnd, this, &JReLineEdit::GetCloseWndSlots);
- m_pSpeedWnd->show();
- }
- void JReLineEdit::GetCloseWndSlots(int nVal)
- {
- double doVal = text().toDouble();
- doVal = doVal + nVal;
- setText(QString::number(doVal, 'f', 2));
- }
- void JReLineEdit::mousePressEvent(QMouseEvent* event)
- {
- if (event->button() == Qt::LeftButton)
- {
- CheckVal();
- }
- QLineEdit::mousePressEvent(event);
- }
|