Skip to content

Commit

Permalink
fix #3057
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15687 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 9, 2011
1 parent 99276bc commit fb43855
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
55 changes: 36 additions & 19 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2679,14 +2679,14 @@ bool QgsVectorLayer::readXml( QDomNode & layer_node )
}
mJoinBuffer->readXml( layer_node );

updateFieldMap();

QString errorMsg;
if ( !readSymbology( layer_node, errorMsg ) )
{
return false;
}

updateFieldMap();

return mValid; // should be true if read successfully

} // void QgsVectorLayer::readXml
Expand Down Expand Up @@ -3039,16 +3039,27 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
if ( !aliasesNode.isNull() )
{
QDomElement aliasElem;
int index;
QString name;

QDomNodeList aliasNodeList = aliasesNode.toElement().elementsByTagName( "alias" );
for ( int i = 0; i < aliasNodeList.size(); ++i )
{
aliasElem = aliasNodeList.at( i ).toElement();
index = aliasElem.attribute( "index" ).toInt();
name = aliasElem.attribute( "name" );
mAttributeAliasMap.insert( index, name );

QString field;
if ( aliasElem.hasAttribute( "field" ) )
{
field = aliasElem.attribute( "field" );
}
else
{
int index = aliasElem.attribute( "index" ).toInt();

if ( pendingFields().contains( index ) )
field = pendingFields()[ index ].name();
}

mAttributeAliasMap.insert( field, aliasElem.attribute( "name" ) );
}
}

Expand Down Expand Up @@ -3217,11 +3228,16 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
if ( mAttributeAliasMap.size() > 0 )
{
QDomElement aliasElem = doc.createElement( "aliases" );
QMap<int, QString>::const_iterator a_it = mAttributeAliasMap.constBegin();
QMap<QString, QString>::const_iterator a_it = mAttributeAliasMap.constBegin();
for ( ; a_it != mAttributeAliasMap.constEnd(); ++a_it )
{
int idx = fieldNameIndex( a_it.key() );
if( idx < 0 )
continue;

QDomElement aliasEntryElem = doc.createElement( "alias" );
aliasEntryElem.setAttribute( "index", QString::number( a_it.key() ) );
aliasEntryElem.setAttribute( "field", a_it.key() );
aliasEntryElem.setAttribute( "index", idx );
aliasEntryElem.setAttribute( "name", a_it.value() );
aliasElem.appendChild( aliasEntryElem );
}
Expand Down Expand Up @@ -3317,21 +3333,23 @@ bool QgsVectorLayer::addAttribute( QString name, QString type )

void QgsVectorLayer::addAttributeAlias( int attIndex, QString aliasString )
{
mAttributeAliasMap.insert( attIndex, aliasString );
if ( !pendingFields().contains( attIndex ) )
return;

QString name = pendingFields()[ attIndex ].name();

mAttributeAliasMap.insert( name, aliasString );
emit layerModified( false );
}

QString QgsVectorLayer::attributeAlias( int attributeIndex ) const
{
QMap<int, QString>::const_iterator alias_it = mAttributeAliasMap.find( attributeIndex );
if ( alias_it != mAttributeAliasMap.constEnd() )
{
return alias_it.value();
}
else
{
return QString();
}
if ( !pendingFields().contains( attributeIndex ) )
return "";

QString name = pendingFields()[ attributeIndex ].name();

return mAttributeAliasMap.value( name, "" );
}

QString QgsVectorLayer::attributeDisplayName( int attributeIndex ) const
Expand Down Expand Up @@ -3369,7 +3387,6 @@ bool QgsVectorLayer::deleteAttribute( int index )
mDeletedAttributeIds.insert( index );
mAddedAttributeIds.remove( index );
mUpdatedFields.remove( index );
mAttributeAliasMap.remove( index );

setModified( true, false );

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.h
Expand Up @@ -884,8 +884,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** field map to commit */
QgsFieldMap mUpdatedFields;

/**Map that stores the aliases for attributes. Key is the attribute index and value the alias for that attribute*/
QMap<int, QString> mAttributeAliasMap;
/**Map that stores the aliases for attributes. Key is the attribute name and value the alias for that attribute*/
QMap< QString, QString > mAttributeAliasMap;

/** max field index */
int mMaxUpdatedIndex;
Expand Down

0 comments on commit fb43855

Please sign in to comment.