Skip to content
Permalink
Browse files

[labeling] Fix python bindings for access to data defined properties

  • Loading branch information
dakcarto committed Aug 31, 2013
1 parent 1a8a293 commit c9c013572fd8b7fc583d5fa7c7721e121274999d
Showing with 87 additions and 22 deletions.
  1. +84 −9 python/core/qgspallabeling.sip
  2. +0 −5 src/core/qgspallabeling.cpp
  3. +3 −8 src/core/qgspallabeling.h
@@ -1,3 +1,83 @@
// QMap<QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined*> is implemented as a Python dictionary.
%MappedType QMap<QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined*> /DocType="dict-of-QgsPalLayerSettings.DataDefinedProperties-QgsDataDefined*"/
{
%TypeHeaderCode
#include <qmap.h>
#include <qgspallabeling.h>
#include <qgsdatadefined.h>
%End
%ConvertFromTypeCode
// Create the dictionary.
PyObject *d = PyDict_New();
if (!d)
return NULL;
// Set the dictionary elements.
QMap<QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined*>::const_iterator i = sipCpp->constBegin();
while (i != sipCpp->constEnd())
{
QgsDataDefined *t = i.value();
PyObject *kobj = sipConvertFromEnum(i.key(), sipType_QgsPalLayerSettings_DataDefinedProperties);
PyObject *tobj = sipConvertFromType(t, sipType_QgsDataDefined, sipTransferObj);
if (kobj == NULL || tobj == NULL || PyDict_SetItem(d, kobj, tobj) < 0)
{
Py_DECREF(d);
if (kobj)
{
Py_DECREF(kobj);
}
if (tobj)
{
Py_DECREF(tobj);
}
else
{
delete t;
}
return NULL;
}
Py_DECREF(kobj);
Py_DECREF(tobj);
++i;
}
return d;
%End
%ConvertToTypeCode
PyObject *kobj, *tobj;
SIP_SSIZE_T i = 0;
// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyDict_Check(sipPy))
return 0;
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
if (!sipCanConvertToType(tobj, sipType_QgsDataDefined, SIP_NOT_NONE))
return 0;
return 1;
}
QMap<QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined*> *qm = new QMap<QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined*>;

while (PyDict_Next(sipPy, &i, &kobj, &tobj))
{
int state, k = SIPLong_AsLong(kobj);
QgsDataDefined *t = reinterpret_cast<QgsDataDefined *>(sipConvertToType(tobj, sipType_QgsDataDefined, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
sipReleaseType(t, sipType_QgsDataDefined, state);
delete qm;
return 0;
}
qm->insert(QgsPalLayerSettings::DataDefinedProperties(k), t);
sipReleaseType(t, sipType_QgsDataDefined, state);
}

*sipCppPtr = qm;

return sipGetState(sipTransferObj);
%End
};


class QgsPalLayerSettings
{
%TypeHeaderCode
@@ -361,12 +441,7 @@ class QgsPalLayerSettings
/** Get a data defined property pointer
* @note added in 1.9, helpful for Python access
*/
QgsDataDefined* dataDefinedProperty( DataDefinedProperties p );

/** Get current data defined properties
* @note added in 1.9, helpful for Python access
*/
QList<QgsPalLayerSettings::DataDefinedProperties> dataDefinedPropertyList();
QgsDataDefined* dataDefinedProperty( QgsPalLayerSettings::DataDefinedProperties p );

/** Set a property as data defined
* @note added in 1.9, helpful for Python access
@@ -407,9 +482,9 @@ class QgsPalLayerSettings
*/
bool dataDefinedUseExpression( QgsPalLayerSettings::DataDefinedProperties p ) const;

/**Stores field names for data defined layer properties*/
//! @note not available in python bindings
//QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > dataDefinedProperties;
/** Map of current data defined properties
*/
QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > dataDefinedProperties;


/** Calculates pixel size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
@@ -1170,11 +1170,6 @@ QgsDataDefined* QgsPalLayerSettings::dataDefinedProperty( DataDefinedProperties
return 0;
}

QList<QgsPalLayerSettings::DataDefinedProperties> QgsPalLayerSettings::dataDefinedPropertyList()
{
return dataDefinedProperties.keys();
}

QMap<QString, QString> QgsPalLayerSettings::dataDefinedMap( DataDefinedProperties p ) const
{
QMap<QString, QString> map;
@@ -415,12 +415,7 @@ class CORE_EXPORT QgsPalLayerSettings
/** Get a data defined property pointer
* @note added in 1.9, helpful for Python access
*/
QgsDataDefined* dataDefinedProperty( DataDefinedProperties p );

/** Get current data defined properties
* @note added in 1.9, helpful for Python access
*/
QList<QgsPalLayerSettings::DataDefinedProperties> dataDefinedPropertyList();
QgsDataDefined* dataDefinedProperty( QgsPalLayerSettings::DataDefinedProperties p );

/** Set a property as data defined
* @note added in 1.9, helpful for Python access
@@ -461,8 +456,8 @@ class CORE_EXPORT QgsPalLayerSettings
*/
bool dataDefinedUseExpression( QgsPalLayerSettings::DataDefinedProperties p ) const;

/**Stores field names for data defined layer properties*/
//! @note not available in python bindings
/** Map of current data defined properties
*/
QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > dataDefinedProperties;


0 comments on commit c9c0135

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