Skip to content

Commit

Permalink
db manager: add credentials to postgis rasters (fixes #13594)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 13, 2015
1 parent e225385 commit 53c507d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/core/qgserror.sip
Expand Up @@ -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;
Expand Down
23 changes: 20 additions & 3 deletions python/plugins/db_manager/db_plugins/postgis/plugin.py
Expand Up @@ -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 ''
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgserror.h
Expand Up @@ -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;
Expand Down

0 comments on commit 53c507d

Please sign in to comment.