Path: blob/devel/ElmerGUI/PythonQt/src/PythonQtMethodInfo.h
3206 views
#ifndef _PYTHONQTMETHODINFO_H1#define _PYTHONQTMETHODINFO_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 PythonQtMethodInfo.h38// \author Florian Link39// \author Last changed by $Author: florian $40// \date 2006-0541*/42//----------------------------------------------------------------------------------4344#include <QByteArray>45#include <QHash>46#include <QList>47#include <QMetaMethod>4849//! stores information about a specific signal/slot/method50class PythonQtMethodInfo51{52public:53//! this is a funny type union of QMetaType and QVariant, only god knows54//! why QMetaType do not support identical types in Qt4,55//! especial the support of Long, Short, Char etc. is missing in QVariant56//! and QMetaType does not know anything about most variant types and e.g. LongLong57enum ParameterType {58Unknown = -1,59Variant = -260};6162//! stores the QVariant id (if available) and the name of the type63struct ParameterInfo {64int typeId; // a mixture from QMetaType and ParameterType65QByteArray name;66bool isPointer;67bool isConst;68};6970PythonQtMethodInfo() {};71~PythonQtMethodInfo() {};72PythonQtMethodInfo(const QMetaMethod& meta);73PythonQtMethodInfo(const PythonQtMethodInfo& other) {74_parameters = other._parameters;75}7677//! returns the method info of the signature, uses a cache internally to speed up78//! multiple requests for the same method79static const PythonQtMethodInfo* getCachedMethodInfo(const QMetaMethod& method);8081//! cleanup the cache82static void cleanupCachedMethodInfos();8384//! returns the number of parameters (without the return value)85int parameterCount() const { return _parameters.size(); };8687//! returns the id for the given type (using an internal dictionary)88static int nameToType(const char* name);8990//! get the parameter infos91const QList<ParameterInfo>& parameters() const { return _parameters; }9293protected:94static void fillParameterInfo(ParameterInfo& type, const QByteArray& name);9596static QHash<QByteArray, int> _parameterTypeDict;9798//! stores the cached signatures of methods to speedup mapping from Qt to Python types99static QHash<QByteArray, PythonQtMethodInfo*> _cachedSignatures;100101QList<ParameterInfo> _parameters;102};103104//! stores information about a slot, including a next pointer to overloaded slots105class PythonQtSlotInfo : public PythonQtMethodInfo106{107public:108enum Type {109MemberSlot, InstanceDecorator, ClassDecorator110};111112PythonQtSlotInfo(const PythonQtSlotInfo& info):PythonQtMethodInfo() {113_meta = info._meta;114_parameters = info._parameters;115_slotIndex = info._slotIndex;116_next = NULL;117_decorator = info._decorator;118_type = info._type;119}120121PythonQtSlotInfo(const QMetaMethod& meta, int slotIndex, QObject* decorator = NULL, Type type = MemberSlot ):PythonQtMethodInfo()122{123const PythonQtMethodInfo* info = getCachedMethodInfo(meta);124_meta = meta;125_parameters = info->parameters();126_slotIndex = slotIndex;127_next = NULL;128_decorator = decorator;129_type = type;130}131132133public:134const QMetaMethod* metaMethod() const { return &_meta; }135136//! get the index of the slot (needed for qt_metacall)137int slotIndex() const { return _slotIndex; }138139//! get next overloaded slot (which has the same name)140PythonQtSlotInfo* nextInfo() const { return _next; }141142//! set the next overloaded slot143void setNextInfo(PythonQtSlotInfo* next) { _next = next; }144145//! returns if the slot is a decorator slot146bool isInstanceDecorator() { return _decorator!=NULL && _type == InstanceDecorator; }147148//! returns if the slot is a constructor slot149bool isClassDecorator() { return _decorator!=NULL && _type == ClassDecorator; }150151QObject* decorator() { return _decorator; }152153//! get the full signature including return type154QString fullSignature(bool skipFirstArg);155156//! get the short slot name157QByteArray slotName();158159private:160int _slotIndex;161PythonQtSlotInfo* _next;162QObject* _decorator;163Type _type;164QMetaMethod _meta;165};166167168#endif169170171