|
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,
|
@@ -312,19 +313,26 @@ def _dragEnterEvent(event):
|
312 | 313 | event.ignore()
|
313 | 314 |
|
314 | 315 | 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): |
319 | 317 | alg = QgsApplication.processingRegistry().createAlgorithmById(algorithm_id)
|
320 | 318 | if alg is not None:
|
321 |
| - self._addAlgorithm(alg, event.pos()) |
| 319 | + self._addAlgorithm(alg, pos) |
322 | 320 | else:
|
323 | 321 | 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() |
324 | 333 | elif event.mimeData().hasText():
|
325 | 334 | 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)) |
328 | 336 | event.accept()
|
329 | 337 | else:
|
330 | 338 | event.ignore()
|
|
0 commit comments