Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Qt5.15 and Qt6 compatibility #15

Merged
merged 16 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/imports/restclient/qmlgenericrestreply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ QtRestClient::QmlGenericRestReply::QmlGenericRestReply(SerializerBase *serialize

QString QtRestClient::QmlGenericRestReply::returnType() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
return QString::fromUtf8(QMetaType::typeName(_returnType));
#else
return QString::fromUtf8(QMetaType(_returnType).name());
#endif
}

QString QtRestClient::QmlGenericRestReply::errorType() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
return QString::fromUtf8(QMetaType::typeName(_errorType));
#else
return QString::fromUtf8(QMetaType(_errorType).name());
#endif
}

void QtRestClient::QmlGenericRestReply::addCompletedHandler(const QJSValue &completedHandler)
Expand Down
2 changes: 1 addition & 1 deletion src/imports/restclient/qmlpaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ QmlPaging QmlPaging::create(RestClient *client, QJSEngine *engine, const RestRep

bool QmlPaging::isValid() const
{
return _paging;
return static_cast<bool>(_paging);
}

RestReply *QmlPaging::next()
Expand Down
2 changes: 1 addition & 1 deletion src/imports/restclient/qmlrestclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ QString QmlRestClass::path() const

QQmlListProperty<QmlRestClass> QmlRestClass::classes()
{
return {this, _childClasses};
return {this, &_childClasses};
}

void QmlRestClass::classBegin() {}
Expand Down
2 changes: 1 addition & 1 deletion src/imports/restclient/qmlrestclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ QmlRestClient::QmlRestClient(QObject *parent) :

QQmlListProperty<QmlRestClass> QmlRestClient::classes()
{
return {this, _childClasses};
return {this, &_childClasses};
}
8 changes: 4 additions & 4 deletions src/restclient/genericrestreply.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ GenericRestReply<Paging<DataClassType>, ErrorClassType> *GenericRestReply<Paging
[&](const auto &data) {
auto iPaging = this->_client->pagingFactory()->createPaging(this->_client->serializer(), data);
auto pData = this->_client->serializer()->deserializeGeneric(std::visit(__private::overload {
[](const QCborArray &data) -> std::variant<QCborValue, QJsonValue> {
return QCborValue{data};
[](const QCborArray &innerData) -> std::variant<QCborValue, QJsonValue> {
return QCborValue{innerData};
},
[](const QJsonArray &data) -> std::variant<QCborValue, QJsonValue> {
return QJsonValue{data};
[](const QJsonArray &innerData) -> std::variant<QCborValue, QJsonValue> {
return QJsonValue{innerData};
}
}, iPaging->items()),
qMetaTypeId<QList<DataClassType>>())
Expand Down
36 changes: 18 additions & 18 deletions src/restclient/paging.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Paging<T>::Paging(IPaging *iPaging, const QList<T> &data, RestClient *client) :
template<typename T>
bool Paging<T>::isValid() const
{
return d->iPaging;
return static_cast<bool>(d->iPaging);
}

template<typename T>
Expand Down Expand Up @@ -140,8 +140,8 @@ void Paging<T>::iterate(const std::function<bool (T, qint64)> &iterator, qint64
//continue to the next one
auto max = calcMax(to);
if (index < max && d->iPaging->hasNext()) {
qCDebug(logPaging) << "Requesting next paging object with offset" << index
<< "as" << d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo);
qCDebug(logPaging, "Requesting next paging object with offset %s as %s", QString::number(index),
d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo));
next()->onSucceeded([iterator, to, index](int, const Paging<T> &paging) {
if (paging.isValid())
paging.iterate(iterator, to, index);
Expand All @@ -161,8 +161,8 @@ void Paging<T>::iterate(QObject *scope, const std::function<bool (T, qint64)> &i
//continue to the next one
auto max = calcMax(to);
if (index < max && d->iPaging->hasNext()) {
qCDebug(logPaging) << "Requesting next paging object with offset" << index
<< "as" << d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo);
qCDebug(logPaging, "Requesting next paging object with offset %s as %s", QString::number(index),
d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo));
next()->onSucceeded(scope, [scope, iterator, to, index](int, const Paging<T> &paging) {
if (paging.isValid())
paging.iterate(scope, iterator, to, index);
Expand All @@ -183,8 +183,8 @@ void Paging<T>::iterate(const std::function<bool(T, qint64)> &iterator, const st
//continue to the next one
auto max = calcMax(to);
if (index < max && d->iPaging->hasNext()) {
qCDebug(logPaging) << "Requesting next paging object with offset" << index
<< "as" << d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo);
qCDebug(logPaging, "Requesting next paging object with offset %s as %s", QString::number(index),
d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo));
next<EO>()->onSucceeded([iterator, errorHandler, failureTransformer, to, index](int, const Paging<T> &paging) {
if (paging.isValid())
paging.iterate(iterator, errorHandler, failureTransformer, to, index);
Expand All @@ -206,8 +206,8 @@ void Paging<T>::iterate(QObject *scope, const std::function<bool(T, qint64)> &it
//continue to the next one
auto max = calcMax(to);
if (index < max && d->iPaging->hasNext()) {
qCDebug(logPaging) << "Requesting next paging object with offset" << index
<< "as" << d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo);
qCDebug(logPaging, "Requesting next paging object with offset %s as %s", QString::number(index),
d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo));
next<EO>()->onSucceeded(scope, [scope, iterator, errorHandler, failureTransformer, to, index](int, const Paging<T> &paging) {
if (paging.isValid())
paging.iterate(scope, iterator, errorHandler, failureTransformer, to, index);
Expand All @@ -229,8 +229,8 @@ void Paging<T>::iterate(const std::function<bool(T, qint64)> &iterator, const st
//continue to the next one
auto max = calcMax(to);
if (index < max && d->iPaging->hasNext()) {
qCDebug(logPaging) << "Requesting next paging object with offset" << index
<< "as" << d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo);
qCDebug(logPaging, "Requesting next paging object with offset %s as %s", QString::number(index),
d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo));
next<EO>()->onSucceeded([iterator, failureHandler, errorHandler, exceptionHandler, to, index](int, const Paging<T> &paging) {
if (paging.isValid())
paging.iterate(iterator, failureHandler, errorHandler, exceptionHandler, to, index);
Expand All @@ -254,8 +254,8 @@ void Paging<T>::iterate(QObject *scope, const std::function<bool(T, qint64)> &it
//continue to the next one
auto max = calcMax(to);
if(index < max && d->iPaging->hasNext()) {
qCDebug(logPaging) << "Requesting next paging object with offset" << index
<< "as" << d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo);
qCDebug(logPaging, "Requesting next paging object with offset %s as %s", QString::number(index),
d->iPaging->next().toString(QUrl::PrettyDecoded | QUrl::RemoveUserInfo));
next<EO>()->onSucceeded(scope, [scope, iterator, failureHandler, errorHandler, exceptionHandler, to, index](int, const Paging<T> &paging) {
if (paging.isValid())
paging.iterate(scope, iterator, failureHandler, errorHandler, exceptionHandler, to, index);
Expand Down Expand Up @@ -292,9 +292,9 @@ qint64 Paging<T>::internalIterate(const std::function<bool (T, qint64)> &iterato
max = static_cast<int>(std::min(to, offset + count) - offset);
}

qCDebug(logPaging).nospace() << "iterating over available range ["
<< offset + start << ":"
<< offset + max - 1 << "]";
qCDebug(logPaging, "iterating over available range [%s:%s]",
QString::number(offset + start),
QString::number(offset + max - 1));

// delete unused items caused by from
for (auto j = 0; j < start; ++j)
Expand All @@ -307,8 +307,8 @@ qint64 Paging<T>::internalIterate(const std::function<bool (T, qint64)> &iterato
auto item = d->data.value(i);
auto index = offset >= 0 ? offset + i : -1ll;
if (!iterator(item, index)) {
qCDebug(logPaging) << "Iterator stopped paging iteration at index"
<< index;
qCDebug(logPaging, "Iterator stopped paging iteration at index %s",
QString::number(index));
canceled = true;
break;
}
Expand Down
14 changes: 13 additions & 1 deletion src/restclient/pagingmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ QVariant PagingModel::headerData(int section, Qt::Orientation orientation, int r

if (d->columns.isEmpty()) {
if (section == 0) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto metaObject = QMetaType::metaObjectForType(d->typeId);
#else
auto metaObject = QMetaType(d->typeId).metaObject();
#endif
if (metaObject)
return QString::fromUtf8(metaObject->className());
}
Expand Down Expand Up @@ -175,7 +179,11 @@ QVariant PagingModel::data(const QModelIndex &index, int role) const
#ifndef Q_RESTCLIENT_NO_JSON_SERIALIZER
} else {
// get the meta object
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto metaObject = QMetaType::metaObjectForType(d->typeId);
#else
const auto metaObject = QMetaType(d->typeId).metaObject();
#endif
if (!metaObject)
return {};

Expand Down Expand Up @@ -298,7 +306,7 @@ RestReply *RestClassFetcher::fetch(const QUrl &url) const

void PagingModelPrivate::clearData()
{
const auto tFlags = QMetaType::typeFlags(typeId);
const auto tFlags = QMetaType(typeId).flags();
if (tFlags.testFlag(QMetaType::PointerToQObject) ||
tFlags.testFlag(QMetaType::TrackingPointerToQObject)) {
for (const auto &value : qAsConst(data)) {
Expand All @@ -313,7 +321,11 @@ void PagingModelPrivate::clearData()
void PagingModelPrivate::generateRoleNames()
{
pagingRoleNames = {{PagingModel::ModelDataRole, "modelData"}};
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const auto metaObject = QMetaType::metaObjectForType(typeId);
#else
const auto metaObject = QMetaType(typeId).metaObject();
#endif
if (metaObject) {
auto roleIndex = PagingModel::ModelDataRole;
for(auto i = 0; i < metaObject->propertyCount(); ++i)
Expand Down
12 changes: 6 additions & 6 deletions src/restclient/qtrestclient_helpertypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct FnBinder<int, QJsonValue> {
xFn(code, QJsonValue{QJsonValue::Undefined});
},
[xFn, code](const QCborValue &){
qCWarning(logGlobal) << "CBOR data in JSON callback - discarding";
qCWarning(logGlobal, "CBOR data in JSON callback - discarding");
},
[xFn, code](const QJsonValue &vValue){
xFn(code, vValue);
Expand All @@ -98,7 +98,7 @@ struct FnBinder<int, QJsonObject> {
xFn(code, QJsonObject{});
},
[xFn, code](const QCborValue &){
qCWarning(logGlobal) << "CBOR data in JSON callback - discarding";
qCWarning(logGlobal, "CBOR data in JSON callback - discarding");
},
[xFn, code](const QJsonValue &vValue){
xFn(code, vValue.toObject());
Expand All @@ -118,7 +118,7 @@ struct FnBinder<int, QJsonArray> {
xFn(code, QJsonArray{});
},
[xFn, code](const QCborValue &){
qCWarning(logGlobal) << "CBOR data in JSON callback - discarding";
qCWarning(logGlobal, "CBOR data in JSON callback - discarding");
},
[xFn, code](const QJsonValue &vValue){
xFn(code, vValue.toArray());
Expand All @@ -141,7 +141,7 @@ struct FnBinder<int, QCborValue> {
xFn(code, vValue);
},
[xFn, code](const QJsonValue &){
qCWarning(logGlobal) << "JSON data in CBOR callback - discarding";
qCWarning(logGlobal, "JSON data in CBOR callback - discarding");
}
}, value);
};
Expand All @@ -161,7 +161,7 @@ struct FnBinder<int, QCborMap> {
xFn(code, vValue.toMap());
},
[xFn, code](const QJsonValue &){
qCWarning(logGlobal) << "JSON data in CBOR callback - discarding";
qCWarning(logGlobal, "JSON data in CBOR callback - discarding");
}
}, value);
};
Expand All @@ -181,7 +181,7 @@ struct FnBinder<int, QCborArray> {
xFn(code, vValue.toArray());
},
[xFn, code](const QJsonValue &){
qCWarning(logGlobal) << "JSON data in CBOR callback - discarding";
qCWarning(logGlobal, "JSON data in CBOR callback - discarding");
}
}, value);
};
Expand Down
8 changes: 8 additions & 0 deletions src/restclient/requestbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ RequestBuilder &RequestBuilder::setFragment(QString fragment)

RequestBuilder &RequestBuilder::addPath(const QString &pathSegment)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
d->path.append(pathSegment.split(QLatin1Char('/'), QString::SkipEmptyParts));
#else
d->path.append(pathSegment.split(QLatin1Char('/'), Qt::SkipEmptyParts));
#endif
return *this;
}

Expand Down Expand Up @@ -225,7 +229,11 @@ QUrl RequestBuilder::buildUrl() const
{
auto url = d->base;

#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
auto pathList = url.path().split(QLatin1Char('/'), QString::SkipEmptyParts);
#else
auto pathList = url.path().split(QLatin1Char('/'), Qt::SkipEmptyParts);
#endif
if (!d->version.isNull())
pathList.append(QLatin1Char('v') + d->version.normalized().toString());
pathList.append(d->path);
Expand Down
4 changes: 4 additions & 0 deletions src/restclient/restclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ RestClass *RestClass::subClass(const QString &path, QObject *parent) const
{
Q_D(const RestClass);
auto nPath = d->subPath;
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
nPath.append(path.split(QLatin1Char('/'), QString::SkipEmptyParts));
#else
nPath.append(path.split(QLatin1Char('/'), Qt::SkipEmptyParts));
#endif
return new RestClass{d->client, std::move(nPath), parent};
}

Expand Down
10 changes: 10 additions & 0 deletions src/restclient/restclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ RestClient::RestClient(SerializerBase *serializer, QObject *parent) :

RestClass *RestClient::createClass(const QString &path, QObject *parent)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
return new RestClass{this, path.split(QLatin1Char('/'), QString::SkipEmptyParts), parent};
#else
return new RestClass{this, path.split(QLatin1Char('/'), Qt::SkipEmptyParts), parent};
#endif
}

RestClass *RestClient::rootClass() const
Expand Down Expand Up @@ -292,8 +296,14 @@ void RestClient::setModernAttributes()
Q_D(RestClient);
QWriteLocker _{d->threadLock};
d->attribs.insert(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
d->attribs.insert(QNetworkRequest::SpdyAllowedAttribute, true);
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
d->attribs.insert(QNetworkRequest::HTTP2AllowedAttribute, true);
#else
d->attribs.insert(QNetworkRequest::Http2AllowedAttribute, true);
#endif
Q_EMIT requestAttributesChanged(d->attribs, {});
}

Expand Down
5 changes: 5 additions & 0 deletions src/restclient/restreply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,13 @@ void RestReplyPrivate::connectReply()
this, &RestReplyPrivate::_q_replyFinished);

// forward some signals
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QObject::connect(networkReply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
q, &RestReply::networkError);
#else
QObject::connect(networkReply, &QNetworkReply::errorOccurred,
q, &RestReply::networkError);
#endif
#ifndef QT_NO_SSL
connect(networkReply, &QNetworkReply::sslErrors,
this, &RestReplyPrivate::_q_handleSslErrors);
Expand Down
3 changes: 2 additions & 1 deletion src/restclient/restreply_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public Q_SLOTS:

class Q_RESTCLIENT_EXPORT RestReplyPrivate : public QObjectPrivate, public QRunnable
{
Q_DECLARE_PUBLIC(RestReply)
public:
Q_DECLARE_PUBLIC(RestReply)

using DataType = RestReply::DataType;
using Error = RestReply::Error;

Expand Down
Loading