49
49
from qgis .core import (Qgis ,
50
50
QgsApplication ,
51
51
QgsSettings ,
52
- QgsProperty ,
52
+ QgsProperty , # NOQA - must be here for saved file evaluation
53
53
QgsProject ,
54
- QgsProcessingFeatureSourceDefinition ,
55
- QgsCoordinateReferenceSystem ,
54
+ QgsProcessingFeatureSourceDefinition , # NOQA - must be here for saved file evaluation
55
+ QgsCoordinateReferenceSystem , # NOQA - must be here for saved file evaluation
56
56
QgsProcessingParameterDefinition ,
57
- QgsProcessingModelAlgorithm )
57
+ QgsProcessingModelAlgorithm ,
58
+ QgsProcessingParameterFile ,
59
+ QgsProcessingParameterMapLayer ,
60
+ QgsProcessingParameterRasterLayer ,
61
+ QgsProcessingParameterMeshLayer ,
62
+ QgsProcessingParameterVectorLayer ,
63
+ QgsProcessingParameterFeatureSource )
58
64
from qgis .gui import (QgsProcessingParameterWidgetContext ,
59
- QgsProcessingContextGenerator )
65
+ QgsProcessingContextGenerator ,
66
+ QgsFindFilesByPatternDialog )
60
67
from qgis .utils import iface
61
68
62
69
from processing .gui .wrappers import WidgetWrapperFactory , WidgetWrapper
@@ -103,9 +110,20 @@ def createMenu(self):
103
110
fill_down_action = QAction (self .tr ('Fill Down' ), self .menu )
104
111
fill_down_action .triggered .connect (self .fillDown )
105
112
fill_down_action .setToolTip (self .tr ('Copy the first value down to all other rows' ))
106
-
107
113
self .menu .addAction (fill_down_action )
108
114
115
+ if isinstance (self .parameterDefinition , (QgsProcessingParameterFile ,
116
+ QgsProcessingParameterMapLayer ,
117
+ QgsProcessingParameterRasterLayer ,
118
+ QgsProcessingParameterMeshLayer ,
119
+ QgsProcessingParameterVectorLayer ,
120
+ QgsProcessingParameterFeatureSource )):
121
+ find_by_pattern_action = QAction (QCoreApplication .translate ('BatchPanel' , 'Add Files by Pattern…' ),
122
+ self .menu )
123
+ find_by_pattern_action .triggered .connect (self .addFilesByPattern )
124
+ find_by_pattern_action .setToolTip (self .tr ('Adds files by a file pattern match' ))
125
+ self .menu .addAction (find_by_pattern_action )
126
+
109
127
def fillDown (self ):
110
128
"""
111
129
Copy the top value down
@@ -127,13 +145,30 @@ def setRowValue(self, row, value, context):
127
145
"""
128
146
Sets the value for a row, in the current column
129
147
"""
148
+ if self .panel .batchRowCount () <= row :
149
+ self .panel .addRow ()
150
+
130
151
wrapper = self .panel .wrappers [row ][self .column ]
131
152
if wrapper is None :
132
153
# e.g. destination header
133
154
self .panel .tblParameters .cellWidget (row + 1 , self .column ).setValue (str (value ))
134
155
else :
135
156
wrapper .setParameterValue (value , context )
136
157
158
+ def addFilesByPattern (self ):
159
+ """
160
+ Populates the dialog using a file pattern match
161
+ """
162
+ dlg = QgsFindFilesByPatternDialog ()
163
+ dlg .setWindowTitle (self .tr ("Add Files by Pattern" ))
164
+ if dlg .exec_ ():
165
+ files = dlg .files ()
166
+ context = dataobjects .createContext ()
167
+
168
+ first_row = self .panel .batchRowCount () if self .panel .batchRowCount () > 1 else 0
169
+ for row , file in enumerate (files ):
170
+ self .setRowValue (first_row + row , file , context )
171
+
137
172
138
173
class BatchPanel (BASE , WIDGET ):
139
174
0 commit comments