1 | // Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com> |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "propertychangehandler_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | namespace Qt3DCore { |
9 | |
10 | /* |
11 | \internal |
12 | \class Qt3DCore::PropertyChangeHandlerBase |
13 | \inmodule Qt3DCore |
14 | \brief Base class for the property change handler. |
15 | */ |
16 | PropertyChangeHandlerBase::PropertyChangeHandlerBase(QObject *parent) : |
17 | QObject(parent) |
18 | { |
19 | } |
20 | |
21 | void PropertyChangeHandlerBase::connectToPropertyChange(const QObject *object, int propertyIndex) |
22 | { |
23 | const QMetaObject *metaObject = object->metaObject(); |
24 | const QMetaProperty property = metaObject->property(index: propertyIndex); |
25 | if (!property.hasNotifySignal()) |
26 | return; |
27 | |
28 | static const int memberOffset = staticMetaObject.methodCount(); |
29 | QMetaObject::Connection connection = QMetaObject::connect(sender: object, signal_index: property.notifySignalIndex(), |
30 | receiver: this, method_index: memberOffset + propertyIndex, |
31 | type: Qt::DirectConnection, types: 0); |
32 | Q_ASSERT(connection); |
33 | Q_UNUSED(connection); |
34 | } |
35 | |
36 | void PropertyChangeHandlerBase::disconnectFromPropertyChange(const QObject *object, int propertyIndex) |
37 | { |
38 | const QMetaObject *metaObject = object->metaObject(); |
39 | const QMetaProperty property = metaObject->property(index: propertyIndex); |
40 | if (!property.hasNotifySignal()) |
41 | return; |
42 | |
43 | static const int memberOffset = staticMetaObject.methodCount(); |
44 | QMetaObject::disconnect(sender: object, signal_index: property.notifySignalIndex(), receiver: this, method_index: memberOffset + propertyIndex); |
45 | } |
46 | |
47 | |
48 | } |
49 | |
50 | QT_END_NAMESPACE |
51 | |
52 | #include "moc_propertychangehandler_p.cpp" |
53 | |