Is there a way to add a current user label to the print composer in QGIS.
I thought there might be something similar to the $CURRENT_DATE format available.
This would be in a windows environment.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Currently, this is an unfulfilled feature request (see Feature #1385).
You could add your ideas for new 'tokens' (or 'fields' as they are monikered in the request). Remember to include recommended formatting options as per Qt classes for the data type, like has been done with the syntax of
$CURRENT_DATE(yyyy-MM-dd), which is resolved using
QDate::currentDate().toString( formatText ) and QDate class string formatting.
However, there are better solutions than trying to implement all the types of tokens users might need or request (which could be an every-expanding list).
There are currently at least two means to implement a more robust solution:
A) Label text is optionally generated using the QGIS Expression Editor
This is currently the method used in the advanced labeling engine...
Since Composer labels are not relative to a map layer's data source, the section of
Fields and Values would need to be replaced and populated with more appropriate Print Composer tokens, e.g. project name, title, projection, user, etc. (date functions are already in the master branch builds). Luckily, there has been work by developers to make it relatively 'easy' to add new expression sections, though it would still take some work. Additional work would also be needed to accommodate new tokens.
B) Label text (or tokens) is optionally the result of Python snippet(s)
While not as user-friendly as the Expression Editor solution, since it requires an understanding of Python, the implementation of such a feature would possibly only require a single development effort. Then, any textual aspect of a QGIS project, including its various Composer items, available via the PyQGIS API (i.e. Python Console), could be accessed, formatted and output to text.
The Python snippets could be wrapped in individual tokens and embedded in the current text of the text edit box, or be contained in an separate text edit box in the GUI, activated by check box. For security reasons, the code would probably not be auto-run on Composer launch (could be an option to allow always, though).
The separate text edit box approach would allow for Python code validation and the keying of specifically named Python functions, for example the following snippet:
import getpass from qgis.core import * def pytoken_user(): return getpass.getuser() def pytoken_title(): return QgsProject.instance().title()
would replace any number of in-text tokens named
Both of the above solutions are considerably more extensible than implementing individual tokens in-line in the QGIS source code. There may be other or better solutions, as well.
Dr. Hugentobler has recently been re-working the Print Composer in QGIS's master branch, so now is an ideal time to request such labeling features for the next version of QGIS. I'll add a feature request for these two ASAP.