Skip to content
Permalink
Browse files

more sip fixes

  • Loading branch information
jef-n committed Sep 24, 2012
1 parent 60ab4b3 commit eef86276634de62e9cf72d654d2830f569cc4397
@@ -10,17 +10,21 @@ which are not wrapped by PyQt:
- QSet<TYPE>
- QMap<qint64, QMap<int, TYPE> >
- QMap<QString, QVariant::Type>
- QMap<QString, int>
- QMap<TYPE1, TYPE2*>
- QMap<double, TYPE>
- QMultiMap<double, TYPE2>
- QMap<qint64, QgsGeometry>
- QMap<qint64, QgsOverlayObject*>
- QList< QPair< QString, QList<QString> > >
- QVector<TYPE*>
*/

%Feature QSETINT_CONVERSION
%Feature QSETTYPE_CONVERSION

%ModuleHeaderCode

// From Python 2.5, some functions use Py_ssize_t instead of int
// thus this typedef is for maintaining backward compatibility
// for older versions of Python
@@ -31,7 +35,6 @@ typedef int Py_ssize_t;
%End



template <TYPE>
%MappedType QVector< QVector<TYPE> >
{
@@ -110,10 +113,10 @@ template <TYPE>
*sipCppPtr = ql;
return sipGetState(sipTransferObj);
%End

};



template <TYPE>
%MappedType QVector< QVector< QVector<TYPE> > >
{
@@ -192,7 +195,6 @@ template <TYPE>
*sipCppPtr = ql;
return sipGetState(sipTransferObj);
%End

};


@@ -269,7 +271,6 @@ template <TYPE>
*sipCppPtr = ql;
return sipGetState(sipTransferObj);
%End

};


@@ -326,10 +327,11 @@ template <TYPE>
*sipCppPtr = qset;
return sipGetState(sipTransferObj);
%End

};
%End



%MappedType QList<qint64>
{
%TypeHeaderCode
@@ -375,9 +377,10 @@ template <TYPE>
*sipCppPtr = qlist;
return sipGetState(sipTransferObj);
%End

};



%MappedType QSet<qint64>
{
%TypeHeaderCode
@@ -423,9 +426,10 @@ template <TYPE>
*sipCppPtr = qset;
return sipGetState(sipTransferObj);
%End

};



%If (QSETTYPE_CONVERSION)
template <TYPE>
%MappedType QSet<TYPE>
@@ -503,6 +507,8 @@ template <TYPE>
};
%End



template<TYPE>
%MappedType QMap<qint64, QMap<int, TYPE> >
{
@@ -627,6 +633,8 @@ template<TYPE>
%End
};



%MappedType QMap<qint64, QgsGeometry>
{
%TypeHeaderCode
@@ -711,6 +719,8 @@ template<TYPE>
%End
};



%MappedType QMap<QString, QVariant::Type>
{
%TypeHeaderCode
@@ -817,6 +827,8 @@ template<TYPE>
%End
};



%MappedType QMap<QString, int>
{
%TypeHeaderCode
@@ -920,6 +932,8 @@ template<TYPE>
%End
};



template<TYPE1, TYPE2>
%MappedType QMap<TYPE1, TYPE2*>
{
@@ -1133,7 +1147,6 @@ template<double, TYPE>




template<double, TYPE2>
%MappedType QMultiMap<double, TYPE2>
{
@@ -1231,8 +1244,7 @@ template<double, TYPE2>
double k = PyFloat_AsDouble(t1obj);
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
TYPE2 *t2 =
reinterpret_cast<TYPE2 *>(sipConvertToInstance(PyList_GET_ITEM(t2obj,
i),
reinterpret_cast<TYPE2 *>(sipConvertToInstance(PyList_GET_ITEM(t2obj, i),
sipClass_TYPE2,
sipTransferObj,
SIP_NOT_NONE,
@@ -1257,7 +1269,9 @@ template<double, TYPE2>

return sipGetState(sipTransferObj);
%End
};
};



%MappedType QMap<qint64, QgsOverlayObject*>
{
@@ -1342,6 +1356,8 @@ template<double, TYPE2>
%End
};



%MappedType QList < QPair< QString, QList<QString> > >
{
%TypeHeaderCode
@@ -1426,3 +1442,93 @@ template<double, TYPE2>
return sipGetState(sipTransferObj);
%End
};



template <TYPE>
%MappedType QVector< TYPE* >
{
%TypeHeaderCode
#include <QVector>
#if (SIP_VERSION >= 0x040900)
#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString))
#endif
#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01)
#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
#endif
%End

%ConvertFromTypeCode
// Create the list
PyObject *l = PyList_New(sipCpp->size());

if (!l)
return NULL;

// Set the dictionary elements.
for( int i = 0; i < sipCpp->size(); i++ )
{
TYPE *t = sipCpp->at(i);
PyObject *tobj = sipConvertFromInstance(t, sipClass_TYPE, sipTransferObj);

if (tobj == NULL || PyList_SetItem(l, i, tobj) < 0)
{
Py_DECREF(l);

if (tobj)
Py_DECREF(tobj);
else
delete t;

return NULL;
}

Py_DECREF(tobj);
}

return l;
%End

%ConvertToTypeCode
PyObject *tobj;

// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyList_Check(sipPy))
return 0;

for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
{
if (!sipCanConvertToInstance(tobj, sipClass_TYPE, SIP_NOT_NONE))
return 0;
}

return 1;
}

QVector<TYPE*> *v = new QVector<TYPE*>( PyList_GET_SIZE(sipPy) );

for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
{
int state;

TYPE *t = reinterpret_cast<TYPE *>(sipConvertToInstance(tobj, sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
sipReleaseInstance(t, sipClass_TYPE, state);
delete v;
return 0;
}

v->replace( i, t );

sipReleaseInstance(t, sipClass_TYPE, state);
}

*sipCppPtr = v;

return sipGetState(sipTransferObj);
%End
};
@@ -38,7 +38,8 @@ class QgsAttributeAction
#include "qgsattributeaction.h"
%End
public:
QgsAttributeAction( QgsVectorLayer * );
//! Constructor
QgsAttributeAction( QgsVectorLayer *layer );

//! Destructor
virtual ~QgsAttributeAction();
@@ -55,9 +56,36 @@ class QgsAttributeAction
* is to be used if the action has a default placeholder.
* @note added to python API in 1.6 (without executePython parameter)
* @deprecated
*/
void doAction( int index,
const QMap<int, QVariant> &values,
int defaultValueIndex = 0 );
const QMap<int, QVariant> &attributes,
int defaultValueIndex = 0 ) /Deprecated/;

/*! Does the given values. defaultValueIndex is the index of the
* field to be used if the action has a $currfield placeholder.
* @note added in 1.9
* @note not available in python bindings
*/
void doActionFeature( int index,
QgsFeature &feat,
int defaultValueIndex = 0 );
%MethodCode
sipCpp->doAction( a0, *a1, a2 );
%End

/*! Does the action using the expression builder to expand it
* and getting values from the passed feature attribute map.
* substitutionMap is used to pass custom substitutions, to replace
* each key in the map with the associated value
* @note added in 1.9
* @note available in python bindings as doActionFeatureSubstitution
*/
void doActionFeatureWithSubstitution( int index,
QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap = 0 );
%MethodCode
sipCpp->doAction( a0, *a1, a2 );
%End

//! Removes all actions
void clearActions();
@@ -68,7 +96,22 @@ class QgsAttributeAction
/*! Expands the given action, replacing all %'s with the value as
* given.
*/
QString expandAction( QString action, const QMap<int, QVariant> &values, uint defaultValueIndex );
QString expandAction( QString action, const QMap<int, QVariant> &attributes, uint defaultValueIndex );

/*! Expands the given action using the expression builder
* This function currently replaces each expression between [% and %]
* placeholders in the action with the result of its evaluation on
* the feature passed as argument.
*
* Additional substitutions can be passed through the substitutionMap
* parameter
*
* @note added in 1.9
*/
QString expandAction( QString action,
QgsFeature &feat,
const QMap<QString, QVariant> *substitutionMap = 0 );


//! Writes the actions out in XML format
bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;
@@ -121,9 +121,9 @@ class QgsCoordinateTransform : QObject
// C style arrays.
void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform) const throw (QgsCsException);

// TODO: argument not supported
//void transformInPlace(std::vector<double>& x, std::vector<double>& y, std::vector<double>& z,
// TransformDirection direction = ForwardTransform);
// TODO: argument not supported
// void transformInPlace( QVector<double>& x, QVector<double>& y, QVector<double>& z,
// TransformDirection direction = ForwardTransform ) const;

/*! Transform a QgsRectangle to the dest Coordinate system
* If the direction is ForwardTransform then coordinates are transformed from layer CS --> map canvas CS,

0 comments on commit eef8627

Please sign in to comment.
You can’t perform that action at this time.