Skip to content

Commit eef8627

Browse files
committed
more sip fixes
1 parent 60ab4b3 commit eef8627

17 files changed

Lines changed: 241 additions & 91 deletions

‎python/core/conversions.sip‎

Lines changed: 117 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ which are not wrapped by PyQt:
1010
- QSet<TYPE>
1111
- QMap<qint64, QMap<int, TYPE> >
1212
- QMap<QString, QVariant::Type>
13+
- QMap<QString, int>
1314
- QMap<TYPE1, TYPE2*>
1415
- QMap<double, TYPE>
1516
- QMultiMap<double, TYPE2>
1617
- QMap<qint64, QgsGeometry>
1718
- QMap<qint64, QgsOverlayObject*>
19+
- QList< QPair< QString, QList<QString> > >
20+
- QVector<TYPE*>
1821
*/
1922

2023
%Feature QSETINT_CONVERSION
2124
%Feature QSETTYPE_CONVERSION
2225

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

3337

34-
3538
template <TYPE>
3639
%MappedType QVector< QVector<TYPE> >
3740
{
@@ -110,10 +113,10 @@ template <TYPE>
110113
*sipCppPtr = ql;
111114
return sipGetState(sipTransferObj);
112115
%End
113-
114116
};
115117

116118

119+
117120
template <TYPE>
118121
%MappedType QVector< QVector< QVector<TYPE> > >
119122
{
@@ -192,7 +195,6 @@ template <TYPE>
192195
*sipCppPtr = ql;
193196
return sipGetState(sipTransferObj);
194197
%End
195-
196198
};
197199

198200

@@ -269,7 +271,6 @@ template <TYPE>
269271
*sipCppPtr = ql;
270272
return sipGetState(sipTransferObj);
271273
%End
272-
273274
};
274275

275276

@@ -326,10 +327,11 @@ template <TYPE>
326327
*sipCppPtr = qset;
327328
return sipGetState(sipTransferObj);
328329
%End
329-
330330
};
331331
%End
332332

333+
334+
333335
%MappedType QList<qint64>
334336
{
335337
%TypeHeaderCode
@@ -375,9 +377,10 @@ template <TYPE>
375377
*sipCppPtr = qlist;
376378
return sipGetState(sipTransferObj);
377379
%End
378-
379380
};
380381

382+
383+
381384
%MappedType QSet<qint64>
382385
{
383386
%TypeHeaderCode
@@ -423,9 +426,10 @@ template <TYPE>
423426
*sipCppPtr = qset;
424427
return sipGetState(sipTransferObj);
425428
%End
426-
427429
};
428430

431+
432+
429433
%If (QSETTYPE_CONVERSION)
430434
template <TYPE>
431435
%MappedType QSet<TYPE>
@@ -503,6 +507,8 @@ template <TYPE>
503507
};
504508
%End
505509

510+
511+
506512
template<TYPE>
507513
%MappedType QMap<qint64, QMap<int, TYPE> >
508514
{
@@ -627,6 +633,8 @@ template<TYPE>
627633
%End
628634
};
629635

636+
637+
630638
%MappedType QMap<qint64, QgsGeometry>
631639
{
632640
%TypeHeaderCode
@@ -711,6 +719,8 @@ template<TYPE>
711719
%End
712720
};
713721

722+
723+
714724
%MappedType QMap<QString, QVariant::Type>
715725
{
716726
%TypeHeaderCode
@@ -817,6 +827,8 @@ template<TYPE>
817827
%End
818828
};
819829

830+
831+
820832
%MappedType QMap<QString, int>
821833
{
822834
%TypeHeaderCode
@@ -920,6 +932,8 @@ template<TYPE>
920932
%End
921933
};
922934

935+
936+
923937
template<TYPE1, TYPE2>
924938
%MappedType QMap<TYPE1, TYPE2*>
925939
{
@@ -1133,7 +1147,6 @@ template<double, TYPE>
11331147

11341148

11351149

1136-
11371150
template<double, TYPE2>
11381151
%MappedType QMultiMap<double, TYPE2>
11391152
{
@@ -1231,8 +1244,7 @@ template<double, TYPE2>
12311244
double k = PyFloat_AsDouble(t1obj);
12321245
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
12331246
TYPE2 *t2 =
1234-
reinterpret_cast<TYPE2 *>(sipConvertToInstance(PyList_GET_ITEM(t2obj,
1235-
i),
1247+
reinterpret_cast<TYPE2 *>(sipConvertToInstance(PyList_GET_ITEM(t2obj, i),
12361248
sipClass_TYPE2,
12371249
sipTransferObj,
12381250
SIP_NOT_NONE,
@@ -1257,7 +1269,9 @@ template<double, TYPE2>
12571269

12581270
return sipGetState(sipTransferObj);
12591271
%End
1260-
};
1272+
};
1273+
1274+
12611275

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

1359+
1360+
13451361
%MappedType QList < QPair< QString, QList<QString> > >
13461362
{
13471363
%TypeHeaderCode
@@ -1426,3 +1442,93 @@ template<double, TYPE2>
14261442
return sipGetState(sipTransferObj);
14271443
%End
14281444
};
1445+
1446+
1447+
1448+
template <TYPE>
1449+
%MappedType QVector< TYPE* >
1450+
{
1451+
%TypeHeaderCode
1452+
#include <QVector>
1453+
#if (SIP_VERSION >= 0x040900)
1454+
#define sipClass_QString ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QString))
1455+
#endif
1456+
#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01)
1457+
#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
1458+
#endif
1459+
%End
1460+
1461+
%ConvertFromTypeCode
1462+
// Create the list
1463+
PyObject *l = PyList_New(sipCpp->size());
1464+
1465+
if (!l)
1466+
return NULL;
1467+
1468+
// Set the dictionary elements.
1469+
for( int i = 0; i < sipCpp->size(); i++ )
1470+
{
1471+
TYPE *t = sipCpp->at(i);
1472+
PyObject *tobj = sipConvertFromInstance(t, sipClass_TYPE, sipTransferObj);
1473+
1474+
if (tobj == NULL || PyList_SetItem(l, i, tobj) < 0)
1475+
{
1476+
Py_DECREF(l);
1477+
1478+
if (tobj)
1479+
Py_DECREF(tobj);
1480+
else
1481+
delete t;
1482+
1483+
return NULL;
1484+
}
1485+
1486+
Py_DECREF(tobj);
1487+
}
1488+
1489+
return l;
1490+
%End
1491+
1492+
%ConvertToTypeCode
1493+
PyObject *tobj;
1494+
1495+
// Check the type if that is all that is required.
1496+
if (sipIsErr == NULL)
1497+
{
1498+
if (!PyList_Check(sipPy))
1499+
return 0;
1500+
1501+
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
1502+
{
1503+
if (!sipCanConvertToInstance(tobj, sipClass_TYPE, SIP_NOT_NONE))
1504+
return 0;
1505+
}
1506+
1507+
return 1;
1508+
}
1509+
1510+
QVector<TYPE*> *v = new QVector<TYPE*>( PyList_GET_SIZE(sipPy) );
1511+
1512+
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
1513+
{
1514+
int state;
1515+
1516+
TYPE *t = reinterpret_cast<TYPE *>(sipConvertToInstance(tobj, sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
1517+
1518+
if (*sipIsErr)
1519+
{
1520+
sipReleaseInstance(t, sipClass_TYPE, state);
1521+
delete v;
1522+
return 0;
1523+
}
1524+
1525+
v->replace( i, t );
1526+
1527+
sipReleaseInstance(t, sipClass_TYPE, state);
1528+
}
1529+
1530+
*sipCppPtr = v;
1531+
1532+
return sipGetState(sipTransferObj);
1533+
%End
1534+
};

‎python/core/qgsattributeaction.sip‎

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class QgsAttributeAction
3838
#include "qgsattributeaction.h"
3939
%End
4040
public:
41-
QgsAttributeAction( QgsVectorLayer * );
41+
//! Constructor
42+
QgsAttributeAction( QgsVectorLayer *layer );
4243

4344
//! Destructor
4445
virtual ~QgsAttributeAction();
@@ -55,9 +56,36 @@ class QgsAttributeAction
5556
* is to be used if the action has a default placeholder.
5657
* @note added to python API in 1.6 (without executePython parameter)
5758
* @deprecated
59+
*/
5860
void doAction( int index,
59-
const QMap<int, QVariant> &values,
60-
int defaultValueIndex = 0 );
61+
const QMap<int, QVariant> &attributes,
62+
int defaultValueIndex = 0 ) /Deprecated/;
63+
64+
/*! Does the given values. defaultValueIndex is the index of the
65+
* field to be used if the action has a $currfield placeholder.
66+
* @note added in 1.9
67+
* @note not available in python bindings
68+
*/
69+
void doActionFeature( int index,
70+
QgsFeature &feat,
71+
int defaultValueIndex = 0 );
72+
%MethodCode
73+
sipCpp->doAction( a0, *a1, a2 );
74+
%End
75+
76+
/*! Does the action using the expression builder to expand it
77+
* and getting values from the passed feature attribute map.
78+
* substitutionMap is used to pass custom substitutions, to replace
79+
* each key in the map with the associated value
80+
* @note added in 1.9
81+
* @note available in python bindings as doActionFeatureSubstitution
82+
*/
83+
void doActionFeatureWithSubstitution( int index,
84+
QgsFeature &feat,
85+
const QMap<QString, QVariant> *substitutionMap = 0 );
86+
%MethodCode
87+
sipCpp->doAction( a0, *a1, a2 );
88+
%End
6189

6290
//! Removes all actions
6391
void clearActions();
@@ -68,7 +96,22 @@ class QgsAttributeAction
6896
/*! Expands the given action, replacing all %'s with the value as
6997
* given.
7098
*/
71-
QString expandAction( QString action, const QMap<int, QVariant> &values, uint defaultValueIndex );
99+
QString expandAction( QString action, const QMap<int, QVariant> &attributes, uint defaultValueIndex );
100+
101+
/*! Expands the given action using the expression builder
102+
* This function currently replaces each expression between [% and %]
103+
* placeholders in the action with the result of its evaluation on
104+
* the feature passed as argument.
105+
*
106+
* Additional substitutions can be passed through the substitutionMap
107+
* parameter
108+
*
109+
* @note added in 1.9
110+
*/
111+
QString expandAction( QString action,
112+
QgsFeature &feat,
113+
const QMap<QString, QVariant> *substitutionMap = 0 );
114+
72115

73116
//! Writes the actions out in XML format
74117
bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const;

‎python/core/qgscoordinatetransform.sip‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ class QgsCoordinateTransform : QObject
121121
// C style arrays.
122122
void transformInPlace( double& x, double& y, double &z, TransformDirection direction = ForwardTransform) const throw (QgsCsException);
123123

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

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

0 commit comments

Comments
 (0)