[qt] Move to modern signal/slot connection mechanism (#138)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
|
||||
#include <QOpenGLWidget>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QScopedPointer>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class QKeyEvent;
|
||||
class QMouseEvent;
|
||||
class QWheelEvent;
|
||||
@@ -43,7 +44,7 @@ private:
|
||||
QPointF m_lastPos;
|
||||
|
||||
QMapboxGLSettings m_settings;
|
||||
QScopedPointer<QMapboxGL> m_map;
|
||||
std::unique_ptr<QMapboxGL> m_map{};
|
||||
|
||||
QPropertyAnimation *m_bearingAnimation;
|
||||
QPropertyAnimation *m_zoomAnimation;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <QStringList>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class QMapboxGLPrivate;
|
||||
|
||||
@@ -245,8 +246,8 @@ public:
|
||||
void removeImage(const QString &name);
|
||||
|
||||
void addCustomLayer(const QString &id,
|
||||
QScopedPointer<QMapbox::CustomLayerHostInterface>& host,
|
||||
const QString& before = QString());
|
||||
std::unique_ptr<QMapbox::CustomLayerHostInterface> host,
|
||||
const QString &before = QString());
|
||||
void addLayer(const QVariantMap ¶ms, const QString& before = QString());
|
||||
bool layerExists(const QString &id);
|
||||
void removeLayer(const QString &id);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace util {
|
||||
AsyncTask::Impl::Impl(std::function<void()>&& 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() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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<QMapbox::CustomLayerHostInterface>& host,
|
||||
const QString& before)
|
||||
std::unique_ptr<QMapbox::CustomLayerHostInterface> host,
|
||||
const QString &before)
|
||||
{
|
||||
class HostWrapper : public mbgl::style::CustomLayerHost {
|
||||
public:
|
||||
QScopedPointer<QMapbox::CustomLayerHostInterface> ptr;
|
||||
HostWrapper(QScopedPointer<QMapbox::CustomLayerHostInterface>& p)
|
||||
: ptr(p.take()) {
|
||||
std::unique_ptr<QMapbox::CustomLayerHostInterface> ptr{};
|
||||
HostWrapper(std::unique_ptr<QMapbox::CustomLayerHostInterface> 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<mbgl::style::CustomLayer>(
|
||||
id.toStdString(),
|
||||
std::make_unique<HostWrapper>(host)),
|
||||
std::make_unique<HostWrapper>(std::move(host))),
|
||||
before.isEmpty() ? mbgl::optional<std::string>() : mbgl::optional<std::string>(before.toStdString()));
|
||||
}
|
||||
|
||||
@@ -1743,9 +1743,9 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
|
||||
|
||||
qRegisterMetaType<QMapboxGL::MapChange>("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<conversion::Error> 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()) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<QVector<QMapbox::Feature>>()
|
||||
|| value.userType() == qMetaTypeId<QList<QMapbox::Feature>>();
|
||||
@@ -71,7 +80,11 @@ public:
|
||||
}
|
||||
|
||||
static optional<bool> 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<float> 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<double> 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<std::string> 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<QColor>());
|
||||
} 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<Value> 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<QColor>()) };
|
||||
} 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<GeoJSON> toGeoJSON(const QVariant& value, Error& error) {
|
||||
@@ -127,7 +174,11 @@ public:
|
||||
return featureCollectionToGeoJSON(value.value<QVector<QMapbox::Feature>>());
|
||||
} else if (value.userType() == qMetaTypeId<QList<QMapbox::Feature>>()) {
|
||||
return featureCollectionToGeoJSON(value.value<QList<QMapbox::Feature>>());
|
||||
#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 {};
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -94,13 +94,13 @@ void RunLoop::addWatch(int fd, Event event, std::function<void(int, Event)>&& cb
|
||||
|
||||
if (event == Event::Read || event == Event::ReadWrite) {
|
||||
auto notifier = std::make_unique<QSocketNotifier>(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<QSocketNotifier>(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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<void ()>&& cb) {
|
||||
|
||||
@@ -11,10 +11,8 @@
|
||||
#include <mbgl/test/util.hpp>
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user