本文整理汇总了C++中QgsVectorLayer::attributeDisplayName方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::attributeDisplayName方法的具体用法?C++ QgsVectorLayer::attributeDisplayName怎么用?C++ QgsVectorLayer::attributeDisplayName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::attributeDisplayName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sourceLayer
void QgsComposerAttributeTableV2::setDisplayAttributes( const QSet<int>& attr, bool refresh )
{
QgsVectorLayer* source = sourceLayer();
if ( !source )
{
return;
}
//rebuild columns list, taking only attributes with index in supplied QSet
qDeleteAll( mColumns );
mColumns.clear();
const QgsFields& fields = source->pendingFields();
if ( !attr.empty() )
{
QSet<int>::const_iterator attIt = attr.constBegin();
for ( ; attIt != attr.constEnd(); ++attIt )
{
int attrIdx = ( *attIt );
if ( !fields.exists( attrIdx ) )
{
continue;
}
QString currentAlias = source->attributeDisplayName( attrIdx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[attrIdx].name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
}
else
{
//resetting, so add all attributes to columns
for ( int idx = 0; idx < fields.count(); ++idx )
{
QString currentAlias = source->attributeDisplayName( idx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[idx].name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
}
if ( refresh )
{
refreshAttributes();
}
}
示例2: 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 );
}
}
示例3: sourceLayer
void QgsComposerAttributeTableV2::setDisplayedFields( const QStringList& fields, bool refresh )
{
QgsVectorLayer* source = sourceLayer();
if ( !source )
{
return;
}
//rebuild columns list, taking only fields contained in supplied list
qDeleteAll( mColumns );
mColumns.clear();
QgsFields layerFields = source->fields();
if ( !fields.isEmpty() )
{
Q_FOREACH ( const QString& field, fields )
{
int attrIdx = layerFields.lookupField( field );
if ( attrIdx < 0 )
continue;
QString currentAlias = source->attributeDisplayName( attrIdx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( layerFields.at( attrIdx ).name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
示例4: sourceLayer
void QgsComposerAttributeTableV2::resetColumns()
{
QgsVectorLayer *source = sourceLayer();
if ( !source )
{
return;
}
//remove existing columns
qDeleteAll( mColumns );
mColumns.clear();
//rebuild columns list from vector layer fields
int idx = 0;
const QgsFields sourceFields = source->fields();
for ( const auto &field : sourceFields )
{
QString currentAlias = source->attributeDisplayName( idx );
QgsComposerTableColumn *col = new QgsComposerTableColumn;
col->setAttribute( field.name() );
col->setHeading( currentAlias );
mColumns.append( col );
idx++;
}
}
示例5: 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", vLayer->attributeDisplayName( idx ) );
attributeElem.setAttribute( "type", QVariant::typeToName( field.type() ) );
attributeElem.setAttribute( "typeName", field.typeName() );
//edit type to text
QgsVectorLayer::EditType typeEnum = vLayer->editType( idx );
attributeElem.setAttribute( "editType", editTypeString( typeEnum ) );
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 );
}
}