Skip to content
Permalink
Browse files

[FEATURE][processing] Allow drag and drop of model files onto QGIS wi…

…ndow

to execute them
  • Loading branch information
nyalldawson committed Sep 15, 2017
1 parent 0df4f4a commit 6300464275914ab8bfef6dd5eb2617bc9c9ff26e
Showing with 25 additions and 2 deletions.
  1. +25 −2 python/plugins/processing/ProcessingPlugin.py
@@ -32,13 +32,16 @@
import sys

from qgis.core import (QgsApplication,
QgsProcessingUtils)
from qgis.gui import QgsOptionsWidgetFactory
QgsProcessingUtils,
QgsProcessingModelAlgorithm)
from qgis.gui import (QgsOptionsWidgetFactory,
QgsCustomDropHandler)
from qgis.PyQt.QtCore import Qt, QCoreApplication, QDir
from qgis.PyQt.QtWidgets import QMenu, QAction
from qgis.PyQt.QtGui import QIcon

from processing.core.Processing import Processing
from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.ProcessingToolbox import ProcessingToolbox
from processing.gui.HistoryDialog import HistoryDialog
from processing.gui.ConfigDialog import ConfigOptionsPage
@@ -66,13 +69,32 @@ def createWidget(self, parent):
return ConfigOptionsPage(parent)


class ProcessingDropHandler(QgsCustomDropHandler):

def handleFileDrop(self, file):
if not file.lower().endswith('.model3'):
return False

alg = QgsProcessingModelAlgorithm()
if not alg.fromFile(file):
return False

alg.setProvider(QgsApplication.processingRegistry().providerById('model'))
dlg = AlgorithmDialog(alg)
dlg.setAttribute(Qt.WA_DeleteOnClose)
dlg.show()
return True


class ProcessingPlugin(object):

def __init__(self, iface):
self.iface = iface
self.options_factory = ProcessingOptionsFactory()
self.options_factory.setTitle(self.tr('Processing'))
iface.registerOptionsWidgetFactory(self.options_factory)
self.drop_handler = ProcessingDropHandler()
iface.registerCustomDropHandler(self.drop_handler)
self.locator_filter = AlgorithmLocatorFilter()
iface.registerLocatorFilter(self.locator_filter)
Processing.initialize()
@@ -159,6 +181,7 @@ def unload(self):

self.iface.unregisterOptionsWidgetFactory(self.options_factory)
self.iface.deregisterLocatorFilter(self.locator_filter)
self.iface.unregisterCustomDropHandler(self.drop_handler)

removeMenus()
Processing.deinitialize()

0 comments on commit 6300464

Please sign in to comment.
You can’t perform that action at this time.