diff options
author | Volker Krause <volker.krause@kdab.com> | 2016-02-08 15:34:14 +0100 |
---|---|---|
committer | Volker Krause <volker.krause@kdab.com> | 2016-02-08 14:37:16 +0000 |
commit | bb287528b4316bb7d892bdfa92404107c137c071 (patch) | |
tree | 1f7c4e977deff693050f892278a5892a02e3af4e /src/core/nodes/propertychangehandler_p.h | |
parent | d2ed5c887250fafb376a13bbea6c5f865815869a (diff) |
Introduce a non-template base class for PropertyChangeHandler.
While my main intention was to get PropertyChangeHandler a meta object so
its instances can be identified in GammaRay, this turned out to also help
with minimizing template code, as half the methods don't actually depend
on the template argument.
Change-Id: I302a305db8ed0c864338d90c9795bf54155c790b
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/core/nodes/propertychangehandler_p.h')
-rw-r--r-- | src/core/nodes/propertychangehandler_p.h | 57 |
1 files changed, 19 insertions, 38 deletions
diff --git a/src/core/nodes/propertychangehandler_p.h b/src/core/nodes/propertychangehandler_p.h index dd4a66c89..afb9866ff 100644 --- a/src/core/nodes/propertychangehandler_p.h +++ b/src/core/nodes/propertychangehandler_p.h @@ -51,6 +51,8 @@ // We mean it. // +#include <Qt3DCore/qt3dcore_global.h> + #include <QObject> #include <QHash> #include <QVector> @@ -61,17 +63,11 @@ QT_BEGIN_NAMESPACE namespace Qt3DCore { -/** - * The property change handler is similar to QSignalSpy, but geared towards the usecase of Qt3D. - * - * It allows connecting to any number of property change signals of the receiver object and forwards - * the signal invocations to the Receiver by calling its propertyChanged function. - */ -template<class Receiver> -class PropertyChangeHandler : public QObject +class QT3DCORESHARED_EXPORT PropertyChangeHandlerBase : public QObject { + Q_OBJECT public: - PropertyChangeHandler(Receiver *receiver, QObject *parent = Q_NULLPTR); + PropertyChangeHandlerBase(QObject *parent = Q_NULLPTR); /** * Connect to the change signal of @p property in @p object. @@ -82,6 +78,19 @@ public: * Disconnect from the change signal of @p property in @p object. */ void disconnectFromPropertyChange(const QObject *object, int propertyIndex); +}; + +/** + * The property change handler is similar to QSignalSpy, but geared towards the usecase of Qt3D. + * + * It allows connecting to any number of property change signals of the receiver object and forwards + * the signal invocations to the Receiver by calling its propertyChanged function. + */ +template<class Receiver> +class PropertyChangeHandler : public PropertyChangeHandlerBase +{ +public: + PropertyChangeHandler(Receiver *receiver, QObject *parent = Q_NULLPTR); /** * @internal @@ -97,40 +106,12 @@ private: template<class Receiver> PropertyChangeHandler<Receiver>::PropertyChangeHandler(Receiver *receiver, QObject *parent) - : QObject(parent) + : PropertyChangeHandlerBase(parent) , m_receiver(receiver) { } template<class Receiver> -void PropertyChangeHandler<Receiver>::connectToPropertyChange(const QObject *object, int propertyIndex) -{ - const QMetaObject *metaObject = object->metaObject(); - const QMetaProperty property = metaObject->property(propertyIndex); - if (!property.hasNotifySignal()) - return; - - static const int memberOffset = QObject::staticMetaObject.methodCount(); - QMetaObject::Connection connection = QMetaObject::connect(object, property.notifySignalIndex(), - this, memberOffset + propertyIndex, - Qt::DirectConnection, 0); - Q_ASSERT(connection); - Q_UNUSED(connection); -} - -template<class Receiver> -void PropertyChangeHandler<Receiver>::disconnectFromPropertyChange(const QObject *object, int propertyIndex) -{ - const QMetaObject *metaObject = object->metaObject(); - const QMetaProperty property = metaObject->property(propertyIndex); - if (!property.hasNotifySignal()) - return; - - static const int memberOffset = QObject::staticMetaObject.methodCount(); - QMetaObject::disconnect(object, property.notifySignalIndex(), this, memberOffset + propertyIndex); -} - -template<class Receiver> int PropertyChangeHandler<Receiver>::qt_metacall(QMetaObject::Call call, int methodId, void **args) { methodId = QObject::qt_metacall(call, methodId, args); |