Patch taken from the upstream repository https://github.com/frescobaldi/python-poppler-qt5/issues/43 From 92e5962ec3751ab051d0b655fd61afc7a1cf709e Mon Sep 17 00:00:00 2001 From: Ben Greiner Date: Thu, 4 Mar 2021 17:02:51 +0100 Subject: [PATCH] map type QVector< QPair > for FormFieldChoice::choicesWithExportValues() (#45) --- types.sip | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/types.sip b/types.sip index 239b8c9..81cb283 100644 --- a/types.sip +++ b/types.sip @@ -331,5 +331,98 @@ template }; +/** + * Convert QVector< QPair > + * from and to a Python list of a 2-item tuple + */ + +template +%MappedType QVector< QPair > +{ +%TypeHeaderCode +#include +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ((l = PyList_New(sipCpp->size())) == NULL) + return NULL; + + // Set the list elements. + for (int i = 0; i < sipCpp->size(); ++i) + { + QPair* p = new QPair(sipCpp->at(i)); + PyObject *ptuple = PyTuple_New(2); + PyObject *pfirst; + PyObject *psecond; + + TYPE *sfirst = new TYPE(p->first); + if ((pfirst = sipConvertFromType(sfirst, sipType_TYPE, sipTransferObj)) == NULL) + { + Py_DECREF(l); + Py_DECREF(ptuple); + return NULL; + } + PyTuple_SET_ITEM(ptuple, 0, pfirst); + + TYPE *ssecond = new TYPE(p->second); + if ((psecond = sipConvertFromType(ssecond, sipType_TYPE, sipTransferObj)) == NULL) + { + Py_DECREF(l); + Py_DECREF(ptuple); + Py_DECREF(pfirst); + return NULL; + } + PyTuple_SET_ITEM(ptuple, 1, psecond); + + PyList_SET_ITEM(l, i, ptuple); + } + + return l; +%End + +%ConvertToTypeCode + const sipTypeDef* qpair_type = sipFindType("QPair"); + + // Check the type if that is all that is required. + if (sipIsErr == NULL) + { + if (!PySequence_Check(sipPy)) + return 0; + + for (int i = 0; i < PySequence_Size(sipPy); ++i) + if (!sipCanConvertToType(PySequence_ITEM(sipPy, i), qpair_type, SIP_NOT_NONE)) + return 0; + + return 1; + } + + + QVector< QPair > *qv = new QVector< QPair >; + + for (int i = 0; i < PySequence_Size(sipPy); ++i) + { + int state; + QPair * p = reinterpret_cast< QPair * >(sipConvertToType(PySequence_ITEM(sipPy, i), qpair_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + + if (*sipIsErr) + { + sipReleaseType(p, qpair_type, state); + delete qv; + return 0; + } + qv->append(*p); + sipReleaseType(p, qpair_type, state); + } + + *sipCppPtr = qv; + return sipGetState(sipTransferObj); +%End + +}; + /* kate: indent-width 4; space-indent on; hl c++; indent-mode cstyle; */ urce): New variables. ("package with properties"): New test Signed-off-by: Ludovic Courtès <ludo@gnu.org> itd 2021-11-17Merge branch 'master' into core-updates-frozenLudovic Courtès 2021-11-11import: print: Replace packages and origins in 'arguments'....* guix/import/print.scm (package->code)[variable-reference] [object->code]: New procedures. [package-lists->code]: Rewrite in terms of 'object->code'. Pass the 'arguments' field through 'object->code'. * tests/print.scm (pkg-with-arguments, pkg-with-arguments-source): New variables. ("package with arguments"): New test. Ludovic Courtès 2021-11-11import: print: Handle patches that are origins....* guix/import/print.scm (package->code)[source->code]: Handle patches that are origins. * tests/print.scm (pkg-with-origin-input): Add 'patches' field. (pkg-with-origin-patch, pkg-with-origin-patch-source): New variables. ("package with origin patch"): New test. Ludovic Courtès 2021-11-11import: print: Correctly handle URI lists....* guix/import/print.scm (package->code)[factorized-uri-code]: New procedure. [source->code]: Use it, and factorize URI when it's a list. * tests/print.scm (pkg-with-origin-input): Check origin URI to a list. Ludovic Courtès 2021-11-11import: print: Properly render packages with origins as inputs....* guix/import/print.scm (package->code)[source->code]: Check whether VERSION is true before calling 'factorize-uri'. [package-lists->code]: Add clause for inputs that are origins. * tests/print.scm (pkg-with-origin-input, pkg-with-origin-input-source): New variables. ("package with origin input"): New test. Ludovic Courtès 2021-07-11import: print: Emit new-style package inputs when possible....* guix/import/print.scm (redundant-input-labels?): New procedure. (package->code)[package-lists->code]: Rename to... [inputs->code]: ... this. When 'redundant-input-labels?' returns true, emit label-less inputs. Adjust callers to new name. * tests/print.scm (pkg-with-inputs): Adjust accordingly. Ludovic Courtès