Skip to content

Commit

Permalink
Merge pull request #37595 from gacarrillor/pr_processing_results_group
Browse files Browse the repository at this point in the history
Load processing results to layer group (optional)
  • Loading branch information
m-kuhn committed Aug 8, 2020
2 parents 5f88e3d + debe220 commit 2b3b88c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
18 changes: 15 additions & 3 deletions python/plugins/processing/core/ProcessingConfig.py
Expand Up @@ -62,6 +62,7 @@ class ProcessingConfig:
DEFAULT_OUTPUT_RASTER_LAYER_EXT = 'DefaultOutputRasterLayerExt'
DEFAULT_OUTPUT_VECTOR_LAYER_EXT = 'DefaultOutputVectorLayerExt'
TEMP_PATH = 'TEMP_PATH2'
RESULTS_GROUP_NAME = 'RESULTS_GROUP_NAME'

settings = {}
settingIcons = {}
Expand Down Expand Up @@ -170,8 +171,18 @@ def initialize():
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.TEMP_PATH,
ProcessingConfig.tr('Override temporary output folder path (leave blank for default)'), None,
valuetype=Setting.FOLDER))
ProcessingConfig.tr('Override temporary output folder path'), None,
valuetype=Setting.FOLDER,
placeholder=ProcessingConfig.tr('Leave blank for default')))

ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.RESULTS_GROUP_NAME,
ProcessingConfig.tr("Results group name"),
"",
valuetype=Setting.STRING,
placeholder=ProcessingConfig.tr("Leave blank to avoid loading results in a predetermined group")
))

@staticmethod
def setGroupIcon(group, icon):
Expand Down Expand Up @@ -258,7 +269,7 @@ class Setting:
MULTIPLE_FOLDERS = 6

def __init__(self, group, name, description, default, hidden=False, valuetype=None,
validator=None, options=None):
validator=None, options=None, placeholder=""):
self.group = group
self.name = name
self.qname = "Processing/Configuration/" + self.name
Expand All @@ -267,6 +278,7 @@ def __init__(self, group, name, description, default, hidden=False, valuetype=No
self.hidden = hidden
self.valuetype = valuetype
self.options = options
self.placeholder = placeholder

if self.valuetype is None:
if isinstance(default, int):
Expand Down
16 changes: 10 additions & 6 deletions python/plugins/processing/gui/ConfigDialog.py
Expand Up @@ -366,15 +366,15 @@ def __init__(self, parent=None):
def createEditor(self, parent, options, index):
setting = index.model().data(index, Qt.UserRole)
if setting.valuetype == Setting.FOLDER:
return FileDirectorySelector(parent)
return FileDirectorySelector(parent, placeholder=setting.placeholder)
elif setting.valuetype == Setting.FILE:
return FileDirectorySelector(parent, True)
return FileDirectorySelector(parent, True, setting.placeholder)
elif setting.valuetype == Setting.SELECTION:
combo = QComboBox(parent)
combo.addItems(setting.options)
return combo
elif setting.valuetype == Setting.MULTIPLE_FOLDERS:
return MultipleDirectorySelector(parent)
return MultipleDirectorySelector(parent, setting.placeholder)
else:
value = self.convertValue(index.model().data(index, Qt.EditRole))
if isinstance(value, int):
Expand All @@ -387,7 +387,9 @@ def createEditor(self, parent, options, index):
spnBox.setDecimals(6)
return spnBox
elif isinstance(value, str):
return QLineEdit(parent)
lineEdit = QLineEdit(parent)
lineEdit.setPlaceholderText(setting.placeholder)
return lineEdit

def setEditorData(self, editor, index):
value = self.convertValue(index.model().data(index, Qt.EditRole))
Expand Down Expand Up @@ -433,13 +435,14 @@ def convertValue(self, value):

class FileDirectorySelector(QWidget):

def __init__(self, parent=None, selectFile=False):
def __init__(self, parent=None, selectFile=False, placeholder=""):
QWidget.__init__(self, parent)

# create gui
self.btnSelect = QToolButton()
self.btnSelect.setText('…')
self.lineEdit = QLineEdit()
self.lineEdit.setPlaceholderText(placeholder)
self.hbl = QHBoxLayout()
self.hbl.setMargin(0)
self.hbl.setSpacing(0)
Expand Down Expand Up @@ -480,13 +483,14 @@ def setText(self, value):

class MultipleDirectorySelector(QWidget):

def __init__(self, parent=None):
def __init__(self, parent=None, placeholder=""):
QWidget.__init__(self, parent)

# create gui
self.btnSelect = QToolButton()
self.btnSelect.setText('…')
self.lineEdit = QLineEdit()
self.lineEdit.setPlaceholderText(placeholder)
self.hbl = QHBoxLayout()
self.hbl.setMargin(0)
self.hbl.setSpacing(0)
Expand Down
13 changes: 12 additions & 1 deletion python/plugins/processing/gui/Postprocessing.py
Expand Up @@ -93,7 +93,18 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True, parame
if style:
layer.loadNamedStyle(style)

details.project.addMapLayer(context.temporaryLayerStore().takeMapLayer(layer))
# Load layer to layer tree root or to a specific group
mapLayer = context.temporaryLayerStore().takeMapLayer(layer)
group_name = ProcessingConfig.getSetting(ProcessingConfig.RESULTS_GROUP_NAME)
if group_name:
group = details.project.layerTreeRoot().findGroup(group_name)
if not group:
group = details.project.layerTreeRoot().insertGroup(0, group_name)

details.project.addMapLayer(mapLayer, False)
group.addLayer(mapLayer)
else:
details.project.addMapLayer(mapLayer)

if details.postProcessor():
details.postProcessor().postProcessLayer(layer, context, feedback)
Expand Down

0 comments on commit 2b3b88c

Please sign in to comment.