[qt] Deprecation warnings and Qt compatibility fixes (#118)
* [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 <morten242@gmail.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<uint8_t[]>(image.sizeInBytes());
|
||||
memcpy(img.get(), image.constBits(), image.sizeInBytes());
|
||||
#else
|
||||
auto img = std::make_unique<uint8_t[]>(image.byteCount());
|
||||
memcpy(img.get(), image.constBits(), image.byteCount());
|
||||
#endif
|
||||
|
||||
glyph.bitmap = AlphaImage { size, std::move(img) };
|
||||
|
||||
|
||||
@@ -109,8 +109,13 @@ std::unique_ptr<mbgl::style::Image> 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<uint8_t[]>(swapped.sizeInBytes());
|
||||
memcpy(img.get(), swapped.constBits(), swapped.sizeInBytes());
|
||||
#else
|
||||
auto img = std::make_unique<uint8_t[]>(swapped.byteCount());
|
||||
memcpy(img.get(), swapped.constBits(), swapped.byteCount());
|
||||
#endif
|
||||
|
||||
return std::make_unique<mbgl::style::Image>(
|
||||
id.toStdString(),
|
||||
|
||||
@@ -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<uint8_t[]>(image.sizeInBytes());
|
||||
memcpy(img.get(), image.constBits(), image.sizeInBytes());
|
||||
#else
|
||||
auto img = std::make_unique<uint8_t[]>(image.byteCount());
|
||||
memcpy(img.get(), image.constBits(), image.byteCount());
|
||||
#endif
|
||||
|
||||
return { { static_cast<uint32_t>(image.width()), static_cast<uint32_t>(image.height()) },
|
||||
std::move(img) };
|
||||
|
||||
@@ -129,12 +129,12 @@ Database::Database(std::unique_ptr<DatabaseImpl> 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(';')) {
|
||||
|
||||
Reference in New Issue
Block a user