From 011198e588774ecf86f692e54aad9c30dcab5a67 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 26 Jul 2019 19:35:22 +0300 Subject: QDeclarativeGeoMapParameter: replace the last use of QSignalMapper in the module The code here is a bit tricky, as it relies on dynamic property inspection, and therefore can't use the statically-typed Qt5 connection syntax to simply connect to a lambda to captures 'i' by value. But QSignalMapper is not just deprecated, its use here is also overkill. Unlike your normal signal mapper, the code doesn't map many source objects to different ints, there is actually one QSignalMapper object _per sender_. But this use-case doesn't need all the sender() inspection that QSignalMapper does under the hood. It just needs a QObject with a map() slot that emits mapped(i), where 'i' is a member variable. Implement that. Change-Id: Ib363144c8ab7997cb0a34c8c9c1a0c348fd38d57 Reviewed-by: Simon Hausmann --- .../qdeclarativegeomapparameter.cpp | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/location/declarativemaps/qdeclarativegeomapparameter.cpp b/src/location/declarativemaps/qdeclarativegeomapparameter.cpp index c1361d5d..2408e1c7 100644 --- a/src/location/declarativemaps/qdeclarativegeomapparameter.cpp +++ b/src/location/declarativemaps/qdeclarativegeomapparameter.cpp @@ -39,10 +39,28 @@ #include #include #include -#include +#include QT_BEGIN_NAMESPACE +namespace { +class SignalMapper : public QObject +{ + Q_OBJECT + + int i; +public: + explicit SignalMapper(int i, QObject *parent = nullptr) + : QObject(parent), i(i) {} + +public Q_SLOTS: + void map() { emit mapped(i); } + +Q_SIGNALS: + void mapped(int); +}; +} // unnamed namespace + /*! \qmltype MapParameter \inqmlmodule QtLocation @@ -114,8 +132,7 @@ void QDeclarativeGeoMapParameter::componentComplete() return; } - QSignalMapper *mapper = new QSignalMapper(this); - mapper->setMapping(this, i); + SignalMapper *mapper = new SignalMapper(i, this); const QByteArray signalName = '2' + property.notifySignal().methodSignature(); // TODO: explain why '2' QObject::connect(this, signalName, mapper, SLOT(map())); @@ -131,3 +148,5 @@ void QDeclarativeGeoMapParameter::onPropertyUpdated(int index) } QT_END_NAMESPACE + +#include "qdeclarativegeomapparameter.moc" -- cgit v1.2.3