28
28
import re
29
29
import json
30
30
31
+ from qgis .utils import iface
31
32
from qgis .PyQt import uic
33
+ from qgis .PyQt .QtCore import Qt
32
34
from qgis .PyQt .QtGui import QTextCursor
33
35
from qgis .PyQt .QtWidgets import (QLineEdit , QPushButton , QLabel ,
34
- QComboBox , QSpacerItem , QSizePolicy )
36
+ QComboBox , QSpacerItem , QSizePolicy ,
37
+ QListWidgetItem )
35
38
36
39
from qgis .core import (QgsProcessingUtils ,
37
40
QgsProcessingParameterDefinition ,
@@ -187,8 +190,20 @@ def fillPredefined(self):
187
190
def setList (self , options ):
188
191
self .options = options
189
192
self .listWidget .clear ()
190
- for opt in options .keys ():
191
- self .listWidget .addItem (opt )
193
+ entries = QgsRasterCalculatorEntry .rasterEntries ()
194
+
195
+ def _find_source (name ):
196
+ for entry in entries :
197
+ if entry .ref == name :
198
+ return entry .raster .source ()
199
+ return ''
200
+
201
+ for name in options .keys ():
202
+ item = QListWidgetItem (name , self .listWidget )
203
+ tooltip = _find_source (name )
204
+ if tooltip :
205
+ item .setData (Qt .ToolTipRole , tooltip )
206
+ self .listWidget .addItem (item )
192
207
193
208
def setValue (self , value ):
194
209
self .text .setPlainText (value )
@@ -202,28 +217,28 @@ class ExpressionWidgetWrapper(WidgetWrapper):
202
217
def _panel (self , options ):
203
218
return ExpressionWidget (options )
204
219
220
+ def _get_options (self ):
221
+ entries = QgsRasterCalculatorEntry .rasterEntries ()
222
+ options = {}
223
+ for entry in entries :
224
+ options [entry .ref ] = entry .ref
225
+ return options
226
+
205
227
def createWidget (self ):
206
228
if self .dialogType == DIALOG_STANDARD :
207
- entries = QgsRasterCalculatorEntry .rasterEntries ()
208
- options = {}
209
- for entry in entries :
210
- options [entry .ref ] = entry .ref
211
- return self ._panel (options )
229
+ if iface is not None and iface .layerTreeView () is not None and iface .layerTreeView ().layerTreeModel () is not None :
230
+ iface .layerTreeView ().layerTreeModel ().dataChanged .connect (self .refresh )
231
+ return self ._panel (self ._get_options ())
212
232
elif self .dialogType == DIALOG_BATCH :
213
233
return QLineEdit ()
214
234
else :
215
235
layers = self .dialog .getAvailableValuesOfType ([QgsProcessingParameterRasterLayer ], [QgsProcessingOutputRasterLayer ])
216
236
options = {self .dialog .resolveValueDescription (lyr ): "{}@1" .format (self .dialog .resolveValueDescription (lyr )) for lyr in layers }
217
- return self ._panel (options )
237
+ self .widget = self ._panel (options )
238
+ return self .widget
218
239
219
- def refresh (self ):
220
- # TODO: check if avoid code duplication with self.createWidget
221
- layers = QgsProcessingUtils .compatibleRasterLayers (QgsProject .instance ())
222
- options = {}
223
- for lyr in layers :
224
- for n in range (lyr .bandCount ()):
225
- options [lyr .name ()] = '{:s}@{:d}' .format (lyr .name (), n + 1 )
226
- self .widget .setList (options )
240
+ def refresh (self , * args ):
241
+ self .widget .setList (self ._get_options ())
227
242
228
243
def setValue (self , value ):
229
244
if self .dialogType == DIALOG_STANDARD :
0 commit comments