I'm doing a little script that allows to add and modify project variables.
The problem is that you don't know what the variables are inside the project from this interface and you have to write them correctly or it will add a new one.
I would like to improve it to looks like that
were you can see all the variables in side the project, and modify them.
Any idea of how to appomplish that? I've looked at the QGIS docs but didn't find anything usefull, but I'm probably wrong.
This is part of my code:
def initAlgorithm(self, config=None):
self.addParameter(
QgsProcessingParameterString(
self.NAME,
'Variable name'
)
)
self.addParameter(
QgsProcessingParameterString(
self.VALUE,
'Variable value'
)
)
def edit_variable(self, context, name, value):
QgsExpressionContextUtils.setProjectVariable(context.project(), name, value)
def prepareAlgorithm(self, parameters, context, feedback):
name = self.parameterAsString(
parameters,
self.NAME,
context
)
value = self.parameterAsString(
parameters,
self.VALUE,
context
)
if not name:
raise QgsProcessingException('Variable name cannot be empty')
QgsExpressionContextUtils.setProjectVariable(context.project(), name, value)
feedback.pushInfo(f'Set variable {name} to {value}')
return True
This is my idea of how to populate this object (perhaps by removing some of the unnecessary variables)
def populate_list(self, context):
project_scope = context.project()
variables = project_scope.variableNames()
for variable in variables:
bla bla




