Skip to content

Commit

Permalink
[processing] Fix crashes and random behavior after dropping algorithms
Browse files Browse the repository at this point in the history
to model designer

Also fixes drag and drop within the algorithm parameter dialog and
the qt warnings thrown during these operations

(cherry picked from commit 30f786c)
  • Loading branch information
nyalldawson committed Mar 5, 2019
1 parent a697c99 commit ad3ba97
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions python/plugins/processing/modeler/ModelerDialog.py
Expand Up @@ -46,7 +46,8 @@
pyqtSignal, pyqtSignal,
QDataStream, QDataStream,
QIODevice, QIODevice,
QUrl) QUrl,
QTimer)
from qgis.PyQt.QtWidgets import (QGraphicsView, from qgis.PyQt.QtWidgets import (QGraphicsView,
QTreeWidget, QTreeWidget,
QMessageBox, QMessageBox,
Expand Down Expand Up @@ -321,19 +322,26 @@ def _dragEnterEvent(event):
event.ignore() event.ignore()


def _dropEvent(event): def _dropEvent(event):
if event.mimeData().hasFormat('application/x-vnd.qgis.qgis.algorithmid'): def alg_dropped(algorithm_id, pos):
data = event.mimeData().data('application/x-vnd.qgis.qgis.algorithmid')
stream = QDataStream(data, QIODevice.ReadOnly)
algorithm_id = stream.readQString()
alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id) alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id)
if alg is not None: if alg is not None:
self._addAlgorithm(alg, event.pos()) self._addAlgorithm(alg, pos)
else: else:
assert False, algorithm_id assert False, algorithm_id

def input_dropped(id, pos):
if id in [param.id() for param in QgsApplication.instance().processingRegistry().parameterTypes()]:
self.addInputOfType(itemId, pos)

if event.mimeData().hasFormat('application/x-vnd.qgis.qgis.algorithmid'):
data = event.mimeData().data('application/x-vnd.qgis.qgis.algorithmid')
stream = QDataStream(data, QIODevice.ReadOnly)
algorithm_id = stream.readQString()
QTimer.singleShot(0, lambda id=algorithm_id, pos=event.pos(): alg_dropped(id, pos))
event.accept()
elif event.mimeData().hasText(): elif event.mimeData().hasText():
itemId = event.mimeData().text() itemId = event.mimeData().text()
if itemId in [param.id() for param in QgsApplication.instance().processingRegistry().parameterTypes()]: QTimer.singleShot(0, lambda id=itemId, pos=event.pos(): input_dropped(id, pos))
self.addInputOfType(itemId, event.pos())
event.accept() event.accept()
else: else:
event.ignore() event.ignore()
Expand Down

0 comments on commit ad3ba97

Please sign in to comment.