Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtSignalReceiver.h
3206 views
#ifndef _PYTHONQTSIGNALRECEIVER_H1#define _PYTHONQTSIGNALRECEIVER_H23/*4*5* Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.6*7* This library is free software; you can redistribute it and/or8* modify it under the terms of the GNU Lesser General Public9* License as published by the Free Software Foundation; either10* version 2.1 of the License, or (at your option) any later version.11*12* This library is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU15* Lesser General Public License for more details.16*17* Further, this software is distributed without any warranty that it is18* free of the rightful claim of any third person regarding infringement19* or the like. Any license provided herein, whether implied or20* otherwise, applies only to this software file. Patent licenses, if21* any, provided herein do not apply to combinations of this program with22* other software, or any other product whatsoever.23*24* You should have received a copy of the GNU Lesser General Public25* License along with this library; if not, write to the Free Software26* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA27*28* Contact information: MeVis Research GmbH, Universitaetsallee 29,29* 28359 Bremen, Germany or:30*31* http://www.mevis.de32*33*/3435//----------------------------------------------------------------------------------36/*!37// \file PythonQtSignalReceiver.h38// \author Florian Link39// \author Last changed by $Author: florian $40// \date 2006-0541*/42//----------------------------------------------------------------------------------4344#include "PythonQt.h"45class PythonQtMethodInfo;4647//! stores information about a signal target48/*! copy construction and assignment works fine with the C++ standard behaviour and are thus not implemented49*/50class PythonQtSignalTarget {51public:52PythonQtSignalTarget() {53_signalId = -1;54_methodInfo = NULL;55_slotId = -1;56}5758PythonQtSignalTarget(int signalId,const PythonQtMethodInfo* methodInfo, int slotId, PyObject* callable)59{60_signalId = signalId;61_slotId = slotId;62_methodInfo = methodInfo;63_callable = callable;64};6566~PythonQtSignalTarget() {67};6869//! get the id of the original signal70int signalId() const { return _signalId; }7172//! get the id that was assigned to this simulated slot73int slotId() const { return _slotId; }7475//! get the signals parameter info76const PythonQtMethodInfo* methodInfo() const { return _methodInfo; }7778//! call the python callable with the given arguments (as defined in methodInfo)79void call(void **arguments) const;8081//! check if it is the same signal target82bool isSame(int signalId, PyObject* callable) const { return callable==_callable && signalId==_signalId; }8384private:85int _signalId;86int _slotId;87const PythonQtMethodInfo* _methodInfo;88PythonQtObjectPtr _callable;89};9091//! base class for signal receivers92/*!93*/94class PythonQtSignalReceiverBase : public QObject {95Q_OBJECT96public:97PythonQtSignalReceiverBase(QObject* obj):QObject(obj) {};98};99100//! receives all signals for one QObject101/*! we derive from our base but do not declare the QObject macro because we want to reimplement qt_metacall only.102*/103class PythonQtSignalReceiver : public PythonQtSignalReceiverBase {104105public:106PythonQtSignalReceiver(QObject* obj);107~PythonQtSignalReceiver();108109//! add a signal handler110bool addSignalHandler(const char* signal, PyObject* callable);111112//! remove a signal handler113bool removeSignalHandler(const char* signal, PyObject* callable);114115//! remove all signal handlers116void removeSignalHandlers();117118//! we implement this method to simulate a number of slots that match the ids in _targets119virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments);120121private:122//! get the index of the signal123int getSignalIndex(const char* signal);124125QObject* _obj;126int _slotCount;127// linear list may get slow on multiple targets, but I think typically we have many objects and just a few signals128QList<PythonQtSignalTarget> _targets;129};130131132#endif133134135