From a13b22276416a14652bd488c058dff1e4fd9fa60 Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Fri, 5 Mar 2021 12:43:26 -0800 Subject: [PATCH] [Qt5] Emit signal when api has finished processing all pending work (#8884) * Fixes #8864 * More elegant solution * Rerun sample generation * Fix whitespace that was fixed in merge conflict --- .../cpp-qt5-client/api-body.mustache | 6 +++ .../cpp-qt5-client/api-header.mustache | 1 + .../petstore/cpp-qt5/client/PFXPetApi.cpp | 48 +++++++++++++++++++ .../petstore/cpp-qt5/client/PFXPetApi.h | 1 + .../petstore/cpp-qt5/client/PFXStoreApi.cpp | 24 ++++++++++ .../petstore/cpp-qt5/client/PFXStoreApi.h | 1 + .../petstore/cpp-qt5/client/PFXUserApi.cpp | 48 +++++++++++++++++++ .../petstore/cpp-qt5/client/PFXUserApi.h | 1 + 8 files changed, 130 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache index fa562529c55..6e290e6eb85 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache @@ -663,6 +663,12 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} connect(worker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback); connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren<{{prefix}}HttpRequestWorker>().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache index ec9228f4f6a..ef0a61ff193 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache @@ -87,6 +87,7 @@ signals: void {{nickname}}SignalEFull({{prefix}}HttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);{{/operation}}{{/operations}} void abortRequestsSignal(); + void allPendingRequestsCompleted(); }; {{#cppNamespaceDeclarations}} diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index 2c2ed764180..0f647d74c01 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -238,6 +238,12 @@ void PFXPetApi::addPet(const PFXPet &body) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -297,6 +303,12 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QVariant &api_key) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -422,6 +434,12 @@ void PFXPetApi::findPetsByStatus(const QList &status) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -557,6 +575,12 @@ void PFXPetApi::findPetsByTags(const QList &tags) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -624,6 +648,12 @@ void PFXPetApi::getPetById(const qint64 &pet_id) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -666,6 +696,12 @@ void PFXPetApi::updatePet(const PFXPet &body) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -731,6 +767,12 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QVariant &name, co connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -796,6 +838,12 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QVariant &additional_meta connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index 93fcee1b7fa..0f99801fc3e 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -165,6 +165,7 @@ signals: void uploadFileSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void abortRequestsSignal(); + void allPendingRequestsCompleted(); }; } // namespace test_namespace diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index d239c81c7ac..b9babe1495a 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -242,6 +242,12 @@ void PFXStoreApi::deleteOrder(const QString &order_id) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::deleteOrderCallback); connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -284,6 +290,12 @@ void PFXStoreApi::getInventory() { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getInventoryCallback); connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -347,6 +359,12 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getOrderByIdCallback); connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -389,6 +407,12 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::placeOrderCallback); connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h index 8a467731d48..8508e14cfb0 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -117,6 +117,7 @@ signals: void placeOrderSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void abortRequestsSignal(); + void allPendingRequestsCompleted(); }; } // namespace test_namespace diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index 3d118c80279..9c6259c575f 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -238,6 +238,12 @@ void PFXUserApi::createUser(const PFXUser &body) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUserCallback); connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -279,6 +285,12 @@ void PFXUserApi::createUsersWithArrayInput(const QList &body) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithArrayInputCallback); connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -320,6 +332,12 @@ void PFXUserApi::createUsersWithListInput(const QList &body) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithListInputCallback); connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -373,6 +391,12 @@ void PFXUserApi::deleteUser(const QString &username) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::deleteUserCallback); connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -426,6 +450,12 @@ void PFXUserApi::getUserByName(const QString &username) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::getUserByNameCallback); connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -498,6 +528,12 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::loginUserCallback); connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -538,6 +574,12 @@ void PFXUserApi::logoutUser() { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::logoutUserCallback); connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } @@ -594,6 +636,12 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) { connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::updateUserCallback); connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, [this](){ + if(findChildren().count() == 0){ + emit allPendingRequestsCompleted(); + } + }); + worker->execute(&input); } diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index 8c075177211..fca34c30aec 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -159,6 +159,7 @@ signals: void updateUserSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void abortRequestsSignal(); + void allPendingRequestsCompleted(); }; } // namespace test_namespace