mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-18 00:06:00 -04: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;
|
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
|
* @return error description
|
||||||
*/
|
*/
|
||||||
QString summary() const;
|
QString summary() const;
|
||||||
|
@ -258,7 +258,8 @@ class PGRasterTable(PGTable, RasterTable):
|
|||||||
|
|
||||||
return PGRasterTableInfo(self)
|
return PGRasterTableInfo(self)
|
||||||
|
|
||||||
def gdalUri(self):
|
def gdalUri(self, uri=None):
|
||||||
|
if not uri:
|
||||||
uri = self.database().uri()
|
uri = self.database().uri()
|
||||||
schema = (u'schema=%s' % self.schemaName()) if self.schemaName() else ''
|
schema = (u'schema=%s' % self.schemaName()) if self.schemaName() else ''
|
||||||
dbname = (u'dbname=%s' % uri.database()) if uri.database() else ''
|
dbname = (u'dbname=%s' % uri.database()) if uri.database() else ''
|
||||||
@ -285,9 +286,25 @@ class PGRasterTable(PGTable, RasterTable):
|
|||||||
return uri
|
return uri
|
||||||
|
|
||||||
def toMapLayer(self):
|
def toMapLayer(self):
|
||||||
from qgis.core import QgsRasterLayer, QgsContrastEnhancement
|
from qgis.core import QgsRasterLayer, QgsContrastEnhancement, QgsDataSourceURI, QgsCredentials
|
||||||
|
|
||||||
rl = QgsRasterLayer(self.gdalUri(), self.name)
|
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():
|
if rl.isValid():
|
||||||
rl.setContrastEnhancement(QgsContrastEnhancement.StretchToMinimumMaximum)
|
rl.setContrastEnhancement(QgsContrastEnhancement.StretchToMinimumMaximum)
|
||||||
return rl
|
return rl
|
||||||
|
@ -108,7 +108,7 @@ class CORE_EXPORT QgsError
|
|||||||
*/
|
*/
|
||||||
QString message( QgsErrorMessage::Format theFormat = QgsErrorMessage::Html ) const;
|
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
|
* @return error description
|
||||||
*/
|
*/
|
||||||
QString summary() const;
|
QString summary() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user