|
37 | 37 | #include <cstdlib> // size_t
|
38 | 38 | #include <limits> // std::numeric_limits
|
39 | 39 |
|
| 40 | + |
| 41 | +#define FEATURE_BUFFER_SIZE 200 |
| 42 | + |
40 | 43 | typedef QgsVectorLayerImport::ImportError createEmptyLayer_t(
|
41 | 44 | const QString &uri,
|
42 | 45 | const QgsFieldMap &fields,
|
@@ -108,6 +111,8 @@ QgsVectorLayerImport::QgsVectorLayerImport(
|
108 | 111 |
|
109 | 112 | QgsVectorLayerImport::~QgsVectorLayerImport()
|
110 | 113 | {
|
| 114 | + flushBuffer(); |
| 115 | + |
111 | 116 | if ( mProvider )
|
112 | 117 | delete mProvider;
|
113 | 118 | }
|
@@ -142,15 +147,34 @@ bool QgsVectorLayerImport::addFeature( QgsFeature& feat )
|
142 | 147 | }
|
143 | 148 | feat.setAttributeMap( newAttrs );
|
144 | 149 |
|
145 |
| - if ( !mProvider->addFeatures( QgsFeatureList() << feat ) ) |
| 150 | + mFeatureBuffer.append( feat ); |
| 151 | + |
| 152 | + if ( mFeatureBuffer.count() >= FEATURE_BUFFER_SIZE ) |
| 153 | + { |
| 154 | + return flushBuffer(); |
| 155 | + } |
| 156 | + |
| 157 | + return true; |
| 158 | +} |
| 159 | + |
| 160 | +bool QgsVectorLayerImport::flushBuffer() |
| 161 | +{ |
| 162 | + if ( mFeatureBuffer.count() <= 0 ) |
| 163 | + return true; |
| 164 | + |
| 165 | + if ( !mProvider->addFeatures( mFeatureBuffer ) ) |
146 | 166 | {
|
147 |
| - mErrorMessage = QObject::tr( "Feature #%1 creation error" ).arg( feat.id() ); |
| 167 | + mErrorMessage = QObject::tr( "Creation error for features from #%1 to #%2" ) |
| 168 | + .arg( mFeatureBuffer.first().id() ) |
| 169 | + .arg( mFeatureBuffer.last().id() ); |
148 | 170 | mError = ErrFeatureWriteFailed;
|
149 | 171 |
|
| 172 | + mFeatureBuffer.clear(); |
150 | 173 | QgsDebugMsg( mErrorMessage );
|
151 | 174 | return false;
|
152 | 175 | }
|
153 | 176 |
|
| 177 | + mFeatureBuffer.clear(); |
154 | 178 | return true;
|
155 | 179 | }
|
156 | 180 |
|
|
0 commit comments