Skip to content
Permalink
Browse files

db manager: show error message in bar when adding a layer fails (fixes

  • Loading branch information
jef-n committed Oct 28, 2014
1 parent 34af978 commit 0a875d3e819750fa4e0240a3d48459ac615bb03b
Showing with 14 additions and 4 deletions.
  1. +1 −1 python/plugins/db_manager/db_model.py
  2. +13 −3 python/plugins/db_manager/db_tree.py
@@ -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
@@ -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
@@ -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.
You can’t perform that action at this time.