aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@openbossa.org>2011-01-26 15:21:37 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:53:46 -0300
commit16c3baa45401a915713b0b6201edf4f5c72822ab (patch)
tree2c8ad631b3f8515f7f8bf9cba486c78325bee618
parent494828092bc5f7853b4e63a6f94dfed8253115b5 (diff)
Implemented fuction __repr__ for base types.
Fixes bug #593 Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r--PySide/QtCore/typesystem_core.xml106
-rw-r--r--PySide/QtGui/typesystem_gui_common.xml151
-rw-r--r--PySide/typesystem_templates.xml23
3 files changed, 278 insertions, 2 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml
index 24ce91f7e..a50750a55 100644
--- a/PySide/QtCore/typesystem_core.xml
+++ b/PySide/QtCore/typesystem_core.xml
@@ -430,6 +430,15 @@
</extra-includes>
</object-type>
<value-type name="QLine" hash-function="PySide::hash">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%i, %i, %i, %i" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.x1(), %CPPSELF.y1(), %CPPSELF.x2(), %CPPSELF.y2()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -501,6 +510,15 @@
<include file-name="datetime.h" location="global"/>
</extra-includes>
<enum-type name="MonthNameType"/>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%i, %i, %i" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -559,6 +577,14 @@
%0 = new %TYPE(date, time, Qt::TimeSpec(%8));
</inject-code>
</add-function>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%i, %i, %i, %i, %i, %i, %i, %i" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.date().year(), %CPPSELF.date().month(), %CPPSELF.date().day(), %CPPSELF.time().hour(), %CPPSELF.time().minute(), %CPPSELF.time().second(), %CPPSELF.time().msec(), (int)%CPPSELF.timeSpec()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -583,6 +609,15 @@
</value-type>
<value-type name="QPoint" hash-function="PySide::hash">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%i, %i" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.x(), %CPPSELF.y()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -614,6 +649,14 @@
<modify-function signature="ry()" remove="all"/>
</value-type>
<value-type name="QRect" hash-function="PySide::hash">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%i, %i, %i, %i" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.width(), %CPPSELF.height()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -675,6 +718,15 @@
</modify-function>
</value-type>
<value-type name="QRectF">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%f, %f, %f, %f" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.width(), %CPPSELF.height()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<!--
FIXME These functions return qreal. Will convert to double (format
string) mess things up in other architectures?
@@ -733,6 +785,15 @@
</modify-function>
</value-type>
<value-type name="QSize" hash-function="PySide::hash">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%i, %i" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.width(), %CPPSELF.height()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -765,6 +826,14 @@
</value-type>
<value-type name="QTime" hash-function="PySide::hash">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%i, %i, %i, %i" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -785,6 +854,14 @@
<value-type name="QUuid">
<enum-type name="Variant"/>
<enum-type name="Version"/>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="'%s'" />
+ <replace from="%REPR_ARGS" to="qPrintable(%CPPSELF.toString())" />
+ </insert-template>
+ </inject-code>
+ </add-function>
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -1214,6 +1291,15 @@
<extra-includes>
<include file-name="QStringList" location="global"/>
</extra-includes>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="'%s'" />
+ <replace from="%REPR_ARGS" to="qPrintable(%CPPSELF.toString())" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -1229,6 +1315,15 @@
<extra-includes>
<include file-name="QStringList" location="global"/>
</extra-includes>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="'%s', %i, %i" />
+ <replace from="%REPR_ARGS" to="qPrintable(%CPPSELF.pattern()), (int)%CPPSELF.caseSensitivity(), (int)%CPPSELF.patternSyntax()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -1291,6 +1386,17 @@
<extra-includes>
<include file-name="QNoImplicitBoolCast" location="global"/>
</extra-includes>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ PyObject* str = PyString_FromStringAndSize(%CPPSELF.constData(), %CPPSELF.size());
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="'%s'" />
+ <replace from="%REPR_ARGS" to="PyString_AS_STRING(str)" />
+ </insert-template>
+ Py_DECREF(str);
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
diff --git a/PySide/QtGui/typesystem_gui_common.xml b/PySide/QtGui/typesystem_gui_common.xml
index c6f29443d..f39478154 100644
--- a/PySide/QtGui/typesystem_gui_common.xml
+++ b/PySide/QtGui/typesystem_gui_common.xml
@@ -175,11 +175,22 @@
<rejection class="*" enum-name="enum_1"/>
<value-type name="QTransform">
<enum-type name="TransformationType"/>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%f, %f, %f, %f, %f, %f, %f, %f, %f" />
+ <replace from="%REPR_ARGS"
+ to="%CPPSELF.m11(), %CPPSELF.m12(), %CPPSELF.m13(), %CPPSELF.m21(), %CPPSELF.m22(), %CPPSELF.m23(), %CPPSELF.m31(), %CPPSELF.m32(), %CPPSELF.m33()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
<replace from="%REDUCE_FORMAT" to="ddddddddd" />
- <replace from="%REDUCE_ARGS" to="%CPPSELF.m11(), %CPPSELF.m12(), %CPPSELF.m13(), %CPPSELF.m21(), %CPPSELF.m22(), %CPPSELF.m23(), %CPPSELF.m31(), %CPPSELF.m32(), %CPPSELF.m33()" />
+ <replace from="%REDUCE_ARGS"
+ to="%CPPSELF.m11(), %CPPSELF.m12(), %CPPSELF.m13(), %CPPSELF.m21(), %CPPSELF.m22(), %CPPSELF.m23(), %CPPSELF.m31(), %CPPSELF.m32(), %CPPSELF.m33()" />
</insert-template>
</inject-code>
</add-function>
@@ -420,6 +431,16 @@
<enum-type name="SequenceFormat"/>
<enum-type name="SequenceMatch"/>
<enum-type name="StandardKey"/>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%i, %i, %i, %i" />
+ <replace from="%REPR_ARGS"
+ to="(*%CPPSELF)[0], (*%CPPSELF)[1], (*%CPPSELF)[2], (*%CPPSELF)[3]" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -512,7 +533,6 @@
</inject-code>
</add-function>
-
<modify-function signature="QPolygon(int, const int *)" remove="all"/>
<modify-function signature="operator+=(QVector)" remove="all"/>
<modify-function signature="operator&lt;&lt;(QPoint)" remove="all"/>
@@ -634,6 +654,16 @@
<extra-includes>
<include file-name="QPainterPath" location="global"/>
</extra-includes>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%f, %f, %f, %f, %f, %f" />
+ <replace from="%REPR_ARGS"
+ to="%CPPSELF.m11(), %CPPSELF.m12(), %CPPSELF.m21(), %CPPSELF.m22(), %CPPSELF.dx(), %CPPSELF.dy()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -5148,6 +5178,15 @@
</object-type>
<value-type name="QMatrix2x2">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="4" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5209,6 +5248,15 @@
</value-type>
<value-type name="QMatrix2x3">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="6" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5270,6 +5318,15 @@
</value-type>
<value-type name="QMatrix2x4">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="8" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5331,6 +5388,15 @@
</value-type>
<value-type name="QMatrix3x2">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="6" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5392,6 +5458,15 @@
</value-type>
<value-type name="QMatrix3x3">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="9" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5453,6 +5528,15 @@
</value-type>
<value-type name="QMatrix3x4">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="12" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5514,6 +5598,15 @@
</value-type>
<value-type name="QMatrix4x2">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="8" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5575,6 +5668,15 @@
</value-type>
<value-type name="QMatrix4x3">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="12" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5637,6 +5739,15 @@
<value-type name="QMatrix4x4">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code_matrix">
+ <replace from="%MATRIX_SIZE" to="16" />
+ <replace from="%MATRIX_TYPE" to="qreal" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code_matrix">
@@ -5732,6 +5843,15 @@
<enum-type name="ChangeFlag" flags="QPinchGesture::ChangeFlags"/>
</object-type>
<value-type name="QQuaternion">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%f, %f, %f, %f" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.scalar(), %CPPSELF.x(), %CPPSELF.y(), %CPPSELF.z()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -5766,6 +5886,15 @@
</object-type>
<value-type name="QVector2D">
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%f, %f" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.x(), %CPPSELF.y()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -5779,6 +5908,15 @@
<extra-includes>
<include file-name="QMatrix4x4" location="global"/>
</extra-includes>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%f, %f, %f" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.z()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
@@ -5792,6 +5930,15 @@
<extra-includes>
<include file-name="QMatrix4x4" location="global"/>
</extra-includes>
+ <add-function signature="__repr__" return-type="PyObject*">
+ <inject-code class="target" position="beginning">
+ <insert-template name="repr_code">
+ <replace from="%REPR_FORMAT" to="%f, %f, %f, %f" />
+ <replace from="%REPR_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.z(), %CPPSELF.w()" />
+ </insert-template>
+ </inject-code>
+ </add-function>
+
<add-function signature="__reduce__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="reduce_code">
diff --git a/PySide/typesystem_templates.xml b/PySide/typesystem_templates.xml
index 65a98b2ba..e13b78d9e 100644
--- a/PySide/typesystem_templates.xml
+++ b/PySide/typesystem_templates.xml
@@ -187,6 +187,29 @@
if (!Shiboken::Object::hasParentInfo(_pySelf))
Shiboken::Object::setParent(%CONVERTTOPYTHON[QApplication*](qApp), %PYARG_0);
</template>
+ <!-- templates for __repr__ -->
+ <template name="repr_code">
+ QString format = QString().sprintf("%s(%REPR_FORMAT)", ((PyObject*)%PYSELF)->ob_type->tp_name, %REPR_ARGS);
+ %PYARG_0 = PyString_FromString(qPrintable(format));
+ </template>
+ <template name="repr_code_matrix">
+ QString format= QString("%1((").arg(((PyObject*)%PYSELF)->ob_type->tp_name);
+
+ QList&lt; %MATRIX_TYPE &gt; cppArgs;
+ %MATRIX_TYPE data[%MATRIX_SIZE];
+ %CPPSELF.copyDataTo(data);
+ int matrixSize = %MATRIX_SIZE;
+ for(int size=0; size &lt; matrixSize; size++) {
+ if (size > 0)
+ format += ", ";
+ format += QString::number(data[size]);
+ }
+ format += "))";
+
+ %PYARG_0 = PyString_FromString(qPrintable(format));
+ </template>
+
+
<!-- templates for __reduce__ -->
<template name="reduce_code">
%PYARG_0 = Py_BuildValue("(N(%REDUCE_FORMAT))", PyObject_Type(%PYSELF), %REDUCE_ARGS);