mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-08 00:05:09 -04:00
add Select By Location to the Selection toolbar (fix #20350)
This commit is contained in:
parent
d3d91b1ac7
commit
1a76a0963e
@ -51,7 +51,7 @@ from processing.gui.AlgorithmLocatorFilter import (AlgorithmLocatorFilter,
|
|||||||
InPlaceAlgorithmLocatorFilter)
|
InPlaceAlgorithmLocatorFilter)
|
||||||
from processing.modeler.ModelerDialog import ModelerDialog
|
from processing.modeler.ModelerDialog import ModelerDialog
|
||||||
from processing.tools.system import tempHelpFolder
|
from processing.tools.system import tempHelpFolder
|
||||||
from processing.gui.menus import removeMenus, initializeMenus, createMenus
|
from processing.gui.menus import removeMenus, initializeMenus, createMenus, createButtons, removeButtons
|
||||||
from processing.core.ProcessingResults import resultsList
|
from processing.core.ProcessingResults import resultsList
|
||||||
|
|
||||||
pluginPath = os.path.dirname(__file__)
|
pluginPath = os.path.dirname(__file__)
|
||||||
@ -271,6 +271,7 @@ class ProcessingPlugin:
|
|||||||
|
|
||||||
initializeMenus()
|
initializeMenus()
|
||||||
createMenus()
|
createMenus()
|
||||||
|
createButtons()
|
||||||
|
|
||||||
# In-place editing button state sync
|
# In-place editing button state sync
|
||||||
self.iface.currentLayerChanged.connect(self.sync_in_place_button_state)
|
self.iface.currentLayerChanged.connect(self.sync_in_place_button_state)
|
||||||
@ -322,6 +323,7 @@ class ProcessingPlugin:
|
|||||||
self.iface.unregisterCustomDropHandler(self.drop_handler)
|
self.iface.unregisterCustomDropHandler(self.drop_handler)
|
||||||
QgsApplication.dataItemProviderRegistry().removeProvider(self.item_provider)
|
QgsApplication.dataItemProviderRegistry().removeProvider(self.item_provider)
|
||||||
|
|
||||||
|
removeButtons()
|
||||||
removeMenus()
|
removeMenus()
|
||||||
Processing.deinitialize()
|
Processing.deinitialize()
|
||||||
|
|
||||||
|
@ -131,6 +131,8 @@ defaultMenuEntries.update({'gdal:buildvirtualraster': miscMenu,
|
|||||||
'gdal:overviews': miscMenu,
|
'gdal:overviews': miscMenu,
|
||||||
'gdal:tileindex': miscMenu})
|
'gdal:tileindex': miscMenu})
|
||||||
|
|
||||||
|
toolBarButtons = {'native:selectbylocation': iface.selectionToolBar()}
|
||||||
|
|
||||||
|
|
||||||
def initializeMenus():
|
def initializeMenus():
|
||||||
for m in defaultMenuEntries.keys():
|
for m in defaultMenuEntries.keys():
|
||||||
@ -281,6 +283,47 @@ def getMenu(name, parent):
|
|||||||
|
|
||||||
def findAction(actions, alg):
|
def findAction(actions, alg):
|
||||||
for action in actions:
|
for action in actions:
|
||||||
if action.data() == alg.id():
|
if (isinstance(alg, str) and action.data() == alg) or (isinstance(alg, QgsProcessingAlgorithm) and action.data() == alg.id()):
|
||||||
return action
|
return action
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def addToolBarButton(algId, toolbar, icon=None, tooltip=None):
|
||||||
|
alg = QgsApplication.processingRegistry().algorithmById(algId)
|
||||||
|
if alg is None or alg.id() != algId:
|
||||||
|
QgsMessageLog.logMessage(Processing.tr('Invalid algorithm ID for button: {}').format(algId), Processing.tr('Processing'))
|
||||||
|
return
|
||||||
|
|
||||||
|
if tooltip is None:
|
||||||
|
if (QgsGui.higFlags() & QgsGui.HigMenuTextIsTitleCase) and not (alg.flags() & QgsProcessingAlgorithm.FlagDisplayNameIsLiteral):
|
||||||
|
tooltip = QgsStringUtils.capitalize(alg.displayName(), QgsStringUtils.TitleCase)
|
||||||
|
else:
|
||||||
|
tooltip = alg.displayName()
|
||||||
|
|
||||||
|
action = QAction(icon or alg.icon(), tooltip, iface.mainWindow())
|
||||||
|
algId = alg.id()
|
||||||
|
action.setData(algId)
|
||||||
|
action.triggered.connect(lambda: _executeAlgorithm(algId))
|
||||||
|
action.setObjectName("mProcessingAlg_%s" % algId)
|
||||||
|
|
||||||
|
if toolbar:
|
||||||
|
toolbar.addAction(action)
|
||||||
|
else:
|
||||||
|
QgsMessageLog.logMessage(Processing.tr('Toolbar "{}" not found').format(toolbar.windowTitle), Processing.tr('Processing'))
|
||||||
|
|
||||||
|
|
||||||
|
def removeToolBarButton(algId, toolbar):
|
||||||
|
if toolbar:
|
||||||
|
action = findAction(toolbar.actions(), algId)
|
||||||
|
if action is not None:
|
||||||
|
toolbar.removeAction(action)
|
||||||
|
|
||||||
|
|
||||||
|
def createButtons():
|
||||||
|
for algId, toolbar in toolBarButtons.items():
|
||||||
|
addToolBarButton(algId, toolbar)
|
||||||
|
|
||||||
|
|
||||||
|
def removeButtons():
|
||||||
|
for algId, toolbar in toolBarButtons.items():
|
||||||
|
removeToolBarButton(algId, toolbar)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user