Skip to content

Commit

Permalink
Fix dest selection panel when used in folder mode
Browse files Browse the repository at this point in the history
Also fix some UX issues with the panel in folder, such as
correctly remembering/restoring last used folders, defaulting
to home dir, don't clear value when canceling while browsing
  • Loading branch information
nyalldawson committed Jun 22, 2017
1 parent 76a9844 commit 9d8118c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion python/plugins/processing/gui/AlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ def getParamValues(self):
dest_project = QgsProject.instance()

value = self.mainWidget.outputWidgets[param.name()].getValue()
if value:
if value and isinstance(value, QgsProcessingOutputLayerDefinition):
value.destinationProject = dest_project
if value:
parameters[param.name()] = value

return parameters
Expand Down
24 changes: 16 additions & 8 deletions python/plugins/processing/gui/DestinationSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import os

from qgis.PyQt import uic
from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtCore import QCoreApplication, QDir
from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog
from qgis.PyQt.QtGui import QCursor
from qgis.gui import QgsEncodingFileDialog, QgsExpressionBuilderDialog
Expand All @@ -40,10 +40,9 @@
QgsSettings,
QgsProcessingParameterFeatureSink,
QgsProcessingOutputLayerDefinition,
QgsProcessingParameterDefinition)
QgsProcessingParameterDefinition,
QgsProcessingParameterFolderOutput)
from processing.core.ProcessingConfig import ProcessingConfig
from processing.core.outputs import OutputVector
from processing.core.outputs import OutputDirectory
from processing.tools.dataobjects import createContext
from processing.gui.PostgisTableSelector import PostgisTableSelector
from processing.gui.ParameterGuiUtils import getFileFilter
Expand Down Expand Up @@ -80,7 +79,7 @@ def __init__(self, parameter, alg):
and alg.provider().supportsNonFileBasedOutput():
# use memory layers for temporary files if supported
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_LAYER)
else:
elif not isinstance(self.parameter, QgsProcessingParameterFolderOutput):
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_FILE)

self.btnSelect.clicked.connect(self.selectOutput)
Expand All @@ -95,7 +94,7 @@ def skipOutput(self):
self.use_temporary = False

def selectOutput(self):
if isinstance(self.parameter, OutputDirectory):
if isinstance(self.parameter, QgsProcessingParameterFolderOutput):
self.selectDirectory()
else:
popupMenu = QMenu()
Expand Down Expand Up @@ -253,10 +252,16 @@ def selectFile(self):
settings.setValue('/Processing/encoding', self.encoding)

def selectDirectory(self):
lastDir = ''
lastDir = self.leText.text()
settings = QgsSettings()
if not lastDir:
lastDir = settings.value("/Processing/LastOutputPath", QDir.homePath())

dirName = QFileDialog.getExistingDirectory(self, self.tr('Select directory'),
lastDir, QFileDialog.ShowDirsOnly)
self.leText.setText(dirName)
if dirName:
self.leText.setText(QDir.toNativeSeparators(dirName))
settings.setValue('/Processing/LastOutputPath', dirName)

def getValue(self):
key = None
Expand All @@ -268,6 +273,9 @@ def getValue(self):
if not key and self.parameter.flags() & QgsProcessingParameterDefinition.FlagOptional:
return None

if isinstance(self.parameter, QgsProcessingParameterFolderOutput):
return key

value = QgsProcessingOutputLayerDefinition(key)
value.createOptions = {'fileEncoding': self.encoding}
return value

0 comments on commit 9d8118c

Please sign in to comment.