本文整理汇总了C++中QgsVectorLayer::displayField方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::displayField方法的具体用法?C++ QgsVectorLayer::displayField怎么用?C++ QgsVectorLayer::displayField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::displayField方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 );
}
}
示例2: fetchFeature
QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsMapCanvas *mpMapCanvas )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
return "";
// Get the setting for the search radius from user preferences, if it exists
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
// create the search rectangle
double searchRadius = mpMapCanvas->extent().width() * ( identifyValue / 100.0 );
QgsRectangle r;
r.setXMinimum( mapPosition.x() - searchRadius );
r.setYMinimum( mapPosition.y() - searchRadius );
r.setXMaximum( mapPosition.x() + searchRadius );
r.setYMaximum( mapPosition.y() + searchRadius );
r = mpMapCanvas->mapSettings().mapToLayerCoordinates( layer, r );
QgsFeature feature;
if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterRect( r ).setFlags( QgsFeatureRequest::ExactIntersect ) ).nextFeature( feature ) )
return "";
int idx = vlayer->fieldNameIndex( vlayer->displayField() );
if ( idx < 0 )
return QgsExpression::replaceExpressionText( vlayer->displayField(), &feature, vlayer );
else
return feature.attribute( idx ).toString();
}
示例3: 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 );
}
}