added conversion rules for QList and QPair containers
This commit is contained in:
parent
96bc2011c8
commit
d753c1cf52
4 changed files with 61 additions and 5 deletions
|
|
@ -2,9 +2,9 @@
|
||||||
template <>
|
template <>
|
||||||
struct Converter<QBool>
|
struct Converter<QBool>
|
||||||
{
|
{
|
||||||
static PyObject* toPython(QBool holder)
|
static PyObject* toPython(QBool cppobj)
|
||||||
{
|
{
|
||||||
return PyBool_FromLong(bool(holder));
|
return PyBool_FromLong((bool) cppobj);
|
||||||
}
|
}
|
||||||
static QBool toCpp(PyObject* pyobj)
|
static QBool toCpp(PyObject* pyobj)
|
||||||
{
|
{
|
||||||
24
PySide/QtCore/qlist_conversions.h
Normal file
24
PySide/QtCore/qlist_conversions.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
template <typename StdList>
|
||||||
|
struct Converter_qlist
|
||||||
|
{
|
||||||
|
static PyObject* toPython(StdList holder)
|
||||||
|
{
|
||||||
|
PyObject* result = PyList_New(holder.size());
|
||||||
|
for (int i = 0; i < holder.size(); i++) {
|
||||||
|
PyList_SET_ITEM(result, i, Converter<typename StdList::value_type>::toPython(holder.at(i)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
static StdList toCpp(PyObject* pyobj)
|
||||||
|
{
|
||||||
|
StdList result;
|
||||||
|
for (int i = 0; i < PySequence_Size(pyobj); i++) {
|
||||||
|
PyObject* pyItem = PySequence_GetItem(pyobj, i);
|
||||||
|
result.append(Converter<typename StdList::value_type>::toCpp(pyItem));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Converter<QList<T> > : Converter_qlist<QList<T> > {};
|
||||||
25
PySide/QtCore/qpair_conversions.h
Normal file
25
PySide/QtCore/qpair_conversions.h
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
template <typename StdPair>
|
||||||
|
struct Converter_qpair
|
||||||
|
{
|
||||||
|
static PyObject* toPython(StdPair holder)
|
||||||
|
{
|
||||||
|
typename StdPair::first_type first(holder.first);
|
||||||
|
typename StdPair::second_type second(holder.second);
|
||||||
|
PyObject* tuple = PyTuple_New(2);
|
||||||
|
PyTuple_SET_ITEM(tuple, 0, Converter<typename StdPair::first_type>::toPython(first));
|
||||||
|
PyTuple_SET_ITEM(tuple, 1, Converter<typename StdPair::second_type>::toPython(second));
|
||||||
|
return tuple;
|
||||||
|
}
|
||||||
|
static StdPair toCpp(PyObject* pyobj)
|
||||||
|
{
|
||||||
|
StdPair result;
|
||||||
|
PyObject* pyFirst = PySequence_GetItem(pyobj, 0);
|
||||||
|
PyObject* pySecond = PySequence_GetItem(pyobj, 1);
|
||||||
|
result.first = Converter<typename StdPair::first_type>::toCpp(pyFirst);
|
||||||
|
result.second = Converter<typename StdPair::second_type>::toCpp(pySecond);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename FT, typename ST>
|
||||||
|
struct Converter<QPair<FT, ST> > : Converter_qpair<QPair<FT, ST> > {};
|
||||||
|
|
@ -286,15 +286,19 @@
|
||||||
<include file-name="QTextDocument" location="global"/>
|
<include file-name="QTextDocument" location="global"/>
|
||||||
</primitive-type>
|
</primitive-type>
|
||||||
<primitive-type name="QBool" target-lang-api-name="PyBool">
|
<primitive-type name="QBool" target-lang-api-name="PyBool">
|
||||||
<conversion-rule file="qtcore_conversions.h"/>
|
<conversion-rule file="qbool_conversions.h"/>
|
||||||
<!-- FIXME This is a workaround to include some headers needed by some includes (nothing to do with QBool) -->
|
<!-- FIXME This is a workaround to include some headers needed by some includes (nothing to do with QBool) -->
|
||||||
<include file-name="QtConcurrentFilter" location="global"/>
|
<include file-name="QtConcurrentFilter" location="global"/>
|
||||||
</primitive-type>
|
</primitive-type>
|
||||||
|
|
||||||
<primitive-type name="std::string"/>
|
<primitive-type name="std::string"/>
|
||||||
<primitive-type name="std::wstring"/>
|
<primitive-type name="std::wstring"/>
|
||||||
<primitive-type name="QStdWString"/>
|
<primitive-type name="QStdWString"/>
|
||||||
|
|
||||||
<container-type name="QList" type="list"/>
|
<container-type name="QList" type="list">
|
||||||
|
<conversion-rule file="qlist_conversions.h"/>
|
||||||
|
<include file-name="QList" location="global"/>
|
||||||
|
</container-type>
|
||||||
<rejection class="QList" function-name="back"/>
|
<rejection class="QList" function-name="back"/>
|
||||||
<rejection class="QList" function-name="begin"/>
|
<rejection class="QList" function-name="begin"/>
|
||||||
<rejection class="QList" function-name="constBegin"/>
|
<rejection class="QList" function-name="constBegin"/>
|
||||||
|
|
@ -351,7 +355,10 @@
|
||||||
<container-type name="QLinkedList" type="linked-list"/>
|
<container-type name="QLinkedList" type="linked-list"/>
|
||||||
<container-type name="QMap" type="map"/>
|
<container-type name="QMap" type="map"/>
|
||||||
<container-type name="QMultiMap" type="multi-map"/>
|
<container-type name="QMultiMap" type="multi-map"/>
|
||||||
<container-type name="QPair" type="pair"/>
|
<container-type name="QPair" type="pair">
|
||||||
|
<conversion-rule file="qpair_conversions.h"/>
|
||||||
|
<include file-name="QPair" location="global"/>
|
||||||
|
</container-type>
|
||||||
<container-type name="QSet" type="set"/>
|
<container-type name="QSet" type="set"/>
|
||||||
<container-type name="QStack" type="stack"/>
|
<container-type name="QStack" type="stack"/>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue