本文整理汇总了C++中QgsVectorLayer::pendingFields方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::pendingFields方法的具体用法?C++ QgsVectorLayer::pendingFields怎么用?C++ QgsVectorLayer::pendingFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::pendingFields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cacheJoinLayer
void QgsVectorLayerJoinBuffer::cacheJoinLayer( QgsVectorJoinInfo& joinInfo )
{
//memory cache not required or already done
if ( !joinInfo.memoryCache || joinInfo.cachedAttributes.size() > 0 )
{
return;
}
QgsVectorLayer* cacheLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( joinInfo.joinLayerId ) );
if ( cacheLayer )
{
int joinFieldIndex;
if ( joinInfo.joinFieldName.isEmpty() )
joinFieldIndex = joinInfo.joinFieldIndex; //for compatibility with 1.x
else
joinFieldIndex = cacheLayer->pendingFields().indexFromName( joinInfo.joinFieldName );
if ( joinFieldIndex < 0 || joinFieldIndex >= cacheLayer->pendingFields().count() )
return;
joinInfo.cachedAttributes.clear();
QgsFeatureIterator fit = cacheLayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ) );
QgsFeature f;
while ( fit.nextFeature( f ) )
{
const QgsAttributes& attrs = f.attributes();
joinInfo.cachedAttributes.insert( attrs[joinFieldIndex].toString(), attrs );
}
}
}
示例2: canvasReleaseEvent
void QgsMapToolOffsetCurve::canvasReleaseEvent( QMouseEvent * e )
{
Q_UNUSED( e );
QgsVectorLayer* vlayer = currentVectorLayer();
if ( !vlayer )
{
deleteRubberBandAndGeometry();
return;
}
if ( !mGeometryModified )
{
deleteRubberBandAndGeometry();
vlayer->destroyEditCommand();
return;
}
if ( mMultiPartGeometry )
{
mModifiedGeometry.convertToMultiType();
}
vlayer->beginEditCommand( tr( "Offset curve" ) );
bool editOk;
if ( mSourceLayerId == vlayer->id() && !mForceCopy )
{
editOk = vlayer->changeGeometry( mModifiedFeature, &mModifiedGeometry );
}
else
{
QgsFeature f;
f.setGeometry( mModifiedGeometry );
//add empty values for all fields (allows inserting attribute values via the feature form in the same session)
QgsAttributes attrs( vlayer->pendingFields().count() );
const QgsFields& fields = vlayer->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
attrs[idx] = QVariant();
}
f.setAttributes( attrs );
editOk = vlayer->addFeature( f );
}
if ( editOk )
{
vlayer->endEditCommand();
}
else
{
vlayer->destroyEditCommand();
}
deleteRubberBandAndGeometry();
deleteDistanceItem();
delete mSnapVertexMarker; mSnapVertexMarker = 0;
mForceCopy = false;
mCanvas->refresh();
}
示例3: writeXML
bool QgsGraduatedSymbolRenderer::writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const
{
bool returnval = true;
QDomElement graduatedsymbol = document.createElement( "graduatedsymbol" );
layer_node.appendChild( graduatedsymbol );
//
// Mode field first ...
//
QString modeValue = "";
if ( mMode == QgsGraduatedSymbolRenderer::Empty )
{
modeValue == "Empty";
}
else if ( QgsGraduatedSymbolRenderer::Quantile )
{
modeValue = "Quantile";
}
else //default
{
modeValue = "Equal Interval";
}
QDomElement modeElement = document.createElement( "mode" );
QDomText modeText = document.createTextNode( modeValue );
modeElement.appendChild( modeText );
graduatedsymbol.appendChild( modeElement );
//
// classification field now ...
//
QDomElement classificationfield = document.createElement( "classificationfield" );
const QgsVectorDataProvider* theProvider = vl.dataProvider();
if ( !theProvider )
{
return false;
}
QString classificationFieldName;
if ( vl.pendingFields().contains( mClassificationField ) )
{
classificationFieldName = vl.pendingFields()[ mClassificationField ].name();
}
QDomText classificationfieldtxt = document.createTextNode( classificationFieldName );
classificationfield.appendChild( classificationfieldtxt );
graduatedsymbol.appendChild( classificationfield );
for ( QList<QgsSymbol*>::const_iterator it = mSymbols.begin(); it != mSymbols.end(); ++it )
{
if ( !( *it )->writeXML( graduatedsymbol, document, &vl ) )
{
returnval = false;
}
}
return returnval;
}
示例4: updatePictureExpression
void QgsComposerPicture::updatePictureExpression()
{
QgsVectorLayer * vl = 0;
if ( mComposition->atlasComposition().enabled() )
{
vl = mComposition->atlasComposition().coverageLayer();
}
if ( mSourceExpression.size() > 0 )
{
if ( mPictureExpr )
{
delete mPictureExpr;
}
mPictureExpr = new QgsExpression( mSourceExpression );
// expression used to evaluate picture source
// test for evaluation errors
if ( mPictureExpr->hasParserError() )
{
QgsMessageLog::logMessage( tr( "Picture expression parsing error: %1" ).arg( mPictureExpr->parserErrorString() ), tr( "Composer" ) );
}
if ( vl )
{
const QgsFields& fields = vl->pendingFields();
mPictureExpr->prepare( fields );
}
}
}
示例5: prepareJoins
void QgsVectorLayerFeatureIterator::prepareJoins()
{
QgsAttributeList fetchAttributes = ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes ) ? mRequest.subsetOfAttributes() : L->pendingAllAttributesList();
QgsAttributeList sourceJoinFields; // attributes that also need to be fetched from this layer in order to have joins working
mFetchJoinInfo.clear();
QgsVectorLayerJoinBuffer* joinBuffer = L->mJoinBuffer;
const QgsFields& fields = L->pendingFields();
for ( QgsAttributeList::const_iterator attIt = fetchAttributes.constBegin(); attIt != fetchAttributes.constEnd(); ++attIt )
{
if ( !fields.exists( *attIt ) )
continue;
if ( fields.fieldOrigin( *attIt ) != QgsFields::OriginJoin )
continue;
int sourceLayerIndex;
const QgsVectorJoinInfo* joinInfo = joinBuffer->joinForFieldIndex( *attIt, fields, sourceLayerIndex );
Q_ASSERT( joinInfo );
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( joinInfo->joinLayerId ) );
Q_ASSERT( joinLayer );
if ( !mFetchJoinInfo.contains( joinLayer ) )
{
FetchJoinInfo info;
info.joinInfo = joinInfo;
info.joinLayer = joinLayer;
if ( joinInfo->targetFieldName.isEmpty() )
info.targetField = joinInfo->targetFieldIndex; //for compatibility with 1.x
else
info.targetField = fields.indexFromName( joinInfo->targetFieldName );
if ( joinInfo->joinFieldName.isEmpty() )
info.joinField = joinInfo->joinFieldIndex; //for compatibility with 1.x
else
info.joinField = joinLayer->pendingFields().indexFromName( joinInfo->joinFieldName );
info.indexOffset = *attIt - sourceLayerIndex;
if ( info.joinField < sourceLayerIndex )
info.indexOffset++;
// for joined fields, we always need to request the targetField from the provider too
if ( !fetchAttributes.contains( info.targetField ) )
sourceJoinFields << info.targetField;
mFetchJoinInfo.insert( joinLayer, info );
}
// store field source index - we'll need it when fetching from provider
mFetchJoinInfo[ joinLayer ].attributes.push_back( sourceLayerIndex );
}
// add sourceJoinFields if we're using a subset
if ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes )
mRequest.setSubsetOfAttributes( mRequest.subsetOfAttributes() + sourceJoinFields );
}
示例6: on_mButtonAddJoin_clicked
void QgsVectorLayerProperties::on_mButtonAddJoin_clicked()
{
QgsAddJoinDialog d( layer );
if ( d.exec() == QDialog::Accepted )
{
QgsVectorJoinInfo info;
info.targetFieldName = d.targetFieldName();
info.joinLayerId = d.joinedLayerId();
info.joinFieldName = d.joinFieldName();
info.memoryCache = d.cacheInMemory();
if ( layer )
{
//create attribute index if possible
if ( d.createAttributeIndex() )
{
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( info.joinLayerId ) );
if ( joinLayer )
{
joinLayer->dataProvider()->createAttributeIndex( joinLayer->pendingFields().indexFromName( info.joinFieldName ) );
}
}
layer->addJoin( info );
addJoinToTreeWidget( info );
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
!layer->isEditable() && layer->vectorJoins().size() < 1 );
}
}
}
示例7: writeXML
bool QgsUniqueValueRenderer::writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const
{
const QgsVectorDataProvider* theProvider = vl.dataProvider();
if ( !theProvider )
{
return false;
}
QString classificationFieldName;
const QgsFields& fields = vl.pendingFields();
if ( mClassificationField >= 0 && mClassificationField < fields.count() )
{
classificationFieldName = fields[ mClassificationField ].name();
}
bool returnval = true;
QDomElement uniquevalue = document.createElement( "uniquevalue" );
layer_node.appendChild( uniquevalue );
QDomElement classificationfield = document.createElement( "classificationfield" );
QDomText classificationfieldtxt = document.createTextNode( classificationFieldName );
classificationfield.appendChild( classificationfieldtxt );
uniquevalue.appendChild( classificationfield );
for ( QMap<QString, QgsSymbol*>::const_iterator it = mSymbols.begin(); it != mSymbols.end(); ++it )
{
if ( !( it.value()->writeXML( uniquevalue, document, &vl ) ) )
{
returnval = false;
}
}
return returnval;
}
示例8: updateFields
void QgsVectorLayerJoinBuffer::updateFields( QgsFields& fields )
{
QList< QgsVectorJoinInfo>::const_iterator joinIt = mVectorJoins.constBegin();
for ( int joinIdx = 0 ; joinIt != mVectorJoins.constEnd(); ++joinIt, ++joinIdx )
{
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( joinIt->joinLayerId ) );
if ( !joinLayer )
{
continue;
}
joinIt->tmpTargetField = fields.indexFromName( joinIt->targetFieldName );
const QgsFields& joinFields = joinLayer->pendingFields();
joinIt->tmpJoinField = joinFields.indexFromName( joinIt->joinFieldName );
for ( int idx = 0; idx < joinFields.count(); ++idx )
{
//skip the join field to avoid double field names (fields often have the same name)
if ( joinFields[idx].name() != joinIt->joinFieldName )
{
QgsField f = joinFields[idx];
f.setName( joinLayer->name() + "_" + f.name() );
fields.append( f, QgsFields::OriginJoin, idx + ( joinIdx*1000 ) );
}
}
}
}
示例9: addLayerProjectSettings
void QgsServerProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocument& doc, QgsMapLayer* currentLayer ) const
{
if ( !currentLayer )
{
return;
}
// Layer tree name
QDomElement treeNameElem = doc.createElement( "TreeName" );
QDomText treeNameText = doc.createTextNode( currentLayer->name() );
treeNameElem.appendChild( treeNameText );
layerElem.appendChild( treeNameElem );
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vLayer = static_cast<QgsVectorLayer*>( currentLayer );
const QSet<QString>& excludedAttributes = vLayer->excludeAttributesWMS();
int displayFieldIdx = vLayer->fieldNameIndex( vLayer->displayField() );
QString displayField = displayFieldIdx < 0 ? "maptip" : vLayer->displayField();
//attributes
QDomElement attributesElem = doc.createElement( "Attributes" );
const QgsFields& layerFields = vLayer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
const QgsField& field = layerFields[idx];
if ( excludedAttributes.contains( field.name() ) )
{
continue;
}
// field alias in case of displayField
if ( idx == displayFieldIdx )
{
displayField = vLayer->attributeDisplayName( idx );
}
QDomElement attributeElem = doc.createElement( "Attribute" );
attributeElem.setAttribute( "name", field.name() );
attributeElem.setAttribute( "type", QVariant::typeToName( field.type() ) );
attributeElem.setAttribute( "typeName", field.typeName() );
QString alias = vLayer->attributeAlias( idx );
if ( !alias.isEmpty() )
{
attributeElem.setAttribute( "alias", alias );
}
//edit type to text
attributeElem.setAttribute( "editType", vLayer->editFormConfig()->widgetType( idx ) );
attributeElem.setAttribute( "comment", field.comment() );
attributeElem.setAttribute( "length", field.length() );
attributeElem.setAttribute( "precision", field.precision() );
attributesElem.appendChild( attributeElem );
}
//displayfield
layerElem.setAttribute( "displayField", displayField );
//geometry type
layerElem.setAttribute( "geometryType", QGis::featureType( vLayer->wkbType() ) );
layerElem.appendChild( attributesElem );
}
}
示例10: updateFields
void QgsVectorLayerJoinBuffer::updateFields( QgsFields& fields )
{
QList< QgsVectorJoinInfo>::const_iterator joinIt = mVectorJoins.constBegin();
for ( int joinIdx = 0 ; joinIt != mVectorJoins.constEnd(); ++joinIt, ++joinIdx )
{
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( joinIt->joinLayerId ) );
if ( !joinLayer )
{
continue;
}
const QgsFields& joinFields = joinLayer->pendingFields();
QString joinFieldName;
if ( joinIt->joinFieldName.isEmpty() && joinIt->joinFieldIndex >= 0 && joinIt->joinFieldIndex < joinFields.count() )
joinFieldName = joinFields.field( joinIt->joinFieldIndex ).name(); //for compatibility with 1.x
else
joinFieldName = joinIt->joinFieldName;
for ( int idx = 0; idx < joinFields.count(); ++idx )
{
//skip the join field to avoid double field names (fields often have the same name)
if ( joinFields[idx].name() != joinFieldName )
{
QgsField f = joinFields[idx];
f.setName( joinLayer->name() + "_" + f.name() );
fields.append( f, QgsFields::OriginJoin, idx + ( joinIdx*1000 ) );
}
}
}
}
示例11: exportErrorsDo
bool QgsGeometryCheckerResultTab::exportErrorsDo( const QString& file )
{
QList< QPair<QString, QString> > attributes;
attributes.append( qMakePair( QString( "FeatureID" ), QString( "String;10;" ) ) );
attributes.append( qMakePair( QString( "ErrorDesc" ), QString( "String;80;" ) ) );
QLibrary ogrLib( QgsProviderRegistry::instance()->library( "ogr" ) );
if ( !ogrLib.load() )
{
return false;
}
typedef bool ( *createEmptyDataSourceProc )( const QString&, const QString&, const QString&, QGis::WkbType, const QList< QPair<QString, QString> >&, const QgsCoordinateReferenceSystem * );
createEmptyDataSourceProc createEmptyDataSource = ( createEmptyDataSourceProc ) cast_to_fptr( ogrLib.resolve( "createEmptyDataSource" ) );
if ( !createEmptyDataSource )
{
return false;
}
if ( !createEmptyDataSource( file, "ESRI Shapefile", mFeaturePool->getLayer()->dataProvider()->encoding(), QGis::WKBPoint, attributes, &mFeaturePool->getLayer()->crs() ) )
{
return false;
}
QgsVectorLayer* layer = new QgsVectorLayer( file, QFileInfo( file ).baseName(), "ogr" );
if ( !layer->isValid() )
{
delete layer;
return false;
}
int fieldFeatureId = layer->fieldNameIndex( "FeatureID" );
int fieldErrDesc = layer->fieldNameIndex( "ErrorDesc" );
for ( int row = 0, nRows = ui.tableWidgetErrors->rowCount(); row < nRows; ++row )
{
QgsGeometryCheckError* error = ui.tableWidgetErrors->item( row, 0 )->data( Qt::UserRole ).value<QgsGeometryCheckError*>();
QgsFeature f( layer->pendingFields() );
f.setAttribute( fieldFeatureId, error->featureId() );
f.setAttribute( fieldErrDesc, error->description() );
f.setGeometry( new QgsGeometry( error->location().clone() ) );
layer->dataProvider()->addFeatures( QgsFeatureList() << f );
}
// Remove existing layer with same uri
QStringList toRemove;
foreach ( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() )
{
if ( dynamic_cast<QgsVectorLayer*>( maplayer ) &&
static_cast<QgsVectorLayer*>( maplayer )->dataProvider()->dataSourceUri() == layer->dataProvider()->dataSourceUri() )
{
toRemove.append( maplayer->id() );
}
}
if ( !toRemove.isEmpty() )
{
QgsMapLayerRegistry::instance()->removeMapLayers( toRemove );
}
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << layer );
return true;
}
示例12: 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()->mapSettings().destinationCrs(),
vl->crs() );
int startVertexIdx = path->findVertex( p1 );
int stopVertexIdx = path->findVertex( p2 );
double time = 0.0;
double cost = 0.0;
Unit timeUnit = Unit::byName( mPlugin->timeUnitName() );
Unit distanceUnit = Unit::byName( mPlugin->distanceUnitName() );
QgsPolyline p;
while ( startVertexIdx != stopVertexIdx )
{
if ( stopVertexIdx < 0 )
break;
QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
const QgsGraphArc& e = path->arc( l.front() );
cost += e.property( 0 ).toDouble();
time += e.property( 1 ).toDouble();
p.push_front( ct.transform( path->vertex( e.inVertex() ).point() ) );
stopVertexIdx = e.outVertex();
}
p.push_front( ct.transform( p1 ) );
QgsFeature f;
f.initAttributes( vl->pendingFields().count() );
f.setGeometry( QgsGeometry::fromPolyline( p ) );
f.setAttribute( 0, cost / distanceUnit.multipler() );
f.setAttribute( 1, time / timeUnit.multipler() );
QgsFeatureList features;
features << f;
vl->dataProvider()->addFeatures( features );
vl->updateExtents();
mPlugin->iface()->mapCanvas()->update();
delete path;
}
示例13: isExpressionValid
bool QgsFieldExpressionWidget::isExpressionValid( const QString expressionStr )
{
QgsVectorLayer* vl = layer();
QgsExpression expression( expressionStr );
expression.prepare( vl ? vl->pendingFields() : QgsFields() );
return !expression.hasParserError();
}
示例14: setEditorData
void FieldSelectorDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const
{
const QgsVectorLayerAndAttributeModel *m = dynamic_cast< const QgsVectorLayerAndAttributeModel *>( index.model() );
if ( !m )
return;
QgsVectorLayer *vl = m->vectorLayer( index );
if ( !vl )
return;
QgsFieldComboBox *fcb = qobject_cast<QgsFieldComboBox *>( editor );
if ( !fcb )
return;
int idx = m->attributeIndex( vl );
if ( vl->pendingFields().exists( idx ) )
fcb->setField( vl->pendingFields()[ idx ].name() );
}
示例15: addLayerProjectSettings
void QgsServerProjectParser::addLayerProjectSettings( QDomElement& layerElem, QDomDocument& doc, QgsMapLayer* currentLayer ) const
{
if ( !currentLayer )
{
return;
}
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer* vLayer = static_cast<QgsVectorLayer*>( currentLayer );
const QSet<QString>& excludedAttributes = vLayer->excludeAttributesWMS();
QString displayField = vLayer->displayField();
//attributes
QDomElement attributesElem = doc.createElement( "Attributes" );
const QgsFields& layerFields = vLayer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
const QgsField& field = layerFields[idx];
if ( excludedAttributes.contains( field.name() ) )
{
continue;
}
// field alias in case of displayField
if ( field.name() == displayField )
{
displayField = vLayer->attributeDisplayName( idx );
}
QDomElement attributeElem = doc.createElement( "Attribute" );
attributeElem.setAttribute( "name", field.name() );
attributeElem.setAttribute( "type", QVariant::typeToName( field.type() ) );
attributeElem.setAttribute( "typeName", field.typeName() );
QString alias = vLayer->attributeAlias( idx );
if ( !alias.isEmpty() )
{
attributeElem.setAttribute( "alias", alias );
}
//edit type to text
attributeElem.setAttribute( "editType", vLayer->editorWidgetV2( idx ) );
attributeElem.setAttribute( "comment", field.comment() );
attributeElem.setAttribute( "length", field.length() );
attributeElem.setAttribute( "precision", field.precision() );
attributesElem.appendChild( attributeElem );
}
//displayfield
layerElem.setAttribute( "displayField", displayField );
layerElem.appendChild( attributesElem );
}
}