Skip to content

Commit

Permalink
Merge pull request #1481 from giohappy/alias_remove_when_empty
Browse files Browse the repository at this point in the history
Remove alias from vector layer if it's an empty string.  Fix #10437
  • Loading branch information
NathanW2 committed Aug 10, 2014
2 parents fe4e552 + 26587af commit c3bd82a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,14 @@ void QgsFieldsProperties::attributesListCellChanged( int row, int column )
QTableWidgetItem *aliasItem = mFieldsList->item( row, column );
if ( aliasItem )
{
mLayer->addAttributeAlias( idx, aliasItem->text() );
if ( !aliasItem->text().trimmed().isEmpty() )
{
mLayer->addAttributeAlias( idx, aliasItem->text() );
}
else
{
mLayer->remAttributeAlias(idx);
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,19 @@ bool QgsVectorLayer::addAttribute( const QgsField &field )
return mEditBuffer->addAttribute( field );
}

void QgsVectorLayer::remAttributeAlias( int attIndex)
{
if ( attIndex < 0 || attIndex >= pendingFields().count() )
return;

QString name = pendingFields()[ attIndex ].name();
if ( mAttributeAliasMap.contains(name) )
{
mAttributeAliasMap.remove( name );
emit layerModified();
}
}

void QgsVectorLayer::addAttributeAlias( int attIndex, QString aliasString )
{
if ( attIndex < 0 || attIndex >= pendingFields().count() )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
void addAttributeAlias( int attIndex, QString aliasString );

/**
* Removes an alias (a display name) for attributes to display in dialogs
* @note added in version 2.4
*/
void remAttributeAlias( int attIndex );

/**
* Adds a tab (for the attribute editor form) holding groups and fields
* @note added in version 2.0
Expand Down

0 comments on commit c3bd82a

Please sign in to comment.