Skip to content
Permalink
Browse files

db manager: add credentials to postgis rasters (fixes #13594)

  • Loading branch information
jef-n committed Oct 13, 2015
1 parent e225385 commit 53c507d3a75234be0fa5e3fad6c0fe4670348fc9
Showing with 22 additions and 5 deletions.
  1. +1 −1 python/core/qgserror.sip
  2. +20 −3 python/plugins/db_manager/db_plugins/postgis/plugin.py
  3. +1 −1 src/core/qgserror.h
@@ -71,7 +71,7 @@ class QgsError
*/
QString message( QgsErrorMessage::Format theFormat = QgsErrorMessage::Html ) const;

/** Short error descriprion, usually the first error in chain, the real error.
/** Short error description, usually the first error in chain, the real error.
* @return error description
*/
QString summary() const;
@@ -258,8 +258,9 @@ def info(self):

return PGRasterTableInfo(self)

def gdalUri(self):
uri = self.database().uri()
def gdalUri(self, uri=None):
if not uri:
uri = self.database().uri()
schema = (u'schema=%s' % self.schemaName()) if self.schemaName() else ''
dbname = (u'dbname=%s' % uri.database()) if uri.database() else ''
host = (u'host=%s' % uri.host()) if uri.host() else ''
@@ -285,9 +286,25 @@ def mimeUri(self):
return uri

def toMapLayer(self):
from qgis.core import QgsRasterLayer, QgsContrastEnhancement
from qgis.core import QgsRasterLayer, QgsContrastEnhancement, QgsDataSourceURI, QgsCredentials

rl = QgsRasterLayer(self.gdalUri(), self.name)
if not rl.isValid():
err = rl.error().summary()
uri = QgsDataSourceURI(self.database().uri())
conninfo = uri.connectionInfo()
username = uri.username()
password = uri.password()

for i in range(3):
(ok, username, password) = QgsCredentials.instance().get(conninfo, username, password, err)
if ok:
uri.setUsername(username)
uri.setPassword(password)
rl = QgsRasterLayer(self.gdalUri(uri), self.name)
if rl.isValid():
break

if rl.isValid():
rl.setContrastEnhancement(QgsContrastEnhancement.StretchToMinimumMaximum)
return rl
@@ -108,7 +108,7 @@ class CORE_EXPORT QgsError
*/
QString message( QgsErrorMessage::Format theFormat = QgsErrorMessage::Html ) const;

/** Short error descriprion, usually the first error in chain, the real error.
/** Short error description, usually the first error in chain, the real error.
* @return error description
*/
QString summary() const;

0 comments on commit 53c507d

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