Skip to content

Commit 001ae44

Browse files
committedAug 14, 2016
[processing] If supported, use memory layers instead of shapefiles
when writing to a temporary result Avoids truncation of field names and other format specific limitations
1 parent a064c0a commit 001ae44

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed
 

‎python/plugins/processing/gui/OutputSelectionPanel.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class OutputSelectionPanel(BASE, WIDGET):
5454

5555
SAVE_TO_TEMP_FILE = QCoreApplication.translate(
5656
'OutputSelectionPanel', '[Save to temporary file]')
57+
SAVE_TO_TEMP_LAYER = QCoreApplication.translate(
58+
'OutputSelectionPanel', '[Create temporary layer]')
5759

5860
def __init__(self, output, alg):
5961
super(OutputSelectionPanel, self).__init__(None)
@@ -63,7 +65,12 @@ def __init__(self, output, alg):
6365
self.alg = alg
6466

6567
if hasattr(self.leText, 'setPlaceholderText'):
66-
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_FILE)
68+
if isinstance(output, OutputVector) \
69+
and alg.provider.supportsNonFileBasedOutput():
70+
# use memory layers for temporary files if supported
71+
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_LAYER)
72+
else:
73+
self.leText.setPlaceholderText(self.SAVE_TO_TEMP_FILE)
6774

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

@@ -73,8 +80,14 @@ def selectOutput(self):
7380
else:
7481
popupMenu = QMenu()
7582

76-
actionSaveToTempFile = QAction(
77-
self.tr('Save to a temporary file'), self.btnSelect)
83+
if isinstance(self.output, OutputVector) \
84+
and self.alg.provider.supportsNonFileBasedOutput():
85+
# use memory layers for temporary files if supported
86+
actionSaveToTempFile = QAction(
87+
self.tr('Create temporary layer'), self.btnSelect)
88+
else:
89+
actionSaveToTempFile = QAction(
90+
self.tr('Save to a temporary file'), self.btnSelect)
7891
actionSaveToTempFile.triggered.connect(self.saveToTemporaryFile)
7992
popupMenu.addAction(actionSaveToTempFile)
8093

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

91104
if isinstance(self.output, OutputVector) \
92105
and self.alg.provider.supportsNonFileBasedOutput():
93-
actionSaveToMemory = QAction(
94-
self.tr('Save to memory layer'), self.btnSelect)
95-
actionSaveToMemory.triggered.connect(self.saveToMemory)
96-
popupMenu.addAction(actionSaveToMemory)
97106
actionSaveToSpatialite = QAction(
98107
self.tr('Save to Spatialite table...'), self.btnSelect)
99108
actionSaveToSpatialite.triggered.connect(self.saveToSpatialite)
@@ -188,9 +197,6 @@ def saveToSpatialite(self):
188197
'the_geom' if self.output.hasGeometry() else None)
189198
self.leText.setText("spatialite:" + uri.uri())
190199

191-
def saveToMemory(self):
192-
self.leText.setText('memory:')
193-
194200
def selectFile(self):
195201
fileFilter = self.output.getFileFilter(self.alg)
196202

@@ -239,8 +245,13 @@ def getValue(self):
239245
fileName = result
240246
if fileName.startswith("[") and fileName.endswith("]"):
241247
fileName = fileName[1:-1]
242-
if fileName.strip() in ['', self.SAVE_TO_TEMP_FILE]:
243-
value = None
248+
if fileName.strip() in ['', self.SAVE_TO_TEMP_FILE, self.SAVE_TO_TEMP_LAYER]:
249+
if isinstance(self.output, OutputVector) \
250+
and self.alg.provider.supportsNonFileBasedOutput():
251+
# use memory layers for temporary files if supported
252+
value = 'memory:'
253+
else:
254+
value = None
244255
elif fileName.startswith('memory:'):
245256
value = fileName
246257
elif fileName.startswith('postgis:'):

0 commit comments

Comments
 (0)
Please sign in to comment.