Skip to content

Commit 0a875d3

Browse files
committed
db manager: show error message in bar when adding a layer fails (fixes #8148)
1 parent 34af978 commit 0a875d3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

python/plugins/db_manager/db_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ def importLayer(self, layerType, providerKey, layerName, uriString, parent):
542542

543543
if not inLayer.isValid():
544544
# invalid layer
545-
QMessageBox.warning(None, self.tr("Invalid layer"), self.tr("Unable to load the layer %s") % inLayer.name)
545+
QMessageBox.warning(None, self.tr("Invalid layer"), self.tr("Unable to load the layer %s") % inLayer.name())
546546
return False
547547

548548
# retrieve information about the new table's db and schema

python/plugins/db_manager/db_tree.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
from PyQt4.QtCore import *
2424
from PyQt4.QtGui import *
2525

26-
from qgis.core import QgsMapLayerRegistry
26+
from qgis.core import QgsMapLayerRegistry, QgsMessageLog
27+
from qgis.gui import QgsMessageBar, QgsMessageBarItem
2728

2829
from .db_model import DBModel
2930
from .db_plugins.plugin import DBPlugin, Schema, Table
@@ -140,10 +141,19 @@ def delete(self):
140141
def addLayer(self):
141142
table = self.currentTable()
142143
if table is not None:
143-
QgsMapLayerRegistry.instance().addMapLayers([table.toMapLayer()])
144+
layer = table.toMapLayer()
145+
layers = QgsMapLayerRegistry.instance().addMapLayers([layer])
146+
if len(layers)<>1:
147+
QgsMessageLog.instance().logMessage( self.tr( "%1 is an invalid layer - not loaded" ).replace( "%1", layer.publicSource() ) )
148+
msgLabel = QLabel( self.tr( "%1 is an invalid layer and cannot be loaded. Please check the <a href=\"#messageLog\">message log</a> for further info." ).replace( "%1", layer.publicSource() ), self.mainWindow.infoBar )
149+
msgLabel.setWordWrap( True )
150+
self.connect( msgLabel, SIGNAL("linkActivated( QString )" ),
151+
self.mainWindow.iface.mainWindow().findChild( QWidget, "MessageLog" ), SLOT( "show()" ) )
152+
self.connect( msgLabel, SIGNAL("linkActivated( QString )" ),
153+
self.mainWindow.iface.mainWindow(), SLOT( "raise()" ) )
154+
self.mainWindow.infoBar.pushItem( QgsMessageBarItem( msgLabel, QgsMessageBar.WARNING ) )
144155

145156
def reconnect(self):
146157
db = self.currentDatabase()
147158
if db is not None:
148159
self.mainWindow.invokeCallback(db.reconnectActionSlot)
149-

0 commit comments

Comments
 (0)