| 1057 | } |
| 1058 | |
| 1059 | void MainWidget::run() |
| 1060 | { |
| 1061 | if(!_displayCmdTab) { |
| 1062 | _displayCmdTab = true; |
| 1063 | ui->_tabWidget->addTab(_tabPage[1],tr("命令")); |
| 1064 | ui->_tabWidget->setCurrentIndex(ui->_tabWidget->count() - 1); |
| 1065 | emit runEnd(true); |
| 1066 | return; |
| 1067 | } else { |
| 1068 | _tabIndex = ui->_tabWidget->indexOf(_tabPage[1]); |
| 1069 | ui->_tabWidget->setCurrentIndex(_tabIndex); |
| 1070 | } |
| 1071 | |
| 1072 | if(_isCmdSplit) { |
| 1073 | _strCmdSplit = ui->_lineEditsplit->text().trimmed(); |
| 1074 | if(_strCmdSplit.isEmpty()) { |
| 1075 | QMessageBox::about(this, tr("错误"), tr("多条命令执行,分隔符不可为空!")); |
| 1076 | emit runEnd(true); |
| 1077 | return; |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | emit runStart(); |
| 1082 | ui->_pushButtonRun->setDisabled(true); |
| 1083 | |
| 1084 | _strCmd.clear(); |
| 1085 | _strCmd = ui->_plainTextEdit->textCursor().selectedText().trimmed(); |
| 1086 | if(_strCmd.isEmpty()) |
| 1087 | _strCmd = ui->_plainTextEdit->toPlainText().trimmed(); |
| 1088 | _cmdRsult.clear(); |
| 1089 | _cmdRsult = _redisClient->command(_strCmd, _strCmdSplit, ui->_ipComboBox->currentIndex() - 1); |
| 1090 | for(int i = 0; i < _cmdRsult.size(); ++i) { |
| 1091 | _byteArray.clear(); |
| 1092 | if(_isResp) { |
| 1093 | if(_isFormat) { |
| 1094 | _iRet = 0; |
| 1095 | _redisClient->formatToResp(_cmdRsult[i], _byteArray , _iRet); |
| 1096 | } else { |
| 1097 | _byteArray = _cmdRsult[i].replace("\r\n","\\r\\n"); |
| 1098 | } |
| 1099 | ui->_textBrowser->append(QTextCodec::codecForLocale()->toUnicode(_byteArray)); |
| 1100 | } else if(_isJson) { |
| 1101 | while(!_jsonArray.isEmpty()) { |
| 1102 | _jsonArray.removeAt(0); |
| 1103 | } |
| 1104 | _redisClient->formatToJson(_cmdRsult[i], _jsonArray); |
| 1105 | _jsonDocument.setArray(_jsonArray); |
| 1106 | if(_isFormat) { |
| 1107 | ui->_textBrowser->append(_jsonDocument.toJson(QJsonDocument::JsonFormat::Indented)); |
| 1108 | } else { |
| 1109 | ui->_textBrowser->append(_jsonDocument.toJson(QJsonDocument::JsonFormat::Compact)); |
| 1110 | } |
| 1111 | } else if(_isText) { |
| 1112 | _iRet = 0; |
| 1113 | _redisClient->formatToText(_cmdRsult[i], _byteArray , _iRet); |
| 1114 | ui->_textBrowser->append(QTextCodec::codecForLocale()->toUnicode(_byteArray)); |
| 1115 | } else { |
| 1116 | ui->_textBrowser->append(tr("配置出错,非json、resp、text格式之一")); |
nothing calls this directly
no test coverage detected