QGIS/python/plugins/processing/gui/EditRenderingStylesDialog.py

97 lines
3.5 KiB
Python
Raw Normal View History

2012-10-05 23:28:47 +02:00
# -*- coding: utf-8 -*-
"""
***************************************************************************
EditRenderingStylesDialog.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
2016-09-21 18:24:26 +02:00
from builtins import str
2012-10-05 23:28:47 +02:00
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
2012-10-05 23:28:47 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2012-10-05 23:28:47 +02:00
__revision__ = '$Format:%H$'
2015-05-18 21:04:20 +03:00
import os
2016-04-29 11:39:26 +02:00
from qgis.PyQt import uic
2016-04-22 10:38:48 +02:00
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QDialog, QHeaderView, QTableWidgetItem
2013-08-12 20:44:27 +02:00
from processing.gui.RenderingStyles import RenderingStyles
from processing.gui.RenderingStyleFilePanel import RenderingStyleFilePanel
from processing.core.outputs import OutputRaster
from processing.core.outputs import OutputVector
2015-05-18 21:04:20 +03:00
pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
os.path.join(pluginPath, 'ui', 'DlgRenderingStyles.ui'))
2012-09-15 18:25:25 +03:00
2015-05-18 21:04:20 +03:00
class EditRenderingStylesDialog(BASE, WIDGET):
2012-09-15 18:25:25 +03:00
def __init__(self, alg):
2015-05-18 21:04:20 +03:00
super(EditRenderingStylesDialog, self).__init__(None)
self.setupUi(self)
self.alg = alg.getCopy()
2012-09-15 18:25:25 +03:00
self.tblStyles.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.setWindowTitle(self.alg.name)
2012-09-15 18:25:25 +03:00
self.valueItems = {}
self.dependentItems = {}
self.setTableContent()
def setTableContent(self):
numOutputs = 0
for output in self.alg.outputs:
if isinstance(output, (OutputVector, OutputRaster)):
if not output.hidden:
numOutputs += 1
self.tblStyles.setRowCount(numOutputs)
2012-09-15 18:25:25 +03:00
i = 0
for output in self.alg.outputs:
if isinstance(output, (OutputVector, OutputRaster)):
if not output.hidden:
item = QTableWidgetItem(output.description + '<'
+ output.__class__.__name__ + '>')
item.setFlags(Qt.ItemIsEnabled)
self.tblStyles.setItem(i, 0, item)
2012-09-15 18:25:25 +03:00
item = RenderingStyleFilePanel()
style = \
RenderingStyles.getStyle(self.alg.commandLineName(),
output.name)
2012-09-15 18:25:25 +03:00
if style:
2016-09-21 18:24:26 +02:00
item.setText(str(style))
2012-09-15 18:25:25 +03:00
self.valueItems[output.name] = item
self.tblStyles.setCellWidget(i, 1, item)
self.tblStyles.setRowHeight(i, 22)
2012-09-15 18:25:25 +03:00
i += 1
def accept(self):
2012-09-15 18:25:25 +03:00
styles = {}
2016-09-21 18:24:26 +02:00
for key in list(self.valueItems.keys()):
styles[key] = str(self.valueItems[key].getValue())
2012-09-15 18:25:25 +03:00
RenderingStyles.addAlgStylesAndSave(self.alg.commandLineName(), styles)
QDialog.accept(self)
def reject(self):
QDialog.reject(self)