EditRenderingStylesDialog.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. """
  2. ***************************************************************************
  3. EditRenderingStylesDialog.py
  4. ---------------------
  5. Date : August 2012
  6. Copyright : (C) 2012 by Victor Olaya
  7. Email : volayaf 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__ = 'Victor Olaya'
  18. __date__ = 'August 2012'
  19. __copyright__ = '(C) 2012, Victor Olaya'
  20. import os
  21. import warnings
  22. from qgis.PyQt import uic
  23. from qgis.PyQt.QtCore import Qt
  24. from qgis.PyQt.QtWidgets import QDialog, QHeaderView, QTableWidgetItem
  25. from qgis.core import (QgsProcessingOutputRasterLayer,
  26. QgsProcessingOutputVectorLayer)
  27. from processing.gui.RenderingStyles import RenderingStyles
  28. from processing.gui.RenderingStyleFilePanel import RenderingStyleFilePanel
  29. pluginPath = os.path.split(os.path.dirname(__file__))[0]
  30. with warnings.catch_warnings():
  31. warnings.filterwarnings("ignore", category=DeprecationWarning)
  32. WIDGET, BASE = uic.loadUiType(
  33. os.path.join(pluginPath, 'ui', 'DlgRenderingStyles.ui'))
  34. class EditRenderingStylesDialog(BASE, WIDGET):
  35. def __init__(self, alg):
  36. super().__init__(None)
  37. self.setupUi(self)
  38. self.alg = alg
  39. self.tblStyles.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  40. self.setWindowTitle(self.alg.displayName())
  41. self.valueItems = {}
  42. self.dependentItems = {}
  43. self.setTableContent()
  44. def setTableContent(self):
  45. numOutputs = 0
  46. for output in self.alg.outputDefinitions():
  47. if isinstance(output, (QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer)):
  48. numOutputs += 1
  49. self.tblStyles.setRowCount(numOutputs)
  50. i = 0
  51. for output in self.alg.outputDefinitions():
  52. if isinstance(output, (QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer)):
  53. item = QTableWidgetItem(output.description() + '<' +
  54. output.__class__.__name__ + '>')
  55. item.setFlags(Qt.ItemIsEnabled)
  56. self.tblStyles.setItem(i, 0, item)
  57. item = RenderingStyleFilePanel()
  58. style = \
  59. RenderingStyles.getStyle(self.alg.id(),
  60. output.name())
  61. if style:
  62. item.setText(str(style))
  63. self.valueItems[output.name()] = item
  64. self.tblStyles.setCellWidget(i, 1, item)
  65. self.tblStyles.setRowHeight(i, 22)
  66. i += 1
  67. def accept(self):
  68. styles = {}
  69. for key in list(self.valueItems.keys()):
  70. styles[key] = str(self.valueItems[key].getValue())
  71. RenderingStyles.addAlgStylesAndSave(self.alg.id(), styles)
  72. QDialog.accept(self)
  73. def reject(self):
  74. QDialog.reject(self)