3030import warnings
3131
3232from qgis .PyQt import uic
33- from qgis .PyQt .QtCore import Qt , QCoreApplication , QModelIndex , QItemSelectionModel
34- from qgis .PyQt .QtWidgets import QToolButton , QMenu , QAction , QMessageBox
33+ from qgis .PyQt .QtCore import Qt , QCoreApplication
34+ from qgis .PyQt .QtWidgets import QToolButton , QMenu , QAction
3535from qgis .utils import iface
3636from qgis .core import (QgsApplication ,
3737 QgsProcessingAlgorithm )
4040 QgsProcessingToolboxProxyModel )
4141
4242from processing .gui .Postprocessing import handleAlgorithmResults
43- from processing .core .ProcessingLog import ProcessingLog
44- from processing .core .ProcessingConfig import ProcessingConfig , settingsWatcher
43+ from processing .core .ProcessingConfig import ProcessingConfig
4544from processing .gui .MessageDialog import MessageDialog
4645from processing .gui .AlgorithmDialog import AlgorithmDialog
4746from processing .gui .BatchAlgorithmDialog import BatchAlgorithmDialog
@@ -76,15 +75,13 @@ def __init__(self):
7675 self .setAllowedAreas (Qt .LeftDockWidgetArea | Qt .RightDockWidgetArea )
7776 self .processingToolbar .setIconSize (iface .iconSize (True ))
7877
79- self .model = QgsProcessingToolboxProxyModel (self ,
80- QgsApplication .processingRegistry (),
81- QgsGui .instance ().processingRecentAlgorithmLog ())
82- self .model .setFilters (QgsProcessingToolboxProxyModel .FilterToolbox )
83- self .algorithmTree .setModel (self .model )
78+ self .algorithmTree .setRegistry (QgsApplication .processingRegistry (),
79+ QgsGui .instance ().processingRecentAlgorithmLog ())
80+ self .algorithmTree .setFilters (QgsProcessingToolboxProxyModel .FilterToolbox )
8481
8582 self .searchBox .setShowSearchIcon (True )
8683
87- self .searchBox .textChanged .connect (self .textChanged )
84+ self .searchBox .textChanged .connect (self .algorithmTree . setFilterString )
8885 self .searchBox .returnPressed .connect (self .activateCurrent )
8986 self .algorithmTree .customContextMenuRequested .connect (
9087 self .showPopupMenu )
@@ -122,33 +119,6 @@ def disabledProviders(self):
122119
123120 return False
124121
125- def textChanged (self ):
126- text = self .searchBox .text ().strip (' ' ).lower ()
127- self .model .setFilterString (text )
128- if text :
129- self .algorithmTree .expandAll ()
130- if not self .algorithmTree .selectionModel ().hasSelection ():
131- # if previously selected item was hidden, auto select the first visible algorithm
132- first_visible_index = self ._findFirstVisibleAlgorithm (QModelIndex ())
133- if first_visible_index is not None :
134- self .algorithmTree .selectionModel ().setCurrentIndex (first_visible_index , QItemSelectionModel .ClearAndSelect )
135- else :
136- self .algorithmTree .collapseAll ()
137-
138- def _findFirstVisibleAlgorithm (self , parent_index ):
139- """
140- Returns the first visible algorithm in the tree widget
141- """
142- for r in range (self .model .rowCount (parent_index )):
143- proxy_index = self .model .index (r , 0 , parent_index )
144- source_index = self .model .mapToSource (proxy_index )
145- if self .model .toolboxModel ().isAlgorithm (source_index ):
146- return proxy_index
147- index = self ._findFirstVisibleAlgorithm (proxy_index )
148- if index is not None :
149- return index
150- return None
151-
152122 def addProviderActions (self , provider ):
153123 if provider .id () in ProviderActions .actions :
154124 toolbarButton = QToolButton ()
@@ -176,22 +146,10 @@ def removeProvider(self, provider_id):
176146 if button :
177147 self .processingToolbar .removeChild (button )
178148
179- def algorithm_for_index (self , index ):
180- source_index = self .model .mapToSource (index )
181- if self .model .toolboxModel ().isAlgorithm (source_index ):
182- return self .model .toolboxModel ().algorithmForIndex (source_index )
183- return None
184-
185- def selected_algorithm (self ):
186- if self .algorithmTree .selectionModel ().hasSelection ():
187- index = self .algorithmTree .selectionModel ().selectedIndexes ()[0 ]
188- return self .algorithm_for_index (index )
189- return None
190-
191149 def showPopupMenu (self , point ):
192150 index = self .algorithmTree .indexAt (point )
193151 popupmenu = QMenu ()
194- alg = self .algorithm_for_index (index )
152+ alg = self .algorithmTree . algorithmForIndex (index )
195153 if alg is not None :
196154 executeAction = QAction (QCoreApplication .translate ('ProcessingToolbox' , 'Execute…' ), popupmenu )
197155 executeAction .triggered .connect (self .executeAlgorithm )
@@ -224,7 +182,7 @@ def showPopupMenu(self, point):
224182 popupmenu .exec_ (self .algorithmTree .mapToGlobal (point ))
225183
226184 def editRenderingStyles (self ):
227- alg = self .selected_algorithm ()
185+ alg = self .algorithmTree . selectedAlgorithm ()
228186 if alg is not None :
229187 dlg = EditRenderingStylesDialog (alg )
230188 dlg .exec_ ()
@@ -233,14 +191,14 @@ def activateCurrent(self):
233191 self .executeAlgorithm ()
234192
235193 def executeAlgorithmAsBatchProcess (self ):
236- alg = self .selected_algorithm ()
194+ alg = self .algorithmTree . selectedAlgorithm ()
237195 if alg is not None :
238196 dlg = BatchAlgorithmDialog (alg )
239197 dlg .show ()
240198 dlg .exec_ ()
241199
242200 def executeAlgorithm (self ):
243- alg = self .selected_algorithm ()
201+ alg = self .algorithmTree . selectedAlgorithm ()
244202 if alg is not None :
245203 ok , message = alg .canExecute ()
246204 if not ok :
0 commit comments