mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] Use ExpressionWidgetWrapperMixin in StringWidgetWrapper
This commit is contained in:
parent
7bffef7044
commit
337d1889b8
@ -1,74 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""
|
|
||||||
***************************************************************************
|
|
||||||
NumberInputPanel.py
|
|
||||||
---------------------
|
|
||||||
Date : August 2016
|
|
||||||
Copyright : (C) 2016 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. *
|
|
||||||
* *
|
|
||||||
***************************************************************************
|
|
||||||
"""
|
|
||||||
from builtins import str
|
|
||||||
|
|
||||||
__author__ = 'Victor Olaya'
|
|
||||||
__date__ = 'August 2016'
|
|
||||||
__copyright__ = '(C) 2016, Victor Olaya'
|
|
||||||
|
|
||||||
# This will get replaced with a git SHA1 when you do a git archive
|
|
||||||
|
|
||||||
__revision__ = '$Format:%H$'
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from qgis.PyQt import uic
|
|
||||||
from qgis.PyQt.QtCore import pyqtSignal
|
|
||||||
from qgis.PyQt.QtWidgets import QDialog
|
|
||||||
|
|
||||||
from qgis.core import (QgsDataSourceUri,
|
|
||||||
QgsCredentials,
|
|
||||||
QgsExpression,
|
|
||||||
QgsRasterLayer)
|
|
||||||
from qgis.gui import QgsEncodingFileDialog, QgsExpressionBuilderDialog
|
|
||||||
from qgis.utils import iface
|
|
||||||
|
|
||||||
pluginPath = os.path.split(os.path.dirname(__file__))[0]
|
|
||||||
WIDGET, BASE = uic.loadUiType(
|
|
||||||
os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui'))
|
|
||||||
|
|
||||||
|
|
||||||
class StringInputPanel(BASE, WIDGET):
|
|
||||||
|
|
||||||
hasChanged = pyqtSignal()
|
|
||||||
|
|
||||||
def __init__(self, param):
|
|
||||||
super(StringInputPanel, self).__init__(None)
|
|
||||||
self.setupUi(self)
|
|
||||||
|
|
||||||
self.param = param
|
|
||||||
self.text = param.default
|
|
||||||
|
|
||||||
self.btnSelect.clicked.connect(self.showExpressionsBuilder)
|
|
||||||
self.leText.textChanged.connect(lambda: self.hasChanged.emit())
|
|
||||||
|
|
||||||
def showExpressionsBuilder(self):
|
|
||||||
context = self.param.expressionContext()
|
|
||||||
dlg = QgsExpressionBuilderDialog(None, self.leText.text(), self, 'generic', context)
|
|
||||||
dlg.setWindowTitle(self.tr('Expression based input'))
|
|
||||||
if dlg.exec_() == QDialog.Accepted:
|
|
||||||
exp = QgsExpression(dlg.expressionText())
|
|
||||||
if not exp.hasParserError():
|
|
||||||
self.setValue(dlg.expressionText())
|
|
||||||
|
|
||||||
def getValue(self):
|
|
||||||
return self.leText.text()
|
|
||||||
|
|
||||||
def setValue(self, value):
|
|
||||||
self.leText.setText(str(value))
|
|
@ -88,7 +88,6 @@ from processing.gui.MultipleInputPanel import MultipleInputPanel
|
|||||||
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
|
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
|
||||||
from processing.gui.FixedTablePanel import FixedTablePanel
|
from processing.gui.FixedTablePanel import FixedTablePanel
|
||||||
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
|
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel
|
||||||
from processing.gui.StringInputPanel import StringInputPanel
|
|
||||||
|
|
||||||
|
|
||||||
DIALOG_STANDARD = 'standard'
|
DIALOG_STANDARD = 'standard'
|
||||||
@ -837,22 +836,19 @@ class VectorWidgetWrapper(WidgetWrapper):
|
|||||||
return self.comboValue(validator, combobox=self.combo)
|
return self.comboValue(validator, combobox=self.combo)
|
||||||
|
|
||||||
|
|
||||||
class StringWidgetWrapper(WidgetWrapper):
|
class StringWidgetWrapper(WidgetWrapper, ExpressionWidgetWrapperMixin):
|
||||||
|
|
||||||
def createWidget(self):
|
def createWidget(self):
|
||||||
if self.dialogType == DIALOG_STANDARD:
|
if self.dialogType == DIALOG_STANDARD:
|
||||||
if self.param.multiline:
|
if self.param.multiline:
|
||||||
widget = QPlainTextEdit()
|
widget = QPlainTextEdit()
|
||||||
if self.param.default:
|
|
||||||
widget.setPlainText(self.param.default)
|
|
||||||
else:
|
else:
|
||||||
widget = StringInputPanel(self.param)
|
self._lineedit = QLineEdit()
|
||||||
if self.param.default:
|
return self.wrapWithExpressionButton(self._lineedit)
|
||||||
widget.setValue(self.param.default)
|
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
widget = QLineEdit()
|
widget = QLineEdit()
|
||||||
if self.param.default:
|
|
||||||
widget.setText(self.param.default)
|
|
||||||
else:
|
else:
|
||||||
# strings, numbers, files and table fields are all allowed input types
|
# strings, numbers, files and table fields are all allowed input types
|
||||||
strings = self.dialog.getAvailableValuesOfType([ParameterString, ParameterNumber, ParameterFile,
|
strings = self.dialog.getAvailableValuesOfType([ParameterString, ParameterNumber, ParameterFile,
|
||||||
@ -860,20 +856,23 @@ class StringWidgetWrapper(WidgetWrapper):
|
|||||||
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
|
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
|
||||||
if self.param.multiline:
|
if self.param.multiline:
|
||||||
widget = MultilineTextPanel(options)
|
widget = MultilineTextPanel(options)
|
||||||
widget.setText(self.param.default or "")
|
|
||||||
else:
|
else:
|
||||||
widget = QComboBox()
|
widget = QComboBox()
|
||||||
widget.setEditable(True)
|
widget.setEditable(True)
|
||||||
for desc, val in options:
|
for desc, val in options:
|
||||||
widget.addItem(desc, val)
|
widget.addItem(desc, val)
|
||||||
widget.setEditText(self.param.default or "")
|
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
def setValue(self, value):
|
def setValue(self, value):
|
||||||
if self.dialogType == DIALOG_STANDARD:
|
if self.dialogType == DIALOG_STANDARD:
|
||||||
pass # TODO
|
if self.param.multiline:
|
||||||
|
self.widget.setPlainText(value)
|
||||||
|
else:
|
||||||
|
self._lineedit.setText(value)
|
||||||
|
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
self.widget.setText(value)
|
self.widget.setText(value)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if self.param.multiline:
|
if self.param.multiline:
|
||||||
self.widget.setValue(value)
|
self.widget.setValue(value)
|
||||||
@ -885,10 +884,12 @@ class StringWidgetWrapper(WidgetWrapper):
|
|||||||
if self.param.multiline:
|
if self.param.multiline:
|
||||||
text = self.widget.toPlainText()
|
text = self.widget.toPlainText()
|
||||||
else:
|
else:
|
||||||
text = self.widget.getValue()
|
text = self._lineedit.text()
|
||||||
return text
|
return text
|
||||||
|
|
||||||
elif self.dialogType == DIALOG_BATCH:
|
elif self.dialogType == DIALOG_BATCH:
|
||||||
return self.widget.text()
|
return self.widget.text()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if self.param.multiline:
|
if self.param.multiline:
|
||||||
value = self.widget.getValue()
|
value = self.widget.getValue()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user