itom
Loading...
Searching...
No Matches
pythonQtSignalMapper.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#ifndef PYTHONQTSIGNALMAPPER_H
24#define PYTHONQTSIGNALMAPPER_H
25
26#ifndef Q_MOC_RUN
27 #define PY_ARRAY_UNIQUE_SYMBOL itom_ARRAY_API
28
29 #include "python/pythonWrapper.h"
30#endif
31
32#include "../global.h"
33
34#include <qvariant.h>
35#include <qobject.h>
36#include <qelapsedtimer.h>
37#include <qhash.h>
38
39namespace ito
40{
41
43{
44public:
45
48
50 PythonQtSignalTarget(IntList &argTypeList, int slotId, int signalId, PyObject* callable, const char *signal, int minRepeatInterval);
51
54
57
60
62 inline int signalId() const { return m_signalId; }
63
65 inline int slotId() const { return m_slotId; }
66
67 // call the python callable with the given arguments (docs see source file)
68 void call(void ** arguments);
69
71 inline IntList argTypeList() const { return m_argTypeList; };
72
74 bool isSame(int signalId, PyObject* callable) const;
75
76private:
79 IntList m_argTypeList;
80
82 {
84
87
90
92 Callable_CFunction
93 };
94
95 /* If the target is a bounded method, m_boundedMethod is true and
96 this member holds a Python weak reference to the method, that acts as slot.
97 m_boundedInstance is != NULL then.
98
99 If the target is an unbounded function, m_boundedMethod is false and
100 this member holds a new reference to the function itself (that acts as slot).
101 m_boundedInstance is NULL then. */
102 PyObject *m_function;
105 QString m_signalName;
106 QElapsedTimer m_elapsedTimer;
107
108 /*
109 if > 0, every call of a certain slot by a certain signal with restart m_elapsedTimer. If the same signal-slot-connection is
110 called another time, while less than m_minRepeatInterval ms have expired, this new invoke will be ignored.
111
112 This can be used to prevent that very fast signal emissions will overflow the call queue for the connected callable python method.
113 */
114 int m_minRepeatInterval;
115};
116
133class PythonQtSignalMapperBase : public QObject
134{
135 Q_OBJECT
136public:
138};
139
162{
163
164public:
167
168 bool addSignalHandler(QObject *obj, const char* signal, int sigId, PyObject* callable, IntList &argTypeList, int minRepeatInterval);
169 bool removeSignalHandler(QObject *obj, int sigId, PyObject* callable);
171
173 virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments);
174
175private:
176 typedef QMap<int, PythonQtSignalTarget> TargetMap;
177
179 /* This list is generated as map, that maps the slotId of the PythonQtSignalTarget
180 to the target itself (for a faster indexing).
181 */
183
185 int m_slotCount;
186
187};
188
189} //end namespace ito
190
191#endif
base class for PythonQtSignalMapper
Definition pythonQtSignalMapper.h:134
This class provides the possibility to redirect any signal emitted in an user-defined GUI to differen...
Definition pythonQtSignalMapper.h:162
virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments)
overwrites qt_metacall from PythonQtSignalMapperBase.
Definition pythonQtSignalMapper.cpp:199
void removeSignalHandlers()
disconnects all signal-slot connections managed by this instance of PythonQtSignalMapper
Definition pythonQtSignalMapper.cpp:178
PythonQtSignalMapper()
constructor
Definition pythonQtSignalMapper.cpp:69
QMap< int, PythonQtSignalTarget > TargetMap
list with all virtual slot targets that are the destination for any registered signal-slot-connection
Definition pythonQtSignalMapper.h:176
bool removeSignalHandler(QObject *obj, int sigId, PyObject *callable)
disconnects a certain connection
Definition pythonQtSignalMapper.cpp:146
bool addSignalHandler(QObject *obj, const char *signal, int sigId, PyObject *callable, IntList &argTypeList, int minRepeatInterval)
creates signal-slot connection between the signal of any widget and a python method as slot
Definition pythonQtSignalMapper.cpp:107
TargetMap m_targets
index of the last virtual slot managed by this instance (auto-incremented)
Definition pythonQtSignalMapper.h:182
~PythonQtSignalMapper()
destructor
Definition pythonQtSignalMapper.cpp:80
Definition pythonQtSignalMapper.h:43
int signalId() const
gets the id of the original signal
Definition pythonQtSignalMapper.h:62
CallableType m_callableType
type of the python callable (see CallableType)
Definition pythonQtSignalMapper.h:104
~PythonQtSignalTarget()
destructor
Definition pythonQtSignalMapper.cpp:330
int slotId() const
gets the id that was assigned to this simulated slot
Definition pythonQtSignalMapper.h:65
PyObject * m_boundedInstance
weak reference to the python-class instance of the function (if the function is bounded) or NULL if t...
Definition pythonQtSignalMapper.h:103
int m_signalId
index of the connected signal
Definition pythonQtSignalMapper.h:78
IntList argTypeList() const
returns list of type-numbers of arguments
Definition pythonQtSignalMapper.h:71
QString m_signalName
signature of the signal (mainly used for debugging reasons)
Definition pythonQtSignalMapper.h:105
PythonQtSignalTarget()
empty constructor
Definition pythonQtSignalMapper.cpp:219
int m_slotId
index of this slot
Definition pythonQtSignalMapper.h:77
void call(void **arguments)
invokes the python method or function
Definition pythonQtSignalMapper.cpp:382
bool isSame(int signalId, PyObject *callable) const
Compares this signal target with given values.
Definition pythonQtSignalMapper.cpp:346
CallableType
Definition pythonQtSignalMapper.h:82
@ Callable_Invalid
the callable is invalid
Definition pythonQtSignalMapper.h:83
@ Callable_Function
function, written in C, stored in m_function. m_boundedInstance is NULL, since the potential self obj...
Definition pythonQtSignalMapper.h:89
@ Callable_Method
unbounded python method, the function is stored in m_function, m_boundedInstance is NULL
Definition pythonQtSignalMapper.h:86
PythonQtSignalTarget & operator=(const PythonQtSignalTarget &rhs)
assignment operator
Definition pythonQtSignalMapper.cpp:306
QElapsedTimer m_elapsedTimer
see m_minRepeatInterval
Definition pythonQtSignalMapper.h:106
IntList m_argTypeList
type id's from QMetaType::type("..."), describing the arguments of the function-call
Definition pythonQtSignalMapper.h:79
Definition apiFunctionsGraph.cpp:40