Skip to content
Permalink
Browse files

[processing] added drag&drop support in modeler

  • Loading branch information
volaya committed Mar 26, 2014
1 parent 36bd2d0 commit 92ee039f1061a27d51b92a2aa1ab286220ab137f
Showing with 65 additions and 2 deletions.
  1. +65 −2 python/plugins/processing/modeler/ModelerDialog.py
@@ -65,7 +65,62 @@ def __init__(self, alg=None):
self.scene = ModelerScene(self)
self.scene.setSceneRect(QRectF(0, 0, 4000, 4000))
self.view.setScene(self.scene)
self.view.setAcceptDrops(True)
self.view.ensureVisible(0, 0, 10, 10)

def _dragEnterEvent(event):
if event.mimeData().hasText():
event.acceptProposedAction()
else:
event.ignore()

def _dropEvent(event):
if event.mimeData().hasText():
text = event.mimeData().text()
print text
if text in ModelerParameterDefinitionDialog.paramTypes:
self.addInputOfType(text)
else:
alg = ModelerUtils.getAlgorithm(text);
if alg is not None:
self._addAlgorithm(alg)
event.accept()
else:
event.ignore()

def _dragMoveEvent(event):
if event.mimeData().hasText():
event.accept()
else:
event.ignore()

self.view.dragEnterEvent = _dragEnterEvent
self.view.dropEvent = _dropEvent
self.view.dragMoveEvent = _dragMoveEvent


def _mimeDataInput(items):
mimeData = QMimeData()
text = items[0].text(0)
mimeData.setText(text)
return mimeData

self.inputsTree.mimeData = _mimeDataInput

self.inputsTree.setDragDropMode(QTreeWidget.DragOnly)
self.inputsTree.setDropIndicatorShown(True)

def _mimeDataAlgorithm(items):
item = items[0]
if isinstance(item, TreeAlgorithmItem):
mimeData = QMimeData()
mimeData.setText(item.alg.commandLineName())
return mimeData

self.algorithmTree.mimeData = _mimeDataAlgorithm

self.algorithmTree.setDragDropMode(QTreeWidget.DragOnly)
self.algorithmTree.setDropIndicatorShown(True)

# Set icons
self.btnOpen.setIcon(
@@ -285,9 +340,13 @@ def repaintModel(self):
self.scene.paintModel(self.alg)
self.view.setScene(self.scene)


def addInput(self):
item = self.inputsTree.currentItem()
paramType = str(item.text(0))
self.addInputOfType(paramType)

def addInputOfType(self, paramType):
if paramType in ModelerParameterDefinitionDialog.paramTypes:
dlg = ModelerParameterDefinitionDialog(self.alg, paramType)
dlg.exec_()
@@ -301,11 +360,12 @@ def addInput(self):
self.hasChanged = True

def fillInputsTree(self):
parametersItem = QTreeWidgetItem()
parametersItem = QTreeWidgetItem()
parametersItem.setText(0, self.tr('Parameters'))
for paramType in ModelerParameterDefinitionDialog.paramTypes:
paramItem = QTreeWidgetItem()
paramItem.setText(0, paramType)
paramItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled)
parametersItem.addChild(paramItem)
self.inputsTree.addTopLevelItem(parametersItem)
parametersItem.setExpanded(True)
@@ -314,7 +374,10 @@ def addAlgorithm(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = ModelerUtils.getAlgorithm(item.alg.commandLineName())
alg = alg.getCopy()
self._addAlgorithm(alg)

def _addAlgorithm(self, alg):
alg = alg.getCopy()
dlg = alg.getCustomModelerParametersDialog(self.alg)
if not dlg:
dlg = ModelerParametersDialog(alg, self.alg)

0 comments on commit 92ee039

Please sign in to comment.
You can’t perform that action at this time.