|
PythonQt
|
00001 #ifndef _PYTHONQTSIGNALRECEIVER_H 00002 #define _PYTHONQTSIGNALRECEIVER_H 00003 00004 /* 00005 * 00006 * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * Further, this software is distributed without any warranty that it is 00019 * free of the rightful claim of any third person regarding infringement 00020 * or the like. Any license provided herein, whether implied or 00021 * otherwise, applies only to this software file. Patent licenses, if 00022 * any, provided herein do not apply to combinations of this program with 00023 * other software, or any other product whatsoever. 00024 * 00025 * You should have received a copy of the GNU Lesser General Public 00026 * License along with this library; if not, write to the Free Software 00027 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 * 00029 * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29, 00030 * 28359 Bremen, Germany or: 00031 * 00032 * http://www.mevis.de 00033 * 00034 */ 00035 00036 //---------------------------------------------------------------------------------- 00043 //---------------------------------------------------------------------------------- 00044 00045 #include "PythonQtPythonInclude.h" 00046 00047 #include "PythonQtSystem.h" 00048 #include "PythonQtObjectPtr.h" 00049 00050 class PythonQtMethodInfo; 00051 class PythonQtClassInfo; 00052 00054 00056 class PYTHONQT_EXPORT PythonQtSignalTarget { 00057 public: 00058 PythonQtSignalTarget() { 00059 _signalId = -1; 00060 _methodInfo = NULL; 00061 _slotId = -1; 00062 } 00063 00064 PythonQtSignalTarget(int signalId,const PythonQtMethodInfo* methodInfo, int slotId, PyObject* callable) 00065 { 00066 _signalId = signalId; 00067 _slotId = slotId; 00068 _methodInfo = methodInfo; 00069 _callable = callable; 00070 }; 00071 00072 ~PythonQtSignalTarget() { 00073 }; 00074 00076 int signalId() const { return _signalId; } 00077 00079 int slotId() const { return _slotId; } 00080 00082 const PythonQtMethodInfo* methodInfo() const { return _methodInfo; } 00083 00085 void call(void **arguments) const; 00086 00088 bool isSame(int signalId, PyObject* callable) const; 00089 00091 static PyObject* call(PyObject* callable, const PythonQtMethodInfo* methodInfo, void **arguments, bool skipFirstArgumentOfMethodInfo = false); 00092 00093 private: 00094 int _signalId; 00095 int _slotId; 00096 const PythonQtMethodInfo* _methodInfo; 00097 PythonQtObjectPtr _callable; 00098 }; 00099 00101 00103 class PythonQtSignalReceiverBase : public QObject { 00104 Q_OBJECT 00105 public: 00106 PythonQtSignalReceiverBase(QObject* obj):QObject(obj) {}; 00107 }; 00108 00110 00112 class PythonQtSignalReceiver : public PythonQtSignalReceiverBase { 00113 00114 public: 00115 PythonQtSignalReceiver(QObject* obj); 00116 ~PythonQtSignalReceiver(); 00117 00119 bool addSignalHandler(const char* signal, PyObject* callable); 00120 00122 bool removeSignalHandler(const char* signal, PyObject* callable = NULL); 00123 00125 virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments); 00126 00127 private: 00129 int getSignalIndex(const char* signal); 00130 00131 QObject* _obj; 00132 PythonQtClassInfo* _objClassInfo; 00133 int _slotCount; 00134 int _destroyedSignalCount; 00135 // linear list may get slow on multiple targets, but I think typically we have many objects and just a few signals 00136 QList<PythonQtSignalTarget> _targets; 00137 00138 static int _destroyedSignal1Id; 00139 static int _destroyedSignal2Id; 00140 }; 00141 00142 00143 #endif 00144
1.7.4