diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-11-17 10:11:17 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-11-17 13:20:07 +0000 |
commit | 603c904cf5ca598ec9b627bbff0c7d2d4ccb7fe2 (patch) | |
tree | c4a203d40d0e655b611c963f2a186b6c3e0b0f51 /sources/pyside6/libpyside/globalreceiverv2.h | |
parent | 70f219d10e15cd8fe125b6169c640598d89223c0 (diff) |
libpyside: Refactor GlobalReceiverV2Map
Use a QHash of object/method PyObject instead of a
QByteArray representing the sum of hash values of both
as a string.
The problem with using hash functions here is that 2 keys
might be identical due to the hashing.
Rename the hash() methods to key().
Task-number: PYSIDE-1422
Change-Id: Ie1344d8bd85a073ef5f6e2cb461bd2f514265a9f
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/libpyside/globalreceiverv2.h')
-rw-r--r-- | sources/pyside6/libpyside/globalreceiverv2.h | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/sources/pyside6/libpyside/globalreceiverv2.h b/sources/pyside6/libpyside/globalreceiverv2.h index 433f587a9..da01e6d33 100644 --- a/sources/pyside6/libpyside/globalreceiverv2.h +++ b/sources/pyside6/libpyside/globalreceiverv2.h @@ -55,8 +55,26 @@ namespace PySide class DynamicSlotDataV2; class GlobalReceiverV2; -typedef QMap<QByteArray, GlobalReceiverV2 *> GlobalReceiverV2Map; -typedef QSharedPointer<GlobalReceiverV2Map> SharedMap; +struct GlobalReceiverKey +{ + const PyObject *object; + const PyObject *method; +}; + +inline bool operator==(const GlobalReceiverKey &k1, const GlobalReceiverKey &k2) +{ + return k1.object == k2.object && k1.method == k2.method; +} + +inline bool operator!=(const GlobalReceiverKey &k1, const GlobalReceiverKey &k2) +{ + return k1.object != k2.object || k1.method != k2.method; +} + +size_t qHash(const GlobalReceiverKey &k, size_t seed = 0); + +using GlobalReceiverV2Map = QHash<GlobalReceiverKey, GlobalReceiverV2 *>; +using GlobalReceiverV2MapPtr = QSharedPointer<GlobalReceiverV2Map>; /** * A class used to make the link between the C++ Signal/Slot and Python callback @@ -72,7 +90,7 @@ public: * @param callback A Python callable object (can be a method or not) * @param ma A SharedPointer used on Signal manager that contains all instaces of GlobalReceiver **/ - GlobalReceiverV2(PyObject *callback, SharedMap map); + GlobalReceiverV2(PyObject *callback, GlobalReceiverV2MapPtr map); /** * Destructor @@ -125,7 +143,7 @@ public: * * @return a string with a unique id based on GlobalReceiver contents **/ - QByteArray hash() const; + GlobalReceiverKey key() const; /** * Use to retrieve the unique hash of the PyObject based on GlobalReceiver rules @@ -133,7 +151,7 @@ public: * @param callback The Python callable object used to calculate the id * @return a string with a unique id based on GlobalReceiver contents **/ - static QByteArray hash(PyObject *callback); + static GlobalReceiverKey key(PyObject *callback); const MetaObjectBuilder &metaObjectBuilder() const { return m_metaObject; } MetaObjectBuilder &metaObjectBuilder() { return m_metaObject; } @@ -142,7 +160,7 @@ private: MetaObjectBuilder m_metaObject; DynamicSlotDataV2 *m_data; QList<const QObject *> m_refs; - SharedMap m_sharedMap; + GlobalReceiverV2MapPtr m_sharedMap; }; } |