Re: [QGIS-Developer] How to use postProcessLayer in plugin processing

2019-05-16 Thread Nyall Dawson
On Thu, 16 May 2019 at 18:33, René-Luc Dhont  wrote:
>
> Thanks, this link is helpful
> https://gist.github.com/nyalldawson/26c091dd48b4f8bf56f172efe22cf75f
>
> It contains a hack to work around sip bug!

Hey Matthias, on this hack -- is it the same issue as you fixed a
while back for registry instances?

Nyall

>
> Regards,
> René-Luc
>
> Le 16/05/2019 à 10:25, Tom Chadwin a écrit :
> > Don't know if any of the links in this reply from Nyall are of any use?
> >
> > https://lists.osgeo.org/pipermail/qgis-developer/2018-September/054480.html
> >
> > Tom
> >
> >
> >
> > -
> > Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon
> > --
> > Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html
> > ___
> > 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] How to use postProcessLayer in plugin processing

2019-05-16 Thread René-Luc Dhont

Thanks, this link is helpful
https://gist.github.com/nyalldawson/26c091dd48b4f8bf56f172efe22cf75f

It contains a hack to work around sip bug!

Regards,
René-Luc

Le 16/05/2019 à 10:25, Tom Chadwin a écrit :

Don't know if any of the links in this reply from Nyall are of any use?

https://lists.osgeo.org/pipermail/qgis-developer/2018-September/054480.html

Tom



-
Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon
--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html
___
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] How to use postProcessLayer in plugin processing

2019-05-16 Thread Tom Chadwin
Don't know if any of the links in this reply from Nyall are of any use?

https://lists.osgeo.org/pipermail/qgis-developer/2018-September/054480.html

Tom



-
Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon 
--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html
___
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] How to use postProcessLayer in plugin processing

2019-05-16 Thread René-Luc Dhont

Hi Devs,

I would like to set the style an output layer in a script processing. My 
algorithm is added to QGIS Processing by a plugin.


I have tested this :

```

class loadNamedStylePostProcessor(QgsProcessingLayerPostProcessorInterface):

    def __init__(self, outputName, feedback):
    super().__init__()
    self.outputName = outputName
    feedback.pushInfo('loadNamedStylePostProcessor init')
    feedback.pushInfo(self.outputName)

    def postProcessLayer(layer, context, feedback):
    feedback.pushInfo('postProcessLayer')
    feedback.pushInfo(self.outputName)
    feedback.pushInfo(layer.name())


class testPostProcessLayerAlgorithm(QgsProcessingAlgorithm):

    OUTPUT = 'OUTPUT'
    INPUT = 'INPUT'

    def initAlgorithm(self, config):
    self.addParameter(
    QgsProcessingParameterFeatureSource(
    self.INPUT,
    self.tr('Input layer'),
    [QgsProcessing.TypeVectorAnyGeometry]
    )
    )

    self.addParameter(
    QgsProcessingParameterFeatureSink(
    self.OUTPUT,
    self.tr('Output layer')
    )
    )

    def processAlgorithm(self, parameters, context, feedback):
    source = self.parameterAsSource(parameters, self.INPUT, context)
    (sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT,
   context, source.fields(), source.wkbType(), 
source.sourceCrs())


    total = 100.0 / source.featureCount() if source.featureCount() 
else 0

    features = source.getFeatures()

    for current, feature in enumerate(features):
    # Stop the algorithm if cancel button has been clicked
    if feedback.isCanceled():
    break

    # Add a feature in the sink
    sink.addFeature(feature, QgsFeatureSink.FastInsert)

    # Update the progress bar
    feedback.setProgress(int(current * total))

    context.layerToLoadOnCompletionDetails(
    dest_id
    ).setPostProcessor(
    loadNamedStylePostProcessor(self.OUTPUT, feedback)
    )

    return {self.OUTPUT: dest_id}

    def name(self):
    return 'test_post_process_layer'

    def displayName(self):
    return self.tr('Test postProcessLayer')

    def group(self):
    return self.tr('Tests')

    def groupId(self):
    return 'tests'

    def tr(self, string):
    return QCoreApplication.translate('Processing', string)

    def createInstance(self):
    return self.__class__()
```

The postProcesser is well initialize, but I never have the messages form 
postProcessLayer.


Any one has already use it in some code ?

Regards,
René-Luc
___
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