#include "QParamDlg.h" #include "colossusbase.h" #pragma execution_character_set("utf-8") QParamDlg::QParamDlg(QWidget *parent) : QDialog(parent)//, m_valueCombox(this) { ui.setupUi(this); m_pTask = NULL; m_pAlgo = NULL; m_type = PARAM_IN; setWindowIcon(QIcon(":/img/resource/app.png")); ui.pushButton->setShortcut(QKeySequence::InsertParagraphSeparator); connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(OnOk())); connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(OnCancel())); // m_valueCombox.setGeometry(QRect(100, 120, 171, 20)); // m_valueCombox.setHidden(true); connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnChangeParamType())); connect(ui.comboBox_2, SIGNAL(currentIndexChanged(int)), this, SLOT(OnChangeAlgo())); connect(ui.m_pbROISet, SIGNAL(clicked()), this, SLOT(OnShowRoiDlg())); //Qt::WindowFlags flags;// = Qt::Dialog; //flags |= Qt::WindowMinMaxButtonsHint; //flags |= Qt::WindowCloseButtonHint; //setWindowFlags(flags); } QParamDlg::~QParamDlg() { } bool QParamDlg::Initialize(IDetectorEngine* lpDE, IDetectorTask* lpTask, IDetectorAlgorithm* lpAlgo, EM_ParamDialogType type) { if (!lpDE || !lpTask || !lpAlgo) return false; m_pDE = lpDE; m_pTask = lpTask; m_pAlgo = lpAlgo; m_type = type; return true; } bool QParamDlg::InitGraphView() { if (!ui.comboBox) return false; ui.comboBox->clear(); for (int i = 0; i < LP_MAX_ALGO_PARAM_NUM; i++) { ui.comboBox->insertItem(i, AlgoParamName[i]); } ui.comboBox->setEditable(false); disconnect(ui.comboBox_2, SIGNAL(currentIndexChanged(int)), 0, 0); ui.comboBox_2->clear(); ui.comboBox_3->clear(); ui.comboBox_2->insertItem(0, "None", LP_DETECTOR_INVALID_ID); int nAlgoCount = m_pTask->EnumAlgorithm(NULL, 0); if (nAlgoCount > 0) { IDetectorAlgorithm** lppAlgo = new IDetectorAlgorithm*[nAlgoCount]; nAlgoCount = m_pTask->EnumAlgorithm(lppAlgo, nAlgoCount); for (int i = 0; i < nAlgoCount; i++) { if (lppAlgo[i] && lppAlgo[i]->GetID() != m_pAlgo->GetID()) { ui.comboBox_2->insertItem(i + 1, lppAlgo[i]->GetAlgorithmInfo()->strName, lppAlgo[i]->GetID()); } } delete[] lppAlgo; } ui.comboBox_2->setCurrentIndex(0); ui.comboBox_3->setCurrentIndex(0); connect(ui.comboBox_2, SIGNAL(currentIndexChanged(int)), this, SLOT(OnChangeAlgo())); return true; } void QParamDlg::CleanUp() { } PLP_ALGORITHM_PARAM QParamDlg::ShowParamDlg(PLP_ALGORITHM_PARAM pParam) { if (pParam) { ui.lineEdit->setText(pParam->strName); ui.comboBox->setCurrentIndex(GetTypeIndex(pParam->type)); _ParamType = pParam->type; int a = ui.comboBox_2->findData(pParam->nSrcAlgoID); int algoID = ui.comboBox_2->findData(pParam->nSrcAlgoID); ui.comboBox_2->setCurrentIndex(algoID > 0 ? algoID : 0); InitValueCtrl(pParam->type, pParam); QString str = QString("%1").arg(pParam->strDescription); ui.lineEdit_3->setText(str); ui.checkBox->setChecked(pParam->bIsSave); ui.checkBox_2->setChecked(pParam->bIsLock); int srcParmID = ui.comboBox_3->findData(pParam->nSrcParamID); ui.comboBox_3->setCurrentIndex(srcParmID > 0 ? srcParmID : 0); if (pParam->type == LP_ROI) m_tRoiData = pParam->value.value(); } else { ui.lineEdit->clear(); ui.lineEdit_2->clear(); ui.comboBox->setCurrentIndex(0); ui.comboBox_2->setCurrentIndex(0); ui.comboBox_3->setCurrentIndex(0); ui.lineEdit_3->clear(); //m_valueCombox.clear(); ui.checkBox->setChecked(false); ui.checkBox_2->setChecked(false); m_tRoiData.img.release(); m_tRoiData.records.clear(); } QDesktopWidget* desktop = QApplication::desktop();// move((desktop->width() - this->width()) / 2, (desktop->height() - this->height()) / 2); if (this->exec() == QDialog::Accepted) { SystemStateInfo::bParamStateFlag = true; LP_ALGORITHM_PARAM tParam; tParam.strName = ui.lineEdit->text(); tParam.type = (AlgoParamType)ui.comboBox->currentIndex(); tParam.nSrcAlgoID = ui.comboBox_2->currentData().toInt(); tParam.nSrcParamID = ui.comboBox_3->currentData().toInt(); tParam.value = GetCtrlValue(tParam.type); tParam.strDescription = ui.lineEdit_3->text(); tParam.bIsSave = ui.checkBox->isChecked(); tParam.bIsLock = ui.checkBox_2->isChecked(); if (pParam) { pParam->strName = tParam.strName; pParam->type = tParam.type; pParam->nSrcAlgoID = tParam.nSrcAlgoID; pParam->nSrcParamID = tParam.nSrcParamID; pParam->value = tParam.value; pParam->strDescription = tParam.strDescription; pParam->bIsSave = tParam.bIsSave; pParam->bIsLock = tParam.bIsLock; return pParam; } PLP_ALGORITHM_PARAM pNewParam = NULL; if (m_type == PARAM_IN) pNewParam = m_pAlgo->AddParam(&tParam); else if (m_type == PARAM_OUT) pNewParam = m_pAlgo->AddOutParam(&tParam); if (pNewParam) { return pNewParam; } } return NULL; } int QParamDlg::GetTypeIndex(AlgoParamType type) { return type; int nIndex; switch (type) { case LP_INT: { nIndex = 0; break; } case LP_BOOLEAN: { nIndex = 1; break; } case LP_STRING: { nIndex = 2; break; } case LP_DOUBLE: { nIndex = 3; break; } case LP_IMAGE: { nIndex = 4; break; } case LP_POINT: { nIndex = 5; break; } case LP_POINTF: { nIndex = 6; break; } case LP_RECT: { nIndex = 7; break; } case LP_RECTF: { nIndex = 8; break; } case LP_ROI: { nIndex = 9; break; } case LP_MAT: { nIndex = 10; break; } case LP_LIST_INT: { nIndex = 11; break; } case LP_LIST_BOOLEAN: { nIndex = 12; break; } case LP_LIST_STRING: { nIndex = 13; break; } case LP_LIST_DOUBLE: { nIndex = 14; } case LP_USER: { nIndex = 15; } default: break; } return nIndex; } void QParamDlg::InitValueCtrl(AlgoParamType type, PLP_ALGORITHM_PARAM pParam) { switch (type) { case LP_INT: { ui.lineEdit_2->setHidden(false); ui.label_2->setHidden(false); ui.m_pbROISet->setHidden(true); //m_valueCombox.setHidden(true); if (pParam) { ui.lineEdit_2->setText(pParam->value.toString()); } break; } case LP_BOOLEAN: { ui.label_2->setHidden(true); ui.lineEdit_2->setHidden(true); ui.m_pbROISet->setHidden(true); //m_valueCombox.setHidden(false); //m_valueCombox.clear(); //m_valueCombox.insertItem(0, "FALSE"); //m_valueCombox.insertItem(1, "TRUE"); //if (pParam) // m_valueCombox.setCurrentIndex(pParam->value.toBool()); break; } case LP_STRING: //{ // ui->lineEdit_2->setHidden(false); // m_valueCombox.setHidden(true); // m_roiButton.setHidden(true); // break; //} case LP_DOUBLE: { ui.label_2->setHidden(false); ui.lineEdit_2->setHidden(false); //m_valueCombox.setHidden(true); ui.m_pbROISet->setHidden(true); if (pParam) { ui.lineEdit_2->setText(pParam->value.toString()); } break; } case LP_IMAGE: { ui.label_2->setHidden(false); ui.lineEdit_2->setHidden(false); //m_valueCombox.setHidden(true); ui.m_pbROISet->setHidden(true); break; } case LP_POINT: { break; } case LP_POINTF: { break; } case LP_RECT: { break; } case LP_RECTF: { break; } case LP_ROI: { ui.label_2->setHidden(true); //m_valueCombox.setHidden(true); ui.lineEdit_2->setHidden(true); ui.m_pbROISet->setHidden(false); break; } case LP_MAT: { break; } default: break; } return; } QVariant QParamDlg::GetCtrlValue(AlgoParamType type) { switch (type) { case LP_INT: { return ui.lineEdit_2->text(); } case LP_BOOLEAN: { //return m_valueCombox.currentIndex(); } case LP_STRING: { return ui.lineEdit_2->text(); } case LP_DOUBLE: { return ui.lineEdit_2->text().toDouble(); } case LP_IMAGE: { break; } case LP_POINT: { break; } case LP_POINTF: { break; } case LP_RECT: { break; } case LP_RECTF: { break; } case LP_ROI: { QVariant value; value.setValue(m_tRoiData); return value; } case LP_MAT: { } default: break; } return NULL; } bool QParamDlg::OnOk() { QDialog::accept(); return true; } bool QParamDlg::OnCancel() { QDialog::reject(); return true; } bool QParamDlg::OnChangeParamType() { AlgoParamType type = (AlgoParamType)ui.comboBox->currentIndex(); InitValueCtrl(type, NULL); _ParamType = type; OnChangeAlgo(); return true; } bool QParamDlg::OnChangeAlgo() { ui.comboBox_3->clear(); ui.comboBox_3->insertItem(0, "None", LP_DETECTOR_INVALID_ID); QVariant v = ui.comboBox_2->currentData(); IDetectorAlgorithm* pAlgo = m_pTask->GetAlgorithm(ui.comboBox_2->currentData().toInt()); if (pAlgo) { int nCount = pAlgo->EnumOutParam(NULL, 0); if (nCount > 0) { LP_ALGORITHM_PARAM** lppParam = new LP_ALGORITHM_PARAM*[nCount]; nCount = pAlgo->EnumOutParam(lppParam, nCount); int nComBoxIndex = 0; for (int i = 0; i < nCount; i++) { if (lppParam[i]) { QString str = lppParam[i]->strName; int ID = lppParam[i]->nID; if (lppParam[i]->type == _ParamType) { ui.comboBox_3->insertItem(nComBoxIndex + 1, lppParam[i]->strName, lppParam[i]->nID); nComBoxIndex++; } } } } } return true; } bool QParamDlg::OnShowRoiDlg() { // if (!m_tRoiDlg.Initialize(m_pDE, m_pAlgo, m_pTask)) // return false; // m_tRoiData.img = m_pTask->GetTaskInfo()->templateImg; // m_tRoiData = m_tRoiDlg.ShowRoiDlg(m_tRoiData); return true; }