PythonQt
PythonQtSignalReceiver.h
Go to the documentation of this file.
1#ifndef _PYTHONQTSIGNALRECEIVER_H
2#define _PYTHONQTSIGNALRECEIVER_H
3
4/*
5 *
6 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * Further, this software is distributed without any warranty that it is
19 * free of the rightful claim of any third person regarding infringement
20 * or the like. Any license provided herein, whether implied or
21 * otherwise, applies only to this software file. Patent licenses, if
22 * any, provided herein do not apply to combinations of this program with
23 * other software, or any other product whatsoever.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
30 * 28359 Bremen, Germany or:
31 *
32 * http://www.mevis.de
33 *
34 */
35
36//----------------------------------------------------------------------------------
43//----------------------------------------------------------------------------------
44
46
47#include "PythonQtSystem.h"
48#include "PythonQtObjectPtr.h"
49
52
54
57{
58public:
60 {
61 _signalId = -1;
62 _methodInfo = nullptr;
63 _slotId = -1;
64 }
65
66 PythonQtSignalTarget(int signalId, const PythonQtMethodInfo* methodInfo, int slotId, PyObject* callable)
67 {
68 _signalId = signalId;
69 _slotId = slotId;
70 _methodInfo = methodInfo;
71 _callable = callable;
72 };
73
75
77 int signalId() const { return _signalId; }
78
80 int slotId() const { return _slotId; }
81
83 const PythonQtMethodInfo* methodInfo() const { return _methodInfo; }
84
86 void call(void** arguments) const;
87
89 bool isSame(int signalId, PyObject* callable) const;
90
92 static PyObject* call(PyObject* callable, const PythonQtMethodInfo* methodInfo, void** arguments,
94
95private:
96 int _signalId;
97 int _slotId;
98 const PythonQtMethodInfo* _methodInfo;
99 PythonQtSafeObjectPtr _callable;
100};
101
103
105class PythonQtSignalReceiverBase : public QObject
106{
108public:
110 : QObject(obj) {};
111};
112
114
117{
118
119public:
122
125
127 bool removeSignalHandler(const char* signal, PyObject* callable = nullptr);
128
130 int qt_metacall(QMetaObject::Call c, int id, void** arguments) override;
131
132private:
134 int getSignalIndex(const char* signal);
135
136 QObject* _obj;
137 PythonQtClassInfo* _objClassInfo;
138 int _slotCount;
139 int _destroyedSignalCount;
140 // linear list may get slow on multiple targets, but I think typically we have many objects and just a few signals
142
143 static int _destroyedSignal1Id;
144 static int _destroyedSignal2Id;
145};
146
147#endif
PyObject * PythonQtConvertPairToPython(const void *inPair, int metaTypeId)
struct _object PyObject
#define PYTHONQT_EXPORT
a class that stores all required information about a Qt object (and an optional associated C++ class ...
stores information about a specific signal/slot/method
a smart pointer that stores a PyObject pointer and that handles reference counting automatically
base class for signal receivers
receives all signals for one QObject
bool addSignalHandler(const char *signal, PyObject *callable)
add a signal handler
~PythonQtSignalReceiver() override
int qt_metacall(QMetaObject::Call c, int id, void **arguments) override
we implement this method to simulate a number of slots that match the ids in _targets
bool removeSignalHandler(const char *signal, PyObject *callable=nullptr)
remove a signal handler for given callable (or all callables on that signal if callable is NULL)
PythonQtSignalReceiver(QObject *obj)
stores information about a signal target
bool isSame(int signalId, PyObject *callable) const
check if it is the same signal target
int slotId() const
get the id that was assigned to this simulated slot
static PyObject * call(PyObject *callable, const PythonQtMethodInfo *methodInfo, void **arguments, bool skipFirstArgumentOfMethodInfo=false)
call the given callable with arguments described by PythonQtMethodInfo, returns a new reference as re...
void call(void **arguments) const
call the python callable with the given arguments (as defined in methodInfo)
const PythonQtMethodInfo * methodInfo() const
get the signals parameter info
int signalId() const
get the id of the original signal
PythonQtSignalTarget(int signalId, const PythonQtMethodInfo *methodInfo, int slotId, PyObject *callable)