diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-26 19:35:22 +0300 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-08-01 11:03:11 +0000 |
commit | 011198e588774ecf86f692e54aad9c30dcab5a67 (patch) | |
tree | 947a041e3bff556ee0a0b33fa22b49cb917398e4 | |
parent | f8694e1f3430b7851fc90e26c6d778a86219379a (diff) | |
download | qtlocation-011198e588774ecf86f692e54aad9c30dcab5a67.tar.gz |
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 <simon.hausmann@qt.io>
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeomapparameter.cpp | 25 |
1 files 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 <QByteArray> #include <QMetaObject> #include <QMetaProperty> -#include <QSignalMapper> +#include <QObject> 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" |