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

This commit is contained in:
Juergen E. Fischer 2015-10-13 22:43:52 +02:00
parent e225385aaa
commit 53c507d3a7
3 changed files with 22 additions and 5 deletions

View File

@ -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;

View File

@ -258,8 +258,9 @@ class PGRasterTable(PGTable, RasterTable):
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 @@ class PGRasterTable(PGTable, RasterTable):
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

View File

@ -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;