diff options
Diffstat (limited to 'sources/pyside6')
| -rw-r--r-- | sources/pyside6/PySide6/QtCore/typesystem_core_common.xml | 24 | ||||
| -rw-r--r-- | sources/pyside6/PySide6/glue/qtcore.cpp | 12 | ||||
| -rw-r--r-- | sources/pyside6/tests/QtCore/qbytearray_test.py | 24 |
3 files changed, 55 insertions, 5 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index e7c85fc55..dbf93a871 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -36,10 +36,26 @@ <modify-argument index="return" pyi-type="str"/> </modify-function> </function> - <function signature="qCompress(const uchar*,qsizetype,int)"/> - <function signature="qCompress(const QByteArray&,int)"/> - <function signature="qUncompress(const uchar*,qsizetype)" doc-file="qbytearray"/> - <function signature="qUncompress(const QByteArray&)" doc-file="qbytearray"/> + <!-- Move PyBuffer overload to front to avoid conversion PyBuffer->QByteArray --> + <function signature="qCompress(const uchar*,qsizetype,int)" overload-number="0"> + <modify-function> + <modify-argument index="1"> + <replace-type modified-type="PyBuffer"/> + </modify-argument> + <inject-code file="../glue/qtcore.cpp" snippet="qcompress-buffer"/> + </modify-function> + </function> + <function signature="qCompress(const QByteArray&,int)" overload-number="1"/> + <!-- Move PyBuffer overload to front to avoid conversion PyBuffer->QByteArray --> + <function signature="qUncompress(const uchar*,qsizetype)" overload-number="0"> + <modify-function> + <modify-argument index="1"> + <replace-type modified-type="PyBuffer"/> + </modify-argument> + <inject-code file="../glue/qtcore.cpp" snippet="quncompress-buffer"/> + </modify-function> + </function> + <function signature="qUncompress(const QByteArray&)" overload-number="1"/> <function signature="qFormatLogMessage(QtMsgType,const QMessageLogContext&,const QString&)" doc-file="qtlogging"/> <function signature="qSetMessagePattern(const QString&)" doc-file="qtlogging"/> diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index 6ce1aa1f7..8613f62b7 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -284,6 +284,18 @@ PySide::addPostRoutine(%1); qAddPostRoutine(PySide::globalPostRoutineCallback); // @snippet qt-qaddpostroutine +// @snippet qcompress-buffer +auto *ptr = reinterpret_cast<uchar*>(Shiboken::Buffer::getPointer(%PYARG_1)); +QByteArray compressed = %FUNCTION_NAME(ptr, %2, %3); +%PYARG_0 = %CONVERTTOPYTHON[QByteArray](compressed); +// @snippet qcompress-buffer + +// @snippet quncompress-buffer +auto *ptr = reinterpret_cast<uchar*>(Shiboken::Buffer::getPointer(%PYARG_1)); +QByteArray uncompressed = %FUNCTION_NAME(ptr, %2); +%PYARG_0 = %CONVERTTOPYTHON[QByteArray](uncompressed); +// @snippet quncompress-buffer + // @snippet qt-version QList<QByteArray> version = QByteArray(qVersion()).split('.'); PyObject *pyQtVersion = PyTuple_New(3); diff --git a/sources/pyside6/tests/QtCore/qbytearray_test.py b/sources/pyside6/tests/QtCore/qbytearray_test.py index c00674859..555faf1c9 100644 --- a/sources/pyside6/tests/QtCore/qbytearray_test.py +++ b/sources/pyside6/tests/QtCore/qbytearray_test.py @@ -15,7 +15,8 @@ from init_paths import init_test_paths init_test_paths(False) -from PySide6.QtCore import QByteArray, QSettings, QObject, QDataStream, QIODevice +from PySide6.QtCore import (QByteArray, QSettings, QObject, QDataStream, + QIODevice, qCompress, qUncompress) class QByteArrayTestToNumber(unittest.TestCase): @@ -256,5 +257,26 @@ class QByteArraySliceAssignment(unittest.TestCase): self.assertEqual(orig_bytes, actual_bytes) +class QCompressTest(unittest.TestCase): + def testQByteArrayCompression(self): + """Compress/uncompress a QByteArray.""" + data = bytes(10 * 'long redundant sentence bla bla', "UTF8") + ba = QByteArray(data) + compressed = qCompress(ba) + self.assertTrue(len(compressed) < len(data)) + uncompressed = qUncompress(compressed) + self.assertEqual(uncompressed, data) + + def testBufferCompression(self): + """Compress/uncompress portions of bytes without converting to + QByteArray.""" + data = bytes(10 * 'long redundant sentence bla bla', "UTF8") + used_len = int(len(data) / 2) + compressed = qCompress(data, used_len, -1) + self.assertTrue(len(compressed) < used_len) + uncompressed = qUncompress(compressed.data(), len(compressed)) + self.assertEqual(uncompressed, data[:used_len]) + + if __name__ == '__main__': unittest.main() |
