Skip to content
Permalink
Browse files
use dedicated header for QgsAttributes
  • Loading branch information
3nids committed Mar 30, 2017
1 parent b0564be commit a44eb4d7b0bac970746e64690201a3a9e0950778
@@ -21,6 +21,7 @@
%Include qgsactionscoperegistry.sip
%Include qgsaggregatecalculator.sip
%Include qgsanimatedicon.sip
%Include qgsattributes.sip
%Include qgsattributetableconfig.sip
%Include qgsattributeeditorelement.sip
%Include qgsbearingutils.sip
@@ -0,0 +1,104 @@
/******************************************************************
* This file has been generated automatically by sipify.pl *
* Do not edit manually ! Edit header file and generate it again. *
*****************************************************************/








typedef QMap<int, QVariant> QgsAttributeMap;

typedef QMap<int, QString> QgsFieldNameMap;

typedef QMap<int, QgsField> QgsFieldMap;


typedef QVector<QVariant> QgsAttributes;

%MappedType QgsAttributes
{
%TypeHeaderCode
#include <qgsfeature.h>
%End

%ConvertFromTypeCode
// Create the list.
PyObject *l;

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

// Set the list elements.
for ( int i = 0; i < sipCpp->size(); ++i )
{
QVariant *v = new QVariant( sipCpp->at( i ) );
PyObject *tobj;

if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant, Py_None ) ) == NULL )
{
Py_DECREF( l );
delete v;

return NULL;
}

PyList_SET_ITEM( l, i, tobj );
}

return l;
%End

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

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QVariant, SIP_NOT_NONE ) )
return 0;

return 1;
}

QgsAttributes *qv = new QgsAttributes;

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
{
int state;
PyObject *obj = PyList_GET_ITEM( sipPy, i );
QVariant *t;
if ( obj == Py_None )
{
t = new QVariant( QVariant::Int );
}
else
{
t = reinterpret_cast<QVariant *>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );

if ( *sipIsErr )
{
sipReleaseType( t, sipType_QVariant, state );

delete qv;
return 0;
}
}

qv->append( *t );

sipReleaseType( t, sipType_QVariant, state );
}

*sipCppPtr = qv;

return sipGetState( sipTransferObj );
%End
};


@@ -12,93 +12,6 @@

typedef qint64 QgsFeatureId;

typedef QMap<int, QVariant> QgsAttributeMap;

typedef QVector<QVariant> QgsAttributes;

%MappedType QgsAttributes
{
%TypeHeaderCode
#include <qgsfeature.h>
%End

%ConvertFromTypeCode
// Create the list.
PyObject *l;

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

// Set the list elements.
for ( int i = 0; i < sipCpp->size(); ++i )
{
QVariant *v = new QVariant( sipCpp->at( i ) );
PyObject *tobj;

if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant, Py_None ) ) == NULL )
{
Py_DECREF( l );
delete v;

return NULL;
}

PyList_SET_ITEM( l, i, tobj );
}

return l;
%End

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

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QVariant, SIP_NOT_NONE ) )
return 0;

return 1;
}

QgsAttributes *qv = new QgsAttributes;

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
{
int state;
PyObject *obj = PyList_GET_ITEM( sipPy, i );
QVariant *t;
if ( obj == Py_None )
{
t = new QVariant( QVariant::Int );
}
else
{
t = reinterpret_cast<QVariant *>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );

if ( *sipIsErr )
{
sipReleaseType( t, sipType_QVariant, state );

delete qv;
return 0;
}
}

qv->append( *t );

sipReleaseType( t, sipType_QVariant, state );
}

*sipCppPtr = qv;

return sipGetState( sipTransferObj );
%End
};



class QgsFeature
{
@@ -535,11 +448,6 @@ typedef QMap<qint64, QgsGeometry> QgsGeometryMap;

typedef QSet<qint64> QgsFeatureIds;

typedef QMap<int, QString> QgsFieldNameMap;


typedef QMap<int, QgsField> QgsFieldMap;

typedef QList<QgsFeature> QgsFeatureList;

// uint qHash( const QgsFeature &key, uint seed = 0 ); // SIP_SKIP
@@ -95,6 +95,7 @@ SET(QGIS_CORE_SRCS
qgsactionmanager.cpp
qgsaggregatecalculator.cpp
qgsanimatedicon.cpp
qgsattributes.cpp
qgsattributetableconfig.cpp
qgsattributeeditorelement.cpp
qgsbearingutils.cpp
@@ -663,6 +664,7 @@ SET(QGIS_CORE_HDRS
qgsactionscope.h
qgsactionmanager.h
qgsaggregatecalculator.h
qgsattributes.h
qgsattributetableconfig.h
qgsattributeeditorelement.h
qgsbearingutils.h
@@ -0,0 +1,31 @@
/***************************************************************************
qgsattributes.cpp - QgsAttributes
---------------------
begin : 29.3.2017
copyright : (C) 2017 by Denis Rouzaud
email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program 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 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsattributes.h"



QgsAttributeMap QgsAttributes::toMap() const
{
QgsAttributeMap map;
for ( int idx = 0; idx < count(); ++idx )
{
QVariant v = at( idx );
if ( v.isValid() )
map.insert( idx, v );
}
return map;
}

0 comments on commit a44eb4d

Please sign in to comment.