diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-01-05 13:54:31 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-01-08 13:05:30 +0100 |
| commit | 5c69ee2f40ec0cf5d44c798feaca64809eb55889 (patch) | |
| tree | f51027efee2d9ffc4fc401c849490add7cf842c4 /sources/pyside6/PySide6 | |
| parent | 2ff4524802b90be37c10662593b5060af86d338f (diff) | |
Add QLatin1String
It is needed For the QIcon::ThemeIcon fields.
Task-number: PYSIDE-2497
Task-number: PYSIDE-2537
Change-Id: I11d94c150dfa614797038e56cd37128bf3e88cff
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6')
| -rw-r--r-- | sources/pyside6/PySide6/QtCore/typesystem_core_common.xml | 13 | ||||
| -rw-r--r-- | sources/pyside6/PySide6/glue/qtcore.cpp | 22 |
2 files changed, 35 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index dbf93a871..3ff08ce8f 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -247,6 +247,17 @@ </conversion-rule> </primitive-type> + <primitive-type name="QLatin1String" target-lang-api-name="PyUnicode"> + <include file-name="QtCore/qlatin1stringview.h" location="global"/> + <conversion-rule> + <native-to-target file="../glue/qtcore.cpp" snippet="return-pyunicode-from-qlatin1string"/> + <target-to-native> + <add-conversion type="PyString" check="qLatin1StringCheck(%in)" + file="../glue/qtcore.cpp" snippet="conversion-pystring-qlatin1string"/> + </target-to-native> + </conversion-rule> + </primitive-type> + <primitive-type name="QAnyStringView" target-lang-api-name="PyUnicode" view-on="QString"> <include file-name="QAnyStringView" location="global"/> <conversion-rule> @@ -668,6 +679,8 @@ <inject-code class="target" position="end" file="../glue/qtcore.cpp" snippet="qt-pysideinit"/> <inject-code class="native" position="beginning" file="../glue/qtcore.cpp" snippet="qt-messagehandler"/> + <inject-code class="native" position="beginning" file="../glue/qtcore.cpp" + snippet="qlatin1string-check"/> <add-function signature="qInstallMessageHandler(PyObject)" return-type="PyObject"> <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qt-installmessagehandler"/> </add-function> diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index 8613f62b7..70370d916 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -1566,6 +1566,28 @@ return PyLong_FromVoidPtr(reinterpret_cast<void *>(%in)); return PySide::qStringToPyUnicode(%in); // @snippet return-pyunicode +// @snippet return-pyunicode-from-qlatin1string +#ifdef Py_LIMITED_API +return PySide::qStringToPyUnicode(QString::fromLatin1(%in)); +#else +return PyUnicode_FromKindAndData(PyUnicode_1BYTE_KIND, %in.constData(), %in.size()); +#endif +// @snippet return-pyunicode-from-qlatin1string + +// @snippet qlatin1string-check +static bool qLatin1StringCheck(PyObject *o) +{ + return PyUnicode_CheckExact(o) != 0 + && _PepUnicode_KIND(o) == PepUnicode_1BYTE_KIND; +} +// @snippet qlatin1string-check + +// @snippet conversion-pystring-qlatin1string +const char *data = reinterpret_cast<const char *>(_PepUnicode_DATA(%in)); +const Py_ssize_t len = PyUnicode_GetLength(%in); +%out = QLatin1String(data, len); +// @snippet conversion-pystring-qlatin1string + // @snippet return-pyunicode-from-qanystringview return PySide::qStringToPyUnicode(%in.toString()); // @snippet return-pyunicode-from-qanystringview |
