diff --git a/MyTcpClient.cpp b/MyTcpClient.cpp index 97f8563..f13b897 100644 --- a/MyTcpClient.cpp +++ b/MyTcpClient.cpp @@ -32,18 +32,18 @@ MyTcpClient* MyTcpClient::instance() } return m_instance; } -void MyTcpClient::connectToServer(const QString &host, quint16 port) { +int MyTcpClient::connectToServer(const QString &host, quint16 port) { serverHost = host; serverPort = port; if (socket->state() == QAbstractSocket::ConnectedState) { qDebug() << "Already connected!"; - return; + return 0; } qDebug() << "Connecting to" << host << ":" << port; socket->connectToHost(host, port); if (!socket->waitForConnected()) { qDebug() << "Connection failed!"; - return; + return -1; } } diff --git a/MyTcpClient.h b/MyTcpClient.h index 22bd924..26377b1 100644 --- a/MyTcpClient.h +++ b/MyTcpClient.h @@ -14,7 +14,7 @@ public: explicit MyTcpClient(QObject *parent = nullptr); ~MyTcpClient(); - void connectToServer(const QString &host, quint16 port); + int connectToServer(const QString &host, quint16 port); int sendData(char* data,qint64 len); void waitForRead(); void disconnectFromServer(); diff --git a/connect.cpp b/connect.cpp index ef9c702..5c78e3b 100644 --- a/connect.cpp +++ b/connect.cpp @@ -4,6 +4,7 @@ #include #include "data_config.h" #include +#include Connect::Connect(QWidget *parent) : QWidget(parent), @@ -30,7 +31,6 @@ void Connect::on_pushButton_connect_clicked() m_tcpClient->connectToServer(g_strServerIp, 10000); QSettings *settings = new QSettings(QCoreApplication::applicationDirPath() + "/config/config.ini", QSettings::IniFormat); settings->setValue("Server/IP", ui->lineEdit_IP->text()); - this->close(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index a460c62..26ac5a1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -116,7 +116,7 @@ MainWindow::MainWindow(QWidget *parent) //qInstallMessageHandler(messageHandler); #endif QDate buildDate = QLocale( QLocale::English ).toDate( QString(__DATE__).replace(" ", " 0"), "MMM dd yyyy"); - QString Version = "V1.0_" + buildDate.toString("yyyyMMdd") + "_24f3"; + QString Version = "V1.0_" + buildDate.toString("yyyyMMdd") + "_3bcd"; ui->label_version->setText(Version); } @@ -438,9 +438,9 @@ void MainWindow::onMenuActionTriggered() { }else if(action->text() == "获取进程号"){ GetCardProcessID(button_id); }else if(action->text() == "复制板卡配置"){ - GetCardProcessID(button_id); + CopySubCard(button_id); }else if(action->text() == "移动板卡配置"){ - GetCardProcessID(button_id); + MoveSubCard(button_id); } break; // 找到按钮后,跳出循环 } @@ -922,6 +922,13 @@ void MainWindow::CopySubCard(int slot){ QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请输入正确的板卡号!")); return ; } + QMessageBox *box = new QMessageBox(QMessageBox::Question, "提示", "是否进行板卡配置复制?", QMessageBox::Yes | QMessageBox::No, this); + box->button(QMessageBox::Yes)->setText("确认"); + box->button(QMessageBox::No)->setText("取消"); + int res = box->exec(); + if(QMessageBox::No == res){ + return; + } int card_type_old = -1, card_type_new = -1; std::shared_ptr base_ptr_old = ConfigMgr::Instance()->GetSlotPtr(slot_no); if(base_ptr_old != nullptr){ @@ -934,17 +941,99 @@ void MainWindow::CopySubCard(int slot){ QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("请选择相同的板卡类型!")); return ; } - }else{ - QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("目标板卡无配置,请使用“移动板卡配置”!")); - return ; } - std::shared_ptr vib_data = std::make_shared(); + std::shared_ptr vib_data = std::dynamic_pointer_cast(base_ptr_old); vib_data->slot_ = value; vib_data->relative_number = value; ConfigMgr::Instance()->AddCard(vib_data); + QList buttonList = btnGroup_slot->buttons(); + for (int i = 1; i < buttonList.count(); i++) { + if(i == value){ + switch (base_ptr_old->card_type_) { + case kCardVibSingle :{ + buttonList[i]->setText("振动"); + break; + } + case kCardKeyphaseSingle:{ + buttonList[i]->setText("键相"); + break; + } + case kCardSpeedSingle:{ + buttonList[i]->setText("转速"); + break; + } + case kCardRelaySingle: + case kCardRelaySingleNOK: + case kCardRelayTMRBackup: + case kCardRelayTMRPrimary:{ + buttonList[i]->setText("继电器"); + break; + } + default: + break; + } + } + } + } void MainWindow::MoveSubCard(int slot){ + slot_no = slot; + QString strTips = QString("请输入1到15之间的数值"); + bool ok = false; + int value = QInputDialog::getInt(this, tr("输入整数对话框"), strTips, 0, 1, 15, 1, &ok); + if(!ok) return; + if(value < 1){ + QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("请输入正确的板卡号!")); + return ; + } + QMessageBox *box = new QMessageBox(QMessageBox::Question, "提示", "是否进行板卡配置移动?", QMessageBox::Yes | QMessageBox::No, this); + box->button(QMessageBox::Yes)->setText("确认"); + box->button(QMessageBox::No)->setText("取消"); + int res = box->exec(); + if(QMessageBox::No == res){ + return; + } + std::shared_ptr base_ptr_old = ConfigMgr::Instance()->GetSlotPtr(slot_no); + std::shared_ptr base_ptr_new = ConfigMgr::Instance()->GetSlotPtr(value); + if(base_ptr_new != nullptr){ + QMessageBox::warning(this, QStringLiteral("警告"), QStringLiteral("目标板卡非空!")); + return ; + } + std::shared_ptr vib_data = std::dynamic_pointer_cast(base_ptr_old); + vib_data->slot_ = value; + ConfigMgr::Instance()->AddCard(vib_data); + ConfigMgr::Instance()->RemoveCard(base_ptr_old); + QList buttonList = btnGroup_slot->buttons(); + for (int i = 1; i < buttonList.count(); i++) { + if(i == value){ + switch (base_ptr_old->card_type_) { + case kCardVibSingle :{ + buttonList[i]->setText("振动"); + break; + } + case kCardKeyphaseSingle:{ + buttonList[i]->setText("键相"); + break; + } + case kCardSpeedSingle:{ + buttonList[i]->setText("转速"); + break; + } + case kCardRelaySingle: + case kCardRelaySingleNOK: + case kCardRelayTMRBackup: + case kCardRelayTMRPrimary:{ + buttonList[i]->setText("继电器"); + break; + } + default: + break; + } + }else if(i == slot){ + buttonList[i]->setText(""); + } + } } void MainWindow::readData(const QByteArray &data) { qDebug() << "Received from server:" << data;