|
46 | 46 | QFileInfo,
|
47 | 47 | QCoreApplication
|
48 | 48 | )
|
49 |
| -from qgis.core import (Qgis, |
50 |
| - QgsApplication, |
51 |
| - QgsSettings, |
52 |
| - QgsProperty, # NOQA - must be here for saved file evaluation |
53 |
| - QgsProject, |
54 |
| - QgsProcessingFeatureSourceDefinition, # NOQA - must be here for saved file evaluation |
55 |
| - QgsCoordinateReferenceSystem, # NOQA - must be here for saved file evaluation |
56 |
| - QgsProcessingParameterDefinition, |
57 |
| - QgsProcessingModelAlgorithm, |
58 |
| - QgsProcessingParameterFile, |
59 |
| - QgsProcessingParameterMapLayer, |
60 |
| - QgsProcessingParameterRasterLayer, |
61 |
| - QgsProcessingParameterMeshLayer, |
62 |
| - QgsProcessingParameterVectorLayer, |
63 |
| - QgsProcessingParameterFeatureSource) |
64 |
| -from qgis.gui import (QgsProcessingParameterWidgetContext, |
65 |
| - QgsProcessingContextGenerator, |
66 |
| - QgsFindFilesByPatternDialog) |
| 49 | +from qgis.core import ( |
| 50 | + Qgis, |
| 51 | + QgsApplication, |
| 52 | + QgsSettings, |
| 53 | + QgsProperty, # NOQA - must be here for saved file evaluation |
| 54 | + QgsProject, |
| 55 | + QgsProcessingFeatureSourceDefinition, # NOQA - must be here for saved file evaluation |
| 56 | + QgsCoordinateReferenceSystem, # NOQA - must be here for saved file evaluation |
| 57 | + QgsProcessingParameterDefinition, |
| 58 | + QgsProcessingModelAlgorithm, |
| 59 | + QgsProcessingParameterFile, |
| 60 | + QgsProcessingParameterMapLayer, |
| 61 | + QgsProcessingParameterRasterLayer, |
| 62 | + QgsProcessingParameterMeshLayer, |
| 63 | + QgsProcessingParameterVectorLayer, |
| 64 | + QgsProcessingParameterFeatureSource, |
| 65 | + QgsProcessingParameterRasterDestination, |
| 66 | + QgsProcessingParameterVectorDestination, |
| 67 | + QgsProcessingParameterFeatureSink, |
| 68 | + QgsProcessingOutputLayerDefinition |
| 69 | +) |
| 70 | +from qgis.gui import ( |
| 71 | + QgsProcessingParameterWidgetContext, |
| 72 | + QgsProcessingContextGenerator, |
| 73 | + QgsFindFilesByPatternDialog |
| 74 | +) |
67 | 75 | from qgis.utils import iface
|
68 | 76 |
|
69 | 77 | from processing.gui.wrappers import WidgetWrapperFactory, WidgetWrapper
|
@@ -171,7 +179,6 @@ def addFilesByPattern(self):
|
171 | 179 |
|
172 | 180 |
|
173 | 181 | class BatchPanel(BASE, WIDGET):
|
174 |
| - |
175 | 182 | PARAMETERS = "PARAMETERS"
|
176 | 183 | OUTPUTS = "OUTPUTS"
|
177 | 184 |
|
@@ -457,3 +464,45 @@ def toggleAdvancedMode(self, checked):
|
457 | 464 | for column, param in enumerate(self.alg.parameterDefinitions()):
|
458 | 465 | if param.flags() & QgsProcessingParameterDefinition.FlagAdvanced:
|
459 | 466 | self.tblParameters.setColumnHidden(column, not checked)
|
| 467 | + |
| 468 | + def parametersForRow(self, row, destinationProject=None, warnOnInvalid=True): |
| 469 | + """ |
| 470 | + Returns the parameters dictionary corresponding to a row in the batch table |
| 471 | + """ |
| 472 | + col = 0 |
| 473 | + parameters = {} |
| 474 | + for param in self.alg.parameterDefinitions(): |
| 475 | + if param.flags() & QgsProcessingParameterDefinition.FlagHidden or param.isDestination(): |
| 476 | + continue |
| 477 | + wrapper = self.wrappers[row][col] |
| 478 | + parameters[param.name()] = wrapper.parameterValue() |
| 479 | + if warnOnInvalid and not param.checkValueIsAcceptable(wrapper.parameterValue()): |
| 480 | + self.parent.messageBar().pushMessage("", |
| 481 | + self.tr('Wrong or missing parameter value: {0} (row {1})').format( |
| 482 | + param.description(), row + 1), |
| 483 | + level=Qgis.Warning, duration=5) |
| 484 | + return {} |
| 485 | + col += 1 |
| 486 | + count_visible_outputs = 0 |
| 487 | + for out in self.alg.destinationParameterDefinitions(): |
| 488 | + if out.flags() & QgsProcessingParameterDefinition.FlagHidden: |
| 489 | + continue |
| 490 | + |
| 491 | + count_visible_outputs += 1 |
| 492 | + widget = self.tblParameters.cellWidget(row + 1, col) |
| 493 | + text = widget.getValue() |
| 494 | + if not warnOnInvalid or out.checkValueIsAcceptable(text): |
| 495 | + if isinstance(out, (QgsProcessingParameterRasterDestination, |
| 496 | + QgsProcessingParameterVectorDestination, |
| 497 | + QgsProcessingParameterFeatureSink)): |
| 498 | + # load rasters and sinks on completion |
| 499 | + parameters[out.name()] = QgsProcessingOutputLayerDefinition(text, destinationProject) |
| 500 | + else: |
| 501 | + parameters[out.name()] = text |
| 502 | + col += 1 |
| 503 | + else: |
| 504 | + self.parent.messageBar().pushMessage("", self.tr('Wrong or missing output value: {0} (row {1})').format( |
| 505 | + out.description(), row + 1), |
| 506 | + level=Qgis.Warning, duration=5) |
| 507 | + return {} |
| 508 | + return parameters |
0 commit comments