diff options
author | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2018-10-11 17:45:43 +0200 |
---|---|---|
committer | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2018-11-22 17:00:11 +0000 |
commit | a57a202a70801f766094c3ed11664b03c9a6a3e4 (patch) | |
tree | 73c2c1f4fc902ccbc10b73811bbf299a2c555728 /sources/pyside2/PySide2/QtScript | |
parent | f93a7369657814206bfbce49817c8fbd9a1bfcba (diff) |
Move inject-code snippets to separate files
When code must be modified or added to certain
functions, we currently have two options:
* Write a template and include it into the typesystem,
* inject code directly at a certain place of the function entry.
The problem with injecting raw code is that since it is an XML
file, one need to escape protected symbols, like "<" and "&".
Thanks to a couple of complementary commits, now we can place
this code snippets on a separate file without triggering
a whole module compiling process, since the typesystem itself
will not be alterered.
All the injected code from the typesystem was removed
and placed into a single file per module inside a top-level directory
called glue.
Some small fixes were included mainly regarding styling
of the code.
Task-number: PYSIDE-834
Change-Id: I823e92d241a528d75d5940090008db9bf297f49e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside2/PySide2/QtScript')
-rw-r--r-- | sources/pyside2/PySide2/QtScript/typesystem_script.xml | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/sources/pyside2/PySide2/QtScript/typesystem_script.xml b/sources/pyside2/PySide2/QtScript/typesystem_script.xml index d2d3e3182..f87e4cfdf 100644 --- a/sources/pyside2/PySide2/QtScript/typesystem_script.xml +++ b/sources/pyside2/PySide2/QtScript/typesystem_script.xml @@ -40,7 +40,7 @@ ****************************************************************************/ --> <typesystem package="PySide2.QtScript"> - <load-typesystem name="QtCore/typesystem_core.xml" generate="no" /> + <load-typesystem name="QtCore/typesystem_core.xml" generate="no"/> <object-type name="QScriptable"/> <object-type name="QScriptClass"> @@ -62,7 +62,7 @@ <enum-type name="QObjectWrapOption" flags="QObjectWrapOptions"/> <enum-type name="ValueOwnership"/> <!-- Not supported BUG #957--> - <modify-function signature="scriptValueFromQMetaObject()" remove="all" /> + <modify-function signature="scriptValueFromQMetaObject()" remove="all"/> </object-type> <object-type name="QScriptExtensionInterface"/> <object-type name="QScriptExtensionPlugin"/> @@ -82,53 +82,23 @@ <enum-type name="ResolveFlag" flags="ResolveFlags"/> <enum-type name="SpecialValue"/> <add-function signature="__repr__" return-type="PyObject*"> - <inject-code class="target" position="beginning"> - if (%CPPSELF.isVariant() || %CPPSELF.isString()) { - QString format = QString().sprintf("%s(\"%s\")", - Py_TYPE(%PYSELF)->tp_name, - qPrintable(%CPPSELF.toString())); - %PYARG_0 = Shiboken::String::fromCString(qPrintable(format)); - } else { - %PYARG_0 = Shiboken::String::fromCString(Py_TYPE(%PYSELF)->tp_name); - } - </inject-code> + <inject-code class="target" position="beginning" file="../glue/qtscript.cpp" snippet="qscriptvalue-repr"/> </add-function> <add-function signature="__mgetitem__"> - <inject-code> - Shiboken::AutoDecRef key(PyObject_Str(_key)); - QVariant res = %CPPSELF.property(Shiboken::String::toCString(key.object())).toVariant(); - if (res.isValid()) { - return %CONVERTTOPYTHON[QVariant](res); - } else { - PyObject* errorType = PyInt_Check(_key) ? PyExc_IndexError : PyExc_KeyError; - PyErr_SetString(errorType, "Key not found."); - return 0; - } - </inject-code> + <inject-code file="../glue/qtscript.cpp" snippet="qscriptvalue-mgetitem"/> </add-function> <add-function signature="__iter__()" return-type="PyObject*"> - <inject-code file="qscript_value_iterator_glue.cpp" /> + <inject-code file="qscript_value_iterator_glue.cpp"/> </add-function> </value-type> <object-type name="QScriptValueIterator"> <add-function signature="__iter__()" return-type="PyObject*"> <inject-code> - <insert-template name="__iter__" /> + <insert-template name="__iter__"/> </inject-code> </add-function> <add-function signature="__next__()" return-type="PyObject*"> - <inject-code> - if (%CPPSELF.hasNext()) { - %CPPSELF.next(); - QString name = %CPPSELF.name(); - QVariant value = %CPPSELF.value().toVariant(); - %PYARG_0 = PyTuple_New(2); - PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[QString](name)); - PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[QVariant](value)); - } else { - PyErr_SetNone(PyExc_StopIteration); - } - </inject-code> + <inject-code file="../glue/qtscript.cpp" snippet="qscriptvalueiterator-next"/> </add-function> </object-type> </typesystem> |