diff options
author | renatofilho <renato.filho@openbossa.org> | 2010-10-13 12:53:10 -0300 |
---|---|---|
committer | renatofilho <renato.filho@openbossa.org> | 2010-10-13 13:42:24 -0300 |
commit | ce09bd623b678eefddbe848b5cb44533cc648ae9 (patch) | |
tree | 61bcb389682095ae399669695b45ec6dd71281a3 | |
parent | eb9b436390a71327104a884afe09b566b0dc5fbd (diff) | |
download | pyside-ce09bd623b678eefddbe848b5cb44533cc648ae9.tar.gz pyside-ce09bd623b678eefddbe848b5cb44533cc648ae9.tar.xz pyside-ce09bd623b678eefddbe848b5cb44533cc648ae9.zip |
Implemented support to deep copy on QtCore.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Lauro Neto <lauro.neto@openbossa.org>
-rw-r--r-- | PySide/QtCore/typesystem_core.xml | 193 | ||||
-rw-r--r-- | PySide/typesystem_templates.xml | 50 | ||||
-rw-r--r-- | tests/QtCore/deepcopy_test.py | 29 |
3 files changed, 202 insertions, 70 deletions
diff --git a/PySide/QtCore/typesystem_core.xml b/PySide/QtCore/typesystem_core.xml index cd46325..a72abce 100644 --- a/PySide/QtCore/typesystem_core.xml +++ b/PySide/QtCore/typesystem_core.xml @@ -671,6 +671,14 @@ </extra-includes> </object-type> <value-type name="QLine" hash-function="PySide::hash"> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(iiii)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.x1(), %CPPSELF.y1(), %CPPSELF.x2(), %CPPSELF.y2()" /> + </insert-template> + </inject-code> + </add-function> <inject-code class="native" position="beginning"> namespace PySide { template<> inline uint hash(const QLine& v) { @@ -681,6 +689,14 @@ </value-type> <value-type name="QLineF"> <enum-type name="IntersectType" /> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(dddd)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.x1(), %CPPSELF.y1(), %CPPSELF.x2(), %CPPSELF.y2()" /> + </insert-template> + </inject-code> + </add-function> <modify-function signature="intersect(QLineF, QPointF*)const"> <modify-argument index="2"> <remove-argument /> @@ -726,13 +742,12 @@ <include file-name="datetime.h" location="global"/> </extra-includes> <enum-type name="MonthNameType"/> - <modify-function signature="julianToGregorian(uint,int&,int&,int&)" remove="all"/> <add-function signature="__reduce__" return-type="PyObject*"> <inject-code class="target" position="beginning"> - <insert-template name="reduce_start"/> - args = Py_BuildValue("(iii)", %CPPSELF.year(), %CPPSELF.month(), - %CPPSELF.day()); - <insert-template name="reduce_finish"/> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(iii)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.year(), %CPPSELF.month(), %CPPSELF.day()" /> + </insert-template> </inject-code> </add-function> <modify-function signature="getDate(int*,int*,int*)" > @@ -767,6 +782,7 @@ %PYARG_0 = Shiboken::makeTuple(week, yearNumber); </inject-code> </modify-function> + <modify-function signature="julianToGregorian(uint,int&,int&,int&)" remove="all"/> </value-type> <value-type name="QDateTime" hash-function="PySide::hash"> <conversion-rule class="target" file="qdatetime_conversions.h"/> @@ -786,24 +802,36 @@ </add-function> <add-function signature="__reduce__" return-type="PyObject*"> <inject-code class="target" position="beginning"> - <insert-template name="reduce_start"/> - QDate date = %CPPSELF.date(); - QTime time = %CPPSELF.time(); - args = Py_BuildValue("(iiiiiiii)", date.year(), date.month(), - date.day(), time.hour(), - time.minute(), time.second(), - time.msec(), (int)%CPPSELF.timeSpec()); - <insert-template name="reduce_finish"/> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(iiiiiiii)" /> + <replace from="%REDUCE_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> </value-type> <value-type name="QDir"> <enum-type name="Filter" flags="QDir::Filters"/> <enum-type name="SortFlag" flags="QDir::SortFlags" /> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(s)" /> + <replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.path())" /> + </insert-template> + </inject-code> + </add-function> <modify-function signature="QDir(QString,QString,QFlags<QDir::SortFlag>,QFlags<QDir::Filter>)" remove="all" /> </value-type> <value-type name="QPoint" hash-function="PySide::hash"> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(ii)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y()" /> + </insert-template> + </inject-code> + </add-function> <inject-code class="native" position="beginning"> namespace PySide { template<> inline uint hash(const QPoint& v) { @@ -815,10 +843,26 @@ <modify-function signature="ry()" remove="all"/> </value-type> <value-type name="QPointF"> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(dd)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y()" /> + </insert-template> + </inject-code> + </add-function> <modify-function signature="rx()" remove="all"/> <modify-function signature="ry()" remove="all"/> </value-type> <value-type name="QRect" hash-function="PySide::hash"> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(iiii)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.width(), %CPPSELF.height()" /> + </insert-template> + </inject-code> + </add-function> <inject-code class="native" position="beginning"> namespace PySide { template<> inline uint hash(const QRect& v) { @@ -832,35 +876,32 @@ <modify-function signature="getRect(int*,int*,int*,int*)const"> <remove/> </modify-function> + </value-type> + <value-type name="QRectF"> + <!-- + FIXME These functions return qreal. Will convert to double (format + string) mess things up in other architectures? + --> <add-function signature="__reduce__" return-type="PyObject*"> <inject-code class="target" position="beginning"> - <insert-template name="reduce_start"/> - args = Py_BuildValue("(iiii)", %CPPSELF.x(), %CPPSELF.y(), - %CPPSELF.width(), %CPPSELF.height()); - <insert-template name="reduce_finish"/> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(dddd)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.x(), %CPPSELF.y(), %CPPSELF.width(), %CPPSELF.height()" /> + </insert-template> </inject-code> </add-function> + <modify-function signature="getCoords(qreal*,qreal*,qreal*,qreal*)const" remove="all" /> + <modify-function signature="getRect(qreal*,qreal*,qreal*,qreal*)const" remove="all" /> </value-type> - <value-type name="QRectF"> - <modify-function signature="getCoords(qreal*,qreal*,qreal*,qreal*)const"> - <remove/> - </modify-function> - <modify-function signature="getRect(qreal*,qreal*,qreal*,qreal*)const"> - <remove/> - </modify-function> + <value-type name="QSize" hash-function="PySide::hash"> <add-function signature="__reduce__" return-type="PyObject*"> <inject-code class="target" position="beginning"> - <insert-template name="reduce_start"/> - // FIXME These functions return qreal. Will convert to double (format - // string) mess things up in other architectures? - args = Py_BuildValue("(dddd)", %CPPSELF.x(), %CPPSELF.y(), - %CPPSELF.width(), %CPPSELF.height()); - <insert-template name="reduce_finish"/> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(ii)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.width(), %CPPSELF.height()" /> + </insert-template> </inject-code> </add-function> - </value-type> - - <value-type name="QSize" hash-function="PySide::hash"> <inject-code class="native" position="beginning"> namespace PySide { template<> inline uint hash(const QSize& v) { @@ -870,41 +911,33 @@ </inject-code> <modify-function signature="rheight()" remove="all"/> <modify-function signature="rwidth()" remove="all"/> - <add-function signature="__reduce__" return-type="PyObject*"> - <inject-code class="target" position="beginning"> - <insert-template name="reduce_start"/> - args = Py_BuildValue("(ii)", %CPPSELF.width(), %CPPSELF.height()); - <insert-template name="reduce_finish"/> - </inject-code> - </add-function> </value-type> <value-type name="QSizeF"> - <modify-function signature="rheight()" remove="all" /> - <modify-function signature="rwidth()" remove="all" /> <add-function signature="__reduce__" return-type="PyObject*"> <inject-code class="target" position="beginning"> - <insert-template name="reduce_start"/> - // FIXME These functions return qreal. Will convert to double (format - // string) mess things up in other architectures? - args = Py_BuildValue("(dd)", %CPPSELF.width(), %CPPSELF.height()); - <insert-template name="reduce_finish"/> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(dd)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.width(), %CPPSELF.height()" /> + </insert-template> </inject-code> </add-function> + <modify-function signature="rheight()" remove="all" /> + <modify-function signature="rwidth()" remove="all" /> </value-type> <value-type name="QTime" hash-function="PySide::hash"> - <conversion-rule class="target" file="qtime_conversions.h"/> - <extra-includes> - <include file-name="datetime.h" location="global"/> - </extra-includes> <add-function signature="__reduce__" return-type="PyObject*"> <inject-code class="target" position="beginning"> - <insert-template name="reduce_start"/> - args = Py_BuildValue("(iiii)", %CPPSELF.hour(), %CPPSELF.minute(), - %CPPSELF.second(), %CPPSELF.msec()); - <insert-template name="reduce_finish"/> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(iiii)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.hour(), %CPPSELF.minute(), %CPPSELF.second(), %CPPSELF.msec()" /> + </insert-template> </inject-code> </add-function> + <conversion-rule class="target" file="qtime_conversions.h"/> + <extra-includes> + <include file-name="datetime.h" location="global"/> + </extra-includes> </value-type> <value-type name="QPersistentModelIndex"> <modify-function signature="internalPointer()const" remove="all"/> @@ -913,6 +946,14 @@ <value-type name="QUuid"> <enum-type name="Variant"/> <enum-type name="Version"/> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(s)" /> + <replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.toString())" /> + </insert-template> + </inject-code> + </add-function> <modify-function signature="QUuid(const char*)" remove="all" /> </value-type> @@ -1008,7 +1049,7 @@ </modify-function> </value-type> <value-type name="QBitArray" hash-function="qHash" > - <modify-function signature="fill(bool,int)" remove="all"/> <!-- FIXME Removed due to a shiboken bug--> + <modify-function signature="fill(bool,int)" remove="all"/> <!-- FIXME Removed due to a shiboken bug--> <add-function signature="__len__"> <inject-code class="target" position="beginning"> return %CPPSELF.size(); @@ -1336,6 +1377,14 @@ <extra-includes> <include file-name="QStringList" location="global"/> </extra-includes> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(s)" /> + <replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.toString())" /> + </insert-template> + </inject-code> + </add-function> </value-type> <value-type name="QRegExp"> <enum-type name="CaretMode"/> @@ -1343,17 +1392,41 @@ <extra-includes> <include file-name="QStringList" location="global"/> </extra-includes> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(sii)" /> + <replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.pattern()), (int)%CPPSELF.caseSensitivity(), (int)%CPPSELF.patternSyntax()" /> + </insert-template> + </inject-code> + </add-function> </value-type> <value-type name="QFileInfo"> <extra-includes> <include file-name="QDateTime" location="global"/> <include file-name="QDir" location="global"/> </extra-includes> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(s)" /> + <replace from="%REDUCE_ARGS" to="qPrintable(%CPPSELF.filePath())" /> + </insert-template> + </inject-code> + </add-function> </value-type> <value-type name="QByteArray" hash-function="qHash"> <extra-includes> <include file-name="QNoImplicitBoolCast" location="global"/> </extra-includes> + <add-function signature="__reduce__" return-type="PyObject*"> + <inject-code class="target" position="beginning"> + <insert-template name="reduce_code"> + <replace from="%REDUCE_FORMAT" to="(s)" /> + <replace from="%REDUCE_ARGS" to="%CPPSELF.constData()" /> + </insert-template> + </inject-code> + </add-function> <modify-function signature="QByteArray(const char *)"> <!-- Keep \x00 bytes passed in python strings --> <inject-code class="target" position="beginning"> @@ -1370,14 +1443,6 @@ #endif </inject-code> - <add-function signature="__reduce__" return-type="PyObject*"> - <inject-code class="target" position="beginning"> - <insert-template name="reduce_start"/> - args = Py_BuildValue("(s)", %CPPSELF.constData()); - <insert-template name="reduce_finish"/> - </inject-code> - </add-function> - <!-- removed functions --> <modify-function signature="begin()" remove="all"/> <modify-function signature="begin()const" remove="all"/> diff --git a/PySide/typesystem_templates.xml b/PySide/typesystem_templates.xml index e9db328..5763434 100644 --- a/PySide/typesystem_templates.xml +++ b/PySide/typesystem_templates.xml @@ -187,12 +187,56 @@ Shiboken::setParent(%CONVERTTOPYTHON[QApplication*](qApp), %PYARG_0); </template> <!-- templates for __reduce__ --> - <template name="reduce_start"> + <template name="reduce_code"> PyObject *type = PyObject_Type(%PYSELF); PyObject *args = NULL; + args = Py_BuildValue("%REDUCE_FORMAT", %REDUCE_ARGS); + %PYARG_0 = Py_BuildValue("(NN)", type, args); </template> - <template name="reduce_finish"> - %PYARG_0 = Py_BuildValue("(OO)", type, args); + <template name="reduce_code_matrix"> + QList< %MATRIX_TYPE > cppArgs; + %MATRIX_TYPE data[%MATRIX_SIZE]; + %CPPSELF.copyDataTo(data); + int matrixSize = %MATRIX_SIZE; + for(int size=0; size < matrixSize; size++) + cppArgs.append(data[size]); + + PyObject *type = PyObject_Type(%PYSELF); + PyObject *args = Py_BuildValue("(N)", %CONVERTTOPYTHON[QList<%MATRIX_TYPE> ](cppArgs)); + %PYARG_0 = Py_BuildValue("(NN)", type, args); + </template> + + <!-- Matrix Aux functions --> + <template name="matrix_constructor"> + if (PySequence_Size(%PYARG_1) == %SIZE) { + Shiboken::AutoDecRef fast(PySequence_Fast(%PYARG_1, "Fail to parse sequnce on %TYPE constructor.")); + qreal values[%SIZE]; + for(int i=0; i < %SIZE; i++) { + PyObject *pv = PySequence_Fast_GET_ITEM(fast.object(), i); + values[i] = %CONVERTTOCPP[qreal](pv); + } + %0 = new %TYPE(values); + } + </template> + + <template name="matrix_data_function"> + const qreal* data = %CPPSELF.constData(); + PyObject *pyData = PyTuple_New(%MATRIX_SIZE); + if (data) { + for(int i=0; i < %MATRIX_SIZE; i++) + PyTuple_SET_ITEM(pyData, i, %CONVERTTOPYTHON[qreal](data[i])); + } + return pyData; </template> + + <template name="matrix_fill_function"> + qreal value = %CONVERTTOCPP[qreal](%PYARG_1); + %CPPSELF.fill(value); + </template> + + <template name="matrix_transposed_function"> + return %CONVERTTOPYTHON[%TRANSPOSED_TYPE](%CPPSELF.transposed()); + </template> + </typesystem> diff --git a/tests/QtCore/deepcopy_test.py b/tests/QtCore/deepcopy_test.py index 9c14272..d440177 100644 --- a/tests/QtCore/deepcopy_test.py +++ b/tests/QtCore/deepcopy_test.py @@ -2,11 +2,11 @@ import unittest from copy import deepcopy -from PySide.QtCore import QByteArray, QDate, QDateTime, QTime -from PySide.QtCore import Qt, QSize, QSizeF, QRect, QRectF +from PySide.QtCore import QByteArray, QDate, QDateTime, QTime, QLine, QLineF +from PySide.QtCore import Qt, QSize, QSizeF, QRect, QRectF, QDir, QPoint, QPointF +from PySide.QtCore import QUuid class DeepCopyHelper: - def testCopy(self): copy = deepcopy([self.original])[0] self.assert_(copy is not self.original) @@ -51,6 +51,29 @@ class QRectFDeepCopy(DeepCopyHelper, unittest.TestCase): def setUp(self): self.original = QRectF(100.33, 200.254, 300.321, 400.123) +class QLineDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QLine(1, 2, 3, 4) + +class QLineFDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QLineF(1.1, 2.2, 3.3, 4.4) + +class QPointDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QPoint(1, 2) + +class QPointFDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QPointF(1.1, 2.2) + +class QDirDeepCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QDir("./") + +class QUuiCopy(DeepCopyHelper, unittest.TestCase): + def setUp(self): + self.original = QUuid("67C8770B-44F1-410A-AB9A-F9B5446F13EE") if __name__ == '__main__': unittest.main() |