Skip to content

Commit 49e3318

Browse files
[qt-cpp] Remove Qt support before Qt 5.15.2 (#19164)
1 parent 94264e5 commit 49e3318

11 files changed

Lines changed: 16 additions & 222 deletions

File tree

modules/openapi-generator/src/main/resources/cpp-qt-client/HttpFileElement.cpp.mustache

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ QJsonValue {{prefix}}HttpFileElement::asJsonValue() const {
5757
if (!result) {
5858
qDebug() << "Error opening file " << local_filename;
5959
}
60-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
6160
return QJsonDocument::fromJson(bArray.data()).object();
62-
#else
63-
return QJsonDocument::fromBinaryData(bArray.data()).object();
64-
#endif
6561
}
6662

6763
bool {{prefix}}HttpFileElement::fromStringValue(const QString &instr) {
@@ -86,11 +82,7 @@ bool {{prefix}}HttpFileElement::fromJsonValue(const QJsonValue &jval) {
8682
file.remove();
8783
}
8884
result = file.open(QIODevice::WriteOnly);
89-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
9085
file.write(QJsonDocument(jval.toObject()).toJson());
91-
#else
92-
file.write(QJsonDocument(jval.toObject()).toBinaryData());
93-
#endif
9486
file.close();
9587
if (!result) {
9688
qDebug() << "Error creating file " << local_filename;

modules/openapi-generator/src/main/resources/cpp-qt-client/HttpRequest.cpp.mustache

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
#include <QUrl>
88
#include <QUuid>
99
#include <QtGlobal>
10-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
11-
#define SKIP_EMPTY_PARTS Qt::SkipEmptyParts
12-
#else
13-
#define SKIP_EMPTY_PARTS QString::SkipEmptyParts
14-
#endif{{#contentCompression}}
10+
{{#contentCompression}}
1511
#include <zlib.h>{{/contentCompression}}
1612

1713
#include "{{prefix}}HttpRequest.h"
@@ -440,14 +436,14 @@ void {{prefix}}HttpRequestWorker::process_response(QNetworkReply *reply) {
440436
}
441437

442438
if (!contentDispositionHdr.isEmpty()) {
443-
auto contentDisposition = contentDispositionHdr.split(QString(";"), SKIP_EMPTY_PARTS);
439+
auto contentDisposition = contentDispositionHdr.split(QString(";"), Qt::SkipEmptyParts);
444440
auto contentType =
445-
!contentTypeHdr.isEmpty() ? contentTypeHdr.split(QString(";"), SKIP_EMPTY_PARTS).first() : QString();
441+
!contentTypeHdr.isEmpty() ? contentTypeHdr.split(QString(";"), Qt::SkipEmptyParts).first() : QString();
446442
if ((contentDisposition.count() > 0) && (contentDisposition.first() == QString("attachment"))) {
447443
QString filename = QUuid::createUuid().toString();
448444
for (const auto &file : contentDisposition) {
449445
if (file.contains(QString("filename"))) {
450-
filename = file.split(QString("="), SKIP_EMPTY_PARTS).at(1);
446+
filename = file.split(QString("="), Qt::SkipEmptyParts).at(1);
451447
break;
452448
}
453449
}
@@ -457,14 +453,14 @@ void {{prefix}}HttpRequestWorker::process_response(QNetworkReply *reply) {
457453
}
458454

459455
} else if (!contentTypeHdr.isEmpty()) {
460-
auto contentType = contentTypeHdr.split(QString(";"), SKIP_EMPTY_PARTS);
456+
auto contentType = contentTypeHdr.split(QString(";"), Qt::SkipEmptyParts);
461457
if ((contentType.count() > 0) && (contentType.first() == QString("multipart/form-data"))) {
462458
// TODO : Handle Multipart responses
463459
} else {
464460
if(!contentEncodingHdr.isEmpty()){
465-
auto encoding = contentEncodingHdr.split(QString(";"), SKIP_EMPTY_PARTS);
461+
auto encoding = contentEncodingHdr.split(QString(";"), Qt::SkipEmptyParts);
466462
if(encoding.count() > 0){
467-
auto compressionTypes = encoding.first().split(',', SKIP_EMPTY_PARTS);
463+
auto compressionTypes = encoding.first().split(',', Qt::SkipEmptyParts);
468464
if(compressionTypes.contains("gzip", Qt::CaseInsensitive) || compressionTypes.contains("deflate", Qt::CaseInsensitive)){
469465
response = decompress(reply->readAll());
470466
} else if(compressionTypes.contains("identity", Qt::CaseInsensitive)){

modules/openapi-generator/src/main/resources/cpp-qt-client/HttpRequest.h.mustache

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
#include <QObject>
1515
#include <QString>
1616
#include <QTimer>
17-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
18-
#include <QRandomGenerator>
19-
#endif
17+
#include <QRandomGenerator>
2018

2119
#include "{{prefix}}HttpFileElement.h"
2220

@@ -89,9 +87,7 @@ private:
8987
bool isResponseCompressionEnabled;
9088
bool isRequestCompressionEnabled;
9189
int httpResponseCode;
92-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
9390
QRandomGenerator randomGenerator;
94-
#endif
9591

9692
void on_reply_timeout(QNetworkReply *reply);
9793
void on_reply_finished(QNetworkReply *reply);

modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,9 @@ int {{classname}}::addServerConfiguration(const QString &operation, const QUrl &
129129
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
130130
*/
131131
void {{classname}}::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, {{prefix}}ServerVariable> &variables) {
132-
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
133132
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
134133
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
135134
}
136-
#else
137-
for (auto &e : _serverIndices.keys()) {
138-
setServerIndex(e, addServerConfiguration(e, url, description, variables));
139-
}
140-
#endif
141135
}
142136

143137
/**
@@ -662,15 +656,9 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
662656
}
663657
}
664658
{{/cookieParams}}
665-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
666659
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
667660
input.headers.insert(keyValueIt->first, keyValueIt->second);
668661
}
669-
#else
670-
for (auto key : _defaultHeaders.keys()) {
671-
input.headers.insert(key, _defaultHeaders[key]);
672-
}
673-
#endif
674662

675663
connect(worker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
676664
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);

samples/client/petstore/cpp-qt/client/PFXHttpFileElement.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ QJsonValue PFXHttpFileElement::asJsonValue() const {
6565
if (!result) {
6666
qDebug() << "Error opening file " << local_filename;
6767
}
68-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
6968
return QJsonDocument::fromJson(bArray.data()).object();
70-
#else
71-
return QJsonDocument::fromBinaryData(bArray.data()).object();
72-
#endif
7369
}
7470

7571
bool PFXHttpFileElement::fromStringValue(const QString &instr) {
@@ -94,11 +90,7 @@ bool PFXHttpFileElement::fromJsonValue(const QJsonValue &jval) {
9490
file.remove();
9591
}
9692
result = file.open(QIODevice::WriteOnly);
97-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
9893
file.write(QJsonDocument(jval.toObject()).toJson());
99-
#else
100-
file.write(QJsonDocument(jval.toObject()).toBinaryData());
101-
#endif
10294
file.close();
10395
if (!result) {
10496
qDebug() << "Error creating file " << local_filename;

samples/client/petstore/cpp-qt/client/PFXHttpRequest.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
#include <QUrl>
1818
#include <QUuid>
1919
#include <QtGlobal>
20-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
21-
#define SKIP_EMPTY_PARTS Qt::SkipEmptyParts
22-
#else
23-
#define SKIP_EMPTY_PARTS QString::SkipEmptyParts
24-
#endif
20+
2521

2622
#include "PFXHttpRequest.h"
2723

@@ -447,14 +443,14 @@ void PFXHttpRequestWorker::process_response(QNetworkReply *reply) {
447443
}
448444

449445
if (!contentDispositionHdr.isEmpty()) {
450-
auto contentDisposition = contentDispositionHdr.split(QString(";"), SKIP_EMPTY_PARTS);
446+
auto contentDisposition = contentDispositionHdr.split(QString(";"), Qt::SkipEmptyParts);
451447
auto contentType =
452-
!contentTypeHdr.isEmpty() ? contentTypeHdr.split(QString(";"), SKIP_EMPTY_PARTS).first() : QString();
448+
!contentTypeHdr.isEmpty() ? contentTypeHdr.split(QString(";"), Qt::SkipEmptyParts).first() : QString();
453449
if ((contentDisposition.count() > 0) && (contentDisposition.first() == QString("attachment"))) {
454450
QString filename = QUuid::createUuid().toString();
455451
for (const auto &file : contentDisposition) {
456452
if (file.contains(QString("filename"))) {
457-
filename = file.split(QString("="), SKIP_EMPTY_PARTS).at(1);
453+
filename = file.split(QString("="), Qt::SkipEmptyParts).at(1);
458454
break;
459455
}
460456
}
@@ -464,14 +460,14 @@ void PFXHttpRequestWorker::process_response(QNetworkReply *reply) {
464460
}
465461

466462
} else if (!contentTypeHdr.isEmpty()) {
467-
auto contentType = contentTypeHdr.split(QString(";"), SKIP_EMPTY_PARTS);
463+
auto contentType = contentTypeHdr.split(QString(";"), Qt::SkipEmptyParts);
468464
if ((contentType.count() > 0) && (contentType.first() == QString("multipart/form-data"))) {
469465
// TODO : Handle Multipart responses
470466
} else {
471467
if(!contentEncodingHdr.isEmpty()){
472-
auto encoding = contentEncodingHdr.split(QString(";"), SKIP_EMPTY_PARTS);
468+
auto encoding = contentEncodingHdr.split(QString(";"), Qt::SkipEmptyParts);
473469
if(encoding.count() > 0){
474-
auto compressionTypes = encoding.first().split(',', SKIP_EMPTY_PARTS);
470+
auto compressionTypes = encoding.first().split(',', Qt::SkipEmptyParts);
475471
if(compressionTypes.contains("gzip", Qt::CaseInsensitive) || compressionTypes.contains("deflate", Qt::CaseInsensitive)){
476472
response = decompress(reply->readAll());
477473
} else if(compressionTypes.contains("identity", Qt::CaseInsensitive)){

samples/client/petstore/cpp-qt/client/PFXHttpRequest.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
#include <QObject>
2525
#include <QString>
2626
#include <QTimer>
27-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
28-
#include <QRandomGenerator>
29-
#endif
27+
#include <QRandomGenerator>
3028

3129
#include "PFXHttpFileElement.h"
3230

@@ -97,9 +95,7 @@ class PFXHttpRequestWorker : public QObject {
9795
bool isResponseCompressionEnabled;
9896
bool isRequestCompressionEnabled;
9997
int httpResponseCode;
100-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
10198
QRandomGenerator randomGenerator;
102-
#endif
10399

104100
void on_reply_timeout(QNetworkReply *reply);
105101
void on_reply_finished(QNetworkReply *reply);

samples/client/petstore/cpp-qt/client/PFXPetApi.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,9 @@ int PFXPetApi::addServerConfiguration(const QString &operation, const QUrl &url,
128128
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
129129
*/
130130
void PFXPetApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
131-
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
132131
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
133132
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
134133
}
135-
#else
136-
for (auto &e : _serverIndices.keys()) {
137-
setServerIndex(e, addServerConfiguration(e, url, description, variables));
138-
}
139-
#endif
140134
}
141135

142136
/**
@@ -242,15 +236,9 @@ void PFXPetApi::addPet(const PFXPet &pfx_pet) {
242236
QByteArray output = pfx_pet.asJson().toUtf8();
243237
input.request_body.append(output);
244238
}
245-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
246239
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
247240
input.headers.insert(keyValueIt->first, keyValueIt->second);
248241
}
249-
#else
250-
for (auto key : _defaultHeaders.keys()) {
251-
input.headers.insert(key, _defaultHeaders[key]);
252-
}
253-
#endif
254242

255243
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback);
256244
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@@ -356,15 +344,9 @@ void PFXPetApi::allPets() {
356344
PFXHttpRequestInput input(fullPath, "GET");
357345

358346

359-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
360347
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
361348
input.headers.insert(keyValueIt->first, keyValueIt->second);
362349
}
363-
#else
364-
for (auto key : _defaultHeaders.keys()) {
365-
input.headers.insert(key, _defaultHeaders[key]);
366-
}
367-
#endif
368350

369351
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::allPetsCallback);
370352
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@@ -460,15 +442,9 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::Optional
460442
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value()));
461443
}
462444
}
463-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
464445
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
465446
input.headers.insert(keyValueIt->first, keyValueIt->second);
466447
}
467-
#else
468-
for (auto key : _defaultHeaders.keys()) {
469-
input.headers.insert(key, _defaultHeaders[key]);
470-
}
471-
#endif
472448

473449
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback);
474450
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@@ -660,15 +636,9 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
660636
PFXHttpRequestInput input(fullPath, "GET");
661637

662638

663-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
664639
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
665640
input.headers.insert(keyValueIt->first, keyValueIt->second);
666641
}
667-
#else
668-
for (auto key : _defaultHeaders.keys()) {
669-
input.headers.insert(key, _defaultHeaders[key]);
670-
}
671-
#endif
672642

673643
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback);
674644
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@@ -870,15 +840,9 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
870840
PFXHttpRequestInput input(fullPath, "GET");
871841

872842

873-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
874843
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
875844
input.headers.insert(keyValueIt->first, keyValueIt->second);
876845
}
877-
#else
878-
for (auto key : _defaultHeaders.keys()) {
879-
input.headers.insert(key, _defaultHeaders[key]);
880-
}
881-
#endif
882846

883847
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback);
884848
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@@ -1012,15 +976,9 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
1012976
PFXHttpRequestInput input(fullPath, "GET");
1013977

1014978

1015-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
1016979
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
1017980
input.headers.insert(keyValueIt->first, keyValueIt->second);
1018981
}
1019-
#else
1020-
for (auto key : _defaultHeaders.keys()) {
1021-
input.headers.insert(key, _defaultHeaders[key]);
1022-
}
1023-
#endif
1024982

1025983
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback);
1026984
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@@ -1092,15 +1050,9 @@ void PFXPetApi::updatePet(const PFXPet &pfx_pet) {
10921050
QByteArray output = pfx_pet.asJson().toUtf8();
10931051
input.request_body.append(output);
10941052
}
1095-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
10961053
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
10971054
input.headers.insert(keyValueIt->first, keyValueIt->second);
10981055
}
1099-
#else
1100-
for (auto key : _defaultHeaders.keys()) {
1101-
input.headers.insert(key, _defaultHeaders[key]);
1102-
}
1103-
#endif
11041056

11051057
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback);
11061058
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@@ -1228,15 +1180,9 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const ::test_namespace::
12281180
input.add_var("status", ::test_namespace::toStringValue(status.value()));
12291181
}
12301182

1231-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
12321183
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
12331184
input.headers.insert(keyValueIt->first, keyValueIt->second);
12341185
}
1235-
#else
1236-
for (auto key : _defaultHeaders.keys()) {
1237-
input.headers.insert(key, _defaultHeaders[key]);
1238-
}
1239-
#endif
12401186

12411187
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback);
12421188
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
@@ -1364,15 +1310,9 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const ::test_namespace::Optiona
13641310
input.add_file("file", file.value().local_filename, file.value().request_filename, file.value().mime_type);
13651311
}
13661312

1367-
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
13681313
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
13691314
input.headers.insert(keyValueIt->first, keyValueIt->second);
13701315
}
1371-
#else
1372-
for (auto key : _defaultHeaders.keys()) {
1373-
input.headers.insert(key, _defaultHeaders[key]);
1374-
}
1375-
#endif
13761316

13771317
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback);
13781318
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);

0 commit comments

Comments
 (0)