Skip to content

Commit

Permalink
setAttributeAlias is now setFieldAlias
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 1, 2016
1 parent 37e06ae commit ff52a9f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions doc/api_break.dox
Expand Up @@ -1416,8 +1416,8 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.</li>
<li>editFormConfig() returns a copy instead of direct access (Use setEditFormConfig to update)
<li>Removed valueRelation(), replaced with QgsEditFormConfig::editorWidgetConfig
<li>Removed fieldNameIndex(), use fields().lookupField() or fields().indexFromName() instead
<li>Renamed addAttributeAlias() to setAttributeAlias()
<li>Renamed remAttributeAlias() to removeAttributeAlias()
<li>Renamed addAttributeAlias() to setFieldAlias()
<li>Renamed remAttributeAlias() to removeFieldAlias()
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayerEditBuffer QgsVectorLayerEditBuffer
Expand Down
10 changes: 5 additions & 5 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -1078,32 +1078,32 @@ class QgsVectorLayer : QgsMapLayer
*
* @note Added in QGIS 3.0
*/
void setAttributeAlias( int index, const QString& aliasString );
void setFieldAlias( int index, const QString& aliasString );

/**
* Removes an alias (a display name) for attributes to display in dialogs
*
* @note Added in QGIS 3.0
*/
void removeAttributeAlias( int index );
void removeFieldAlias( int index );

/** Renames an attribute field (but does not commit it).
* @param attIndex attribute index
* @param newName new name of field
* @note added in QGIS 2.16
*/
bool renameAttribute( int attIndex, const QString& newName );
bool renameAttribute( int index, const QString& newName );

/**
* Returns the alias of an attribute name or a null string if there is no alias.
*
* @see {attributeDisplayName( int attributeIndex )} which returns the field name
* if no alias is defined.
*/
QString attributeAlias( int attributeIndex ) const;
QString attributeAlias( int index ) const;

/** Convenience function that returns the attribute alias if defined or the field name else */
QString attributeDisplayName( int attributeIndex ) const;
QString attributeDisplayName( int index ) const;

const QMap< QString, QString >& attributeAliases() const;

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -765,11 +765,11 @@ void QgsFieldsProperties::attributesListCellChanged( int row, int column )
{
if ( !aliasItem->text().trimmed().isEmpty() )
{
mLayer->setAttributeAlias( idx, aliasItem->text() );
mLayer->setFieldAlias( idx, aliasItem->text() );
}
else
{
mLayer->removeAttributeAlias( idx );
mLayer->removeFieldAlias( idx );
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2107,7 +2107,7 @@ bool QgsVectorLayer::addAttribute( const QgsField &field )
return mEditBuffer->addAttribute( field );
}

void QgsVectorLayer::removeAttributeAlias( int attIndex )
void QgsVectorLayer::removeFieldAlias( int attIndex )
{
if ( attIndex < 0 || attIndex >= fields().count() )
return;
Expand All @@ -2123,15 +2123,15 @@ void QgsVectorLayer::removeAttributeAlias( int attIndex )
}
}

bool QgsVectorLayer::renameAttribute( int attIndex, const QString& newName )
bool QgsVectorLayer::renameAttribute( int index, const QString& newName )
{
if ( !mEditBuffer || !mDataProvider )
return false;

return mEditBuffer->renameAttribute( attIndex, newName );
return mEditBuffer->renameAttribute( index, newName );
}

void QgsVectorLayer::setAttributeAlias( int attIndex, const QString& aliasString )
void QgsVectorLayer::setFieldAlias( int attIndex, const QString& aliasString )
{
if ( attIndex < 0 || attIndex >= fields().count() )
return;
Expand All @@ -2144,18 +2144,18 @@ void QgsVectorLayer::setAttributeAlias( int attIndex, const QString& aliasString
emit layerModified(); // TODO[MD]: should have a different signal?
}

QString QgsVectorLayer::attributeAlias( int attributeIndex ) const
QString QgsVectorLayer::attributeAlias( int index ) const
{
if ( attributeIndex < 0 || attributeIndex >= fields().count() )
if ( index < 0 || index >= fields().count() )
return QString();

return fields().at( attributeIndex ).alias();
return fields().at( index ).alias();
}

QString QgsVectorLayer::attributeDisplayName( int attributeIndex ) const
QString QgsVectorLayer::attributeDisplayName( int index ) const
{
if ( attributeIndex >= 0 && attributeIndex < mFields.count() )
return mFields.at( attributeIndex ).displayName();
if ( index >= 0 && index < mFields.count() )
return mFields.at( index ).displayName();
else
return QString();
}
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1202,32 +1202,32 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*
* @note Added in QGIS 3.0
*/
void setAttributeAlias( int index, const QString& aliasString );
void setFieldAlias( int index, const QString& aliasString );

/**
* Removes an alias (a display name) for attributes to display in dialogs
*
* @note Added in QGIS 3.0
*/
void removeAttributeAlias( int index );
void removeFieldAlias( int index );

/** Renames an attribute field (but does not commit it).
* @param attIndex attribute index
* @param index attribute index
* @param newName new name of field
* @note added in QGIS 2.16
*/
bool renameAttribute( int attIndex, const QString& newName );
bool renameAttribute( int index, const QString& newName );

/**
* Returns the alias of an attribute name or a null string if there is no alias.
*
* @see {attributeDisplayName( int attributeIndex )} which returns the field name
* if no alias is defined.
*/
QString attributeAlias( int attributeIndex ) const;
QString attributeAlias( int index ) const;

/** Convenience function that returns the attribute alias if defined or the field name else */
QString attributeDisplayName( int attributeIndex ) const;
QString attributeDisplayName( int index ) const;

//! Returns a map of field name to attribute alias
QgsStringMap attributeAliases() const;
Expand Down
12 changes: 6 additions & 6 deletions tests/src/python/test_qgsvectorlayer.py
Expand Up @@ -1615,27 +1615,27 @@ def testGetSetAliases(self):
self.assertFalse(layer.attributeAlias(1))
self.assertFalse(layer.attributeAlias(2))

layer.addAttributeAlias(0, "test")
layer.setFieldAlias(0, "test")
self.assertEqual(layer.attributeAlias(0), "test")
self.assertFalse(layer.attributeAlias(1))
self.assertFalse(layer.attributeAlias(2))
self.assertEqual(layer.fields().at(0).alias(), "test")

layer.addAttributeAlias(1, "test2")
layer.setFieldAlias(1, "test2")
self.assertEqual(layer.attributeAlias(0), "test")
self.assertEqual(layer.attributeAlias(1), "test2")
self.assertFalse(layer.attributeAlias(2))
self.assertEqual(layer.fields().at(0).alias(), "test")
self.assertEqual(layer.fields().at(1).alias(), "test2")

layer.addAttributeAlias(1, None)
layer.setFieldAlias(1, None)
self.assertEqual(layer.attributeAlias(0), "test")
self.assertFalse(layer.attributeAlias(1))
self.assertFalse(layer.attributeAlias(2))
self.assertEqual(layer.fields().at(0).alias(), "test")
self.assertFalse(layer.fields().at(1).alias())

layer.remAttributeAlias(0)
layer.removeFieldAlias(0)
self.assertFalse(layer.attributeAlias(0))
self.assertFalse(layer.attributeAlias(1))
self.assertFalse(layer.attributeAlias(2))
Expand All @@ -1657,8 +1657,8 @@ def testSaveRestoreAliases(self):
self.assertFalse(layer2.attributeAlias(1))

# set some aliases
layer.addAttributeAlias(0, "test")
layer.addAttributeAlias(1, "test2")
layer.setFieldAlias(0, "test")
layer.setFieldAlias(1, "test2")

doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
Expand Down

0 comments on commit ff52a9f

Please sign in to comment.