diff options
7 files changed, 63 insertions, 0 deletions
diff --git a/examples/scriptableapplication/mainwindow.h b/examples/scriptableapplication/mainwindow.h index 476243f9b..3cc898ff7 100644 --- a/examples/scriptableapplication/mainwindow.h +++ b/examples/scriptableapplication/mainwindow.h @@ -16,6 +16,8 @@ public: void testFunction1(); + static constexpr auto TEST = QLatin1StringView("test"); + private Q_SLOTS: void slotRunScript(); void slotPrintDiagnostics(); 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 diff --git a/sources/pyside6/tests/pysidetest/repr_test.py b/sources/pyside6/tests/pysidetest/repr_test.py index 01cc36b37..863f17657 100644 --- a/sources/pyside6/tests/pysidetest/repr_test.py +++ b/sources/pyside6/tests/pysidetest/repr_test.py @@ -49,6 +49,15 @@ class QObjectDerivedReprTest(unittest.TestCase): # __repr__ should use the operator<<(QDebug,...) implementation self.assertEqual(str(t), "TestObject2WithNamespace(injected_repr)") + def testLatin1StringField(self): + self.assertEqual(TestObject.LATIN1_TEST_FIELD, "test") + + def testLatin1Setter(self): + to = TestObject(123) + value = "test" + to.setQLatin1String(value) + self.assertEqual(to.qLatin1String(), value) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/pysidetest/testobject.cpp b/sources/pyside6/tests/pysidetest/testobject.cpp index 2233bad62..78c52ee59 100644 --- a/sources/pyside6/tests/pysidetest/testobject.cpp +++ b/sources/pyside6/tests/pysidetest/testobject.cpp @@ -30,6 +30,16 @@ void TestObject::emitSignalWithTypedefValue(int value) emit signalWithTypedefValue(TypedefValue(value)); } +void TestObject::setQLatin1String(QLatin1String v) +{ + m_qLatin1String = v; +} + +QString TestObject::qLatin1String() const +{ + return m_qLatin1String; +} + QDebug operator<<(QDebug dbg, TestObject& testObject) { QDebugStateSaver saver(dbg); diff --git a/sources/pyside6/tests/pysidetest/testobject.h b/sources/pyside6/tests/pysidetest/testobject.h index d3f0b2018..80944e14b 100644 --- a/sources/pyside6/tests/pysidetest/testobject.h +++ b/sources/pyside6/tests/pysidetest/testobject.h @@ -45,6 +45,11 @@ public: void emitSignalWithTypedefValue(int value); + static constexpr auto LATIN1_TEST_FIELD = QLatin1StringView("test"); + + void setQLatin1String(QLatin1String v); + QString qLatin1String() const; + signals: void idValue(int newValue); void justASignal(); @@ -56,6 +61,7 @@ signals: private: int m_idValue; QList<QObject*> m_children; + QString m_qLatin1String; }; PYSIDETEST_API QDebug operator<<(QDebug dbg, TestObject &testObject); diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index 47899803b..0604381e0 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -229,6 +229,7 @@ type_map.update({ "qreal": float, "QSet": typing.Set, "QString": str, + "QLatin1String": str, "QStringView": str, "QStringList": StringList, "quint16": int, |