|
46 | 46 | pyqtSignal,
|
47 | 47 | QDataStream,
|
48 | 48 | QIODevice,
|
49 |
| - QUrl) |
| 49 | + QUrl, |
| 50 | + QTimer) |
50 | 51 | from qgis.PyQt.QtWidgets import (QGraphicsView,
|
51 | 52 | QTreeWidget,
|
52 | 53 | QMessageBox,
|
@@ -342,19 +343,26 @@ def _dragEnterEvent(event):
|
342 | 343 | event.ignore()
|
343 | 344 |
|
344 | 345 | 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): |
349 | 347 | alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id)
|
350 | 348 | if alg is not None:
|
351 |
| - self._addAlgorithm(alg, event.pos()) |
| 349 | + self._addAlgorithm(alg, pos) |
352 | 350 | else:
|
353 | 351 | 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() |
354 | 363 | elif event.mimeData().hasText():
|
355 | 364 | 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)) |
358 | 366 | event.accept()
|
359 | 367 | else:
|
360 | 368 | event.ignore()
|
|
0 commit comments