|
|
#include "QModelMangerUI.h"
|
|
|
#include <QSharedPointer>
|
|
|
#include <QTableView>
|
|
|
#include <QMessageBox>
|
|
|
#include <QTimer>
|
|
|
#include "QPLCIndexUI.h"
|
|
|
#include "WfModel.h"
|
|
|
#include "QAddModeUI.h"
|
|
|
#define LP_WF_PLC_MAX_INDEX 1000
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
QModelMangerUI::QModelMangerUI(QWidget *parent)
|
|
|
: QWidget(parent)
|
|
|
{
|
|
|
ui.setupUi(this);
|
|
|
connect(ui.wf_model_select_button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
connect(ui.wf_model_add_button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
connect(ui.wf_model_mod_button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
connect(ui.wf_model_delete_button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
connect(ui.wf_chkbox_read_mode_from_plc, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxChange(int)));
|
|
|
}
|
|
|
|
|
|
QModelMangerUI::~QModelMangerUI()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
Q_SLOT void QModelMangerUI::onButtonClicked()
|
|
|
{
|
|
|
QString strObj = sender()->objectName();
|
|
|
if ("wf_model_select_button" == strObj) {
|
|
|
if (!m_pCtrl->IOnlineMode()) {
|
|
|
IStation *pStation = getStation();
|
|
|
if (pStation) {
|
|
|
QString strModel = pStation->currentSelectModel();
|
|
|
if (!strModel.isEmpty()) {
|
|
|
m_pCtrl->ISelModel(currentTab(), strModel);
|
|
|
ui.mLblModelState->setText(tr("current %1 OK!").arg(strModel));
|
|
|
m_pCtrl->ISetModifyModel(true);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if ("wf_model_add_button" == strObj) {
|
|
|
|
|
|
QAddModeUI adddlg(this);
|
|
|
adddlg.setWindowIcon(QIcon(":/leaper/Resource/app.png"));
|
|
|
adddlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
if (adddlg.exec() == QDialog::Accepted)
|
|
|
{
|
|
|
QString strName = adddlg.getInputName();
|
|
|
int nStaionID = currentTab();
|
|
|
bool bFlag = m_pCtrl->IAddModel(nStaionID, strName);
|
|
|
if (bFlag) {
|
|
|
ui.mLblModelState->setText(tr("add %1 successful!").arg(strName));
|
|
|
if (m_pCtrl)
|
|
|
m_pCtrl->ISaveModel(nStaionID, strName);
|
|
|
}
|
|
|
else {
|
|
|
QMessageBox msgWarning(QMessageBox::Warning, QObject::tr("错误警告"), strName + QObject::tr(" 添加失败,可能名字重复"), QMessageBox::Yes);
|
|
|
msgWarning.setWindowIcon(QIcon(":/leaper/Resource/app.png"));
|
|
|
msgWarning.setButtonText(QMessageBox::Yes, QObject::tr("确认"));
|
|
|
msgWarning.exec();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
QTimer::singleShot(5000, [&]() {
|
|
|
ui.mLblModelState->setText("");
|
|
|
});
|
|
|
}
|
|
|
else if ("wf_model_mod_button" == strObj) {
|
|
|
|
|
|
}
|
|
|
else if ("wf_model_delete_button" == strObj) {
|
|
|
IStation *pStation = getStation();
|
|
|
if (pStation) {
|
|
|
QString strModel = pStation->currentSelectModel();
|
|
|
if (!strModel.isEmpty()) {
|
|
|
QString strName = m_pCtrl->IGetCurrentRuningModel(currentTab());
|
|
|
if (strModel == strName)
|
|
|
{
|
|
|
QMessageBox msgWarning(QMessageBox::Warning, QObject::tr("错误警告"), strModel + QObject::tr(" 正在使用,不能被删除"), QMessageBox::Yes);
|
|
|
msgWarning.setWindowIcon(QIcon(":/leaper/Resource/app.png"));
|
|
|
msgWarning.setButtonText(QMessageBox::Yes, QObject::tr("确认"));
|
|
|
msgWarning.exec();
|
|
|
return ;
|
|
|
}
|
|
|
QMessageBox msgBox(QMessageBox::Warning, QObject::tr("型号删除"), QObject::tr("删除") + strModel + "?", QMessageBox::Yes | QMessageBox::No);
|
|
|
msgBox.setWindowIcon(QIcon(":/leaper/Resource/app.png"));
|
|
|
if (QMessageBox::Yes == msgBox.exec()) {
|
|
|
bool b = m_pCtrl->IDeleteModel(currentTab(), strModel);
|
|
|
if (!b) {
|
|
|
ui.mLblModelState->setText(QObject::tr("delete %1 failed!").arg(strModel));
|
|
|
}
|
|
|
else {
|
|
|
ui.mLblModelState->setText(QObject::tr("delete %1 successful!").arg(strModel));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int QModelMangerUI::lastNum(QString str)
|
|
|
{
|
|
|
return str.right(1).toInt();
|
|
|
}
|
|
|
|
|
|
Q_SLOT bool QModelMangerUI::OnCellDoubleClicked(const QModelIndex &index)
|
|
|
{
|
|
|
QString strListName = sender()->objectName();
|
|
|
if (1 != index.column()) {
|
|
|
return false;
|
|
|
}
|
|
|
int stationID = lastNum(strListName);
|
|
|
IStation *pStation = getStation(stationID);
|
|
|
if (pStation) {
|
|
|
QString strModel = pStation->model(index.row());
|
|
|
QString strName = QObject::tr("模型号:") + strModel;
|
|
|
WfModel *pModel = pStation->wfModel(strModel);
|
|
|
if (!pModel) {
|
|
|
return false;
|
|
|
}
|
|
|
QPLCIndexUI dlg(this);
|
|
|
dlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
dlg.setModelName(strName);
|
|
|
dlg.setModelIndex(pModel->nIndex);
|
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
|
{
|
|
|
int nIndex = dlg.getModelIndex();
|
|
|
|
|
|
QStringList strList = pStation->modelList();
|
|
|
bool bExist = false;
|
|
|
QString strExistModel;
|
|
|
foreach(QString var, strList) {
|
|
|
if (var == strModel)
|
|
|
continue;
|
|
|
if (nIndex != LP_WF_PLC_MAX_INDEX && nIndex == pStation->wfModel(var)->nIndex) {
|
|
|
bExist = true;
|
|
|
strExistModel = var;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (bExist == true)
|
|
|
{
|
|
|
QMessageBox msgWarning(QMessageBox::Warning, QObject::tr("警告"), strName + QObject::tr("索引修改失败,与%1索引值冲突").arg(strExistModel), QMessageBox::Yes);
|
|
|
msgWarning.setWindowIcon(QIcon(":/leaper/Resource/app.png"));
|
|
|
msgWarning.setButtonText(QMessageBox::Yes, QObject::tr("确认"));
|
|
|
msgWarning.exec();
|
|
|
|
|
|
ui.mLblModelState->setText(QObject::tr(" %1 的 PLC索引值修改失败!").arg(strModel));
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
pModel->nIndex = nIndex;
|
|
|
if (m_pCtrl)
|
|
|
m_pCtrl->ISaveModel(stationID, strModel);
|
|
|
ui.mLblModelState->setText(QObject::tr(" %1 的 PLC索引值修改成功!").arg(strModel));
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
Q_SLOT void QModelMangerUI::onCheckBoxChange(int state)
|
|
|
{
|
|
|
if (state > 0)
|
|
|
{
|
|
|
ui.wf_model_select_button->setDisabled(true);
|
|
|
if (m_pCtrl)
|
|
|
m_pCtrl->ISetOnlineModel(true);
|
|
|
}
|
|
|
else {
|
|
|
ui.wf_model_select_button->setDisabled(false);
|
|
|
if (m_pCtrl)
|
|
|
m_pCtrl->ISetOnlineModel(false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
IStation * QModelMangerUI::getStation(int nIndex)
|
|
|
{
|
|
|
if (nIndex == -1) {
|
|
|
QWidget *pWidget = ui.tabWidgetStation->currentWidget();
|
|
|
if (pWidget) {
|
|
|
nIndex = lastNum(pWidget->objectName());
|
|
|
}
|
|
|
}
|
|
|
return m_pCtrl->IGetStationById(nIndex);
|
|
|
}
|
|
|
|
|
|
void QModelMangerUI::showEvent(QShowEvent *event)
|
|
|
{
|
|
|
if (m_pCtrl) {
|
|
|
if (m_pCtrl->IOnlineMode() == true)
|
|
|
{
|
|
|
ui.wf_chkbox_read_mode_from_plc->setChecked(true);
|
|
|
}
|
|
|
else {
|
|
|
ui.wf_chkbox_read_mode_from_plc->setChecked(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void QModelMangerUI::closeEvent(QCloseEvent *event)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
void QModelMangerUI::onInitModelList(IWfCtrl *pCtrl)
|
|
|
{
|
|
|
m_pCtrl = pCtrl;
|
|
|
if (m_pCtrl)
|
|
|
{
|
|
|
ui.tabWidgetStation->clear();
|
|
|
QStringList lst = m_pCtrl->IGetStationKeys();
|
|
|
for (int i = 0; i < lst.size(); i++) {
|
|
|
QTableView *pW = new QTableView(ui.tabWidgetStation);
|
|
|
IStation *pStation = m_pCtrl->IGetStationByKey(lst.at(i));
|
|
|
QString strObjName = "wf_cam_listwidget_" + QString::number(pStation->stationId());
|
|
|
pW->setObjectName(strObjName);
|
|
|
int nIndex = pStation->stationId()-1;
|
|
|
ui.tabWidgetStation->insertTab(nIndex, (QWidget*)pW, pStation->stationShowName());
|
|
|
pStation->setView(pW);
|
|
|
connect(pW, SIGNAL(doubleClicked(const QModelIndex &)),this, SLOT(OnCellDoubleClicked(const QModelIndex &)));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
int QModelMangerUI::currentTab()
|
|
|
{
|
|
|
QWidget *pWidget = ui.tabWidgetStation->currentWidget();
|
|
|
if (pWidget) {
|
|
|
return lastNum(pWidget->objectName());
|
|
|
}
|
|
|
return -1;
|
|
|
} |