From 7b08608f7fc78d4fa3fbc5dbbd31ccbf5addd72a Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Mon, 27 Mar 2017 14:41:33 +0200 Subject: [PATCH] sipify QgsVectorLayer, QgsFeature --- python/core/qgsfeature.sip | 510 ++++++++++++++------------- python/core/qgsvectorlayer.sip | 621 +++++++++++++++++---------------- scripts/sipify.pl | 8 +- 3 files changed, 599 insertions(+), 540 deletions(-) diff --git a/python/core/qgsfeature.sip b/python/core/qgsfeature.sip index abcadf3f66e..70e549fe055 100644 --- a/python/core/qgsfeature.sip +++ b/python/core/qgsfeature.sip @@ -1,126 +1,121 @@ +/****************************************************************** + * This file has been generated automatically by sipify.pl * + * Do not edit manually ! Edit header file and generate it again. * + *****************************************************************/ + + + + + + + typedef qint64 QgsFeatureId; + typedef QMap QgsAttributeMap; + typedef QVector QgsAttributes; -// QgsAttributes is implemented as a Python list of Python objects. %MappedType QgsAttributes { %TypeHeaderCode -#include // NO_SIPIFY +#include %End %ConvertFromTypeCode - // Create the list. - PyObject *l; + // Create the list. + PyObject *l; - if ( ( l = PyList_New(sipCpp->size() ) ) == NULL ) - return NULL; + if ( ( l = PyList_New( sipCpp->size() ) ) == NULL ) + return NULL; - // Set the list elements. - for ( int i = 0; i < sipCpp->size(); ++i ) + // 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 ) { - QVariant *v = new QVariant( sipCpp->at( i ) ); - PyObject *tobj; + Py_DECREF( l ); + delete v; - if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant,Py_None ) ) == NULL ) - { - Py_DECREF( l ); - delete v; - - return NULL; - } - - PyList_SET_ITEM( l, i, tobj ); + return NULL; } - return l; + 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)) + // 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; - 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; + } - return 1; - } + QgsAttributes *qv = new QgsAttributes; - QgsAttributes *qv = new QgsAttributes; - - for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i) + 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 ) { - int state; - PyObject *obj = PyList_GET_ITEM(sipPy, i); - QVariant *t; - if ( obj == Py_None ) + t = new QVariant( QVariant::Int ); + } + else + { + t = reinterpret_cast( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) ); + + if ( *sipIsErr ) { - t = new QVariant( QVariant::Int ); + sipReleaseType( t, sipType_QVariant, state ); + + delete qv; + return 0; } - else - { - t = reinterpret_cast(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; + qv->append( *t ); - return sipGetState(sipTransferObj); + sipReleaseType( t, sipType_QVariant, state ); + } + + *sipCppPtr = qv; + + return sipGetState( sipTransferObj ); %End }; -// key = feature id, value = changed attributes -typedef QMap > QgsChangedAttributesMap; -// key = feature id, value = changed geometry -typedef QMap QgsGeometryMap; -// key = field index, value = field name -typedef QMap QgsFieldNameMap; - -typedef QList QgsFeatureList; - -typedef QMap QgsFieldMap; - -/** \ingroup core - * The feature class encapsulates a single feature including its id, - * geometry and a list of field/values attributes. - * \note QgsFeature objects are implicitly shared. - * @author Gary E.Sherman - */ class QgsFeature { -%TypeHeaderCode -#include -#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01) -#define sipType_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) -#endif -%End %Docstring -/** \ingroup core The feature class encapsulates a single feature including its id, geometry and a list of field/values attributes. \note QgsFeature objects are implicitly shared. @author Gary E.Sherman -/ + +%End + +%TypeHeaderCode +#include "qgsfeature.h" +#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01) +#define sipType_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) +#endif %End @@ -130,101 +125,101 @@ class QgsFeature %MethodCode QgsAttributes attributes = sipCpp->attributes(); PyObject *attrs = sipConvertFromType( &attributes, sipType_QgsAttributes, Py_None ); - sipRes = PyObject_GetIter(attrs); + sipRes = PyObject_GetIter( attrs ); %End - SIP_PYOBJECT __getitem__(int key); + SIP_PYOBJECT __getitem__( int key ); %MethodCode - QgsAttributes attrs = sipCpp->attributes(); - if (a0 < 0 || a0 >= attrs.count()) - { - PyErr_SetString(PyExc_KeyError, QByteArray::number(a0)); - sipIsErr = 1; - } - else - { - QVariant *v = new QVariant( attrs.at(a0) ); - sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None ); - } -%End - - SIP_PYOBJECT __getitem__(const QString &name); -%MethodCode - int fieldIdx = sipCpp->fieldNameIndex(*a0); - if (fieldIdx == -1) - { - PyErr_SetString(PyExc_KeyError, a0->toAscii()); - sipIsErr = 1; - } - else - { - QVariant *v = new QVariant( sipCpp->attribute(fieldIdx) ); - sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None ); - } -%End - - void __setitem__(int key, QVariant value /GetWrapper/); -%MethodCode - bool rv; - - if ( a1Wrapper == Py_None ) - { - rv = sipCpp->setAttribute(a0, QVariant( QVariant::Int ) ); - } - else - { - rv = sipCpp->setAttribute(a0, *a1); - } - - if ( !rv ) - { - PyErr_SetString(PyExc_KeyError, QByteArray::number(a0)); - sipIsErr = 1; - } -%End - - void __setitem__(const QString &key, QVariant value /GetWrapper/); -%MethodCode - int fieldIdx = sipCpp->fieldNameIndex(*a0); - if (fieldIdx == -1) - { - PyErr_SetString(PyExc_KeyError, a0->toAscii()); - sipIsErr = 1; - } - else - { - if ( a1Wrapper == Py_None ) + QgsAttributes attrs = sipCpp->attributes(); + if ( a0 < 0 || a0 >= attrs.count() ) { - sipCpp->setAttribute(*a0, QVariant( QVariant::Int ) ); + PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); + sipIsErr = 1; } else { - sipCpp->setAttribute(fieldIdx, *a1); + QVariant *v = new QVariant( attrs.at( a0 ) ); + sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None ); } - } %End - void __delitem__(int key); + SIP_PYOBJECT __getitem__( const QString &name ); %MethodCode - if (a0 >= 0 && a0 < sipCpp->attributes().count()) - sipCpp->deleteAttribute(a0); - else - { - PyErr_SetString(PyExc_KeyError, QByteArray::number(a0)); - sipIsErr = 1; - } + int fieldIdx = sipCpp->fieldNameIndex( *a0 ); + if ( fieldIdx == -1 ) + { + PyErr_SetString( PyExc_KeyError, a0->toAscii() ); + sipIsErr = 1; + } + else + { + QVariant *v = new QVariant( sipCpp->attribute( fieldIdx ) ); + sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None ); + } %End - void __delitem__(const QString &name); + void __setitem__( int key, QVariant value /GetWrapper/ ); %MethodCode - int fieldIdx = sipCpp->fieldNameIndex(*a0); - if (fieldIdx == -1) - { - PyErr_SetString(PyExc_KeyError, a0->toAscii()); - sipIsErr = 1; - } - else - sipCpp->deleteAttribute(fieldIdx); + bool rv; + + if ( a1Wrapper == Py_None ) + { + rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) ); + } + else + { + rv = sipCpp->setAttribute( a0, *a1 ); + } + + if ( !rv ) + { + PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); + sipIsErr = 1; + } +%End + + void __setitem__( const QString &key, QVariant value /GetWrapper/ ); +%MethodCode + int fieldIdx = sipCpp->fieldNameIndex( *a0 ); + if ( fieldIdx == -1 ) + { + PyErr_SetString( PyExc_KeyError, a0->toAscii() ); + sipIsErr = 1; + } + else + { + if ( a1Wrapper == Py_None ) + { + sipCpp->setAttribute( *a0, QVariant( QVariant::Int ) ); + } + else + { + sipCpp->setAttribute( fieldIdx, *a1 ); + } + } +%End + + void __delitem__( int key ); +%MethodCode + if ( a0 >= 0 && a0 < sipCpp->attributes().count() ) + sipCpp->deleteAttribute( a0 ); + else + { + PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); + sipIsErr = 1; + } +%End + + void __delitem__( const QString &name ); +%MethodCode + int fieldIdx = sipCpp->fieldNameIndex( *a0 ); + if ( fieldIdx == -1 ) + { + PyErr_SetString( PyExc_KeyError, a0->toAscii() ); + sipIsErr = 1; + } + else + sipCpp->deleteAttribute( fieldIdx ); %End QgsFeature( qint64 id = 0 ); @@ -233,7 +228,16 @@ class QgsFeature QgsFeature( const QgsFeature &rhs ); - ~QgsFeature(); + // QgsFeature &operator=( const QgsFeature &rhs ); // SIP_SKIP + + + // bool operator==( const QgsFeature &other ) const; // SIP_SKIP + + + // bool operator!=( const QgsFeature &other ) const; // SIP_SKIP + + + virtual ~QgsFeature(); QgsFeatureId id() const; @@ -243,39 +247,39 @@ class QgsFeature void setAttributes( const QgsAttributes &attrs ); - bool setAttribute( int field, const QVariant &attr /GetWrapper/); + bool setAttribute( int field, const QVariant &attr /GetWrapper/ ); %MethodCode - bool rv; + bool rv; - if ( a1Wrapper == Py_None ) - { - rv = sipCpp->setAttribute(a0, QVariant( QVariant::Int ) ); - } - else - { - rv = sipCpp->setAttribute(a0, *a1); - } + if ( a1Wrapper == Py_None ) + { + rv = sipCpp->setAttribute( a0, QVariant( QVariant::Int ) ); + } + else + { + rv = sipCpp->setAttribute( a0, *a1 ); + } - if ( !rv ) - { - PyErr_SetString(PyExc_KeyError, QByteArray::number(a0)); - sipIsErr = 1; - } + if ( !rv ) + { + PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); + sipIsErr = 1; + } - sipRes = rv; + sipRes = rv; %End void initAttributes( int fieldCount ); void deleteAttribute( int field ); %MethodCode - if ( a0 >= 0 && a0 < sipCpp->attributes().count() ) - sipCpp->deleteAttribute(a0); - else - { - PyErr_SetString(PyExc_KeyError, QByteArray::number(a0)); - sipIsErr = 1; - } + if ( a0 >= 0 && a0 < sipCpp->attributes().count() ) + sipCpp->deleteAttribute( a0 ); + else + { + PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); + sipIsErr = 1; + } %End bool isValid() const; @@ -296,77 +300,97 @@ class QgsFeature void setAttribute( const QString &name, const QVariant &value /GetWrapper/ ); %MethodCode - int fieldIdx = sipCpp->fieldNameIndex(*a0); - if (fieldIdx == -1) - { - PyErr_SetString(PyExc_KeyError, a0->toAscii()); - sipIsErr = 1; - } - else - { - if ( a1Wrapper == Py_None ) + int fieldIdx = sipCpp->fieldNameIndex( *a0 ); + if ( fieldIdx == -1 ) { - sipCpp->setAttribute(*a0, QVariant( QVariant::Int ) ); - } - else - { - sipCpp->setAttribute(fieldIdx, *a1); - } - } -%End - - bool deleteAttribute( const QString &name ); -%MethodCode - int fieldIdx = sipCpp->fieldNameIndex(*a0); - if (fieldIdx == -1) - { - PyErr_SetString(PyExc_KeyError, a0->toAscii()); - sipIsErr = 1; - sipRes = false; - } - else - { - sipCpp->deleteAttribute( fieldIdx ); - sipRes = true; - } -%End - - SIP_PYOBJECT attribute( const QString &name ) const; -%MethodCode - int fieldIdx = sipCpp->fieldNameIndex(*a0); - if (fieldIdx == -1) - { - PyErr_SetString(PyExc_KeyError, a0->toAscii()); - sipIsErr = 1; - } - else - { - QVariant *v = new QVariant( sipCpp->attribute(fieldIdx) ); - sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None ); - } -%End - - SIP_PYOBJECT attribute( int fieldIdx ) const; -%MethodCode - { - if (a0 < 0 || a0 >= sipCpp->attributes().count()) - { - PyErr_SetString(PyExc_KeyError, QByteArray::number(a0)); + PyErr_SetString( PyExc_KeyError, a0->toAscii() ); sipIsErr = 1; } else { - QVariant *v = new QVariant( sipCpp->attribute(a0) ); + if ( a1Wrapper == Py_None ) + { + sipCpp->setAttribute( *a0, QVariant( QVariant::Int ) ); + } + else + { + sipCpp->setAttribute( fieldIdx, *a1 ); + } + } +%End + + bool deleteAttribute( const QString &name ); +%MethodCode + int fieldIdx = sipCpp->fieldNameIndex( *a0 ); + if ( fieldIdx == -1 ) + { + PyErr_SetString( PyExc_KeyError, a0->toAscii() ); + sipIsErr = 1; + sipRes = false; + } + else + { + sipCpp->deleteAttribute( fieldIdx ); + sipRes = true; + } +%End + + SIP_PYOBJECT attribute( const QString &name ) const; +%MethodCode + int fieldIdx = sipCpp->fieldNameIndex( *a0 ); + if ( fieldIdx == -1 ) + { + PyErr_SetString( PyExc_KeyError, a0->toAscii() ); + sipIsErr = 1; + } + else + { + QVariant *v = new QVariant( sipCpp->attribute( fieldIdx ) ); sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None ); } - } +%End + + SIP_PYOBJECT attribute( int fieldIdx ) const; +%MethodCode + { + if ( a0 < 0 || a0 >= sipCpp->attributes().count() ) + { + PyErr_SetString( PyExc_KeyError, QByteArray::number( a0 ) ); + sipIsErr = 1; + } + else + { + QVariant *v = new QVariant( sipCpp->attribute( a0 ) ); + sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None ); + } + } %End int fieldNameIndex( const QString &fieldName ) const; - //! Allows direct construction of QVariants from features. operator QVariant() const; }; // class QgsFeature +// CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsFeature &feature ); // SIP_SKIP + +// CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsFeature &feature ); // SIP_SKIP + + +typedef QMap > QgsChangedAttributesMap; + +typedef QMap QgsGeometryMap; + typedef QSet QgsFeatureIds; + +typedef QMap QgsFieldNameMap; + + +typedef QMap QgsFieldMap; + +typedef QList QgsFeatureList; + +// uint qHash( const QgsFeature &key, uint seed = 0 ); // SIP_SKIP + + + diff --git a/python/core/qgsvectorlayer.sip b/python/core/qgsvectorlayer.sip index d3d918abe37..34456e499ba 100644 --- a/python/core/qgsvectorlayer.sip +++ b/python/core/qgsvectorlayer.sip @@ -1,290 +1,307 @@ +/****************************************************************** + * This file has been generated automatically by sipify.pl * + * Do not edit manually ! Edit header file and generate it again. * + *****************************************************************/ + + + + + + + typedef QList QgsAttributeList; typedef QSet QgsAttributeIds; +typedef QList QgsPointSequence; + -/** \ingroup core - * Represents a vector layer which manages a vector based data sets. - * - * The QgsVectorLayer is instantiated by specifying the name of a data provider, - * such as postgres or wfs, and url defining the specific data set to connect to. - * The vector layer constructor in turn instantiates a QgsVectorDataProvider subclass - * corresponding to the provider type, and passes it the url. The data provider - * connects to the data source. - * - * The QgsVectorLayer provides a common interface to the different data types. It also - * manages editing transactions. - * - * Sample usage of the QgsVectorLayer class: - * - * \code - * QString uri = "point?crs=epsg:4326&field=id:integer"; - * QgsVectorLayer *scratchLayer = new QgsVectorLayer(uri, "Scratch point layer", "memory"); - * \endcode - * - * The main data providers supported by QGIS are listed below. - * - * \section providers Vector data providers - * - * \subsection memory Memory data providerType (memory) - * - * The memory data provider is used to construct in memory data, for example scratch - * data or data generated from spatial operations such as contouring. There is no - * inherent persistent storage of the data. The data source uri is constructed. The - * url specifies the geometry type ("point", "linestring", "polygon", - * "multipoint","multilinestring","multipolygon"), optionally followed by url parameters - * as follows: - * - * - crs=definition - * Defines the coordinate reference system to use for the layer. - * definition is any string accepted by QgsCoordinateReferenceSystem::createFromString() - * - * - index=yes - * Specifies that the layer will be constructed with a spatial index - * - * - field=name:type(length,precision) - * Defines an attribute of the layer. Multiple field parameters can be added - * to the data provider definition. type is one of "integer", "double", "string". - * - * An example url is "Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes" - * - * \subsection ogr OGR data provider (ogr) - * - * Accesses data using the OGR drivers (http://www.gdal.org/ogr/ogr_formats.html). The url - * is the OGR connection string. A wide variety of data formats can be accessed using this - * driver, including file based formats used by many GIS systems, database formats, and - * web services. Some of these formats are also supported by custom data providers listed - * below. - * - * \subsection spatialite Spatialite data provider (spatialite) - * - * Access data in a spatialite database. The url defines the connection parameters, table, - * geometry column, and other attributes. The url can be constructed using the - * QgsDataSourceUri class. - * - * \subsection postgres Postgresql data provider (postgres) - * - * Connects to a postgresql database. The url defines the connection parameters, table, - * geometry column, and other attributes. The url can be constructed using the - * QgsDataSourceUri class. - * - * \subsection mssql Microsoft SQL server data provider (mssql) - * - * Connects to a Microsoft SQL server database. The url defines the connection parameters, table, - * geometry column, and other attributes. The url can be constructed using the - * QgsDataSourceUri class. - * - * \subsection wfs WFS (web feature service) data provider (wfs) - * - * Used to access data provided by a web feature service. - * - * The url can be a HTTP url to a WFS server (legacy, e.g. http://foobar/wfs?TYPENAME=xxx&SRSNAME=yyy[&FILTER=zzz]), or, - * starting with QGIS 2.16, a URI constructed using the QgsDataSourceUri class with the following parameters : - * - url=string (mandatory): HTTP url to a WFS server endpoint. e.g http://foobar/wfs - * - typename=string (mandatory): WFS typename - * - srsname=string (recommended): SRS like 'EPSG:XXXX' - * - username=string - * - password=string - * - authcfg=string - * - version=auto/1.0.0/1.1.0/2.0.0 - * -sql=string: full SELECT SQL statement with optional WHERE, ORDER BY and possibly with JOIN if supported on server - * - filter=string: QGIS expression or OGC/FES filter - * - retrictToRequestBBOX=1: to download only features in the view extent (or more generally - * in the bounding box of the feature iterator) - * - maxNumFeatures=number - * - IgnoreAxisOrientation=1: to ignore EPSG axis order for WFS 1.1 or 2.0 - * - InvertAxisOrientation=1: to invert axis order - * - hideDownloadProgressDialog=1: to hide the download progress dialog - * - * The ‘FILTER’ query string parameter can be used to filter - * the WFS feature type. The ‘FILTER’ key value can either be a QGIS expression - * or an OGC XML filter. If the value is set to a QGIS expression the driver will - * turn it into OGC XML filter before passing it to the WFS server. Beware the - * QGIS expression filter only supports” =, !=, <, >, <=, >=, AND, OR, NOT, LIKE, IS NULL” - * attribute operators, “BBOX, Disjoint, Intersects, Touches, Crosses, Contains, Overlaps, Within” - * spatial binary operators and the QGIS local “geomFromWKT, geomFromGML” - * geometry constructor functions. - * - * Also note: - * - * - You can use various functions available in the QGIS Expression list, - * however the function must exist server side and have the same name and arguments to work. - * - * - Use the special $geometry parameter to provide the layer geometry column as input - * into the spatial binary operators e.g intersects($geometry, geomFromWKT('POINT (5 6)')) - * - * \subsection delimitedtext Delimited text file data provider (delimitedtext) - * - * Accesses data in a delimited text file, for example CSV files generated by - * spreadsheets. The contents of the file are split into columns based on specified - * delimiter characters. Each record may be represented spatially either by an - * X and Y coordinate column, or by a WKT (well known text) formatted columns. - * - * The url defines the filename, the formatting options (how the - * text in the file is divided into data fields, and which fields contain the - * X,Y coordinates or WKT text definition. The options are specified as url query - * items. - * - * At its simplest the url can just be the filename, in which case it will be loaded - * as a CSV formatted file. - * - * The url may include the following items: - * - * - encoding=UTF-8 - * - * Defines the character encoding in the file. The default is UTF-8. To use - * the default encoding for the operating system use "System". - * - * - type=(csv|regexp|whitespace|plain) - * - * Defines the algorithm used to split records into columns. Records are - * defined by new lines, except for csv format files for which quoted fields - * may span multiple records. The default type is csv. - * - * - "csv" splits the file based on three sets of characters: - * delimiter characters, quote characters, - * and escape characters. Delimiter characters mark the end - * of a field. Quote characters enclose a field which can contain - * delimiter characters, and newlines. Escape characters cause the - * following character to be treated literally (including delimiter, - * quote, and newline characters). Escape and quote characters must - * be different from delimiter characters. Escape characters that are - * also quote characters are treated specially - they can only - * escape themselves within quotes. Elsewhere they are treated as - * quote characters. The defaults for delimiter, quote, and escape - * are ',', '"', '"'. - * - "regexp" splits each record using a regular expression (see QRegExp - * documentation for details). - * - "whitespace" splits each record based on whitespace (on or more whitespace - * characters. Leading whitespace in the record is ignored. - * - "plain" is provided for backwards compatibility. It is equivalent to - * CSV except that the default quote characters are single and double quotes, - * and there is no escape characters. - * - * - delimiter=characters - * - * Defines the delimiter characters used for csv and plain type files, or the - * regular expression for regexp type files. It is a literal string of characters - * except that "\t" may be used to represent a tab character. - * - * - quote=characters - * - * Defines the characters that are used as quote characters for csv and plain type - * files. - * - * - escape=characters - * - * Defines the characters used to escape delimiter, quote, and newline characters. - * - * - skipLines=n - * - * Defines the number of lines to ignore at the beginning of the file (default 0) - * - * - useHeader=(yes|no) - * - * Defines whether the first record in the file (after skipped lines) contains - * column names (default yes) - * - * - trimFields=(yes|no) - * - * If yes then leading and trailing whitespace will be removed from fields - * - * - skipEmptyFields=(yes|no) - * - * If yes then empty fields will be discarded (equivalent to concatenating consecutive - * delimiters) - * - * - maxFields=# - * - * Specifies the maximum number of fields to load for each record. Additional - * fields will be discarded. Default is 0 - load all fields. - * - * - decimalPoint=c - * - * Defines a character that is used as a decimal point in the numeric columns - * The default is '.'. - * - * - xField=column yField=column - * - * Defines the name of the columns holding the x and y coordinates for XY point geometries. - * If the useHeader is no (ie there are no column names), then this is the column - * number (with the first column as 1). - * - * - xyDms=(yes|no) - * - * If yes then the X and Y coordinates are interpreted as - * degrees/minutes/seconds format (fairly permissively), - * or degree/minutes format. - * - * - wktField=column - * - * Defines the name of the columns holding the WKT geometry definition for WKT geometries. - * If the useHeader is no (ie there are no column names), then this is the column - * number (with the first column as 1). - * - * - geomType=(point|line|polygon|none) - * - * Defines the geometry type for WKT type geometries. QGIS will only display one - * type of geometry for the layer - any others will be ignored when the file is - * loaded. By default the provider uses the type of the first geometry in the file. - * Use geomType to override this type. - * - * geomType can also be set to none, in which case the layer is loaded without - * geometries. - * - * - subset=expression - * - * Defines an expression that will identify a subset of records to display - * - * - crs=crsstring - * - * Defines the coordinate reference system used for the layer. This can be - * any string accepted by QgsCoordinateReferenceSystem::createFromString() - * - * -subsetIndex=(yes|no) - * - * Determines whether the provider generates an index to improve the efficiency - * of subsets. The default is yes - * - * -spatialIndex=(yes|no) - * - * Determines whether the provider generates a spatial index. The default is no. - * - * -watchFile=(yes|no) - * - * Defines whether the file will be monitored for changes. The default is - * to monitor for changes. - * - * - quiet - * - * Errors encountered loading the file will not be reported in a user dialog if - * quiet is included (They will still be shown in the output log). - * - * \subsection gpx GPX data provider (gpx) - * - * Provider reads tracks, routes, and waypoints from a GPX file. The url - * defines the name of the file, and the type of data to retrieve from it - * ("track", "route", or "waypoint"). - * - * An example url is "/home/user/data/holiday.gpx?type=route" - * - * \subsection grass Grass data provider (grass) - * - * Provider to display vector data in a GRASS GIS layer. - * - * TODO QGIS3: Remove virtual from non-inherited methods (like isModified) - */ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator { +%Docstring + Represents a vector layer which manages a vector based data sets. + + The QgsVectorLayer is instantiated by specifying the name of a data provider, + such as postgres or wfs, and url defining the specific data set to connect to. + The vector layer constructor in turn instantiates a QgsVectorDataProvider subclass + corresponding to the provider type, and passes it the url. The data provider + connects to the data source. + + The QgsVectorLayer provides a common interface to the different data types. It also + manages editing transactions. + + Sample usage of the QgsVectorLayer class: + + \code + QString uri = "point?crs=epsg:4326&field=id:integer"; + QgsVectorLayer *scratchLayer = new QgsVectorLayer(uri, "Scratch point layer", "memory"); + \endcode + + The main data providers supported by QGIS are listed below. + + \section providers Vector data providers + + \subsection memory Memory data providerType (memory) + + The memory data provider is used to construct in memory data, for example scratch + data or data generated from spatial operations such as contouring. There is no + inherent persistent storage of the data. The data source uri is constructed. The + url specifies the geometry type ("point", "linestring", "polygon", + "multipoint","multilinestring","multipolygon"), optionally followed by url parameters + as follows: + + - crs=definition + Defines the coordinate reference system to use for the layer. + definition is any string accepted by QgsCoordinateReferenceSystem::createFromString() + + - index=yes + Specifies that the layer will be constructed with a spatial index + + - field=name:type(length,precision) + Defines an attribute of the layer. Multiple field parameters can be added + to the data provider definition. type is one of "integer", "double", "string". + + An example url is "Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes" + + \subsection ogr OGR data provider (ogr) + + Accesses data using the OGR drivers (http://www.gdal.org/ogr/ogr_formats.html). The url + is the OGR connection string. A wide variety of data formats can be accessed using this + driver, including file based formats used by many GIS systems, database formats, and + web services. Some of these formats are also supported by custom data providers listed + below. + + \subsection spatialite Spatialite data provider (spatialite) + + Access data in a spatialite database. The url defines the connection parameters, table, + geometry column, and other attributes. The url can be constructed using the + QgsDataSourceUri class. + + \subsection postgres Postgresql data provider (postgres) + + Connects to a postgresql database. The url defines the connection parameters, table, + geometry column, and other attributes. The url can be constructed using the + QgsDataSourceUri class. + + \subsection mssql Microsoft SQL server data provider (mssql) + + Connects to a Microsoft SQL server database. The url defines the connection parameters, table, + geometry column, and other attributes. The url can be constructed using the + QgsDataSourceUri class. + + \subsection wfs WFS (web feature service) data provider (wfs) + + Used to access data provided by a web feature service. + + The url can be a HTTP url to a WFS server (legacy, e.g. http://foobar/wfs?TYPENAME=xxx&SRSNAME=yyy[&FILTER=zzz]), or, + starting with QGIS 2.16, a URI constructed using the QgsDataSourceUri class with the following parameters : + - url=string (mandatory): HTTP url to a WFS server endpoint. e.g http://foobar/wfs + - typename=string (mandatory): WFS typename + - srsname=string (recommended): SRS like 'EPSG:XXXX' + - username=string + - password=string + - authcfg=string + - version=auto/1.0.0/1.1.0/2.0.0 + -sql=string: full SELECT SQL statement with optional WHERE, ORDER BY and possibly with JOIN if supported on server + - filter=string: QGIS expression or OGC/FES filter + - restrictToRequestBBOX=1: to download only features in the view extent (or more generally + in the bounding box of the feature iterator) + - maxNumFeatures=number + - IgnoreAxisOrientation=1: to ignore EPSG axis order for WFS 1.1 or 2.0 + - InvertAxisOrientation=1: to invert axis order + - hideDownloadProgressDialog=1: to hide the download progress dialog + + The ‘FILTER’ query string parameter can be used to filter + the WFS feature type. The ‘FILTER’ key value can either be a QGIS expression + or an OGC XML filter. If the value is set to a QGIS expression the driver will + turn it into OGC XML filter before passing it to the WFS server. Beware the + QGIS expression filter only supports” =, !=, <, >, <=, >=, AND, OR, NOT, LIKE, IS NULL” + attribute operators, “BBOX, Disjoint, Intersects, Touches, Crosses, Contains, Overlaps, Within” + spatial binary operators and the QGIS local “geomFromWKT, geomFromGML” + geometry constructor functions. + + Also note: + + - You can use various functions available in the QGIS Expression list, + however the function must exist server side and have the same name and arguments to work. + + - Use the special $geometry parameter to provide the layer geometry column as input + into the spatial binary operators e.g intersects($geometry, geomFromWKT('POINT (5 6)')) + + \subsection delimitedtext Delimited text file data provider (delimitedtext) + + Accesses data in a delimited text file, for example CSV files generated by + spreadsheets. The contents of the file are split into columns based on specified + delimiter characters. Each record may be represented spatially either by an + X and Y coordinate column, or by a WKT (well known text) formatted columns. + + The url defines the filename, the formatting options (how the + text in the file is divided into data fields, and which fields contain the + X,Y coordinates or WKT text definition. The options are specified as url query + items. + + At its simplest the url can just be the filename, in which case it will be loaded + as a CSV formatted file. + + The url may include the following items: + + - encoding=UTF-8 + + Defines the character encoding in the file. The default is UTF-8. To use + the default encoding for the operating system use "System". + + - type=(csv|regexp|whitespace|plain) + + Defines the algorithm used to split records into columns. Records are + defined by new lines, except for csv format files for which quoted fields + may span multiple records. The default type is csv. + + - "csv" splits the file based on three sets of characters: + delimiter characters, quote characters, + and escape characters. Delimiter characters mark the end + of a field. Quote characters enclose a field which can contain + delimiter characters, and newlines. Escape characters cause the + following character to be treated literally (including delimiter, + quote, and newline characters). Escape and quote characters must + be different from delimiter characters. Escape characters that are + also quote characters are treated specially - they can only + escape themselves within quotes. Elsewhere they are treated as + quote characters. The defaults for delimiter, quote, and escape + are ',', '"', '"'. + - "regexp" splits each record using a regular expression (see QRegExp + documentation for details). + - "whitespace" splits each record based on whitespace (on or more whitespace + characters. Leading whitespace in the record is ignored. + - "plain" is provided for backwards compatibility. It is equivalent to + CSV except that the default quote characters are single and double quotes, + and there is no escape characters. + + - delimiter=characters + + Defines the delimiter characters used for csv and plain type files, or the + regular expression for regexp type files. It is a literal string of characters + except that "\t" may be used to represent a tab character. + + - quote=characters + + Defines the characters that are used as quote characters for csv and plain type + files. + + - escape=characters + + Defines the characters used to escape delimiter, quote, and newline characters. + + - skipLines=n + + Defines the number of lines to ignore at the beginning of the file (default 0) + + - useHeader=(yes|no) + + Defines whether the first record in the file (after skipped lines) contains + column names (default yes) + + - trimFields=(yes|no) + + If yes then leading and trailing whitespace will be removed from fields + + - skipEmptyFields=(yes|no) + + If yes then empty fields will be discarded (equivalent to concatenating consecutive + delimiters) + + - maxFields=# + + Specifies the maximum number of fields to load for each record. Additional + fields will be discarded. Default is 0 - load all fields. + + - decimalPoint=c + + Defines a character that is used as a decimal point in the numeric columns + The default is '.'. + + - xField=column yField=column + + Defines the name of the columns holding the x and y coordinates for XY point geometries. + If the useHeader is no (ie there are no column names), then this is the column + number (with the first column as 1). + + - xyDms=(yes|no) + + If yes then the X and Y coordinates are interpreted as + degrees/minutes/seconds format (fairly permissively), + or degree/minutes format. + + - wktField=column + + Defines the name of the columns holding the WKT geometry definition for WKT geometries. + If the useHeader is no (ie there are no column names), then this is the column + number (with the first column as 1). + + - geomType=(point|line|polygon|none) + + Defines the geometry type for WKT type geometries. QGIS will only display one + type of geometry for the layer - any others will be ignored when the file is + loaded. By default the provider uses the type of the first geometry in the file. + Use geomType to override this type. + + geomType can also be set to none, in which case the layer is loaded without + geometries. + + - subset=expression + + Defines an expression that will identify a subset of records to display + + - crs=crsstring + + Defines the coordinate reference system used for the layer. This can be + any string accepted by QgsCoordinateReferenceSystem::createFromString() + + -subsetIndex=(yes|no) + + Determines whether the provider generates an index to improve the efficiency + of subsets. The default is yes + + -spatialIndex=(yes|no) + + Determines whether the provider generates a spatial index. The default is no. + + -watchFile=(yes|no) + + Defines whether the file will be monitored for changes. The default is + to monitor for changes. + + - quiet + + Errors encountered loading the file will not be reported in a user dialog if + quiet is included (They will still be shown in the output log). + + \subsection gpx GPX data provider (gpx) + + Provider reads tracks, routes, and waypoints from a GPX file. The url + defines the name of the file, and the type of data to retrieve from it + ("track", "route", or "waypoint"). + + An example url is "/home/user/data/holiday.gpx?type=route" + + \subsection grass Grass data provider (grass) + + Provider to display vector data in a GRASS GIS layer. + + TODO QGIS3: Remove virtual from non-inherited methods (like isModified) + @see QgsVectorLayerUtils() + + +%End + %TypeHeaderCode #include "qgsvectorlayer.h" %End + public: - //! Result of an edit operation enum EditResult { Success, @@ -294,7 +311,6 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator InvalidLayer, }; - //! Selection behavior enum SelectBehavior { SetSelection, @@ -306,8 +322,12 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QgsVectorLayer( const QString &path = QString::null, const QString &baseName = QString::null, const QString &providerLib = "ogr", bool loadDefaultStyleFlag = true ); + virtual ~QgsVectorLayer(); +// QgsVectorLayer( const QgsVectorLayer &rhs ) = delete; +// QgsVectorLayer &operator=( QgsVectorLayer const &rhs ) = delete; + QString storageType() const; QString capabilitiesString() const; @@ -322,7 +342,8 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QgsVectorDataProvider *dataProvider(); - // const QgsVectorDataProvider *dataProvider() const; + // const QgsVectorDataProvider *dataProvider() const; // SIP_SKIP + void setProviderEncoding( const QString &encoding ); @@ -387,7 +408,8 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QgsFeatureRenderer *renderer(); - // const QgsFeatureRenderer *renderer() const { return mRendererV2; } + // const QgsFeatureRenderer *renderer() const { return mRenderer; } // SIP_SKIP + void setRenderer( QgsFeatureRenderer *r /Transfer/ ); @@ -420,7 +442,7 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag /Out/ ); - bool readSymbology( const QDomNode &node, QString &errorMessage ); + bool readSymbology( const QDomNode &layerNode, QString &errorMessage ); bool readStyle( const QDomNode &node, QString &errorMessage ); @@ -428,7 +450,8 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const; - bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props ) const; + bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props = QgsStringMap() ) const; + bool readSld( const QDomNode &node, QString &errorMessage ); long featureCount( const QString &legendKey ) const; @@ -447,7 +470,7 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QgsFeature getFeature( QgsFeatureId fid ); - QgsFeatureIterator getFeatures( QgsFeatureIds fids ); + QgsFeatureIterator getFeatures( const QgsFeatureIds &fids ); QgsFeatureIterator getFeatures( const QgsRectangle &rectangle ); @@ -473,7 +496,7 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator int addPart( const QList &ring ); - int addPart( const QList &ring ) /PyName=addPartV2/; + int addPart( const QgsPointSequence &ring ) /PyName=addPartV2/; int addPart( QgsCurve *ring /Transfer/ ) /PyName=addCurvedPart/; @@ -489,9 +512,11 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator int insertSegmentVerticesForSnap( const QList &snapResults ); - // const QgsAbstractVectorLayerLabeling *labeling() const { return mLabeling; } + // const QgsAbstractVectorLayerLabeling *labeling() const { return mLabeling; } // SIP_SKIP + + + // void setLabeling( QgsAbstractVectorLayerLabeling *labeling ); // SIP_SKIP - // void setLabeling( QgsAbstractVectorLayerLabeling *labeling ); virtual bool isEditable() const; @@ -546,19 +571,21 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QString attributeDisplayName( int index ) const; - const QMap< QString, QString > &attributeAliases() const; + QgsStringMap attributeAliases() const; QSet excludeAttributesWms() const; + void setExcludeAttributesWms( const QSet &att ); QSet excludeAttributesWfs() const; + void setExcludeAttributesWfs( const QSet &att ); bool deleteAttribute( int attr ); bool deleteAttributes( QList attrs ); - bool addFeatures( QList features, bool makeSelected = true ); + bool addFeatures( QgsFeatureList features, bool makeSelected = true ); bool deleteFeature( QgsFeatureId fid ); @@ -578,6 +605,9 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QgsVectorLayerEditBuffer *editBuffer(); + // const QgsVectorLayerEditBuffer *editBuffer() const { return mEditBuffer; } // SIP_SKIP + + void beginEditCommand( const QString &text ); void endEditCommand(); @@ -596,7 +626,7 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator void updateFields(); QVariant defaultValue( int index, const QgsFeature &feature = QgsFeature(), - QgsExpressionContext *context = nullptr ) const; + QgsExpressionContext *context = 0 ) const; void setDefaultValueExpression( int index, const QString &expression ); @@ -613,13 +643,15 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QString constraintDescription( int index ) const; void setConstraintExpression( int index, const QString &expression, const QString &description = QString() ); + void setEditorWidgetSetup( int index, const QgsEditorWidgetSetup &setup ); + QgsEditorWidgetSetup editorWidgetSetup( int index ) const; void uniqueValues( int index, QList &uniqueValues /Out/, int limit = -1 ) const; QStringList uniqueStringsMatching( int index, const QString &substring, int limit = -1, - QgsFeedback *feedback = nullptr ) const; + QgsFeedback *feedback = 0 ) const; QVariant minimumValue( int index ) const; @@ -628,8 +660,8 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate, const QString &fieldOrExpression, const QgsAggregateCalculator::AggregateParameters ¶meters = QgsAggregateCalculator::AggregateParameters(), - QgsExpressionContext *context = nullptr, - bool *ok = nullptr ) const; + QgsExpressionContext *context = 0, + bool *ok = 0 ) const; QList< QVariant > getValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, QgsFeedback *feedback = 0 ) const; @@ -643,7 +675,8 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator QString metadata() const; - // inline QgsGeometryCache *cache(); + // inline QgsGeometryCache *cache() { return mCache; } // SIP_SKIP + void setSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod ); @@ -668,6 +701,7 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator void setEditFormConfig( const QgsEditFormConfig &editFormConfig ); public slots: + void select( QgsFeatureId featureId ); void select( const QgsFeatureIds &featureIds ); @@ -720,6 +754,7 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator void updatedFields(); + void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value ); void geometryChanged( QgsFeatureId fid, const QgsGeometry &geometry ); @@ -756,12 +791,12 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator void editFormConfigChanged(); void readOnlyChanged(); + + protected: - void setExtent( const QgsRectangle &rect ); + void setExtent( const QgsRectangle &rect ); private: // Private methods - - QgsVectorLayer( const QgsVectorLayer &rhs ); - - + QgsVectorLayer( const QgsVectorLayer &rhs ); }; + diff --git a/scripts/sipify.pl b/scripts/sipify.pl index 85d959a6cd1..85b3193e7fa 100755 --- a/scripts/sipify.pl +++ b/scripts/sipify.pl @@ -16,7 +16,7 @@ my $SIP_RUN = 0; my $HEADER_CODE = 0; my $PRIVATE_SECTION = 0; -my $comment; +my $comment = ''; my $nesting_index = 0; my $private_section_line = ''; @@ -131,10 +131,10 @@ while(!eof $header) { # Detect comment block if ($line =~ m/\s*\/\*\*/) { - $comment = ""; + $comment = ''; while(!eof $header) { $line = readline $header; - $line =~ m/\s*\*?(.*)/; + $line =~ m/\s*\*?(.*?)(\/)?$/; $comment .= "$1\n"; if ( $line =~ m/\*\/$/ ) { last; @@ -237,7 +237,7 @@ while(!eof $header) { # deleted functions if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*= delete;$/ ) { - $line = readline $header; + $line =~ s/^/\/\//; } $line =~ s/SIP_FACTORY/\/Factory\//;