Skip to content

Commit

Permalink
db manager: show error message in bar when adding a layer fails (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 29, 2014
1 parent 34af978 commit 0a875d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_model.py
Expand Up @@ -542,7 +542,7 @@ def importLayer(self, layerType, providerKey, layerName, uriString, parent):

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

# retrieve information about the new table's db and schema
Expand Down
16 changes: 13 additions & 3 deletions python/plugins/db_manager/db_tree.py
Expand Up @@ -23,7 +23,8 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import QgsMapLayerRegistry
from qgis.core import QgsMapLayerRegistry, QgsMessageLog
from qgis.gui import QgsMessageBar, QgsMessageBarItem

from .db_model import DBModel
from .db_plugins.plugin import DBPlugin, Schema, Table
Expand Down Expand Up @@ -140,10 +141,19 @@ def delete(self):
def addLayer(self):
table = self.currentTable()
if table is not None:
QgsMapLayerRegistry.instance().addMapLayers([table.toMapLayer()])
layer = table.toMapLayer()
layers = QgsMapLayerRegistry.instance().addMapLayers([layer])
if len(layers)<>1:
QgsMessageLog.instance().logMessage( self.tr( "%1 is an invalid layer - not loaded" ).replace( "%1", layer.publicSource() ) )
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 )
msgLabel.setWordWrap( True )
self.connect( msgLabel, SIGNAL("linkActivated( QString )" ),
self.mainWindow.iface.mainWindow().findChild( QWidget, "MessageLog" ), SLOT( "show()" ) )
self.connect( msgLabel, SIGNAL("linkActivated( QString )" ),
self.mainWindow.iface.mainWindow(), SLOT( "raise()" ) )
self.mainWindow.infoBar.pushItem( QgsMessageBarItem( msgLabel, QgsMessageBar.WARNING ) )

def reconnect(self):
db = self.currentDatabase()
if db is not None:
self.mainWindow.invokeCallback(db.reconnectActionSlot)

0 comments on commit 0a875d3

Please sign in to comment.