Skip to content
Permalink
Browse files

[processing] more improvements for storing db data in log

This allows reusing commands that use a db-based layer.

It disables parameter validity checks for layers. Those checks should now be performed at the algorithm level before executing (not yet implemented)
  • Loading branch information
volaya committed Jun 23, 2015
1 parent 6e4113f commit 6ce2333f9866ca869d2c2c1c1423159539161642
Showing with 25 additions and 33 deletions.
  1. +4 −26 python/plugins/processing/core/parameters.py
  2. +21 −7 python/plugins/processing/tools/dataobjects.py
@@ -18,7 +18,6 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
@@ -149,16 +148,9 @@ def getValueAsCommandLineParameter(self):
if self.value is None:
return unicode(None)
else:
s = unicode(self.value)
if isWindows():
s = s.replace('\\', '\\\\')
s = s.replace('"', "'")
s = dataobjects.normalizeLayerSource(unicode(self.value))
s = '"%s"' % s

s = re.sub("'user.*?'", "", s)
s = re.sub("'password.*?'", "", s)

return s
return s

class ParameterExtent(Parameter):

@@ -523,16 +515,7 @@ def setValue(self, obj):
return True
else:
self.value = unicode(obj)
layers = dataobjects.getRasterLayers()
for layer in layers:
if layer.name() == self.value:
self.value = unicode(layer.dataProvider().dataSourceUri())
return True
if os.path.exists(self.value) or QgsRasterLayer(self.value).isValid():
return True
else:
# Layer could not be found
return False
return True


def getFileFilter(self):
@@ -744,12 +727,7 @@ def setValue(self, obj):
return True
else:
self.value = unicode(obj)
layers = dataobjects.getVectorLayers(self.shapetype)
for layer in layers:
if layer.name() == self.value or layer.source() == self.value:
self.value = unicode(layer.source())
return True
return os.path.exists(self.value)
return True


def getSafeExportedLayer(self):
@@ -17,6 +17,7 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
@@ -33,7 +34,7 @@
from qgis.utils import iface
from processing.core.ProcessingConfig import ProcessingConfig
from processing.algs.gdal.GdalUtils import GdalUtils
from processing.tools.system import getTempFilenameInTempFolder, getTempFilename
from processing.tools.system import getTempFilenameInTempFolder, getTempFilename, isWindows

ALL_TYPES = [-1]

@@ -208,9 +209,16 @@ def getObject(uriorname):
ret = getObjectFromUri(uriorname)
return ret

def normalizeLayerSource(source):
if isWindows():
s = source.replace('\\', '/')
s = s.replace('"', "'")
s = re.sub("user=.*?", "", s)
s = re.sub("password=.*?", "", s)
return s

def getObjectFromUri(uri, forceLoad=True):
"""Returns an object (layer/table) given a file location.
"""Returns an object (layer/table) given a source definition.
if forceLoad is true, it tries to load it if it is not currently open
Otherwise, it will return the object only if it is loaded in QGIS.
@@ -222,15 +230,15 @@ def getObjectFromUri(uri, forceLoad=True):
return _loadedLayers[uri]
layers = getRasterLayers()
for layer in layers:
if layer.source() == uri:
if normalizeLayerSource(layer.source()) == normalizeLayerSource(uri):
return layer
layers = getVectorLayers()
for layer in layers:
if layer.source() == uri:
if normalizeLayerSource(layer.source()) == normalizeLayerSource(uri):
return layer
tables = getTables()
for table in tables:
if table.source() == uri:
if normalizeLayerSource(table.source()) == normalizeLayerSource(uri):
return table
if forceLoad:
settings = QSettings()
@@ -242,13 +250,19 @@ def getObjectFromUri(uri, forceLoad=True):
if layer.isValid():
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
_loadedLayers[layer.source()] = layer
_loadedLayers[normalizeLayerSource(layer.source())] = layer
return layer
layer = QgsVectorLayer(uri, uri, 'postgres')
if layer.isValid():
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
_loadedLayers[normalizeLayerSource(layer.source())] = layer
return layer
layer = QgsRasterLayer(uri, uri)
if layer.isValid():
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)
_loadedLayers[layer.source()] = layer
_loadedLayers[normalizeLayerSource(layer.source())] = layer
return layer
if prjSetting:
settings.setValue('/Projections/defaultBehaviour', prjSetting)

0 comments on commit 6ce2333

Please sign in to comment.
You can’t perform that action at this time.