|
|
|
|
|
#include "QModelMangerUI.h"
|
|
|
|
|
|
#include <QSharedPointer>
|
|
|
|
|
|
#include <QTableView>
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
#include "QPLCIndexUI.h"
|
|
|
|
|
|
#include "QAddModeUI.h"
|
|
|
|
|
|
#include "IStation.h"
|
|
|
|
|
|
#include "IWfCtrl.h"
|
|
|
|
|
|
#include "lpGlobalConfig.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()) {
|
|
|
|
|
|
QString nStaionID = currentTab();
|
|
|
|
|
|
IStation *pStation = m_pCtrl->IGetStationByKey(nStaionID);
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
if (nStaionID == lpGlobalConfig::instance()->m_StationSolution_1)
|
|
|
|
|
|
{
|
|
|
|
|
|
lpGlobalConfig::instance()->m_StationRunModel_1 = strModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (nStaionID == lpGlobalConfig::instance()->m_StationSolution_2)
|
|
|
|
|
|
{
|
|
|
|
|
|
lpGlobalConfig::instance()->m_StationRunModel_2 = strModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
lpGlobalConfig::instance()->writeConfig();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
QString 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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), strName + QObject::tr(" <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>"), QMessageBox::Yes);
|
|
|
|
|
|
msgWarning.setWindowIcon(QIcon(":/leaper/Resource/app.png"));
|
|
|
|
|
|
msgWarning.setButtonText(QMessageBox::Yes, QObject::tr("ȷ<EFBFBD><EFBFBD>"));
|
|
|
|
|
|
msgWarning.exec();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QTimer::singleShot(5000, [&]() {
|
|
|
|
|
|
ui.mLblModelState->setText("");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("wf_model_mod_button" == strObj) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("wf_model_delete_button" == strObj) {
|
|
|
|
|
|
QString nStaionID = currentTab();
|
|
|
|
|
|
IStation *pStation = m_pCtrl->IGetStationByKey(nStaionID);
|
|
|
|
|
|
if (pStation) {
|
|
|
|
|
|
QString strModel = pStation->currentSelectModel();
|
|
|
|
|
|
if (!strModel.isEmpty()) {
|
|
|
|
|
|
QString strName = m_pCtrl->IGetCurrentRuningModel(currentTab());
|
|
|
|
|
|
if (strModel == strName)
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox msgWarning(QMessageBox::Warning, QObject::tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), strModel + QObject::tr(" <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>ܱ<EFBFBD>ɾ<EFBFBD><C9BE>"), QMessageBox::Yes);
|
|
|
|
|
|
msgWarning.setWindowIcon(QIcon(":/leaper/Resource/app.png"));
|
|
|
|
|
|
msgWarning.setButtonText(QMessageBox::Yes, QObject::tr("ȷ<EFBFBD><EFBFBD>"));
|
|
|
|
|
|
msgWarning.exec();
|
|
|
|
|
|
return ;
|
|
|
|
|
|
}
|
|
|
|
|
|
QMessageBox msgBox(QMessageBox::Warning, QObject::tr("<EFBFBD>ͺ<EFBFBD>ɾ<EFBFBD><EFBFBD>"), QObject::tr("ɾ<EFBFBD><EFBFBD>") + 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
QString key = m_tabViewKeys.value(strListName);
|
|
|
|
|
|
int stationID = lastNum(strListName);
|
|
|
|
|
|
IStation *pStation = m_pCtrl->IGetStationByKey(key);
|
|
|
|
|
|
if (pStation) {
|
|
|
|
|
|
QString strModel = pStation->model(index.row());
|
|
|
|
|
|
QString strName = QObject::tr("ģ<EFBFBD>ͺ<EFBFBD>:") + strModel;
|
|
|
|
|
|
int plcIndex = m_pCtrl->IGetPLCIndex(key, strModel);
|
|
|
|
|
|
QPLCIndexUI dlg(this);
|
|
|
|
|
|
dlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
|
|
|
dlg.setModelName(strName);
|
|
|
|
|
|
dlg.setModelIndex(plcIndex);
|
|
|
|
|
|
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 == m_pCtrl->IGetPLCIndex(key, var)) {
|
|
|
|
|
|
bExist = true;
|
|
|
|
|
|
strExistModel = var;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (bExist == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox msgWarning(QMessageBox::Warning, QObject::tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), strName + QObject::tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>,<2C><>%1<><31><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ͻ").arg(strExistModel), QMessageBox::Yes);
|
|
|
|
|
|
msgWarning.setWindowIcon(QIcon(":/leaper/Resource/app.png"));
|
|
|
|
|
|
msgWarning.setButtonText(QMessageBox::Yes, QObject::tr("ȷ<EFBFBD><EFBFBD>"));
|
|
|
|
|
|
msgWarning.exec();
|
|
|
|
|
|
|
|
|
|
|
|
ui.mLblModelState->setText(QObject::tr(" %1 <20><> PLC<4C><43><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>").arg(strModel));
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_pCtrl->ISetPLCIndex(key, strModel, nIndex);
|
|
|
|
|
|
if (m_pCtrl)
|
|
|
|
|
|
m_pCtrl->ISaveModel(key, strModel);
|
|
|
|
|
|
ui.mLblModelState->setText(QObject::tr(" %1 <20><> PLC<4C><43><EFBFBD><EFBFBD>ֵ<EFBFBD>ijɹ<C4B3><C9B9><EFBFBD>").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::changeEvent(QEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.retranslateUi(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QModelMangerUI::onInitModelList(IWfCtrl *pCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pCtrl = pCtrl;
|
|
|
|
|
|
ui.tabWidgetStation->clear();
|
|
|
|
|
|
|
|
|
|
|
|
QStringList lst = pCtrl->IGetStationKeys();
|
|
|
|
|
|
int nIndex = 0;
|
|
|
|
|
|
for each (QString var in lst) {
|
|
|
|
|
|
QTableView *pW = new QTableView(ui.tabWidgetStation);
|
|
|
|
|
|
pW->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
|
|
pW->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
pW->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
IStation *pStation = pCtrl->IGetStationByKey(var);
|
|
|
|
|
|
QString strObjName = "wf_cam_listwidget_" + QString::number(nIndex);
|
|
|
|
|
|
m_tabViewKeys.insert(strObjName, var);
|
|
|
|
|
|
pW->setObjectName(strObjName);
|
|
|
|
|
|
ui.tabWidgetStation->addTab((QWidget*)pW, var);
|
|
|
|
|
|
pStation->setView(pW);
|
|
|
|
|
|
connect(pW, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(OnCellDoubleClicked(const QModelIndex &)));
|
|
|
|
|
|
nIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString QModelMangerUI::currentTab()
|
|
|
|
|
|
{
|
|
|
|
|
|
QWidget *pWidget = ui.tabWidgetStation->currentWidget();
|
|
|
|
|
|
if (pWidget) {
|
|
|
|
|
|
QString s = pWidget->objectName();
|
|
|
|
|
|
QString key = m_tabViewKeys.value(s);
|
|
|
|
|
|
return key;
|
|
|
|
|
|
}
|
|
|
|
|
|
return QString();
|
|
|
|
|
|
}
|