修改插件目录, 去除无用文件
This commit is contained in:
parent
67aa780e4d
commit
1a82d4ac85
|
Before Width: | Height: | Size: 479 B After Width: | Height: | Size: 479 B |
|
|
@ -68,12 +68,15 @@ void MyUnitUI::setParams(QString &strParams)
|
|||
QAction *MyUnitUI::createAction()
|
||||
{
|
||||
//下面, 平台显示按钮, 如需要平台显示解开注释
|
||||
m_pAction = new QAction();
|
||||
m_pAction->setText("直方图");
|
||||
m_pAction->setToolTip("直方图");
|
||||
m_pAction->setIcon( QIcon(":/image/zfu.png"));
|
||||
m_pAction->setProperty("PluginName", PLUGINUNIT);
|
||||
// m_pAction = new QAction();
|
||||
|
||||
if(m_pAction)
|
||||
{
|
||||
m_pAction->setText("直方图"); // 按钮显示文字
|
||||
m_pAction->setToolTip("直方图"); // 鼠标移动到按钮显示tip
|
||||
m_pAction->setIcon( QIcon(":/image/zfu.png")); // 按钮显示图片
|
||||
m_pAction->setProperty("PluginName", PLUGINUNIT); // 模块名字
|
||||
}
|
||||
return m_pAction;
|
||||
}
|
||||
|
||||
|
|
@ -1,207 +0,0 @@
|
|||
#include "cloudalgorithmaccess.h"
|
||||
#include <QDebug>
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
|
||||
CloudAlgorithmAccess::CloudAlgorithmAccess(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_tcpSocket = new QTcpSocket(this);
|
||||
m_responseResult.clear();
|
||||
|
||||
}
|
||||
|
||||
QByteArray CloudAlgorithmAccess::sendHttpPost(const QString &host, int port, const QString &path, const QByteArray &data)
|
||||
{
|
||||
// 连接服务器
|
||||
m_tcpSocket->connectToHost(host, port);
|
||||
if (!m_tcpSocket->waitForConnected(5000)) {
|
||||
qDebug() << "Connection failed!";
|
||||
return QByteArray(); // 连接失败
|
||||
}
|
||||
|
||||
// 构建HTTP请求
|
||||
QByteArray request =
|
||||
"POST " + path.toUtf8() + " HTTP/1.1\r\n" +
|
||||
"Host: " + host.toUtf8() + "\r\n" +
|
||||
"Content-Type: application/json\r\n" +
|
||||
"Content-Length: " + QByteArray::number(data.length()) + "\r\n" +
|
||||
"Connection: close\r\n" +
|
||||
"\r\n" +
|
||||
data;
|
||||
|
||||
// 发送请求
|
||||
m_tcpSocket->write(request); // 将request数据写入套接字的写缓冲区,并尝试发送。
|
||||
m_tcpSocket->waitForBytesWritten(5000); // 等待直到数据被实际发送(即写入网络)或超时5秒。
|
||||
|
||||
// 等待响应
|
||||
QByteArray response;
|
||||
while ( m_tcpSocket->waitForReadyRead(5000)) {
|
||||
response.append(m_tcpSocket->readAll());
|
||||
if (m_tcpSocket->bytesAvailable() == 0 && ! m_tcpSocket->isValid()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_tcpSocket->close();
|
||||
|
||||
// 提取响应体(跳过HTTP头)尝试标准分隔符 \r\n\r\n
|
||||
int headerEnd = response.indexOf("\r\n\r\n");
|
||||
if (headerEnd != -1) {
|
||||
return response.mid(headerEnd + 4);
|
||||
}
|
||||
// 尝试 \n\n(某些服务器可能使用)
|
||||
headerEnd = response.indexOf("\n\n");
|
||||
if (headerEnd != -1) {
|
||||
return response.mid(headerEnd + 2);
|
||||
}
|
||||
|
||||
// 如果找不到标准分隔符,返回原始内容
|
||||
qDebug() << "警告:无法解析HTTP响应格式,返回原始内容";
|
||||
return response;
|
||||
}
|
||||
|
||||
///计算孔隙度的json拼接样例
|
||||
QString CloudAlgorithmAccess::buildJson(const QVector<double>& depths, const QVector<double>& values)
|
||||
{
|
||||
QString json = "{";
|
||||
json += QString::fromUtf8("\"methodName\":\"根据声波时差计算(默认)\",");
|
||||
json += "\"coefficient\":{\"DTpm\":\"49\",\"DTpf\":\"188.9\"},";
|
||||
json += "\"curvesInfo\":{\"curveSource\":\"\",\"mdList\":[";
|
||||
|
||||
// 添加深度数据
|
||||
for (int i = 0; i < depths.size(); i++) {
|
||||
if (i > 0) json += ",";
|
||||
json += QString::number(depths[i]);
|
||||
}
|
||||
|
||||
json += QString::fromUtf8("],\"curveList\":[{\"curveName\":\"纵波时差\",\"minValue\":0,\"maxValue\":0,\"valueList\":[");
|
||||
|
||||
// 添加声波时差数据
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
if (i > 0) json += ",";
|
||||
json += QString::number(values[i]);
|
||||
}
|
||||
|
||||
json += "]}]}}";
|
||||
qDebug() << "json:" << json;
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
// 解析JSON数据的函数
|
||||
int CloudAlgorithmAccess::parseResponseData(QString jsonData) {
|
||||
//QString jsonData = QString::fromUtf8(data);
|
||||
m_responseResult.clear();
|
||||
int result = ParseSuccess;
|
||||
|
||||
// 检查响应码
|
||||
int codePos = jsonData.indexOf("\"code\":");
|
||||
if (codePos == -1) {
|
||||
result = ParseNoCode;
|
||||
return result;
|
||||
}
|
||||
|
||||
int codeStart = jsonData.indexOf(":", codePos) + 1;
|
||||
int codeEnd = jsonData.indexOf(",", codeStart);
|
||||
QString codeStr = jsonData.mid(codeStart, codeEnd - codeStart).trimmed();
|
||||
|
||||
int code = codeStr.toInt();
|
||||
if (code != 200) {
|
||||
result = ParseCodeError;
|
||||
return result;
|
||||
}
|
||||
|
||||
// 查找data数组开始位置
|
||||
int dataStartPos = jsonData.indexOf("\"data\":[");
|
||||
if (dataStartPos == -1) {
|
||||
result = ParseDataError;
|
||||
return result;
|
||||
}
|
||||
|
||||
dataStartPos = jsonData.indexOf("[", dataStartPos) + 1;
|
||||
|
||||
// 解析每个数据项
|
||||
int pos = dataStartPos;
|
||||
while (pos < jsonData.length()) {
|
||||
// 查找对象开始
|
||||
int objStart = jsonData.indexOf("{", pos);
|
||||
if (objStart == -1) break;
|
||||
|
||||
// 查找对象结束
|
||||
int objEnd = jsonData.indexOf("}", objStart);
|
||||
if (objEnd == -1) break;
|
||||
|
||||
QString objStr = jsonData.mid(objStart, objEnd - objStart + 1);
|
||||
|
||||
ResponseData data;
|
||||
|
||||
// 解析depth字段
|
||||
int depthPos = objStr.indexOf("\"depth\":");
|
||||
if (depthPos != -1) {
|
||||
int depthStart = objStr.indexOf(":", depthPos) + 1;
|
||||
int depthEnd = objStr.indexOf(",", depthStart);
|
||||
if (depthEnd == -1) depthEnd = objStr.indexOf("}", depthStart);
|
||||
QString depthStr = objStr.mid(depthStart, depthEnd - depthStart).trimmed();
|
||||
data.depth = depthStr.toDouble();
|
||||
}
|
||||
|
||||
// 解析value字段
|
||||
int valuePos = objStr.indexOf("\"value\":");
|
||||
if (valuePos != -1) {
|
||||
int valueStart = objStr.indexOf(":", valuePos) + 1;
|
||||
int valueEnd = objStr.indexOf(",", valueStart);
|
||||
if (valueEnd == -1) valueEnd = objStr.indexOf("}", valueStart);
|
||||
QString valueStr = objStr.mid(valueStart, valueEnd - valueStart).trimmed();
|
||||
data.value = valueStr.toDouble();
|
||||
}
|
||||
|
||||
// 解析overlying_Pressure字段
|
||||
int pressurePos = objStr.indexOf("\"overlying_Pressure\":");
|
||||
if (pressurePos != -1) {
|
||||
int pressureStart = objStr.indexOf(":", pressurePos) + 1;
|
||||
int pressureEnd = objStr.indexOf(",", pressureStart);
|
||||
if (pressureEnd == -1) pressureEnd = objStr.indexOf("}", pressureStart);
|
||||
QString pressureStr = objStr.mid(pressureStart, pressureEnd - pressureStart).trimmed();
|
||||
data.overlying_Pressure = pressureStr.toDouble();
|
||||
}
|
||||
|
||||
// 解析dp字段
|
||||
int dpPos = objStr.indexOf("\"dp\":");
|
||||
if (dpPos != -1) {
|
||||
int dpStart = objStr.indexOf(":", dpPos) + 1;
|
||||
int dpEnd = objStr.indexOf(",", dpStart);
|
||||
if (dpEnd == -1) dpEnd = objStr.indexOf("}", dpStart);
|
||||
QString dpStr = objStr.mid(dpStart, dpEnd - dpStart).trimmed();
|
||||
data.dp = dpStr.toDouble();
|
||||
}
|
||||
|
||||
// 解析dpTrend字段
|
||||
int dpTrendPos = objStr.indexOf("\"dpTrend\":");
|
||||
if (dpTrendPos != -1) {
|
||||
int dpTrendStart = objStr.indexOf(":", dpTrendPos) + 1;
|
||||
int dpTrendEnd = objStr.indexOf(",", dpTrendStart);
|
||||
if (dpTrendEnd == -1) dpTrendEnd = objStr.indexOf("}", dpTrendStart);
|
||||
QString dpTrendStr = objStr.mid(dpTrendStart, dpTrendEnd - dpTrendStart).trimmed();
|
||||
data.dpTrend = dpTrendStr.toDouble();
|
||||
}
|
||||
|
||||
m_responseResult.append(data);
|
||||
pos = objEnd + 1;
|
||||
|
||||
// 检查是否还有下一个对象
|
||||
if (jsonData.indexOf("{", pos) == -1) break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const QList<ResponseData> &CloudAlgorithmAccess::getResponseResult() const
|
||||
{
|
||||
return m_responseResult;
|
||||
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#ifndef CLOUDALGORITHMACCESS_H
|
||||
#define CLOUDALGORITHMACCESS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QVector>
|
||||
class QTcpSocket;
|
||||
// 定义数据结构体
|
||||
struct ResponseData {
|
||||
int depth;
|
||||
double value;
|
||||
double overlying_Pressure;
|
||||
double dp;
|
||||
double dpTrend;
|
||||
};
|
||||
|
||||
enum ParseResult{
|
||||
ParseSuccess,
|
||||
ParseNoCode,
|
||||
ParseCodeError,
|
||||
ParseDataError
|
||||
};
|
||||
|
||||
class CloudAlgorithmAccess : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CloudAlgorithmAccess(QObject *parent = 0);
|
||||
QByteArray sendHttpPost(const QString &host, int port, const QString &path, const QByteArray &data);
|
||||
int parseResponseData(QString jsonData);
|
||||
QString buildJson(const QVector<double>& depths, const QVector<double>& values);
|
||||
const QList<ResponseData> &getResponseResult() const ;
|
||||
|
||||
private:
|
||||
QTcpSocket *m_tcpSocket;
|
||||
///响应数据解析完成后放入该容器中
|
||||
QList<ResponseData> m_responseResult;
|
||||
|
||||
};
|
||||
|
||||
#endif // CLOUDALGORITHMACCESS_H
|
||||
Loading…
Reference in New Issue
Block a user