Skip to content

Commit c3bd82a

Browse files
committedAug 10, 2014
Merge pull request #1481 from giohappy/alias_remove_when_empty
Remove alias from vector layer if it's an empty string. Fix #10437
2 parents fe4e552 + 26587af commit c3bd82a

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
 

‎src/app/qgsfieldsproperties.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,14 @@ void QgsFieldsProperties::attributesListCellChanged( int row, int column )
605605
QTableWidgetItem *aliasItem = mFieldsList->item( row, column );
606606
if ( aliasItem )
607607
{
608-
mLayer->addAttributeAlias( idx, aliasItem->text() );
608+
if ( !aliasItem->text().trimmed().isEmpty() )
609+
{
610+
mLayer->addAttributeAlias( idx, aliasItem->text() );
611+
}
612+
else
613+
{
614+
mLayer->remAttributeAlias(idx);
615+
}
609616
}
610617
}
611618
}

‎src/core/qgsvectorlayer.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,19 @@ bool QgsVectorLayer::addAttribute( const QgsField &field )
20462046
return mEditBuffer->addAttribute( field );
20472047
}
20482048

2049+
void QgsVectorLayer::remAttributeAlias( int attIndex)
2050+
{
2051+
if ( attIndex < 0 || attIndex >= pendingFields().count() )
2052+
return;
2053+
2054+
QString name = pendingFields()[ attIndex ].name();
2055+
if ( mAttributeAliasMap.contains(name) )
2056+
{
2057+
mAttributeAliasMap.remove( name );
2058+
emit layerModified();
2059+
}
2060+
}
2061+
20492062
void QgsVectorLayer::addAttributeAlias( int attIndex, QString aliasString )
20502063
{
20512064
if ( attIndex < 0 || attIndex >= pendingFields().count() )

‎src/core/qgsvectorlayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
11161116
*/
11171117
void addAttributeAlias( int attIndex, QString aliasString );
11181118

1119+
/**
1120+
* Removes an alias (a display name) for attributes to display in dialogs
1121+
* @note added in version 2.4
1122+
*/
1123+
void remAttributeAlias( int attIndex );
1124+
11191125
/**
11201126
* Adds a tab (for the attribute editor form) holding groups and fields
11211127
* @note added in version 2.0

0 commit comments

Comments
 (0)
Please sign in to comment.