本文整理汇总了C++中QgsVectorLayer::startEditing方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::startEditing方法的具体用法?C++ QgsVectorLayer::startEditing怎么用?C++ QgsVectorLayer::startEditing使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::startEditing方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: newFeature
QgsVectorLayer *QgsAuxiliaryLayer::toSpatialLayer() const
{
QgsVectorLayer *layer = QgsMemoryProviderUtils::createMemoryLayer( QStringLiteral( "auxiliary_layer" ), fields(), mLayer->wkbType(), mLayer->crs() );
QString pkField = mJoinInfo.targetFieldName();
QgsFeature joinFeature;
QgsFeature targetFeature;
QgsFeatureIterator it = getFeatures();
layer->startEditing();
while ( it.nextFeature( joinFeature ) )
{
QString filter = QgsExpression::createFieldEqualityExpression( pkField, joinFeature.attribute( AS_JOINFIELD ) );
QgsFeatureRequest request;
request.setFilterExpression( filter );
mLayer->getFeatures( request ).nextFeature( targetFeature );
if ( targetFeature.isValid() )
{
QgsFeature newFeature( joinFeature );
newFeature.setGeometry( targetFeature.geometry() );
layer->addFeature( newFeature );
}
}
layer->commitChanges();
return layer;
}
示例2: make_layer
static QgsVectorLayer* make_layer( const QStringList& wkts )
{
QgsVectorLayer* vl = new QgsVectorLayer( "LineString", "x", "memory" );
Q_ASSERT( vl->isValid() );
vl->startEditing();
Q_FOREACH ( const QString& wkt, wkts )
{
QgsFeature f( make_feature( wkt ) );
vl->addFeature( f, false );
}
示例3: exportPath
void RgShortestPathWidget::exportPath()
{
RgExportDlg dlg( this );
if ( !dlg.exec() )
return;
QgsVectorLayer *vl = dlg.mapLayer();
if ( vl == NULL )
return;
QgsPoint p1, p2;
QgsGraph *path = getPath( p1, p2 );
if ( path == NULL )
return;
QgsCoordinateTransform ct( mPlugin->iface()->mapCanvas()->mapRenderer()->destinationCrs(),
vl->crs() );
int startVertexIdx = path->findVertex( p1 );
int stopVertexIdx = path->findVertex( p2 );
QgsPolyline p;
while ( startVertexIdx != stopVertexIdx )
{
QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
const QgsGraphArc& e = path->arc( l.front() );
p.push_front( ct.transform( path->vertex( e.inVertex() ).point() ) );
stopVertexIdx = e.outVertex();
}
p.push_front( ct.transform( p1 ) );
vl->startEditing();
QgsFeature f;
f.setGeometry( QgsGeometry::fromPolyline( p ) );
vl->addFeature( f );
vl->updateExtents();
mPlugin->iface()->mapCanvas()->update();
delete path;
}
示例4: createTransactionDocument
//.........这里部分代码省略.........
if ( actionName == QLatin1String( "Insert" ) )
{
if ( !accessControl->layerInsertPermission( layer ) )
{
throw QgsSecurityAccessException( QStringLiteral( "Feature insert permission denied" ) );
}
}
else if ( actionName == QLatin1String( "Update" ) )
{
if ( !accessControl->layerUpdatePermission( layer ) )
{
throw QgsSecurityAccessException( QStringLiteral( "Feature update permission denied" ) );
}
}
else if ( actionName == QLatin1String( "Delete" ) )
{
if ( !accessControl->layerDeletePermission( layer ) )
{
throw QgsSecurityAccessException( QStringLiteral( "Feature delete permission denied" ) );
}
}
#endif
// Get the provider and it's capabilities
QgsVectorDataProvider* provider = layer->dataProvider();
if ( !provider )
{
continue;
}
int cap = provider->capabilities();
// Start the update transaction
layer->startEditing();
if (( cap & QgsVectorDataProvider::ChangeAttributeValues ) && ( cap & QgsVectorDataProvider::ChangeGeometries ) )
{
// Loop through the update elements for this layer
QDomNodeList upNodeList = typeNameElem.elementsByTagNameNS( WFS_NAMESPACE, QStringLiteral( "Update" ) );
for ( int j = 0; j < upNodeList.count(); ++j )
{
if ( !configParser->wfstUpdateLayers().contains( layer->id() ) )
{
//no wfs permissions to do updates
QString errorMsg = "No permissions to do WFS updates on layer '" + layer->name() + "'";
QgsMessageLog::logMessage( errorMsg, QStringLiteral( "Server" ), QgsMessageLog::CRITICAL );
addTransactionResult( resp, respElem, QStringLiteral( "FAILED" ), QStringLiteral( "Update" ), errorMsg );
return resp;
}
actionElem = upNodeList.at( j ).toElement();
// Get the Feature Ids for this filter on the layer
QDomElement filterElem = actionElem.elementsByTagName( QStringLiteral( "Filter" ) ).at( 0 ).toElement();
QgsFeatureIds fids = getFeatureIdsFromFilter( filterElem, layer );
// Loop through the property elements
// Store properties and the geometry element
QDomNodeList propertyNodeList = actionElem.elementsByTagName( QStringLiteral( "Property" ) );
QMap<QString, QString> propertyMap;
QDomElement propertyElem;
QDomElement nameElem;
QDomElement valueElem;
QDomElement geometryElem;
for ( int l = 0; l < propertyNodeList.count(); ++l )
{
示例5: testOKButtonStatus
void TestQgsAttributeForm::testOKButtonStatus()
{
// make a temporary vector layer
QString def = QStringLiteral( "Point?field=col0:integer" );
QgsVectorLayer* layer = new QgsVectorLayer( def, QStringLiteral( "test" ), QStringLiteral( "memory" ) );
// add a feature to the vector layer
QgsFeature ft( layer->dataProvider()->fields(), 1 );
ft.setAttribute( QStringLiteral( "col0" ), 0 );
ft.setValid( true );
// set constraint
layer->setConstraintExpression( 0, QString() );
// build a form for this feature
QgsAttributeForm form( layer );
form.setFeature( ft );
QPushButton *okButton = form.mButtonBox->button( QDialogButtonBox::Ok );
// get wrapper
QgsEditorWidgetWrapper *ww;
ww = qobject_cast<QgsEditorWidgetWrapper*>( form.mWidgets[0] );
// testing stuff
QSignalSpy spy1( &form, SIGNAL( attributeChanged( QString, QVariant ) ) );
QSignalSpy spy2( layer, SIGNAL( editingStarted() ) );
QSignalSpy spy3( layer, SIGNAL( editingStopped() ) );
// no constraint but layer not editable : OK button disabled
QCOMPARE( layer->isEditable(), false );
QCOMPARE( okButton->isEnabled(), false );
// no constraint and editable layer : OK button enabled
layer->startEditing();
QCOMPARE( spy2.count(), 1 );
QCOMPARE( layer->isEditable(), true );
QCOMPARE( okButton->isEnabled(), true );
// invalid constraint and editable layer : OK button disabled
layer->setConstraintExpression( 0, QStringLiteral( "col0 = 0" ) );
QgsAttributeForm form2( layer );
form2.setFeature( ft );
ww = qobject_cast<QgsEditorWidgetWrapper*>( form2.mWidgets[0] );
okButton = form2.mButtonBox->button( QDialogButtonBox::Ok );
ww->setValue( 1 );
QCOMPARE( okButton->isEnabled(), false );
// valid constraint and editable layer : OK button enabled
layer->setConstraintExpression( 0, QStringLiteral( "col0 = 2" ) );
QgsAttributeForm form3( layer );
form3.setFeature( ft );
ww = qobject_cast<QgsEditorWidgetWrapper*>( form3.mWidgets[0] );
okButton = form3.mButtonBox->button( QDialogButtonBox::Ok );
ww->setValue( 2 );
QCOMPARE( okButton->isEnabled(), true );
// valid constraint and not editable layer : OK button disabled
layer->rollBack();
QCOMPARE( spy3.count(), 1 );
QCOMPARE( layer->isEditable(), false );
QCOMPARE( okButton->isEnabled(), false );
// set soft constraint
layer->setFieldConstraint( 0, QgsFieldConstraints::ConstraintExpression, QgsFieldConstraints::ConstraintStrengthSoft );
QgsAttributeForm form4( layer );
form4.setFeature( ft );
ww = qobject_cast<QgsEditorWidgetWrapper*>( form4.mWidgets[0] );
okButton = form4.mButtonBox->button( QDialogButtonBox::Ok );
ww->setValue( 1 );
QVERIFY( !okButton->isEnabled() );
layer->startEditing();
// just a soft constraint, so OK should be enabled
QVERIFY( okButton->isEnabled() );
layer->rollBack();
QVERIFY( !okButton->isEnabled() );
}
示例6: copyVectorLayer
//.........这里部分代码省略.........
// add new layer
QgsVectorLayer* newLayer = new QgsVectorLayer( QString( "dbname='%1' table='%2'(Geometry) sql=" )
.arg( offlineDbPath ).arg( tableName ), tableName + " (offline)", "spatialite" );
if ( newLayer->isValid() )
{
// mark as offline layer
newLayer->setCustomProperty( CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE, true );
// store original layer source
newLayer->setCustomProperty( CUSTOM_PROPERTY_REMOTE_SOURCE, layer->source() );
newLayer->setCustomProperty( CUSTOM_PROPERTY_REMOTE_PROVIDER, layer->providerType() );
// copy style
bool hasLabels = layer->hasLabelsEnabled();
if ( !hasLabels )
{
// NOTE: copy symbology before adding the layer so it is displayed correctly
copySymbology( layer, newLayer );
}
// register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << newLayer );
if ( hasLabels )
{
// NOTE: copy symbology of layers with labels enabled after adding to project, as it will crash otherwise (WORKAROUND)
copySymbology( layer, newLayer );
}
// TODO: layer order
// copy features
newLayer->startEditing();
QgsFeature f;
// NOTE: force feature recount for PostGIS layer, else only visible features are counted, before iterating over all features (WORKAROUND)
layer->setSubsetString( "" );
QgsFeatureIterator fit = layer->getFeatures();
emit progressModeSet( QgsOfflineEditing::CopyFeatures, layer->featureCount() );
int featureCount = 1;
QList<QgsFeatureId> remoteFeatureIds;
while ( fit.nextFeature( f ) )
{
remoteFeatureIds << f.id();
// NOTE: Spatialite provider ignores position of geometry column
// fill gap in QgsAttributeMap if geometry column is not last (WORKAROUND)
int column = 0;
QgsAttributes attrs = f.attributes();
QgsAttributes newAttrs( attrs.count() );
for ( int it = 0; it < attrs.count(); ++it )
{
newAttrs[column++] = attrs[it];
}
f.setAttributes( newAttrs );
newLayer->addFeature( f, false );
emit progressUpdated( featureCount++ );
}
if ( newLayer->commitChanges() )
{
示例7: synchronize
void QgsOfflineEditing::synchronize()
{
// open logging db
sqlite3* db = openLoggingDb();
if ( db == NULL )
{
return;
}
emit progressStarted();
// restore and sync remote layers
QList<QgsMapLayer*> offlineLayers;
QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin() ; layer_it != mapLayers.end(); ++layer_it )
{
QgsMapLayer* layer = layer_it.value();
if ( layer->customProperty( CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE, false ).toBool() )
{
offlineLayers << layer;
}
}
for ( int l = 0; l < offlineLayers.count(); l++ )
{
QgsMapLayer* layer = offlineLayers[l];
emit layerProgressUpdated( l + 1, offlineLayers.count() );
QString remoteSource = layer->customProperty( CUSTOM_PROPERTY_REMOTE_SOURCE, "" ).toString();
QString remoteProvider = layer->customProperty( CUSTOM_PROPERTY_REMOTE_PROVIDER, "" ).toString();
QString remoteName = layer->name();
remoteName.remove( QRegExp( " \\(offline\\)$" ) );
QgsVectorLayer* remoteLayer = new QgsVectorLayer( remoteSource, remoteName, remoteProvider );
if ( remoteLayer->isValid() )
{
// TODO: only add remote layer if there are log entries?
QgsVectorLayer* offlineLayer = qobject_cast<QgsVectorLayer*>( layer );
// copy style
copySymbology( offlineLayer, remoteLayer );
// register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << remoteLayer, true );
// apply layer edit log
QString qgisLayerId = layer->id();
QString sql = QString( "SELECT \"id\" FROM 'log_layer_ids' WHERE \"qgis_id\" = '%1'" ).arg( qgisLayerId );
int layerId = sqlQueryInt( db, sql, -1 );
if ( layerId != -1 )
{
remoteLayer->startEditing();
// TODO: only get commitNos of this layer?
int commitNo = getCommitNo( db );
for ( int i = 0; i < commitNo; i++ )
{
// apply commits chronologically
applyAttributesAdded( remoteLayer, db, layerId, i );
applyAttributeValueChanges( offlineLayer, remoteLayer, db, layerId, i );
applyGeometryChanges( remoteLayer, db, layerId, i );
}
applyFeaturesAdded( offlineLayer, remoteLayer, db, layerId );
applyFeaturesRemoved( remoteLayer, db, layerId );
if ( remoteLayer->commitChanges() )
{
// update fid lookup
updateFidLookup( remoteLayer, db, layerId );
// clear edit log for this layer
sql = QString( "DELETE FROM 'log_added_attrs' WHERE \"layer_id\" = %1" ).arg( layerId );
sqlExec( db, sql );
sql = QString( "DELETE FROM 'log_added_features' WHERE \"layer_id\" = %1" ).arg( layerId );
sqlExec( db, sql );
sql = QString( "DELETE FROM 'log_removed_features' WHERE \"layer_id\" = %1" ).arg( layerId );
sqlExec( db, sql );
sql = QString( "DELETE FROM 'log_feature_updates' WHERE \"layer_id\" = %1" ).arg( layerId );
sqlExec( db, sql );
sql = QString( "DELETE FROM 'log_geometry_updates' WHERE \"layer_id\" = %1" ).arg( layerId );
sqlExec( db, sql );
// reset commitNo
QString sql = QString( "UPDATE 'log_indices' SET 'last_index' = 0 WHERE \"name\" = 'commit_no'" );
sqlExec( db, sql );
}
else
{
showWarning( remoteLayer->commitErrors().join( "\n" ) );
}
}
// remove offline layer
QgsMapLayerRegistry::instance()->removeMapLayers(
( QStringList() << qgisLayerId ) );
//.........这里部分代码省略.........