From aef3d4dd74bad5b49bef8ed6c40ac68b8343ffd7 Mon Sep 17 00:00:00 2001 From: Tadej Novak Date: Fri, 16 Jul 2021 09:52:48 +0200 Subject: [PATCH] [qt] Deprecation warnings and Qt compatibility fixes (#118) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [qt] Fix compilation of the sqlite wrapper * [qt] Fix QImage-related warnings * Update Qt redirection handling Since 5.9 RedirectPolicyAttribute is preferred, and from 6.0 the behavior of NoLessSafeRedirectPolicy is the default. * [qt] Fix more deprecation warnings Co-authored-by: MÃ¥rten Nordheim --- platform/qt/app/mapwindow.cpp | 10 +++++++--- platform/qt/src/http_file_source.cpp | 11 +++++++++++ platform/qt/src/local_glyph_rasterizer.cpp | 9 +++++++++ platform/qt/src/qmapboxgl.cpp | 5 +++++ platform/qt/src/qt_image.cpp | 5 +++++ platform/qt/src/sqlite3.cpp | 8 ++++++-- 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 58f1619c8..1cd1daaa9 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -448,16 +448,20 @@ void MapWindow::mouseMoveEvent(QMouseEvent *ev) void MapWindow::wheelEvent(QWheelEvent *ev) { - if (ev->orientation() == Qt::Horizontal) { + if (ev->angleDelta().y() == 0) { return; } - float factor = ev->delta() / 1200.; - if (ev->delta() < 0) { + float factor = ev->angleDelta().y() / 1200.; + if (ev->angleDelta().y() < 0) { factor = factor > -1 ? factor : 1 / factor; } +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + m_map->scaleBy(1 + factor, ev->position()); +#else m_map->scaleBy(1 + factor, ev->pos()); +#endif ev->accept(); } diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/http_file_source.cpp index 0e7167f06..9d4b97bbf 100644 --- a/platform/qt/src/http_file_source.cpp +++ b/platform/qt/src/http_file_source.cpp @@ -31,11 +31,22 @@ void HTTPFileSource::Impl::request(HTTPRequest* req) } QNetworkRequest networkRequest = req->networkRequest(); +#if QT_VERSION < 0x060000 +# if QT_VERSION >= 0x050900 + networkRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute, + QNetworkRequest::NoLessSafeRedirectPolicy); +# elif QT_VERSION >= 0x050600 networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); +# endif +#endif data.first = m_manager->get(networkRequest); connect(data.first, SIGNAL(finished()), this, SLOT(onReplyFinished())); +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + connect(data.first, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), this, SLOT(onReplyFinished())); +#else connect(data.first, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onReplyFinished())); +#endif } void HTTPFileSource::Impl::cancel(HTTPRequest* req) diff --git a/platform/qt/src/local_glyph_rasterizer.cpp b/platform/qt/src/local_glyph_rasterizer.cpp index 31abfd450..b1fe3845d 100644 --- a/platform/qt/src/local_glyph_rasterizer.cpp +++ b/platform/qt/src/local_glyph_rasterizer.cpp @@ -52,7 +52,11 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) { return glyph; } +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) + glyph.metrics.width = impl->metrics->horizontalAdvance(glyphID); +#else glyph.metrics.width = impl->metrics->width(glyphID); +#endif glyph.metrics.height = impl->metrics->height(); glyph.metrics.left = 3; glyph.metrics.top = -8; @@ -68,8 +72,13 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) { // Render at constant baseline, to align with glyphs that are rendered by node-fontnik. painter.drawText(QPointF(0, 20), QString(QChar(glyphID))); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + auto img = std::make_unique(image.sizeInBytes()); + memcpy(img.get(), image.constBits(), image.sizeInBytes()); +#else auto img = std::make_unique(image.byteCount()); memcpy(img.get(), image.constBits(), image.byteCount()); +#endif glyph.bitmap = AlphaImage { size, std::move(img) }; diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 5c4735cd6..29f40c428 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -109,8 +109,13 @@ std::unique_ptr toStyleImage(const QString &id, const QImage .rgbSwapped() .convertToFormat(QImage::Format_ARGB32_Premultiplied); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + auto img = std::make_unique(swapped.sizeInBytes()); + memcpy(img.get(), swapped.constBits(), swapped.sizeInBytes()); +#else auto img = std::make_unique(swapped.byteCount()); memcpy(img.get(), swapped.constBits(), swapped.byteCount()); +#endif return std::make_unique( id.toStdString(), diff --git a/platform/qt/src/qt_image.cpp b/platform/qt/src/qt_image.cpp index 302d39873..4cec62aa8 100644 --- a/platform/qt/src/qt_image.cpp +++ b/platform/qt/src/qt_image.cpp @@ -45,8 +45,13 @@ PremultipliedImage decodeImage(const std::string& string) { throw std::runtime_error("Unsupported image type"); } +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + auto img = std::make_unique(image.sizeInBytes()); + memcpy(img.get(), image.constBits(), image.sizeInBytes()); +#else auto img = std::make_unique(image.byteCount()); memcpy(img.get(), image.constBits(), image.byteCount()); +#endif return { { static_cast(image.width()), static_cast(image.height()) }, std::move(img) }; diff --git a/platform/qt/src/sqlite3.cpp b/platform/qt/src/sqlite3.cpp index 75befc37c..ed4e7b9e7 100644 --- a/platform/qt/src/sqlite3.cpp +++ b/platform/qt/src/sqlite3.cpp @@ -129,12 +129,12 @@ Database::Database(std::unique_ptr impl_) : impl(std::move(impl_)) {} -Database::Database(Database &&other) +Database::Database(Database &&other) noexcept : impl(std::move(other.impl)) { assert(impl); } -Database &Database::operator=(Database &&other) { +Database &Database::operator=(Database &&other) noexcept { std::swap(impl, other.impl); assert(impl); return *this; @@ -176,7 +176,11 @@ void Database::exec(const std::string &sql) { } void DatabaseImpl::exec(const std::string& sql) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QStringList statements = QString::fromStdString(sql).split(';', Qt::SkipEmptyParts); +#else QStringList statements = QString::fromStdString(sql).split(';', QString::SkipEmptyParts); +#endif statements.removeAll("\n"); for (QString statement : statements) { if (!statement.endsWith(';')) {