summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-11-01 18:42:47 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-12-09 19:25:36 -0300
commit0f38019c02fe0459230c6ca583a7b2aba12e6212 (patch)
treef0432bbeb3ca9e60473c7a4d785c2d396065ab5a
parentc93001f792db0de9eede4ef14ba365ea21470f78 (diff)
downloadpyside-0f38019c02fe0459230c6ca583a7b2aba12e6212.tar.gz
pyside-0f38019c02fe0459230c6ca583a7b2aba12e6212.tar.xz
pyside-0f38019c02fe0459230c6ca583a7b2aba12e6212.zip
Replaced TypeResolver by SbkConverter and SpecificConverter.
Also updated QtGui's WId conversion to Python 3.
-rw-r--r--PySide/QtCore/typesystem_core.xml98
-rw-r--r--PySide/QtDeclarative/pysideqmlregistertype.cpp4
-rw-r--r--PySide/QtDeclarative/typesystem_declarative.xml3
-rw-r--r--PySide/QtGui/typesystem_gui_win.xml20
-rw-r--r--PySide/QtSql/typesystem_sql.xml3
-rw-r--r--libpyside/globalreceiver.cpp7
-rw-r--r--libpyside/globalreceiverv2.cpp2
-rw-r--r--libpyside/pyside.cpp10
-rw-r--r--libpyside/pysidemetafunction.cpp27
-rw-r--r--libpyside/pysideproperty.cpp10
-rw-r--r--libpyside/signalmanager.cpp46
-rw-r--r--tests/QtCore/qobject_property_test.py9
-rw-r--r--tests/pysidetest/testview.cpp2
-rw-r--r--tests/pysidetest/typesystem_pysidetest.xml38
14 files changed, 175 insertions, 104 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index f41688c..5ecbf79 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -170,7 +170,7 @@
<!-- FIXME This is a workaround to include some headers needed by some includes (nothing to do with QBool) -->
<include file-name="QtConcurrentFilter" location="global"/>
</primitive-type>
- <primitive-type name="QString">
+ <primitive-type name="QString" target-lang-api-name="PyUnicode">
<include file-name="QString" location="global"/>
<conversion-rule file="qstring_conversions.h">
<native-to-target>
@@ -248,22 +248,28 @@
<native-to-target>
if (!%in.isValid())
Py_RETURN_NONE;
+
if (qstrcmp(%in.typeName(), "QVariantList") == 0) {
QList&lt;QVariant&gt; var = %in.value&lt;QVariantList&gt;();
return %CONVERTTOPYTHON[QList&lt;QVariant&gt;](var);
}
+
if (qstrcmp(%in.typeName(), "QStringList") == 0) {
QStringList var = %in.value&lt;QStringList&gt;();
return %CONVERTTOPYTHON[QList&lt;QString&gt;](var);
}
+
if (qstrcmp(%in.typeName(), "QVariantMap") == 0) {
QMap&lt;QString, QVariant&gt; var = %in.value&lt;QVariantMap&gt;();
return %CONVERTTOPYTHON[QMap&lt;QString, QVariant&gt;](var);
}
- Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(%in.typeName());
- if (tr)
- return tr->toPython(const_cast&lt;void*&gt;(%in.data()));
- // TODO-CONVERTERS: SET ERROR
+
+ Shiboken::Conversions::SpecificConverter converter(cppInRef.typeName());
+ if (converter) {
+ void* ptr = cppInRef.data();
+ return converter.toPython(ptr);
+ }
+ PyErr_Format(PyExc_RuntimeError, "Can't find converter for '%s'.", %in.typeName());
return 0;
</native-to-target>
<target-to-native>
@@ -273,11 +279,11 @@
<add-conversion type="Py_None">
%out = %OUTTYPE();
</add-conversion>
- <add-conversion type="PyString" check="%CHECKTYPE[QString](%in)">
+ <add-conversion type="QString" check="Shiboken::String::check(%in)">
QString in = %CONVERTTOCPP[QString](%in);
%out = %OUTTYPE(in);
</add-conversion>
- <add-conversion type="QByteArray" check="%CHECKTYPE[QByteArray](%in)">
+ <add-conversion type="QByteArray">
QByteArray in = %CONVERTTOCPP[QByteArray](%in);
%out = %OUTTYPE(in);
</add-conversion>
@@ -301,19 +307,16 @@
// a class supported by QVariant?
int typeCode;
const char* typeName = QVariant_resolveMetaType(%in->ob_type, &amp;typeCode);
- if (typeCode &amp;&amp; typeName) {
- Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(typeName);
- QVariant var(typeCode, (void*)0);
- void* args[] = { var.data() };
- tr->toCpp(%in, args);
- %out = var;
- }
+ if (!typeCode || !typeName)
+ return;
+ QVariant var(typeCode, (void*)0);
+ Shiboken::Conversions::SpecificConverter converter(typeName);
+ converter.toCpp(pyIn, var.data());
+ %out = var;
</add-conversion>
<add-conversion type="PyDict">
QVariant ret = QVariant_convertToVariantMap(%in);
- if (ret.isValid())
- %out = ret;
- %out = QVariant::fromValue&lt;PySide::PyObjectWrapper&gt;(%in);
+ %out = ret.isValid() ? ret : QVariant::fromValue&lt;PySide::PyObjectWrapper&gt;(%in);
</add-conversion>
<add-conversion type="PySequence">
%out = QVariant_convertToVariantList(%in);
@@ -372,15 +375,13 @@
listTypeName += '>';
typeId = QMetaType::type(listTypeName);
if (typeId &gt; 0) {
- Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(listTypeName);
- if (!tr) {
- qWarning() &lt;&lt; "TypeResolver for :" &lt;&lt; listTypeName &lt;&lt; "not registered.";
- } else {
+ Shiboken::Conversions::SpecificConverter converter(listTypeName);
+ if (converter) {
QVariant var(typeId, (void*)0);
- void* args[] = { var.data(), 0 };
- tr->toCpp(list, args);
+ converter.toCpp(list, &amp;var);
return var;
}
+ qWarning() &lt;&lt; "Type converter for :" &lt;&lt; listTypeName &lt;&lt; "not registered.";
}
}
return QVariant();
@@ -417,25 +418,22 @@
}
static QVariant QVariant_convertToVariantList(PyObject* list)
{
- bool allString = QVariant_isStringList(list);
- if (allString) {
+ if (QVariant_isStringList(list)) {
QList&lt;QString &gt; lst = %CONVERTTOCPP[QList&lt;QString&gt;](list);
return QVariant(QStringList(lst));
- } else {
- QVariant valueList = QVariant_convertToValueList(list);
- if (valueList.isValid())
- return valueList;
- QList&lt;QVariant&gt; lst;
- Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList"));
- Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object());
- for (int i = 0; i &lt; size; ++i) {
- PyObject* pyItem = PySequence_Fast_GET_ITEM(fast.object(), i);
- QVariant item = %CONVERTTOCPP[QVariant](pyItem);
- lst.append(item);
- }
- return QVariant(lst);
}
- Q_ASSERT(false);
+ QVariant valueList = QVariant_convertToValueList(list);
+ if (valueList.isValid())
+ return valueList;
+ QList&lt;QVariant&gt; lst;
+ Shiboken::AutoDecRef fast(PySequence_Fast(list, "Failed to convert QVariantList"));
+ Py_ssize_t size = PySequence_Fast_GET_SIZE(fast.object());
+ for (int i = 0; i &lt; size; ++i) {
+ PyObject* pyItem = PySequence_Fast_GET_ITEM(fast.object(), i);
+ QVariant item = %CONVERTTOCPP[QVariant](pyItem);
+ lst.append(item);
+ }
+ return QVariant(lst);
}
</inject-code>
@@ -444,12 +442,10 @@
<native-to-target>
const char* typeName = QVariant::typeToName(%in);
PyObject* %out;
- if (!typeName) {
- %out = Py_None;
- } else {
- Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(typeName);
- %out = tr ? (PyObject*)tr->pythonType() : Py_None;
- }
+ PyTypeObject* pyType = 0;
+ if (typeName)
+ pyType = Shiboken::Conversions::getPythonTypeObject(typeName);
+ %out = pyType ? ((PyObject*)pyType) : Py_None;
Py_INCREF(%out);
return %out;
</native-to-target>
@@ -492,7 +488,10 @@
</conversion-rule>
</primitive-type>
- <primitive-type name="QVariantMap" />
+ <primitive-type name="QVariantMap" target-lang-api-name="PyDict"/>
+ <inject-code class="target" position="end">
+ Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QTCORE_QMAP_QSTRING_QVARIANT_IDX], "QVariantMap");
+ </inject-code>
<inject-code class="native" position="beginning">
static bool QVariantType_isStringList(PyObject* list)
@@ -920,9 +919,10 @@
<!--signal/slot-->
<inject-code class="target" position="end">
- Shiboken::TypeResolver::createValueTypeResolver&lt;QString>("unicode");
- Shiboken::TypeResolver::createValueTypeResolver&lt;QString>("str");
- Shiboken::TypeResolver::createValueTypeResolver&lt;QVariantList>("QVariantList");
+ Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QSTRING_IDX], "unicode");
+ Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QSTRING_IDX], "str");
+ Shiboken::Conversions::registerConverterName(SbkPySide_QtCoreTypeConverters[SBK_QTCORE_QLIST_QVARIANT_IDX], "QVariantList");
+
PySide::init(module);
Py_AtExit(QtCoreModuleExit);
</inject-code>
diff --git a/PySide/QtDeclarative/pysideqmlregistertype.cpp b/PySide/QtDeclarative/pysideqmlregistertype.cpp
index 6c59516..30844c6 100644
--- a/PySide/QtDeclarative/pysideqmlregistertype.cpp
+++ b/PySide/QtDeclarative/pysideqmlregistertype.cpp
@@ -93,8 +93,8 @@ int PySide::qmlRegisterType(PyObject* pyObj, const char* uri, int versionMajor,
{
using namespace Shiboken;
- static PyTypeObject* qobjectType = TypeResolver::get("QObject*")->pythonType();
- static PyTypeObject* qdeclarativeType = TypeResolver::get("QDeclarativeItem*")->pythonType();
+ static PyTypeObject* qobjectType = Shiboken::Conversions::getPythonTypeObject("QObject*");
+ static PyTypeObject* qdeclarativeType = Shiboken::Conversions::getPythonTypeObject("QDeclarativeItem*");
assert(qobjectType);
static int nextType = 0;
diff --git a/PySide/QtDeclarative/typesystem_declarative.xml b/PySide/QtDeclarative/typesystem_declarative.xml
index 91c2e48..1bc18ba 100644
--- a/PySide/QtDeclarative/typesystem_declarative.xml
+++ b/PySide/QtDeclarative/typesystem_declarative.xml
@@ -60,8 +60,7 @@
</enum-type>
<inject-code class="target" position="end">
- Shiboken::TypeResolver::createValueTypeResolver&lt; QList&lt;QObject*&gt; &gt;("QList&lt;QObject*&gt;");
- PySide::initQmlSupport(module);
+ PySide::initQmlSupport(module);
</inject-code>
<object-type name="QDeclarativeExtensionInterface"/>
diff --git a/PySide/QtGui/typesystem_gui_win.xml b/PySide/QtGui/typesystem_gui_win.xml
index a0cfe84..28b48e6 100644
--- a/PySide/QtGui/typesystem_gui_win.xml
+++ b/PySide/QtGui/typesystem_gui_win.xml
@@ -23,14 +23,32 @@
<primitive-type name="WId" target-lang-api-name="PyObject">
<conversion-rule file="glue/wid_conversions.h">
<native-to-target>
+ #ifdef IS_PY3K
+ return PyCapsule_New(%in, 0, 0);
+ #else
return PyCObject_FromVoidPtr(%in, 0);
+ #endif
</native-to-target>
<target-to-native>
- <add-conversion type="PyCObject">
+ <add-conversion type="checkPyCapsuleOrPyCObject">
+ #ifdef IS_PY3K
+ %out = (%OUTTYPE)PyCapsule_GetPointer(%in, 0);
+ #else
%out = (%OUTTYPE)PyCObject_AsVoidPtr(%in);
+ #endif
</add-conversion>
</target-to-native>
</conversion-rule>
</primitive-type>
+ <inject-code class="native" position="beginning">
+ static bool checkPyCapsuleOrPyCObject(PyObject* pyObj)
+ {
+ #ifdef IS_PY3K
+ return PyCapsule_CheckExact(pyObj);
+ #else
+ return PyCObject_Check(pyObj);
+ #endif
+ }
+ </inject-code>
<enum-type name="QPixmap::HBitmapFormat" />
</typesystem>
diff --git a/PySide/QtSql/typesystem_sql.xml b/PySide/QtSql/typesystem_sql.xml
index d6007ef..2efe429 100644
--- a/PySide/QtSql/typesystem_sql.xml
+++ b/PySide/QtSql/typesystem_sql.xml
@@ -81,9 +81,6 @@
<include file-name="QSqlField" location="global"/>
</extra-includes>
<modify-function signature="append(QSqlField)" access="non-final"/>
- <inject-code position="end">
- Shiboken::TypeResolver::createReferenceTypeResolver&lt; ::QSqlRecord >("QSqlRecord&amp;");
- </inject-code>
</value-type>
<value-type name="QSqlError">
diff --git a/libpyside/globalreceiver.cpp b/libpyside/globalreceiver.cpp
index 05d5e4d..ace1692 100644
--- a/libpyside/globalreceiver.cpp
+++ b/libpyside/globalreceiver.cpp
@@ -29,6 +29,7 @@
#include <QEvent>
#include <QLinkedList>
#include <autodecref.h>
+#include <sbkconverter.h>
#include <gilstate.h>
#include "typeresolver.h"
@@ -293,8 +294,9 @@ int GlobalReceiver::qt_metacall(QMetaObject::Call call, int id, void** args)
QList<QByteArray> paramTypes = slot.parameterTypes();
Shiboken::AutoDecRef preparedArgs(PyTuple_New(paramTypes.count()));
for (int i = 0, max = paramTypes.count(); i < max; ++i) {
- PyObject* arg = Shiboken::TypeResolver::get(paramTypes[i].constData())->toPython(args[i+1]); // Do not increment the reference
- PyTuple_SET_ITEM(preparedArgs.object(), i, arg);
+ const QByteArray& paramType = paramTypes[i];
+ Shiboken::Conversions::SpecificConverter converter(paramType.constData());
+ PyTuple_SET_ITEM(preparedArgs.object(), i, converter.toPython(args[i+1]));
}
retval = data->call(preparedArgs);
}
@@ -306,4 +308,3 @@ int GlobalReceiver::qt_metacall(QMetaObject::Call call, int id, void** args)
return -1;
}
-
diff --git a/libpyside/globalreceiverv2.cpp b/libpyside/globalreceiverv2.cpp
index cfcf477..65a37ee 100644
--- a/libpyside/globalreceiverv2.cpp
+++ b/libpyside/globalreceiverv2.cpp
@@ -111,7 +111,7 @@ QByteArray DynamicSlotDataV2::hash(PyObject* callback)
{
Shiboken::GilState gil;
if (PyMethod_Check(callback))
- return QByteArray::number((qlonglong)PyObject_Hash(PyMethod_GET_FUNCTION(callback)))
+ return QByteArray::number((qlonglong)PyObject_Hash(PyMethod_GET_FUNCTION(callback)))
+ QByteArray::number((qlonglong)PyObject_Hash(PyMethod_GET_SELF(callback)));
else
return QByteArray::number((qlonglong)PyObject_Hash(callback));
diff --git a/libpyside/pyside.cpp b/libpyside/pyside.cpp
index e2736f1..0d96f95 100644
--- a/libpyside/pyside.cpp
+++ b/libpyside/pyside.cpp
@@ -35,6 +35,7 @@
#include <basewrapper.h>
#include <conversions.h>
+#include <sbkconverter.h>
#include <typeresolver.h>
#include <bindingmanager.h>
#include <algorithm>
@@ -141,7 +142,7 @@ void destroyQCoreApplication()
Shiboken::BindingManager& bm = Shiboken::BindingManager::instance();
SbkObject* pyQApp = bm.retrieveWrapper(app);
- PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType();
+ PyTypeObject* pyQObjectType = Shiboken::Conversions::getPythonTypeObject("QObject*");
assert(pyQObjectType);
void* data[2] = {pyQApp, pyQObjectType};
@@ -174,7 +175,10 @@ void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base, const s
//initialize staticQMetaObject property
void* metaObjectPtr = &userData->mo;
- Shiboken::AutoDecRef pyMetaObject(Shiboken::TypeResolver::get("QMetaObject*")->toPython(&metaObjectPtr));
+ static SbkConverter* converter = Shiboken::Conversions::getConverter("QMetaObject");
+ if (!converter)
+ return;
+ Shiboken::AutoDecRef pyMetaObject(Shiboken::Conversions::pointerToPython(converter, metaObjectPtr));
PyObject_SetAttrString(reinterpret_cast<PyObject*>(type), "staticMetaObject", pyMetaObject);
}
@@ -185,7 +189,7 @@ void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base)
void initQObjectSubType(SbkObjectType* type, PyObject* args, PyObject* kwds)
{
- PyTypeObject* qObjType = Shiboken::TypeResolver::get("QObject*")->pythonType();
+ PyTypeObject* qObjType = Shiboken::Conversions::getPythonTypeObject("QObject*");
QByteArray className(Shiboken::String::toCString(PyTuple_GET_ITEM(args, 0)));
PyObject* bases = PyTuple_GET_ITEM(args, 1);
diff --git a/libpyside/pysidemetafunction.cpp b/libpyside/pysidemetafunction.cpp
index 271ab43..17fe839 100644
--- a/libpyside/pysidemetafunction.cpp
+++ b/libpyside/pysidemetafunction.cpp
@@ -169,10 +169,10 @@ bool call(QObject* self, int methodIndex, PyObject* args, PyObject** retVal)
continue;
}
- Shiboken::TypeResolver* typeResolver = Shiboken::TypeResolver::get(typeName);
- if (typeResolver) {
- if (Shiboken::TypeResolver::getType(typeName) == Shiboken::TypeResolver::ValueType) {
- int typeId = QMetaType::type(typeName);
+ Shiboken::Conversions::SpecificConverter converter(typeName);
+ if (converter) {
+ int typeId = QMetaType::type(typeName);
+ if (!Shiboken::Conversions::pythonTypeIsObjectType(converter)) {
if (!typeId) {
PyErr_Format(PyExc_TypeError, "Value types used on meta functions (including signals) need to be "
"registered on meta type: %s", typeName.data());
@@ -181,8 +181,15 @@ bool call(QObject* self, int methodIndex, PyObject* args, PyObject** retVal)
methValues[i] = QVariant(typeId, (void*) 0);
}
methArgs[i] = methValues[i].data();
- if (i != 0) // Don't do this for return type
- typeResolver->toCpp(PySequence_Fast_GET_ITEM(sequence.object(), i - 1), &methArgs[i]);
+ if (i == 0) // Don't do this for return type
+ continue;
+ if (typeId == QVariant::String) {
+ QString tmp;
+ converter.toCpp(PySequence_Fast_GET_ITEM(sequence.object(), i - 1), &tmp);
+ methValues[i] = tmp;
+ } else {
+ converter.toCpp(PySequence_Fast_GET_ITEM(sequence.object(), i - 1), methArgs[i]);
+ }
} else {
PyErr_Format(PyExc_TypeError, "Unknown type used to call meta function (that may be a signal): %s", argTypes[i].constData());
break;
@@ -195,10 +202,10 @@ bool call(QObject* self, int methodIndex, PyObject* args, PyObject** retVal)
if (retVal) {
if (methArgs[0]) {
- static Shiboken::TypeResolver* qVariantTypeResolver = Shiboken::TypeResolver::get("QVariant");
- Q_ASSERT(qVariantTypeResolver);
-
- *retVal = qVariantTypeResolver->toPython(&methValues[0]);
+ static SbkConverter* qVariantTypeConverter = Shiboken::Conversions::getConverter("QVariant");
+ Q_ASSERT(qVariantTypeConverter);
+ *retVal = Shiboken::Conversions::copyToPython(qVariantTypeConverter, &methValues[0]);
+ SbkDbg() << (*retVal);
} else {
*retVal = Py_None;
Py_INCREF(*retVal);
diff --git a/libpyside/pysideproperty.cpp b/libpyside/pysideproperty.cpp
index 4d253e8..e5ae5d5 100644
--- a/libpyside/pysideproperty.cpp
+++ b/libpyside/pysideproperty.cpp
@@ -104,8 +104,10 @@ PyTypeObject PySidePropertyType = {
static void qpropertyMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::Call call, void** args)
{
- Shiboken::TypeResolver* typeResolver = Shiboken::TypeResolver::get(pp->d->typeName);
- Q_ASSERT(typeResolver);
+ Shiboken::Conversions::SpecificConverter converter(pp->d->typeName);
+ Q_ASSERT(converter);
+
+ QByteArray type(pp->d->typeName);
switch(call) {
case QMetaObject::ReadProperty:
@@ -113,7 +115,7 @@ static void qpropertyMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::C
Shiboken::GilState gil;
PyObject* value = PySide::Property::getValue(pp, self);
if (value) {
- typeResolver->toCpp(value, &args[0]);
+ converter.toCpp(value, args[0]);
Py_DECREF(value);
} else if (PyErr_Occurred()) {
PyErr_Print(); // Clear any errors but print them to stderr
@@ -124,7 +126,7 @@ static void qpropertyMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::C
case QMetaObject::WriteProperty:
{
Shiboken::GilState gil;
- Shiboken::AutoDecRef value(typeResolver->toPython(args[0]));
+ Shiboken::AutoDecRef value(converter.toPython(args[0]));
PySide::Property::setValue(pp, self, value);
break;
}
diff --git a/libpyside/signalmanager.cpp b/libpyside/signalmanager.cpp
index 54fce07..4bcfae5 100644
--- a/libpyside/signalmanager.cpp
+++ b/libpyside/signalmanager.cpp
@@ -38,6 +38,7 @@
#include <algorithm>
#include <typeresolver.h>
#include <basewrapper.h>
+#include <sbkconverter.h>
#include <conversions.h>
#if QSLOT_CODE != 1 || QSIGNAL_CODE != 2
@@ -225,6 +226,22 @@ static void clearSignalManager()
PySide::SignalManager::instance().clear();
}
+static void PyObject_PythonToCpp_PyObject_PTR(PyObject* pyIn, void* cppOut)
+{
+ *((PyObject**)cppOut) = pyIn;
+}
+static PythonToCppFunc is_PyObject_PythonToCpp_PyObject_PTR_Convertible(PyObject* pyIn)
+{
+ return PyObject_PythonToCpp_PyObject_PTR;
+}
+static PyObject* PyObject_PTR_CppToPython_PyObject(const void* cppIn)
+{
+ PyObject* pyOut = (PyObject*)cppIn;
+ if (pyOut)
+ Py_INCREF(pyOut);
+ return pyOut;
+}
+
SignalManager::SignalManager() : m_d(new SignalManagerPrivate)
{
// Register Qt primitive typedefs used on signals.
@@ -234,9 +251,14 @@ SignalManager::SignalManager() : m_d(new SignalManagerPrivate)
qRegisterMetaType<PyObjectWrapper>(PYTHON_TYPE);
qRegisterMetaTypeStreamOperators<PyObjectWrapper>(PYTHON_TYPE);
- TypeResolver::createValueTypeResolver<PyObjectWrapper>(PYTHON_TYPE);
- TypeResolver::createValueTypeResolver<PyObjectWrapper>("object");
- TypeResolver::createValueTypeResolver<PyObjectWrapper>("PySide::PyObjectWrapper");
+ SbkConverter* converter = Shiboken::Conversions::createConverter(&PyBaseObject_Type, 0);
+ Shiboken::Conversions::setCppPointerToPythonFunction(converter, PyObject_PTR_CppToPython_PyObject);
+ Shiboken::Conversions::setPythonToCppPointerFunctions(converter, PyObject_PythonToCpp_PyObject_PTR, is_PyObject_PythonToCpp_PyObject_PTR_Convertible);
+ Shiboken::Conversions::registerConverterName(converter, PYTHON_TYPE);
+ Shiboken::Conversions::registerConverterName(converter, "object");
+ Shiboken::Conversions::registerConverterName(converter, "PyObjectWrapper");
+ Shiboken::Conversions::registerConverterName(converter, "PySide::PyObjectWrapper");
+
PySide::registerCleanupFunction(clearSignalManager);
if (!metaObjectAttr)
@@ -436,11 +458,12 @@ int SignalManager::callPythonMetaMethod(const QMetaMethod& method, void** args,
if (!retval.isNull() && retval != Py_None && !PyErr_Occurred()) {
const char* returnType = method.typeName();
if (returnType && std::strcmp("", returnType)) {
- Shiboken::TypeResolver* typeResolver = Shiboken::TypeResolver::get(returnType);
- if (typeResolver)
- typeResolver->toCpp(retval, &args[0]);
+ Shiboken::Conversions::SpecificConverter converter(returnType);
+ if (converter)
+ converter.toCpp(retval, args[0]);
else
- PyErr_Format(PyExc_RuntimeError, "Can't fidn type resolver \"%s\" to call Python meta method.", returnType);
+ PyErr_Format(PyExc_RuntimeError, "Can't find converter for '%s' to call Python meta method.", returnType);
+
}
}
}
@@ -555,13 +578,10 @@ static PyObject* parseArguments(const QList<QByteArray>& paramTypes, void** args
for (int i = 0, max = argsSize; i < max; ++i) {
void* data = args[i+1];
const char* dataType = paramTypes[i].constData();
-
- Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(dataType);
- if (tr) {
- PyObject* arg = tr->toPython(data);
- PyTuple_SET_ITEM(preparedArgs, i, arg);
+ Shiboken::Conversions::SpecificConverter converter(dataType);
+ if (converter) {
+ PyTuple_SET_ITEM(preparedArgs, i, converter.toPython(data));
} else {
-
PyErr_Format(PyExc_TypeError, "Can't call meta function because I have no idea how to handle %s", dataType);
Py_DECREF(preparedArgs);
return 0;
diff --git a/tests/QtCore/qobject_property_test.py b/tests/QtCore/qobject_property_test.py
index 4889591..17589cb 100644
--- a/tests/QtCore/qobject_property_test.py
+++ b/tests/QtCore/qobject_property_test.py
@@ -3,7 +3,7 @@
import unittest
-from PySide.QtCore import *
+from PySide.QtCore import QObject, Property, Signal
class MyObjectWithNotifyProperty(QObject):
def __init__(self, parent=None):
@@ -31,7 +31,12 @@ class PropertyWithNotify(unittest.TestCase):
obj.myProperty = 10
self.assert_(self.called_)
+ def testHasProperty(self):
+ o = MyObjectWithNotifyProperty()
+ o.setProperty("myProperty", 10)
+ self.assertEqual(o.myProperty, 10)
+ self.assertEqual(o.property("myProperty"), 10)
+
if __name__ == '__main__':
unittest.main()
-
diff --git a/tests/pysidetest/testview.cpp b/tests/pysidetest/testview.cpp
index 75620e0..6adfe69 100644
--- a/tests/pysidetest/testview.cpp
+++ b/tests/pysidetest/testview.cpp
@@ -1,5 +1,6 @@
#include "testview.h"
+#include <QDebug>
#include <QWidget>
#include <QAbstractListModel>
#include <QAbstractItemDelegate>
@@ -21,4 +22,3 @@ TestView::getEditorWidgetFromItemDelegate() const
QStyleOptionViewItem options;
return m_delegate->createEditor(0, options, index);
}
-
diff --git a/tests/pysidetest/typesystem_pysidetest.xml b/tests/pysidetest/typesystem_pysidetest.xml
index fb9b82b..babb541 100644
--- a/tests/pysidetest/typesystem_pysidetest.xml
+++ b/tests/pysidetest/typesystem_pysidetest.xml
@@ -3,27 +3,46 @@
<load-typesystem name="typesystem_core.xml" generate="no" />
<load-typesystem name="typesystem_gui.xml" generate="no"/>
<value-type name="IntValue"/>
- <primitive-type name="TypedefValue"/>
+ <primitive-type name="TypedefValue">
+ <!--
+ A conversion rule is used here because ApiExtractor can't associate
+ a primitive typedef to a non-primitive type. That would be a good
+ improvement to ApiExtractor.
+ -->
+ <conversion-rule>
+ <native-to-target>
+ return %CONVERTTOPYTHON[IntValue](%in);
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="IntValue">
+ IntValue value = %CONVERTTOCPP[IntValue](%in);
+ %out = %OUTTYPE(value);
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
+ </primitive-type>
<object-type name="TestObject" />
+ <primitive-type name="PySideInt"/>
+ <primitive-type name="PySideCPP2::PySideLong"/>
+ <!--<primitive-type name="PySideLong"/>-->
+
<function signature="getHiddenObject()" />
<inject-code position="end">
- Shiboken::TypeResolver::createObjectTypeResolver&lt; ::PySideCPP2::TestObjectWithoutNamespace>("TestObjectWithoutNamespace*");
- Shiboken::TypeResolver::createValueTypeResolver&lt; ::PySideCPP2::PySideLong>("PySideLong");
- Shiboken::TypeResolver::createObjectTypeResolver&lt; ::PySideCPP::TestObjectWithNamespace>("TestObjectWithNamespace*");
- Shiboken::TypeResolver::createValueTypeResolver&lt; ::PySideInt>("PySideInt");
- qRegisterMetaType&lt;PySideInt>("PySideInt");
- qRegisterMetaType&lt;PySideCPP2::PySideLong>("PySideLong");
+ Shiboken::Conversions::registerConverterName(Shiboken::Conversions::PrimitiveTypeConverter&lt;long&gt;(), "PySideLong");
+ Shiboken::Conversions::registerConverterName(Shiboken::Conversions::PrimitiveTypeConverter&lt;long&gt;(), "PySideCPP2::PySideLong");
+ qRegisterMetaType&lt;PySideInt>("PySideInt");
+ qRegisterMetaType&lt;PySideCPP2::PySideLong>("PySideLong");
</inject-code>
<namespace-type name="PySideCPP">
- <object-type name="TestObjectWithNamespace" />
+ <object-type name="TestObjectWithNamespace"/>
</namespace-type>
<namespace-type name="PySideCPP2" generate="no">
<enum-type name="Enum1" />
- <object-type name="TestObjectWithoutNamespace" >
+ <object-type name="TestObjectWithoutNamespace">
<enum-type name="Enum2" />
</object-type>
</namespace-type>
@@ -36,4 +55,3 @@
</modify-function>
</object-type>
</typesystem>
-