Skip to content

Commit

Permalink
more sip fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Sep 24, 2012
1 parent 60ab4b3 commit eef8627
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 91 deletions.
128 changes: 117 additions & 11 deletions python/core/conversions.sip
Expand Up @@ -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
Expand All @@ -31,7 +35,6 @@ typedef int Py_ssize_t;
%End



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

};



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

};


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

};


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

};
%End



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

};



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

};



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



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



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



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



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



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




template<double, TYPE2>
%MappedType QMultiMap<double, TYPE2>
{
Expand Down Expand Up @@ -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,
Expand All @@ -1257,7 +1269,9 @@ template<double, TYPE2>

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



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



%MappedType QList < QPair< QString, QList<QString> > >
{
%TypeHeaderCode
Expand Down Expand Up @@ -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
};
51 changes: 47 additions & 4 deletions python/core/qgsattributeaction.sip
Expand Up @@ -38,7 +38,8 @@ class QgsAttributeAction
#include "qgsattributeaction.h"
%End
public:
QgsAttributeAction( QgsVectorLayer * );
//! Constructor
QgsAttributeAction( QgsVectorLayer *layer );

//! Destructor
virtual ~QgsAttributeAction();
Expand All @@ -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();
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions python/core/qgscoordinatetransform.sip
Expand Up @@ -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,
Expand Down

0 comments on commit eef8627

Please sign in to comment.