Skip to content
Permalink
Browse files

Merge branch 'import_layer'

  • Loading branch information
brushtyler committed Sep 14, 2011
2 parents 262ec3f + 37b2c04 commit 5f9956e655fa9015e1af0e6ebe2422e83a363001
Showing with 31 additions and 2 deletions.
  1. +26 −2 src/core/qgsvectorlayerimport.cpp
  2. +5 −0 src/core/qgsvectorlayerimport.h
@@ -37,6 +37,9 @@
#include <cstdlib> // size_t
#include <limits> // std::numeric_limits


#define FEATURE_BUFFER_SIZE 200

typedef QgsVectorLayerImport::ImportError createEmptyLayer_t(
const QString &uri,
const QgsFieldMap &fields,
@@ -108,6 +111,8 @@ QgsVectorLayerImport::QgsVectorLayerImport(

QgsVectorLayerImport::~QgsVectorLayerImport()
{
flushBuffer();

if ( mProvider )
delete mProvider;
}
@@ -142,15 +147,34 @@ bool QgsVectorLayerImport::addFeature( QgsFeature& feat )
}
feat.setAttributeMap( newAttrs );

if ( !mProvider->addFeatures( QgsFeatureList() << feat ) )
mFeatureBuffer.append( feat );

if ( mFeatureBuffer.count() >= FEATURE_BUFFER_SIZE )
{
return flushBuffer();
}

return true;
}

bool QgsVectorLayerImport::flushBuffer()
{
if ( mFeatureBuffer.count() <= 0 )
return true;

if ( !mProvider->addFeatures( mFeatureBuffer ) )
{
mErrorMessage = QObject::tr( "Feature #%1 creation error" ).arg( feat.id() );
mErrorMessage = QObject::tr( "Creation error for features from #%1 to #%2" )
.arg( mFeatureBuffer.first().id() )
.arg( mFeatureBuffer.last().id() );
mError = ErrFeatureWriteFailed;

mFeatureBuffer.clear();
QgsDebugMsg( mErrorMessage );
return false;
}

mFeatureBuffer.clear();
return true;
}

@@ -86,6 +86,9 @@ class CORE_EXPORT QgsVectorLayerImport
~QgsVectorLayerImport();

protected:
/** flush the buffer writing the features to the new layer */
bool flushBuffer();

/** contains error value */
ImportError mError;
QString mErrorMessage;
@@ -94,6 +97,8 @@ class CORE_EXPORT QgsVectorLayerImport

/** map attribute indexes to new field indexes */
QMap<int, int> mOldToNewAttrIdx;

QgsFeatureList mFeatureBuffer;
};

#endif

0 comments on commit 5f9956e

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