Skip to content
Permalink
Browse files

[processing] When an optional output is set to 'skip output', disable

and clear the associated 'add to qgis' checkbox
  • Loading branch information
nyalldawson committed May 6, 2018
1 parent cb638b6 commit f4ec9e2abb193e50cfe7631d92790fdbc1af3b61
@@ -29,7 +29,7 @@
import os

from qgis.PyQt import uic
from qgis.PyQt.QtCore import QCoreApplication, QDir
from qgis.PyQt.QtCore import QCoreApplication, QDir, pyqtSignal
from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog, QInputDialog
from qgis.PyQt.QtGui import QCursor
from qgis.gui import QgsEncodingSelectionDialog
@@ -62,6 +62,8 @@ class DestinationSelectionPanel(BASE, WIDGET):
SKIP_OUTPUT = QCoreApplication.translate(
'DestinationSelectionPanel', '[Skip output]')

skipOutputChanged = pyqtSignal(bool)

def __init__(self, parameter, alg):
super(DestinationSelectionPanel, self).__init__(None)
self.setupUi(self)
@@ -89,10 +91,17 @@ def __init__(self, parameter, alg):
def textChanged(self):
self.use_temporary = False

def outputIsSkipped(self):
"""
Returns true if output is set to be skipped
signal """
return not self.leText.text() and not self.use_temporary

def skipOutput(self):
self.leText.setPlaceholderText(self.SKIP_OUTPUT)
self.leText.setText('')
self.use_temporary = False
self.skipOutputChanged.emit(True)

def selectOutput(self):
if isinstance(self.parameter, QgsProcessingParameterFolderDestination):
@@ -152,6 +161,7 @@ def saveToTemporary(self):
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_FILE)
self.leText.setText('')
self.use_temporary = True
self.skipOutputChanged.emit(False)

def saveToPostGIS(self):
dlg = PostgisTableSelector(self, self.parameter.name().lower())
@@ -176,6 +186,8 @@ def saveToPostGIS(self):
QgsCredentials.instance().put(connInfo, user, passwd)
self.leText.setText("postgis:" + uri.uri())

self.skipOutputChanged.emit(False)

def saveToGeopackage(self):
file_filter = self.tr('GeoPackage files (*.gpkg);;All files (*.*)', 'OutputFile')

@@ -205,6 +217,8 @@ def saveToGeopackage(self):
'geom' if isinstance(self.parameter, QgsProcessingParameterFeatureSink) and self.parameter.hasGeometry() else None)
self.leText.setText("ogr:" + uri.uri())

self.skipOutputChanged.emit(False)

def selectFile(self):
file_filter = getFileFilter(self.parameter)
settings = QgsSettings()
@@ -245,6 +259,8 @@ def selectFile(self):
if not last_ext_path is None:
settings.setValue(last_ext_path, os.path.splitext(filename)[1].lower())

self.skipOutputChanged.emit(False)

def selectEncoding(self):
dialog = QgsEncodingSelectionDialog(
self, self.tr('File encoding'), self.encoding)
@@ -266,12 +282,15 @@ def selectDirectory(self):
self.leText.setText(QDir.toNativeSeparators(dirName))
settings.setValue('/Processing/LastOutputPath', dirName)

self.skipOutputChanged.emit(False)

def setValue(self, value):
if value == 'memory:':
self.saveToTemporary()
else:
self.leText.setText(value)
self.use_temporary = False
self.skipOutputChanged.emit(False)

def getValue(self):
key = None
@@ -30,6 +30,7 @@
__revision__ = '$Format:%H$'

import os
from functools import partial

from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingParameterExtent,
@@ -164,7 +165,14 @@ def initWidgets(self):
if isinstance(output, (QgsProcessingParameterRasterDestination, QgsProcessingParameterFeatureSink, QgsProcessingParameterVectorDestination)):
check = QCheckBox()
check.setText(self.tr('Open output file after running algorithm'))
check.setChecked(True)

def skipOutputChanged(checkbox, skipped):
checkbox.setEnabled(not skipped)
if skipped:
checkbox.setChecked(False)
check.setChecked(not widget.outputIsSkipped())
check.setEnabled(not widget.outputIsSkipped())
widget.skipOutputChanged.connect(partial(skipOutputChanged, check))
self.layoutMain.insertWidget(self.layoutMain.count() - 1, check)
self.checkBoxes[output.name()] = check

0 comments on commit f4ec9e2

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