[cpp-qt-client]Allow nullable parameters (#17805)

* [cpp-qt-client]Allow nullable parameters

Fixes #17756

* Update samples
This commit is contained in:
Miklós Márton 2024-02-23 09:01:13 +01:00 committed by GitHub
parent c4f90d058b
commit 9c72b25bf4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 45 deletions

View File

@ -397,7 +397,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
} }
fullPath.append(paramString); fullPath.append(paramString);
{{/isPrimitiveType}}{{#isPrimitiveType}} {{/isPrimitiveType}}{{#isPrimitiveType}}
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}}))); fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding({{paramName}}{{^required}}.stringValue(){{/required}}));
{{/isPrimitiveType}} {{/isPrimitiveType}}
{{/collectionFormat}} {{/collectionFormat}}
{{#collectionFormat}} {{#collectionFormat}}

View File

@ -21,27 +21,6 @@
namespace {{this}} { namespace {{this}} {
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}
template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val){
m_hasValue = true;
m_Value = val;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}
};
bool setDateTimeFormat(const QString &format); bool setDateTimeFormat(const QString &format);
bool setDateTimeFormat(const Qt::DateFormat &format); bool setDateTimeFormat(const Qt::DateFormat &format);
@ -264,6 +243,37 @@ bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
return ok; return ok;
} }
template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_isNull = false;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val, bool isNull = false){
m_hasValue = true;
m_Value = val;
m_isNull = isNull;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}
QString stringValue() const {
if (m_isNull) {
return QStringLiteral("");
} else {
return toStringValue(value());
}
}
};
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
} // namespace {{this}} } // namespace {{this}}
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}

View File

@ -29,27 +29,6 @@
namespace test_namespace { namespace test_namespace {
template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val){
m_hasValue = true;
m_Value = val;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}
};
bool setDateTimeFormat(const QString &format); bool setDateTimeFormat(const QString &format);
bool setDateTimeFormat(const Qt::DateFormat &format); bool setDateTimeFormat(const Qt::DateFormat &format);
@ -272,6 +251,37 @@ bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
return ok; return ok;
} }
template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_isNull = false;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val, bool isNull = false){
m_hasValue = true;
m_Value = val;
m_isNull = isNull;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}
QString stringValue() const {
if (m_isNull) {
return QStringLiteral("");
} else {
return toStringValue(value());
}
}
};
} // namespace test_namespace } // namespace test_namespace
#endif // PFX_HELPERS_H #endif // PFX_HELPERS_H

View File

@ -655,7 +655,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
else else
fullPath.append("?"); fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(username));
} }
{ {
@ -670,7 +670,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
else else
fullPath.append("?"); fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password))); fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(password));
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);