Skip to content

Commit

Permalink
add funzione custom
Browse files Browse the repository at this point in the history
  • Loading branch information
pigreco committed Aug 2, 2024
1 parent efa9095 commit b21b7ad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ data | descrizione
21/05/2024 | nono post del blog [calcolo distanza predefinita](https://hfcqgis.opendatasicilia.it/blog/2024/05/21/distanza-predefinita-su-form/)
16/07/2024 | decimo post del blog [mappa valori al volo](https://hfcqgis.opendatasicilia.it/blog/2024/07/16/mappa-valori-generata-al-volo/)
27/07/2024 | undicesimo post del blog [statistiche punti sovrapposti](https://hfcqgis.opendatasicilia.it/blog/2024/07/27/statistiche-punti-sovrapposti/)
02/08/2024 | nuova funzione custom [recupera alias campo]()
36 changes: 36 additions & 0 deletions docs/gr_funzioni/custom/custom_unico.md
Original file line number Diff line number Diff line change
Expand Up @@ -1147,3 +1147,39 @@ def get_catg_label(value_in, feature, parent):
Lo script è stato realizzato da [Giulio Fattori](https://github.com/Korto19)

[![](../../img/custom/estrarre_label.png)](../../img/custom/estrarre_label.png)

## Recupera l'alias di un attributo specificato nel layer corrente

```py
# -*- coding: utf-8 -*-
"""
/***************************************************************************
ALIAS NAME CC BY 4.0
-------------------
copyright : (C) 2024 by Federico Gianoli
***************************************************************************/
"""

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom')
def get_field_alias(field_name, feature, parent):
"""
Retrieves the alias of a field specified in the current layer.
<ul> </ul>
<h2>Example usage:</h2>
<ul>
<li>get_field_alias('Field_Name') -> 'FieldAlias'</li>
</ul>
"""
layer = feature.fields()
field_index = layer.indexOf(field_name)

if field_index != -1:
alias = layer[field_index].alias()
return alias
else:
return f"Field '{field_name}' not found."
```
[![](../../img/custom/get_alias.png)](../../img/custom/get_alias.png)
Binary file added docs/img/custom/get_alias.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b21b7ad

Please sign in to comment.