You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.2 KiB
C++

5 years ago
#include "DsgAlgoDlg.h"
#include "ui_AlgoDlg.h"
#include "qfiledialog.h"
#include "QDesktopWidget"
CDsgAlgoDlg::CDsgAlgoDlg(QWidget *parent) : QDialog(parent), ui(new Ui::AlgoDlg)
{
m_pDE = NULL;
m_pTask = NULL;
m_bAlgoChanged = false;
ui->setupUi(this);
setWindowIcon(QIcon(":/img/resource/app.png"));
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(OnOk()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(OnCancel()));
connect(ui->pushButton_4, SIGNAL(clicked()), this, SLOT(OnSelectAlgo()));
}
CDsgAlgoDlg::~CDsgAlgoDlg()
{
if (ui) {
delete ui;
ui = NULL;
}
}
5 years ago
bool CDsgAlgoDlg::Initialize(IDetectorEngine* lpDE, IDetectorTask* lpTask)
{
if (!lpDE || !lpTask)
return false;
m_pDE = lpDE;
m_pTask = lpTask;
return true;
}
bool CDsgAlgoDlg::OnOk()
{
QDialog::accept();
return true;
}
bool CDsgAlgoDlg::OnCancel()
{
QDialog::reject();
return true;
}
bool CDsgAlgoDlg::OnSelectAlgo()
{
QString strFileName = QFileDialog::getOpenFileName(this, "open file", "", "File (*.dll)");
if (strFileName.length() > 0)
{
ui->lineEdit_4->setText(strFileName);
m_bAlgoChanged = true;
return true;
}
return false;
}
IDetectorAlgorithm* CDsgAlgoDlg::ShowAlgoDlg(IDetectorAlgorithm* pAlgo)
{
if (!m_pTask)
return NULL;
if (pAlgo)
{
ui->lineEdit->setText(QObject::tr(pAlgo->GetAlgorithmInfo()->strName.toStdString().c_str()));
ui->lineEdit_2->setText(pAlgo->GetAlgorithmInfo()->strDescription);
ui->lineEdit_3->setText(QString::number(pAlgo->GetAlgorithmInfo()->nRoiID));
ui->lineEdit_4->setText(pAlgo->GetAlgorithmInfo()->strPath);
}
else
{
ui->lineEdit->clear();
ui->lineEdit_2->clear();
ui->lineEdit_3->clear();
ui->lineEdit_4->clear();
}
QDesktopWidget* desktop = QApplication::desktop();//
move((desktop->width() - this->width()) / 2, (desktop->height() - this->height()) / 2);
if (this->exec() == QDialog::Accepted )
{
if (false == m_bAlgoChanged) //<! 算法未重新加载
{
return pAlgo;
}
LP_DETECTOR_ALGORITHM tAlgoInfo;
tAlgoInfo.strName = ui->lineEdit->text();
tAlgoInfo.strDescription = ui->lineEdit_2->text();
if (ui->lineEdit_3->text().length() > 0)
tAlgoInfo.nRoiID = ui->lineEdit_3->text().toInt();
tAlgoInfo.strPath = ui->lineEdit_4->text();
if (pAlgo)
{
pAlgo->SetAlgorithmInfo(&tAlgoInfo);
if (tAlgoInfo.strPath.size() > 0)
{
if (!pAlgo->Load(tAlgoInfo.strPath.left(tAlgoInfo.strPath.lastIndexOf("."))))
{
QMessageBox::information(NULL, QObject::tr("错误提示"), QObject::tr("加载算法库失败"));
}
}
else
{
if (!pAlgo->Load(tAlgoInfo.strName))
{
QMessageBox::information(NULL, QObject::tr("错误提示"), QObject::tr("加载算法库失败"));
}
}
pAlgo->InitAlgo();
return pAlgo;
}
IDetectorAlgorithm* pNewAlgo = m_pTask->AddAlgorithm(&tAlgoInfo);
if (tAlgoInfo.strPath.size() > 0)
{
if (!pNewAlgo->Load(tAlgoInfo.strPath.left(tAlgoInfo.strPath.lastIndexOf("."))))
{
QMessageBox::information(NULL, QObject::tr("错误提示"), QObject::tr("加载算法库失败"));
}
}
else
{
if (!pNewAlgo->Load(tAlgoInfo.strName))
{
QMessageBox::information(NULL, QObject::tr("错误提示"), QObject::tr("加载算法库失败"));
}
}
pNewAlgo->InitAlgo();
return pNewAlgo;
}
return pAlgo;
}