本文整理汇总了C++中QgsVectorDataProvider::capabilities方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorDataProvider::capabilities方法的具体用法?C++ QgsVectorDataProvider::capabilities怎么用?C++ QgsVectorDataProvider::capabilities使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorDataProvider
的用法示例。
在下文中一共展示了QgsVectorDataProvider::capabilities方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertAvailableLayers
void QgsZonalStatisticsDialog::insertAvailableLayers()
{
//insert available raster layers
//enter available layers into the combo box
QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin();
for ( ; layer_it != mapLayers.end(); ++layer_it )
{
QgsRasterLayer* rl = dynamic_cast<QgsRasterLayer*>( layer_it.value() );
if ( rl )
{
QgsRasterDataProvider* rp = rl->dataProvider();
if ( rp && rp->name() == "gdal" )
{
mRasterLayerComboBox->addItem( rl->name(), QVariant( rl->id() ) );
}
}
else
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer_it.value() );
if ( vl && vl->geometryType() == QGis::Polygon )
{
QgsVectorDataProvider* provider = vl->dataProvider();
if ( provider->capabilities() & QgsVectorDataProvider::AddAttributes )
{
mPolygonLayerComboBox->addItem( vl->name(), QVariant( vl->id() ) );
}
}
}
}
}
示例2: commitChanges
bool QgsVectorLayerEditBuffer::commitChanges( QStringList& commitErrors )
{
QgsVectorDataProvider* provider = L->dataProvider();
commitErrors.clear();
int cap = provider->capabilities();
bool success = true;
//
// update geometries
//
if ( !mChangedGeometries.isEmpty() )
{
if (( cap & QgsVectorDataProvider::ChangeGeometries ) && provider->changeGeometryValues( mChangedGeometries ) )
{
commitErrors << tr( "SUCCESS: %n geometries were changed.", "changed geometries count", mChangedGeometries.size() );
emit committedGeometriesChanges( L->id(), mChangedGeometries );
mChangedGeometries.clear();
}
else
{
commitErrors << tr( "ERROR: %n geometries not changed.", "not changed geometries count", mChangedGeometries.size() );
success = false;
}
}
QgsFields oldFields = L->fields();
//
// delete attributes
//
bool attributesChanged = false;
if ( !mDeletedAttributeIds.isEmpty() )
{
if (( cap & QgsVectorDataProvider::DeleteAttributes ) && provider->deleteAttributes( mDeletedAttributeIds.toSet() ) )
{
commitErrors << tr( "SUCCESS: %n attribute(s) deleted.", "deleted attributes count", mDeletedAttributeIds.size() );
emit committedAttributesDeleted( L->id(), mDeletedAttributeIds );
mDeletedAttributeIds.clear();
attributesChanged = true;
}
else
{
commitErrors << tr( "ERROR: %n attribute(s) not deleted.", "not deleted attributes count", mDeletedAttributeIds.size() );
#if 0
QString list = "ERROR: Pending attribute deletes:";
Q_FOREACH ( int idx, mDeletedAttributeIds )
{
list.append( ' ' + L->pendingFields().at( idx ).name() );
}
commitErrors << list;
#endif
success = false;
}
}
示例3: providerCanSimplify
bool QgsVectorLayerFeatureIterator::providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const
{
QgsVectorDataProvider* provider = L->dataProvider();
if ( provider && methodType != QgsSimplifyMethod::NoSimplification )
{
int capabilities = provider->capabilities();
if ( methodType == QgsSimplifyMethod::OptimizeForRendering )
{
return ( capabilities & QgsVectorDataProvider::SimplifyGeometries );
}
else if ( methodType == QgsSimplifyMethod::PreserveTopology )
{
return ( capabilities & QgsVectorDataProvider::SimplifyGeometriesWithTopologicalValidation );
}
}
return false;
}
示例4: on_mJoinLayerComboBox_currentIndexChanged
void QgsAddJoinDialog::on_mJoinLayerComboBox_currentIndexChanged( int index )
{
mJoinFieldComboBox->clear();
QString layerId = mJoinLayerComboBox->itemData( index ).toString();
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId );
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( layer );
if ( !vLayer )
{
return;
}
QStandardItemModel* subsetModel = new QStandardItemModel( this );
const QgsFields& layerFields = vLayer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
mJoinFieldComboBox->addItem( layerFields[idx].name(), idx );
QStandardItem* subsetItem = new QStandardItem( layerFields[idx].name() );
subsetItem->setCheckable( true );
//subsetItem->setFlags( subsetItem->flags() | Qt::ItemIsUserCheckable );
subsetModel->appendRow( subsetItem );
}
//does provider support creation of attribute indices?
QgsVectorDataProvider* dp = vLayer->dataProvider();
if ( dp && ( dp->capabilities() & QgsVectorDataProvider::CreateAttributeIndex ) )
{
mCreateIndexCheckBox->setEnabled( true );
}
else
{
mCreateIndexCheckBox->setEnabled( false );
mCreateIndexCheckBox->setChecked( false );
}
mJoinFieldsSubsetView->setModel( subsetModel );
if ( !mUseCustomPrefix->isChecked() )
{
mCustomPrefix->setText( layer->name() + "_" );
}
}
示例5: commitChanges
bool QgsVectorLayerEditBuffer::commitChanges( QStringList& commitErrors )
{
QgsVectorDataProvider* provider = L->dataProvider();
commitErrors.clear();
int cap = provider->capabilities();
bool success = true;
QgsFields oldFields = L->pendingFields();
bool hadPendingDeletes = !mDeletedFeatureIds.isEmpty();
//
// delete attributes
//
bool attributesChanged = false;
if ( !mDeletedAttributeIds.isEmpty() )
{
if (( cap & QgsVectorDataProvider::DeleteAttributes ) && provider->deleteAttributes( mDeletedAttributeIds.toSet() ) )
{
commitErrors << tr( "SUCCESS: %n attribute(s) deleted.", "deleted attributes count", mDeletedAttributeIds.size() );
emit committedAttributesDeleted( L->id(), mDeletedAttributeIds );
mDeletedAttributeIds.clear();
attributesChanged = true;
}
else
{
commitErrors << tr( "ERROR: %n attribute(s) not deleted.", "not deleted attributes count", mDeletedAttributeIds.size() );
#if 0
QString list = "ERROR: Pending attribute deletes:";
foreach ( int idx, mDeletedAttributeIds )
{
list.append( " " + L->pendingFields()[idx].name() );
}
commitErrors << list;
#endif
success = false;
}
}
示例6: joinedLayerChanged
void QgsJoinDialog::joinedLayerChanged( QgsMapLayer* layer )
{
mJoinFieldComboBox->clear();
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( layer );
if ( !vLayer )
{
return;
}
mUseJoinFieldsSubset->setChecked( false );
QStandardItemModel* subsetModel = new QStandardItemModel( this );
const QgsFields& layerFields = vLayer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
QStandardItem* subsetItem = new QStandardItem( layerFields[idx].name() );
subsetItem->setCheckable( true );
//subsetItem->setFlags( subsetItem->flags() | Qt::ItemIsUserCheckable );
subsetModel->appendRow( subsetItem );
}
mJoinFieldsSubsetView->setModel( subsetModel );
QgsVectorDataProvider* dp = vLayer->dataProvider();
bool canCreateAttrIndex = dp && ( dp->capabilities() & QgsVectorDataProvider::CreateAttributeIndex );
if ( canCreateAttrIndex )
{
mCreateIndexCheckBox->setEnabled( true );
}
else
{
mCreateIndexCheckBox->setEnabled( false );
mCreateIndexCheckBox->setChecked( false );
}
if ( !mUseCustomPrefix->isChecked() )
{
mCustomPrefix->setText( layer->name() + "_" );
}
}
示例7: cadCanvasReleaseEvent
void QgsMapToolDigitizeFeature::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayer );
if ( !vlayer )
//if no given layer take the current from canvas
vlayer = currentVectorLayer();
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
QgsWkbTypes::Type layerWKBType = vlayer->wkbType();
QgsVectorDataProvider *provider = vlayer->dataProvider();
if ( !( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) )
{
emit messageEmitted( tr( "The data provider for this layer does not support the addition of features." ), Qgis::Warning );
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
// POINT CAPTURING
if ( mode() == CapturePoint )
{
if ( e->button() != Qt::LeftButton )
return;
//check we only use this tool for point/multipoint layers
if ( vlayer->geometryType() != QgsWkbTypes::PointGeometry && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture point' tool on this vector layer" ), Qgis::Warning );
return;
}
QgsPointXY savePoint; //point in layer coordinates
try
{
QgsPoint fetchPoint;
int res;
res = fetchLayerPoint( e->mapPointMatch(), fetchPoint );
if ( res == 0 )
{
savePoint = QgsPointXY( fetchPoint.x(), fetchPoint.y() );
}
else
{
savePoint = toLayerCoordinates( vlayer, e->mapPoint() );
}
QgsDebugMsg( "savePoint = " + savePoint.toString() );
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), Qgis::Warning );
return;
}
//only do the rest for provider with feature addition support
//note that for the grass provider, this will return false since
//grass provider has its own mechanism of feature addition
if ( provider->capabilities() & QgsVectorDataProvider::AddFeatures )
{
QgsFeature f( vlayer->fields(), 0 );
QgsGeometry g;
if ( layerWKBType == QgsWkbTypes::Point )
{
g = QgsGeometry::fromPointXY( savePoint );
}
else if ( !QgsWkbTypes::isMultiType( layerWKBType ) && QgsWkbTypes::hasZ( layerWKBType ) )
{
g = QgsGeometry( new QgsPoint( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), defaultZValue() ) );
}
else if ( QgsWkbTypes::isMultiType( layerWKBType ) && !QgsWkbTypes::hasZ( layerWKBType ) )
{
g = QgsGeometry::fromMultiPointXY( QgsMultiPointXY() << savePoint );
}
else if ( QgsWkbTypes::isMultiType( layerWKBType ) && QgsWkbTypes::hasZ( layerWKBType ) )
{
QgsMultiPoint *mp = new QgsMultiPoint();
mp->addGeometry( new QgsPoint( QgsWkbTypes::PointZ, savePoint.x(), savePoint.y(), defaultZValue() ) );
g = QgsGeometry( mp );
}
else
{
// if layer supports more types (mCheckGeometryType is false)
g = QgsGeometry::fromPointXY( savePoint );
}
if ( QgsWkbTypes::hasM( layerWKBType ) )
{
//.........这里部分代码省略.........
示例8: canvasReleaseEvent
void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )
{
QgsDebugMsg( "entered." );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
QGis::WkbType layerWKBType = vlayer->wkbType();
QgsVectorDataProvider* provider = vlayer->dataProvider();
if ( !( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) )
{
QMessageBox::information( 0, tr( "Layer cannot be added to" ),
tr( "The data provider for this layer does not support the addition of features." ) );
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
// POINT CAPTURING
if ( mode() == CapturePoint )
{
//check we only use this tool for point/multipoint layers
if ( vlayer->geometryType() != QGis::Point )
{
QMessageBox::information( 0, tr( "Wrong editing tool" ),
tr( "Cannot apply the 'capture point' tool on this vector layer" ) );
return;
}
QgsPoint idPoint; //point in map coordinates
QList<QgsSnappingResult> snapResults;
QgsPoint savePoint; //point in layer coordinates
if ( mSnapper.snapToBackgroundLayers( e->pos(), snapResults ) == 0 )
{
idPoint = snapPointFromResults( snapResults, e->pos() );
try
{
savePoint = toLayerCoordinates( vlayer, idPoint );
QgsDebugMsg( "savePoint = " + savePoint.toString() );
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
QMessageBox::information( 0, tr( "Coordinate transform error" ),
tr( "Cannot transform the point to the layers coordinate system" ) );
return;
}
}
//only do the rest for provider with feature addition support
//note that for the grass provider, this will return false since
//grass provider has its own mechanism of feature addition
if ( provider->capabilities() & QgsVectorDataProvider::AddFeatures )
{
QgsFeature* f = new QgsFeature( 0, "WKBPoint" );
QgsGeometry *g = 0;
if ( layerWKBType == QGis::WKBPoint || layerWKBType == QGis::WKBPoint25D )
{
g = QgsGeometry::fromPoint( savePoint );
}
else if ( layerWKBType == QGis::WKBMultiPoint || layerWKBType == QGis::WKBMultiPoint25D )
{
g = QgsGeometry::fromMultiPoint( QgsMultiPoint() << savePoint );
}
f->setGeometry( g );
vlayer->beginEditCommand( tr( "Feature added" ) );
if ( addFeature( vlayer, f ) )
{
vlayer->endEditCommand();
}
else
{
delete f;
vlayer->destroyEditCommand();
}
mCanvas->refresh();
}
}
else if ( mode() == CaptureLine || mode() == CapturePolygon )
{
//check we only use the line tool for line/multiline layers
if ( mode() == CaptureLine && vlayer->geometryType() != QGis::Line )
//.........这里部分代码省略.........
示例9: featureTypeList
void QgsWfsProjectParser::featureTypeList( QDomElement& parentElement, QDomDocument& doc ) const
{
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return;
}
QStringList wfsLayersId = mProjectParser->wfsLayers();
QSet<QString> wfstUpdateLayersId = wfstUpdateLayers();
QSet<QString> wfstInsertLayersId = wfstInsertLayers();
QSet<QString> wfstDeleteLayersId = wfstDeleteLayers();
QMap<QString, QgsMapLayer *> layerMap;
Q_FOREACH ( const QDomElement &elem, projectLayerElements )
{
QString type = elem.attribute( "type" );
if ( type == "vector" )
{
QString layerId = mProjectParser->layerId( elem );
if ( !wfsLayersId.contains( layerId ) )
{
continue;
}
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
if ( !layer )
{
continue;
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
if ( !mAccessControl->layerReadPermission( layer ) )
{
continue;
}
#endif
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
layerMap.insert( layer->id(), layer );
QDomElement layerElem = doc.createElement( "FeatureType" );
QDomElement nameElem = doc.createElement( "Name" );
//We use the layer name even though it might not be unique.
//Because the id sometimes contains user/pw information and the name is more descriptive
QString typeName = layer->name();
if ( !layer->shortName().isEmpty() )
typeName = layer->shortName();
typeName = typeName.replace( " ", "_" );
QDomText nameText = doc.createTextNode( typeName );
nameElem.appendChild( nameText );
layerElem.appendChild( nameElem );
QDomElement titleElem = doc.createElement( "Title" );
QString titleName = layer->title();
if ( titleName.isEmpty() )
{
titleName = layer->name();
}
QDomText titleText = doc.createTextNode( titleName );
titleElem.appendChild( titleText );
layerElem.appendChild( titleElem );
QDomElement abstractElem = doc.createElement( "Abstract" );
QString abstractName = layer->abstract();
if ( abstractName.isEmpty() )
{
abstractName = "";
}
QDomText abstractText = doc.createTextNode( abstractName );
abstractElem.appendChild( abstractText );
layerElem.appendChild( abstractElem );
//keyword list
if ( !layer->keywordList().isEmpty() )
{
QDomElement keywordsElem = doc.createElement( "Keywords" );
QDomText keywordsText = doc.createTextNode( layer->keywordList() );
keywordsElem.appendChild( keywordsText );
layerElem.appendChild( keywordsElem );
}
//appendExGeographicBoundingBox( layerElem, doc, layer->extent(), layer->crs() );
QDomElement srsElem = doc.createElement( "SRS" );
QDomText srsText = doc.createTextNode( layer->crs().authid() );
srsElem.appendChild( srsText );
layerElem.appendChild( srsElem );
//wfs:Operations element
QDomElement operationsElement = doc.createElement( "Operations"/*wfs:Operations*/ );
//wfs:Query element
QDomElement queryElement = doc.createElement( "Query"/*wfs:Query*/ );
operationsElement.appendChild( queryElement );
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
QgsVectorDataProvider* provider = vlayer->dataProvider();
if (( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) && wfstInsertLayersId.contains( layer->id() ) )
{
//wfs:Insert element
QDomElement insertElement = doc.createElement( "Insert"/*wfs:Insert*/ );
operationsElement.appendChild( insertElement );
//.........这里部分代码省略.........
示例10: getFeatureTypeListElement
//.........这里部分代码省略.........
QDomText titleText = doc.createTextNode( title );
titleElem.appendChild( titleText );
layerElem.appendChild( titleElem );
//create Abstract
QString abstract = layer->abstract();
if ( !abstract.isEmpty() )
{
QDomElement abstractElem = doc.createElement( QStringLiteral( "Abstract" ) );
QDomText abstractText = doc.createTextNode( abstract );
abstractElem.appendChild( abstractText );
layerElem.appendChild( abstractElem );
}
//create keywords
QString keywords = layer->keywordList();
if ( !keywords.isEmpty() )
{
QDomElement keywordsElem = doc.createElement( QStringLiteral( "Keywords" ) );
QDomText keywordsText = doc.createTextNode( keywords );
keywordsElem.appendChild( keywordsText );
layerElem.appendChild( keywordsElem );
}
//create SRS
QDomElement srsElem = doc.createElement( QStringLiteral( "SRS" ) );
QDomText srsText = doc.createTextNode( layer->crs().authid() );
srsElem.appendChild( srsText );
layerElem.appendChild( srsElem );
//create LatLongBoundingBox
QgsRectangle layerExtent = layer->extent();
QDomElement bBoxElement = doc.createElement( QStringLiteral( "LatLongBoundingBox" ) );
bBoxElement.setAttribute( QStringLiteral( "minx" ), QString::number( layerExtent.xMinimum() ) );
bBoxElement.setAttribute( QStringLiteral( "miny" ), QString::number( layerExtent.yMinimum() ) );
bBoxElement.setAttribute( QStringLiteral( "maxx" ), QString::number( layerExtent.xMaximum() ) );
bBoxElement.setAttribute( QStringLiteral( "maxy" ), QString::number( layerExtent.yMaximum() ) );
layerElem.appendChild( bBoxElement );
// layer metadata URL
QString metadataUrl = layer->metadataUrl();
if ( !metadataUrl.isEmpty() )
{
QDomElement metaUrlElem = doc.createElement( QStringLiteral( "MetadataURL" ) );
QString metadataUrlType = layer->metadataUrlType();
metaUrlElem.setAttribute( QStringLiteral( "type" ), metadataUrlType );
QString metadataUrlFormat = layer->metadataUrlFormat();
if ( metadataUrlFormat == QLatin1String( "text/xml" ) )
{
metaUrlElem.setAttribute( QStringLiteral( "format" ), QStringLiteral( "XML" ) );
}
else
{
metaUrlElem.setAttribute( QStringLiteral( "format" ), QStringLiteral( "TXT" ) );
}
QDomText metaUrlText = doc.createTextNode( metadataUrl );
metaUrlElem.appendChild( metaUrlText );
layerElem.appendChild( metaUrlElem );
}
//wfs:Operations element
QDomElement operationsElement = doc.createElement( QStringLiteral( "Operations" )/*wfs:Operations*/ );
//wfs:Query element
QDomElement queryElement = doc.createElement( QStringLiteral( "Query" )/*wfs:Query*/ );
operationsElement.appendChild( queryElement );
if ( wfstUpdateLayersId.contains( layer->id() ) ||
wfstInsertLayersId.contains( layer->id() ) ||
wfstDeleteLayersId.contains( layer->id() ) )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
QgsVectorDataProvider *provider = vlayer->dataProvider();
if ( ( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) && wfstInsertLayersId.contains( layer->id() ) )
{
//wfs:Insert element
QDomElement insertElement = doc.createElement( QStringLiteral( "Insert" )/*wfs:Insert*/ );
operationsElement.appendChild( insertElement );
}
if ( ( provider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) &&
( provider->capabilities() & QgsVectorDataProvider::ChangeGeometries ) &&
wfstUpdateLayersId.contains( layer->id() ) )
{
//wfs:Update element
QDomElement updateElement = doc.createElement( QStringLiteral( "Update" )/*wfs:Update*/ );
operationsElement.appendChild( updateElement );
}
if ( ( provider->capabilities() & QgsVectorDataProvider::DeleteFeatures ) && wfstDeleteLayersId.contains( layer->id() ) )
{
//wfs:Delete element
QDomElement deleteElement = doc.createElement( QStringLiteral( "Delete" )/*wfs:Delete*/ );
operationsElement.appendChild( deleteElement );
}
}
layerElem.appendChild( operationsElement );
featureTypeListElement.appendChild( layerElem );
}
return featureTypeListElement;
}
示例11: createTransactionDocument
//.........这里部分代码省略.........
if ( layer && wfsLayersId.contains( layer->id() ) )
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
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;
示例12: cadCanvasReleaseEvent
void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
{
QgsVectorLayer* vlayer = currentVectorLayer();
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
QGis::WkbType layerWKBType = vlayer->wkbType();
QgsVectorDataProvider* provider = vlayer->dataProvider();
if ( !( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) )
{
emit messageEmitted( tr( "The data provider for this layer does not support the addition of features." ), QgsMessageBar::WARNING );
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
// POINT CAPTURING
if ( mode() == CapturePoint )
{
if ( e->button() != Qt::LeftButton )
return;
//check we only use this tool for point/multipoint layers
if ( vlayer->geometryType() != QGis::Point && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture point' tool on this vector layer" ), QgsMessageBar::WARNING );
return;
}
QgsPoint savePoint; //point in layer coordinates
try
{
savePoint = toLayerCoordinates( vlayer, e->mapPoint() );
QgsDebugMsg( "savePoint = " + savePoint.toString() );
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
return;
}
//only do the rest for provider with feature addition support
//note that for the grass provider, this will return false since
//grass provider has its own mechanism of feature addition
if ( provider->capabilities() & QgsVectorDataProvider::AddFeatures )
{
QgsFeature f( vlayer->fields(), 0 );
QgsGeometry *g = 0;
if ( layerWKBType == QGis::WKBPoint || layerWKBType == QGis::WKBPoint25D )
{
g = QgsGeometry::fromPoint( savePoint );
}
else if ( layerWKBType == QGis::WKBMultiPoint || layerWKBType == QGis::WKBMultiPoint25D )
{
g = QgsGeometry::fromMultiPoint( QgsMultiPoint() << savePoint );
}
else
{
// if layer supports more types (mCheckGeometryType is false)
g = QgsGeometry::fromPoint( savePoint );
}
f.setGeometry( g );
f.setValid( true );
addFeature( vlayer, &f, false );
mCanvas->refresh();
}
}
// LINE AND POLYGON CAPTURING
else if ( mode() == CaptureLine || mode() == CapturePolygon )
{
//check we only use the line tool for line/multiline layers
if ( mode() == CaptureLine && vlayer->geometryType() != QGis::Line && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture line' tool on this vector layer" ), QgsMessageBar::WARNING );
return;
}
//check we only use the polygon tool for polygon/multipolygon layers
if ( mode() == CapturePolygon && vlayer->geometryType() != QGis::Polygon && mCheckGeometryType )
{
emit messageEmitted( tr( "Wrong editing tool, cannot apply the 'capture polygon' tool on this vector layer" ), QgsMessageBar::WARNING );
return;
//.........这里部分代码省略.........
示例13: mErrorCount
QgsVectorLayerImport::QgsVectorLayerImport( const QString &uri,
const QString &providerKey,
const QgsFields& fields,
QGis::WkbType geometryType,
const QgsCoordinateReferenceSystem* crs,
bool overwrite,
const QMap<QString, QVariant> *options,
QProgressDialog *progress )
: mErrorCount( 0 )
, mAttributeCount( -1 )
, mProgress( progress )
{
mProvider = nullptr;
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( providerKey );
if ( !myLib )
{
mError = ErrInvalidProvider;
mErrorMessage = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
return;
}
createEmptyLayer_t * pCreateEmpty = reinterpret_cast< createEmptyLayer_t * >( cast_to_fptr( myLib->resolve( "createEmptyLayer" ) ) );
if ( !pCreateEmpty )
{
delete myLib;
mError = ErrProviderUnsupportedFeature;
mErrorMessage = QObject::tr( "Provider %1 has no %2 method" ).arg( providerKey, "createEmptyLayer" );
return;
}
delete myLib;
// create an empty layer
QString errMsg;
mError = pCreateEmpty( uri, fields, geometryType, crs, overwrite, &mOldToNewAttrIdx, &errMsg, options );
if ( hasError() )
{
mErrorMessage = errMsg;
return;
}
Q_FOREACH ( int idx, mOldToNewAttrIdx.values() )
{
if ( idx > mAttributeCount )
mAttributeCount = idx;
}
mAttributeCount++;
QgsDebugMsg( "Created empty layer" );
QgsVectorDataProvider *vectorProvider = dynamic_cast< QgsVectorDataProvider* >( pReg->provider( providerKey, uri ) );
if ( !vectorProvider || !vectorProvider->isValid() || ( vectorProvider->capabilities() & QgsVectorDataProvider::AddFeatures ) == 0 )
{
mError = ErrInvalidLayer;
mErrorMessage = QObject::tr( "Loading of layer failed" );
if ( vectorProvider )
delete vectorProvider;
return;
}
mProvider = vectorProvider;
mError = NoError;
}
示例14: commitChanges
bool QgsVectorLayerEditBuffer::commitChanges( QStringList& commitErrors )
{
QgsVectorDataProvider* provider = L->dataProvider();
commitErrors.clear();
int cap = provider->capabilities();
bool success = true;
QgsFields oldFields = L->pendingFields();
//
// delete attributes
//
bool attributesChanged = false;
if ( !mDeletedAttributeIds.isEmpty() )
{
if (( cap & QgsVectorDataProvider::DeleteAttributes ) && provider->deleteAttributes( mDeletedAttributeIds.toSet() ) )
{
commitErrors << tr( "SUCCESS: %n attribute(s) deleted.", "deleted attributes count", mDeletedAttributeIds.size() );
emit committedAttributesDeleted( L->id(), mDeletedAttributeIds );
mDeletedAttributeIds.clear();
attributesChanged = true;
}
else
{
commitErrors << tr( "ERROR: %n attribute(s) not deleted.", "not deleted attributes count", mDeletedAttributeIds.size() );
success = false;
}
}
//
// add attributes
//
if ( !mAddedAttributes.isEmpty() )
{
if (( cap & QgsVectorDataProvider::AddAttributes ) && provider->addAttributes( mAddedAttributes ) )
{
commitErrors << tr( "SUCCESS: %n attribute(s) added.", "added attributes count", mAddedAttributes.size() );
emit committedAttributesAdded( L->id(), mAddedAttributes );
mAddedAttributes.clear();
attributesChanged = true;
}
else
{
commitErrors << tr( "ERROR: %n new attribute(s) not added", "not added attributes count", mAddedAttributes.size() );
success = false;
}
}
//
// check that addition/removal went as expected
//
bool attributeChangesOk = true;
if ( attributesChanged )
{
L->updateFields();
QgsFields newFields = L->pendingFields();
if ( oldFields.count() != newFields.count() )
{
commitErrors << tr( "ERROR: the count of fields is incorrect after addition/removal of fields!" );
attributeChangesOk = false; // don't try attribute updates - they'll fail.
}
for ( int i = 0; i < oldFields.count(); ++i )
{
const QgsField& oldField = oldFields[i];
const QgsField& newField = newFields[i];
if ( attributeChangesOk && oldField != newField )
{
commitErrors << tr( "ERROR: field with index %1 is not the same!" ).arg( i );
attributeChangesOk = false; // don't try attribute updates - they'll fail.
}
}
}
if ( attributeChangesOk )
{
//
// change attributes
//
if ( !mChangedAttributeValues.isEmpty() )
{
if (( cap & QgsVectorDataProvider::ChangeAttributeValues ) && provider->changeAttributeValues( mChangedAttributeValues ) )
{
commitErrors << tr( "SUCCESS: %n attribute value(s) changed.", "changed attribute values count", mChangedAttributeValues.size() );
emit committedAttributeValuesChanges( L->id(), mChangedAttributeValues );
mChangedAttributeValues.clear();
}
else
{
commitErrors << tr( "ERROR: %n attribute value change(s) not applied.", "not changed attribute values count", mChangedAttributeValues.size() );
success = false;
}
//.........这里部分代码省略.........
示例15: commitChanges
bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
{
QgsVectorDataProvider *provider = L->dataProvider();
commitErrors.clear();
int cap = provider->capabilities();
bool success = true;
// geometry updates attribute updates
// yes no => changeGeometryValues
// no yes => changeAttributeValues
// yes yes => changeFeatures
// to fix https://issues.qgis.org/issues/15741
// first of all check if feature to add is compatible with provider type
// this check have to be done before all checks to avoid to clear internal
// buffer if some of next steps success.
if ( success && !mAddedFeatures.isEmpty() )
{
if ( cap & QgsVectorDataProvider::AddFeatures )
{
if ( provider->doesStrictFeatureTypeCheck() )
{
for ( const auto &f : qgis::as_const( mAddedFeatures ) )
{
if ( ( ! f.hasGeometry() ) ||
( f.geometry().wkbType() == provider->wkbType() ) )
continue;
if ( provider->convertToProviderType( f.geometry() ).isNull() )
{
commitErrors << tr( "ERROR: %n feature(s) not added - geometry type is not compatible with the current layer.", "not added features count", mAddedFeatures.size() );
success = false;
break;
}
}
}
}
else
{
commitErrors << tr( "ERROR: %n feature(s) not added - provider doesn't support adding features.", "not added features count", mAddedFeatures.size() );
success = false;
}
}
//
// update geometries
//
if ( !mChangedGeometries.isEmpty() && ( ( cap & QgsVectorDataProvider::ChangeFeatures ) == 0 || mChangedAttributeValues.isEmpty() ) )
{
if ( provider->changeGeometryValues( mChangedGeometries ) )
{
commitErrors << tr( "SUCCESS: %n geometries were changed.", "changed geometries count", mChangedGeometries.size() );
emit committedGeometriesChanges( L->id(), mChangedGeometries );
mChangedGeometries.clear();
}
else
{
commitErrors << tr( "ERROR: %n geometries not changed.", "not changed geometries count", mChangedGeometries.size() );
success = false;
}
}
QgsFields oldFields = L->fields();
//
// delete attributes
//
bool attributesChanged = false;
if ( !mDeletedAttributeIds.isEmpty() )
{
if ( ( cap & QgsVectorDataProvider::DeleteAttributes ) && provider->deleteAttributes( mDeletedAttributeIds.toSet() ) )
{
commitErrors << tr( "SUCCESS: %n attribute(s) deleted.", "deleted attributes count", mDeletedAttributeIds.size() );
emit committedAttributesDeleted( L->id(), mDeletedAttributeIds );
mDeletedAttributeIds.clear();
attributesChanged = true;
}
else
{
commitErrors << tr( "ERROR: %n attribute(s) not deleted.", "not deleted attributes count", mDeletedAttributeIds.size() );
#if 0
QString list = "ERROR: Pending attribute deletes:";
Q_FOREACH ( int idx, mDeletedAttributeIds )
{
list.append( ' ' + L->fields().at( idx ).name() );
}
commitErrors << list;
#endif
success = false;
}
}