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.
valvedetect/tpvs17/lpMain/QModelMangerUI.cpp

203 lines
5.8 KiB
C++

#include "QModelMangerUI.h"
#include <QSharedPointer>
#include <QTableView>
#include <QMessageBox>
#include <QTimer>
#include "QPLCIndexUI.h"
#include "WfModel.h"
#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()));
QRegExp regx("[a-zA-Z0-9]+$");
QSharedPointer<QValidator> validator = QSharedPointer<QValidator>(new QRegExpValidator(regx));
ui.wf_model_input_edit->setValidator(validator.data());
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) {
QString strModel = ui.wf_model_input_edit->text();
if (!strModel.isEmpty() && !strModel.contains(_WF_UNIQUE_SPLIT) && !strModel.contains("##")
&& strModel.size() >= 3 && strModel.size() <= 20 && !strModel.contains(" ")) {
int nIndex = currentTab();
bool bFlag = m_pCtrl->IAddModel(nIndex, strModel);
if (bFlag) {
ui.mLblModelState->setText(tr("add %1 successful!").arg(strModel));
ui.wf_model_input_edit->setText("");
}
else {
ui.mLblModelState->setText(tr("add %1 failed!").arg(strModel));
}
}
else {
ui.mLblModelState->setText(QObject::tr("ģ<EFBFBD>ͺ<EFBFBD><EFBFBD>в<EFBFBD><EFBFBD>ܰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ո<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><EFBFBD>20֮<EFBFBD><EFBFBD>!"));
}
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->currentRunningModel();
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/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/app.png"));
if (QMessageBox::Yes == msgBox.exec()) {
bool b = m_pCtrl->IDeleteModel(currentTab(), strModel);
if (!b) {
ui.mLblModelState->setText(tr("delete %1 failed!").arg(strModel));
}
else {
ui.mLblModelState->setText(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("ģ<EFBFBD>ͺ<EFBFBD>:") + strModel;
WfModel *pModel = pStation->wfModel(strModel);
if (!pModel) {
return false;
}
QPLCIndexUI dlg(this);
dlg.setModelName(strName);
dlg.setModelIndex(pModel->nIndex);
if (dlg.exec() == QDialog::Accepted)
{
int nIndex = dlg.getModelIndex();
pModel->nIndex = nIndex;
}
}
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 strName = "wf_cam_listwidget_" + QString::number(pStation->stationId());
pW->setObjectName(strName);
int nIndex = pStation->stationId()-1;
ui.tabWidgetStation->insertTab(nIndex, (QWidget*)pW, pStation->stationShowName());
pStation->setWidget(strName, 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;
}