Skip to content
Permalink
Browse files
fix #3057
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15687 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 9, 2011
1 parent 7b497d2 commit 3c50546bf469d4a2ff3de082f19be3fb7238513e
Showing with 38 additions and 21 deletions.
  1. +36 −19 src/core/qgsvectorlayer.cpp
  2. +2 −2 src/core/qgsvectorlayer.h
@@ -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
@@ -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" ) );
}
}

@@ -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 );
}
@@ -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
@@ -3369,7 +3387,6 @@ bool QgsVectorLayer::deleteAttribute( int index )
mDeletedAttributeIds.insert( index );
mAddedAttributeIds.remove( index );
mUpdatedFields.remove( index );
mAttributeAliasMap.remove( index );

setModified( true, false );

@@ -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;

0 comments on commit 3c50546

Please sign in to comment.