Skip to content

Commit

Permalink
Add placeholder to ProcessingConfig (Setting class); use the placehol…
Browse files Browse the repository at this point in the history
…der for 'results group name' setting
  • Loading branch information
gacarrillor committed Jul 20, 2020
1 parent bf6f4c5 commit debe220
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 8 additions & 4 deletions python/plugins/processing/core/ProcessingConfig.py
Expand Up @@ -171,15 +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))
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 @@ -266,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 @@ -275,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

0 comments on commit debe220

Please sign in to comment.