// This is the SIP interface definition for all types based on the QValueList
// template.
//
// Copyright (c) 2004
// 	Riverbank Computing Limited <info@riverbankcomputing.co.uk>
// 
// This file is part of PyQt.
// 
// This copy of PyQt is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2, or (at your option) any later
// version.
// 
// PyQt is supplied in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
// 
// You should have received a copy of the GNU General Public License along with
// PyQt; see the file LICENSE.  If not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
%ExportedDoc
<Sect2><Title>QValueList&lt;type&gt; (Qt v2+)</Title>
<Para>
Types based on the <Literal>QValueList</Literal> template are automatically
converted to and from Python lists of the type.
</Para>
</Sect2>
%End


%If (Qt_2_2_0 -)

%MappedType QValueList<QTranslatorMessage>
{
%TypeHeaderCode
#include <qvaluelist.h>
%End

%ConvertFromTypeCode
	// Handle no list.

	if (!sipCpp)
		return PyList_New(0);

	// Convert to a Python list of QTranslatorMessage instances.

	int i;
	PyObject *l;

	// Create the list.

	if ((l = PyList_New(sipCpp -> count())) == NULL)
		return NULL;

	// Get it.

	i = 0;
	QValueListConstIterator<QTranslatorMessage> it;

	for (it = sipCpp -> begin(); it != sipCpp -> end(); ++it)
	{
		PyObject *tmobj;

		if ((tmobj = sipBuildResult(NULL,"N",new QTranslatorMessage(*it),sipClass_QTranslatorMessage)) == NULL || PyList_SetItem(l,i,tmobj) < 0)
		{
			Py_XDECREF(tmobj);
			Py_DECREF(l);

			return NULL;
		}

		++i;
	}

	return l;
%End

%ConvertToTypeCode
	// At the moment this will never be called, so provide a null
	// implementation.

	if (sipIsErr == NULL)
		return PyList_Check(sipPy);

	PyErr_Format(PyExc_TypeError,"Converting to QValueList<QTranslatorMessage> not yet implemented");

	*sipIsErr = 1;

	return 0;
%End
};

%End


%If (Qt_NETWORKPROTOCOL)
%If (Qt_2_1_0 -)

%MappedType QValueList<QUrlInfo>
{
%TypeHeaderCode
#include <qvaluelist.h>
%End

%ConvertFromTypeCode
	// Handle no list.

	if (!sipCpp)
		return PyList_New(0);

	// Convert to a Python list of QUrlInfo instances.

	int i;
	PyObject *l;

	// Create the list.

	if ((l = PyList_New(sipCpp -> count())) == NULL)
		return NULL;

	// Get it.

	i = 0;
	QValueListConstIterator<QUrlInfo> it;

	for (it = sipCpp -> begin(); it != sipCpp -> end(); ++it)
	{
		PyObject *tmobj;

		if ((tmobj = sipBuildResult(NULL,"N",new QUrlInfo(*it),sipClass_QUrlInfo)) == NULL || PyList_SetItem(l,i,tmobj) < 0)
		{
			Py_XDECREF(tmobj);
			Py_DECREF(l);

			return NULL;
		}

		++i;
	}

	return l;
%End

%ConvertToTypeCode
	// Convert a Python list of QUrlInfo instances to a
	// QValueList<QUrlInfo> on the heap.
 
	if (sipIsErr == NULL)
		return PyList_Check(sipPy);

	if (sipPy == Py_None)
	{
		*sipCppPtr = NULL;

		return 0;
	}

	QValueList<QUrlInfo> *qvl = new QValueList<QUrlInfo>;
 
	for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
	{
		int iserr = 0;

		QUrlInfo *itm = reinterpret_cast<QUrlInfo *>(sipForceConvertTo_QUrlInfo(PyList_GET_ITEM(sipPy,i),&iserr));

		if (!itm || iserr)
		{
			*sipIsErr = 1;
			delete qvl;

			return 0;
		}

		qvl -> append(*itm);
	}
 
	*sipCppPtr = qvl;
 
	return 1;
%End
};

%End
%End


%If (Qt_IMAGE_TEXT)
%If (Qt_2_1_0 -)

%MappedType QValueList<QImageTextKeyLang>
{
%TypeHeaderCode
#include <qvaluelist.h>
%End

%ConvertFromTypeCode
	// Handle no list.

	if (!sipCpp)
		return PyList_New(0);

	// Convert to a Python list of QImageTextKeyLang instances.

	int i;
	PyObject *l;

	// Create the list.

	if ((l = PyList_New(sipCpp -> count())) == NULL)
		return NULL;

	// Get it.

	i = 0;
	QValueListConstIterator<QImageTextKeyLang> it;

	for (it = sipCpp -> begin(); it != sipCpp -> end(); ++it)
	{
		PyObject *tmobj;

		if ((tmobj = sipBuildResult(NULL,"N",new QImageTextKeyLang(*it),sipClass_QImageTextKeyLang)) == NULL || PyList_SetItem(l,i,tmobj) < 0)
		{
			Py_XDECREF(tmobj);
			Py_DECREF(l);

			return NULL;
		}

		++i;
	}

	return l;
%End

%ConvertToTypeCode
	// Convert a Python list of QImageTextKeyLang instances to a
	// QValueList<QImageTextKeyLang> on the heap.
 
	if (sipIsErr == NULL)
		return PyList_Check(sipPy);

	if (sipPy == Py_None)
	{
		*sipCppPtr = NULL;

		return 0;
	}

	QValueList<QImageTextKeyLang> *qvl = new QValueList<QImageTextKeyLang>;
 
	for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
	{
		int iserr = 0;

		QImageTextKeyLang *itm = reinterpret_cast<QImageTextKeyLang *>(sipForceConvertTo_QImageTextKeyLang(PyList_GET_ITEM(sipPy,i),&iserr));

		if (!itm || iserr)
		{
			*sipIsErr = 1;
			delete qvl;

			return 0;
		}

		qvl -> append(*itm);
	}
 
	*sipCppPtr = qvl;
 
	return 1;
%End
};

%End
%End


%If (Qt_DRAGANDDROP)
%If (Qt_2_1_0 -)

%MappedType QValueList<QIconDragItem>
{
%TypeHeaderCode
#include <qvaluelist.h>
%End

%ConvertFromTypeCode
	// Handle no list.

	if (!sipCpp)
		return PyList_New(0);

	// Convert to a Python list of QIconDragItem instances.

	int i;
	PyObject *l;

	// Create the list.

	if ((l = PyList_New(sipCpp -> count())) == NULL)
		return NULL;

	// Get it.

	i = 0;
	QValueListConstIterator<QIconDragItem> it;

	for (it = sipCpp -> begin(); it != sipCpp -> end(); ++it)
	{
		PyObject *tmobj;

		if ((tmobj = sipBuildResult(NULL,"N",new QIconDragItem(*it),sipClass_QIconDragItem)) == NULL || PyList_SetItem(l,i,tmobj) < 0)
		{
			Py_XDECREF(tmobj);
			Py_DECREF(l);

			return NULL;
		}

		++i;
	}

	return l;
%End

%ConvertToTypeCode
	// At the moment this will never be called, so provide a null
	// implementation.

	if (sipIsErr == NULL)
		return PyList_Check(sipPy);

	PyErr_Format(PyExc_TypeError,"Converting to QValueList<QIconDragItem> not yet implemented");

	*sipIsErr = 1;

	return 0;
%End
};

%End
%End


%If (Qt_3_0_0 -)

%MappedType QValueList<QPixmap>
{
%TypeHeaderCode
#include <qvaluelist.h>
%End

%ConvertFromTypeCode
	// Handle no list.

	if (!sipCpp)
		return PyList_New(0);

	// Convert to a Python list of QPixmap instances.

	int i;
	PyObject *l;

	// Create the list.

	if ((l = PyList_New(sipCpp -> count())) == NULL)
		return NULL;

	// Get it.

	i = 0;
	QValueListConstIterator<QPixmap> it;

	for (it = sipCpp -> begin(); it != sipCpp -> end(); ++it)
	{
		PyObject *tmobj;

		if ((tmobj = sipBuildResult(NULL,"N",new QPixmap(*it),sipClass_QPixmap)) == NULL || PyList_SetItem(l,i,tmobj) < 0)
		{
			Py_XDECREF(tmobj);
			Py_DECREF(l);

			return NULL;
		}

		++i;
	}

	return l;
%End

%ConvertToTypeCode
	// Convert a Python list of QPixmap instances to a QValueList<QPixmap>
	// on the heap.
 
	if (sipIsErr == NULL)
		return PyList_Check(sipPy);

	if (sipPy == Py_None)
	{
		*sipCppPtr = NULL;

		return 0;
	}

	QValueList<QPixmap> *qvl = new QValueList<QPixmap>;
 
	for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
	{
		int iserr = 0;

		QPixmap *itm = reinterpret_cast<QPixmap *>(sipForceConvertTo_QPixmap(PyList_GET_ITEM(sipPy,i),&iserr));

		if (!itm || iserr)
		{
			*sipIsErr = 1;
			delete qvl;

			return 0;
		}

		qvl -> append(*itm);
	}
 
	*sipCppPtr = qvl;
 
	return 1;
%End
};

%End


%If (Qt_2_00 -)

%MappedType QValueList<int>
{
%TypeHeaderCode
#include <qvaluelist.h>
%End

%ConvertFromTypeCode
	// Handle no list.

	if (!sipCpp)
		return PyList_New(0);

	// Convert to a Python list of integers.

	PyObject *l;

	// Create the list.

	if ((l = PyList_New(sipCpp -> count())) == NULL)
		return NULL;

	// Get it.

	for (uint i = 0; i < sipCpp -> count(); ++i)
		if (PyList_SetItem(l,i,PyInt_FromLong((long)(*sipCpp)[i])) < 0)
		{
			Py_DECREF(l);

			return NULL;
		}

	return l;
%End

%ConvertToTypeCode
	// Convert a Python list of integers to a QValueList<int> on the heap.
 
	if (sipIsErr == NULL)
		return PyList_Check(sipPy);

	if (sipPy == Py_None)
	{
		*sipCppPtr = NULL;

		return 0;
	}

	QValueList<int> *qvl = new QValueList<int>;
 
	PyErr_Clear();

	for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
	{
		qvl -> append((int)PyInt_AsLong(PyList_GET_ITEM(sipPy,i)));
 
		if (PyErr_Occurred() != NULL)
		{
			delete qvl;
			*sipIsErr = 1;

			return 0;
		}
	}
 
	*sipCppPtr = qvl;
 
	return 1;
%End
};

%End
