Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtSignalReceiver.h
3206 views
1
#ifndef _PYTHONQTSIGNALRECEIVER_H
2
#define _PYTHONQTSIGNALRECEIVER_H
3
4
/*
5
*
6
* Copyright (C) 2006 MeVis Research GmbH 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 Research GmbH, Universitaetsallee 29,
30
* 28359 Bremen, Germany or:
31
*
32
* http://www.mevis.de
33
*
34
*/
35
36
//----------------------------------------------------------------------------------
37
/*!
38
// \file PythonQtSignalReceiver.h
39
// \author Florian Link
40
// \author Last changed by $Author: florian $
41
// \date 2006-05
42
*/
43
//----------------------------------------------------------------------------------
44
45
#include "PythonQt.h"
46
class PythonQtMethodInfo;
47
48
//! stores information about a signal target
49
/*! copy construction and assignment works fine with the C++ standard behaviour and are thus not implemented
50
*/
51
class PythonQtSignalTarget {
52
public:
53
PythonQtSignalTarget() {
54
_signalId = -1;
55
_methodInfo = NULL;
56
_slotId = -1;
57
}
58
59
PythonQtSignalTarget(int signalId,const PythonQtMethodInfo* methodInfo, int slotId, PyObject* callable)
60
{
61
_signalId = signalId;
62
_slotId = slotId;
63
_methodInfo = methodInfo;
64
_callable = callable;
65
};
66
67
~PythonQtSignalTarget() {
68
};
69
70
//! get the id of the original signal
71
int signalId() const { return _signalId; }
72
73
//! get the id that was assigned to this simulated slot
74
int slotId() const { return _slotId; }
75
76
//! get the signals parameter info
77
const PythonQtMethodInfo* methodInfo() const { return _methodInfo; }
78
79
//! call the python callable with the given arguments (as defined in methodInfo)
80
void call(void **arguments) const;
81
82
//! check if it is the same signal target
83
bool isSame(int signalId, PyObject* callable) const { return callable==_callable && signalId==_signalId; }
84
85
private:
86
int _signalId;
87
int _slotId;
88
const PythonQtMethodInfo* _methodInfo;
89
PythonQtObjectPtr _callable;
90
};
91
92
//! base class for signal receivers
93
/*!
94
*/
95
class PythonQtSignalReceiverBase : public QObject {
96
Q_OBJECT
97
public:
98
PythonQtSignalReceiverBase(QObject* obj):QObject(obj) {};
99
};
100
101
//! receives all signals for one QObject
102
/*! we derive from our base but do not declare the QObject macro because we want to reimplement qt_metacall only.
103
*/
104
class PythonQtSignalReceiver : public PythonQtSignalReceiverBase {
105
106
public:
107
PythonQtSignalReceiver(QObject* obj);
108
~PythonQtSignalReceiver();
109
110
//! add a signal handler
111
bool addSignalHandler(const char* signal, PyObject* callable);
112
113
//! remove a signal handler
114
bool removeSignalHandler(const char* signal, PyObject* callable);
115
116
//! remove all signal handlers
117
void removeSignalHandlers();
118
119
//! we implement this method to simulate a number of slots that match the ids in _targets
120
virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments);
121
122
private:
123
//! get the index of the signal
124
int getSignalIndex(const char* signal);
125
126
QObject* _obj;
127
int _slotCount;
128
// linear list may get slow on multiple targets, but I think typically we have many objects and just a few signals
129
QList<PythonQtSignalTarget> _targets;
130
};
131
132
133
#endif
134
135