Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 7, 2018
1 parent cb638b6 commit f4ec9e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
21 changes: 20 additions & 1 deletion python/plugins/processing/gui/DestinationSelectionPanel.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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())
Expand All @@ -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')

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -30,6 +30,7 @@
__revision__ = '$Format:%H$'

import os
from functools import partial

from qgis.core import (QgsProcessingParameterDefinition,
QgsProcessingParameterExtent,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f4ec9e2

Please sign in to comment.