diff --git a/.gitignore b/.gitignore index 1a6c40f..83f6364 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,4 @@ -*.iml -.gradle -/local.properties .idea/ -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures -/obj -*.apk -*/obj -/.idea/misc.xml -*.version.json -app/src/main/assets/version.json *build* *release* *debug* @@ -21,6 +7,3 @@ app/src/main/assets/version.json *.Release *.Debug *.exe -cmake-build-debug/ -debug/ -release/ diff --git a/SerialWizard.pro.user b/SerialWizard.pro.user deleted file mode 100644 index 6d823fe..0000000 --- a/SerialWizard.pro.user +++ /dev/null @@ -1,318 +0,0 @@ - - - - - - EnvironmentId - {209392b2-9c75-4135-8667-79efe8f1fbca} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.7.0 MinGW 32bit - Desktop Qt 5.7.0 MinGW 32bit - qt.57.win32_mingw53_kit - 1 - 0 - 0 - - E:/work/00code/SerialWizard/build-SerialWizard-Desktop_Qt_5_7_0_MinGW_32bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - E:/work/00code/SerialWizard/build-SerialWizard-Desktop_Qt_5_7_0_MinGW_32bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - E:/work/00code/SerialWizard/build-SerialWizard-Desktop_Qt_5_7_0_MinGW_32bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - - 2 - 构建 - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - - 1 - 清理 - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - 部署 - - ProjectExplorer.BuildSteps.Deploy - - 1 - 在本地部署 - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - SerialWizard - SerialWizard2 - Qt4ProjectManager.Qt4RunConfiguration:E:/work/00code/SerialWizard/SerialWizard.pro - true - - SerialWizard.pro - false - - E:/work/00code/SerialWizard/build-SerialWizard-Desktop_Qt_5_7_0_MinGW_32bit-Release - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - diff --git a/mainwindow.cpp b/mainwindow.cpp index 8562ec6..298aea5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -223,12 +223,14 @@ void MainWindow::initUi() { sendDataGroupBox->setLayout(sendDataLayout); sendTextEdit = new QTextEdit(this); - transferButton = new QPushButton(tr("转换"), this); + transferHexButton = new QPushButton(tr("转换为十六进制"), this); + transferAsciiButton = new QPushButton(tr("转换为文本"), this); sendButton = new QPushButton(tr("发送")); auto sendButtonLayout = new QVBoxLayout; - sendButtonLayout->addWidget(transferButton); + sendButtonLayout->addWidget(transferHexButton); + sendButtonLayout->addWidget(transferAsciiButton); sendButtonLayout->addWidget(sendButton); auto sendLayout = new QHBoxLayout; @@ -373,17 +375,14 @@ void MainWindow::initConnect() { } }); - connect(transferButton, &QPushButton::clicked, [this] { + connect(transferHexButton, &QPushButton::clicked, [this] { auto text = sendTextEdit->toPlainText(); - text.replace(" ", ""); - QString result; - QRegExp rx("^[0-9A-Fa-f]+$"); - if (rx.exactMatch(text)) { - result = QString::fromLocal8Bit(dataFromHex(text)); - } else { - result = dataToHex(text.toLocal8Bit()); - } - + auto result = QString(dataToHex(text.toLocal8Bit())); + sendTextEdit->setText(result); + }); + connect(transferAsciiButton, &QPushButton::clicked, [this] { + auto text = sendTextEdit->toPlainText(); + QString result = QString::fromLocal8Bit(dataFromHex(text)); sendTextEdit->setText(result); }); @@ -438,12 +437,13 @@ void MainWindow::open() { QFile file(fileName); if (file.open(QIODevice::ReadOnly)) { auto data = file.readAll(); + sendTextEdit->setText(QString::fromLocal8Bit(data)); } } void MainWindow::save() { - + saveReceivedData(); } void MainWindow::tool() { @@ -709,8 +709,7 @@ void MainWindow::clearReceivedData() { void MainWindow::saveReceivedData() { QString fileName = QFileDialog::getSaveFileName(this, tr("保存接收数据"), - "/", - tr("Text (*.txt)")); + "/", tr("Text (*.txt)")); if (fileName.isEmpty()) { return; } @@ -758,7 +757,6 @@ void MainWindow::saveSentData() { file.close(); - if (okToContinue(tr("消息"), tr("发送数据保存成功,是否打开所在文件夹?"))) { QProcess::startDetached("explorer.exe /select," + QDir::toNativeSeparators(fileName)); } diff --git a/mainwindow.h b/mainwindow.h index 40ef5a0..b6899eb 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -178,7 +178,8 @@ private slots: QPushButton *sendFrameButton; QPushButton *sendButton; - QPushButton *transferButton; + QPushButton *transferHexButton; + QPushButton *transferAsciiButton; QTimer *autoSendTimer; QByteArray *mySendData;