Skip to content
Permalink
Browse files

[processing] show confirmation when closing modeler with unsaved model

(fix #9889)
  • Loading branch information
alexbruy committed Mar 26, 2014
1 parent f8a558a commit 05ce12062c2431976081eb07c6a731d7114f7f0a
Showing with 34 additions and 30 deletions.
  1. +34 −30 python/plugins/processing/modeler/ModelerDialog.py
@@ -67,17 +67,17 @@ def __init__(self, alg=None):
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()
event.ignore()

def _dropEvent(event):
if event.mimeData().hasText():
if event.mimeData().hasText():
text = event.mimeData().text()
print text
print text
if text in ModelerParameterDefinitionDialog.paramTypes:
self.addInputOfType(text)
else:
@@ -87,39 +87,39 @@ def _dropEvent(event):
event.accept()
else:
event.ignore()

def _dragMoveEvent(event):
if event.mimeData().hasText():
event.accept()
else:
event.ignore()
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)

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.setDragDropMode(QTreeWidget.DragOnly)
self.inputsTree.setDropIndicatorShown(True)
def _mimeDataAlgorithm(items):

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

self.algorithmTree.mimeData = _mimeDataAlgorithm
self.algorithmTree.setDragDropMode(QTreeWidget.DragOnly)

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

# Set icons
@@ -149,6 +149,7 @@ def _mimeDataAlgorithm(items):
self.inputsTree.doubleClicked.connect(self.addInput)
self.searchBox.textChanged.connect(self.fillAlgorithmTree)
self.algorithmTree.doubleClicked.connect(self.addAlgorithm)
self.scene.changed.connect(self.changeModel)

self.btnOpen.clicked.connect(self.openModel)
self.btnSave.clicked.connect(self.save)
@@ -172,6 +173,9 @@ def _mimeDataAlgorithm(items):
# closing this dialog
self.update = False

def changeModel(self):
self.hasChanged = True

def closeEvent(self, evt):
if self.hasChanged:
ret = QMessageBox.question(self, self.tr('Message'),
@@ -340,13 +344,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):

def addInputOfType(self, paramType):
if paramType in ModelerParameterDefinitionDialog.paramTypes:
dlg = ModelerParameterDefinitionDialog(self.alg, paramType)
dlg.exec_()
@@ -360,7 +364,7 @@ def addInputOfType(self, paramType):
self.hasChanged = True

def fillInputsTree(self):
parametersItem = QTreeWidgetItem()
parametersItem = QTreeWidgetItem()
parametersItem.setText(0, self.tr('Parameters'))
for paramType in ModelerParameterDefinitionDialog.paramTypes:
paramItem = QTreeWidgetItem()
@@ -375,9 +379,9 @@ def addAlgorithm(self):
if isinstance(item, TreeAlgorithmItem):
alg = ModelerUtils.getAlgorithm(item.alg.commandLineName())
self._addAlgorithm(alg)

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

0 comments on commit 05ce120

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