#include "DialogNewGVL.h"
#include "Common.h"
#include "WindowAppMdiFrame.h"
#include "PouManager.h"
DialogNewGVL::DialogNewGVL(QWidget *parent)
: QDialog(parent)
, m_pSelHdwTool(nullptr)
{
ui.setupUi(this);
// 对话框初始化
initUI();
}
DialogNewGVL::~DialogNewGVL()
{
}
///
/// 对话框初始化
///
void DialogNewGVL::initUI()
{
this->setWindowTitle(("Add New GVL"));
this->setAttribute(Qt::WA_QuitOnClose);
this->setWindowModality(Qt::ApplicationModal);
// 设置默认的GVL名称
ui.editName->setText(("GVL2"));
// 初始化Gvl类型的下拉选项(要跳过最后一个)
for (int i=0 ;i< gvlTypeString.size() ;i++ )
{
if ("系统变量" != gvlTypeString.at(i))
{
ui.comboGvlType->addItem(gvlTypeString.at(i));
}
}
ui.comboGvlType->setCurrentIndex(0);
// 初始化硬件组态下拉框
this->initCommboHdw();
// 槽函数
connect(ui.createButton, SIGNAL(clicked()), this, SLOT(onButtonCreateClicked()));
connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(ui.comboGvlType, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboTypeChanged(int)));
// 设置固定窗体大小
this->setFixedSize(375, 303);
//this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
ui.comboHdw->hide();
ui.label_Hdw->hide();
}
///
/// 硬件组态下拉框初始化
///
void DialogNewGVL::initCommboHdw()
{
// 获取硬件Pou
POU* hdwPou = g_pPouManager->getHdwPou();
// 获取所有的硬件Tool
const QVector& hdwTools = hdwPou->GetAllStandardTools();
// 添加至下拉框中
for (TOOL* tool : hdwTools)
{
ui.comboHdw->addItem(tool->strInstanceName);
// 并且保存下拉框选项序号和工具的对应关系
m_HdwTools.push_back(tool);
}
}
///
/// Create按钮
///
void DialogNewGVL::onButtonCreateClicked()
{
// 标签名字全局不允许重复
if (VPGlobal::getMdiFrame()->findSubView(ui.editName->text())!=nullptr)
{
Utility::VPCriticalMessageBox(("The GVL name is duplicated!"));
return;
}
if (ui.editName->text().isEmpty())
{
Utility::VPCriticalMessageBox(("The GVL name is invalid!"));
return;
}
// 保存用户输入的内容
m_gvlName = ui.editName->text();
switch (ui.comboGvlType->currentIndex())
{
case 0:
m_gvlType = GVL_MODE::GVL_BASIC;
break;
case 1:
m_gvlType = GVL_MODE::GVL_STANDARD;
break;
case 2:
m_gvlType = GVL_MODE::GVL_DB;
break;
default:
break;
}
// 2022-3-2,如果是DB类型的话,需要保存当前选择的Dll指针
if (m_gvlType == GVL_MODE::GVL_DB)
{
if ( ui.comboHdw->count() == 0)
{
return;
}
int nIndex = ui.comboHdw->currentIndex();
if (!m_HdwTools[nIndex]->strHdwInstName.isEmpty())
{
qWarning() << "The Tool " << m_HdwTools[nIndex] << "Bound to DB" << m_HdwTools[nIndex]->strHdwInstName;
return;
}
m_pSelHdwTool = m_HdwTools[nIndex];
}
else
{
m_pSelHdwTool = nullptr;
}
this->accept();
}
///
/// Type选择框变更
///
///
void DialogNewGVL::onComboTypeChanged(int index)
{
switch (index)
{
case 0:
ui.comboHdw->hide();
ui.label_Hdw->hide();
break;
case 1:
ui.comboHdw->hide();
ui.label_Hdw->hide();
break;
case 2:
ui.comboHdw->show();
ui.label_Hdw->show();
break;
default:
break;
}
}
///
///
///
///
void DialogNewGVL::setDefaultName(QString strName)
{
ui.editName->setText(strName);
}