Skip to content

Commit e6b9a89

Browse files
committed
[processing] Fix crashes and random behavior after dropping algorithms
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)
1 parent 3121761 commit e6b9a89

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

python/plugins/processing/modeler/ModelerDialog.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
pyqtSignal,
4747
QDataStream,
4848
QIODevice,
49-
QUrl)
49+
QUrl,
50+
QTimer)
5051
from qgis.PyQt.QtWidgets import (QGraphicsView,
5152
QTreeWidget,
5253
QMessageBox,
@@ -312,19 +313,26 @@ def _dragEnterEvent(event):
312313
event.ignore()
313314

314315
def _dropEvent(event):
315-
if event.mimeData().hasFormat('application/x-vnd.qgis.qgis.algorithmid'):
316-
data = event.mimeData().data('application/x-vnd.qgis.qgis.algorithmid')
317-
stream = QDataStream(data, QIODevice.ReadOnly)
318-
algorithm_id = stream.readQString()
316+
def alg_dropped(algorithm_id, pos):
319317
alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id)
320318
if alg is not None:
321-
self._addAlgorithm(alg, event.pos())
319+
self._addAlgorithm(alg, pos)
322320
else:
323321
assert False, algorithm_id
322+
323+
def input_dropped(id, pos):
324+
if id in [param.id() for param in QgsApplication.instance().processingRegistry().parameterTypes()]:
325+
self.addInputOfType(itemId, pos)
326+
327+
if event.mimeData().hasFormat('application/x-vnd.qgis.qgis.algorithmid'):
328+
data = event.mimeData().data('application/x-vnd.qgis.qgis.algorithmid')
329+
stream = QDataStream(data, QIODevice.ReadOnly)
330+
algorithm_id = stream.readQString()
331+
QTimer.singleShot(0, lambda id=algorithm_id, pos=event.pos(): alg_dropped(id, pos))
332+
event.accept()
324333
elif event.mimeData().hasText():
325334
itemId = event.mimeData().text()
326-
if itemId in [param.id() for param in QgsApplication.instance().processingRegistry().parameterTypes()]:
327-
self.addInputOfType(itemId, event.pos())
335+
QTimer.singleShot(0, lambda id=itemId, pos=event.pos(): input_dropped(id, pos))
328336
event.accept()
329337
else:
330338
event.ignore()

0 commit comments

Comments
 (0)