diff options
-rw-r--r-- | examples/xml/dombookmarks/dombookmarks.py | 9 | ||||
-rw-r--r-- | sources/pyside6/PySide6/QtXml/typesystem_xml.xml | 4 | ||||
-rw-r--r-- | sources/pyside6/tests/QtXml/qdomdocument_test.py | 23 | ||||
-rw-r--r-- | sources/shiboken6/doc/typesystem_converters.rst | 36 | ||||
-rw-r--r-- | sources/shiboken6/doc/typesystem_variables.rst | 2 |
5 files changed, 42 insertions, 32 deletions
diff --git a/examples/xml/dombookmarks/dombookmarks.py b/examples/xml/dombookmarks/dombookmarks.py index 4f778acbd..f02251849 100644 --- a/examples/xml/dombookmarks/dombookmarks.py +++ b/examples/xml/dombookmarks/dombookmarks.py @@ -112,11 +112,12 @@ class XbelTree(QTreeWidget): self._bookmark_icon.addPixmap(style.standardPixmap(QStyle.StandardPixmap.SP_FileIcon)) def read(self, device): - ok, errorStr, errorLine, errorColumn = self._dom_document.setContent(device, True) - if not ok: + result = self._dom_document.setContent(device, + QDomDocument.ParseOption.UseNamespaceProcessing) + if not result: QMessageBox.information(self.window(), "DOM Bookmarks", - f"Parse error at line {errorLine}, " - f"column {errorColumn}:\n{errorStr}") + f"Parse error at line {result.errorLine}, " + f"column {result.errorColumn}:\n{result.errorMessage}") return False root = self._dom_document.documentElement() diff --git a/sources/pyside6/PySide6/QtXml/typesystem_xml.xml b/sources/pyside6/PySide6/QtXml/typesystem_xml.xml index 089978b6d..93d3c1f56 100644 --- a/sources/pyside6/PySide6/QtXml/typesystem_xml.xml +++ b/sources/pyside6/PySide6/QtXml/typesystem_xml.xml @@ -20,7 +20,7 @@ <enum-type name="ParseOption" flags="ParseOptions" since="6.5"/> <!-- will be replaced in inject code --> - <value-type name="ParseResult"/> + <value-type name="ParseResult" operator-bool="yes"/> <modify-function signature="setContent(const QByteArray&,bool,QString*,int*,int*)"> <modify-argument index="3"> @@ -130,6 +130,8 @@ </modify-argument> <inject-code class="target" position="beginning" file="../glue/qtxml.cpp" snippet="qdomdocument-setcontent" /> </modify-function> + <declare-function signature="setContent(const QByteArray&@data@, QDomDocument::ParseOptions@options@=QDomDocument::ParseOption::Default)" + return-type="QDomDocument::ParseResult" since="6.8" /> </value-type> <value-type name="QDomDocumentFragment"/> diff --git a/sources/pyside6/tests/QtXml/qdomdocument_test.py b/sources/pyside6/tests/QtXml/qdomdocument_test.py index 8fe4f6e17..b321b1bdf 100644 --- a/sources/pyside6/tests/QtXml/qdomdocument_test.py +++ b/sources/pyside6/tests/QtXml/qdomdocument_test.py @@ -44,18 +44,20 @@ class QDomDocumentTest(unittest.TestCase): def testQDomDocumentSetContentWithBadXmlData(self): '''Sets invalid xml as the QDomDocument contents.''' - ok, errorStr, errorLine, errorColumn = self.dom.setContent(self.badXmlData, True) - self.assertFalse(ok) - self.assertEqual(errorStr, 'Opening and ending tag mismatch.') - self.assertEqual(errorLine, 4) + parseResult = self.dom.setContent(self.badXmlData, + QDomDocument.ParseOption.UseNamespaceProcessing) + self.assertFalse(parseResult) + self.assertEqual(parseResult.errorMessage, 'Opening and ending tag mismatch.') + self.assertEqual(parseResult.errorLine, 4) def testQDomDocumentSetContentWithGoodXmlData(self): '''Sets valid xml as the QDomDocument contents.''' - ok, errorStr, errorLine, errorColumn = self.dom.setContent(self.goodXmlData, True) - self.assertTrue(ok) - self.assertEqual(errorStr, '') - self.assertEqual(errorLine, 0) - self.assertEqual(errorColumn, 0) + parseResult = self.dom.setContent(self.goodXmlData, + QDomDocument.ParseOption.UseNamespaceProcessing) + self.assertTrue(parseResult) + self.assertEqual(parseResult.errorMessage, '') + self.assertEqual(parseResult.errorLine, 0) + self.assertEqual(parseResult.errorColumn, 0) def testQDomDocumentData(self): '''Checks the QDomDocument elements for the valid xml contents.''' @@ -66,7 +68,8 @@ class QDomDocumentTest(unittest.TestCase): self.assertTrue(element.hasAttribute(attribute)) self.assertEqual(element.attribute(attribute), value) - ok, errorStr, errorLine, errorColumn = self.dom.setContent(self.goodXmlData, True) + parseResult = self.dom.setContent(self.goodXmlData, # noqa F:841 + QDomDocument.ParseOption.UseNamespaceProcessing) root = self.dom.documentElement() self.assertEqual(root.tagName(), 'typesystem') checkAttribute(root, 'package', 'PySide6.QtXml') diff --git a/sources/shiboken6/doc/typesystem_converters.rst b/sources/shiboken6/doc/typesystem_converters.rst index ab6fba930..f34f5b829 100644 --- a/sources/shiboken6/doc/typesystem_converters.rst +++ b/sources/shiboken6/doc/typesystem_converters.rst @@ -16,7 +16,8 @@ C++ and vice-versa. // C++ class struct Complex { - Complex(double real, double imag); + explicit Complex(double real, double imag); + double real() const; double imag() const; }; @@ -82,8 +83,9 @@ Here's how to do it: <!-- Code injection at module level. --> <inject-code class="native" position="beginning"> - static bool Check2TupleOfNumbers(PyObject* pyIn) { - if (!PySequence_Check(pyIn) || !(PySequence_Size(pyIn) == 2)) + static bool Check2TupleOfNumbers(PyObject *pyIn) + { + if (PySequence_Check(pyIn) == 0 || PySequence_Size(pyIn) != 2) return false; Shiboken::AutoDecRef pyReal(PySequence_GetItem(pyIn, 0)); if (!PyNumber_Check(pyReal)) @@ -134,7 +136,8 @@ Container Conversions Converters for :ref:`container-type <container-type>` are pretty much the same as for other type, except that they make use of the type system variables -:ref:`%INTYPE_# <intype_n>` and :ref:`%OUTTYPE_# <outtype_n>`. +:ref:`%INTYPE_# <intype_n>` and :ref:`%OUTTYPE_# <outtype_n>` denoting the +template parameters. |project| combines the conversion code for containers with the conversion defined (or automatically generated) for the containers. @@ -147,13 +150,12 @@ defined (or automatically generated) for the containers. <native-to-target> PyObject* %out = PyDict_New(); - %INTYPE::const_iterator it = %in.begin(); - for (; it != %in.end(); ++it) { - %INTYPE_0 key = it->first; - %INTYPE_1 value = it->second; - PyDict_SetItem(%out, + for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it) { + const auto &key = it->first; + const auto &value = it->second; + PyDict_SetItem(%out, %CONVERTTOPYTHON[%INTYPE_0](key), - %CONVERTTOPYTHON[%INTYPE_1](value)); + %CONVERTTOPYTHON[%INTYPE_1](value)); } return %out; </native-to-target> @@ -161,8 +163,8 @@ defined (or automatically generated) for the containers. <target-to-native> <add-conversion type="PyDict"> - PyObject* key; - PyObject* value; + PyObject *key{}; + PyObject *value{}; Py_ssize_t pos = 0; while (PyDict_Next(%in, &pos, &key, &value)) { %OUTTYPE_0 cppKey = %CONVERTTOCPP[%OUTTYPE_0](key); @@ -183,10 +185,10 @@ defined (or automatically generated) for the containers. For this case, a number of pre-defined conversion templates are provided (see :ref:`predefined_templates`). -.. _variables_and_functions: +.. _converter_variables_and_functions: -Variables & Functions -===================== +Converter Variables & Functions +=============================== .. _in: @@ -212,7 +214,7 @@ Variables & Functions .. _intype_n: **%INTYPE_#** - Replaced by the name of the #th type used in a container. + Replaced by the name of the #th template parameter type used in a container. .. _outtype: @@ -225,7 +227,7 @@ Variables & Functions .. _outtype_n: **%OUTTYPE_#** - Replaced by the name of the #th type used in a container. + Replaced by the name of the #th template parameter type used in a container. .. _checktype: diff --git a/sources/shiboken6/doc/typesystem_variables.rst b/sources/shiboken6/doc/typesystem_variables.rst index 5eb5d5abe..6dfd1f801 100644 --- a/sources/shiboken6/doc/typesystem_variables.rst +++ b/sources/shiboken6/doc/typesystem_variables.rst @@ -16,6 +16,8 @@ implementation specifics. Variables ========= +In addition to the below listed variables, there are some variables specific to type +conversion code (see :ref:`converter_variables_and_functions`). .. _cpp_return_argument: |