Skip to content
Permalink
Browse files

Fix processing rendering styles for output dialog, functionality

  • Loading branch information
nyalldawson committed Aug 18, 2017
1 parent 0a4a7ac commit 7879c0a20b460ed1f6167850a8a1841af48529b5
@@ -92,14 +92,19 @@ class QgsProcessingContext
struct LayerDetails
{

LayerDetails( const QString &name, QgsProject *project );
LayerDetails( const QString &name, QgsProject *project, const QString &outputName = QString() );
%Docstring
Constructor for LayerDetails.
%End

QString name;
%Docstring
Friendly name for layer, to use when loading layer into project.
%End

QString outputName;
%Docstring
Associated output name from algorithm which generated the layer.
%End

QgsProject *project;
@@ -32,12 +32,11 @@
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog, QHeaderView, QTableWidgetItem

from qgis.core import QgsProcessingParameterDefinition
from qgis.core import (QgsProcessingOutputRasterLayer,
QgsProcessingOutputVectorLayer)

from processing.gui.RenderingStyles import RenderingStyles
from processing.gui.RenderingStyleFilePanel import RenderingStyleFilePanel
from processing.core.outputs import OutputRaster
from processing.core.outputs import OutputVector

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
@@ -61,29 +60,27 @@ def __init__(self, alg):

def setTableContent(self):
numOutputs = 0
for output in self.alg.outputs:
if isinstance(output, (OutputVector, OutputRaster)):
if not output.flags() & QgsProcessingParameterDefinition.FlagHidden:
numOutputs += 1
for output in self.alg.outputDefinitions():
if isinstance(output, (QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer)):
numOutputs += 1
self.tblStyles.setRowCount(numOutputs)

i = 0
for output in self.alg.outputs:
if isinstance(output, (OutputVector, OutputRaster)):
if not output.flags() & QgsProcessingParameterDefinition.FlagHidden:
item = QTableWidgetItem(output.description() + '<' +
output.__class__.__name__ + '>')
item.setFlags(Qt.ItemIsEnabled)
self.tblStyles.setItem(i, 0, item)
item = RenderingStyleFilePanel()
style = \
RenderingStyles.getStyle(self.alg.id(),
output.name())
if style:
item.setText(str(style))
self.valueItems[output.name()] = item
self.tblStyles.setCellWidget(i, 1, item)
self.tblStyles.setRowHeight(i, 22)
for output in self.alg.outputDefinitions():
if isinstance(output, (QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer)):
item = QTableWidgetItem(output.description() + '<' +
output.__class__.__name__ + '>')
item.setFlags(Qt.ItemIsEnabled)
self.tblStyles.setItem(i, 0, item)
item = RenderingStyleFilePanel()
style = \
RenderingStyles.getStyle(self.alg.id(),
output.name())
if style:
item.setText(str(style))
self.valueItems[output.name()] = item
self.tblStyles.setCellWidget(i, 1, item)
self.tblStyles.setRowHeight(i, 22)
i += 1

def accept(self):
@@ -60,7 +60,9 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
if layer is not None:
layer.setName(details.name)

style = RenderingStyles.getStyle(alg.id(), layer.name())
style = None
if details.outputName:
style = RenderingStyles.getStyle(alg.id(), details.outputName)
if style is None:
if layer.type() == QgsMapLayer.RasterLayer:
style = ProcessingConfig.getSetting(ProcessingConfig.RASTER_STYLE)
@@ -134,14 +134,18 @@ class CORE_EXPORT QgsProcessingContext
/**
* Constructor for LayerDetails.
*/
LayerDetails( const QString &name, QgsProject *project )
LayerDetails( const QString &name, QgsProject *project, const QString &outputName = QString() )
: name( name )
, outputName( outputName )
, project( project )
{}

//! Friendly name for layer, to use when loading layer into project.
QString name;

//! Associated output name from algorithm which generated the layer.
QString outputName;

//! Destination project
QgsProject *project;

@@ -265,7 +265,10 @@ QgsFeatureSink *QgsProcessingParameters::parameterAsSink( const QgsProcessingPar
{
destName = definition->description();
}
context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject ) );
QString outputName;
if ( definition )
outputName = definition->name();
context.addLayerToLoadOnCompletion( destinationIdentifier, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName ) );
}

return sink.release();
@@ -404,11 +407,14 @@ QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingPara

if ( destinationProject )
{
QString outputName;
if ( destName.isEmpty() && definition )
{
destName = definition->description();
}
context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject ) );
if ( definition )
outputName = definition->name();
context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName ) );
}

return dest;
@@ -1382,6 +1382,7 @@ void TestQgsProcessing::parameters()
QCOMPARE( context2.layersToLoadOnCompletion().size(), 1 );
QCOMPARE( context2.layersToLoadOnCompletion().keys().at( 0 ), destId );
QCOMPARE( context2.layersToLoadOnCompletion().values().at( 0 ).name, QStringLiteral( "my_dest" ) );
QCOMPARE( context2.layersToLoadOnCompletion().values().at( 0 ).outputName, QStringLiteral( "fs" ) );
}

void TestQgsProcessing::algorithmParameters()
@@ -3820,6 +3821,7 @@ void TestQgsProcessing::parameterRasterOut()
QCOMPARE( context2.layersToLoadOnCompletion().size(), 1 );
QCOMPARE( context2.layersToLoadOnCompletion().keys().at( 0 ), QStringLiteral( "test.tif" ) );
QCOMPARE( context2.layersToLoadOnCompletion().values().at( 0 ).name, QStringLiteral( "my_dest" ) );
QCOMPARE( context2.layersToLoadOnCompletion().values().at( 0 ).outputName, QStringLiteral( "x" ) );
}

void TestQgsProcessing::parameterFileOut()

0 comments on commit 7879c0a

Please sign in to comment.
You can’t perform that action at this time.