Skip to content

Commit 3aff69c

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
1 parent 853d648 commit 3aff69c

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,
@@ -342,19 +343,26 @@ def _dragEnterEvent(event):
342343
event.ignore()
343344

344345
def _dropEvent(event):
345-
if event.mimeData().hasFormat('application/x-vnd.qgis.qgis.algorithmid'):
346-
data = event.mimeData().data('application/x-vnd.qgis.qgis.algorithmid')
347-
stream = QDataStream(data, QIODevice.ReadOnly)
348-
algorithm_id = stream.readQString()
346+
def alg_dropped(algorithm_id, pos):
349347
alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id)
350348
if alg is not None:
351-
self._addAlgorithm(alg, event.pos())
349+
self._addAlgorithm(alg, pos)
352350
else:
353351
assert False, algorithm_id
352+
353+
def input_dropped(id, pos):
354+
if id in [param.id() for param in QgsApplication.instance().processingRegistry().parameterTypes()]:
355+
self.addInputOfType(itemId, pos)
356+
357+
if event.mimeData().hasFormat('application/x-vnd.qgis.qgis.algorithmid'):
358+
data = event.mimeData().data('application/x-vnd.qgis.qgis.algorithmid')
359+
stream = QDataStream(data, QIODevice.ReadOnly)
360+
algorithm_id = stream.readQString()
361+
QTimer.singleShot(0, lambda id=algorithm_id, pos=event.pos(): alg_dropped(id, pos))
362+
event.accept()
354363
elif event.mimeData().hasText():
355364
itemId = event.mimeData().text()
356-
if itemId in [param.id() for param in QgsApplication.instance().processingRegistry().parameterTypes()]:
357-
self.addInputOfType(itemId, event.pos())
365+
QTimer.singleShot(0, lambda id=itemId, pos=event.pos(): input_dropped(id, pos))
358366
event.accept()
359367
else:
360368
event.ignore()

0 commit comments

Comments
 (0)