123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- #include "ToolDialog.h"
- ToolDialogImpl::ToolDialogImpl(QWidget *parent)
- : DllToolDialog(parent)
- {
- ui.setupUi(this);
- this->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint /*| Qt::WindowStaysOnTopHint*/);
- connect(this, SIGNAL(sigUpdateUI()), this, SLOT(on_UpdateUI()));
- m_bEnableInPutValue1 = false;
- m_bEnableInPutValue2 = false;
- m_fInPutValue1 = 0;
- m_fInPutValue2 = 0;
- m_fOutPutValue = 0;
- }
- ToolDialogImpl::~ToolDialogImpl()
- {
- }
- VPEnum::RETURN_VALUE ToolDialogImpl::Execute()
- {
- if (ui.comboBoxMode->currentIndex() == 3)
- {
- if (m_fInPutValue2 == 0)
- {
- m_fInPutValue2 = 1;
- }
- }
- if (m_bEnableInPutValue1)
- {
- QString str = ui.lineEditValue1->text();
- m_fInPutValue1 = str.toFloat();
- }
- if (m_bEnableInPutValue2)
- {
- QString str = ui.lineEditValue2->text();
- m_fInPutValue2 = str.toFloat();
- }
- switch (ui.comboBoxMode->currentIndex())
- {
- case 0:m_fOutPutValue = m_fInPutValue1 + m_fInPutValue2; break;
- case 1:m_fOutPutValue = m_fInPutValue1 - m_fInPutValue2; break;
- case 2:m_fOutPutValue = m_fInPutValue1 * m_fInPutValue2; break;
- case 3:m_fOutPutValue = m_fInPutValue1 / m_fInPutValue2; break;
- default:
- break;
- }
- emit sigUpdateUI();
-
- return VPEnum::RETURN_VALUE::Success;
- }
- void ToolDialogImpl::Running(bool bRun)
- {
- }
- bool ToolDialogImpl::Serialized(QDataStream& ar, bool bIsOut)
- {
- int paranum;//参数数量
- if (bIsOut)//保存参数流程
- {
- paranum = 6;
- ar << paranum;//先保存参数数量
- ar << (int)1 << ui.comboBoxMode->currentIndex();
- ar << (int)2 << m_bEnableInPutValue1;
- ar << (int)3 << m_bEnableInPutValue2;
- ar << (int)4 << m_fInPutValue1;
- ar << (int)5 << m_fInPutValue2;
- ar << (int)6 << m_fOutPutValue;
-
-
- }
- else//加载参数流程,参数加载顺序一定要跟保存顺序一致
- {
- int nMode = 0;
- int para;
- ar >> paranum;//读取参数数量
- for (int i = 0; i < paranum; i++)
- {
- ar >> para;
- switch (para)
- {
- case 1: ar >> nMode; break;
-
- case 2: ar >> m_bEnableInPutValue1; break;
- case 3: ar >> m_bEnableInPutValue2; break;
- case 4: ar >> m_fInPutValue1; break;
- case 5: ar >> m_fInPutValue2; break;
- case 6: ar >> m_fOutPutValue; break;
-
- default:
- {
- qWarning() << "Serialized(In) Error";
- return false;
- }
- break;
- }
- }
- ui.comboBoxMode->setCurrentIndex(nMode);
- if (!m_bEnableInPutValue1)
- {
- m_fInPutValue1 = 0;
- }
- if (!m_bEnableInPutValue2)
- {
- m_fInPutValue2 = 0;
- }
- m_fOutPutValue = 0.0;
- ui.checkBoxEnValue1->setChecked(m_bEnableInPutValue1);
- ui.checkBoxEnValue2->setChecked(m_bEnableInPutValue2);
- ui.lineEditValue1->setText(QString::number(m_fInPutValue1) );
- ui.lineEditValue2->setText(QString::number(m_fInPutValue2));
- ui.lineEditValue->setText(QString::number(m_fOutPutValue));
- }
- return true;
- }
- void ToolDialogImpl::on_UpdateUI()
- {
- if (! m_bEnableInPutValue1)
- {
- QString str = QString::number(m_fInPutValue1);
- ui.lineEditValue1->setText(str);
- }
- if (!m_bEnableInPutValue2)
- {
- QString str = QString::number(m_fInPutValue2);
- ui.lineEditValue2->setText(str);
- }
- QString str = QString::number(m_fOutPutValue);
- ui.lineEditValue->setText(str);
- }
- /// <summary>
- /// 确定
- /// </summary>
- void ToolDialogImpl::on_btnOK_clicked()
- {
- this->hide();
- }
- /// <summary>
- /// 取消按钮
- /// </summary>
- void ToolDialogImpl::on_btnCancel_clicked()
- {
- // 将本工具的恢复到打开工具之前的状态
- RecoverData();
- }
- /// <summary>
- /// 测试按钮
- /// </summary>
- void ToolDialogImpl::on_btnExecute_clicked()
- {
- QElapsedTimer toolTimer;
- toolTimer.start();
- // 发送事件
- ToolEvent* pToolEvent = new ToolEvent(m_strPouName, m_strInstanceName, TOOL_EVENT_TYPE::TOOL_TRIGGER);
- QCoreApplication::sendEvent(m_pEventTarget, pToolEvent);
- // 统计返回值
- VPEnum::RETURN_VALUE ret = pToolEvent->ret;
- double nExecTime = toolTimer.elapsed();
- QString str;
- str = QString("耗时: %1 ms").arg(nExecTime, 0, 'G', 5);
- ui.label_time->setText(str);
- str = QString("状态: %1 ").arg(QMetaEnum::fromType<VPEnum::RETURN_VALUE>().key((short)ret));
- ui.label_state->setText(str);
- delete pToolEvent;
- }
- void ToolDialogImpl::on_checkBoxEnValue1_stateChanged(int arg1)
- {
- if (arg1 == Qt::CheckState::Checked)
- {
- ui.lineEditValue1->setEnabled(true);
- m_bEnableInPutValue1 = true;
- }
- else
- {
- ui.lineEditValue1->setEnabled(false);
- m_bEnableInPutValue1 = false;
- }
- }
- void ToolDialogImpl::on_checkBoxEnValue2_stateChanged(int arg1)
- {
- if (arg1 == Qt::CheckState::Checked)
- {
- ui.lineEditValue2->setEnabled(true);
- m_bEnableInPutValue2 = true;
- }
- else
- {
- ui.lineEditValue2->setEnabled(false);
- m_bEnableInPutValue2 = false;
- }
- }
|