mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
db manager: add credentials to postgis rasters (fixes #13594)
This commit is contained in:
parent
e225385aaa
commit
53c507d3a7
@ -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 @@ 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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user