Skip to content

Commit

Permalink
Processing - Support OutputVector with no geometry in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-morvan committed May 17, 2016
1 parent fc5f70c commit afbe914
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
7 changes: 5 additions & 2 deletions python/plugins/processing/gui/OutputSelectionPanel.py
Expand Up @@ -142,7 +142,9 @@ def saveToPostGIS(self):
password = settings.value(mySettings + '/password')
uri = QgsDataSourceURI()
uri.setConnection(host, str(port), dbname, user, password)
uri.setDataSource(dlg.schema, dlg.table, "the_geom")
uri.setDataSource(dlg.schema, dlg.table,
"the_geom" if self.output.hasGeometry() else None)

connInfo = uri.connectionInfo()
(success, user, passwd) = QgsCredentials.instance().get(connInfo, None, None)
if success:
Expand Down Expand Up @@ -182,7 +184,8 @@ def saveToSpatialite(self):

uri = QgsDataSourceURI()
uri.setDatabase(fileName)
uri.setDataSource('', self.output.name.lower(), 'the_geom')
uri.setDataSource('', self.output.name.lower(),
'the_geom' if self.output.hasGeometry() else None)
self.leText.setText("spatialite:" + uri.uri())

def saveToMemory(self):
Expand Down
37 changes: 30 additions & 7 deletions python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -259,6 +259,22 @@ def initWidgets(self):
self.checkBoxes[output.name] = check
self.valueItems[output.name] = widget

if isinstance(output, OutputVector):
if output.base_input in self.dependentItems:
items = self.dependentItems[output.base_input]
else:
items = []
self.dependentItems[output.base_input] = items
items.append(output)

base_input = self.alg.getParameterFromName(output.base_input)
if isinstance(base_input, ParameterVector):
layers = dataobjects.getVectorLayers(base_input.shapetype)
else:
layers = dataobjects.getTables()
if len(layers) > 0:
output.base_layer = layers[0]

def buttonToggled(self, value):
if value:
sender = self.sender()
Expand Down Expand Up @@ -343,7 +359,7 @@ def getWidgetFromParameter(self, param):
else:
items = []
self.dependentItems[param.parent] = items
items.append(param.name)
items.append(param)
parent = self.alg.getParameterFromName(param.parent)
if isinstance(parent, ParameterVector):
layers = dataobjects.getVectorLayers(parent.shapetype)
Expand Down Expand Up @@ -434,12 +450,15 @@ def updateDependentFields(self):
return
children = self.dependentItems[sender.name]
for child in children:
widget = self.valueItems[child]
widget.clear()
if self.alg.getParameterFromName(child).optional:
widget.addItem(self.tr('[not set]'))
widget.addItems(self.getFields(layer,
self.alg.getParameterFromName(child).datatype))
if isinstance(child, ParameterTableField):
widget = self.valueItems[child.name]
widget.clear()
if self.alg.getParameterFromName(child).optional:
widget.addItem(self.tr('[not set]'))
widget.addItems(self.getFields(layer,
self.alg.getParameterFromName(child).datatype))
if isinstance(child, OutputVector):
child.base_layer = layer

def getFields(self, layer, datatype):
fieldTypes = []
Expand All @@ -460,4 +479,8 @@ def somethingDependsOnThisParameter(self, parent):
if isinstance(param, ParameterTableField):
if param.parent == parent.name:
return True
for output in self.alg.outputs:
if isinstance(output, OutputVector):
if output.base_layer == parent.name:
return True
return False

0 comments on commit afbe914

Please sign in to comment.