Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3392 from nyalldawson/processing_temp
[processing] If supported, use memory layers instead of shapefiles
  • Loading branch information
alexbruy committed Aug 16, 2016
2 parents 282f406 + 001ae44 commit ce13310
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions python/plugins/processing/gui/OutputSelectionPanel.py
Expand Up @@ -54,6 +54,8 @@ class OutputSelectionPanel(BASE, WIDGET):

SAVE_TO_TEMP_FILE = QCoreApplication.translate(
'OutputSelectionPanel', '[Save to temporary file]')
SAVE_TO_TEMP_LAYER = QCoreApplication.translate(
'OutputSelectionPanel', '[Create temporary layer]')

def __init__(self, output, alg):
super(OutputSelectionPanel, self).__init__(None)
Expand All @@ -63,7 +65,12 @@ def __init__(self, output, alg):
self.alg = alg

if hasattr(self.leText, 'setPlaceholderText'):
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_FILE)
if isinstance(output, OutputVector) \
and alg.provider.supportsNonFileBasedOutput():
# use memory layers for temporary files if supported
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_LAYER)
else:
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_FILE)

self.btnSelect.clicked.connect(self.selectOutput)

Expand All @@ -73,8 +80,14 @@ def selectOutput(self):
else:
popupMenu = QMenu()

actionSaveToTempFile = QAction(
self.tr('Save to a temporary file'), self.btnSelect)
if isinstance(self.output, OutputVector) \
and self.alg.provider.supportsNonFileBasedOutput():
# use memory layers for temporary files if supported
actionSaveToTempFile = QAction(
self.tr('Create temporary layer'), self.btnSelect)
else:
actionSaveToTempFile = QAction(
self.tr('Save to a temporary file'), self.btnSelect)
actionSaveToTempFile.triggered.connect(self.saveToTemporaryFile)
popupMenu.addAction(actionSaveToTempFile)

Expand All @@ -90,10 +103,6 @@ def selectOutput(self):

if isinstance(self.output, OutputVector) \
and self.alg.provider.supportsNonFileBasedOutput():
actionSaveToMemory = QAction(
self.tr('Save to memory layer'), self.btnSelect)
actionSaveToMemory.triggered.connect(self.saveToMemory)
popupMenu.addAction(actionSaveToMemory)
actionSaveToSpatialite = QAction(
self.tr('Save to Spatialite table...'), self.btnSelect)
actionSaveToSpatialite.triggered.connect(self.saveToSpatialite)
Expand Down Expand Up @@ -188,9 +197,6 @@ def saveToSpatialite(self):
'the_geom' if self.output.hasGeometry() else None)
self.leText.setText("spatialite:" + uri.uri())

def saveToMemory(self):
self.leText.setText('memory:')

def selectFile(self):
fileFilter = self.output.getFileFilter(self.alg)

Expand Down Expand Up @@ -239,8 +245,13 @@ def getValue(self):
fileName = result
if fileName.startswith("[") and fileName.endswith("]"):
fileName = fileName[1:-1]
if fileName.strip() in ['', self.SAVE_TO_TEMP_FILE]:
value = None
if fileName.strip() in ['', self.SAVE_TO_TEMP_FILE, self.SAVE_TO_TEMP_LAYER]:
if isinstance(self.output, OutputVector) \
and self.alg.provider.supportsNonFileBasedOutput():
# use memory layers for temporary files if supported
value = 'memory:'
else:
value = None
elif fileName.startswith('memory:'):
value = fileName
elif fileName.startswith('postgis:'):
Expand Down

0 comments on commit ce13310

Please sign in to comment.