mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] added predefined expressions to raster calculator
This commit is contained in:
parent
8a3c1efefe
commit
bb7b6d41bc
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>644</width>
|
||||
<height>296</height>
|
||||
<height>493</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -343,9 +343,6 @@
|
||||
<string>Expression</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="text">
|
||||
<property name="sizePolicy">
|
||||
@ -362,6 +359,34 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Predefined expressions</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboPredefined"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonAddPredefined">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>buttonAddPredefined</zorder>
|
||||
<zorder>buttonAddPredefined</zorder>
|
||||
<zorder>comboPredefined</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -2,21 +2,62 @@ from processing.gui.wrappers import WidgetWrapper, DIALOG_STANDARD, DIALOG_BATCH
|
||||
from processing.tools import dataobjects
|
||||
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
|
||||
from qgis.PyQt.QtWidgets import QListWidget, QLineEdit, QPushButton
|
||||
from qgis.PyQt.QtGui import QTextCursor
|
||||
from qgis.PyQt.QtGui import QTextCursor, QLabel, QComboBox, QSizePolicy, QSpacerItem
|
||||
from processing.core.outputs import OutputRaster
|
||||
from processing.core.parameters import ParameterRaster
|
||||
from processing.gui.wrappers import InvalidParameterValue
|
||||
import os
|
||||
from qgis.PyQt import uic
|
||||
from functools import partial
|
||||
import re
|
||||
|
||||
pluginPath = os.path.dirname(__file__)
|
||||
WIDGET_DLG, BASE_DLG = uic.loadUiType(
|
||||
os.path.join(pluginPath, 'PredefinedExpressionDialog.ui'))
|
||||
|
||||
class PredefinedExpressionDialog(BASE_DLG, WIDGET_DLG):
|
||||
|
||||
def __init__(self, expression, options):
|
||||
super(PredefinedExpressionDialog, self).__init__()
|
||||
self.setupUi(self)
|
||||
|
||||
self.filledExpression = None
|
||||
self.options = options
|
||||
self.expression = expression
|
||||
self.variables = set(re.findall('\[.*?\]', expression))
|
||||
self.comboBoxes = {}
|
||||
for variable in self.variables:
|
||||
label = QLabel(variable[1:-1])
|
||||
combo = QComboBox()
|
||||
for opt in self.options.keys():
|
||||
combo.addItem(opt)
|
||||
self.comboBoxes[variable] = combo
|
||||
self.groupBox.layout().addWidget(label)
|
||||
self.groupBox.layout().addWidget(combo)
|
||||
|
||||
verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
|
||||
self.groupBox.layout().addItem(verticalSpacer)
|
||||
|
||||
self.buttonBox.rejected.connect(self.cancelPressed)
|
||||
self.buttonBox.accepted.connect(self.okPressed)
|
||||
|
||||
def cancelPressed(self):
|
||||
self.close()
|
||||
|
||||
def okPressed(self):
|
||||
self.filledExpression = self.expression
|
||||
for name, combo in self.comboBoxes.items():
|
||||
self.filledExpression = self.filledExpression.replace(name,
|
||||
self.options[combo.currentText()])
|
||||
self.close()
|
||||
|
||||
WIDGET, BASE = uic.loadUiType(
|
||||
os.path.join(pluginPath, 'ExpressionWidget.ui'))
|
||||
|
||||
|
||||
class ExpressionWidget(BASE, WIDGET):
|
||||
|
||||
expressions = {"NDVI": "([NIR] - [Red]) % ([NIR] + [Red])"}
|
||||
|
||||
def __init__(self, options):
|
||||
super(ExpressionWidget, self).__init__(None)
|
||||
self.setupUi(self)
|
||||
@ -36,6 +77,20 @@ class ExpressionWidget(BASE, WIDGET):
|
||||
for button in buttons:
|
||||
button.clicked.connect(partial(addButtonText, button.text()))
|
||||
self.listWidget.itemDoubleClicked.connect(doubleClicked)
|
||||
|
||||
self.fillPredefined()
|
||||
self.buttonAddPredefined.clicked.connect(self.addPredefined)
|
||||
|
||||
def addPredefined(self):
|
||||
expression = self.expressions[self.comboPredefined.currentText()]
|
||||
dlg = PredefinedExpressionDialog(expression, self.options)
|
||||
dlg.exec_()
|
||||
if dlg.filledExpression:
|
||||
self.text.setPlainText(dlg.filledExpression)
|
||||
|
||||
def fillPredefined(self):
|
||||
for expression in self.expressions:
|
||||
self.comboPredefined.addItem(expression)
|
||||
|
||||
def setList(self, options):
|
||||
self.options = options
|
||||
|
Loading…
x
Reference in New Issue
Block a user