diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 1cd1daaa9..7f657ed08 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -409,7 +409,11 @@ void MapWindow::keyPressEvent(QKeyEvent *ev) void MapWindow::mousePressEvent(QMouseEvent *ev) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + m_lastPos = ev->position(); +#else m_lastPos = ev->localPos(); +#endif if (ev->type() == QEvent::MouseButtonPress) { if (ev->buttons() == (Qt::LeftButton | Qt::RightButton)) { @@ -430,19 +434,24 @@ void MapWindow::mousePressEvent(QMouseEvent *ev) void MapWindow::mouseMoveEvent(QMouseEvent *ev) { - QPointF delta = ev->localPos() - m_lastPos; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const QPointF &position = ev->position(); +#else + const QPointF &position = ev->localPos(); +#endif + QPointF delta = position - m_lastPos; if (!delta.isNull()) { if (ev->buttons() == Qt::LeftButton && ev->modifiers() & Qt::ShiftModifier) { m_map->pitchBy(delta.y()); } else if (ev->buttons() == Qt::LeftButton) { m_map->moveBy(delta); } else if (ev->buttons() == Qt::RightButton) { - m_map->rotateBy(m_lastPos, ev->localPos()); + m_map->rotateBy(m_lastPos, position); } } - m_lastPos = ev->localPos(); + m_lastPos = position; ev->accept(); } @@ -468,7 +477,7 @@ void MapWindow::wheelEvent(QWheelEvent *ev) void MapWindow::initializeGL() { m_map.reset(new QMapboxGL(nullptr, m_settings, size(), pixelRatio())); - connect(m_map.data(), SIGNAL(needsRendering()), this, SLOT(update())); + connect(m_map.get(), SIGNAL(needsRendering()), this, SLOT(update())); // Set default location to Helsinki. m_map->setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 5); @@ -481,11 +490,11 @@ void MapWindow::initializeGL() setWindowTitle(QString("MapLibre GL: ") + styleUrl); } - m_bearingAnimation = new QPropertyAnimation(m_map.data(), "bearing"); - m_zoomAnimation = new QPropertyAnimation(m_map.data(), "zoom"); + m_bearingAnimation = new QPropertyAnimation(m_map.get(), "bearing"); + m_zoomAnimation = new QPropertyAnimation(m_map.get(), "zoom"); - connect(m_zoomAnimation, SIGNAL(finished()), this, SLOT(animationFinished())); - connect(m_zoomAnimation, SIGNAL(valueChanged(const QVariant&)), this, SLOT(animationValueChanged())); + connect(m_zoomAnimation, &QPropertyAnimation::finished, this, &MapWindow::animationFinished); + connect(m_zoomAnimation, &QPropertyAnimation::valueChanged, this, &MapWindow::animationValueChanged); } void MapWindow::paintGL() diff --git a/platform/qt/app/mapwindow.hpp b/platform/qt/app/mapwindow.hpp index 0671c4251..f74f1b378 100644 --- a/platform/qt/app/mapwindow.hpp +++ b/platform/qt/app/mapwindow.hpp @@ -5,9 +5,10 @@ #include #include -#include #include +#include + class QKeyEvent; class QMouseEvent; class QWheelEvent; @@ -43,7 +44,7 @@ private: QPointF m_lastPos; QMapboxGLSettings m_settings; - QScopedPointer m_map; + std::unique_ptr m_map{}; QPropertyAnimation *m_bearingAnimation; QPropertyAnimation *m_zoomAnimation; diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp index 743f068ed..58fe922fd 100644 --- a/platform/qt/include/qmapboxgl.hpp +++ b/platform/qt/include/qmapboxgl.hpp @@ -11,6 +11,7 @@ #include #include +#include class QMapboxGLPrivate; @@ -245,8 +246,8 @@ public: void removeImage(const QString &name); void addCustomLayer(const QString &id, - QScopedPointer& host, - const QString& before = QString()); + std::unique_ptr host, + const QString &before = QString()); void addLayer(const QVariantMap ¶ms, const QString& before = QString()); bool layerExists(const QString &id); void removeLayer(const QString &id); diff --git a/platform/qt/src/async_task.cpp b/platform/qt/src/async_task.cpp index 79abd2945..2422e547e 100644 --- a/platform/qt/src/async_task.cpp +++ b/platform/qt/src/async_task.cpp @@ -11,7 +11,7 @@ namespace util { AsyncTask::Impl::Impl(std::function&& fn) : runLoop(RunLoop::Get()), task(std::move(fn)) { - connect(this, SIGNAL(send(void)), this, SLOT(runTask(void)), Qt::QueuedConnection); + connect(this, &AsyncTask::Impl::send, this, &AsyncTask::Impl::runTask, Qt::QueuedConnection); } void AsyncTask::Impl::maySend() { diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/http_file_source.cpp index 9d4b97bbf..a2a13c5e1 100644 --- a/platform/qt/src/http_file_source.cpp +++ b/platform/qt/src/http_file_source.cpp @@ -31,21 +31,21 @@ void HTTPFileSource::Impl::request(HTTPRequest* req) } QNetworkRequest networkRequest = req->networkRequest(); -#if QT_VERSION < 0x060000 -# if QT_VERSION >= 0x050900 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +# if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) networkRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); -# elif QT_VERSION >= 0x050600 +# elif QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); -# endif +# endif #endif data.first = m_manager->get(networkRequest); - connect(data.first, SIGNAL(finished()), this, SLOT(onReplyFinished())); + connect(data.first, &QNetworkReply::finished, this, &HTTPFileSource::Impl::onReplyFinished); #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) - connect(data.first, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), this, SLOT(onReplyFinished())); + connect(data.first, &QNetworkReply::errorOccurred, this, &HTTPFileSource::Impl::onReplyFinished); #else - connect(data.first, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onReplyFinished())); + connect(data.first, &QNetworkReply::error, this, &HTTPFileSource::Impl::onReplyFinished); #endif } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 4ea257150..8b566080b 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -1350,14 +1350,14 @@ void QMapboxGL::removeSource(const QString& id) this API and is not officially supported. Use at your own risk. */ void QMapboxGL::addCustomLayer(const QString &id, - QScopedPointer& host, - const QString& before) + std::unique_ptr host, + const QString &before) { class HostWrapper : public mbgl::style::CustomLayerHost { public: - QScopedPointer ptr; - HostWrapper(QScopedPointer& p) - : ptr(p.take()) { + std::unique_ptr ptr{}; + HostWrapper(std::unique_ptr p) + : ptr(std::move(p)) { } void initialize() { @@ -1386,7 +1386,7 @@ void QMapboxGL::addCustomLayer(const QString &id, d_ptr->mapObj->getStyle().addLayer(std::make_unique( id.toStdString(), - std::make_unique(host)), + std::make_unique(std::move(host))), before.isEmpty() ? mbgl::optional() : mbgl::optional(before.toStdString())); } @@ -1743,9 +1743,9 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin qRegisterMetaType("QMapboxGL::MapChange"); - connect(m_mapObserver.get(), SIGNAL(mapChanged(QMapboxGL::MapChange)), q, SIGNAL(mapChanged(QMapboxGL::MapChange))); - connect(m_mapObserver.get(), SIGNAL(mapLoadingFailed(QMapboxGL::MapLoadingFailure,QString)), q, SIGNAL(mapLoadingFailed(QMapboxGL::MapLoadingFailure,QString))); - connect(m_mapObserver.get(), SIGNAL(copyrightsChanged(QString)), q, SIGNAL(copyrightsChanged(QString))); + connect(m_mapObserver.get(), &QMapboxGLMapObserver::mapChanged, q, &QMapboxGL::mapChanged); + connect(m_mapObserver.get(), &QMapboxGLMapObserver::mapLoadingFailed, q, &QMapboxGL::mapLoadingFailed); + connect(m_mapObserver.get(), &QMapboxGLMapObserver::copyrightsChanged, q, &QMapboxGL::copyrightsChanged); auto resourceOptions = resourceOptionsFromQMapboxGLSettings(settings); for (auto style : resourceOptions.tileServerOptions().defaultStyles()) { @@ -1778,7 +1778,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin } // Needs to be Queued to give time to discard redundant draw calls via the `renderQueued` flag. - connect(this, SIGNAL(needsRendering()), q, SIGNAL(needsRendering()), Qt::QueuedConnection); + connect(this, &QMapboxGLPrivate::needsRendering, q, &QMapboxGL::needsRendering, Qt::QueuedConnection); } QMapboxGLPrivate::~QMapboxGLPrivate() @@ -1826,7 +1826,7 @@ void QMapboxGLPrivate::createRenderer() m_localFontFamily ); - connect(m_mapRenderer.get(), SIGNAL(needsRendering()), this, SLOT(requestRendering())); + connect(m_mapRenderer.get(), &QMapboxGLMapRenderer::needsRendering, this, &QMapboxGLPrivate::requestRendering); m_mapRenderer->setObserver(m_rendererObserver); @@ -1886,7 +1886,11 @@ bool QMapboxGLPrivate::setProperty(const PropertySetter& setter, const QString& mbgl::optional result; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.typeId() == QMetaType::QString) { +#else if (value.type() == QVariant::String) { +#endif mbgl::JSDocument document; document.Parse<0>(value.toString().toStdString()); if (!document.HasParseError()) { diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp index 7c7f5ee15..6451045a4 100644 --- a/platform/qt/src/qmapboxgl_map_renderer.cpp +++ b/platform/qt/src/qmapboxgl_map_renderer.cpp @@ -43,7 +43,7 @@ QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio, QMapboxGLSettings:: mbgl::Scheduler::SetCurrent(scheduler); } - connect(scheduler, SIGNAL(needsProcessing()), this, SIGNAL(needsRendering())); + connect(scheduler, &QMapboxGLScheduler::needsProcessing, this, &QMapboxGLMapRenderer::needsRendering); } } diff --git a/platform/qt/src/qt_conversion.hpp b/platform/qt/src/qt_conversion.hpp index 397cf5cca..00a39c64b 100644 --- a/platform/qt/src/qt_conversion.hpp +++ b/platform/qt/src/qt_conversion.hpp @@ -23,7 +23,11 @@ public: } static bool isArray(const QVariant& value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::QVariantList)); +#else return value.canConvert(QVariant::List); +#endif } static std::size_t arrayLength(const QVariant& value) { @@ -35,8 +39,13 @@ public: } static bool isObject(const QVariant& value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::QVariantMap)) + || value.typeId() == QMetaType::QByteArray +#else return value.canConvert(QVariant::Map) || value.type() == QVariant::ByteArray +#endif || QString(value.typeName()) == QStringLiteral("QMapbox::Feature") || value.userType() == qMetaTypeId>() || value.userType() == qMetaTypeId>(); @@ -71,7 +80,11 @@ public: } static optional toBool(const QVariant& value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.typeId() == QMetaType::Bool) { +#else if (value.type() == QVariant::Bool) { +#endif return value.toBool(); } else { return {}; @@ -79,7 +92,11 @@ public: } static optional toNumber(const QVariant& value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) { +#else if (value.type() == QVariant::Int || value.type() == QVariant::Double) { +#endif return value.toFloat(); } else { return {}; @@ -87,7 +104,11 @@ public: } static optional toDouble(const QVariant& value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) { +#else if (value.type() == QVariant::Int || value.type() == QVariant::Double) { +#endif return value.toDouble(); } else { return {}; @@ -95,6 +116,15 @@ public: } static optional toString(const QVariant& value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.typeId() == QMetaType::QString) { + return value.toString().toStdString(); + } else if (value.typeId() == QMetaType::QColor) { + return convertColor(value.value()); + } else { + return {}; + } +#else if (value.type() == QVariant::String) { return value.toString().toStdString(); } else if (value.type() == QVariant::Color) { @@ -102,9 +132,25 @@ public: } else { return {}; } +#endif } static optional toValue(const QVariant& value) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (value.typeId() == QMetaType::Bool) { + return { value.toBool() }; + } else if (value.typeId() == QMetaType::QString) { + return { value.toString().toStdString() }; + } else if (value.typeId() == QMetaType::QColor) { + return { convertColor(value.value()) }; + } else if (value.typeId() == QMetaType::Int) { + return { int64_t(value.toInt()) }; + } else if (QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::Double))) { + return { value.toDouble() }; + } else { + return {}; + } +#else if (value.type() == QVariant::Bool) { return { value.toBool() }; } else if (value.type() == QVariant::String) { @@ -118,6 +164,7 @@ public: } else { return {}; } +#endif } static optional toGeoJSON(const QVariant& value, Error& error) { @@ -127,7 +174,11 @@ public: return featureCollectionToGeoJSON(value.value>()); } else if (value.userType() == qMetaTypeId>()) { return featureCollectionToGeoJSON(value.value>()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + } else if (value.typeId() != QMetaType::QByteArray) { +#else } else if (value.type() != QVariant::ByteArray) { +#endif error = { "JSON data must be in QByteArray" }; return {}; } diff --git a/platform/qt/src/qt_geojson.cpp b/platform/qt/src/qt_geojson.cpp index 3b775685b..27f867dec 100644 --- a/platform/qt/src/qt_geojson.cpp +++ b/platform/qt/src/qt_geojson.cpp @@ -80,7 +80,11 @@ mbgl::Value asMapboxGLPropertyValue(const QVariant &value) { return mbglMap; }; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + switch (value.typeId()) { +#else switch (value.type()) { +#endif case QMetaType::UnknownType: return mbgl::NullValue {}; case QMetaType::Bool: @@ -104,7 +108,11 @@ mbgl::Value asMapboxGLPropertyValue(const QVariant &value) { } mbgl::FeatureIdentifier asMapboxGLFeatureIdentifier(const QVariant &id) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + switch (id.typeId()) { +#else switch (id.type()) { +#endif case QMetaType::UnknownType: return {}; case QMetaType::ULongLong: diff --git a/platform/qt/src/run_loop.cpp b/platform/qt/src/run_loop.cpp index c25243c8e..7394fc7bc 100644 --- a/platform/qt/src/run_loop.cpp +++ b/platform/qt/src/run_loop.cpp @@ -94,13 +94,13 @@ void RunLoop::addWatch(int fd, Event event, std::function&& cb if (event == Event::Read || event == Event::ReadWrite) { auto notifier = std::make_unique(fd, QSocketNotifier::Read); - QObject::connect(notifier.get(), SIGNAL(activated(int)), impl.get(), SLOT(onReadEvent(int))); + QObject::connect(notifier.get(), &QSocketNotifier::activated, impl.get(), &RunLoop::Impl::onReadEvent); impl->readPoll[fd] = WatchPair(std::move(notifier), std::move(cb)); } if (event == Event::Write || event == Event::ReadWrite) { auto notifier = std::make_unique(fd, QSocketNotifier::Write); - QObject::connect(notifier.get(), SIGNAL(activated(int)), impl.get(), SLOT(onWriteEvent(int))); + QObject::connect(notifier.get(), &QSocketNotifier::activated, impl.get(), &RunLoop::Impl::onWriteEvent); impl->writePoll[fd] = WatchPair(std::move(notifier), std::move(cb)); } } diff --git a/platform/qt/src/sqlite3.cpp b/platform/qt/src/sqlite3.cpp index 2c1ccc879..f5194f7b2 100644 --- a/platform/qt/src/sqlite3.cpp +++ b/platform/qt/src/sqlite3.cpp @@ -240,7 +240,11 @@ template <> void Query::bind(int offset, std::nullptr_t) { assert(stmt.impl); // Field numbering starts at 0. +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + stmt.impl->query.bindValue(offset - 1, QVariant(), QSql::In); +#else stmt.impl->query.bindValue(offset - 1, QVariant(QVariant::Invalid), QSql::In); +#endif checkQueryError(stmt.impl->query); } diff --git a/platform/qt/src/timer.cpp b/platform/qt/src/timer.cpp index 4ae3631e5..05876c24c 100644 --- a/platform/qt/src/timer.cpp +++ b/platform/qt/src/timer.cpp @@ -10,7 +10,7 @@ namespace util { Timer::Impl::Impl() { timer.setTimerType(Qt::PreciseTimer); - connect(&timer, SIGNAL(timeout()), this, SLOT(timerFired())); + connect(&timer, &QTimer::timeout, this, &Timer::Impl::timerFired); } void Timer::Impl::start(uint64_t timeout, uint64_t repeat_, std::function&& cb) { diff --git a/platform/qt/test/qmapboxgl.test.cpp b/platform/qt/test/qmapboxgl.test.cpp index 604bdde89..22ed9779d 100644 --- a/platform/qt/test/qmapboxgl.test.cpp +++ b/platform/qt/test/qmapboxgl.test.cpp @@ -11,10 +11,8 @@ #include QMapboxGLTest::QMapboxGLTest() : size(512, 512), fbo((assert(widget.context()->isValid()), widget.makeCurrent(), size)), map(nullptr, settings, size) { - connect(&map, SIGNAL(mapChanged(QMapboxGL::MapChange)), - this, SLOT(onMapChanged(QMapboxGL::MapChange))); - connect(&map, SIGNAL(needsRendering()), - this, SLOT(onNeedsRendering())); + connect(&map, &QMapboxGL::mapChanged, this, &QMapboxGLTest::onMapChanged); + connect(&map, &QMapboxGL::needsRendering, this, &QMapboxGLTest::onNeedsRendering); map.resize(fbo.size()); map.setFramebufferObject(fbo.handle(), fbo.size()); map.setCoordinateZoom(QMapbox::Coordinate(60.170448, 24.942046), 14);