140 lines
3.8 KiB
C++
140 lines
3.8 KiB
C++
|
#include "SarUploadDialog.h"
|
|||
|
|
|||
|
#include "saruploaddialog.h"
|
|||
|
#include <QVBoxLayout>
|
|||
|
#include <QHBoxLayout>
|
|||
|
#include <QFormLayout>
|
|||
|
#include <QGroupBox>
|
|||
|
#include <QLabel>
|
|||
|
#include <QFileDialog>
|
|||
|
#include <QMessageBox>
|
|||
|
#include <QHttpMultiPart>
|
|||
|
#include <QUrlQuery>
|
|||
|
#include <QLineEdit>
|
|||
|
#include <QDateTimeEdit>
|
|||
|
#include <QPushButton>
|
|||
|
#include <QNetworkReply>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
SarUploadDialog::SarUploadDialog(QWidget* parent)
|
|||
|
: QDialog(parent),
|
|||
|
networkManager(new QNetworkAccessManager(this))
|
|||
|
{
|
|||
|
setupUi();
|
|||
|
initConnections();
|
|||
|
}
|
|||
|
|
|||
|
SarUploadDialog::~SarUploadDialog()
|
|||
|
{
|
|||
|
// <20>Զ<EFBFBD><D4B6>ͷ<EFBFBD>Qt<51><74><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
void SarUploadDialog::setupUi()
|
|||
|
{
|
|||
|
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QGroupBox* groupBox = new QGroupBox("Upload Parameters ( * required)");
|
|||
|
QFormLayout* formLayout = new QFormLayout;
|
|||
|
|
|||
|
// dataSource<63>ֶ<EFBFBD>
|
|||
|
leFilePath = new QLineEdit;
|
|||
|
btnBrowse = new QPushButton("Browse...");
|
|||
|
QHBoxLayout* fileLayout = new QHBoxLayout;
|
|||
|
fileLayout->addWidget(leFilePath);
|
|||
|
fileLayout->addWidget(btnBrowse);
|
|||
|
formLayout->addRow("dataSource*:", fileLayout);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ֶγ<D6B6>ʼ<EFBFBD><CABC>...
|
|||
|
|
|||
|
groupBox->setLayout(formLayout);
|
|||
|
mainLayout->addWidget(groupBox);
|
|||
|
|
|||
|
// <20><>ť<EFBFBD><C5A5>
|
|||
|
QHBoxLayout* buttonLayout = new QHBoxLayout;
|
|||
|
btnExecute = new QPushButton("Execute");
|
|||
|
btnClear = new QPushButton("Clear");
|
|||
|
btnCancel = new QPushButton("Cancel");
|
|||
|
buttonLayout->addWidget(btnExecute);
|
|||
|
buttonLayout->addWidget(btnClear);
|
|||
|
buttonLayout->addWidget(btnCancel);
|
|||
|
mainLayout->addLayout(buttonLayout);
|
|||
|
}
|
|||
|
|
|||
|
void SarUploadDialog::initConnections()
|
|||
|
{
|
|||
|
connect(btnBrowse, &QPushButton::clicked, this, &SarUploadDialog::onBrowseClicked);
|
|||
|
connect(btnExecute, &QPushButton::clicked, this, &SarUploadDialog::onExecuteClicked);
|
|||
|
connect(btnClear, &QPushButton::clicked, [this]() {
|
|||
|
leFilePath->clear();
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>...
|
|||
|
});
|
|||
|
connect(btnCancel, &QPushButton::clicked, this, &QDialog::reject);
|
|||
|
}
|
|||
|
|
|||
|
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۺ<EFBFBD><DBBA><EFBFBD>
|
|||
|
void SarUploadDialog::onBrowseClicked()
|
|||
|
{
|
|||
|
QString file = QFileDialog::getOpenFileName(this, "Select SAR File");
|
|||
|
if (!file.isEmpty()) leFilePath->setText(file);
|
|||
|
}
|
|||
|
|
|||
|
// ִ<><D6B4><EFBFBD>ϴ<EFBFBD>
|
|||
|
void SarUploadDialog::onExecuteClicked()
|
|||
|
{
|
|||
|
if (!validateInputs()) return;
|
|||
|
|
|||
|
QUrlQuery query;
|
|||
|
query.addQueryItem("dataType", leDataType->text());
|
|||
|
query.addQueryItem("dataname", leDataname->text());
|
|||
|
|
|||
|
QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
|
|||
|
|
|||
|
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
QHttpPart filePart;
|
|||
|
filePart.setHeader(QNetworkRequest::ContentDispositionHeader,
|
|||
|
QVariant("form-data; name=\"dataSource\"; filename=\""
|
|||
|
+ QFileInfo(leFilePath->text()).fileName() + "\""));
|
|||
|
QFile* file = new QFile(leFilePath->text());
|
|||
|
file->open(QIODevice::ReadOnly);
|
|||
|
filePart.setBodyDevice(file);
|
|||
|
multiPart->append(filePart);
|
|||
|
|
|||
|
QUrl url("http://your-api-domain/api/uploadOpticalSar");
|
|||
|
url.setQuery(query);
|
|||
|
|
|||
|
QNetworkRequest request(url);
|
|||
|
request.setRawHeader("Accept", "application/json");
|
|||
|
|
|||
|
QNetworkReply* reply = networkManager->put(request, multiPart);
|
|||
|
connect(reply, &QNetworkReply::finished, [=]() {
|
|||
|
handleResponse(reply);
|
|||
|
multiPart->deleteLater();
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
// <20><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
|
|||
|
void SarUploadDialog::handleResponse(QNetworkReply* reply)
|
|||
|
{
|
|||
|
if (reply->error() == QNetworkReply::NoError) {
|
|||
|
QMessageBox::information(this, "Success", "Upload completed successfully");
|
|||
|
}
|
|||
|
else {
|
|||
|
QMessageBox::critical(this, "Error",
|
|||
|
QString("Error %1: %2").arg(reply->error()).arg(reply->errorString()));
|
|||
|
}
|
|||
|
reply->deleteLater();
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
|
|||
|
bool SarUploadDialog::validateInputs()
|
|||
|
{
|
|||
|
if (leFilePath->text().isEmpty()) {
|
|||
|
QMessageBox::warning(this, "Warning", "dataSource is required!");
|
|||
|
return false;
|
|||
|
}
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD>...
|
|||
|
return true;
|
|||
|
}
|