Re: [QGIS-Developer] Adding Map layer to current project destroy custom layer variables in Qgis3

2018-06-21 Thread David Marteau
Hi,

Yes, that's the point. I was surprised by the fact that those variables where 
stored as part of the exported qml file. 

I was trying to set those variable in processing algorithm so that I could 
achieve some parametrization of the style associated with the processing 
output, but no luck
since the qml  overwrite them when loaded in the layer.


> Le 21 juin 2018 à 11:48, Matthias Kuhn  a écrit :
> 
> Hi David,
> 
> Variables are a part of QML / Layer Style. There is a QEP open about
> handling of this:
> 
> https://github.com/qgis/QGIS-Enhancement-Proposals/issues/125
> 
> While variables are not explicitly mentioned in there, it would be good
> to treat them in the same way. I.e. allow exporting and importing QML
> files without variables. This should allow to export and subsequently
> load a style without variables being embedded.
> Would be great if you could add a comment to the QEP.
> 
> Thanks
> Matthias
> 
> On 06/20/2018 10:06 PM, David Marteau wrote:
>> 
>> Just found out that this is not addMapLayer that remove the variables
>> but 'layer.loadNamedStyle'
>> 
>> Print layer.customProperty('variableNames') just before calling
>> 'layer.loadNamedStyle' show variables
>> Print layer.customProperty('variableNames') just after the call :  empty
>> list
>> 
>> Reproduced in the python console:
>> 
> QgsExpressionContextUtils.setLayerVariable(layer,'FOO','BAR')
> layer.customProperty('variableNames')
>> ['FOO']
> layer.loadNamedStyle('mystyle.qml')
>> ('', True)
> layer.customProperty('variableNames')
>> []
>> 
>> 
>>> Le 20 juin 2018 à 18:13, David Marteau >> > a écrit :
>>> 
>>> Hi
>>> 
>>> I'm trying to set custom layers variables from processing
>>> using  QgsExpressionContextUtils.setLayerVariables to destination
>>> layers , I have found that those variables does not appear in 
>>> Qgis. 
>>> 
>>> I have found that when the layer is inserted in the current project
>>> (https://github.com/qgis/QGIS/blob/master/python/plugins/processing/gui/Postprocessing.py#L81)
>>> the layer variables are removed - Checking existence of the variable
>>> before
>>> and after the call of 'addMaperLayer' shows that layer variables are
>>> removed from custom properties.
>>> 
>>> I cannot tell if this is a bug or not because it seems that the
>>> removal may occurs in some signal handler. So if somebody has some
>>> clues to where to look, I will be grateful.
>>> 
>>> 
>>> Qgis version: 3.0.3-Girona
>>> 
>>> David
>> 
>> 
>> 
>> ___
>> QGIS-Developer mailing list
>> QGIS-Developer@lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> 
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] Adding Map layer to current project destroy custom layer variables in Qgis3

2018-06-21 Thread Matthias Kuhn
Hi David,

Variables are a part of QML / Layer Style. There is a QEP open about
handling of this:

https://github.com/qgis/QGIS-Enhancement-Proposals/issues/125

While variables are not explicitly mentioned in there, it would be good
to treat them in the same way. I.e. allow exporting and importing QML
files without variables. This should allow to export and subsequently
load a style without variables being embedded.
Would be great if you could add a comment to the QEP.

Thanks
Matthias

On 06/20/2018 10:06 PM, David Marteau wrote:
> 
> Just found out that this is not addMapLayer that remove the variables
> but 'layer.loadNamedStyle'
> 
> Print layer.customProperty('variableNames') just before calling
> 'layer.loadNamedStyle' show variables
> Print layer.customProperty('variableNames') just after the call :  empty
> list
> 
> Reproduced in the python console:
> 
 QgsExpressionContextUtils.setLayerVariable(layer,'FOO','BAR')
 layer.customProperty('variableNames')
> ['FOO']
 layer.loadNamedStyle('mystyle.qml')
> ('', True)
 layer.customProperty('variableNames')
> []
> 
> 
>> Le 20 juin 2018 à 18:13, David Marteau > > a écrit :
>>
>> Hi
>>
>> I'm trying to set custom layers variables from processing
>> using  QgsExpressionContextUtils.setLayerVariables to destination
>> layers , I have found that those variables does not appear in 
>> Qgis. 
>>
>> I have found that when the layer is inserted in the current project
>> (https://github.com/qgis/QGIS/blob/master/python/plugins/processing/gui/Postprocessing.py#L81)
>> the layer variables are removed - Checking existence of the variable
>> before
>> and after the call of 'addMaperLayer' shows that layer variables are
>> removed from custom properties.
>>
>> I cannot tell if this is a bug or not because it seems that the
>> removal may occurs in some signal handler. So if somebody has some
>> clues to where to look, I will be grateful.
>>
>>
>> Qgis version: 3.0.3-Girona
>>
>> David
> 
> 
> 
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 
___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] Adding Map layer to current project destroy custom layer variables in Qgis3

2018-06-21 Thread Richard Duivenvoorde
Hi David,

this sounds like a bug, so I would say: create an issue with clear steps
so others can reproduce/fix BUT I cannot reproduce. Doing your steps
I see 'FOO' is just saved in the project file (and viewable after
unzipping the qgz file)
And even after loading the qml and restartnig QGIS it is there.

I also am not sure what the exact purpose of
QgsExpressionContextUtils.setLayerVariable
would be, if I want stuff to be saved in project file I use:
layer.setCustomProperty('FOO', 'BAR')
and to retreive it:
layer.customProperty('FOO', '')

But, maybe others can tell something about this.
I use QGIS self build on Debian:
https://github.com/qgis/QGIS/commit/4790747aea

Regards,

Richard Duivenvoorde

On 20-06-18 22:06, David Marteau wrote:
> 
> Just found out that this is not addMapLayer that remove the variables
> but 'layer.loadNamedStyle'
> 
> Print layer.customProperty('variableNames') just before calling
> 'layer.loadNamedStyle' show variables
> Print layer.customProperty('variableNames') just after the call :  empty
> list
> 
> Reproduced in the python console:
> 
 QgsExpressionContextUtils.setLayerVariable(layer,'FOO','BAR')
 layer.customProperty('variableNames')
> ['FOO']
 layer.loadNamedStyle('mystyle.qml')
> ('', True)
 layer.customProperty('variableNames')
> []
> 
> 
>> Le 20 juin 2018 à 18:13, David Marteau > > a écrit :
>>
>> Hi
>>
>> I'm trying to set custom layers variables from processing
>> using  QgsExpressionContextUtils.setLayerVariables to destination
>> layers , I have found that those variables does not appear in 
>> Qgis. 
>>
>> I have found that when the layer is inserted in the current project
>> (https://github.com/qgis/QGIS/blob/master/python/plugins/processing/gui/Postprocessing.py#L81)
>> the layer variables are removed - Checking existence of the variable
>> before
>> and after the call of 'addMaperLayer' shows that layer variables are
>> removed from custom properties.
>>
>> I cannot tell if this is a bug or not because it seems that the
>> removal may occurs in some signal handler. So if somebody has some
>> clues to where to look, I will be grateful.
>>
>>
>> Qgis version: 3.0.3-Girona
>>
>> David
> 
> 
> 
> ___
> QGIS-Developer mailing list
> QGIS-Developer@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> 

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Re: [QGIS-Developer] Adding Map layer to current project destroy custom layer variables in Qgis3

2018-06-20 Thread David Marteau

Just found out that this is not addMapLayer that remove the variables but 
'layer.loadNamedStyle'

Print layer.customProperty('variableNames') just before calling 
'layer.loadNamedStyle' show variables
Print layer.customProperty('variableNames') just after the call :  empty list

Reproduced in the python console:

>>> QgsExpressionContextUtils.setLayerVariable(layer,'FOO','BAR')
>>> layer.customProperty('variableNames')
['FOO']
>>> layer.loadNamedStyle('mystyle.qml')
('', True)
>>> layer.customProperty('variableNames')
[]


> Le 20 juin 2018 à 18:13, David Marteau  a écrit :
> 
> Hi
> 
> I'm trying to set custom layers variables from processing using  
> QgsExpressionContextUtils.setLayerVariables to destination layers , I have 
> found that those variables does not appear in 
> Qgis. 
> 
> I have found that when the layer is inserted in the current project 
> (https://github.com/qgis/QGIS/blob/master/python/plugins/processing/gui/Postprocessing.py#L81
>  
> )
>  the layer variables are removed - Checking existence of the variable before
> and after the call of 'addMaperLayer' shows that layer variables are removed 
> from custom properties.
> 
> I cannot tell if this is a bug or not because it seems that the removal may 
> occurs in some signal handler. So if somebody has some clues to where to 
> look, I will be grateful.
> 
> 
> Qgis version: 3.0.3-Girona
> 
> David

___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

[QGIS-Developer] Adding Map layer to current project destroy custom layer variables in Qgis3

2018-06-20 Thread David Marteau
Hi

I'm trying to set custom layers variables from processing using  
QgsExpressionContextUtils.setLayerVariables to destination layers , I have 
found that those variables does not appear in 
Qgis. 

I have found that when the layer is inserted in the current project 
(https://github.com/qgis/QGIS/blob/master/python/plugins/processing/gui/Postprocessing.py#L81
 
)
 the layer variables are removed - Checking existence of the variable before
and after the call of 'addMaperLayer' shows that layer variables are removed 
from custom properties.

I cannot tell if this is a bug or not because it seems that the removal may 
occurs in some signal handler. So if somebody has some clues to where to look, 
I will be grateful.


Qgis version: 3.0.3-Girona

David___
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer