|
32 | 32 | import os
|
33 | 33 | from functools import cmp_to_key
|
34 | 34 |
|
35 |
| -from qgis.core import QgsCoordinateReferenceSystem, QgsApplication, QgsWkbTypes, QgsMapLayerProxyModel |
36 |
| -from qgis.PyQt.QtWidgets import QCheckBox, QComboBox, QLineEdit, QPlainTextEdit, QWidget, QHBoxLayout, QToolButton, QFileDialog |
37 |
| -from qgis.gui import (QgsFieldExpressionWidget, |
38 |
| - QgsExpressionLineEdit, |
39 |
| - QgsProjectionSelectionWidget, |
40 |
| - QgsGenericProjectionSelector, |
41 |
| - QgsFieldComboBox, |
42 |
| - QgsFieldProxyModel, |
43 |
| - QgsMapLayerComboBox |
44 |
| - ) |
| 35 | +from qgis.core import ( |
| 36 | + QgsApplication, |
| 37 | + QgsCoordinateReferenceSystem, |
| 38 | + QgsExpression, |
| 39 | + QgsMapLayerProxyModel, |
| 40 | + QgsWkbTypes, |
| 41 | +) |
| 42 | +from qgis.PyQt.QtWidgets import ( |
| 43 | + QCheckBox, |
| 44 | + QComboBox, |
| 45 | + QDialog, |
| 46 | + QFileDialog, |
| 47 | + QHBoxLayout, |
| 48 | + QLineEdit, |
| 49 | + QPlainTextEdit, |
| 50 | + QToolButton, |
| 51 | + QWidget, |
| 52 | +) |
| 53 | +from qgis.gui import ( |
| 54 | + QgsExpressionLineEdit, |
| 55 | + QgsExpressionBuilderDialog, |
| 56 | + QgsFieldComboBox, |
| 57 | + QgsFieldExpressionWidget, |
| 58 | + QgsFieldProxyModel, |
| 59 | + QgsGenericProjectionSelector, |
| 60 | + QgsMapLayerComboBox, |
| 61 | + QgsProjectionSelectionWidget, |
| 62 | +) |
45 | 63 | from qgis.PyQt.QtCore import pyqtSignal, QObject, QVariant, QSettings
|
46 | 64 |
|
47 | 65 | from processing.gui.NumberInputPanel import NumberInputPanel, ModellerNumberInputPanel
|
@@ -175,6 +193,36 @@ def getFileName(self, initial_value=''):
|
175 | 193 | return filename, selected_filter
|
176 | 194 |
|
177 | 195 |
|
| 196 | +class ExpressionEnabledWidgetWrapper(WidgetWrapper): |
| 197 | + |
| 198 | + def createWidget(self, basewidget): |
| 199 | + expr_button = QToolButton() |
| 200 | + expr_button.clicked.connect(self.showExpressionsBuilder) |
| 201 | + expr_button.setText('...') |
| 202 | + |
| 203 | + layout = QHBoxLayout() |
| 204 | + layout.setContentsMargins(0, 0, 0, 0) |
| 205 | + layout.addWidget(basewidget) |
| 206 | + layout.addWidget(expr_button) |
| 207 | + |
| 208 | + widget = QWidget() |
| 209 | + widget.setLayout(layout) |
| 210 | + |
| 211 | + return widget |
| 212 | + |
| 213 | + def showExpressionsBuilder(self): |
| 214 | + context = self.param.expressionContext() |
| 215 | + value = self.value() |
| 216 | + if not isinstance(value, str): |
| 217 | + value = '' |
| 218 | + dlg = QgsExpressionBuilderDialog(None, value, self.widget, 'generic', context) |
| 219 | + dlg.setWindowTitle(self.tr('Expression based input')) |
| 220 | + if dlg.exec_() == QDialog.Accepted: |
| 221 | + exp = QgsExpression(dlg.expressionText()) |
| 222 | + if not exp.hasParserError(): |
| 223 | + self.setValue(dlg.expressionText()) |
| 224 | + |
| 225 | + |
178 | 226 | class BasicWidgetWrapper(WidgetWrapper):
|
179 | 227 |
|
180 | 228 | def createWidget(self):
|
|
0 commit comments