2
* This file is part of the PySide project.
4
* Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
6
* Contact: PySide team <contact@pyside.org>
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.
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.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
#include "pysidemetafunction.h"
27
#include <QMetaMethod>
33
struct PySideMetaFunctionPrivate
40
static void functionFree(void*);
41
static PyObject* functionCall(PyObject*, PyObject*, PyObject*);
43
PyTypeObject PySideMetaFunctionType = {
46
/*tp_name*/ "PySide.MetaFunction",
47
/*tp_basicsize*/ sizeof(PySideMetaFunction),
59
/*tp_call*/ functionCall,
64
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
65
/*tp_doc*/ "MetaFunction",
69
/*tp_weaklistoffset*/ 0,
82
/*tp_new*/ PyType_GenericNew,
83
/*tp_free*/ functionFree,
93
void functionFree(void *self)
95
PySideMetaFunction* function = reinterpret_cast<PySideMetaFunction*>(self);
99
PyObject* functionCall(PyObject* self, PyObject* args, PyObject* kw)
101
static Shiboken::TypeResolver* typeResolver = Shiboken::TypeResolver::get("QVariant");
102
Q_ASSERT(typeResolver);
104
QGenericArgument gArgs[10];
106
PySideMetaFunction* function = reinterpret_cast<PySideMetaFunction*>(self);
107
QMetaMethod method = function->d->method;
108
int argsGiven = method.parameterTypes().size();
110
for (int i = 0; i < argsGiven; ++i) {
111
Shiboken::AutoDecRef pyArg(PySequence_GetItem(args, i));
112
gArgs[i] = Q_ARG(QVariant, vArgs[i]);
113
void* v[1] = { &vArgs[i] };
114
typeResolver->toCpp(pyArg, v);
118
QGenericReturnArgument returnValue = Q_RETURN_ARG(QVariant, retVariant);
119
method.invoke(function->d->qobject, returnValue, gArgs[0], gArgs[1], gArgs[2], gArgs[3], gArgs[4], gArgs[5], gArgs[6], gArgs[7], gArgs[8], gArgs[9]);
122
if (retVariant.isValid())
123
return typeResolver->toPython(&retVariant);
130
namespace PySide { namespace MetaFunction {
132
void init(PyObject* module)
134
if (PyType_Ready(&PySideMetaFunctionType) < 0)
137
PyModule_AddObject(module, "MetaFunction", ((PyObject*)&PySideMetaFunctionType));
140
PySideMetaFunction* newObject(QObject* source, int methodIndex)
142
if (methodIndex >= source->metaObject()->methodCount())
145
QMetaMethod method = source->metaObject()->method(methodIndex);
146
if ((method.methodType() == QMetaMethod::Slot) ||
147
(method.methodType() == QMetaMethod::Method)) {
148
PySideMetaFunction* function = PyObject_New(PySideMetaFunction, &PySideMetaFunctionType);
149
function->d = new PySideMetaFunctionPrivate();
150
function->d->qobject = source;
151
function->d->method = method;
157
} //namespace MetaFunction