Skip to content

Commit 26587af

Browse files
committed
Remove alias from vector layer if it's an empty string
1 parent 4b2c00c commit 26587af

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/app/qgsfieldsproperties.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,14 @@ void QgsFieldsProperties::attributesListCellChanged( int row, int column )
602602
QTableWidgetItem *aliasItem = mFieldsList->item( row, column );
603603
if ( aliasItem )
604604
{
605-
mLayer->addAttributeAlias( idx, aliasItem->text() );
605+
if ( !aliasItem->text().trimmed().isEmpty() )
606+
{
607+
mLayer->addAttributeAlias( idx, aliasItem->text() );
608+
}
609+
else
610+
{
611+
mLayer->remAttributeAlias(idx);
612+
}
606613
}
607614
}
608615
}

src/core/qgsvectorlayer.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,19 @@ bool QgsVectorLayer::addAttribute( const QgsField &field )
20402040
return mEditBuffer->addAttribute( field );
20412041
}
20422042

2043+
void QgsVectorLayer::remAttributeAlias( int attIndex)
2044+
{
2045+
if ( attIndex < 0 || attIndex >= pendingFields().count() )
2046+
return;
2047+
2048+
QString name = pendingFields()[ attIndex ].name();
2049+
if ( mAttributeAliasMap.contains(name) )
2050+
{
2051+
mAttributeAliasMap.remove( name );
2052+
emit layerModified();
2053+
}
2054+
}
2055+
20432056
void QgsVectorLayer::addAttributeAlias( int attIndex, QString aliasString )
20442057
{
20452058
if ( attIndex < 0 || attIndex >= pendingFields().count() )

src/core/qgsvectorlayer.h

+6
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
11031103
*/
11041104
void addAttributeAlias( int attIndex, QString aliasString );
11051105

1106+
/**
1107+
* Removes an alias (a display name) for attributes to display in dialogs
1108+
* @note added in version 2.4
1109+
*/
1110+
void remAttributeAlias( int attIndex );
1111+
11061112
/**
11071113
* Adds a tab (for the attribute editor form) holding groups and fields
11081114
* @note added in version 2.0

0 commit comments

Comments
 (0)