Skip to content

Commit

Permalink
QgsVectorLayerImport is a QgsFeatureSink
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 6, 2017
1 parent 8d03642 commit 46ff652
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions python/core/qgsvectorlayerimport.sip
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
1. static call to QgsVectorFileWriter::writeAsShapefile(...) which saves the whole vector layer
2. create an instance of the class and issue calls to addFeature(...)
*/
class QgsVectorLayerImport
class QgsVectorLayerImport : QgsFeatureSink
{
%TypeHeaderCode
#include <qgsvectorlayerimport.h>
Expand Down Expand Up @@ -85,7 +85,7 @@ class QProgressDialog;

int errorCount() const;

/** Add feature to the new created layer */
bool addFeatures( QgsFeatureList &features );
bool addFeature( QgsFeature &feature );

/** Close the new created layer */
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsvectorlayerimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ QString QgsVectorLayerImport::errorMessage()
return mErrorMessage;
}

bool QgsVectorLayerImport::addFeatures( QgsFeatureList &features )
{
QgsFeatureList::iterator fIt = features.begin();
bool result = true;
for ( ; fIt != features.end(); ++fIt )
{
result = result && addFeature( *fIt );
}
return result;
}

bool QgsVectorLayerImport::addFeature( QgsFeature &feat )
{
QgsAttributes attrs = feat.attributes();
Expand Down
7 changes: 4 additions & 3 deletions src/core/qgsvectorlayerimport.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "qgis_core.h"
#include "qgis.h"
#include "qgsfeature.h"
#include "qgsfeaturesink.h"

class QProgressDialog;
class QgsVectorDataProvider;
Expand All @@ -34,7 +35,7 @@ class QgsFields;
1. static call to QgsVectorFileWriter::writeAsShapefile(...) which saves the whole vector layer
2. create an instance of the class and issue calls to addFeature(...)
*/
class CORE_EXPORT QgsVectorLayerImport
class CORE_EXPORT QgsVectorLayerImport : public QgsFeatureSink
{
public:

Expand Down Expand Up @@ -114,8 +115,8 @@ class CORE_EXPORT QgsVectorLayerImport

int errorCount() const { return mErrorCount; }

//! Add feature to the new created layer
bool addFeature( QgsFeature &feature );
bool addFeatures( QgsFeatureList &features ) override;
bool addFeature( QgsFeature &feature ) override;

//! Close the new created layer
~QgsVectorLayerImport();
Expand Down

0 comments on commit 46ff652

Please sign in to comment.