RasterOptionsWidget.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """
  2. ***************************************************************************
  3. RasterOptionsWidget.py
  4. ---------------------
  5. Date : December 2016
  6. Copyright : (C) 2016 by Alexander Bruy
  7. Email : alexander dot bruy at gmail dot com
  8. ***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************
  16. """
  17. __author__ = 'Alexander Bruy'
  18. __date__ = 'December 2016'
  19. __copyright__ = '(C) 2016, Alexander Bruy'
  20. from qgis.PyQt.QtWidgets import QLineEdit, QComboBox
  21. from qgis.gui import QgsRasterFormatSaveOptionsWidget
  22. from qgis.core import (QgsProcessingParameterString,
  23. QgsProcessingOutputString)
  24. from processing.gui.wrappers import WidgetWrapper, DIALOG_MODELER, DIALOG_BATCH
  25. class RasterOptionsWidgetWrapper(WidgetWrapper):
  26. def createWidget(self):
  27. if self.dialogType == DIALOG_MODELER:
  28. widget = QComboBox()
  29. widget.setEditable(True)
  30. strings = self.dialog.getAvailableValuesOfType(QgsProcessingParameterString, QgsProcessingOutputString)
  31. options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
  32. for desc, val in options:
  33. widget.addItem(desc, val)
  34. widget.setEditText(self.parameterDefinition().defaultValue() or '')
  35. return widget
  36. elif self.dialogType == DIALOG_BATCH:
  37. widget = QLineEdit()
  38. if self.parameterDefinition().defaultValue():
  39. widget.setText(self.parameterDefinition().defaultValue())
  40. return widget
  41. else:
  42. return QgsRasterFormatSaveOptionsWidget()
  43. def setValue(self, value):
  44. if value is None:
  45. value = ''
  46. if self.dialogType == DIALOG_MODELER:
  47. self.setComboValue(value)
  48. elif self.dialogType == DIALOG_BATCH:
  49. self.widget.setText(value)
  50. else:
  51. # The QgsRasterFormatSaveOptionsWidget requires space delimited options, but this wrapper uses | delimiter
  52. self.widget.setOptions(value.replace('|', ' '))
  53. def value(self):
  54. if self.dialogType == DIALOG_MODELER:
  55. return self.comboValue()
  56. elif self.dialogType == DIALOG_BATCH:
  57. return self.widget.text()
  58. else:
  59. return '|'.join(self.widget.options())